[gimp] app: port GimpBlendTool to pause()/resume()-less drawing
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: port GimpBlendTool to pause()/resume()-less drawing
- Date: Mon, 28 Mar 2011 09:10:44 +0000 (UTC)
commit aa5d2f8082e5c3e26c42b49e9ccf7e1e58cb0cdb
Author: Michael Natterer <mitch gimp org>
Date: Mon Mar 28 11:08:40 2011 +0200
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.
app/display/gimpcanvashandle.c | 21 ++++++++++++
app/display/gimpcanvashandle.h | 26 ++++++++------
app/display/gimpcanvasline.c | 21 ++++++++++++
app/display/gimpcanvasline.h | 6 +++
app/tools/gimpblendtool.c | 70 +++++++++++++++++++++++++---------------
app/tools/gimpblendtool.h | 22 +++++++-----
6 files changed, 120 insertions(+), 46 deletions(-)
---
diff --git a/app/display/gimpcanvashandle.c b/app/display/gimpcanvashandle.c
index f1294e5..007d050 100644
--- a/app/display/gimpcanvashandle.c
+++ b/app/display/gimpcanvashandle.c
@@ -403,14 +403,35 @@ gimp_canvas_handle_new (GimpDisplayShell *shell,
}
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
gimp_canvas_handle_set_angles (GimpCanvasHandle *handle,
gdouble start_angle,
gdouble slice_angle)
{
g_return_if_fail (GIMP_IS_CANVAS_HANDLE (handle));
+ gimp_canvas_item_begin_change (GIMP_CANVAS_ITEM (handle));
+
g_object_set (handle,
"start-angle", start_angle,
"slice-angle", slice_angle,
NULL);
+
+ gimp_canvas_item_end_change (GIMP_CANVAS_ITEM (handle));
}
diff --git a/app/display/gimpcanvashandle.h b/app/display/gimpcanvashandle.h
index 504110b..7e5efeb 100644
--- a/app/display/gimpcanvashandle.h
+++ b/app/display/gimpcanvashandle.h
@@ -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,
- GimpHandleType type,
- GimpHandleAnchor anchor,
- gdouble x,
- gdouble y,
- gint width,
- gint height);
-void gimp_canvas_handle_set_angles (GimpCanvasHandle *handle,
- gdouble start_handle,
- gdouble slice_handle);
+GimpCanvasItem * gimp_canvas_handle_new (GimpDisplayShell *shell,
+ GimpHandleType type,
+ GimpHandleAnchor anchor,
+ gdouble x,
+ gdouble y,
+ gint width,
+ gint height);
+
+void gimp_canvas_handle_set_position (GimpCanvasHandle *handle,
+ gdouble x,
+ gdouble y);
+void gimp_canvas_handle_set_angles (GimpCanvasHandle *handle,
+ gdouble start_handle,
+ gdouble slice_handle);
#endif /* __GIMP_CANVAS_HANDLE_H__ */
diff --git a/app/display/gimpcanvasline.c b/app/display/gimpcanvasline.c
index bf01e73..04c204d 100644
--- a/app/display/gimpcanvasline.c
+++ b/app/display/gimpcanvasline.c
@@ -267,3 +267,24 @@ gimp_canvas_line_new (GimpDisplayShell *shell,
"y2", y2,
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));
+}
diff --git a/app/display/gimpcanvasline.h b/app/display/gimpcanvasline.h
index 754dbdb..a38abc2 100644
--- a/app/display/gimpcanvasline.h
+++ b/app/display/gimpcanvasline.h
@@ -55,5 +55,11 @@ GimpCanvasItem * gimp_canvas_line_new (GimpDisplayShell *shell,
gdouble x2,
gdouble y2);
+void gimp_canvas_line_set (GimpCanvasLine *line,
+ gdouble x1,
+ gdouble y1,
+ gdouble x2,
+ gdouble y2);
+
#endif /* __GIMP_CANVAS_LINE_H__ */
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index 80b62b8..6876586 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -37,6 +37,8 @@
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpwidgets-utils.h"
+#include "display/gimpcanvashandle.h"
+#include "display/gimpcanvasline.h"
#include "display/gimpdisplay.h"
#include "gimpblendoptions.h"
@@ -79,6 +81,7 @@ static void gimp_blend_tool_cursor_update (GimpTool *tool,
GimpDisplay *display);
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,
GdkModifierType state,
@@ -279,8 +282,6 @@ gimp_blend_tool_motion (GimpTool *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_y = coords->y;
@@ -312,10 +313,10 @@ gimp_blend_tool_motion (GimpTool *tool,
gimp_tool_pop_status (tool, 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_y = coords->y;
+
+ gimp_blend_tool_update_items (blend_tool);
}
static void
@@ -329,8 +330,6 @@ gimp_blend_tool_active_modifier_key (GimpTool *tool,
if (key == GDK_CONTROL_MASK)
{
- gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
-
blend_tool->end_x = blend_tool->mouse_x;
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_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);
- /* 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 */
- gimp_draw_tool_add_handle (draw_tool,
- GIMP_HANDLE_CROSS,
+ blend_tool->start_handle =
+ 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_y,
- GIMP_TOOL_HANDLE_SIZE_CROSS,
- GIMP_TOOL_HANDLE_SIZE_CROSS,
- GIMP_HANDLE_ANCHOR_CENTER);
+ blend_tool->end_x,
+ blend_tool->end_y);
/* Draw end target */
- gimp_draw_tool_add_handle (draw_tool,
- GIMP_HANDLE_CROSS,
- blend_tool->end_x,
- blend_tool->end_y,
- GIMP_TOOL_HANDLE_SIZE_CROSS,
- GIMP_TOOL_HANDLE_SIZE_CROSS,
- GIMP_HANDLE_ANCHOR_CENTER);
+ blend_tool->end_handle =
+ gimp_draw_tool_add_handle (draw_tool,
+ GIMP_HANDLE_CROSS,
+ blend_tool->end_x,
+ blend_tool->end_y,
+ GIMP_TOOL_HANDLE_SIZE_CROSS,
+ 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
diff --git a/app/tools/gimpblendtool.h b/app/tools/gimpblendtool.h
index 336bd74..1e1ea6c 100644
--- a/app/tools/gimpblendtool.h
+++ b/app/tools/gimpblendtool.h
@@ -37,17 +37,21 @@ typedef struct _GimpBlendToolClass GimpBlendToolClass;
struct _GimpBlendTool
{
- GimpDrawTool parent_instance;
+ GimpDrawTool parent_instance;
- gdouble start_x; /* starting x coord */
- gdouble start_y; /* starting y coord */
- gdouble end_x; /* ending x coord */
- gdouble end_y; /* ending y coord */
+ gdouble start_x; /* starting x coord */
+ gdouble start_y; /* starting y coord */
+ gdouble end_x; /* ending x coord */
+ gdouble end_y; /* ending y coord */
- gdouble last_x; /* last x coord */
- gdouble last_y; /* last y coord */
- gdouble mouse_x; /* pointer x coord */
- gdouble mouse_y; /* pointer y coord */
+ gdouble last_x; /* last x coord */
+ gdouble last_y; /* last y coord */
+ gdouble mouse_x; /* pointer x coord */
+ gdouble mouse_y; /* pointer y coord */
+
+ GimpCanvasItem *start_handle;
+ GimpCanvasItem *line;
+ GimpCanvasItem *end_handle;
};
struct _GimpBlendToolClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]