home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Examples / DistributedObjects / remoteSpot / SpotView.m < prev    next >
Text File  |  1992-07-24  |  2KB  |  111 lines

  1.  
  2. #import "SpotView.h"
  3. #import "Spot.h"
  4. #import "Thinker.h"
  5.  
  6. @implementation SpotView
  7.  
  8. - (BOOL) acceptsFirstMouse
  9. {    return YES;
  10. }
  11.  
  12. - initFrame:(const NXRect *)r
  13. {
  14.     [super initFrame:r];
  15.     [self allocateGState];        // For faster lock/unlockFocus
  16.     return self;
  17. }
  18.  
  19. - lateInit
  20. {
  21.     server = [myThinker server];
  22.     return self;
  23. }
  24.  
  25. - mouseDown:(NXEvent *)theEvent
  26. {
  27.     NXPoint mouseLocation, offset;
  28.     id spotToMove = nil;
  29.     int    looping = YES, oldMask;
  30.  
  31.     oldMask = [window addToEventMask:NX_MOUSEDRAGGEDMASK];
  32.     do {
  33.         mouseLocation = theEvent->location;
  34.         [self convertPoint:&mouseLocation fromView:nil];
  35.         
  36.         switch (theEvent->type)
  37.         {
  38.             case NX_MOUSEDOWN:
  39.                 spotToMove = [server getSpotForPoint:mouseLocation
  40.                                 spotLocation:&offset];
  41.                 if (!spotToMove)
  42.                 {
  43.                     looping = NO;
  44.                     break;
  45.                 }
  46.                 offset.x = mouseLocation.x - offset.x;
  47.                 offset.y = mouseLocation.y - offset.y;
  48.                 break;
  49.  
  50.             case NX_MOUSEUP:
  51.                 looping = NO;
  52.                 // now fall into mousedragged implementation
  53.  
  54.             case NX_MOUSEDRAGGED:
  55.                 mouseLocation.x -= offset.x;
  56.                 mouseLocation.y -= offset.E'1            if (![spotToMove setLocation:mouseLocation])
  57.                 {
  58.                     looping = NO;
  59.                     spotToMove = nil;
  60.                 }
  61.                 break;
  62.         }
  63.         
  64.        } while (looping && (theEvent = [NXApp getNextEvent:
  65.             NX_MOUSEUPMASK|NX_MOUSEDRAGGEDMASK]));
  66.  
  67.     [window setEventMask:oldMask];
  68.  
  69.     [spotToMove unlock];
  70.     // if (![myThinker isServer])
  71.     if ([spotToMove isProxy])
  72.     {
  73.         // this actually frees the local proxy but may or may not
  74.         // free the ref-counted spot on the server side
  75.  
  76.         [spotToMove free];
  77.     }
  78.  
  79.     return self;
  80. }
  81.  
  82. - drawSelf:(const NXRect *) rects :(int)rectCount
  83. {
  84.     int    i, n;
  85.     id aSpot;
  86.     NXPoint pnt;
  87.  
  88.     PSsetgray(NX_WHITE);
  89.     NXRectFill(&bounds);
  90.  
  91.     // the list is retrieved bycopy so it is local, as are
  92.     // all the objects in the list
  93.  
  94.     spotList = [myThinker spotList];
  95.     
  96.     n = [spotList count];
  97.     
  98.     for (i = 0; i < n; i++)
  99.     {
  100.         aSpot = [spotList objectAt:i];
  101.         NXSetColor([aSpot color]);
  102.         pnt = [aSpot location];
  103.         PSarc(pnt.x+15, pnt.y+15, 15, 0, 360);
  104.         PSfill();
  105.     }
  106.     return self;
  107. }
  108.  
  109.  
  110. @end
  111.