home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Graphics / ToyViewer-2.6a / src / ImageOpr.bproj / TonePanelCtrl.m < prev   
Encoding:
Text File  |  1997-01-23  |  1.5 KB  |  81 lines

  1. #import  "TonePanelCtrl.h"
  2. #import  <appkit/Control.h>
  3. #import  <appkit/Matrix.h>
  4. #import  <stdio.h>
  5. #import  "../common.h"
  6. #import  "../ImageOpCtr.h"
  7. #import  "../ImageOpr.h"
  8.  
  9.  
  10. @implementation TonePanelCtrl
  11.  
  12. - init
  13. {
  14.     return [self reset:nil];
  15. }
  16.  
  17. - reset: sender
  18. {
  19.     int    i;
  20.  
  21.     if (sender && [sender selectedTag] != 0)
  22.         [mainSlider setFloatValue: 1.0];
  23.     for (i = 0; i < N_Colors; i++)
  24.         ratios[i] = 1.0;
  25.     return [self changeMainValue: self];
  26. }
  27.  
  28. /* Local Method */
  29. - setFormatFloat:(float)value to:target
  30. {
  31.     char    buf[16];
  32.  
  33.     sprintf(buf, "%4.2f", (int)(value * 20.0) / 20.0);
  34.     return [target setStringValue: buf];
  35. }
  36.  
  37. - changeMainValue: sender
  38. {
  39.     int    i;
  40.     float    v, cv;
  41.  
  42.     v = [mainSlider floatValue];
  43.     [self setFormatFloat:v to:mainIndicator];
  44.     for (i = 0; i < N_Colors; i++) {
  45.         cv = v * ratios[i];
  46.         if (cv > Colors_MAXVAL) cv = Colors_MAXVAL;
  47.         [[colorSliders cellAt:i :0] setFloatValue: cv];
  48.         [self setFormatFloat:cv to:[colorIndicators cellAt:i :0]];
  49.     }
  50.     return self;
  51. }
  52.  
  53. - changeColorValue: sender
  54. {
  55.     id    cell;
  56.     int    tag;
  57.     float    v, mv;
  58.  
  59.     cell = [sender selectedCell];
  60.     tag = [cell tag];
  61.     v = [cell floatValue];
  62.     mv = [mainSlider floatValue];
  63.     ratios[tag] = (mv > 0.01) ? (v / mv) : 1.0;
  64.     [self setFormatFloat:v to:[colorIndicators cellAt:tag :0]];
  65.     return self;
  66. }
  67.  
  68. - colorTone: sender
  69. {
  70.     int    i;
  71.     float    values[N_Colors];
  72.  
  73.     for (i = 0; i < N_Colors; i++)
  74.         values[i] = [[colorIndicators cellAt:i :0] floatValue];
  75.     [imageOpCtr colorToneEnhance: values];
  76.     /* This message will be delegated to ImageOpr */
  77.     return self;
  78. }
  79.  
  80. @end
  81.