app: port GimpBlendTool to pause()/resume()-less drawing

Instead, keep around the created GimpCanvasItems, and update them when
the blend coordiates change. Add setters to GipmCanvasLine and
GimpCanvasHandle which take care of calling begin_change() and
end_change() on the items around the change, so thes invalidate
properly.
This commit is contained in:
Michael Natterer
2011-03-28 11:08:40 +02:00
parent 1c0fe73da4
commit aa5d2f8082
6 changed files with 120 additions and 46 deletions

View File

@ -402,6 +402,23 @@ gimp_canvas_handle_new (GimpDisplayShell *shell,
NULL); NULL);
} }
void
gimp_canvas_handle_set_position (GimpCanvasHandle *handle,
gdouble x,
gdouble y)
{
g_return_if_fail (GIMP_IS_CANVAS_HANDLE (handle));
gimp_canvas_item_begin_change (GIMP_CANVAS_ITEM (handle));
g_object_set (handle,
"x", x,
"y", y,
NULL);
gimp_canvas_item_end_change (GIMP_CANVAS_ITEM (handle));
}
void void
gimp_canvas_handle_set_angles (GimpCanvasHandle *handle, gimp_canvas_handle_set_angles (GimpCanvasHandle *handle,
gdouble start_angle, gdouble start_angle,
@ -409,8 +426,12 @@ gimp_canvas_handle_set_angles (GimpCanvasHandle *handle,
{ {
g_return_if_fail (GIMP_IS_CANVAS_HANDLE (handle)); g_return_if_fail (GIMP_IS_CANVAS_HANDLE (handle));
gimp_canvas_item_begin_change (GIMP_CANVAS_ITEM (handle));
g_object_set (handle, g_object_set (handle,
"start-angle", start_angle, "start-angle", start_angle,
"slice-angle", slice_angle, "slice-angle", slice_angle,
NULL); NULL);
gimp_canvas_item_end_change (GIMP_CANVAS_ITEM (handle));
} }

View File

@ -47,18 +47,22 @@ struct _GimpCanvasHandleClass
}; };
GType gimp_canvas_handle_get_type (void) G_GNUC_CONST; GType gimp_canvas_handle_get_type (void) G_GNUC_CONST;
GimpCanvasItem * gimp_canvas_handle_new (GimpDisplayShell *shell, GimpCanvasItem * gimp_canvas_handle_new (GimpDisplayShell *shell,
GimpHandleType type, GimpHandleType type,
GimpHandleAnchor anchor, GimpHandleAnchor anchor,
gdouble x, gdouble x,
gdouble y, gdouble y,
gint width, gint width,
gint height); gint height);
void gimp_canvas_handle_set_angles (GimpCanvasHandle *handle,
gdouble start_handle, void gimp_canvas_handle_set_position (GimpCanvasHandle *handle,
gdouble slice_handle); gdouble x,
gdouble y);
void gimp_canvas_handle_set_angles (GimpCanvasHandle *handle,
gdouble start_handle,
gdouble slice_handle);
#endif /* __GIMP_CANVAS_HANDLE_H__ */ #endif /* __GIMP_CANVAS_HANDLE_H__ */

View File

@ -267,3 +267,24 @@ gimp_canvas_line_new (GimpDisplayShell *shell,
"y2", y2, "y2", y2,
NULL); NULL);
} }
void
gimp_canvas_line_set (GimpCanvasLine *line,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2)
{
g_return_if_fail (GIMP_IS_CANVAS_LINE (line));
gimp_canvas_item_begin_change (GIMP_CANVAS_ITEM (line));
g_object_set (line,
"x1", x1,
"y1", y1,
"x2", x2,
"y2", y2,
NULL);
gimp_canvas_item_end_change (GIMP_CANVAS_ITEM (line));
}

View File

@ -55,5 +55,11 @@ GimpCanvasItem * gimp_canvas_line_new (GimpDisplayShell *shell,
gdouble x2, gdouble x2,
gdouble y2); gdouble y2);
void gimp_canvas_line_set (GimpCanvasLine *line,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2);
#endif /* __GIMP_CANVAS_LINE_H__ */ #endif /* __GIMP_CANVAS_LINE_H__ */

View File

