home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / Tutorial / Cookbook / 21.mouse / NewScottView.m < prev    next >
Encoding:
Text File  |  1993-01-19  |  1.9 KB  |  112 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "NewScottView.h"
  5. #import <appkit/appkit.h>
  6. #import <appkit/Control.h>
  7. #import <dpsclient/wraps.h>
  8. #import <appkit/Application.h>
  9. #import <appkit/Responder.h>
  10.  
  11. @implementation NewScottView
  12.  
  13. - setPenColorCtrl:anObject
  14. {
  15.     penColorCtrl = anObject;
  16.     return self;
  17. }
  18.  
  19. - setPenWidthCtrl:anObject
  20. {
  21.     penWidthCtrl = anObject;
  22.     return self;
  23. }
  24.  
  25. - setBackColorCtrl:anObject
  26. {
  27.     backColorCtrl = anObject;
  28.     return self;
  29. }
  30.  
  31. - setPenWidth:sender
  32. {
  33.     penWidth = [sender floatValue];
  34.     return self;
  35. }
  36.  
  37. - clearView:sender
  38. {
  39.     [self display];
  40.     return self;
  41. }
  42.  
  43. - setBackColor:sender
  44. {
  45.     backColor = [sender floatValue];
  46.     return self;
  47. }
  48.  
  49. - setPenColor:sender
  50. {
  51.     penColor = [sender floatValue];
  52.     return self;
  53. }
  54. + newFrame: (NXRect *)nf
  55. {
  56.     self = [super newFrame:nf];
  57.     backColor = 1.0;
  58.     penColor = 0.0;
  59.     penWidth = 1.0;
  60.     return self;
  61. }
  62.  
  63. - drawSelf:(NXRect *)list:(int)count
  64. {
  65.     [self lockFocus];
  66.     PSsetgray(backColor);
  67.     NXRectFill(&bounds);
  68.     [self unlockFocus];
  69.     return self;
  70. }
  71.  
  72.  
  73. - mouseDown: (NXEvent *)ptr
  74. {
  75.     NXPoint    mLoc, oldLoc;
  76.     NXEvent    *nextEvent;
  77.     BOOL    looping = YES;
  78.     int    oldMask;
  79.     int    checkMask;
  80.     
  81.     oldMask = [window eventMask];
  82.     checkMask = NX_MOUSEUPMASK | NX_MOUSEDRAGGEDMASK;
  83.     [window setEventMask:( oldMask|checkMask)];
  84.     [self lockFocus];
  85.     oldLoc = ptr->location;
  86.     [self convertPoint:&oldLoc fromView:nil];
  87.     PSsetgray(penColor);
  88.     PSsetlinewidth(penWidth);
  89.     while (looping) {
  90.         nextEvent = [NXApp getNextEvent:checkMask];
  91.         looping = (nextEvent->type != NX_MOUSEUP);
  92.         if (looping) {
  93.             mLoc = nextEvent->location;
  94.             [self convertPoint:&mLoc fromView:nil];
  95.             if ((mLoc.x != oldLoc.x) | (mLoc.y != oldLoc.y)) {
  96.                 PSnewpath();
  97.                 PSmoveto(oldLoc.x,oldLoc.y);
  98.                 
  99.                 PSlineto(mLoc.x,mLoc.y);
  100.                 PSclosepath();
  101.                 PSstroke();
  102.                 [window flushWindow];
  103.                 oldLoc = mLoc;
  104.             }
  105.         }
  106.     }
  107.     [self unlockFocus];
  108.     [window setEventMask:oldMask];
  109.     return self;
  110. }
  111. @end
  112.