Basic button press now works
This commit is contained in:
parent
c33f759c26
commit
d71e580abe
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user