[gimp/blend-tool-fun: 6/10] app: Add a basic live preview to GimpBlendTool using GimpImageMap
- From: Michael Henning <mhenning src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/blend-tool-fun: 6/10] app: Add a basic live preview to GimpBlendTool using GimpImageMap
- Date: Thu, 26 Jun 2014 16:58:19 +0000 (UTC)
commit 2b3f8cfa7d4b38bbc38ca92d2ec2f638b8c360cb
Author: Michael Henning <drawoc darkrefraction com>
Date: Fri Jun 20 11:28:01 2014 -0400
app: Add a basic live preview to GimpBlendTool using GimpImageMap
app/tools/gimpblendtool.c | 105 +++++++++++++++++++++++++++++++++++++++++++++
app/tools/gimpblendtool.h | 4 ++
2 files changed, 109 insertions(+), 0 deletions(-)
---
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index ea8f959..f0bcac8 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -37,7 +37,9 @@
#include "core/gimperror.h"
#include "core/gimpgradient.h"
#include "core/gimpimage.h"
+#include "core/gimpimagemap.h"
#include "core/gimpprogress.h"
+#include "core/gimpprojection.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpwidgets-utils.h"
@@ -115,6 +117,15 @@ static void gimp_blend_tool_push_status (GimpBlendTool *blend_
GdkModifierType state,
GimpDisplay *display);
+static void gimp_blend_tool_create_graph (GimpBlendTool *blend_tool);
+static void gimp_blend_tool_update_preview_coords (GimpBlendTool *blend_tool);
+
+static void gimp_blend_tool_create_image_map (GimpBlendTool *blend_tool,
+ GimpDrawable *drawable);
+static void gimp_blend_tool_image_map_flush (GimpImageMap *image_map,
+ GimpTool *tool);
+
+
G_DEFINE_TYPE (GimpBlendTool, gimp_blend_tool, GIMP_TYPE_DRAW_TOOL)
@@ -314,6 +325,9 @@ gimp_blend_tool_button_press (GimpTool *tool,
tool->display = display;
gimp_blend_tool_update_items (blend_tool);
+ gimp_blend_tool_update_preview_coords (blend_tool);
+ gimp_image_map_apply (blend_tool->image_map, NULL);
+
gimp_tool_control_activate (tool->control);
gimp_blend_tool_push_status (blend_tool, state, display);
@@ -378,6 +392,9 @@ gimp_blend_tool_motion (GimpTool *tool,
gimp_blend_tool_push_status (blend_tool, state, display);
gimp_blend_tool_update_items (blend_tool);
+
+ gimp_blend_tool_update_preview_coords (blend_tool);
+ gimp_image_map_apply (blend_tool->image_map, NULL);
}
static void
@@ -460,6 +477,9 @@ gimp_blend_tool_active_modifier_key (GimpTool *tool,
gimp_blend_tool_push_status (blend_tool, state, display);
gimp_blend_tool_update_items (blend_tool);
+
+ gimp_blend_tool_update_preview_coords (blend_tool);
+ gimp_image_map_apply (blend_tool->image_map, NULL);
}
else if (key == GDK_MOD1_MASK)
{
@@ -619,6 +639,8 @@ gimp_blend_tool_start (GimpBlendTool *blend_tool,
tool->display = display;
tool->drawable = drawable;
+ gimp_blend_tool_create_image_map (blend_tool, drawable);
+
if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (blend_tool)))
gimp_draw_tool_start (GIMP_DRAW_TOOL (blend_tool), display);
}
@@ -628,6 +650,22 @@ gimp_blend_tool_halt (GimpBlendTool *blend_tool)
{
GimpTool *tool = GIMP_TOOL (blend_tool);
+ if (blend_tool->graph)
+ {
+ g_object_unref (blend_tool->graph);
+ blend_tool->graph = NULL;
+ blend_tool->render_node = NULL;
+ }
+
+ if (blend_tool->image_map)
+ {
+ gimp_image_map_abort (blend_tool->image_map);
+ g_object_unref (blend_tool->image_map);
+ blend_tool->image_map = NULL;
+
+ gimp_image_flush (gimp_display_get_image (tool->display));
+ }
+
tool->display = NULL;
tool->drawable = NULL;
@@ -710,3 +748,70 @@ gimp_blend_tool_push_status (GimpBlendTool *blend_tool,
g_free (status_help);
}
+
+/* gegl graph stuff */
+
+static void
+gimp_blend_tool_create_graph (GimpBlendTool *blend_tool)
+{
+ GeglNode *graph, *output, *render;
+
+ /* render_node is not supposed to be recreated */
+ g_return_if_fail (blend_tool->graph == NULL);
+
+ graph = gegl_node_new ();
+
+ output = gegl_node_get_output_proxy (graph, "output");
+
+
+ render = gegl_node_new_child (graph,
+ "operation", "gimp:blend",
+ NULL);
+
+ gegl_node_link (render, output);
+
+ blend_tool->graph = graph;
+ blend_tool->render_node = render;
+}
+
+static void
+gimp_blend_tool_update_preview_coords (GimpBlendTool *blend_tool)
+{
+ gegl_node_set (blend_tool->render_node,
+ "start_x", blend_tool->start_x,
+ "start_y", blend_tool->start_y,
+ "end_x", blend_tool->end_x,
+ "end_y", blend_tool->end_y,
+ NULL);
+}
+
+/* Image map stuff */
+
+static void
+gimp_blend_tool_create_image_map (GimpBlendTool *blend_tool,
+ GimpDrawable *drawable)
+{
+ if (! blend_tool->graph)
+ gimp_blend_tool_create_graph (blend_tool);
+
+ blend_tool->image_map = gimp_image_map_new (drawable,
+ C_("undo-type", "Blend"),
+ blend_tool->graph,
+ GIMP_STOCK_TOOL_BLEND);
+
+ gimp_image_map_set_region (blend_tool->image_map,
+ GIMP_IMAGE_MAP_REGION_DRAWABLE);
+
+ g_signal_connect (blend_tool->image_map, "flush",
+ G_CALLBACK (gimp_blend_tool_image_map_flush),
+ blend_tool);
+}
+
+static void
+gimp_blend_tool_image_map_flush (GimpImageMap *image_map,
+ GimpTool *tool)
+{
+ GimpImage *image = gimp_display_get_image (tool->display);
+
+ gimp_projection_flush (gimp_image_get_projection (image));
+}
diff --git a/app/tools/gimpblendtool.h b/app/tools/gimpblendtool.h
index ac94303..6f35d04 100644
--- a/app/tools/gimpblendtool.h
+++ b/app/tools/gimpblendtool.h
@@ -59,6 +59,10 @@ struct _GimpBlendTool
GimpCanvasItem *start_handle;
GimpCanvasItem *line;
GimpCanvasItem *end_handle;
+
+ GeglNode *graph;
+ GeglNode *render_node;
+ GimpImageMap *image_map;
};
struct _GimpBlendToolClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]