|
|
1.1 root 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.y;
57: if (![spotToMove setLocation:mouseLocation])
58: {
59: looping = NO;
60: spotToMove = nil;
61: }
62: break;
63: }
64:
65: } while (looping && (theEvent = [NXApp getNextEvent:
66: NX_MOUSEUPMASK|NX_MOUSEDRAGGEDMASK]));
67:
68: [window setEventMask:oldMask];
69:
70: [spotToMove unlock];
71: // if (![myThinker isServer])
72: if ([spotToMove isProxy])
73: {
74: // this actually frees the local proxy but may or may not
75: // free the ref-counted spot on the server side
76:
77: [spotToMove free];
78: }
79:
80: return self;
81: }
82:
83: - drawSelf:(const NXRect *) rects :(int)rectCount
84: {
85: int i, n;
86: id aSpot;
87: NXPoint pnt;
88:
89: PSsetgray(NX_WHITE);
90: NXRectFill(&bounds);
91:
92: // the list is retrieved bycopy so it is local, as are
93: // all the objects in the list
94:
95: spotList = [myThinker spotList];
96:
97: n = [spotList count];
98:
99: for (i = 0; i < n; i++)
100: {
101: aSpot = [spotList objectAt:i];
102: NXSetColor([aSpot color]);
103: pnt = [aSpot location];
104: PSarc(pnt.x+15, pnt.y+15, 15, 0, 360);
105: PSfill();
106: }
107: return self;
108: }
109:
110:
111: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.