@ -37,6 +37,8 @@
#include "widgets/gimphelp-ids.h" #include "widgets/gimphelp-ids.h"
#include "widgets/gimpwidgets-utils.h" #include "widgets/gimpwidgets-utils.h"
#include "display/gimpcanvashandle.h"
#include "display/gimpcanvasline.h"
#include "display/gimpdisplay.h" #include "display/gimpdisplay.h"
#include "gimpblendoptions.h" #include "gimpblendoptions.h"
@ -79,6 +81,7 @@ static void gimp_blend_tool_cursor_update (GimpTool *tool,
GimpDisplay *display); GimpDisplay *display);
static void gimp_blend_tool_draw (GimpDrawTool *draw_tool); static void gimp_blend_tool_draw (GimpDrawTool *draw_tool);
static void gimp_blend_tool_update_items (GimpBlendTool *blend_tool);
static void gimp_blend_tool_push_status (GimpBlendTool *blend_tool, static void gimp_blend_tool_push_status (GimpBlendTool *blend_tool,
GdkModifierType state, GdkModifierType state,
@ -279,8 +282,6 @@ gimp_blend_tool_motion (GimpTool *tool,
{ {
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool); GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
blend_tool->mouse_x = coords->x; blend_tool->mouse_x = coords->x;
blend_tool->mouse_y = coords->y; blend_tool->mouse_y = coords->y;
@ -312,10 +313,10 @@ gimp_blend_tool_motion (GimpTool *tool,
gimp_tool_pop_status (tool, display); gimp_tool_pop_status (tool, display);
gimp_blend_tool_push_status (blend_tool, state, display); gimp_blend_tool_push_status (blend_tool, state, display);
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
blend_tool->last_x = coords->x; blend_tool->last_x = coords->x;
blend_tool->last_y = coords->y; blend_tool->last_y = coords->y;
gimp_blend_tool_update_items (blend_tool);
} }
static void static void
@ -329,8 +330,6 @@ gimp_blend_tool_active_modifier_key (GimpTool *tool,
if (key == GDK_CONTROL_MASK) if (key == GDK_CONTROL_MASK)
{ {
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
blend_tool->end_x = blend_tool->mouse_x; blend_tool->end_x = blend_tool->mouse_x;
blend_tool->end_y = blend_tool->mouse_y; blend_tool->end_y = blend_tool->mouse_y;
@ -345,7 +344,7 @@ gimp_blend_tool_active_modifier_key (GimpTool *tool,
gimp_tool_pop_status (tool, display); gimp_tool_pop_status (tool, display);
gimp_blend_tool_push_status (blend_tool, state, display); gimp_blend_tool_push_status (blend_tool, state, display);
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); gimp_blend_tool_update_items (blend_tool);
} }
} }
@ -376,30 +375,49 @@ gimp_blend_tool_draw (GimpDrawTool *draw_tool)
{ {
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (draw_tool); GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (draw_tool);
/* Draw the line between the start and end coords */
gimp_draw_tool_add_line (draw_tool,
blend_tool->start_x,
blend_tool->start_y,
blend_tool->end_x,
blend_tool->end_y);
/* Draw start target */ /* Draw start target */
gimp_draw_tool_add_handle (draw_tool, blend_tool->start_handle =
GIMP_HANDLE_CROSS, gimp_draw_tool_add_handle (draw_tool,
GIMP_HANDLE_CROSS,
blend_tool->start_x,
blend_tool->start_y,
GIMP_TOOL_HANDLE_SIZE_CROSS,
GIMP_TOOL_HANDLE_SIZE_CROSS,
GIMP_HANDLE_ANCHOR_CENTER);
/* Draw the line between the start and end coords */
blend_tool->line =
gimp_draw_tool_add_line (draw_tool,
blend_tool->start_x, blend_tool->start_x,
blend_tool->start_y, blend_tool->start_y,
GIMP_TOOL_HANDLE_SIZE_CROSS, blend_tool->end_x,
GIMP_TOOL_HANDLE_SIZE_CROSS, blend_tool->end_y);
GIMP_HANDLE_ANCHOR_CENTER);
/* Draw end target */ /* Draw end target */
gimp_draw_tool_add_handle (draw_tool, blend_tool->end_handle =
GIMP_HANDLE_CROSS, gimp_draw_tool_add_handle (draw_tool,
blend_tool->end_x, GIMP_HANDLE_CROSS,
blend_tool->end_y, blend_tool->end_x,
GIMP_TOOL_HANDLE_SIZE_CROSS, blend_tool->end_y,
GIMP_TOOL_HANDLE_SIZE_CROSS, GIMP_TOOL_HANDLE_SIZE_CROSS,
GIMP_HANDLE_ANCHOR_CENTER); GIMP_TOOL_HANDLE_SIZE_CROSS,
GIMP_HANDLE_ANCHOR_CENTER);
}
static void
gimp_blend_tool_update_items (GimpBlendTool *blend_tool)
{
if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (blend_tool)))
{
gimp_canvas_line_set (GIMP_CANVAS_LINE (blend_tool->line),
blend_tool->start_x,
blend_tool->start_y,
blend_tool->end_x,
blend_tool->end_y);
gimp_canvas_handle_set_position (GIMP_CANVAS_HANDLE (blend_tool->end_handle),
blend_tool->end_x,
blend_tool->end_y);
}
} }
static void static void

View File

@ -37,17 +37,21 @@ typedef struct _GimpBlendToolClass GimpBlendToolClass;
struct _GimpBlendTool struct _GimpBlendTool
{ {
GimpDrawTool parent_instance; GimpDrawTool parent_instance;
gdouble start_x; /* starting x coord */ gdouble start_x; /* starting x coord */
gdouble start_y; /* starting y coord */ gdouble start_y; /* starting y coord */
gdouble end_x; /* ending x coord */ gdouble end_x; /* ending x coord */
gdouble end_y; /* ending y coord */ gdouble end_y; /* ending y coord */
gdouble last_x; /* last x coord */ gdouble last_x; /* last x coord */
gdouble last_y; /* last y coord */ gdouble last_y; /* last y coord */
gdouble mouse_x; /* pointer x coord */ gdouble mouse_x; /* pointer x coord */
gdouble mouse_y; /* pointer y coord */ gdouble mouse_y; /* pointer y coord */
GimpCanvasItem *start_handle;
GimpCanvasItem *line;
GimpCanvasItem *end_handle;
}; };
struct _GimpBlendToolClass struct _GimpBlendToolClass