home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / AppKit / Rulers / ColorRect.m < prev    next >
Text File  |  1996-04-26  |  2KB  |  93 lines

  1. /* ColorRect.m
  2.  *
  3.  * by Nik Gervae, Technical Publications, NeXT Software Inc.
  4.  *
  5.  * You may freely copy, distribute, and reuse the code in this example.
  6.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to
  7.  * its fitness for any particular use.
  8.  */
  9.  
  10.  
  11. #import "ColorRect.h"
  12.  
  13. @implementation ColorRect
  14.  
  15. - (id)initWithFrame:(NSRect)aRect color:(NSColor *)aColor
  16. {
  17.     self = [super init];
  18.     if (!self) return nil;
  19.     frame = aRect;
  20.     color = [aColor copyWithZone:[self zone]];
  21.     return self;
  22. }
  23.  
  24. - (void)setFrame:(NSRect)aRect
  25. {
  26.     frame = aRect;
  27.     return;
  28. }
  29.  
  30. - (NSRect)frame
  31. {
  32.     return frame;
  33. }
  34.  
  35. - (NSColor *)color
  36. {
  37.     return color;
  38. }
  39.  
  40. - (void)setLocked:(BOOL)flag
  41. {
  42.     locked = flag;
  43.     return;
  44. }
  45.  
  46.  
  47. - (BOOL)isLocked
  48. {
  49.     return locked;
  50. }
  51.  
  52.  
  53. - (void)drawRect:(NSRect)aRect selected:(BOOL)flag
  54. {
  55.     NSRect dRect;
  56.  
  57.     PSgsave();
  58.     NSRectClip(aRect);
  59.  
  60.     dRect = NSIntersectionRect(aRect, frame);
  61.     [color set];
  62.     NSRectFill(dRect);
  63.  
  64.     if (flag) {
  65.         [[NSColor blackColor] set];
  66.         PSsetlinewidth(4.0);
  67.         NSFrameRect(frame);
  68.     }
  69.  
  70.     if (locked) {
  71.         float xSize;
  72.  
  73.         [[NSColor blackColor] set];
  74.         PSsetlinewidth(3.0);
  75.  
  76.         if (NSWidth(frame) > 10.0) xSize = 5.0;
  77.         else xSize = 2.0;
  78.  
  79.         PSmoveto(NSMidX(frame) - xSize, NSMidY(frame) - xSize);
  80.         PSlineto(NSMidX(frame) + xSize, NSMidY(frame) + xSize);
  81.         PSmoveto(NSMidX(frame) - xSize, NSMidY(frame) + xSize);
  82.         PSlineto(NSMidX(frame) + xSize, NSMidY(frame) - xSize);
  83.         PSstroke();
  84.     }
  85.  
  86.     PSgrestore();
  87.  
  88.     return;
  89. }
  90.  
  91.  
  92. @end
  93.