You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
3.5 KiB
75 lines
3.5 KiB
13 years ago
|
https://sourceforge.net/tracker/?func=detail&aid=3082301&group_id=163434&atid=827735
|
||
|
To make the image patch even more useful, I've written this patch to allow the aspect ratio
|
||
|
to be preserved when resizing selections. (It doesn't just apply to images.) Simply resize using the right
|
||
|
mouse button (button-3) rather than the left mouse button.
|
||
|
This patch should be applied after the enhanced image patch. (Though it'd be easy enough to make the
|
||
|
changes to the raw 0.4.5 source directly since it doesn't change any of the image patch related areas.)
|
||
|
David Barton ( db9052 ) - 2010-10-06 09:30:56 PDT
|
||
|
|
||
|
diff -ur xournal-0.4.5/src/xo-paint.c xournal-0.4.5-aspectratio/src/xo-paint.c
|
||
|
--- xournal-0.4.5/src/xo-paint.c 2010-10-06 16:45:01.000000000 +0100
|
||
|
+++ xournal-0.4.5-aspectratio/src/xo-paint.c 2010-10-06 17:10:19.000000000 +0100
|
||
|
@@ -609,6 +609,12 @@
|
||
|
ui.selection->new_x2 = ui.selection->bbox.right;
|
||
|
gnome_canvas_item_set(ui.selection->canvas_item, "dash", NULL, NULL);
|
||
|
update_cursor_for_resize(pt);
|
||
|
+
|
||
|
+ // Check whether we should preserve the aspect ratio
|
||
|
+ if (event->button.button == 3)
|
||
|
+ ui.cur_brush->tool_options |= TOOLOPT_SELECT_PRESERVE;
|
||
|
+ else
|
||
|
+ ui.cur_brush->tool_options &= ~TOOLOPT_SELECT_PRESERVE;
|
||
|
return TRUE;
|
||
|
}
|
||
|
return FALSE;
|
||
|
@@ -740,6 +746,38 @@
|
||
|
if (ui.selection->resizing_left) ui.selection->new_x1 = pt[0];
|
||
|
if (ui.selection->resizing_right) ui.selection->new_x2 = pt[0];
|
||
|
|
||
|
+ if (ui.cur_brush->tool_options & TOOLOPT_SELECT_PRESERVE) {
|
||
|
+ double aspectratio = (ui.selection->bbox.top - ui.selection->bbox.bottom)/(ui.selection->bbox.right - ui.selection->bbox.left);
|
||
|
+ double newheight = ui.selection->new_y1 - ui.selection->new_y2;
|
||
|
+ double newwidth = ui.selection->new_x2 - ui.selection->new_x1;
|
||
|
+ gboolean boundheight;
|
||
|
+
|
||
|
+ // Resizing from top or bottom only
|
||
|
+ if ((ui.selection->resizing_top || ui.selection->resizing_bottom) && !(ui.selection->resizing_left || ui.selection->resizing_right))
|
||
|
+ boundheight = 0;
|
||
|
+ // Resizing from right or left only
|
||
|
+ else if (!(ui.selection->resizing_top || ui.selection->resizing_bottom) && (ui.selection->resizing_left || ui.selection->resizing_right))
|
||
|
+ boundheight = 1;
|
||
|
+ // Resizing from a corner
|
||
|
+ else if (newheight/aspectratio > newwidth)
|
||
|
+ boundheight = 0;
|
||
|
+ else
|
||
|
+ boundheight = 1;
|
||
|
+
|
||
|
+ if (boundheight) {
|
||
|
+ // Bound the height
|
||
|
+ newheight = newwidth*aspectratio;
|
||
|
+ if (ui.selection->resizing_top) ui.selection->new_y1 = ui.selection->new_y2 + newheight;
|
||
|
+ else ui.selection->new_y2 = ui.selection->new_y1 - newheight;
|
||
|
+ }
|
||
|
+ else {
|
||
|
+ // Bound the width
|
||
|
+ newwidth = newheight/aspectratio;
|
||
|
+ if (ui.selection->resizing_left) ui.selection->new_x1 = ui.selection->new_x2 - newwidth;
|
||
|
+ else ui.selection->new_x2 = ui.selection->new_x1 + newwidth;
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
gnome_canvas_item_set(ui.selection->canvas_item,
|
||
|
"x1", ui.selection->new_x1, "x2", ui.selection->new_x2,
|
||
|
"y1", ui.selection->new_y1, "y2", ui.selection->new_y2, NULL);
|
||
|
diff -ur xournal-0.4.5/src/xournal.h xournal-0.4.5-aspectratio/src/xournal.h
|
||
|
--- xournal-0.4.5/src/xournal.h 2010-10-06 16:45:01.000000000 +0100
|
||
|
+++ xournal-0.4.5-aspectratio/src/xournal.h 2010-10-06 16:31:07.000000000 +0100
|
||
|
@@ -130,6 +130,7 @@
|
||
|
#define TOOLOPT_ERASER_STANDARD 0
|
||
|
#define TOOLOPT_ERASER_WHITEOUT 1
|
||
|
#define TOOLOPT_ERASER_STROKES 2
|
||
|
+#define TOOLOPT_SELECT_PRESERVE 1 // Preserve the aspect ratio of the selection when resizing
|
||
|
|
||
|
extern double predef_thickness[NUM_STROKE_TOOLS][THICKNESS_MAX];
|
||
|
|