This is ImageWithGlove.m in view mode; [Download] [Up]
/* * Written by Joe Freeman 2/91 * * Simple class that hacks the Matel PowerGlove into ImagePaint * * This sets up a timed entry that causes the program to poll the * current glove location. That location is then mapped to the screen * to allow the user to paint, as if using the mouse. * */ /* Generated by Interface Builder */ #import "ImageWithGlove.h" #import "PowerGlove.h" #import <c.h> #import <appkit/Application.h> #import <appkit/NXColorWell.h> #import <appkit/Slider.h> #import <dpsclient/psops.h> #import <dpsclient/wraps.h> #import <appkit/Button.h> @implementation ImageWithGlove void timeHandler(DPSTimedEntry teNumber, double now, void *userData) { [(id)userData getGloveData]; } - initFrame:(const NXRect *)theFrame { [super initFrame:theFrame]; powerGlove = [[PowerGlove alloc] init]; [powerGlove init]; [powerGlove setxHyst:0 yHyst:0 zHyst:0]; timerNum = DPSAddTimedEntry(0.10, &timeHandler, self, NX_BASETHRESHOLD); return self; } /* need to get the current glove position and fake like we are an event */ /* convert glove position to be full scale in this view */ - getGloveData { NXEvent temp; int tempLocationZ, lastLocationZ; static NXEvent last; float tempSize; NXColor tempBrushColor; #ifdef DEBUG fprintf(stderr, "X = %d, Y= %d, Z = %d, " "Thumb = %d, Index = %d, Middle = %d, Ring %d\n", [powerGlove gloveX], [powerGlove gloveY], [powerGlove gloveZ], [powerGlove thumb], [powerGlove index], [powerGlove middle], [powerGlove ring]); #endif if ([powerGlove thumb]>1){ [brushDisplay performClick:self]; }else if ([powerGlove index]>1){ tempSize = [brushSize floatValue]+ [brushSize maxValue]* 0.05; if (tempSize > [brushSize maxValue]) tempSize = tempSize - [brushSize maxValue]; [brushSize setFloatValue:tempSize]; [self drawBrushImage:self]; } if ([powerGlove middle]>1 || [powerGlove ring] >1){ //fprintf(stderr,"%d,%d-",[powerGlove middle],[powerGlove ring]); /* mouse down or mouse dragged */ if (last.type == NX_MOUSEDOWN || last.type == NX_MOUSEDRAGGED) { temp.type = NX_MOUSEDRAGGED; // temp.location.x = last.location.x + [powerGlove gloveX]/4.0; // temp.location.y = last.location.y + [powerGlove gloveY]/4.0; temp.location.x = ([powerGlove gloveX] + 128.0) * (bounds.size.width / 255.0 ) + bounds.origin.x; temp.location.y = ([powerGlove gloveY] + 128.0) * (bounds.size.height / 255.0 ) + bounds.origin.y; tempLocationZ = - [powerGlove gloveZ] + 32; temp.location.x = MAX (temp.location.x, bounds.origin.x); temp.location.x = MIN (temp.location.x, NX_MAXX(&bounds)); temp.location.y = MAX (temp.location.y, bounds.origin.y); temp.location.y = MIN (temp.location.y, NX_MAXY(&bounds)); tempLocationZ = MAX (tempLocationZ, 0.0 ); tempLocationZ = MIN (tempLocationZ, 64.0 ); tempBrushColor = NXConvertGrayAlphaToColor( tempLocationZ / 64.0, 1.0); [brushColor setColor: tempBrushColor]; [self drawBrushImage:self]; }else { temp.type = NX_MOUSEDOWN; PScurrentmouse([window windowNum], &temp.location.x,&temp.location.y); [self convertPoint:&temp.location fromView:nil]; } } else if (last.type == NX_MOUSEDOWN || last.type == NX_MOUSEDRAGGED){ temp.type = NX_MOUSEUP; temp.location.x = last.location.x; temp.location.y = last.location.y; } else { temp.type = NX_NULLEVENT; } if (temp.type == NX_MOUSEDOWN) [self mouseDownAction:&temp.location]; else if (temp.type == NX_MOUSEUP) [self mouseUpAction:&temp.location]; else if (temp.type == NX_MOUSEDRAGGED) [self mouseDraggedAction:&temp.location]; last = temp; return self; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.