croptool

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

commit 89bb20af1990f76cf59eaba938293edc9cb273e9
parent 05b43ed687efd682f96189d9920d0198e1841a37
Author: lumidify <nobody@lumidify.org>
Date:   Thu, 23 Apr 2020 11:19:15 +0200

Allow the selection box to be removed

Diffstat:
MREADME | 5+++--
Mcroptool.c | 36+++++++++++++++++++++++++-----------
2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/README b/README @@ -20,7 +20,7 @@ in the middle, you can move it. Clicking outside creates a new box. I don't know if all of the collision logic is entirely correct, so tell me if you notice any problems. -Three keys are recognized: enter/return, right arrow, and left arrow. +Four keys are recognized: enter/return, delete, right arrow, and left arrow. Enter and right arrow both go to the next image, but enter copies the selection box from the current image and uses it for the next picture, while right arrow just goes to the next image and only displays a @@ -28,7 +28,8 @@ selection box if it already had one. This is so that lots of pages of a digitized book can be cropped quickly since the selection box needs to be tweaked occasionally (since my digitizing equipment, if it can be called that, isn't exactly very professional). Left arrow -just goes to the last picture. +just goes to the last picture. Delete removes the selection for the +current image (this is then also not printed out at the end). Note that resizing the window currently does not resize the images. It will only take effect if you move to another image. There may be diff --git a/croptool.c b/croptool.c @@ -89,6 +89,7 @@ static void next_picture(GtkWidget *area, struct State *state, gboolean copy_box static void last_picture(GtkWidget *area, struct State *state); static GdkPixbuf *load_pixbuf(char *filename, int w, int h, int *actual_w, int *actual_h); static void print_selection(struct Selection *sel, const char *filename); +static void clear_selection(GtkWidget *area, struct State *state); int main(int argc, char *argv[]) { GtkWidget *window; @@ -314,22 +315,23 @@ static void redraw(GtkWidget *area, struct State *state) { if (!state->cur_pixbuf) return; - if (!state->selections[state->cur_selection]) - return; - struct Rect rect = state->selections[state->cur_selection]->rect; cairo_t *cr; cr = gdk_cairo_create(area->window); gdk_cairo_set_source_pixbuf(cr, state->cur_pixbuf, 0, 0); cairo_paint(cr); - gdk_cairo_set_source_color(cr, &state->gdk_color); - cairo_move_to(cr, rect.x0, rect.y0); - cairo_line_to(cr, rect.x1, rect.y0); - cairo_line_to(cr, rect.x1, rect.y1); - cairo_line_to(cr, rect.x0, rect.y1); - cairo_line_to(cr, rect.x0, rect.y0); - cairo_stroke(cr); + if (state->selections[state->cur_selection]) { + struct Rect rect = state->selections[state->cur_selection]->rect; + gdk_cairo_set_source_color(cr, &state->gdk_color); + cairo_move_to(cr, rect.x0, rect.y0); + cairo_line_to(cr, rect.x1, rect.y0); + cairo_line_to(cr, rect.x1, rect.y1); + cairo_line_to(cr, rect.x0, rect.y1); + cairo_line_to(cr, rect.x0, rect.y0); + cairo_stroke(cr); + } + cairo_destroy(cr); } @@ -344,7 +346,7 @@ configure_event(GtkWidget *area, GdkEvent *event, gpointer data) { static gboolean draw_expose(GtkWidget *area, GdkEvent *event, gpointer data) { struct State *state = (struct State *)data; - if (state->cur_selection < 0 || !state->selections[state->cur_selection]) + if (state->cur_selection < 0) return FALSE; redraw(area, state); return FALSE; @@ -476,6 +478,15 @@ last_picture(GtkWidget *area, struct State *state) { change_picture(area, tmp_pixbuf, tmp_cur_selection, orig_w, orig_h, state, FALSE); } +static void +clear_selection(GtkWidget *area, struct State *state) { + if (state->cur_selection < 0 || !state->selections[state->cur_selection]) + return; + free(state->selections[state->cur_selection]); + state->selections[state->cur_selection] = NULL; + gtk_widget_queue_draw(area); +} + static gboolean key_press(GtkWidget *area, GdkEventKey *event, gpointer data) { struct State *state = (struct State *)data; @@ -489,6 +500,9 @@ key_press(GtkWidget *area, GdkEventKey *event, gpointer data) { case GDK_KEY_Return: next_picture(area, state, TRUE); break; + case GDK_KEY_Delete: + clear_selection(area, state); + break; } return FALSE; }