From ee3648293706ce512277532951fa015ecfc0ee3e Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Fri, 8 Jun 2012 19:59:07 +0100 Subject: Set the cursor when dragging would resize bounding box This makes it obvious to users when clicking will resize the bounding box, rather than creating a new one. --- tikzit/src/gtk/GraphInputHandler.h | 2 +- tikzit/src/gtk/GraphInputHandler.m | 70 +++++++++++++++++++++++++++++--------- tikzit/src/gtk/Surface.h | 14 ++++++++ tikzit/src/gtk/WidgetSurface.m | 48 ++++++++++++++++++++++---- 4 files changed, 111 insertions(+), 23 deletions(-) diff --git a/tikzit/src/gtk/GraphInputHandler.h b/tikzit/src/gtk/GraphInputHandler.h index 61af36f..9955459 100644 --- a/tikzit/src/gtk/GraphInputHandler.h +++ b/tikzit/src/gtk/GraphInputHandler.h @@ -50,7 +50,7 @@ typedef enum { NSPoint oldLeaderPos; Edge *modifyEdge; NSMutableSet *selectionBoxContents; - ResizeHandle grabbedResizeHandle; + ResizeHandle currentResizeHandle; NSPoint oldOrigin; } diff --git a/tikzit/src/gtk/GraphInputHandler.m b/tikzit/src/gtk/GraphInputHandler.m index 4d77045..caaadeb 100644 --- a/tikzit/src/gtk/GraphInputHandler.m +++ b/tikzit/src/gtk/GraphInputHandler.m @@ -34,7 +34,7 @@ static const InputMask unionSelectMask = ShiftMask; leaderNode = nil; modifyEdge = nil; selectionBoxContents = [[NSMutableSet alloc] initWithCapacity:10]; - grabbedResizeHandle = NoHandle; + currentResizeHandle = NoHandle; } return self; @@ -94,6 +94,7 @@ static const InputMask unionSelectMask = ShiftMask; if (mode != m) { if (mode == BoundingBoxMode) { [renderer setBoundingBoxHandlesShown:NO]; + [[renderer surface] setCursor:NormalCursor]; } mode = m; [self deselectAll]; @@ -143,9 +144,9 @@ static const InputMask unionSelectMask = ShiftMask; } } else if (mode == BoundingBoxMode) { state = BoundingBoxState; - grabbedResizeHandle = [renderer boundingBoxResizeHandleAt:pos]; + currentResizeHandle = [renderer boundingBoxResizeHandleAt:pos]; [[self doc] startChangeBoundingBox]; - if (grabbedResizeHandle == NoHandle) { + if (currentResizeHandle == NoHandle) { [[[self doc] graph] setBoundingBox:NSZeroRect]; [renderer setBoundingBoxHandlesShown:NO]; } @@ -324,7 +325,7 @@ static const InputMask unionSelectMask = ShiftMask; } else if (state == BoundingBoxState) { Grid *grid = [renderer grid]; Graph *graph = [[self doc] graph]; - if (grabbedResizeHandle == NoHandle) { + if (currentResizeHandle == NoHandle) { NSRect bbox = NSRectAroundPoints( [grid snapScreenPoint:dragOrigin], [grid snapScreenPoint:pos] @@ -334,9 +335,9 @@ static const InputMask unionSelectMask = ShiftMask; NSRect bbox = [transformer rectToScreen:[graph boundingBox]]; NSPoint p2 = [grid snapScreenPoint:pos]; - if (grabbedResizeHandle == NorthWestHandle || - grabbedResizeHandle == NorthHandle || - grabbedResizeHandle == NorthEastHandle) { + if (currentResizeHandle == NorthWestHandle || + currentResizeHandle == NorthHandle || + currentResizeHandle == NorthEastHandle) { float dy = p2.y - NSMinY(bbox); if (dy < bbox.size.height) { @@ -347,9 +348,9 @@ static const InputMask unionSelectMask = ShiftMask; bbox.size.height = 0; } - } else if (grabbedResizeHandle == SouthWestHandle || - grabbedResizeHandle == SouthHandle || - grabbedResizeHandle == SouthEastHandle) { + } else if (currentResizeHandle == SouthWestHandle || + currentResizeHandle == SouthHandle || + currentResizeHandle == SouthEastHandle) { float dy = p2.y - NSMaxY(bbox); if (-dy < bbox.size.height) { @@ -359,9 +360,9 @@ static const InputMask unionSelectMask = ShiftMask; } } - if (grabbedResizeHandle == NorthWestHandle || - grabbedResizeHandle == WestHandle || - grabbedResizeHandle == SouthWestHandle) { + if (currentResizeHandle == NorthWestHandle || + currentResizeHandle == WestHandle || + currentResizeHandle == SouthWestHandle) { float dx = p2.x - NSMinX(bbox); if (dx < bbox.size.width) { @@ -372,9 +373,9 @@ static const InputMask unionSelectMask = ShiftMask; bbox.size.width = 0; } - } else if (grabbedResizeHandle == NorthEastHandle || - grabbedResizeHandle == EastHandle || - grabbedResizeHandle == SouthEastHandle) { + } else if (currentResizeHandle == NorthEastHandle || + currentResizeHandle == EastHandle || + currentResizeHandle == SouthEastHandle) { float dx = p2.x - NSMaxX(bbox); if (-dx < bbox.size.width) { @@ -393,6 +394,43 @@ static const InputMask unionSelectMask = ShiftMask; [[renderer transformer] setOrigin:newOrigin]; [renderer invalidateGraph]; } + if (mode == BoundingBoxMode && state != BoundingBoxState) { + ResizeHandle handle = [renderer boundingBoxResizeHandleAt:pos]; + if (handle != currentResizeHandle) { + currentResizeHandle = handle; + Cursor c = NormalCursor; + switch (handle) { + case EastHandle: + c = ResizeRightCursor; + break; + case SouthEastHandle: + c = ResizeBottomRightCursor; + break; + case SouthHandle: + c = ResizeBottomCursor; + break; + case SouthWestHandle: + c = ResizeBottomLeftCursor; + break; + case WestHandle: + c = ResizeLeftCursor; + break; + case NorthWestHandle: + c = ResizeTopLeftCursor; + break; + case NorthHandle: + c = ResizeTopCursor; + break; + case NorthEastHandle: + c = ResizeTopRightCursor; + break; + default: + c = NormalCursor; + break; + } + [[renderer surface] setCursor:c]; + } + } } - (void) mouseScrolledAt:(NSPoint)pos inDirection:(ScrollDirection)dir withMask:(InputMask)mask { diff --git a/tikzit/src/gtk/Surface.h b/tikzit/src/gtk/Surface.h index d2a0dba..449721f 100644 --- a/tikzit/src/gtk/Surface.h +++ b/tikzit/src/gtk/Surface.h @@ -19,6 +19,18 @@ #import "RenderContext.h" #import "Transformer.h" +typedef enum { + NormalCursor, + ResizeRightCursor, + ResizeBottomRightCursor, + ResizeBottomCursor, + ResizeBottomLeftCursor, + ResizeLeftCursor, + ResizeTopLeftCursor, + ResizeTopCursor, + ResizeTopRightCursor +} Cursor; + @protocol Surface; @protocol RenderDelegate @@ -85,6 +97,8 @@ - (void) zoomInAboutPoint:(NSPoint)p; - (void) zoomOutAboutPoint:(NSPoint)p; - (void) zoomResetAboutPoint:(NSPoint)p; + +- (void) setCursor:(Cursor)c; @end // vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/WidgetSurface.m b/tikzit/src/gtk/WidgetSurface.m index 3538f72..14d799b 100644 --- a/tikzit/src/gtk/WidgetSurface.m +++ b/tikzit/src/gtk/WidgetSurface.m @@ -82,6 +82,14 @@ static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, Widge return self; } +- (void) dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [transformer release]; + g_object_unref (G_OBJECT (widget)); + + [super dealloc]; +} + - (void) invalidateRect:(NSRect)rect { if (!NSIsEmptyRect (rect)) { GdkWindow *window = gtk_widget_get_window (widget); @@ -278,12 +286,40 @@ static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, Widge [self zoomTo:defaultScale aboutPoint:p]; } -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [transformer release]; - g_object_unref (G_OBJECT (widget)); - - [super dealloc]; +- (void) setCursor:(Cursor)c { + GdkWindow *window = gtk_widget_get_window (widget); + GdkCursor *cursor = NULL; + switch (c) { + case ResizeRightCursor: + cursor = gdk_cursor_new (GDK_RIGHT_SIDE); + break; + case ResizeBottomRightCursor: + cursor = gdk_cursor_new (GDK_BOTTOM_RIGHT_CORNER); + break; + case ResizeBottomCursor: + cursor = gdk_cursor_new (GDK_BOTTOM_SIDE); + break; + case ResizeBottomLeftCursor: + cursor = gdk_cursor_new (GDK_BOTTOM_LEFT_CORNER); + break; + case ResizeLeftCursor: + cursor = gdk_cursor_new (GDK_LEFT_SIDE); + break; + case ResizeTopLeftCursor: + cursor = gdk_cursor_new (GDK_TOP_LEFT_CORNER); + break; + case ResizeTopCursor: + cursor = gdk_cursor_new (GDK_TOP_SIDE); + break; + case ResizeTopRightCursor: + cursor = gdk_cursor_new (GDK_TOP_RIGHT_CORNER); + break; + default: break; + } + gdk_window_set_cursor (window, cursor); + if (cursor != NULL) { + gdk_cursor_unref (cursor); + } } @end -- cgit v1.2.3