Commit 7caa9093 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

added TRANSFORM_HANDLE_NONE (will get rid of TRANSFORM_CREATING later).

2006-06-20  Sven Neumann  <sven@gimp.org>

	* app/tools/tools-enums.h: added TRANSFORM_HANDLE_NONE (will
	get rid of TRANSFORM_CREATING later).

	* app/tools/gimptransformtool.[ch]: added member "use_handles" and
	default to FALSE for all "use_foo" variables.  Only deal with the
	handles the specific transform tool asks for.  Set cursors
	according to the active handle.

	* app/tools/gimpfliptool.c
	* app/tools/gimpperspectivetool.c
	* app/tools/gimprotatetool.c
	* app/tools/gimpscaletool.c
	* app/tools/gimpsheartool.c: changed accordingly.
parent 7e82d162
2006-06-20 Sven Neumann <sven@gimp.org>
* app/tools/tools-enums.h: added TRANSFORM_HANDLE_NONE (will get
rid of TRANSFORM_CREATING later).
* app/tools/gimptransformtool.[ch]: added member "use_handles" and
default to FALSE for all "use_foo" variables. Only deal with the
handles the specific transform tool asks for. Set cursors
according to the active handle.
* app/tools/gimpfliptool.c
* app/tools/gimpperspectivetool.c
* app/tools/gimprotatetool.c
* app/tools/gimpscaletool.c
* app/tools/gimpsheartool.c: changed accordingly.
2006-06-19 Sven Neumann <sven@gimp.org>
* app/actions/error-console-commands.c
......
......@@ -98,8 +98,7 @@ gimp_flip_tool_class_init (GimpFlipToolClass *klass)
static void
gimp_flip_tool_init (GimpFlipTool *flip_tool)
{
GimpTool *tool = GIMP_TOOL (flip_tool);
GimpTransformTool *transform_tool = GIMP_TRANSFORM_TOOL (flip_tool);
GimpTool *tool = GIMP_TOOL (flip_tool);
gimp_tool_control_set_snap_to (tool->control, FALSE);
gimp_tool_control_set_cursor (tool->control, GIMP_CURSOR_MOUSE);
......@@ -108,8 +107,6 @@ gimp_flip_tool_init (GimpFlipTool *flip_tool)
GIMP_TOOL_CURSOR_FLIP_HORIZONTAL);
gimp_tool_control_set_toggle_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_FLIP_VERTICAL);
transform_tool->use_grid = FALSE;
}
static void
......
......@@ -97,6 +97,10 @@ gimp_perspective_tool_init (GimpPerspectiveTool *perspective_tool)
tr_tool->shell_desc = _("Perspective Transform Information");
tr_tool->progress_text = _("Perspective");
tr_tool->use_grid = TRUE;
tr_tool->use_handles = TRUE;
tr_tool->use_center = TRUE;
}
static void
......
......@@ -114,6 +114,9 @@ gimp_rotate_tool_init (GimpRotateTool *rotate_tool)
tr_tool->shell_desc = _("Rotation Information");
tr_tool->progress_text = _("Rotating");
tr_tool->use_grid = TRUE;
tr_tool->use_center = TRUE;
}
static void
......
......@@ -107,6 +107,10 @@ gimp_scale_tool_init (GimpScaleTool *scale_tool)
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;
}
static void
......
......@@ -112,9 +112,10 @@ gimp_shear_tool_init (GimpShearTool *shear_tool)
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_SHEAR);
tr_tool->use_center = FALSE;
tr_tool->shell_desc = _("Shearing Information");
tr_tool->progress_text = _("Shearing");
tr_tool->use_grid = TRUE;
}
static void
......@@ -177,11 +178,8 @@ static void
gimp_shear_tool_motion (GimpTransformTool *tr_tool,
GimpDisplay *display)
{
gdouble diffx, diffy;
gint dir;
diffx = tr_tool->curx - tr_tool->lastx;
diffy = tr_tool->cury - tr_tool->lasty;
gdouble diffx = tr_tool->curx - tr_tool->lastx;
gdouble diffy = tr_tool->cury - tr_tool->lasty;
/* If we haven't yet decided on which way to control shearing
* decide using the maximum differential
......@@ -211,43 +209,19 @@ gimp_shear_tool_motion (GimpTransformTool *tr_tool,
}
/* if the direction is known, keep track of the magnitude */
if (tr_tool->trans_info[HORZ_OR_VERT] != GIMP_ORIENTATION_UNKNOWN)
if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_HORIZONTAL)
{
dir = tr_tool->trans_info[HORZ_OR_VERT];
switch (tr_tool->function)
{
case TRANSFORM_HANDLE_NW:
if (dir == GIMP_ORIENTATION_HORIZONTAL)
tr_tool->trans_info[XSHEAR] -= diffx;
else
tr_tool->trans_info[YSHEAR] -= diffy;
break;
case TRANSFORM_HANDLE_NE:
if (dir == GIMP_ORIENTATION_HORIZONTAL)
tr_tool->trans_info[XSHEAR] -= diffx;
else
tr_tool->trans_info[YSHEAR] += diffy;
break;
case TRANSFORM_HANDLE_SW:
if (dir == GIMP_ORIENTATION_HORIZONTAL)
tr_tool->trans_info[XSHEAR] += diffx;
else
tr_tool->trans_info[YSHEAR] -= diffy;
break;
case TRANSFORM_HANDLE_SE:
if (dir == GIMP_ORIENTATION_HORIZONTAL)
tr_tool->trans_info[XSHEAR] += diffx;
else
tr_tool->trans_info[YSHEAR] += diffy;
break;
default:
break;
}
if (tr_tool->cury > (tr_tool->ty1 + tr_tool->ty3) / 2)
tr_tool->trans_info[XSHEAR] += diffx;
else
tr_tool->trans_info[XSHEAR] -= diffx;
}
else if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_VERTICAL)
{
if (tr_tool->curx > (tr_tool->tx1 + tr_tool->tx2) / 2)
tr_tool->trans_info[YSHEAR] += diffy;
else
tr_tool->trans_info[YSHEAR] -= diffy;
}
}
......@@ -259,7 +233,9 @@ gimp_shear_tool_recalc (GimpTransformTool *tr_tool,
if (tr_tool->trans_info[XSHEAR] == 0.0 &&
tr_tool->trans_info[YSHEAR] == 0.0)
tr_tool->trans_info[HORZ_OR_VERT] = GIMP_ORIENTATION_UNKNOWN;
{
tr_tool->trans_info[HORZ_OR_VERT] = GIMP_ORIENTATION_UNKNOWN;
}
if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_HORIZONTAL)
amount = tr_tool->trans_info[XSHEAR];
......
......@@ -209,8 +209,9 @@ gimp_transform_tool_init (GimpTransformTool *tr_tool)
gimp_matrix3_identity (&tr_tool->transform);
tr_tool->use_grid = TRUE;
tr_tool->use_center = TRUE;
tr_tool->use_grid = FALSE;
tr_tool->use_handles = FALSE;
tr_tool->use_center = FALSE;
tr_tool->ngx = 0;
tr_tool->ngy = 0;
tr_tool->grid_coords = NULL;
......@@ -244,6 +245,7 @@ gimp_transform_tool_constructor (GType type,
{
tr_tool->type =
GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options)->type;
tr_tool->direction =
GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options)->direction;
......@@ -396,7 +398,7 @@ gimp_transform_tool_button_press (GimpTool *tool,
{
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
if (tr_tool->function == TRANSFORM_CREATING && tr_tool->use_grid)
if (tr_tool->function == TRANSFORM_CREATING)
gimp_transform_tool_oper_update (tool, coords, state, TRUE, display);
tr_tool->lastx = tr_tool->startx = coords->x;
......@@ -549,10 +551,12 @@ gimp_transform_tool_oper_update (GimpTool *tool,
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
if (! tr_tool->use_grid)
tr_tool->function = TRANSFORM_HANDLE_NONE;
if (display != tool->display)
return;
if (display == tool->display)
if (tr_tool->use_handles)
{
gdouble closest_dist;
gdouble dist;
......@@ -588,17 +592,18 @@ gimp_transform_tool_oper_update (GimpTool *tool,
closest_dist = dist;
tr_tool->function = TRANSFORM_HANDLE_SE;
}
}
if (gimp_draw_tool_on_handle (draw_tool, display,
coords->x, coords->y,
GIMP_HANDLE_CIRCLE,
tr_tool->tcx, tr_tool->tcy,
HANDLE_SIZE, HANDLE_SIZE,
GTK_ANCHOR_CENTER,
FALSE))
{
tr_tool->function = TRANSFORM_HANDLE_CENTER;
}
if (tr_tool->use_center &&
gimp_draw_tool_on_handle (draw_tool, display,
coords->x, coords->y,
GIMP_HANDLE_CIRCLE,
tr_tool->tcx, tr_tool->tcy,
HANDLE_SIZE, HANDLE_SIZE,
GTK_ANCHOR_CENTER,
FALSE))
{
tr_tool->function = TRANSFORM_HANDLE_CENTER;
}
}
......@@ -608,36 +613,60 @@ gimp_transform_tool_cursor_update (GimpTool *tool,
GdkModifierType state,
GimpDisplay *display)
{
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
GimpTransformOptions *options;
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_NONE;
if (tr_tool->use_grid)
options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
if (tr_tool->use_handles)
{
GimpTransformOptions *options;
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_NONE;
switch (tr_tool->function)
{
case TRANSFORM_HANDLE_NW:
gimp_tool_control_set_cursor (tool->control,
GIMP_CURSOR_CORNER_TOP_LEFT);
break;
options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
case TRANSFORM_HANDLE_NE:
gimp_tool_control_set_cursor (tool->control,
GIMP_CURSOR_CORNER_TOP_RIGHT);
break;
switch (options->type)
{
case GIMP_TRANSFORM_TYPE_LAYER:
case GIMP_TRANSFORM_TYPE_SELECTION:
case TRANSFORM_HANDLE_SW:
gimp_tool_control_set_cursor (tool->control,
GIMP_CURSOR_CORNER_BOTTOM_LEFT);
break;
case GIMP_TRANSFORM_TYPE_PATH:
if (! gimp_image_get_active_vectors (display->image))
modifier = GIMP_CURSOR_MODIFIER_BAD;
case TRANSFORM_HANDLE_SE:
gimp_tool_control_set_cursor (tool->control,
GIMP_CURSOR_CORNER_BOTTOM_RIGHT);
break;
}
if (tr_tool->use_center && tr_tool->function == TRANSFORM_HANDLE_CENTER)
{
if (modifier != GIMP_CURSOR_MODIFIER_BAD)
modifier = GIMP_CURSOR_MODIFIER_MOVE;
default:
gimp_tool_control_set_cursor (tool->control, GIMP_CURSOR_MOUSE);
}
}
if (tr_tool->use_center && tr_tool->function == TRANSFORM_HANDLE_CENTER)
{
modifier = GIMP_CURSOR_MODIFIER_MOVE;
}
gimp_tool_control_set_cursor_modifier (tool->control, modifier);
switch (options->type)
{
case GIMP_TRANSFORM_TYPE_LAYER:
case GIMP_TRANSFORM_TYPE_SELECTION:
break;
case GIMP_TRANSFORM_TYPE_PATH:
if (! gimp_image_get_active_vectors (display->image))
modifier = GIMP_CURSOR_MODIFIER_BAD;
break;
}
gimp_tool_control_set_cursor_modifier (tool->control, modifier);
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
}
......@@ -649,90 +678,93 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
GimpTransformOptions *options;
gdouble z1, z2, z3, z4;
if (! tr_tool->use_grid)
return;
options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
/* draw the bounding box */
gimp_draw_tool_draw_line (draw_tool,
tr_tool->tx1, tr_tool->ty1,
tr_tool->tx2, tr_tool->ty2,
FALSE);
gimp_draw_tool_draw_line (draw_tool,
tr_tool->tx2, tr_tool->ty2,
tr_tool->tx4, tr_tool->ty4,
FALSE);
gimp_draw_tool_draw_line (draw_tool,
tr_tool->tx3, tr_tool->ty3,
tr_tool->tx4, tr_tool->ty4,
FALSE);
gimp_draw_tool_draw_line (draw_tool,
tr_tool->tx3, tr_tool->ty3,
tr_tool->tx1, tr_tool->ty1,
FALSE);
/* We test if the transformed polygon is convex.
* if z1 and z2 have the same sign as well as z3 and z4
* the polygon is convex.
*/
z1 = ((tr_tool->tx2 - tr_tool->tx1) * (tr_tool->ty4 - tr_tool->ty1) -
(tr_tool->tx4 - tr_tool->tx1) * (tr_tool->ty2 - tr_tool->ty1));
z2 = ((tr_tool->tx4 - tr_tool->tx1) * (tr_tool->ty3 - tr_tool->ty1) -
(tr_tool->tx3 - tr_tool->tx1) * (tr_tool->ty4 - tr_tool->ty1));
z3 = ((tr_tool->tx4 - tr_tool->tx2) * (tr_tool->ty3 - tr_tool->ty2) -
(tr_tool->tx3 - tr_tool->tx2) * (tr_tool->ty4 - tr_tool->ty2));
z4 = ((tr_tool->tx3 - tr_tool->tx2) * (tr_tool->ty1 - tr_tool->ty2) -
(tr_tool->tx1 - tr_tool->tx2) * (tr_tool->ty3 - tr_tool->ty2));
/* Draw the grid (not for path transform since it looks ugly) */
if (tr_tool->type != GIMP_TRANSFORM_TYPE_PATH &&
tr_tool->grid_coords &&
tr_tool->tgrid_coords &&
z1 * z2 > 0 &&
z3 * z4 > 0)
if (tr_tool->use_grid)
{
gint gci, i, k;
k = tr_tool->ngx + tr_tool->ngy;
options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
for (i = 0, gci = 0; i < k; i++, gci += 4)
/* draw the bounding box */
gimp_draw_tool_draw_line (draw_tool,
tr_tool->tx1, tr_tool->ty1,
tr_tool->tx2, tr_tool->ty2,
FALSE);
gimp_draw_tool_draw_line (draw_tool,
tr_tool->tx2, tr_tool->ty2,
tr_tool->tx4, tr_tool->ty4,
FALSE);
gimp_draw_tool_draw_line (draw_tool,
tr_tool->tx3, tr_tool->ty3,
tr_tool->tx4, tr_tool->ty4,
FALSE);
gimp_draw_tool_draw_line (draw_tool,
tr_tool->tx3, tr_tool->ty3,
tr_tool->tx1, tr_tool->ty1,
FALSE);
/* We test if the transformed polygon is convex.
* if z1 and z2 have the same sign as well as z3 and z4
* the polygon is convex.
*/
z1 = ((tr_tool->tx2 - tr_tool->tx1) * (tr_tool->ty4 - tr_tool->ty1) -
(tr_tool->tx4 - tr_tool->tx1) * (tr_tool->ty2 - tr_tool->ty1));
z2 = ((tr_tool->tx4 - tr_tool->tx1) * (tr_tool->ty3 - tr_tool->ty1) -
(tr_tool->tx3 - tr_tool->tx1) * (tr_tool->ty4 - tr_tool->ty1));
z3 = ((tr_tool->tx4 - tr_tool->tx2) * (tr_tool->ty3 - tr_tool->ty2) -
(tr_tool->tx3 - tr_tool->tx2) * (tr_tool->ty4 - tr_tool->ty2));
z4 = ((tr_tool->tx3 - tr_tool->tx2) * (tr_tool->ty1 - tr_tool->ty2) -
(tr_tool->tx1 - tr_tool->tx2) * (tr_tool->ty3 - tr_tool->ty2));
/* Draw the grid (not for path transform since it looks ugly) */
if (tr_tool->type != GIMP_TRANSFORM_TYPE_PATH &&
tr_tool->grid_coords &&
tr_tool->tgrid_coords &&
z1 * z2 > 0 &&
z3 * z4 > 0)
{
gimp_draw_tool_draw_line (draw_tool,
tr_tool->tgrid_coords[gci],
tr_tool->tgrid_coords[gci + 1],
tr_tool->tgrid_coords[gci + 2],
tr_tool->tgrid_coords[gci + 3],
FALSE);
gint gci, i, k;
k = tr_tool->ngx + tr_tool->ngy;
for (i = 0, gci = 0; i < k; i++, gci += 4)
{
gimp_draw_tool_draw_line (draw_tool,
tr_tool->tgrid_coords[gci],
tr_tool->tgrid_coords[gci + 1],
tr_tool->tgrid_coords[gci + 2],
tr_tool->tgrid_coords[gci + 3],
FALSE);
}
}
}
/* draw the tool handles */
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_SQUARE,
tr_tool->tx1, tr_tool->ty1,
HANDLE_SIZE, HANDLE_SIZE,
GTK_ANCHOR_CENTER,
FALSE);
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_SQUARE,
tr_tool->tx2, tr_tool->ty2,
HANDLE_SIZE, HANDLE_SIZE,
GTK_ANCHOR_CENTER,
FALSE);
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_SQUARE,
tr_tool->tx3, tr_tool->ty3,
HANDLE_SIZE, HANDLE_SIZE,
GTK_ANCHOR_CENTER,
FALSE);
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_SQUARE,
tr_tool->tx4, tr_tool->ty4,
HANDLE_SIZE, HANDLE_SIZE,
GTK_ANCHOR_CENTER,
FALSE);
if (tr_tool->use_handles)
{
/* draw the tool handles */
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_SQUARE,
tr_tool->tx1, tr_tool->ty1,
HANDLE_SIZE, HANDLE_SIZE,
GTK_ANCHOR_CENTER,
FALSE);
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_SQUARE,
tr_tool->tx2, tr_tool->ty2,
HANDLE_SIZE, HANDLE_SIZE,
GTK_ANCHOR_CENTER,
FALSE);
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_SQUARE,
tr_tool->tx3, tr_tool->ty3,
HANDLE_SIZE, HANDLE_SIZE,
GTK_ANCHOR_CENTER,
FALSE);
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_SQUARE,
tr_tool->tx4, tr_tool->ty4,
HANDLE_SIZE, HANDLE_SIZE,
GTK_ANCHOR_CENTER,
FALSE);
}
/* draw the center */
if (tr_tool->use_center)
......@@ -796,7 +828,9 @@ gimp_transform_tool_dialog_update (GimpTransformTool *tr_tool)
{
if (tr_tool->dialog &&
GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog_update)
GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog_update (tr_tool);
{
GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog_update (tr_tool);
}
}
static TileManager *
......
......@@ -76,7 +76,8 @@ struct _GimpTransformTool
TransformAction function; /* current tool activity */
gboolean use_grid; /* does the tool use the grid */
gboolean use_center; /* use the center handle */
gboolean use_handles; /* uses the corner handles */
gboolean use_center; /* uses the center handle */
gint ngx, ngy; /* number of grid lines in original
* x and y directions
......
......@@ -169,6 +169,7 @@ typedef enum /*< skip >*/
typedef enum /*< skip >*/
{
TRANSFORM_CREATING,
TRANSFORM_HANDLE_NONE,
TRANSFORM_HANDLE_NW, /* north west */
TRANSFORM_HANDLE_NE, /* north east */
TRANSFORM_HANDLE_SW, /* south west */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment