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.
This commit is contained in:
Michael Natterer 2010-09-29 22:12:01 +02:00
parent 81cfb44047
commit 7edfa2ca54
8 changed files with 119 additions and 47 deletions

View File

@ -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 \

View File

@ -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);

View File

@ -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);
}

View File

@ -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__ */

View File

@ -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);

View File

@ -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 */

View File

@ -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"
@ -180,37 +181,36 @@ 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

View File

@ -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,