From 15620f36b2dcd94bd9e90854a8e2b82ecb6582aa Mon Sep 17 00:00:00 2001 From: William Skaggs Date: Wed, 23 Aug 2006 22:13:17 +0000 Subject: [PATCH] Bill Skaggs * app/tools/tools-enums.h * app/tools/gimptransformtool.[ch]: add support for handles at midpoints of edges. * app/tools/gimpscaletool.c: use midpoint handles for scaling with fixed width or height. Fixes bug #344955. --- ChangeLog | 9 +++ app/tools/gimpscaletool.c | 21 +++++-- app/tools/gimptransformtool.c | 115 ++++++++++++++++++++++++++++++++++ app/tools/gimptransformtool.h | 55 ++++++++-------- app/tools/tools-enums.h | 4 ++ 5 files changed, 171 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d4ab95c4e..e865b77c17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-08-23 Bill Skaggs + + * app/tools/tools-enums.h + * app/tools/gimptransformtool.[ch]: add support for handles at + midpoints of edges. + + * app/tools/gimpscaletool.c: use midpoint handles for scaling + with fixed width or height. Fixes bug #344955. + 2006-08-23 Sven Neumann * libgimpbase/gimpbaseenums.[ch]: removed "(Fastest)" from "None" diff --git a/app/tools/gimpscaletool.c b/app/tools/gimpscaletool.c index 9b1e44666c..97e7ec4b4e 100644 --- a/app/tools/gimpscaletool.c +++ b/app/tools/gimpscaletool.c @@ -105,13 +105,14 @@ gimp_scale_tool_init (GimpScaleTool *scale_tool) gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_RESIZE); - tr_tool->undo_desc = Q_("command|Scale"); - tr_tool->shell_desc = _("Scaling Information"); - tr_tool->progress_text = _("Scaling"); + tr_tool->undo_desc = Q_("command|Scale"); + tr_tool->shell_desc = _("Scaling Information"); + tr_tool->progress_text = _("Scaling"); - tr_tool->use_grid = TRUE; - tr_tool->use_handles = TRUE; - tr_tool->use_center = TRUE; + tr_tool->use_grid = TRUE; + tr_tool->use_handles = TRUE; + tr_tool->use_center = TRUE; + tr_tool->use_mid_handles = TRUE; } static void @@ -198,6 +199,8 @@ gimp_scale_tool_motion (GimpTransformTool *tr_tool, switch (tr_tool->function) { + case TRANSFORM_HANDLE_N: + diff_x = 0; /* and fall through */ case TRANSFORM_HANDLE_NW: x1 = &tr_tool->trans_info[X0]; y1 = &tr_tool->trans_info[Y0]; @@ -206,6 +209,8 @@ gimp_scale_tool_motion (GimpTransformTool *tr_tool, dir_x = dir_y = 1; break; + case TRANSFORM_HANDLE_E: + diff_y = 0; /* and fall through */ case TRANSFORM_HANDLE_NE: x1 = &tr_tool->trans_info[X1]; y1 = &tr_tool->trans_info[Y0]; @@ -215,6 +220,8 @@ gimp_scale_tool_motion (GimpTransformTool *tr_tool, dir_y = 1; break; + case TRANSFORM_HANDLE_W: + diff_y = 0; /* and fall through */ case TRANSFORM_HANDLE_SW: x1 = &tr_tool->trans_info[X0]; y1 = &tr_tool->trans_info[Y1]; @@ -224,6 +231,8 @@ gimp_scale_tool_motion (GimpTransformTool *tr_tool, dir_y = -1; break; + case TRANSFORM_HANDLE_S: + diff_x = 0; /* and fall through */ case TRANSFORM_HANDLE_SE: x1 = &tr_tool->trans_info[X1]; y1 = &tr_tool->trans_info[Y1]; diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c index d7520e0da5..712d05f30d 100644 --- a/app/tools/gimptransformtool.c +++ b/app/tools/gimptransformtool.c @@ -212,6 +212,7 @@ gimp_transform_tool_init (GimpTransformTool *tr_tool) tr_tool->use_grid = FALSE; tr_tool->use_handles = FALSE; tr_tool->use_center = FALSE; + tr_tool->use_mid_handles = FALSE; tr_tool->ngx = 0; tr_tool->ngy = 0; tr_tool->grid_coords = NULL; @@ -593,6 +594,63 @@ gimp_transform_tool_oper_update (GimpTool *tool, closest_dist = dist; tr_tool->function = TRANSFORM_HANDLE_SE; } + + if (tr_tool->use_mid_handles) + { + gdouble x, y; + + x = (tr_tool->tx1 + tr_tool->tx2) / 2.0; + y = (tr_tool->ty1 + tr_tool->ty2) / 2.0; + if (gimp_draw_tool_on_handle (draw_tool, display, + coords->x, coords->y, + GIMP_HANDLE_SQUARE, + x, y, + 2 * HANDLE_SIZE, 2 * HANDLE_SIZE, + GTK_ANCHOR_CENTER, + FALSE)) + { + tr_tool->function = TRANSFORM_HANDLE_N; + } + + x = (tr_tool->tx2 + tr_tool->tx4) / 2.0; + y = (tr_tool->ty2 + tr_tool->ty4) / 2.0; + if (gimp_draw_tool_on_handle (draw_tool, display, + coords->x, coords->y, + GIMP_HANDLE_SQUARE, + x, y, + 2 * HANDLE_SIZE, 2 * HANDLE_SIZE, + GTK_ANCHOR_CENTER, + FALSE)) + { + tr_tool->function = TRANSFORM_HANDLE_E; + } + + x = (tr_tool->tx3 + tr_tool->tx4) / 2.0; + y = (tr_tool->ty3 + tr_tool->ty4) / 2.0; + if (gimp_draw_tool_on_handle (draw_tool, display, + coords->x, coords->y, + GIMP_HANDLE_SQUARE, + x, y, + 2 * HANDLE_SIZE, 2 * HANDLE_SIZE, + GTK_ANCHOR_CENTER, + FALSE)) + { + tr_tool->function = TRANSFORM_HANDLE_S; + } + + x = (tr_tool->tx3 + tr_tool->tx1) / 2.0; + y = (tr_tool->ty3 + tr_tool->ty1) / 2.0; + if (gimp_draw_tool_on_handle (draw_tool, display, + coords->x, coords->y, + GIMP_HANDLE_SQUARE, + x, y, + 2 * HANDLE_SIZE, 2 * HANDLE_SIZE, + GTK_ANCHOR_CENTER, + FALSE)) + { + tr_tool->function = TRANSFORM_HANDLE_W; + } + } } if (tr_tool->use_center && @@ -643,6 +701,22 @@ gimp_transform_tool_cursor_update (GimpTool *tool, cursor = GIMP_CURSOR_CORNER_BOTTOM_RIGHT; break; + case TRANSFORM_HANDLE_N: + cursor = GIMP_CURSOR_SIDE_TOP; + break; + + case TRANSFORM_HANDLE_E: + cursor = GIMP_CURSOR_SIDE_RIGHT; + break; + + case TRANSFORM_HANDLE_S: + cursor = GIMP_CURSOR_SIDE_BOTTOM; + break; + + case TRANSFORM_HANDLE_W: + cursor = GIMP_CURSOR_SIDE_LEFT; + break; + default: cursor = GIMP_CURSOR_CROSSHAIR_SMALL; break; @@ -766,6 +840,47 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool) HANDLE_SIZE, HANDLE_SIZE, GTK_ANCHOR_CENTER, FALSE); + + if (tr_tool->use_mid_handles) + { + gdouble x, y; + + x = (tr_tool->tx1 + tr_tool->tx2) / 2.0; + y = (tr_tool->ty1 + tr_tool->ty2) / 2.0; + gimp_draw_tool_draw_handle (draw_tool, + GIMP_HANDLE_SQUARE, + x, y, + HANDLE_SIZE, HANDLE_SIZE, + GTK_ANCHOR_CENTER, + FALSE); + + x = (tr_tool->tx2 + tr_tool->tx4) / 2.0; + y = (tr_tool->ty2 + tr_tool->ty4) / 2.0; + gimp_draw_tool_draw_handle (draw_tool, + GIMP_HANDLE_SQUARE, + x, y, + HANDLE_SIZE, HANDLE_SIZE, + GTK_ANCHOR_CENTER, + FALSE); + + x = (tr_tool->tx3 + tr_tool->tx4) / 2.0; + y = (tr_tool->ty3 + tr_tool->ty4) / 2.0; + gimp_draw_tool_draw_handle (draw_tool, + GIMP_HANDLE_SQUARE, + x, y, + HANDLE_SIZE, HANDLE_SIZE, + GTK_ANCHOR_CENTER, + FALSE); + + x = (tr_tool->tx3 + tr_tool->tx1) / 2.0; + y = (tr_tool->ty3 + tr_tool->ty1) / 2.0; + gimp_draw_tool_draw_handle (draw_tool, + GIMP_HANDLE_SQUARE, + x, y, + HANDLE_SIZE, HANDLE_SIZE, + GTK_ANCHOR_CENTER, + FALSE); + } } /* draw the center */ diff --git a/app/tools/gimptransformtool.h b/app/tools/gimptransformtool.h index 8ef9ff1f4a..41e0ccca74 100644 --- a/app/tools/gimptransformtool.h +++ b/app/tools/gimptransformtool.h @@ -45,48 +45,49 @@ struct _GimpTransformTool { GimpDrawTool parent_instance; - gdouble startx; /* starting x coord */ - gdouble starty; /* starting y coord */ + gdouble startx; /* starting x coord */ + gdouble starty; /* starting y coord */ - gdouble curx; /* current x coord */ - gdouble cury; /* current y coord */ + gdouble curx; /* current x coord */ + gdouble cury; /* current y coord */ - gdouble lastx; /* last x coord */ - gdouble lasty; /* last y coord */ + gdouble lastx; /* last x coord */ + gdouble lasty; /* last y coord */ - GdkModifierType state; /* state of buttons and keys */ + GdkModifierType state; /* state of buttons and keys */ - gint x1, y1; /* upper left hand coordinate */ - gint x2, y2; /* lower right hand coords */ - gdouble cx, cy; /* center point (for rotation) */ + gint x1, y1; /* upper left hand coordinate */ + gint x2, y2; /* lower right hand coords */ + gdouble cx, cy; /* center point (for rotation) */ - gdouble tx1, ty1; /* transformed coords */ + gdouble tx1, ty1; /* transformed coords */ gdouble tx2, ty2; gdouble tx3, ty3; gdouble tx4, ty4; gdouble tcx, tcy; - GimpMatrix3 transform; /* transformation matrix */ - TransInfo trans_info; /* transformation info */ + GimpMatrix3 transform; /* transformation matrix */ + TransInfo trans_info; /* transformation info */ - TransInfo old_trans_info; /* for cancelling a drag operation */ + TransInfo old_trans_info; /* for cancelling a drag operation */ - TileManager *original; /* pointer to original tiles */ + TileManager *original; /* pointer to original tiles */ - TransformAction function; /* current tool activity */ + TransformAction function; /* current tool activity */ - gboolean use_grid; /* does the tool use the grid */ - gboolean use_handles; /* uses the corner handles */ - gboolean use_center; /* uses the center handle */ + gboolean use_grid; /* does the tool use the grid */ + gboolean use_handles; /* uses the corner handles */ + gboolean use_center; /* uses the center handle */ + gboolean use_mid_handles; /* use handles at midpoints of edges */ - gint ngx, ngy; /* number of grid lines in original - * x and y directions - */ - gdouble *grid_coords; /* x and y coordinates of the grid - * endpoints (a total of (ngx+ngy)*2 - * coordinate pairs) - */ - gdouble *tgrid_coords; /* transformed grid_coords */ + gint ngx, ngy; /* number of grid lines in original + * x and y directions + */ + gdouble *grid_coords; /* x and y coordinates of the grid + * endpoints (a total of (ngx+ngy)*2 + * coordinate pairs) + */ + gdouble *tgrid_coords; /* transformed grid_coords */ GimpTransformType type; GimpTransformDirection direction; diff --git a/app/tools/tools-enums.h b/app/tools/tools-enums.h index 9382ee271c..6356bbdd17 100644 --- a/app/tools/tools-enums.h +++ b/app/tools/tools-enums.h @@ -174,6 +174,10 @@ typedef enum /*< skip >*/ TRANSFORM_HANDLE_NE, /* north east */ TRANSFORM_HANDLE_SW, /* south west */ TRANSFORM_HANDLE_SE, /* south east */ + TRANSFORM_HANDLE_N, /* north */ + TRANSFORM_HANDLE_S, /* south */ + TRANSFORM_HANDLE_E, /* east */ + TRANSFORM_HANDLE_W, /* west */ TRANSFORM_HANDLE_CENTER } TransformAction;