home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Examples / AppKit / Draw / Rectangle.m < prev    next >
Text File  |  1992-07-20  |  1KB  |  58 lines

  1. #import "draw.h"
  2.  
  3. @implementation Rectangle : Graphic
  4. /*
  5.  * This is the canonical Graphic.
  6.  * It doesn't get much simpler than this.
  7.  *
  8.  * This line is just a stub to get genstrings to generate
  9.  * a .strings file entry for the name of this type of Graphic.
  10.  * The name is used in the Undo New <Whatever> menu item.
  11.  *
  12.  * NXLocalString("Rectangle", NULL, "Name of the tool that draws rectangles, i.e., the %s of the New %s operation.")
  13.  */
  14.  
  15. + initialize
  16. /*
  17.  * This bumps the class version so that we can compatibly read
  18.  * old Graphic objects out of an archive.
  19.  */
  20. {
  21.     [Rectangle setVersion:1];
  22.     return self;
  23. }
  24.  
  25. /* Methods overridden from superclass */
  26.  
  27. - (float)naturalAspectRatio
  28. /*
  29.  * The natural aspect ratio of a rectangle is 1.0 (a square).
  30.  */
  31. {
  32.     return 1.0;
  33. }
  34.  
  35. - (Graphic *)colorAcceptorAt:(const NXPoint *)point
  36. {
  37.     if ([self hit:point]) return self;
  38.     return nil;
  39. }
  40.  
  41. - draw
  42. {
  43.     if (bounds.size.width < 1.0 || bounds.size.height < 1.0) return self;
  44.  
  45.     if ([self fill]) {
  46.     [self setFillColor];
  47.     NXRectFill(&bounds);
  48.     }
  49.     if (!gFlags.nooutline) {
  50.     [self setLineColor];
  51.     PSrectstroke(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
  52.     }
  53.  
  54.     return self;
  55. }
  56.  
  57. @end
  58.