Commit 80492e66 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

added stock *items* (not only icons) for all tools so they can be used as

2001-11-22  Michael Natterer  <mitch@gimp.org>

	* libgimpwidgets/gimpstock.c: added stock *items* (not only icons)
	for all tools so they can be used as action buttons.

	* app/tools/gimptransformtool.[ch]: added
	transform_tool->use_center so subclasses can switch on/off center
	detection/cursor_update . Added an oper_update() implementation
	and figure the current handle out there. Reordered button_press()
	so we don't need to call it recursively.

	* app/tools/gimpperspectivetool.c
	* app/tools/gimprotatetool.c
	* app/tools/gimpscaletool.c
	* app/tools/gimpsheartool.c: use the new stock items instead of
	_("Rotate") etc.

	* app/tools/gimpperspectivetool.c
	* app/tools/gimpscaletool.c: allow the whole thing being dragged
	around by handling the center separately.

	* app/tools/gimpdrawtool.c: gimp_draw_tool_on_handle(): need to
	use the radius, not the diameter to check if being over a
	GIMP_HANDLE_CIRCLE handle.
parent a08f3ac0
2001-11-22 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/gimpstock.c: added stock *items* (not only icons)
for all tools so they can be used as action buttons.
* app/tools/gimptransformtool.[ch]: added
transform_tool->use_center so subclasses can switch on/off center
detection/cursor_update . Added an oper_update() implementation
and figure the current handle out there. Reordered button_press()
so we don't need to call it recursively.
* app/tools/gimpperspectivetool.c
* app/tools/gimprotatetool.c
* app/tools/gimpscaletool.c
* app/tools/gimpsheartool.c: use the new stock items instead of
_("Rotate") etc.
* app/tools/gimpperspectivetool.c
* app/tools/gimpscaletool.c: allow the whole thing being dragged
around by handling the center separately.
* app/tools/gimpdrawtool.c: gimp_draw_tool_on_handle(): need to
use the radius, not the diameter to check if being over a
GIMP_HANDLE_CIRCLE handle.
2001-11-22 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/gimpwidgets.[ch]: use "gimp-item-data" instead of
......
......@@ -627,7 +627,9 @@ gimp_draw_tool_on_handle (GimpDrawTool *draw_tool,
/* FIXME */
if (width != height)
width = (width + height) >> 1;
width = (width + height) / 2;
width /= 2;
return ((SQR (handle_tx - tx) + SQR (handle_ty - ty)) < SQR (width));
......
......@@ -147,7 +147,7 @@ gimp_perspective_tool_transform (GimpTransformTool *transform_tool,
"tools/transform_perspective.html");
gimp_transform_tool_info_dialog_connect (transform_tool,
_("Transform"));
GIMP_STOCK_TOOL_PERSPECTIVE);
info_dialog_add_label (transform_tool->info_dialog, _("Matrix:"),
matrix_row_buf[0]);
......@@ -221,20 +221,30 @@ perspective_tool_motion (GimpTransformTool *transform_tool,
switch (transform_tool->function)
{
case TRANSFORM_HANDLE_1:
transform_tool->trans_info [X0] += diff_x;
transform_tool->trans_info [Y0] += diff_y;
transform_tool->trans_info[X0] += diff_x;
transform_tool->trans_info[Y0] += diff_y;
break;
case TRANSFORM_HANDLE_2:
transform_tool->trans_info [X1] += diff_x;
transform_tool->trans_info [Y1] += diff_y;
transform_tool->trans_info[X1] += diff_x;
transform_tool->trans_info[Y1] += diff_y;
break;
case TRANSFORM_HANDLE_3:
transform_tool->trans_info [X2] += diff_x;
transform_tool->trans_info [Y2] += diff_y;
transform_tool->trans_info[X2] += diff_x;
transform_tool->trans_info[Y2] += diff_y;
break;
case TRANSFORM_HANDLE_4:
transform_tool->trans_info [X3] += diff_x;
transform_tool->trans_info [Y3] += diff_y;
transform_tool->trans_info[X3] += diff_x;
transform_tool->trans_info[Y3] += diff_y;
break;
case TRANSFORM_HANDLE_CENTER:
transform_tool->trans_info[X0] += diff_x;
transform_tool->trans_info[Y0] += diff_y;
transform_tool->trans_info[X1] += diff_x;
transform_tool->trans_info[Y1] += diff_y;
transform_tool->trans_info[X2] += diff_x;
transform_tool->trans_info[Y2] += diff_y;
transform_tool->trans_info[X3] += diff_x;
transform_tool->trans_info[Y3] += diff_y;
break;
default:
break;
......
......@@ -176,7 +176,7 @@ gimp_rotate_tool_transform (GimpTransformTool *transform_tool,
"tools/transform_rotate.html");
gimp_transform_tool_info_dialog_connect (transform_tool,
_("Rotate"));
GIMP_STOCK_TOOL_ROTATE);
widget =
info_dialog_add_spinbutton (transform_tool->info_dialog, _("Angle:"),
......
......@@ -173,7 +173,7 @@ gimp_scale_tool_transform (GimpTransformTool *transform_tool,
"tools/transform_scale.html");
gimp_transform_tool_info_dialog_connect (transform_tool,
_("Scale"));
GIMP_STOCK_TOOL_SCALE);
info_dialog_add_label (transform_tool->info_dialog,
_("Original Width:"),
......@@ -327,10 +327,10 @@ gimp_scale_tool_info_update (GimpTransformTool *transform_tool)
}
/* Find current sizes */
x3 = (gint) transform_tool->trans_info [X0];
y3 = (gint) transform_tool->trans_info [Y0];
x4 = (gint) transform_tool->trans_info [X1];
y4 = (gint) transform_tool->trans_info [Y1];
x3 = (gint) transform_tool->trans_info[X0];
y3 = (gint) transform_tool->trans_info[Y0];
x4 = (gint) transform_tool->trans_info[X1];
y4 = (gint) transform_tool->trans_info[Y1];
size_vals[0] = x4 - x3;
size_vals[1] = y4 - y3;
......@@ -406,36 +406,44 @@ gimp_scale_tool_motion (GimpTransformTool *transform_tool,
switch (transform_tool->function)
{
case TRANSFORM_HANDLE_1:
x1 = &transform_tool->trans_info [X0];
y1 = &transform_tool->trans_info [Y0];
x2 = &transform_tool->trans_info [X1];
y2 = &transform_tool->trans_info [Y1];
x1 = &transform_tool->trans_info[X0];
y1 = &transform_tool->trans_info[Y0];
x2 = &transform_tool->trans_info[X1];
y2 = &transform_tool->trans_info[Y1];
dir_x = dir_y = 1;
break;
case TRANSFORM_HANDLE_2:
x1 = &transform_tool->trans_info [X1];
y1 = &transform_tool->trans_info [Y0];
x2 = &transform_tool->trans_info [X0];
y2 = &transform_tool->trans_info [Y1];
x1 = &transform_tool->trans_info[X1];
y1 = &transform_tool->trans_info[Y0];
x2 = &transform_tool->trans_info[X0];
y2 = &transform_tool->trans_info[Y1];
dir_x = -1;
dir_y = 1;
break;
case TRANSFORM_HANDLE_3:
x1 = &transform_tool->trans_info [X0];
y1 = &transform_tool->trans_info [Y1];
x2 = &transform_tool->trans_info [X1];
y2 = &transform_tool->trans_info [Y0];
x1 = &transform_tool->trans_info[X0];
y1 = &transform_tool->trans_info[Y1];
x2 = &transform_tool->trans_info[X1];
y2 = &transform_tool->trans_info[Y0];
dir_x = 1;
dir_y = -1;
break;
case TRANSFORM_HANDLE_4:
x1 = &transform_tool->trans_info [X1];
y1 = &transform_tool->trans_info [Y1];
x2 = &transform_tool->trans_info [X0];
y2 = &transform_tool->trans_info [Y0];
x1 = &transform_tool->trans_info[X1];
y1 = &transform_tool->trans_info[Y1];
x2 = &transform_tool->trans_info[X0];
y2 = &transform_tool->trans_info[Y0];
dir_x = dir_y = -1;
break;
case TRANSFORM_HANDLE_CENTER:
transform_tool->trans_info[X0] += diff_x;
transform_tool->trans_info[Y0] += diff_y;
transform_tool->trans_info[X1] += diff_x;
transform_tool->trans_info[Y1] += diff_y;
transform_tool->trans_info[X2] += diff_x;
transform_tool->trans_info[Y2] += diff_y;
transform_tool->trans_info[X3] += diff_x;
transform_tool->trans_info[Y3] += diff_y;
return;
default:
return;
......
......@@ -141,11 +141,15 @@ gimp_shear_tool_class_init (GimpShearToolClass *klass)
static void
gimp_shear_tool_init (GimpShearTool *shear_tool)
{
GimpTool *tool;
GimpTool *tool;
GimpTransformTool *transform_tool;
tool = GIMP_TOOL (shear_tool);
tool = GIMP_TOOL (shear_tool);
transform_tool = GIMP_TRANSFORM_TOOL (shear_tool);
tool->tool_cursor = GIMP_SHEAR_TOOL_CURSOR;
transform_tool->use_center = FALSE;
}
static TileManager *
......@@ -164,7 +168,7 @@ gimp_shear_tool_transform (GimpTransformTool *transform_tool,
"tools/transform_shear.html");
gimp_transform_tool_info_dialog_connect (transform_tool,
_("Shear"));
GIMP_STOCK_TOOL_SHEAR);
info_dialog_add_spinbutton (transform_tool->info_dialog,
_("Shear Magnitude X:"),
......
......@@ -87,6 +87,10 @@ static void gimp_transform_tool_motion (GimpTool *tool,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_transform_tool_oper_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_transform_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
......@@ -165,6 +169,7 @@ gimp_transform_tool_class_init (GimpTransformToolClass *klass)
tool_class->button_press = gimp_transform_tool_button_press;
tool_class->button_release = gimp_transform_tool_button_release;
tool_class->motion = gimp_transform_tool_motion;
tool_class->oper_update = gimp_transform_tool_oper_update;
tool_class->cursor_update = gimp_transform_tool_cursor_update;
draw_class->draw = gimp_transform_tool_draw;
......@@ -190,6 +195,7 @@ gimp_transform_tool_init (GimpTransformTool *transform_tool)
gimp_matrix3_identity (transform_tool->transform);
transform_tool->use_grid = TRUE;
transform_tool->use_center = TRUE;
transform_tool->ngx = 0;
transform_tool->ngy = 0;
transform_tool->grid_coords = NULL;
......@@ -285,6 +291,67 @@ gimp_transform_tool_button_press (GimpTool *tool,
drawable = gimp_image_active_drawable (gdisp->gimage);
if (gdisp != tool->gdisp)
{
/* Initialisation stuff: if the cursor is clicked inside the current
* selection, show the bounding box and handles...
*/
gimp_drawable_offsets (drawable, &off_x, &off_y);
if (coords->x >= off_x &&
coords->y >= off_y &&
coords->x < (off_x + gimp_drawable_width (drawable)) &&
coords->y < (off_y + gimp_drawable_height (drawable)))
{
if (gimage_mask_is_empty (gdisp->gimage) ||
gimage_mask_value (gdisp->gimage, coords->x, coords->y))
{
if (GIMP_IS_LAYER (drawable) &&
gimp_layer_get_mask (GIMP_LAYER (drawable)))
{
g_message (_("Transformations do not work on\n"
"layers that contain layer masks."));
tool->state = INACTIVE;
return;
}
/* If the tool is already active, clear the current state
* and reset
*/
if (tool->state == ACTIVE)
{
g_warning ("%s: tool_already ACTIVE", G_GNUC_FUNCTION);
gimp_transform_tool_reset (tr_tool, gdisp);
}
/* Set the pointer to the active display */
tool->gdisp = gdisp;
tool->drawable = drawable;
tool->state = ACTIVE;
/* Find the transform bounds for some tools (like scale,
* perspective) that actually need the bounds for
* initializing
*/
gimp_transform_tool_bounds (tr_tool, gdisp);
/* Initialize the transform tool */
gimp_transform_tool_transform (tr_tool, gdisp, TRANSFORM_INIT);
/* Recalculate the transform tool */
gimp_transform_tool_recalc (tr_tool, gdisp);
/* start drawing the bounding box and handles... */
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool),
shell->canvas->window);
/* find which handle we're dragging */
gimp_transform_tool_oper_update (tool, coords, state, gdisp);
}
}
}
if (tr_tool->function == TRANSFORM_CREATING && tool->state == ACTIVE)
{
gint i;
......@@ -300,52 +367,6 @@ gimp_transform_tool_button_press (GimpTool *tool,
*/
if (gdisp == tool->gdisp)
{
gdouble closest_dist;
gdouble dist;
closest_dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
coords->x, coords->y,
tr_tool->tx1, tr_tool->ty1);
tr_tool->function = TRANSFORM_HANDLE_1;
dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
coords->x, coords->y,
tr_tool->tx2, tr_tool->ty2);
if (dist < closest_dist)
{
closest_dist = dist;
tr_tool->function = TRANSFORM_HANDLE_2;
}
dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
coords->x, coords->y,
tr_tool->tx3, tr_tool->ty3);
if (dist < closest_dist)
{
closest_dist = dist;
tr_tool->function = TRANSFORM_HANDLE_3;
}
dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
coords->x, coords->y,
tr_tool->tx4, tr_tool->ty4);
if (dist < closest_dist)
{
closest_dist = dist;
tr_tool->function = TRANSFORM_HANDLE_4;
}
if (gimp_draw_tool_on_handle (draw_tool, gdisp,
coords->x, coords->y,
GIMP_HANDLE_CIRCLE,
tr_tool->tcx, tr_tool->tcy,
HANDLE, HANDLE,
GIMP_HANDLE_CIRCLE,
FALSE))
{
tr_tool->function = TRANSFORM_HANDLE_CENTER;
}
/* Save the current pointer position */
tr_tool->lastx = tr_tool->startx = coords->x;
tr_tool->lasty = tr_tool->starty = coords->y;
......@@ -357,64 +378,6 @@ gimp_transform_tool_button_press (GimpTool *tool,
NULL, NULL, time);
tool->state = ACTIVE;
return;
}
/* Initialisation stuff: if the cursor is clicked inside the current
* selection, show the bounding box and handles...
*/
gimp_drawable_offsets (drawable, &off_x, &off_y);
if (coords->x >= off_x &&
coords->y >= off_y &&
coords->x < (off_x + gimp_drawable_width (drawable)) &&
coords->y < (off_y + gimp_drawable_height (drawable)))
{
if (gimage_mask_is_empty (gdisp->gimage) ||
gimage_mask_value (gdisp->gimage, coords->x, coords->y))
{
if (GIMP_IS_LAYER (drawable) &&
gimp_layer_get_mask (GIMP_LAYER (drawable)))
{
g_message (_("Transformations do not work on\n"
"layers that contain layer masks."));
tool->state = INACTIVE;
return;
}
/* If the tool is already active, clear the current state
* and reset
*/
if (tool->state == ACTIVE)
{
g_warning ("%s: tool_already ACTIVE", G_GNUC_FUNCTION);
gimp_transform_tool_reset (tr_tool, gdisp);
}
/* Set the pointer to the active display */
tool->gdisp = gdisp;
tool->drawable = drawable;
tool->state = ACTIVE;
/* Find the transform bounds for some tools (like scale,
* perspective) that actually need the bounds for
* initializing
*/
gimp_transform_tool_bounds (tr_tool, gdisp);
/* Initialize the transform tool */
gimp_transform_tool_transform (tr_tool, gdisp, TRANSFORM_INIT);
/* Recalculate the transform tool */
gimp_transform_tool_recalc (tr_tool, gdisp);
/* start drawing the bounding box and handles... */
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), shell->canvas->window);
/* recall this function to find which handle we're dragging */
gimp_transform_tool_button_press (tool, coords, time, state, gdisp);
}
}
}
......@@ -502,14 +465,80 @@ gimp_transform_tool_motion (GimpTool *tool,
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
}
static void
gimp_transform_tool_oper_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpTransformTool *tr_tool;
GimpDrawTool *draw_tool;
tr_tool = GIMP_TRANSFORM_TOOL (tool);
draw_tool = GIMP_DRAW_TOOL (tool);
if (gdisp == tool->gdisp)
{
gdouble closest_dist;
gdouble dist;
closest_dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
coords->x, coords->y,
tr_tool->tx1, tr_tool->ty1);
tr_tool->function = TRANSFORM_HANDLE_1;
dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
coords->x, coords->y,
tr_tool->tx2, tr_tool->ty2);
if (dist < closest_dist)
{
closest_dist = dist;
tr_tool->function = TRANSFORM_HANDLE_2;
}
dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
coords->x, coords->y,
tr_tool->tx3, tr_tool->ty3);
if (dist < closest_dist)
{
closest_dist = dist;
tr_tool->function = TRANSFORM_HANDLE_3;
}
dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
coords->x, coords->y,
tr_tool->tx4, tr_tool->ty4);
if (dist < closest_dist)
{
closest_dist = dist;
tr_tool->function = TRANSFORM_HANDLE_4;
}
if (gimp_draw_tool_on_handle (draw_tool, gdisp,
coords->x, coords->y,
GIMP_HANDLE_CIRCLE,
tr_tool->tcx, tr_tool->tcy,
HANDLE, HANDLE,
GTK_ANCHOR_CENTER,
FALSE))
{
tr_tool->function = TRANSFORM_HANDLE_CENTER;
}
}
}
static void
gimp_transform_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpDrawable *drawable;
GdkCursorType ctype = GDK_TOP_LEFT_ARROW;
GimpTransformTool *tr_tool;
GimpDrawable *drawable;
GdkCursorType ctype = GDK_TOP_LEFT_ARROW;
GimpCursorModifier cmodifier = GIMP_CURSOR_MODIFIER_NONE;
tr_tool = GIMP_TRANSFORM_TOOL (tool);
if ((drawable = gimp_image_active_drawable (gdisp->gimage)))
{
......@@ -535,10 +564,15 @@ gimp_transform_tool_cursor_update (GimpTool *tool,
}
}
if (tr_tool->use_center && tr_tool->function == TRANSFORM_HANDLE_CENTER)
{
cmodifier = GIMP_CURSOR_MODIFIER_MOVE;
}
gimp_display_shell_install_tool_cursor (GIMP_DISPLAY_SHELL (gdisp->shell),
ctype,
tool->tool_cursor,
GIMP_CURSOR_MODIFIER_NONE);
cmodifier);
}
static void
......@@ -619,12 +653,15 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
FALSE);
/* draw the center */
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_FILLED_CIRCLE,
tr_tool->tcx, tr_tool->tcy,
HANDLE, HANDLE,
GTK_ANCHOR_CENTER,
FALSE);
if (tr_tool->use_center)
{
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_FILLED_CIRCLE,
tr_tool->tcx, tr_tool->tcy,
HANDLE, HANDLE,
GTK_ANCHOR_CENTER,
FALSE);
}
if (options->show_path)
{
......@@ -764,7 +801,8 @@ gimp_transform_tool_transform_tiles (GimpTransformTool *transform_tool,
g_return_val_if_fail (progress_text != NULL, NULL);
if (transform_tool->info_dialog)
gtk_widget_set_sensitive (GTK_WIDGET (transform_tool->info_dialog), FALSE);
gtk_widget_set_sensitive (GTK_WIDGET (transform_tool->info_dialog->shell),
FALSE);
tool = GIMP_TOOL (transform_tool);
......@@ -791,11 +829,7 @@ gimp_transform_tool_transform_tiles (GimpTransformTool *transform_tool,
void
gimp_transform_tool_transform_bounding_box (GimpTransformTool *tr_tool)
{
GimpTool *tool;
gint i, k;
gint gci;
tool = GIMP_TOOL (tr_tool);
g_return_if_fail (GIMP_IS_TRANSFORM_TOOL (tr_tool));
gimp_matrix3_transform_point (tr_tool->transform,
tr_tool->x1, tr_tool->y1,
......@@ -814,11 +848,13 @@ gimp_transform_tool_transform_bounding_box (GimpTransformTool *tr_tool)
tr_tool->cx, tr_tool->cy,
&tr_tool->tcx, &tr_tool->tcy);
if (tr_tool->grid_coords != NULL &&
tr_tool->tgrid_coords != NULL)
if (tr_tool->grid_coords != NULL && tr_tool->tgrid_coords != NULL)
{
gint i, k;
gint gci;
gci = 0;
k = (tr_tool->ngx + tr_tool->ngy) * 2;
k = (tr_tool->ngx + tr_tool->ngy) * 2;
for (i = 0; i < k; i++)
{
......@@ -915,7 +951,7 @@ gimp_transform_tool_info_dialog_connect (GimpTransformTool *tr_tool,
ok_button, transform_ok_callback,
tr_tool, NULL, NULL, TRUE, FALSE,
_("Reset"), transform_reset_callback,
GIMP_STOCK_RESET, transform_reset_callback,
tr_tool, NULL, NULL, FALSE, FALSE,
NULL);
......
......@@ -80,6 +80,7 @@ struct _GimpTransformTool
TransformAction function; /* current tool activity */
gboolean use_grid; /* does the tool use the grid */
gboolean use_center; /* use the center handle */
gint ngx, ngy; /* number of grid lines in original
* x and y directions
......
......@@ -110,7 +110,46 @@ static GtkStockItem gimp_stock_items[] =
{ GIMP_STOCK_SELECTION_REPLACE, NULL, 0, 0, "gimp-libgimp" },
{ GIMP_STOCK_SELECTION_ADD, NULL, 0, 0, "gimp-libgimp" },
{ GIMP_STOCK_SELECTION_SUBTRACT, NULL, 0, 0, "gimp-libgimp" },
{ GIMP_STOCK_SELECTION_INTERSECT, NULL, 0, 0, "gimp-libgimp" }
{ GIMP_STOCK_SELECTION_INTERSECT, NULL, 0, 0, "gimp-libgimp" },