From d71e580abeabfdf4b8c7d97f02cd22bff7a78e3c Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Wed, 18 Apr 2012 14:45:31 +0200 Subject: [PATCH] Basic button press now works --- ogl_editor/src/RocketGui.c | 5 ++ ogl_editor/src/macosx/RocketView.m | 97 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 99 insertions(+), 3 deletions(-) diff --git a/ogl_editor/src/RocketGui.c b/ogl_editor/src/RocketGui.c index f75c851..1f99752 100644 --- a/ogl_editor/src/RocketGui.c +++ b/ogl_editor/src/RocketGui.c @@ -89,14 +89,19 @@ struct LoadedImages static bool RocketGui_regionHit(const RocketControlInfo* control) { + printf("mouse %d %d\n", g_rocketGuiState.mousex, g_rocketGuiState.mousey); + printf("control %d %d %d %d\n", control->x, control->y, control->width, control->height); + if (g_rocketGuiState.mousex < control->x || g_rocketGuiState.mousey < control->y || g_rocketGuiState.mousex >= control->x + control->width || g_rocketGuiState.mousey >= control->y + control->height) { + printf("false\n"); return false; } + printf("true\n"); return true; } diff --git a/ogl_editor/src/macosx/RocketView.m b/ogl_editor/src/macosx/RocketView.m index a29fabd..76cca8c 100644 --- a/ogl_editor/src/macosx/RocketView.m +++ b/ogl_editor/src/macosx/RocketView.m @@ -2,9 +2,11 @@ #import "RocketView.h" #include "../GFXBackend.h" +#include "../RocketGui.h" extern void Editor_init(); extern void Editor_guiUpdate(); +extern RocketGuiState g_rocketGuiState; @implementation RocketView @@ -88,12 +90,101 @@ extern void Editor_guiUpdate(); return YES; } -- (void)mouseDown:(NSEvent *)theEvent +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +-(void) viewWillMoveToWindow:(NSWindow *)newWindow { - printf("mouseDown\n"); - [[self nextResponder] mouseDown:theEvent]; + // Setup a new tracking area when the view is added to the window. + NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:[self frame] + options: (NSTrackingMouseMoved | NSTrackingActiveAlways) owner:self userInfo:nil]; + [self addTrackingArea:trackingArea]; } +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +- (void)mouseMoved:(NSEvent *)event +{ + NSWindow* window = [self window]; + //NSPoint originalMouseLocation = [window convertBaseToScreen:[event locationInWindow]]; + NSRect originalFrame = [window frame]; + NSPoint location = [window mouseLocationOutsideOfEventStream]; + + g_rocketGuiState.mousex = (int)location.x; + g_rocketGuiState.mousey = (int)originalFrame.size.height - (int)location.y - 23; + + printf("mouseMoved %d %d\n", g_rocketGuiState.mousex, g_rocketGuiState.mousey); + + Editor_guiUpdate(); +} + +static NSPoint s_prevDragPos; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +- (void)mouseDragged:(NSEvent *)event +{ + NSWindow* window = [self window]; + NSRect originalFrame = [window frame]; + NSPoint location = [window mouseLocationOutsideOfEventStream]; + g_rocketGuiState.mousex = (int)location.x; + g_rocketGuiState.mousey = (int)originalFrame.size.height - (int)location.y; + + if (g_rocketGuiState.activeItem != -1) + { + Editor_guiUpdate(); + return; + } + + NSPoint newMouseLocation = [window convertBaseToScreen:[event locationInWindow]]; + NSPoint delta = NSMakePoint(newMouseLocation.x - s_prevDragPos.x, + newMouseLocation.y - s_prevDragPos.y); + + NSRect newFrame = originalFrame; + + newFrame.origin.x += delta.x; + newFrame.origin.y += delta.y; + + s_prevDragPos = newMouseLocation; + + printf("mouseDragged\n"); + + [window setFrame:newFrame display:YES animate:NO]; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +- (void)mouseUp:(NSEvent *)event +{ + g_rocketGuiState.mouseDown = 0; + printf("mouseUp\n"); + Editor_guiUpdate(); +} + +// +// mouseDown: +// +// Handles mouse clicks in our frame. Two actions: +// - click in the resize box should resize the window +// - click anywhere else will drag the window. +// + +- (void)mouseDown:(NSEvent *)event +{ + NSWindow *window = [self window]; + s_prevDragPos = [window convertBaseToScreen:[event locationInWindow]]; + NSRect originalFrame = [window frame]; + NSPoint location = [window mouseLocationOutsideOfEventStream]; + + g_rocketGuiState.mousex = (int)location.x; + g_rocketGuiState.mousey = (int)originalFrame.size.height - (int)location.y - 23; + + g_rocketGuiState.mouseDown = 1; + printf("mouseDown\n"); + + Editor_guiUpdate(); +} + + -(BOOL) isOpaque { return YES;