[gimp] app: start an infrastructure where the shell keeps around its canvas items
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: start an infrastructure where the shell keeps around its canvas items
- Date: Wed, 29 Sep 2010 20:14:47 +0000 (UTC)
commit 7edfa2ca543739fb86c9e2e277470d8f3df5ee45
Author: Michael Natterer <mitch gimp org>
Date: Wed Sep 29 22:12:01 2010 +0200
app: start an infrastructure where the shell keeps around its canvas items
- Invalidate the proper area when an item gets added or removed.
- Draw the kept canvas items instead of calling a draw tool function.
- The draw tool now sets its item on the shell.
app/display/Makefile.am | 2 +
app/display/gimpdisplayshell-callbacks.c | 15 ++------
app/display/gimpdisplayshell-items.c | 55 ++++++++++++++++++++++++++++++
app/display/gimpdisplayshell-items.h | 31 +++++++++++++++++
app/display/gimpdisplayshell.c | 9 +++++
app/display/gimpdisplayshell.h | 2 +
app/tools/gimpdrawtool.c | 49 +++++++++------------------
app/tools/gimpdrawtool.h | 3 --
8 files changed, 119 insertions(+), 47 deletions(-)
---
diff --git a/app/display/Makefile.am b/app/display/Makefile.am
index 3b82f4a..ab093df 100644
--- a/app/display/Makefile.am
+++ b/app/display/Makefile.am
@@ -79,6 +79,8 @@ libappdisplay_a_sources = \
gimpdisplayshell-layer-select.h \
gimpdisplayshell-icon.c \
gimpdisplayshell-icon.h \
+ gimpdisplayshell-items.c \
+ gimpdisplayshell-items.h \
gimpdisplayshell-preview.c \
gimpdisplayshell-preview.h \
gimpdisplayshell-progress.c \
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index d1261bc..835acec 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -60,6 +60,7 @@
#include "widgets/gimpuimanager.h"
#include "gimpcanvas.h"
+#include "gimpcanvasitem.h"
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-appearance.h"
@@ -2350,17 +2351,9 @@ gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
cairo_restore (cr);
/* draw tool items */
- {
- GimpTool *tool = tool_manager_get_active (shell->display->gimp);
-
- if (GIMP_IS_DRAW_TOOL (tool) &&
- GIMP_DRAW_TOOL (tool)->display == shell->display)
- {
- cairo_save (cr);
- gimp_draw_tool_draw_items (GIMP_DRAW_TOOL (tool), cr);
- cairo_restore (cr);
- }
- }
+ cairo_save (cr);
+ gimp_canvas_item_draw (shell->canvas_item, shell, cr);
+ cairo_restore (cr);
/* and the cursor (if we have a software cursor) */
cairo_save (cr);
diff --git a/app/display/gimpdisplayshell-items.c b/app/display/gimpdisplayshell-items.c
new file mode 100644
index 0000000..d98e1ae
--- /dev/null
+++ b/app/display/gimpdisplayshell-items.c
@@ -0,0 +1,55 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpdisplayshell-items.c
+ * Copyright (C) 2010 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "display-types.h"
+
+#include "gimpcanvasgroup.h"
+#include "gimpdisplayshell.h"
+#include "gimpdisplayshell-expose.h"
+#include "gimpdisplayshell-items.h"
+
+
+void
+gimp_display_shell_add_item (GimpDisplayShell *shell,
+ GimpCanvasItem *item)
+{
+ g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
+ g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
+
+ gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (shell->canvas_item), item);
+
+ gimp_display_shell_expose_item (shell, item);
+}
+
+void
+gimp_display_shell_remove_item (GimpDisplayShell *shell,
+ GimpCanvasItem *item)
+{
+ g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
+ g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
+
+ gimp_display_shell_expose_item (shell, item);
+
+ gimp_canvas_group_remove_item (GIMP_CANVAS_GROUP (shell->canvas_item), item);
+}
diff --git a/app/display/gimpdisplayshell-items.h b/app/display/gimpdisplayshell-items.h
new file mode 100644
index 0000000..59b040f
--- /dev/null
+++ b/app/display/gimpdisplayshell-items.h
@@ -0,0 +1,31 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpdisplayshell-items.h
+ * Copyright (C) 2010 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_DISPLAY_SHELL_ITEMS_H__
+#define __GIMP_DISPLAY_SHELL_ITEMS_H__
+
+
+void gimp_display_shell_add_item (GimpDisplayShell *shell,
+ GimpCanvasItem *item);
+void gimp_display_shell_remove_item (GimpDisplayShell *shell,
+ GimpCanvasItem *item);
+
+
+#endif /* __GIMP_DISPLAY_SHELL_ITEMS_H__ */
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index f349495..3402f73 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -53,6 +53,7 @@
#include "tools/tool_manager.h"
#include "gimpcanvas.h"
+#include "gimpcanvasgroup.h"
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-appearance.h"
@@ -290,6 +291,8 @@ gimp_display_shell_init (GimpDisplayShell *shell)
GIMP_DISPLAY_RENDER_BUF_WIDTH,
GIMP_DISPLAY_RENDER_BUF_HEIGHT);
+ shell->canvas_item = gimp_canvas_group_new ();
+
shell->icon_size = 32;
shell->cursor_format = GIMP_CURSOR_FORMAT_BITMAP;
@@ -793,6 +796,12 @@ gimp_display_shell_dispose (GObject *object)
shell->mask = NULL;
}
+ if (shell->canvas_item)
+ {
+ g_object_unref (shell->canvas_item);
+ shell->canvas_item = NULL;
+ }
+
if (shell->event_history)
{
g_array_free (shell->event_history, TRUE);
diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h
index a6eb26d..eefbcf9 100644
--- a/app/display/gimpdisplayshell.h
+++ b/app/display/gimpdisplayshell.h
@@ -135,6 +135,8 @@ struct _GimpDisplayShell
cairo_surface_t *mask_surface; /* buffer for rendering the mask */
cairo_pattern_t *checkerboard; /* checkerboard pattern */
+ GimpCanvasItem *canvas_item; /* items drawn on the canvas */
+
guint title_idle_id; /* title update idle ID */
gchar *title; /* current title */
gchar *status; /* current default statusbar content */
diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c
index 285482f..7e99785 100644
--- a/app/tools/gimpdrawtool.c
+++ b/app/tools/gimpdrawtool.c
@@ -46,6 +46,7 @@
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-expose.h"
+#include "display/gimpdisplayshell-items.h"
#include "display/gimpdisplayshell-transform.h"
#include "gimpdrawtool.h"
@@ -181,36 +182,35 @@ gimp_draw_tool_clear_items (GimpDrawTool *draw_tool)
}
static void
-gimp_draw_tool_invalidate_items (GimpDrawTool *draw_tool)
-{
- if (draw_tool->item)
- {
- GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
-
- gimp_display_shell_expose_item (shell, draw_tool->item);
- }
-}
-
-static void
gimp_draw_tool_draw (GimpDrawTool *draw_tool)
{
if (draw_tool->display && draw_tool->paused_count == 0)
{
- gimp_draw_tool_invalidate_items (draw_tool);
- gimp_draw_tool_clear_items (draw_tool);
+ GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
+
+ if (draw_tool->item)
+ {
+ gimp_display_shell_remove_item (shell, draw_tool->item);
+ gimp_draw_tool_clear_items (draw_tool);
+ }
GIMP_DRAW_TOOL_GET_CLASS (draw_tool)->draw (draw_tool);
- gimp_draw_tool_invalidate_items (draw_tool);
+ if (draw_tool->item)
+ {
+ gimp_display_shell_add_item (shell, draw_tool->item);
+ }
}
}
static void
gimp_draw_tool_undraw (GimpDrawTool *draw_tool)
{
- if (draw_tool->display)
+ if (draw_tool->display && draw_tool->item)
{
- gimp_draw_tool_invalidate_items (draw_tool);
+ GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
+
+ gimp_display_shell_remove_item (shell, draw_tool->item);
gimp_draw_tool_clear_items (draw_tool);
}
}
@@ -272,23 +272,6 @@ gimp_draw_tool_resume (GimpDrawTool *draw_tool)
gimp_draw_tool_draw (draw_tool);
}
-void
-gimp_draw_tool_draw_items (GimpDrawTool *draw_tool,
- cairo_t *cr)
-{
- g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
- g_return_if_fail (cr != NULL);
-
- if (draw_tool->item &&
- gimp_draw_tool_is_active (draw_tool) &&
- draw_tool->paused_count == 0)
- {
- GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
-
- gimp_canvas_item_draw (draw_tool->item, shell, cr);
- }
-}
-
/**
* gimp_draw_tool_calc_distance:
* @draw_tool: a #GimpDrawTool
diff --git a/app/tools/gimpdrawtool.h b/app/tools/gimpdrawtool.h
index 4b43489..d5279b7 100644
--- a/app/tools/gimpdrawtool.h
+++ b/app/tools/gimpdrawtool.h
@@ -66,9 +66,6 @@ gboolean gimp_draw_tool_is_active (GimpDrawTool *draw_too
void gimp_draw_tool_pause (GimpDrawTool *draw_tool);
void gimp_draw_tool_resume (GimpDrawTool *draw_tool);
-void gimp_draw_tool_draw_items (GimpDrawTool *draw_tool,
- cairo_t *cr);
-
gdouble gimp_draw_tool_calc_distance (GimpDrawTool *draw_tool,
GimpDisplay *display,
gdouble x1,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]