From 2e7c80384be13a7dd595bb69f9bc844cd1641ea6 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sat, 14 Mar 2009 12:59:34 +0000 Subject: [PATCH] =?UTF-8?q?Bug=20566443=20=E2=80=93=20diagonal=20method=20?= =?UTF-8?q?guidelines=20for=20crop=20tool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2009-03-14 Sven Neumann Bug 566443 – diagonal method guidelines for crop tool * app/tools/tools-enums.[ch] * app/tools/gimprectangletool.c (gimp_rectangle_tool_draw_guides): applied a slightly modified patch from Lukasz Hladowski, based on a patch from Tim Jedlicka. This adds diagonal guidelines as described by Edwin Westhoff to the rectangle tools. svn path=/trunk/; revision=28156 --- ChangeLog | 10 ++++ app/tools/gimprectangletool.c | 109 +++++++++++++++++++++++----------- app/tools/tools-enums.c | 2 + app/tools/tools-enums.h | 3 +- 4 files changed, 89 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3d3e9a7344..f1533248dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-03-14 Sven Neumann + + Bug 566443 – diagonal method guidelines for crop tool + + * app/tools/tools-enums.[ch] + * app/tools/gimprectangletool.c (gimp_rectangle_tool_draw_guides): + applied a slightly modified patch from Lukasz Hladowski, based on + a patch from Tim Jedlicka. This adds diagonal guidelines as + described by Edwin Westhoff to the rectangle tools. + 2009-03-13 Sven Neumann Bug 574427 – Stroke path with paint tool error diff --git a/app/tools/gimprectangletool.c b/app/tools/gimprectangletool.c index 5484961f91..e88c2e645d 100644 --- a/app/tools/gimprectangletool.c +++ b/app/tools/gimprectangletool.c @@ -1826,66 +1826,106 @@ gimp_rectangle_tool_draw (GimpDrawTool *draw_tool) static void gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool) { - GimpTool *tool = GIMP_TOOL (draw_tool); - GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool); - gdouble pub_x1, pub_y1, pub_x2, pub_y2; + GimpTool *tool = GIMP_TOOL (draw_tool); + gdouble x1, y1; + gdouble x2, y2; gimp_rectangle_tool_get_public_rect (GIMP_RECTANGLE_TOOL (draw_tool), - &pub_x1, &pub_y1, &pub_x2, &pub_y2); + &x1, &y1, &x2, &y2); - switch (private->guide) + switch (GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool)->guide) { case GIMP_RECTANGLE_GUIDE_NONE: break; case GIMP_RECTANGLE_GUIDE_CENTER_LINES: gimp_draw_tool_draw_line (draw_tool, - pub_x1, (pub_y1 + pub_y2) / 2, - pub_x2, (pub_y1 + pub_y2) / 2, FALSE); + x1, (y1 + y2) / 2, + x2, (y1 + y2) / 2, FALSE); gimp_draw_tool_draw_line (draw_tool, - (pub_x1 + pub_x2) / 2, pub_y1, - (pub_x1 + pub_x2) / 2, pub_y2, FALSE); + (x1 + x2) / 2, y1, + (x1 + x2) / 2, y2, FALSE); break; case GIMP_RECTANGLE_GUIDE_THIRDS: gimp_draw_tool_draw_line (draw_tool, - pub_x1, (2 * pub_y1 + pub_y2) / 3, - pub_x2, (2 * pub_y1 + pub_y2) / 3, FALSE); + x1, (2 * y1 + y2) / 3, + x2, (2 * y1 + y2) / 3, FALSE); gimp_draw_tool_draw_line (draw_tool, - pub_x1, (pub_y1 + 2 * pub_y2) / 3, - pub_x2, (pub_y1 + 2 * pub_y2) / 3, FALSE); + x1, (y1 + 2 * y2) / 3, + x2, (y1 + 2 * y2) / 3, FALSE); gimp_draw_tool_draw_line (draw_tool, - (2 * pub_x1 + pub_x2) / 3, pub_y1, - (2 * pub_x1 + pub_x2) / 3, pub_y2, FALSE); + (2 * x1 + x2) / 3, y1, + (2 * x1 + x2) / 3, y2, FALSE); gimp_draw_tool_draw_line (draw_tool, - (pub_x1 + 2 * pub_x2) / 3, pub_y1, - (pub_x1 + 2 * pub_x2) / 3, pub_y2, FALSE); + (x1 + 2 * x2) / 3, y1, + (x1 + 2 * x2) / 3, y2, FALSE); break; case GIMP_RECTANGLE_GUIDE_GOLDEN: gimp_draw_tool_draw_line (draw_tool, - pub_x1, - (2 * pub_y1 + (1 + SQRT5) * pub_y2) / (3 + SQRT5), - pub_x2, - (2 * pub_y1 + (1 + SQRT5) * pub_y2) / (3 + SQRT5), + x1, + (2 * y1 + (1 + SQRT5) * y2) / (3 + SQRT5), + x2, + (2 * y1 + (1 + SQRT5) * y2) / (3 + SQRT5), FALSE); gimp_draw_tool_draw_line (draw_tool, - pub_x1, - ((1 + SQRT5) * pub_y1 + 2 * pub_y2) / (3 + SQRT5), - pub_x2, - ((1 + SQRT5) * pub_y1 + 2 * pub_y2) / (3 + SQRT5), + x1, + ((1 + SQRT5) * y1 + 2 * y2) / (3 + SQRT5), + x2, + ((1 + SQRT5) * y1 + 2 * y2) / (3 + SQRT5), FALSE); gimp_draw_tool_draw_line (draw_tool, - (2 * pub_x1 + (1 + SQRT5) * pub_x2) / (3 + SQRT5), - pub_y1, - (2 * pub_x1 + (1 + SQRT5) * pub_x2) / (3 + SQRT5), - pub_y2, + (2 * x1 + (1 + SQRT5) * x2) / (3 + SQRT5), + y1, + (2 * x1 + (1 + SQRT5) * x2) / (3 + SQRT5), + y2, FALSE); gimp_draw_tool_draw_line (draw_tool, - ((1 + SQRT5) * pub_x1 + 2 * pub_x2) / (3 + SQRT5), - pub_y1, - ((1 + SQRT5) * pub_x1 + 2 * pub_x2) / (3 + SQRT5), - pub_y2, FALSE); + ((1 + SQRT5) * x1 + 2 * x2) / (3 + SQRT5), + y1, + ((1 + SQRT5) * x1 + 2 * x2) / (3 + SQRT5), + y2, FALSE); + break; + + /* This code implements the method of diagonals discovered by + * Edwin Westhoff - see http://www.diagonalmethod.info/ + */ + case GIMP_RECTANGLE_GUIDE_DIAGONALS: + { + /* the side of the largest square that can be + * fitted in whole into the rectangle (x1, y1), (x2, y2) + */ + const gdouble square_side = MIN (x2 - x1, y2 - y1); + + /* diagonal from the top-left edge */ + gimp_draw_tool_draw_line (draw_tool, + x1, y1, + x1 + square_side, y1 + square_side, + FALSE); + /* diagonal from the top-right edge */ + gimp_draw_tool_draw_line (draw_tool, + x2, y1, + x2 - square_side, y1 + square_side, + FALSE); + + /* If user selected a square, we cannot draw from bottom points + * as we would erase the guides drawn from the top points + */ + if ((x1 + square_side != x2) || (y1 + square_side != y2)) + { + /* diagonal from the bottom-left edge */ + gimp_draw_tool_draw_line (draw_tool, + x1, y2, + x1 + square_side, y2 - square_side, + FALSE); + /* diagonal from the bottom-right edge */ + gimp_draw_tool_draw_line (draw_tool, + x2, y2, + x2 - square_side, y2 - square_side, + FALSE); + } + } break; } } @@ -1900,7 +1940,8 @@ gimp_rectangle_tool_update_handle_sizes (GimpRectangleTool *rect_tool) gint visible_rectangle_height; gint rectangle_width; gint rectangle_height; - gdouble pub_x1, pub_y1, pub_x2, pub_y2; + gdouble pub_x1, pub_y1; + gdouble pub_x2, pub_y2; tool = GIMP_TOOL (rect_tool); private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool); diff --git a/app/tools/tools-enums.c b/app/tools/tools-enums.c index 9dc9e89f57..34eeb76667 100644 --- a/app/tools/tools-enums.c +++ b/app/tools/tools-enums.c @@ -51,6 +51,7 @@ gimp_rectangle_guide_get_type (void) { GIMP_RECTANGLE_GUIDE_CENTER_LINES, "GIMP_RECTANGLE_GUIDE_CENTER_LINES", "center-lines" }, { GIMP_RECTANGLE_GUIDE_THIRDS, "GIMP_RECTANGLE_GUIDE_THIRDS", "thirds" }, { GIMP_RECTANGLE_GUIDE_GOLDEN, "GIMP_RECTANGLE_GUIDE_GOLDEN", "golden" }, + { GIMP_RECTANGLE_GUIDE_DIAGONALS, "GIMP_RECTANGLE_GUIDE_DIAGONALS", "diagonals" }, { 0, NULL, NULL } }; @@ -60,6 +61,7 @@ gimp_rectangle_guide_get_type (void) { GIMP_RECTANGLE_GUIDE_CENTER_LINES, NC_("rectangle-guide", "Center lines"), NULL }, { GIMP_RECTANGLE_GUIDE_THIRDS, NC_("rectangle-guide", "Rule of thirds"), NULL }, { GIMP_RECTANGLE_GUIDE_GOLDEN, NC_("rectangle-guide", "Golden sections"), NULL }, + { GIMP_RECTANGLE_GUIDE_DIAGONALS, NC_("rectangle-guide", "Diagonal lines"), NULL }, { 0, NULL, NULL } }; diff --git a/app/tools/tools-enums.h b/app/tools/tools-enums.h index 57af33eca3..a4038580b4 100644 --- a/app/tools/tools-enums.h +++ b/app/tools/tools-enums.h @@ -44,7 +44,8 @@ typedef enum GIMP_RECTANGLE_GUIDE_NONE, /*< desc="No guides" >*/ GIMP_RECTANGLE_GUIDE_CENTER_LINES, /*< desc="Center lines" >*/ GIMP_RECTANGLE_GUIDE_THIRDS, /*< desc="Rule of thirds" >*/ - GIMP_RECTANGLE_GUIDE_GOLDEN /*< desc="Golden sections" >*/ + GIMP_RECTANGLE_GUIDE_GOLDEN, /*< desc="Golden sections" >*/ + GIMP_RECTANGLE_GUIDE_DIAGONALS /*< desc="Diagonal lines" >*/ } GimpRectangleGuide;