croptool

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

commit 50b1f64a9a348f88ec9b54771936a8936c927891
parent 6bf921b112f844413c2ded7bb9b582cf440ec0fd
Author: lumidify <nobody@lumidify.org>
Date:   Thu, 16 Apr 2020 08:34:30 +0200

Round instead of casting; allow to make window smaller than 500x500

Diffstat:
Mcroptool.c | 19++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/croptool.c b/croptool.c @@ -17,6 +17,7 @@ #include <stdio.h> #include <limits.h> #include <stdlib.h> +#include <math.h> #include <gtk/gtk.h> #include <cairo/cairo.h> #include <gdk/gdkkeysyms.h> @@ -117,7 +118,7 @@ int main(int argc, char *argv[]) { window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "croptool"); - gtk_widget_set_size_request(window, 500, 500); + gtk_window_set_default_size(GTK_WINDOW(window), 500, 500); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL); GtkWidget *area = gtk_drawing_area_new(); @@ -181,10 +182,10 @@ print_selection(struct Selection *sel, const char *filename) { int x0 = sel->rect.x0, y0 = sel->rect.y0; int x1 = sel->rect.x1, y1 = sel->rect.y1; sort_coordinates(&x0, &y0, &x1, &y1); - x0 = (int)(x0 * scale); - y0 = (int)(y0 * scale); - x1 = (int)(x1 * scale); - y1 = (int)(y1 * scale); + x0 = round(x0 * scale); + y0 = round(y0 * scale); + x1 = round(x1 * scale); + y1 = round(y1 * scale); /* The box is completely outside of the picture. */ if (x0 >= sel->orig_w || y0 >= sel->orig_h) return; @@ -424,10 +425,10 @@ change_picture( * This only takes width into account because the * aspect ratio should have been preserved anyways */ double scale = (double)actual_w / sel->scaled_w; - sel->rect.x0 = (int)(sel->rect.x0 * scale); - sel->rect.y0 = (int)(sel->rect.y0 * scale); - sel->rect.x1 = (int)(sel->rect.x1 * scale); - sel->rect.y1 = (int)(sel->rect.y1 * scale); + sel->rect.x0 = round(sel->rect.x0 * scale); + sel->rect.y0 = round(sel->rect.y0 * scale); + sel->rect.x1 = round(sel->rect.x1 * scale); + sel->rect.y1 = round(sel->rect.y1 * scale); sel->scaled_w = actual_w; sel->scaled_h = actual_h; }