class library: Spawner - don't access PriorityQueue-array
[supercollider.git] / editors / scapp / TabletEvents.m
blob96e2c8cc8ee7bc738b73aade9ce7c18677003c78
1 /*----------------------------------------------------------------------------
3 FILE NAME
5 TabletEvents.m - Implamentation file for TabletEvent Category.
6                  This is an extension to the NSEvent class.
8 COPYRIGHT
10 Copyright WACOM Technology, Inc. 2001.
12 All rights reserved.
14 ----------------------------------------------------------------------------*/
16 #import "TabletEvents.h"
18 NSString *kProximityNotification = @"Proximity Event Notification"; 
20 NSString *kVendorID = @"vendorID";
21 NSString *kTabletID = @"tabletID";
22 NSString *kPointerID = @"pointerID";
23 NSString *kDeviceID = @"deviceID";
24 NSString *kSystemTabletID = @"systemTabletID";
25 NSString *kVendorPointerType = @"vendorPointerType";
26 NSString *kPointerSerialNumber = @"pointerSerialNumber";
27 NSString *kUniqueID = @"uniqueID";
28 NSString *kCapabilityMask = @"capabilityMask";
29 NSString *kPointerType = @"pointerType";
30 NSString *kEnterProximity = @"enterProximity"; 
32 @implementation NSEvent (TabletEvents) 
33 //////////////////////////////////////////////////////////////////////////////
34 - (void *)eventRef
36    return _eventRef;
41 //////////////////////////////////////////////////////////////////////////////
42 - (BOOL) isTabletPointerEvent
44         OSStatus        result;
45    UInt32       eventType;
46         
47         switch (GetEventClass((EventRef)_eventRef))
48         {
49                 case kEventClassMouse:
50                         result = GetEventParameter((EventRef)_eventRef,
51                                                                                 kEventParamTabletEventType,
52                                                                                 typeUInt32, NULL,
53                                                                                 sizeof( eventType ), NULL,
54                                                                                 &eventType      );
56          if ( result == noErr )
57          {
58             if ( eventType == kEventTabletPoint )
59             {
60                                         return YES;
61             }
62          }
63                 break;
64                         
65                 case kEventClassTablet:
66                         if(GetEventKind((EventRef)_eventRef) == kEventTabletPoint)
67                         {
68                                 return YES;
69                         }
70                 break;
71                         
72                 default:
73                 break;
74         }
75         
76         return NO;
81 //////////////////////////////////////////////////////////////////////////////
82 - (BOOL) isTabletProximityEvent
84         OSStatus        result;
85    UInt32       eventType;
87         switch (GetEventClass((EventRef)_eventRef))
88         {
89                 case kEventClassMouse:
90                         result = GetEventParameter((EventRef)_eventRef,
91                                                                                 kEventParamTabletEventType,
92                                                                                 typeUInt32, NULL,
93                                                                                 sizeof( eventType ), NULL,
94                                                                                 &eventType      );
96          if ( result == noErr )
97          {
98             if ( eventType == kEventTabletProximity )
99             {
100                                         return YES;
101             }
102          }
103                 break;
105                 case kEventClassTablet:
106                         if(GetEventKind((EventRef)_eventRef) == kEventTabletProximity)
107                         {
108                                 return YES;
109                         }
110                 break;
112                 default:
113                 break;
114         }
116         return NO;
121 //////////////////////////////////////////////////////////////////////////////
122 - (TabletPointerRec) tabletRec
124    OSStatus             result;
125    TabletPointerRec tabletData;
126    
127    result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec, 
128                                                                                 typeTabletPointerRec, NULL, 
129                                                                                 sizeof( TabletPointerRec ), NULL, &tabletData );
130    
131    return tabletData;
136 //////////////////////////////////////////////////////////////////////////////
137 - (void) setLocation:(NSPoint)loc
139    _location = loc;
144 //////////////////////////////////////////////////////////////////////////////
145 - (unsigned int) deviceID
147    OSStatus             result;
148    TabletPointerRec tabletData;
149    UInt16 theDeviceID = 0;
150    
151    result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec, 
152                                                                                 typeTabletPointerRec, NULL, 
153                                                                                 sizeof( TabletPointerRec ), NULL, &tabletData );
154    
155    if (result == noErr)
156    {
157       theDeviceID = tabletData.deviceID;
158    }
159    
160    return theDeviceID;
165 //////////////////////////////////////////////////////////////////////////////
166 - (int) absoluteX
168    OSStatus             result;
169    TabletPointerRec tabletData;
170    SInt32 absX = 0;
171    
172    result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec, 
173                                                                                 typeTabletPointerRec, NULL, 
174                                                                                 sizeof( TabletPointerRec ), NULL, &tabletData );
175    
176    if (result == noErr)
177    {
178       absX = tabletData.absX;
179    }
180    
181    return absX;
186 //////////////////////////////////////////////////////////////////////////////
187 - (int) absoluteY
189    OSStatus             result;
190    TabletPointerRec tabletData;
191    SInt32 absY = 0;
192    
193    result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec, 
194                                                                                 typeTabletPointerRec, NULL, 
195                                                                                 sizeof( TabletPointerRec ), NULL, &tabletData );
196    
197    if (result == noErr)
198    {
199       absY = tabletData.absX;
200    }
201    
202    return absY;
207 //////////////////////////////////////////////////////////////////////////////
208 - (int) absoluteZ
210    OSStatus             result;
211    TabletPointerRec tabletData;
212    SInt32 absZ = 0;
213    
214    result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec, 
215                                                                                 typeTabletPointerRec, NULL, 
216                                                                                 sizeof( TabletPointerRec ), NULL, &tabletData );
217    
218    if (result == noErr)
219    {
220       absZ = tabletData.absZ;
221    }
222    
223    return absZ;
228 //////////////////////////////////////////////////////////////////////////////
229 - (void) getAbsoluteX:(SInt32*)absX Y:(SInt32*)absY Z:(SInt32*)absZ
231    OSStatus             result;
232    TabletPointerRec tabletData;
233    
234    result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec, 
235                                                                                 typeTabletPointerRec, NULL, 
236                                                                                 sizeof( TabletPointerRec ), NULL, &tabletData );
237    
238    if (result == noErr)
239    {
240       if (absX != NULL)
241       {
242          *absX = tabletData.absX;
243       }
244       
245       if (absY != NULL)
246       {
247          *absY = tabletData.absY;
248       }
249       
250       if (absZ != NULL)
251       {
252          *absZ = tabletData.absZ;
253       }
254    }
259 //////////////////////////////////////////////////////////////////////////////
260 - (NSPoint) tilt
262    OSStatus             result;
263    TabletPointerRec tabletData;
264    NSPoint theTilt = {0.0, 0.0};
265    
266    result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec, 
267                                                                                 typeTabletPointerRec, NULL, 
268                                                                                 sizeof( TabletPointerRec ), NULL, &tabletData );
269    
270    if (result == noErr)
271    {
272         theTilt.x = tabletData.tiltX/32767.0;
273       theTilt.y = tabletData.tiltY/32767.0;
274    }
275    
276    return theTilt;
282 //////////////////////////////////////////////////////////////////////////////
283 - (UInt16) rawTabletPressure
285    OSStatus             result;
286    TabletPointerRec tabletData;
287    UInt16 pressure = 0;
288    
289    result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec, 
290                                                                                 typeTabletPointerRec, NULL, 
291                                                                                 sizeof( TabletPointerRec ), NULL, &tabletData );
292    
293    if (result == noErr)
294    {
295       pressure = tabletData.pressure;
296    }
297    
298    return pressure;
303 //////////////////////////////////////////////////////////////////////////////
304 - (float) scaledTabletPressure
306    OSStatus             result;
307    TabletPointerRec tabletData;
308    float pressure = 0.0;
309    
310    result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec, 
311                                                                                 typeTabletPointerRec, NULL, 
312                                                                                 sizeof( TabletPointerRec ), NULL, &tabletData );
313    
314    if (result == noErr)
315    {
316       pressure = (float)tabletData.pressure/65535.0;
317    }
318    
319    return pressure;
324 //////////////////////////////////////////////////////////////////////////////
325 - (float) rotationInDegrees; /* 0.0¡ <-> +359.99999¡ */
327    OSStatus             result;
328    TabletPointerRec tabletData;
329    UInt16 rotation = 0;
330    float rotDeg = 0.0;
331    
332    result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec, 
333                                                                                 typeTabletPointerRec, NULL, 
334                                                                                 sizeof( TabletPointerRec ), NULL, &tabletData );
335    
336    if (result == noErr)
337    {
338       rotation = tabletData.rotation;
339       rotDeg = (float)rotation/64.0;
340    }
341    
342    return rotDeg;
347 //////////////////////////////////////////////////////////////////////////////
348 - (float) rotationInRadians; /* 0 <-> 2¹ */
350    OSStatus             result;
351    TabletPointerRec tabletData;
352    UInt16 rotation = 0;
353    float rotRad = 0.0;
354    
355    result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec, 
356                                                                                 typeTabletPointerRec, NULL, 
357                                                                                 sizeof( TabletPointerRec ), NULL, &tabletData );
358    
359    if (result == noErr)
360    {
361       rotation = tabletData.rotation;
362       rotRad = (float)rotation/64.0;
363       rotRad = (rotRad * pi) / 180.0;
364    }
365    
366    return rotRad;
369 @end