home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / OOP_Course / Labs / DrawSquare / SquareView.m < prev   
Encoding:
Text File  |  1993-01-18  |  778 b   |  36 lines

  1. #import "SquareView.h"
  2.  
  3. @implementation SquareView
  4.  
  5. - takeSliderInput:sender
  6. {
  7.     xSlider    = [sender floatValue];
  8.     [self display];    
  9.     return self;
  10. }
  11.  
  12.  
  13. - drawSelf:(const NXRect*)r :(int)c
  14. {
  15.     float side;            //temporary side of the square
  16.     
  17.     PSsetgray(NX_WHITE);
  18.     NXRectFill(&bounds);    //erase the present view
  19.     PSsetgray(NX_BLACK);
  20.     PSsetlinewidth(5.0);
  21.     /* Scale the side to the minimum of the view width and height. */
  22.     side = xSlider*((bounds.size.width < bounds.size.height) ?
  23.                          bounds.size.width : bounds.size.height);
  24.     /* Draw the square. */
  25.     PSnewpath();
  26.     PSmoveto(bounds.size.width/2.0-side/2.0, bounds.size.height/2.0-side/2.0);
  27.     PSrlineto(0.0, side);
  28.     PSrlineto(side,0.0);
  29.     PSrlineto(0.0,-side);
  30.     PSclosepath();
  31.     PSstroke();
  32.     return self;
  33. }
  34.  
  35. @end
  36.