2010-09-23 15:09:52 +00:00
|
|
|
#include "QF/sys.h"
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 08:35:25 +00:00
|
|
|
#include "KeypairView.h"
|
|
|
|
#include "TextureView.h"
|
|
|
|
#include "TexturePalette.h"
|
|
|
|
|
|
|
|
#include "Storage.h"
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
NOTE: I am specifically not using cached image reps, because the data is also needed for texturing the views, and a cached rep would waste tons of space.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@implementation TextureView
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) init
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
deselectIndex = -1;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) setParent: (id)from
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
parent_i = from;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (BOOL) acceptsFirstMouse
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) drawRect: (NSRect)rects
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i;
|
|
|
|
int max;
|
|
|
|
id list_i;
|
2010-09-29 20:09:11 +00:00
|
|
|
texpal_t *t;
|
2010-09-11 10:03:41 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
NSPoint p;
|
|
|
|
NSRect r;
|
|
|
|
int selected;
|
2010-09-29 20:09:11 +00:00
|
|
|
NSMutableDictionary *attribs = [NSMutableDictionary dictionary];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
selected = [parent_i getSelectedTexture];
|
|
|
|
list_i = [parent_i getList];
|
2010-09-14 13:17:35 +00:00
|
|
|
[[NSFont systemFontOfSize: FONTSIZE] set];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-23 15:09:52 +00:00
|
|
|
[[NSColor lightGrayColor] set];
|
|
|
|
NSRectFill (rects);
|
2010-09-24 11:46:06 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
if (!list_i) // WADfile didn't init
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (deselectIndex != -1) {
|
2010-09-29 20:09:11 +00:00
|
|
|
t = [list_i elementAt: deselectIndex];
|
2003-03-18 19:48:24 +00:00
|
|
|
r = t->r;
|
|
|
|
r.origin.x -= TEX_INDENT;
|
|
|
|
r.origin.y -= TEX_INDENT;
|
2010-09-11 10:03:41 +00:00
|
|
|
r.size.width += TEX_INDENT * 2;
|
|
|
|
r.size.height += TEX_INDENT * 2;
|
|
|
|
|
2010-09-23 15:09:52 +00:00
|
|
|
[[NSColor lightGrayColor] set];
|
|
|
|
NSRectFill (r);
|
2003-03-18 19:48:24 +00:00
|
|
|
p = t->r.origin;
|
|
|
|
p.y += TEX_SPACING;
|
2010-09-23 15:09:52 +00:00
|
|
|
[t->image drawAtPoint: p];
|
|
|
|
[[NSColor blackColor] set];
|
2003-03-18 19:48:24 +00:00
|
|
|
x = t->r.origin.x;
|
|
|
|
y = t->r.origin.y + 7;
|
2010-09-23 15:09:52 +00:00
|
|
|
[[NSString stringWithCString: t->name]
|
2010-09-29 20:09:11 +00:00
|
|
|
drawAtPoint: NSMakePoint (x, y) withAttributes: attribs];
|
2003-03-18 19:48:24 +00:00
|
|
|
deselectIndex = -1;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
max = [list_i count];
|
2010-09-23 15:09:52 +00:00
|
|
|
[[NSColor blackColor] set];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < max; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
t = [list_i elementAt: i];
|
2003-03-18 19:48:24 +00:00
|
|
|
r = t->r;
|
2010-09-11 10:03:41 +00:00
|
|
|
r.origin.x -= TEX_INDENT / 2;
|
2003-03-18 19:48:24 +00:00
|
|
|
r.size.width += TEX_INDENT;
|
|
|
|
r.origin.y += 4;
|
2010-09-19 08:28:28 +00:00
|
|
|
if (NSIntersectsRect (rects, r) == YES && t->display) {
|
2010-09-11 10:03:41 +00:00
|
|
|
if (selected == i) {
|
2010-09-23 15:09:52 +00:00
|
|
|
[[NSColor whiteColor] set];
|
|
|
|
NSRectFill (r);
|
|
|
|
[[NSColor redColor] set];
|
2010-09-29 20:09:11 +00:00
|
|
|
NSFrameRect (r);
|
2010-09-23 15:09:52 +00:00
|
|
|
[[NSColor blackColor] set];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
p = t->r.origin;
|
|
|
|
p.y += TEX_SPACING;
|
2010-09-23 15:09:52 +00:00
|
|
|
[t->image drawAtPoint: p];
|
2003-03-18 19:48:24 +00:00
|
|
|
x = t->r.origin.x;
|
|
|
|
y = t->r.origin.y + 7;
|
2010-09-23 15:09:52 +00:00
|
|
|
[[NSString stringWithCString: t->name]
|
2010-09-29 20:09:11 +00:00
|
|
|
drawAtPoint: NSMakePoint (x, y) withAttributes: attribs];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) deselect
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
deselectIndex = [parent_i getSelectedTexture];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) mouseDown: (NSEvent *)theEvent
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
NSPoint loc;
|
|
|
|
int i;
|
|
|
|
int max;
|
|
|
|
|
|
|
|
// int oldwindowmask;
|
2010-09-29 20:09:11 +00:00
|
|
|
texpal_t *t;
|
2010-09-11 10:03:41 +00:00
|
|
|
id list;
|
|
|
|
NSRect r;
|
|
|
|
|
|
|
|
// oldwindowmask = [window addToEventMask:NSLeftMouseDraggedMask];
|
2010-09-29 20:09:11 +00:00
|
|
|
loc = [theEvent locationInWindow];
|
2010-10-10 08:07:48 +00:00
|
|
|
loc = [self convertPoint: loc fromView: NULL];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
list = [parent_i getList];
|
|
|
|
max = [list count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < max; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
t = [list elementAt: i];
|
2003-03-18 19:48:24 +00:00
|
|
|
r = t->r;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (NSPointInRect (loc, r) == YES) {
|
|
|
|
[self deselect];
|
2010-09-29 20:09:11 +00:00
|
|
|
[parent_i setSelectedTexture: i];
|
2003-03-18 19:48:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
// [window setEventMask:oldwindowmask];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|