home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d571 / gwin.lha / Gwin / Examples / changecolor.c < prev    next >
C/C++ Source or Header  |  1991-12-22  |  5KB  |  180 lines

  1. #include <stdio.h>
  2. #include "gwin.user.h"
  3.  
  4. /* I used this routine, embedded a geographic display system, */
  5. /* to adjust the relative brightnesses of the colors I was    */
  6. /* using so that I could get 35mm slides without the white    */
  7. /* "blooming" compared to the red.  I held a photocell up to  */
  8. /* each square region on the screen and read the intrinsic    */
  9. /* brightness with a voltmeter.  I then adjusted each color   */
  10. /* by clicking on the sub-squares to adjust the amount of red,*/
  11. /* blue, and green being used and adjusted to taste and to    */
  12. /* the camera response.                                       */
  13.  
  14. #define MAXBOXES 32
  15.  
  16. float black       = 0.0;
  17. float red         = 1.0;
  18. float green       = 2.0;
  19. float border      = 3.0;
  20. float yellow      = 5.0;
  21. float white       = 7.0;
  22. float forestgreen = 13.0;
  23. float aqua        = 14.0;
  24. float darkblue    = 10.0;
  25. float blue        = 11.0;
  26.  
  27. int Red = 0;
  28. int Green = 1;
  29. int Blue = 2;
  30.  
  31. struct boxstruct {
  32. int active;
  33. float x1,y1,x2,y2,color;
  34. } boxdata[MAXBOXES];
  35.  
  36. main()
  37. {
  38.  
  39.    USTART("high2",0.,600.,0.,400.);
  40.    adjust_color();
  41. }
  42.  
  43. adjust_color()
  44. {
  45. float x,y,redvalue,greenvalue,bluevalue;
  46. int index,more,color,increment;
  47. float x1,y1,x2,y2;
  48.  
  49.    x1 = 0.0;
  50.    y1 = 0.0;
  51.    x2 = 100.0;
  52.    y2 = 100.0;
  53.  
  54.    udarea(G,x1,x2,y1,y2);
  55.    upset(G,"colo",white);
  56.    uoutln(G);
  57.  
  58.    draw_box((int)red,red,                 1.,1.,13.,20.);
  59.    draw_box((int)green,green,            15.,1.,27.,20.);
  60.    draw_box((int)blue,blue,              29.,1.,41.,20.);
  61.    draw_box((int)yellow,yellow,          43.,1.,55.,20.);
  62.    draw_box((int)white,white,            57.,1.,69.,20.);
  63.    draw_box((int)forestgreen,forestgreen,71.,1.,83.,20.);
  64.    draw_box((int)aqua,aqua,              85.,1.,97.,20.);
  65.    draw_box((int)border,border,          1.,21.,13.,40.);
  66.  
  67.    for(;;){
  68.       if(ugrin(G,&x,&y)) {UEND();exit(0);}
  69.       getboxdata(x,y,&index,&more,&color);
  70.       if(index < 0 )break;
  71.       ugetrgb(G,(float)index,&redvalue,&greenvalue,&bluevalue);
  72.       if(more){
  73.          increment = 1;
  74.       }else{
  75.          increment = -1;
  76.       }
  77.  
  78.       if(color == Red  ) redvalue    = redvalue + increment;
  79.       if(color == Green) greenvalue  = greenvalue + increment;
  80.       if(color == Blue ) bluevalue   = bluevalue + increment;
  81.  
  82.       usetrgb(G,(float)index,redvalue,greenvalue,bluevalue);
  83.       draw_box(index,boxdata[index].color,
  84.                      boxdata[index].x1,
  85.                      boxdata[index].y1,
  86.                      boxdata[index].x2,
  87.                      boxdata[index].y2);
  88.    }
  89.  
  90.    UEND();
  91. }
  92.  
  93. draw_box(boxindex,color,x1,y1,x2,y2)
  94. int boxindex;
  95. float color;
  96. float x1,y1,x2,y2;
  97. {
  98. float redvalue,greenvalue,bluevalue;
  99. char redint[10],greenint[10],blueint[10];
  100.  
  101.    if(boxindex >= MAXBOXES){
  102.       printf("Box index limit of %d exceeded.\n",MAXBOXES);
  103.       {UEND();exit(1);}
  104.    }
  105.  
  106.    ugetrgb(G,(float)boxindex,&redvalue,&greenvalue,&bluevalue);
  107.  
  108.    upset(G,"colo",color);
  109.    uset(G,"fill");
  110.    umove(G,x1,y1);
  111.    udraw(G,x1,y2);
  112.    udraw(G,x2,y2);
  113.    udraw(G,x2,y1);
  114.    udraw(G,x1,y1);
  115.    uset(G,"nofi");
  116.  
  117.    upset(G,"colo",black);
  118.  
  119.    umove(G,x1,y1+.3333*(y2-y1));
  120.    udraw(G,x2,y1+.3333*(y2-y1));
  121.  
  122.    umove(G,x1,y1+.6666*(y2-y1));
  123.    udraw(G,x2,y1+.6666*(y2-y1));
  124.  
  125.    umove(G,x1+.5*(x2-x1),y1);
  126.    udraw(G,x1+.5*(x2-x1),y2);
  127.  
  128.    sprintf(redint,"%2.0f",redvalue);
  129.    sprintf(greenint,"%2.0f",greenvalue);
  130.    sprintf(blueint,"%2.0f",bluevalue);
  131.  
  132.    upset(G,"bcol",color);
  133.    uprint(G,x1+.7*(x2-x1),y1+.78*(y2-y1),redint);
  134.    uprint(G,x1+.7*(x2-x1),y1+.45*(y2-y1),greenint);
  135.    uprint(G,x1+.7*(x2-x1),y1+.11*(y2-y1),blueint);
  136.    upset(G,"bcol",black);
  137.  
  138.    boxdata[boxindex].active = 1;
  139.    boxdata[boxindex].x1 = x1;
  140.    boxdata[boxindex].x2 = x2;
  141.    boxdata[boxindex].y1 = y1;
  142.    boxdata[boxindex].y2 = y2;
  143.    boxdata[boxindex].color = color;
  144.  
  145. }
  146.  
  147. getboxdata(x,y,index,more,color)
  148. float x,y;
  149. int *index,*more,*color;
  150. {
  151. int i;
  152. float rmax, gmax;
  153.  
  154.    *more = 0;
  155.    *index = -1;
  156.    for(i=0;i<MAXBOXES;i++){
  157.       if(       x >= boxdata[i].x1
  158.              && x <= boxdata[i].x2
  159.              && y >= boxdata[i].y1
  160.              && y <= boxdata[i].y2){
  161.          *index = i;
  162.          if(x > boxdata[i].x1
  163.                 + .5*(boxdata[i].x2 - boxdata[i].x1)){
  164.             *more = 1;
  165.          }else{
  166.             *more = 0;
  167.          }
  168.  
  169.          rmax = boxdata[i].y1 + .3333*(boxdata[i].y2 - boxdata[i].y1);
  170.          gmax = boxdata[i].y1 + .6666*(boxdata[i].y2 - boxdata[i].y1);
  171.  
  172.          if(y >= gmax)             *color = Red;
  173.          if(y >= rmax && y < gmax) *color = Green;
  174.          if(y <  rmax)             *color = Blue;
  175.       }
  176.    }
  177. }
  178.  
  179.  
  180.