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

  1. //
  2. //    MiscScreenColor.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 MiscScreenColor
  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. - initColor:(NXColor)color
  34. {
  35.     return [self initColorFromPixel:NULL inView:nil];
  36. }
  37.  
  38. - initColorFromPixel:(NXPoint *)location
  39. {
  40.     return [self initColorFromPixel:location inView:nil];
  41. }
  42.  
  43. - initColorFromPixel:(NXPoint *)location inView:view
  44. {
  45.     [self setLocation:location];
  46.     [self setView:view];
  47.     [self setDelegate:nil];
  48.     [self updateColor];
  49.     return self;
  50. }
  51.  
  52. - (NXColor)actualColor
  53. { // keep us up to date
  54.     [self updateColor];
  55.     return [super actualColor];
  56. }
  57.  
  58. - (NXPoint)location { return theLocation; }
  59. - view
  60. {
  61.     return theView;
  62. }
  63.  
  64. - setView:aView
  65. {
  66.     id ret = [self view];
  67.     theView = aView;
  68.     return ret;
  69. }
  70.  
  71. - setLocation:(NXPoint *)location
  72. {
  73.     if (!location) {
  74.         theLocation.x = 0.0;
  75.         theLocation.y = 0.0;
  76.         return nil;
  77.     }
  78.     theLocation.x = location->x;
  79.     theLocation.y = location->y;
  80.     return self;
  81. }
  82.  
  83. - updateColor
  84. {
  85.     id view = [self view];
  86.     NXPoint location = [self location];
  87.     if (view && ![view isFocusView]) [view lockFocus];
  88.     [super setColorFromPixel:&location];
  89.     if (view && ![view isFocusView]) [view lockFocus];
  90.     return self;
  91. }
  92.  
  93. - read:(NXTypedStream *)stream
  94. {
  95.     NXPoint newPoint;
  96.     id newView;
  97.     [super read:stream];
  98.     NXReadPoint(stream, &newPoint);
  99.     newView = NXReadObject(stream);
  100.     [self setLocation:&newPoint];
  101.     [self setView:newView];
  102.     return self;
  103. }
  104.  
  105. - write:(NXTypedStream *)stream
  106. {
  107.     id view = [self view];
  108.     NXPoint point = [self location];
  109.     [super write:stream];
  110.     NXWritePoint(stream, &point);
  111.     NXWriteObject(stream, view);
  112.     return self;
  113. }
  114.  
  115. - encodeUsing:(id <NXEncoding>)portal
  116. {
  117.     id view = [self view];
  118.     NXPoint point = [self location];
  119.     [super encodeUsing:portal];
  120.     [portal encodeData:&(point.x) ofType:"f"];
  121.     [portal encodeData:&(point.y) ofType:"f"];
  122.     [portal encodeData:&view ofType:"@"];
  123.     return self;
  124. }
  125.  
  126. - decodeUsing:(id <NXDecoding>)portal
  127. {
  128.     NXPoint newPoint;
  129.     id newView;
  130.     [super decodeUsing:portal];
  131.     [portal decodeData:&(newPoint.x) ofType:"f"];
  132.     [portal decodeData:&(newPoint.y) ofType:"f"];
  133.     [portal decodeData:&newView ofType:"@"];
  134.     [self setLocation:&newPoint];
  135.     [self setView:newView];
  136.     return self;
  137. }
  138.  
  139. - encodeRemotelyFor:(NXConnection *)connection
  140.     freeAfterEncoding:(BOOL *)flagp isBycopy:(BOOL)isByCopy
  141. {
  142.     return [super encodeRemotelyFor:connection
  143.                 freeAfterEncoding:flagp isBycopy:isByCopy];
  144. }
  145.  
  146. - (const char *)getInspectorClassName
  147. {
  148.     return "MiscScreenColorInspector";
  149. }
  150.  
  151. - (NXImage *)getIBImage
  152. {
  153.     return [NXImage findImageNamed:"MiscScreenColorObj"];
  154. }
  155.  
  156. @end