croptool

Image cropping tool
git clone git://lumidify.org/croptool.git
Log | Files | Refs | README

commit 3c5129b4e685e8e098026434ea5e5807050dc18e
parent 8ea1b32c8ee63a66d2b6c4328e060ff004a5c1a3
Author: lumidify <nobody@lumidify.org>
Date:   Fri,  1 May 2020 11:26:45 +0200

Add cursors

Diffstat:
Mcroptool.c | 37+++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/croptool.c b/croptool.c @@ -65,6 +65,7 @@ struct State { GdkPixbuf *cur_pixbuf; struct Point move_handle; gboolean moving; + gboolean resizing; gboolean lock_x; gboolean lock_y; GdkColor gdk_color; @@ -109,6 +110,7 @@ int main(int argc, char *argv[]) { state->filenames = argv; state->cur_selection = -1; state->moving = FALSE; + state->resizing = FALSE; state->lock_x = FALSE; state->lock_y = FALSE; state->window_w = 0; @@ -127,7 +129,7 @@ int main(int argc, char *argv[]) { gtk_widget_add_events(area, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK | GDK_KEY_PRESS_MASK | - GDK_POINTER_MOTION_HINT_MASK); + GDK_POINTER_MOTION_HINT_MASK | GDK_POINTER_MOTION_MASK); gtk_container_add(GTK_CONTAINER(window), area); g_signal_connect(area, "expose-event", G_CALLBACK(draw_expose), state); @@ -299,6 +301,7 @@ button_press(GtkWidget *area, GdkEventButton *event, gpointer data) { rect->x1 = x; rect->y1 = y; } + state->resizing = TRUE; return FALSE; } @@ -306,6 +309,7 @@ static gboolean button_release(GtkWidget *area, GdkEventButton *event, gpointer data) { struct State *state = (struct State *)data; state->moving = FALSE; + state->resizing = FALSE; state->lock_x = FALSE; state->lock_y = FALSE; return FALSE; @@ -369,11 +373,40 @@ drag_motion(GtkWidget *area, GdkEventMotion *event, gpointer data) { rect->y1 += y_delta; state->move_handle.x = x; state->move_handle.y = y; - } else { + } else if (state->resizing == TRUE) { if (state->lock_y != TRUE) rect->x1 = x; if (state->lock_x != TRUE) rect->y1 = y; + } else { + int x0 = rect->x0, x1 = rect->x1; + int y0 = rect->y0, y1 = rect->y1; + sort_coordinates(&x0, &y0, &x1, &y1); + GdkCursor *c = NULL; + GdkCursor *old = gdk_window_get_cursor(area->window); + if (old) + gdk_cursor_unref(old); + if (collide_point(x, y, x0, y0)) { + c = gdk_cursor_new(GDK_TOP_LEFT_CORNER); + } else if (collide_point(x, y, x1, y0)) { + c = gdk_cursor_new(GDK_TOP_RIGHT_CORNER); + } else if (collide_point(x, y, x0, y1)) { + c = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER); + } else if (collide_point(x, y, x1, y1)) { + c = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER); + } else if (collide_line(x, y, x0, y0, x1, y0)) { + c = gdk_cursor_new(GDK_TOP_SIDE); + } else if (collide_line(x, y, x1, y1, x0, y1)) { + c = gdk_cursor_new(GDK_BOTTOM_SIDE); + } else if (collide_line(x, y, x1, y1, x1, y0)) { + c = gdk_cursor_new(GDK_RIGHT_SIDE); + } else if (collide_line(x, y, x0, y0, x0, y1)) { + c = gdk_cursor_new(GDK_LEFT_SIDE); + } else if (collide_rect(x, y, *rect)) { + c = gdk_cursor_new(GDK_FLEUR); + } + gdk_window_set_cursor(area->window, c); + return FALSE; } gtk_widget_queue_draw(area);