2010-09-11 23:43:55 +00:00
|
|
|
#include "QF/sys.h"
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
#include "ZView.h"
|
|
|
|
#include "ZScrollView.h"
|
|
|
|
#include "QuakeEd.h"
|
|
|
|
#include "Map.h"
|
|
|
|
#include "XYView.h"
|
|
|
|
#include "CameraView.h"
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
id zview_i;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
id zscrollview_i, zscalemenu_i, zscalebutton_i;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
float zplane;
|
|
|
|
float zplanedir;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
extern NSBezierPath *path;
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
@implementation ZView
|
2003-03-18 19:48:24 +00:00
|
|
|
/*
|
|
|
|
==================
|
|
|
|
initWithFrame:
|
|
|
|
==================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
- (id) initWithFrame:(NSRect) frameRect
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
NSPoint pt;
|
2010-09-24 11:44:07 +00:00
|
|
|
NSBezierPath *path;
|
|
|
|
|
|
|
|
path = checker = [NSBezierPath new];
|
|
|
|
[path setLineWidth: 0.3];
|
|
|
|
[path moveToPoint: NSMakePoint (-16, -16)];
|
|
|
|
[path relativeLineToPoint: NSMakePoint (32, 32)];
|
|
|
|
[path moveToPoint: NSMakePoint (-16, 16)];
|
|
|
|
[path relativeLineToPoint: NSMakePoint (32, -32)];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
origin[0] = 0.333;
|
|
|
|
origin[1] = 0.333;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[super initWithFrame:frameRect];
|
|
|
|
[self allocateGState];
|
|
|
|
[self clearBounds];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
zview_i = self;
|
|
|
|
scale = 1;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
//
|
2003-03-18 19:48:24 +00:00
|
|
|
// initialize the pop up menus
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
zscalebutton_i =[[NSPopUpButton alloc] init];
|
|
|
|
[zscalebutton_i setTarget:self];
|
|
|
|
[zscalebutton_i setAction: @selector (scaleMenuTarget:)];
|
|
|
|
|
|
|
|
[zscalebutton_i addItemWithTitle:@"12.5%"];
|
|
|
|
[zscalebutton_i addItemWithTitle:@"25%"];
|
|
|
|
[zscalebutton_i addItemWithTitle:@"50%"];
|
|
|
|
[zscalebutton_i addItemWithTitle:@"75%"];
|
|
|
|
[zscalebutton_i addItemWithTitle:@"100%"];
|
|
|
|
[zscalebutton_i addItemWithTitle:@"200%"];
|
|
|
|
[zscalebutton_i addItemWithTitle:@"300%"];
|
|
|
|
[zscalebutton_i selectItemAtIndex:4];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
// initialize the scroll view
|
2010-09-19 18:06:35 +00:00
|
|
|
zscrollview_i =[[ZScrollView alloc] initWithFrame: frameRect
|
|
|
|
button1: zscalebutton_i];
|
2010-09-11 10:03:41 +00:00
|
|
|
[zscrollview_i setAutoresizingMask:NSViewWidthSizable |
|
2010-09-19 18:06:35 +00:00
|
|
|
NSViewHeightSizable];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
[zscrollview_i setDocumentView:self];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-22 13:18:13 +00:00
|
|
|
[_super_view setBoundsOrigin: NSMakePoint (0, 0)];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
minheight = 0;
|
|
|
|
maxheight = 64;
|
|
|
|
|
2010-09-22 13:18:13 +00:00
|
|
|
pt.x = -[_super_view bounds].size.width / 2;
|
2003-03-18 19:48:24 +00:00
|
|
|
pt.y = -128;
|
|
|
|
|
|
|
|
[self newRealBounds];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-19 18:06:35 +00:00
|
|
|
[self setOrigin: pt scale:1];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return zscrollview_i;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-setXYOrigin:(NSPoint *) pt
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
origin[0] = pt->x + 0.333;
|
|
|
|
origin[1] = pt->y + 0.333;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-(float) currentScale
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
return scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
setOrigin:scale:
|
|
|
|
===================
|
|
|
|
*/
|
2010-09-19 18:06:35 +00:00
|
|
|
-setOrigin:(NSPoint) pt scale:(float) sc
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
NSRect sframe;
|
2010-09-22 13:18:13 +00:00
|
|
|
NSRect bounds;
|
|
|
|
NSRect size;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-22 13:18:13 +00:00
|
|
|
// calculate the area visible in the cliprect
|
2003-03-18 19:48:24 +00:00
|
|
|
scale = sc;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-22 13:18:13 +00:00
|
|
|
bounds =[_super_view bounds];
|
|
|
|
bounds.origin = pt;
|
|
|
|
bounds.size.width /= 1;
|
|
|
|
bounds.size.height /= scale;
|
|
|
|
|
|
|
|
size = NSMakeRect (0, oldminheight, 1, oldmaxheight - oldminheight);
|
|
|
|
// union with the realbounds
|
|
|
|
bounds = NSUnionRect (size, bounds);
|
|
|
|
// redisplay everything
|
|
|
|
bounds.origin = NSMakePoint (-bounds.size.width/2, bounds.origin.y);
|
|
|
|
sframe = bounds;
|
|
|
|
sframe.origin.x *= 1;
|
|
|
|
sframe.origin.y *= scale;
|
|
|
|
sframe.size.width *= 1;
|
|
|
|
sframe.size.height *= scale;
|
|
|
|
|
|
|
|
// size this view
|
2010-09-24 14:17:25 +00:00
|
|
|
[quakeed_i disableFlushWindow];
|
2010-09-22 13:18:13 +00:00
|
|
|
[self setFrame:sframe bounds:bounds scale:NSMakeSize (1, scale)];
|
|
|
|
|
|
|
|
// scroll and scale the clip view
|
|
|
|
pt.x *= 1;
|
|
|
|
pt.y *= scale;
|
|
|
|
[_super_view setBoundsOrigin: pt];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-24 14:17:25 +00:00
|
|
|
[quakeed_i enableFlushWindow];
|
2003-03-18 19:48:24 +00:00
|
|
|
[zscrollview_i display];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
scaleMenuTarget:
|
|
|
|
|
|
|
|
Called when the scaler popup on the window is used
|
|
|
|
====================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-scaleMenuTarget:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
char const *item;
|
2010-09-22 13:18:13 +00:00
|
|
|
NSRect rect;
|
|
|
|
NSPoint mid, org, orig;
|
2010-09-11 10:03:41 +00:00
|
|
|
float nscale;
|
|
|
|
|
|
|
|
item =[[sender titleOfSelectedItem] cString];
|
|
|
|
sscanf (item, "%f", &nscale);
|
2003-03-18 19:48:24 +00:00
|
|
|
nscale /= 100;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
if (nscale == scale)
|
|
|
|
return NULL;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
// keep the center of the view constant
|
2010-09-22 13:18:13 +00:00
|
|
|
rect =[_super_view bounds];
|
|
|
|
mid.x = rect.size.width / 2;
|
|
|
|
mid.y = rect.size.height / 2;
|
|
|
|
|
|
|
|
org.x = (rect.origin.x + mid.x) / 1;
|
|
|
|
org.y = (rect.origin.y + mid.y) / scale;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-22 13:18:13 +00:00
|
|
|
orig.x = org.x - mid.x / 1;
|
|
|
|
orig.y = org.y - mid.y / nscale;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-22 13:18:13 +00:00
|
|
|
[self setOrigin: orig scale:nscale];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-clearBounds
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
topbound = 999999;
|
|
|
|
bottombound = -999999;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-getBounds: (float *) top:(float *) bottom;
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
*top = topbound;
|
|
|
|
*bottom = bottombound;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
addToHeightRange:
|
|
|
|
==================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-addToHeightRange:(float) height
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
if (height < minheight)
|
|
|
|
minheight = height;
|
|
|
|
if (height > maxheight)
|
|
|
|
maxheight = height;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
newSuperBounds
|
|
|
|
|
|
|
|
When _super_view is resized
|
|
|
|
==================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-newSuperBounds
|
|
|
|
{
|
2003-03-18 19:48:24 +00:00
|
|
|
oldminheight++;
|
|
|
|
[self newRealBounds];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
newRealBounds
|
|
|
|
|
|
|
|
Should only change the scroll bars, not cause any redraws.
|
|
|
|
If realbounds has shrunk, nothing will change.
|
|
|
|
===================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-newRealBounds
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-22 13:18:13 +00:00
|
|
|
NSRect bounds;
|
|
|
|
NSRect sframe;
|
|
|
|
NSRect size;
|
|
|
|
|
2010-09-19 18:06:35 +00:00
|
|
|
NSClipView *cv = (NSClipView *) _super_view;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
if (minheight == oldminheight && maxheight == oldmaxheight)
|
|
|
|
return self;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
oldminheight = minheight;
|
|
|
|
oldmaxheight = maxheight;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
minheight -= 16;
|
|
|
|
maxheight += 16;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-22 13:18:13 +00:00
|
|
|
// calculate the area visible in the cliprect
|
|
|
|
bounds =[cv bounds];
|
|
|
|
bounds.size.width /= 1;
|
|
|
|
bounds.size.height /= scale;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-22 13:18:13 +00:00
|
|
|
size = NSMakeRect (0, minheight, 1, maxheight - minheight);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-22 13:18:13 +00:00
|
|
|
bounds = NSUnionRect (size, bounds);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-22 13:18:13 +00:00
|
|
|
sframe = bounds;
|
|
|
|
sframe.size.width *= 1;
|
|
|
|
sframe.size.height *= scale;
|
|
|
|
|
|
|
|
// size this view
|
2010-09-24 14:17:25 +00:00
|
|
|
[quakeed_i disableFlushWindow];
|
2010-09-22 13:18:13 +00:00
|
|
|
[self setFrame:sframe bounds:bounds scale:NSMakeSize (1, scale)];
|
|
|
|
|
|
|
|
[[_super_view superview] reflectScrolledClipView: cv];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-24 14:17:25 +00:00
|
|
|
[quakeed_i enableFlushWindow];
|
2010-09-19 18:06:35 +00:00
|
|
|
[[zscrollview_i verticalScroller] display];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
drawGrid
|
|
|
|
|
|
|
|
Draws tile markings every 64 units, and grid markings at the grid scale if
|
|
|
|
the grid lines are >= 4 pixels apart
|
|
|
|
|
|
|
|
Rect is in global world (unscaled) coordinates
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
|
2010-09-12 05:31:59 +00:00
|
|
|
-drawGrid:(NSRect) rect
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int y, stopy;
|
|
|
|
float top, bottom;
|
|
|
|
int left, right;
|
|
|
|
int gridsize;
|
|
|
|
BOOL showcoords;
|
2010-09-24 11:44:07 +00:00
|
|
|
NSMutableDictionary *attribs = [NSMutableDictionary dictionary];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
showcoords =[quakeed_i showCoordinates];
|
|
|
|
|
|
|
|
gridsize =[xyview_i gridsize];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
left = _bounds.origin.x;
|
|
|
|
right = 24;
|
2010-09-12 05:31:59 +00:00
|
|
|
bottom = rect.origin.y - 1;
|
|
|
|
top = rect.origin.y + rect.size.height + 2;
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
|
|
|
// grid
|
|
|
|
//
|
|
|
|
// can't just divide by grid size because of negetive coordinate
|
|
|
|
// truncating direction
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
if (gridsize >= 4 / scale) {
|
|
|
|
y = floor (bottom / gridsize);
|
|
|
|
stopy = floor (top / gridsize);
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
y *= gridsize;
|
|
|
|
stopy *= gridsize;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (y < bottom)
|
|
|
|
y += gridsize;
|
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
[path removeAllPoints];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
for (; y <= stopy; y += gridsize)
|
|
|
|
if (y & 31) {
|
|
|
|
[path moveToPoint:NSMakePoint (left, y)];
|
|
|
|
[path lineToPoint:NSMakePoint (right, y)];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
// endUserPath (upath, dps_ustroke);
|
2010-09-24 11:44:07 +00:00
|
|
|
[[NSColor colorWithCalibratedRed: 0.8 green: 0.8 blue: 1.0 alpha: 1.0]
|
|
|
|
set]; // thin grid color
|
2010-09-09 11:46:38 +00:00
|
|
|
[path stroke];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// half tiles
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
y = floor (bottom / 32);
|
|
|
|
stopy = floor (top / 32);
|
|
|
|
|
|
|
|
if (!(((int) y + 4096) & 1))
|
2003-03-18 19:48:24 +00:00
|
|
|
y++;
|
|
|
|
y *= 32;
|
|
|
|
stopy *= 32;
|
|
|
|
if (stopy >= top)
|
|
|
|
stopy -= 32;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
[path removeAllPoints];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
for (; y <= stopy; y += 64) {
|
|
|
|
[path moveToPoint:NSMakePoint (left, y)];
|
|
|
|
[path lineToPoint:NSMakePoint (right, y)];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
// endUserPath (upath, dps_ustroke);
|
2010-09-24 11:44:07 +00:00
|
|
|
[[NSColor colorWithCalibratedWhite: 12.0 / 16.0 alpha: 1.0]
|
|
|
|
set];
|
2010-09-09 11:46:38 +00:00
|
|
|
[path stroke];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// tiles
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
y = floor (bottom / 64);
|
|
|
|
stopy = floor (top / 64);
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
y *= 64;
|
|
|
|
stopy *= 64;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (y < bottom)
|
|
|
|
y += 64;
|
2003-03-18 19:48:24 +00:00
|
|
|
if (stopy >= top)
|
|
|
|
stopy -= 64;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
[path removeAllPoints];
|
2010-09-24 11:44:07 +00:00
|
|
|
[[NSColor colorWithCalibratedWhite: 0.0 / 16.0 alpha: 1.0]
|
|
|
|
set]; // for text
|
2010-09-23 08:29:52 +00:00
|
|
|
[[NSFont systemFontOfSize: 10] set];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
for (; y <= stopy; y += 64) {
|
|
|
|
if (showcoords) {
|
2010-09-24 11:44:07 +00:00
|
|
|
NSString *s = [NSString stringWithFormat: @"%i", y];
|
|
|
|
[s drawAtPoint: NSMakePoint (left, y) withAttributes: attribs];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
[path moveToPoint:NSMakePoint (left + 24, y)];
|
|
|
|
[path lineToPoint:NSMakePoint (right, y)];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// divider
|
2010-09-11 10:03:41 +00:00
|
|
|
[path moveToPoint:NSMakePoint (0, _bounds.origin.y)];
|
|
|
|
[path lineToPoint:NSMakePoint (0,
|
|
|
|
_bounds.origin.y + _bounds.size.height)];
|
|
|
|
|
|
|
|
// endUserPath (upath, dps_ustroke);
|
2010-09-24 11:44:07 +00:00
|
|
|
[[NSColor colorWithCalibratedWhite: 10.0 / 16.0 alpha: 1.0]
|
|
|
|
set];
|
2010-09-09 11:46:38 +00:00
|
|
|
[path stroke];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// origin
|
|
|
|
//
|
2010-09-24 11:44:07 +00:00
|
|
|
[[NSColor colorWithCalibratedWhite: 4.0 / 16.0 alpha: 1.0]
|
|
|
|
set];
|
|
|
|
[path removeAllPoints];
|
|
|
|
[path setLineWidth: 5];
|
|
|
|
[path moveToPoint: NSMakePoint (right, 0)];
|
|
|
|
[path lineToPoint: NSMakePoint (left, 0)];
|
|
|
|
[path stroke];
|
|
|
|
[path setLineWidth: 1];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-drawZplane
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-24 11:44:07 +00:00
|
|
|
[[NSColor colorWithCalibratedRed: 0.2 green: 0.2 blue: 0.0 alpha: 1.0]
|
|
|
|
set];
|
|
|
|
[path appendBezierPathWithArcWithCenter: NSMakePoint (0, zplane)
|
|
|
|
radius: 4
|
|
|
|
startAngle: 0
|
|
|
|
endAngle: 180];
|
|
|
|
[path fill];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
drawSelf
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
2010-09-12 05:31:59 +00:00
|
|
|
-drawRect: (NSRect) rects
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-19 18:06:35 +00:00
|
|
|
//NSRect visRect;
|
|
|
|
//Sys_Printf("ZView:drawRect\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
minheight = 999999;
|
|
|
|
maxheight = -999999;
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
// allways draw the entire bar
|
2010-09-19 18:06:35 +00:00
|
|
|
//visRect =[self visibleRect];
|
2010-09-24 11:44:07 +00:00
|
|
|
rects = [self visibleRect];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
// erase window
|
2010-09-12 05:31:59 +00:00
|
|
|
NSEraseRect (rects);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
// draw grid
|
2010-09-12 05:31:59 +00:00
|
|
|
[self drawGrid:rects];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
// draw zplane
|
2010-09-24 11:44:07 +00:00
|
|
|
// [self drawZplane]; FIXME zplane doesn't do anything yet
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
// draw all entities
|
2010-09-11 10:03:41 +00:00
|
|
|
[map_i makeUnselectedPerform:@selector (ZDrawSelf)];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
// possibly resize the view
|
|
|
|
[self newRealBounds];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
XYDrawSelf
|
|
|
|
==============
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-XYDrawSelf
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-24 11:44:07 +00:00
|
|
|
NSBezierPath *path;
|
|
|
|
NSAffineTransform *trans;
|
|
|
|
|
|
|
|
[[NSColor colorWithCalibratedRed: 0 green: 0.5 blue: 1.0 alpha: 1.0] set];
|
|
|
|
|
|
|
|
trans = [NSAffineTransform transform];
|
|
|
|
[trans translateXBy: origin[0] yBy: origin[1]];
|
|
|
|
|
|
|
|
path = [checker copy];
|
|
|
|
[path transformUsingAffineTransform: trans];
|
|
|
|
[path stroke];
|
|
|
|
[path release];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
getPoint: (NSPoint *)pt
|
|
|
|
==============
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-getPoint:(NSPoint *) pt
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
pt->x = origin[0] + 0.333; // offset a bit to avoid edge cases
|
2003-03-18 19:48:24 +00:00
|
|
|
pt->y = origin[1] + 0.333;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-setPoint:(NSPoint *) pt
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
origin[0] = pt->x;
|
|
|
|
origin[1] = pt->y;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
MOUSE CLICKING
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
dragLoop:
|
|
|
|
================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
static NSPoint oldreletive;
|
|
|
|
|
|
|
|
-dragFrom: (NSEvent *) startevent useGrid: (BOOL) ug callback:(void (*)(float dy)) callback
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
NSEvent *event;
|
|
|
|
NSPoint startpt, newpt;
|
|
|
|
NSPoint reletive, delta;
|
|
|
|
int gridsize;
|
|
|
|
|
|
|
|
gridsize =[xyview_i gridsize];
|
|
|
|
|
|
|
|
startpt =[startevent locationInWindow];
|
|
|
|
startpt =[self convertPoint: startpt fromView:NULL];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
oldreletive.x = oldreletive.y = 0;
|
2010-09-09 11:46:38 +00:00
|
|
|
reletive.x = 0;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
while (1) {
|
2010-09-09 11:46:38 +00:00
|
|
|
unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask
|
2010-09-11 10:03:41 +00:00
|
|
|
| NSRightMouseUpMask | NSRightMouseDraggedMask
|
|
|
|
| NSApplicationDefinedMask;
|
|
|
|
event =[NSApp nextEventMatchingMask: eventMask untilDate:[NSDate
|
|
|
|
distantFuture]
|
|
|
|
inMode: NSEventTrackingRunLoopMode dequeue:YES];
|
|
|
|
|
|
|
|
if ([event type] == NSLeftMouseUp ||[event type] == NSRightMouseUp)
|
2003-03-18 19:48:24 +00:00
|
|
|
break;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
newpt =[event locationInWindow];
|
|
|
|
newpt =[self convertPoint: newpt fromView:NULL];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
reletive.y = newpt.y - startpt.y;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if (ug) { // we want truncate towards 0 behavior
|
|
|
|
// here
|
|
|
|
reletive.y = gridsize * (int) (reletive.y / gridsize);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (reletive.y == oldreletive.y)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
delta.y = reletive.y - oldreletive.y;
|
2010-09-11 10:03:41 +00:00
|
|
|
oldreletive = reletive;
|
|
|
|
callback (delta.y);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
void
|
|
|
|
ZDragCallback (float dy)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sb_translate[0] = 0;
|
|
|
|
sb_translate[1] = 0;
|
|
|
|
sb_translate[2] = dy;
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
[map_i makeSelectedPerform:@selector (translate)];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i redrawInstance];
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-selectionDragFrom:(NSEvent *) theEvent
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("dragging selection\n");
|
2010-09-11 10:03:41 +00:00
|
|
|
[self dragFrom: theEvent useGrid: YES callback:ZDragCallback];
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateCamera];
|
|
|
|
return self;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
void
|
|
|
|
ZScrollCallback (float dy)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
NSRect basebounds;
|
|
|
|
NSPoint neworg;
|
|
|
|
float scale;
|
|
|
|
|
|
|
|
basebounds =[[zview_i superview] bounds];
|
|
|
|
basebounds =[zview_i convertRect: basebounds fromView:[zview_i
|
|
|
|
superview]];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
neworg.y = basebounds.origin.y - dy;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
scale =[zview_i currentScale];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
oldreletive.y -= dy;
|
2010-09-19 18:06:35 +00:00
|
|
|
[zview_i setOrigin: neworg scale:scale];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-scrollDragFrom:(NSEvent *) theEvent
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("scrolling view\n");
|
2010-09-11 10:03:41 +00:00
|
|
|
[self dragFrom: theEvent useGrid: YES callback:ZScrollCallback];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
void
|
|
|
|
ZControlCallback (float dy)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numcontrolpoints; i++)
|
2003-03-18 19:48:24 +00:00
|
|
|
controlpoints[i][2] += dy;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
[[map_i selectedBrush] calcWindings];
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i redrawInstance];
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-(BOOL) planeDragFrom:(NSEvent *) theEvent
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
NSPoint pt;
|
|
|
|
vec3_t dragpoint;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
if ([map_i numSelected] != 1)
|
|
|
|
return NO;
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
pt =[theEvent locationInWindow];
|
|
|
|
pt =[self convertPoint: pt fromView:NULL];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
dragpoint[0] = origin[0];
|
|
|
|
dragpoint[1] = origin[1];
|
|
|
|
dragpoint[2] = pt.y;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
[[map_i selectedBrush] getZdragface:dragpoint];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (!numcontrolpoints)
|
|
|
|
return NO;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("dragging brush plane\n");
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
pt =[theEvent locationInWindow];
|
|
|
|
pt =[self convertPoint: pt fromView:NULL];
|
|
|
|
|
|
|
|
[self dragFrom: theEvent useGrid: YES callback:ZControlCallback];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[[map_i selectedBrush] removeIfInvalid];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateCamera];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
mouseDown
|
|
|
|
===================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-(void) mouseDown:(NSEvent *) theEvent
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
NSPoint pt;
|
|
|
|
int flags;
|
|
|
|
vec3_t p1;
|
|
|
|
|
|
|
|
pt =[theEvent locationInWindow];
|
|
|
|
pt =[self convertPoint: pt fromView:NULL];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
p1[0] = origin[0];
|
|
|
|
p1[1] = origin[1];
|
|
|
|
p1[2] = pt.y;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
flags =
|
|
|
|
[theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask |
|
|
|
|
NSAlternateKeyMask | NSCommandKeyMask);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// shift click to select / deselect a brush from the world
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
if (flags == NSShiftKeyMask) {
|
|
|
|
[map_i selectRay: p1: p1:NO];
|
2003-03-18 19:48:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// alt click = set entire brush texture
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
if (flags == NSAlternateKeyMask) {
|
|
|
|
[map_i setTextureRay: p1: p1:YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// control click = position view
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
if (flags == NSControlKeyMask) {
|
|
|
|
[cameraview_i setZOrigin:pt.y];
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-09 11:46:38 +00:00
|
|
|
[cameraview_i ZmouseDown: &pt flags:[theEvent modifierFlags]];
|
2003-03-18 19:48:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// bare click to drag icons or new brush drag
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
if (flags == 0) {
|
2003-03-18 19:48:24 +00:00
|
|
|
// check eye
|
2010-09-12 02:13:35 +00:00
|
|
|
if ([cameraview_i ZmouseDown: &pt flags:[theEvent modifierFlags]])
|
2003-03-18 19:48:24 +00:00
|
|
|
return;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if ([map_i numSelected]) {
|
|
|
|
if (pt.x > 0) {
|
|
|
|
if ([self planeDragFrom:theEvent])
|
2003-03-18 19:48:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
[self selectionDragFrom:theEvent];
|
2003-03-18 19:48:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-22 13:18:13 +00:00
|
|
|
Sys_Printf ("bad flags for click %x %g %g\n", flags, pt.x, pt.y);
|
2003-03-18 19:48:24 +00:00
|
|
|
NopSound ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
rightMouseDown
|
|
|
|
===================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-(void) rightMouseDown:(NSEvent *) theEvent
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
NSPoint pt;
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
pt =[theEvent locationInWindow];
|
|
|
|
pt =[self convertPoint: pt fromView:NULL];
|
|
|
|
|
|
|
|
flags =
|
|
|
|
[theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask |
|
|
|
|
NSAlternateKeyMask | NSCommandKeyMask);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// click = scroll view
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
if (flags == 0) {
|
|
|
|
[self scrollDragFrom:theEvent];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("bad flags for click\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
NopSound ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
XY mouse view methods
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
modalMoveLoop
|
|
|
|
================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-modalMoveLoop: (NSPoint *) basept: (vec3_t) movemod:converter
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
vec3_t originbase;
|
|
|
|
NSEvent *event;
|
|
|
|
NSPoint newpt;
|
|
|
|
vec3_t delta;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
VectorCopy (origin, originbase);
|
|
|
|
|
2010-09-26 13:45:26 +00:00
|
|
|
// modal event loop using instance drawing
|
2003-03-18 19:48:24 +00:00
|
|
|
goto drawentry;
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
while ([event type] != NSLeftMouseUp) {
|
2003-03-18 19:48:24 +00:00
|
|
|
// calculate new point
|
2010-09-11 10:03:41 +00:00
|
|
|
newpt =[event locationInWindow];
|
|
|
|
newpt =[converter convertPoint: newpt fromView:NULL];
|
|
|
|
|
|
|
|
delta[0] = newpt.x - basept->x;
|
|
|
|
delta[1] = newpt.y - basept->y;
|
|
|
|
delta[2] = delta[1]; // height change
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
origin[i] = originbase[i] + movemod[i] * delta[i];
|
|
|
|
|
|
|
|
|
2010-09-26 13:45:26 +00:00
|
|
|
drawentry:
|
2003-03-18 19:48:24 +00:00
|
|
|
// instance draw new frame
|
|
|
|
[quakeed_i newinstance];
|
|
|
|
[self display];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
event =[NSApp nextEventMatchingMask: eventMask untilDate:[NSDate
|
|
|
|
distantFuture]
|
|
|
|
inMode: NSEventTrackingRunLoopMode dequeue:YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-26 13:45:26 +00:00
|
|
|
// draw the brush back into the window buffer
|
|
|
|
// [xyview_i display];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
XYmouseDown
|
|
|
|
===============
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-(BOOL) XYmouseDown:(NSPoint *) pt
|
|
|
|
{
|
|
|
|
vec3_t movemod;
|
|
|
|
|
|
|
|
if (fabs (pt->x - origin[0]) > 16 || fabs (pt->y - origin[1]) > 16)
|
2003-03-18 19:48:24 +00:00
|
|
|
return NO;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
movemod[0] = 1;
|
|
|
|
movemod[1] = 1;
|
|
|
|
movemod[2] = 0;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
[self modalMoveLoop: pt: movemod:xyview_i];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|