home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / MiscKit / Source / MiscHalftoneColor.m < prev    next >
Encoding:
Text File  |  1994-01-25  |  3.4 KB  |  147 lines

  1. //
  2. //    MiscHalftoneColor.m -- a class for color "tints"  (to specify a halftone)
  3. //        Written by Don Yacktman (c) 1994 by Don Yacktman.
  4. //                Version 1.0.  All rights reserved.
  5. //
  6. //        This notice may not be removed from this source code.
  7. //
  8. //    This object is included in the MiscKit by permission from the author
  9. //    and its use is governed by the MiscKit license, found in the file
  10. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  11. //    for a list of all applicable permissions and restrictions.
  12. //    
  13.  
  14. #import <misckit/misckit.h>
  15.  
  16. @implementation MiscHalftoneColor
  17.  
  18. + (BOOL)canInitFromPasteboard:(Pasteboard *)pasteboard
  19. { // ***** need version to handle object type
  20.     return [super canInitFromPasteboard:pasteboard];
  21. }
  22.  
  23. - setFromPasteBoard:(Pasteboard *)pasteboard
  24. { // ***** need version to handle object type
  25.     return [super setFromPasteBoard:pasteboard];
  26. }
  27.  
  28. - writeToPasteBoard:(Pasteboard *)pasteboard
  29. { // ***** need version to handle object type
  30.     return [super writeToPasteBoard:pasteboard];
  31. }
  32.  
  33. - setHalftone:(float)amount
  34. {
  35.     percent = MAX(MIN(amount, 1.0), 0.0);
  36.     return self;
  37. }
  38.  
  39. - (float)halftone { return percent; }
  40.  
  41. - (NXColor)filterColor:(NXColor)input
  42. { // halftone the color to print before printing it:
  43.     float c, m, y, k;
  44.     id workingColor = [MiscColor newColor:input];
  45.     [workingColor getCyan:&c magenta:&m yellow:&y black:&k];
  46.     [workingColor setCyan:(c * percent) magenta:(m * percent)
  47.             yellow:(y * percent) black:(k * percent)];
  48.     return [workingColor color];
  49. }
  50.  
  51. - setColorFromObject:object
  52. {
  53.     if ([super setColorFromObject:object]) {
  54.         // preserve halftoning info if available, if not, assume 100% color
  55.         if ([object respondsTo:@selector(halftone)])
  56.             percent = [object halftone];
  57.         else percent = 1.0;
  58.         return self;
  59.     }
  60.     return nil;
  61. }
  62.  
  63. - (BOOL)isEqualHalftoneAmount:anObject
  64. {
  65.     if ([anObject respondsTo:@selector(halftone)])
  66.         if ([anObject halftone] == percent) return YES;
  67.     return NO;
  68. }
  69.  
  70. - (BOOL)isEqualColor:anObject
  71. {
  72.     if ([super isEqualColor:anObject]) {
  73.         return [self isEqualHalftoneAmount:anObject];
  74.     } else {
  75.         if ([anObject respondsTo:@selector(isEqualToColor:)])
  76.             return [anObject isEqualToColor:[self filterColor:theColor]];
  77.         else if ([anObject respondsTo:@selector(color)]) {
  78.             id tempColor = [MiscColor newColor:[self filterColor:theColor]];
  79.             BOOL ret = [tempColor isEqualToColor:[anObject color]];
  80.             [tempColor free];
  81.             return ret;
  82.         }
  83.     }
  84.     return NO;
  85. }
  86.  
  87. - (BOOL)isEqual:anObject
  88. {
  89.     if ([super isEqual:anObject]) {
  90.         return [self isEqualHalftoneAmount:anObject];
  91.     }
  92.     return NO;
  93. }
  94.  
  95. - read:(NXTypedStream *)stream
  96. {
  97.     [super read:stream];
  98.     NXReadTypes(stream, "f", &percent);
  99.     return self;
  100. }
  101.  
  102. - write:(NXTypedStream *)stream
  103. {
  104.     [super write:stream];
  105.     NXWriteTypes(stream, "f", &percent);
  106.     return self;
  107. }
  108.  
  109. - encodeUsing:(id <NXEncoding>)portal
  110. {
  111.     [super encodeUsing:portal];
  112.     [portal encodeData:&percent ofType:"f"];
  113.     return self;
  114. }
  115.  
  116. - decodeUsing:(id <NXDecoding>)portal
  117. {
  118.     [super decodeUsing:portal];
  119.     [portal decodeData:&percent ofType:"f"];
  120.     return self;
  121. }
  122.  
  123. - encodeRemotelyFor:(NXConnection *)connection
  124.     freeAfterEncoding:(BOOL *)flagp isBycopy:(BOOL)isByCopy
  125. {
  126.     return [super encodeRemotelyFor:connection
  127.                 freeAfterEncoding:flagp isBycopy:isByCopy];
  128. }
  129.  
  130. - (const char *)getInspectorClassName
  131. {
  132.     return "MiscHalftoneColorInspector";
  133. }
  134.  
  135. - (NXImage *)getIBImage
  136. {
  137.     return [NXImage findImageNamed:"MiscHalftoneColorObj"];
  138. }
  139.  
  140. - setColorFromPixel:(NXPoint *)location
  141. {
  142.     [super setColorFromPixel:location];
  143.     percent = 1.0;
  144.     return self;
  145. }
  146.  
  147. @end