ftp.nice.ch/pub/next/developer/resources/palettesfor2.xx/JS.N.bs.tar.gz#/JoyStick/JoyStick.m

This is JoyStick.m in view mode; [Download] [Up]

#import <appkit/Application.h>
#import <dpsclient/psops.h>
#import <dpsclient/dpsclient.h>
#include <stdlib.h>
#include <stdio.h>

#import "JoyStick.h"

@implementation JoyStick

void JS_scroller(DPSTimedEntry teNumber, double now,id userData)
{
    NXPoint mouseLoc;

    [[userData window] getMouseLocation:&mouseLoc];
    [userData convertPoint:&mouseLoc fromView:nil];
    [userData setPos:(NXPoint)mouseLoc];

}

- (float)getYVal:sender
{
    return y*ymax;
}

- (float)getXVal:sender
{
    return x*xmax;
}

-setXMax:(float)val
{
xmax=2*val;
return self;
}
-setYMax:(float)val
{
ymax=2*val;
return self;
}

- (float)yMax
{
    return 0.5*ymax;
}
- (float)xMax
{
    return 0.5*xmax;
}

-setTrackTime:(float)val
    {
    tracktime=val;
    return self;
    }
-setFadeTime:(float)val
    {
    fadetime=val;
    return self;
    }
-(float)trackTime
    {
    return tracktime;
    }
-(float)fadeTime
    {
    return fadetime;
    }

- drawSelf:(const NXRect *)rects :(int)rectCount
{
    PSsetgray(NX_DKGRAY);
    PSrectfill(-0.55,-0.55,1.1,1.1);
    PSsetgray(NX_WHITE);
    PSsetlinewidth(0.02);
    PSmoveto(0,-1.1);
    PSlineto(0,1.1);
    PSmoveto(-1.1,0);
    PSlineto(1.1,0);
    PSstroke();
    PSsetgray(NX_BLACK);
    PSrectfill(x-0.05,y-0.05,0.1,0.1);
        
    return self;
}

- initFrame:(const NXRect *)frameRect
    {    
    [super initFrame:frameRect];
    
    [self setDrawSize:(NXCoord)1.1:(NXCoord)1.1];
    [self setDrawOrigin:-(float)0.55 :-(float)0.55];

    timer = (DPSTimedEntry)-1;
    tracktime=0.1;
    fadetime=0.7;
    track=NO;
    x=y=0;
    xmax=1;
    ymax=1;
    
    return self;
    }

-sizeTo:(NXCoord)width:(NXCoord)height
{
[super sizeTo:width :height];
[self setDrawSize:(NXCoord)1.1:(NXCoord)1.1];
[self setDrawOrigin:-(float)0.55 :-(float)0.55];
return self;
}

-free
{
if(timer !=  (DPSTimedEntry)-1)
	DPSRemoveTimedEntry(timer);
[super free];
return self;
}
- setPos:(NXPoint)mouseLoc
{
if(track==YES)
    {
    x=	mouseLoc.x<0.5	? mouseLoc.x 	:0.5 ;
    x=	x>-0.5			? x 				:-0.5;
    y=	mouseLoc.y<0.5	? mouseLoc.y 	: 0.5 ;
    y=	y>-0.5			? y 				:-0.5;
    }
else
    {
    x *=fadetime;
    y *=fadetime;
    if (x*x<0.0001 && y*y<0.0001 && timer != (DPSTimedEntry)-1)
	{
	DPSRemoveTimedEntry(timer);
	timer=(DPSTimedEntry) -1;
	x=y=0;
	}
    }
    [self display];
    return self;
}


- (BOOL)acceptsFirstMouse
{
    return YES;
}

- mouseDown:(NXEvent *)theEvent
{
    track=YES;
    if(timer== (DPSTimedEntry)-1)
	timer=DPSAddTimedEntry(tracktime, (DPSTimedEntryProc)JS_scroller, (void *)self, NX_BASETHRESHOLD);
    return(self);
}

- mouseUp:(NXEvent *)theEvent
{
    track=NO;
    return(self);
}

-write:(NXTypedStream *)stream
    {
    [super write:stream];
    NXWriteTypes(stream,"ffff",&xmax,&ymax,&tracktime,&fadetime);
    return self;
    }
    
-read:(NXTypedStream *)stream
    {
    [super read:stream];
    NXReadTypes(stream,"ffff",&xmax,&ymax,&tracktime,&fadetime);
    x=y=0;
    timer= (DPSTimedEntry)-1;
    track=NO;
    return self;
    }
    
- (const char*) inspectorName
    {
    return "JoyStickInspector";
    }

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.