Commit 0d3f7193 authored by Michael Natterer's avatar Michael Natterer 😴

app: add gimp_draw_tool_set_widget() and use it in all ported tools

which so far manages drawing of the widget's GimpCanvasItem. Remove
GimpDrawTool::draw() implementations from most of the affected tools.
parent 87e6de78
......@@ -119,8 +119,6 @@ static void gimp_blend_tool_options_notify (GimpTool *tool,
GimpToolOptions *options,
const GParamSpec *pspec);
static void gimp_blend_tool_draw (GimpDrawTool *draw_tool);
static void gimp_blend_tool_start (GimpBlendTool *blend_tool,
GimpDisplay *display);
static void gimp_blend_tool_halt (GimpBlendTool *blend_tool);
......@@ -189,9 +187,8 @@ gimp_blend_tool_register (GimpToolRegisterCallback callback,
static void
gimp_blend_tool_class_init (GimpBlendToolClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
object_class->dispose = gimp_blend_tool_dispose;
......@@ -209,8 +206,6 @@ gimp_blend_tool_class_init (GimpBlendToolClass *klass)
tool_class->undo = gimp_blend_tool_undo;
tool_class->redo = gimp_blend_tool_redo;
tool_class->options_notify = gimp_blend_tool_options_notify;
draw_tool_class->draw = gimp_blend_tool_draw;
}
static void
......@@ -368,6 +363,8 @@ gimp_blend_tool_button_press (GimpTool *tool,
blend_tool->end_x,
blend_tool->end_y);
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), blend_tool->line);
gimp_tool_widget_hover (blend_tool->line, coords, state, TRUE);
g_signal_connect (blend_tool->line, "changed",
......@@ -682,19 +679,6 @@ gimp_blend_tool_options_notify (GimpTool *tool,
}
}
static void
gimp_blend_tool_draw (GimpDrawTool *draw_tool)
{
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (draw_tool);
if (blend_tool->line)
{
GimpCanvasItem *item = gimp_tool_widget_get_item (blend_tool->line);
gimp_draw_tool_add_item (draw_tool, item);
}
}
static void
gimp_blend_tool_start (GimpBlendTool *blend_tool,
GimpDisplay *display)
......
......@@ -87,8 +87,6 @@ static void gimp_crop_tool_options_notify (GimpTool
GimpToolOptions *options,
const GParamSpec *pspec);
static void gimp_crop_tool_draw (GimpDrawTool *draw_tool);
static void gimp_crop_tool_rectangle_changed (GimpToolWidget *rectangle,
GimpCropTool *crop_tool);
static void gimp_crop_tool_rectangle_response (GimpToolWidget *rectangle,
......@@ -156,9 +154,8 @@ gimp_crop_tool_register (GimpToolRegisterCallback callback,
static void
gimp_crop_tool_class_init (GimpCropToolClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
object_class->constructed = gimp_crop_tool_constructed;
......@@ -171,8 +168,6 @@ gimp_crop_tool_class_init (GimpCropToolClass *klass)
tool_class->oper_update = gimp_crop_tool_oper_update;
tool_class->cursor_update = gimp_crop_tool_cursor_update;
tool_class->options_notify = gimp_crop_tool_options_notify;
draw_tool_class->draw = gimp_crop_tool_draw;
}
static void
......@@ -280,6 +275,8 @@ gimp_crop_tool_button_press (GimpTool *tool,
crop_tool->rectangle = widget = gimp_tool_rectangle_new (shell);
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), widget);
for (i = 0; i < G_N_ELEMENTS (properties); i++)
g_object_bind_property (G_OBJECT (options), properties[i],
G_OBJECT (widget), properties[i],
......@@ -459,19 +456,6 @@ gimp_crop_tool_options_notify (GimpTool *tool,
}
}
static void
gimp_crop_tool_draw (GimpDrawTool *draw_tool)
{
GimpCropTool *crop_tool = GIMP_CROP_TOOL (draw_tool);
if (crop_tool->rectangle)
{
GimpCanvasItem *item = gimp_tool_widget_get_item (crop_tool->rectangle);
gimp_draw_tool_add_item (draw_tool, item);
}
}
static void
gimp_crop_tool_rectangle_changed (GimpToolWidget *rectangle,
GimpCropTool *crop_tool)
......
......@@ -49,6 +49,7 @@
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-items.h"
#include "display/gimpdisplayshell-transform.h"
#include "display/gimptoolwidget.h"
#include "gimpdrawtool.h"
......@@ -164,6 +165,7 @@ gimp_draw_tool_control (GimpTool *tool,
case GIMP_TOOL_ACTION_HALT:
if (gimp_draw_tool_is_active (draw_tool))
gimp_draw_tool_stop (draw_tool);
gimp_draw_tool_set_widget (draw_tool, NULL);
break;
case GIMP_TOOL_ACTION_COMMIT:
......@@ -269,7 +271,12 @@ gimp_draw_tool_undraw (GimpDrawTool *draw_tool)
static void
gimp_draw_tool_real_draw (GimpDrawTool *draw_tool)
{
/* the default implementation does nothing */
if (draw_tool->widget)
{
GimpCanvasItem *item = gimp_tool_widget_get_item (draw_tool->widget);
gimp_draw_tool_add_item (draw_tool, item);
}
}
void
......@@ -424,6 +431,43 @@ gimp_draw_tool_calc_distance_square (GimpDrawTool *draw_tool,
return SQR (tx2 - tx1) + SQR (ty2 - ty1);
}
void
gimp_draw_tool_set_widget (GimpDrawTool *draw_tool,
GimpToolWidget *widget)
{
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
g_return_if_fail (widget == NULL || GIMP_IS_TOOL_WIDGET (widget));
if (widget == draw_tool->widget)
return;
if (draw_tool->widget)
{
if (gimp_draw_tool_is_active (draw_tool))
{
GimpCanvasItem *item = gimp_tool_widget_get_item (draw_tool->widget);
gimp_draw_tool_remove_item (draw_tool, item);
}
g_object_unref (draw_tool->widget);
}
draw_tool->widget = widget;
if (draw_tool->widget)
{
g_object_ref (draw_tool->widget);
if (gimp_draw_tool_is_active (draw_tool))
{
GimpCanvasItem *item = gimp_tool_widget_get_item (draw_tool->widget);
gimp_draw_tool_add_item (draw_tool, item);
}
}
}
void
gimp_draw_tool_add_preview (GimpDrawTool *draw_tool,
GimpCanvasItem *item)
......
......@@ -51,6 +51,7 @@ struct _GimpDrawTool
guint draw_timeout; /* draw delay timeout ID */
guint64 last_draw_time; /* time of last draw(), monotonically */
GimpToolWidget *widget;
GimpCanvasItem *preview;
GimpCanvasItem *item;
GList *group_stack;
......@@ -90,6 +91,9 @@ gdouble gimp_draw_tool_calc_distance_square (GimpDrawTool *draw_too
gdouble x2,
gdouble y2);
void gimp_draw_tool_set_widget (GimpDrawTool *draw_tool,
GimpToolWidget *widget);
void gimp_draw_tool_add_preview (GimpDrawTool *draw_tool,
GimpCanvasItem *item);
void gimp_draw_tool_remove_preview (GimpDrawTool *draw_tool,
......
......@@ -98,8 +98,6 @@ static void gimp_free_select_tool_active_modifier_key (GimpTool
GdkModifierType state,
GimpDisplay *display);
static void gimp_free_select_tool_draw (GimpDrawTool *draw_tool);
static void gimp_free_select_tool_real_select (GimpFreeSelectTool *fst,
GimpDisplay *display,
const GimpVector2 *points,
......@@ -142,9 +140,8 @@ gimp_free_select_tool_register (GimpToolRegisterCallback callback,
static void
gimp_free_select_tool_class_init (GimpFreeSelectToolClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
object_class->finalize = gimp_free_select_tool_finalize;
......@@ -158,8 +155,6 @@ gimp_free_select_tool_class_init (GimpFreeSelectToolClass *klass)
tool_class->modifier_key = gimp_free_select_tool_modifier_key;
tool_class->active_modifier_key = gimp_free_select_tool_active_modifier_key;
draw_tool_class->draw = gimp_free_select_tool_draw;
klass->select = gimp_free_select_tool_real_select;
g_type_class_add_private (klass, sizeof (GimpFreeSelectToolPrivate));
......@@ -340,6 +335,8 @@ gimp_free_select_tool_button_press (GimpTool *tool,
private->polygon = gimp_tool_polygon_new (shell);
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), private->polygon);
g_signal_connect (private->polygon, "changed",
G_CALLBACK (gimp_free_select_tool_polygon_changed),
fst);
......@@ -475,20 +472,6 @@ gimp_free_select_tool_active_modifier_key (GimpTool *tool,
}
}
static void
gimp_free_select_tool_draw (GimpDrawTool *draw_tool)
{
GimpFreeSelectTool *fst = GIMP_FREE_SELECT_TOOL (draw_tool);
GimpFreeSelectToolPrivate *priv = fst->private;
if (priv->polygon)
{
GimpCanvasItem *item = gimp_tool_widget_get_item (priv->polygon);
gimp_draw_tool_add_item (draw_tool, item);
}
}
static void
gimp_free_select_tool_real_select (GimpFreeSelectTool *fst,
GimpDisplay *display,
......
......@@ -90,8 +90,6 @@ static void gimp_measure_tool_cursor_update (GimpTool *tool,
GdkModifierType state,
GimpDisplay *display);
static void gimp_measure_tool_draw (GimpDrawTool *draw_tool);
static void gimp_measure_tool_compass_changed (GimpToolWidget *widget,
GimpMeasureTool *measure);
static void gimp_measure_tool_compass_status (GimpToolWidget *widget,
......@@ -140,8 +138,7 @@ gimp_measure_tool_register (GimpToolRegisterCallback callback,
static void
gimp_measure_tool_class_init (GimpMeasureToolClass *klass)
{
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
tool_class->control = gimp_measure_tool_control;
tool_class->button_press = gimp_measure_tool_button_press;
......@@ -151,8 +148,6 @@ gimp_measure_tool_class_init (GimpMeasureToolClass *klass)
tool_class->active_modifier_key = gimp_measure_tool_active_modifier_key;
tool_class->oper_update = gimp_measure_tool_oper_update;
tool_class->cursor_update = gimp_measure_tool_cursor_update;
draw_tool_class->draw = gimp_measure_tool_draw;
}
static void
......@@ -238,6 +233,8 @@ gimp_measure_tool_button_press (GimpTool *tool,
measure->x[2],
measure->y[2]);
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), measure->compass);
gimp_tool_widget_hover (measure->compass, coords, state, TRUE);
g_signal_connect (measure->compass, "changed",
......@@ -402,19 +399,6 @@ gimp_measure_tool_cursor_update (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
}
static void
gimp_measure_tool_draw (GimpDrawTool *draw_tool)
{
GimpMeasureTool *measure = GIMP_MEASURE_TOOL (draw_tool);
if (measure->compass)
{
GimpCanvasItem *item = gimp_tool_widget_get_item (measure->compass);
gimp_draw_tool_add_item (draw_tool, item);
}
}
static void
gimp_measure_tool_compass_changed (GimpToolWidget *widget,
GimpMeasureTool *measure)
......
......@@ -765,9 +765,7 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
G_BINDING_SYNC_CREATE |
G_BINDING_BIDIRECTIONAL);
item = gimp_tool_widget_get_item (tr_tool->widget);
gimp_draw_tool_add_item (draw_tool, item);
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
}
if (options->type == GIMP_TRANSFORM_TYPE_SELECTION)
......@@ -1369,6 +1367,8 @@ gimp_transform_tool_get_widget (GimpTransformTool *tr_tool)
widget = GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->get_widget (tr_tool);
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tr_tool), widget);
g_object_bind_property (G_OBJECT (options), "grid-type",
G_OBJECT (widget), "guide-type",
G_BINDING_SYNC_CREATE |
......
......@@ -106,8 +106,6 @@ static void gimp_vector_tool_cursor_update (GimpTool *tool,
GdkModifierType state,
GimpDisplay *display);
static void gimp_vector_tool_draw (GimpDrawTool *draw_tool);
static void gimp_vector_tool_start (GimpVectorTool *vector_tool,
GimpDisplay *display);
static void gimp_vector_tool_halt (GimpVectorTool *vector_tool);
......@@ -184,9 +182,8 @@ gimp_vector_tool_register (GimpToolRegisterCallback callback,
static void
gimp_vector_tool_class_init (GimpVectorToolClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
object_class->dispose = gimp_vector_tool_dispose;
......@@ -198,8 +195,6 @@ gimp_vector_tool_class_init (GimpVectorToolClass *klass)
tool_class->modifier_key = gimp_vector_tool_modifier_key;
tool_class->oper_update = gimp_vector_tool_oper_update;
tool_class->cursor_update = gimp_vector_tool_cursor_update;
draw_tool_class->draw = gimp_vector_tool_draw;
}
static void
......@@ -430,19 +425,6 @@ gimp_vector_tool_cursor_update (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
}
static void
gimp_vector_tool_draw (GimpDrawTool *draw_tool)
{
GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (draw_tool);
if (vector_tool->path)
{
GimpCanvasItem *item = gimp_tool_widget_get_item (vector_tool->path);
gimp_draw_tool_add_item (draw_tool, item);
}
}
static void
gimp_vector_tool_start (GimpVectorTool *vector_tool,
GimpDisplay *display)
......@@ -456,6 +438,8 @@ gimp_vector_tool_start (GimpVectorTool *vector_tool,
vector_tool->path = widget = gimp_tool_path_new (shell);
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), widget);
g_object_bind_property (G_OBJECT (options), "vectors-edit-mode",
G_OBJECT (widget), "edit-mode",
G_BINDING_SYNC_CREATE |
......
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