home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / OOP_Course / Labs / FruitView / Fruit.m < prev    next >
Encoding:
Text File  |  1993-01-18  |  1.8 KB  |  105 lines

  1. /* Objective_C Implementation of the Fruit Class: Fruit.m */
  2.  
  3. #import "Fruit.h"
  4.  
  5. @implementation Fruit
  6.  
  7. /* Initialize a new fruit. */
  8.  
  9. /* Intialize display to be showing correct current values. */
  10. -appDidInit:sender
  11. {
  12.     [self displayValues:self];
  13.     return self;
  14. }
  15.  
  16. - initFrame:(const NXRect *)frameRect
  17. {
  18.     [super initFrame:frameRect];
  19.     [self setDiameter:1];        // init the diameter
  20.     [self setColor:NX_COLORRED];     // init the color
  21.     return self;            // return the new instance
  22. }
  23.  
  24. //set color by having a color chip dropped onto the view
  25. -acceptColor:(NXColor)aColor atPoint:(NXPoint *)aPoint
  26. {
  27.     [self setColor:aColor];
  28.     return self;
  29. }
  30.  
  31. /* Action method for setting the color of the fruit. */
  32. -takeColorFrom:sender
  33. {
  34.     [self setColor:[sender color]];
  35.     return self;
  36. }
  37.  
  38. /* Set the color of the fruit. */
  39. -setColor:(NXColor)aColor
  40. {
  41.     color = aColor;
  42.     [self display];
  43.     return self;
  44. }
  45.  
  46. /* Return the fruit's color. */
  47. - (NXColor)color
  48. {
  49.     return color;
  50. }
  51.  
  52. /* Action method for setting the diameter of the fruit. */
  53. -takeDiameterFrom:sender
  54. {
  55.     [self setDiameter:[sender intValue]];
  56.     return self;
  57. }
  58.  
  59. /* Set the fruit's diameter. */
  60. -setDiameter: (int) aSize
  61. {
  62.     diameter = aSize;
  63.     [self display];
  64.     return self;
  65. }
  66.  
  67. /* Return the fruit's diameter. */
  68. - (int) diameter
  69. {
  70.     return diameter;
  71. }
  72.  
  73. /* Tell the fruit to increase its diameter. */
  74. - grow:sender
  75. {
  76.     [self setDiameter:([self diameter] + 1)];
  77.     return self;
  78. }
  79.  
  80. - displayValues:sender
  81. {
  82.     [colorDisplay setColor:color];
  83.     [diameterDisplay setIntValue:diameter];
  84.     return self;
  85. }
  86.  
  87. - drawSelf:(const NXRect*)r :(int)c
  88. {
  89.     PSsetgray(NX_LTGRAY);
  90.     NXRectFill(&bounds);        //"erase" to gray
  91.  
  92.     NXSetColor(color);    //for drawing, set to selected color
  93.     
  94.     /* Draw the fruit. */
  95.     PSnewpath();
  96.     PSarc(bounds.size.width/2.0, bounds.size.height/2.0,
  97.                 [self diameter]/2.0,0.,360.);
  98.     PSclosepath();
  99.  
  100.     PSfill();        //fill the defined path
  101.     return self;
  102. }
  103.  
  104. @end
  105.