
/* Generated by Interface Builder */

#import "chaosControl.h"
#import "chaosView.h"
#import "Colormap.h"
#import "chaosStorage.h"
#import <appkit/Cell.h>			/* for floatValue, etc */
#import <appkit/Matrix.h>		/* for selectedCell */

@implementation chaosControl

- headhome :sender
{
	float newX, newY, newDX, newDY;	// New center and width/height
	int newDepth;
	
	[chaosViewInstance gohome: &newX: &newY: &newDX: &newDY: &newDepth];
	[selectedXCenter setFloatValue:newX];
	[selectedYCenter setFloatValue:newY];
	[selectedXScale setFloatValue:newDX];
	[selectedYScale setFloatValue:newDY];
	[selectedDepth setFloatValue:newDepth];
  return self;
}

- appDidInit :sender
{
	float newX, newY, newDX, newDY;	// New center and width/height
	int newDepth;
	
	[chaosMenuSelector chaosLoad:self];
	[chaosViewInstance gohome: &newX: &newY: &newDX: &newDY: &newDepth];
	[selectedXCenter setFloatValue:newX];
	[selectedYCenter setFloatValue:newY];
	[selectedXScale setFloatValue:newDX];
	[selectedYScale setFloatValue:newDY];
	[selectedDepth setFloatValue:newDepth];
	[currentXCenter setFloatValue:newX];
	[currentYCenter setFloatValue:newY];
	[currentXScale setFloatValue:newDX];
	[currentYScale setFloatValue:newDY];
	[currentDepth setFloatValue:newDepth];
	[myColormap setup:self];
	[self colorZebra:self];
	[viewWindow setContentView: chaosViewInstance];
  return self;
}

- colorStorms:sender
{ return [myColormap setColors :3 :.5 :.4 :5 :.5 :.4 :1 :.87 :.87]; }
- colorZebra:sender
{ return [myColormap setColors :5 :.5 :.5 :5 :.5 :.5 :5 :.5 :.5]; }
- colorOasis:sender
/* Courtesy of Jay Capela: great designer, great haircut */
{ return [myColormap setColors :.66 :.854 :.46 :2.1 :.336 :.8 :2.0 :.576 :.5]; }
- colorArctic:sender
{ return [myColormap setColors :.5 :0 :.88 :1.5 :0 :.5 :.5 :0 :.1]; }
- colorGothic:sender
{ return [myColormap setColors :3 :.5 :.73 :3 :.74 :.87 :1.1 :.33 :.54]; }
- colorDeco:sender
{ return [myColormap setColors :1 :.5 :.46 :5 :.5 :.8 :3 :.5 :.5]; }

- upleft:sender
{
	[chaosViewInstance scrollup];
	[chaosViewInstance scrollleft];
    return self;
}

- up:sender
{
	[chaosViewInstance scrollup];
    return self;
}

- upright:sender
{
	[chaosViewInstance scrollup];
	[chaosViewInstance scrollright];
    return self;
}

- right:sender
{
	[chaosViewInstance scrollright];
    return self;
}

- downright:sender
{
	[chaosViewInstance scrolldown];
	[chaosViewInstance scrollright];
    return self;
}

- down:sender
{
	[chaosViewInstance scrolldown];
    return self;
}

- downleft:sender
{
	[chaosViewInstance scrolldown];
	[chaosViewInstance scrollleft];
    return self;
}

- left:sender
{
	[chaosViewInstance scrollleft];
    return self;
}

- changeSelectedRect:sender
{
    return self;
}

- feedPoints:sender
{
    return self;
}

- look:sender
{
	[chaosViewInstance examinSelected:[selectedXCenter floatValue]:
			  [selectedYCenter floatValue]:
			  [selectedXScale floatValue]:
			  [selectedYScale floatValue]:
			  [selectedDepth intValue]];
    return self;
}

- zoom:sender
{
	[currentXCenter setFloatValue:[selectedXCenter floatValue]];
	[currentYCenter setFloatValue:[selectedYCenter floatValue]];
	[currentXScale  setFloatValue:[selectedXScale floatValue]];
	[currentYScale  setFloatValue:[selectedYScale floatValue]];
	[currentDepth  setIntValue:[selectedDepth intValue]];
	[self runstop:sender];	// This may just stop it...so
	if (!windowEvent)	// If it's stopped run it again.
		[self runstop:sender];
    return self;
}

- stopfeedPoints:sender
{
    return self;
}

- selectedTextDidChange:sender
{
    return self;
}

void dolines(DPSTimedEntry windowEventber, double now, void *theObject)
{
	[(id)theObject drawline];
}

- runstop:sender
{
if (windowEvent)
	{
	[runButton setTitle:"RUN"];
	DPSRemoveTimedEntry (windowEvent);
	windowEvent=0;
	}
else
	{
	[runButton setTitle:"STOP"];
	[chaosViewInstance startM:[currentXCenter floatValue]:
			  [currentYCenter floatValue]:
			  [currentXScale floatValue]:
			  [currentYScale floatValue]:
			  [currentDepth intValue]];
	windowEvent = DPSAddTimedEntry(0.0, &dolines, chaosViewInstance, 1 /*30*/);
	}
    return self;
}

- selectChaos: sender
{
	id newChaosClass;
	NXRect theRect;
	[chaosViewInstance getFrame:&theRect];
	if (windowEvent)
		[self runstop:self];
	newChaosClass = [chaosMenuSelector accessViewList:self];
	chaosViewInstance = [[newChaosClass alloc/*FromZone:[chaosViewInstance zone]*/] init];
	newChaosClass = [viewWindow setContentView: chaosViewInstance];
	[newChaosClass free];
	[myColormap getnewChaosView:chaosViewInstance];
	[chaosViewInstance getController: self: myColormap];
		{
		float newX, newY, newDX, newDY;	// New center and width/height
		int newDepth;
	
		[chaosViewInstance gohome: &newX: &newY: &newDX: &newDY: &newDepth];
		[selectedXCenter setFloatValue:newX];
		[selectedYCenter setFloatValue:newY];
		[selectedXScale setFloatValue:newDX];
		[selectedYScale setFloatValue:newDY];
		[selectedDepth setFloatValue:newDepth];
		[currentXCenter setFloatValue:newX];
		[currentYCenter setFloatValue:newY];
		[currentXScale setFloatValue:newDX];
		[currentYScale setFloatValue:newDY];
		[currentDepth setFloatValue:newDepth];
		}
	return self;
}

- setParameters:(float) selX:(float) selY:(float) widthX:(float) heightY
{
	[selectedXCenter setFloatValue:selX];
	[selectedYCenter setFloatValue:selY];
	[selectedXScale setFloatValue:widthX];
	[selectedYScale setFloatValue:heightY];
	[chaosControlWindow makeKeyAndOrderFront:self]; 
	return self;
}

@end
