app: draw guides using GimpCanvasItems

- Add signals GimpImage::guide_added(), removed() and moved()
- Remove singal GimpImage::update_guide()
- Adapt core code to emit the new signals instead of update_guide()
- Have the shell connect to the new signals and update guide canvas
  items as needed
- Remove gimp_display_shell_draw_guides()
This commit is contained in:
Michael Natterer 2010-10-01 10:34:15 +02:00
parent 3b4f2ec94c
commit 26d0035be0
10 changed files with 192 additions and 125 deletions

View File

@ -151,6 +151,7 @@ gimp_guide_undo_pop (GimpUndo *undo,
GimpGuideUndo *guide_undo = GIMP_GUIDE_UNDO (undo);
GimpOrientationType orientation;
gint position;
gboolean moved = FALSE;
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
@ -168,13 +169,16 @@ gimp_guide_undo_pop (GimpUndo *undo,
}
else
{
gimp_image_update_guide (undo->image, guide_undo->guide);
gimp_guide_set_position (guide_undo->guide, guide_undo->position);
gimp_image_update_guide (undo->image, guide_undo->guide);
moved = TRUE;
}
gimp_guide_set_orientation (guide_undo->guide, guide_undo->orientation);
if (moved || guide_undo->orientation != orientation)
gimp_image_guide_moved (undo->image, guide_undo->guide);
guide_undo->position = position;
guide_undo->orientation = orientation;
}

View File

@ -171,12 +171,10 @@ gimp_image_arrange_objects (GimpImage *image,
{
case GIMP_ORIENTATION_VERTICAL:
gimp_image_move_guide (image, guide, z1 + xtranslate, TRUE);
gimp_image_update_guide (image, guide);
break;
case GIMP_ORIENTATION_HORIZONTAL:
gimp_image_move_guide (image, guide, z1 + ytranslate, TRUE);
gimp_image_update_guide (image, guide);
break;
default:

View File

@ -98,7 +98,7 @@ gimp_image_add_guide (GimpImage *image,
gimp_guide_set_position (guide, position);
g_object_ref (G_OBJECT (guide));
gimp_image_update_guide (image, guide);
gimp_image_guide_added (image, guide);
}
void
@ -113,14 +113,14 @@ gimp_image_remove_guide (GimpImage *image,
private = GIMP_IMAGE_GET_PRIVATE (image);
gimp_image_update_guide (image, guide);
if (push_undo)
gimp_image_undo_push_guide (image, C_("undo-type", "Remove Guide"), guide);
private->guides = g_list_remove (private->guides, guide);
gimp_guide_removed (guide);
gimp_image_guide_removed (image, guide);
gimp_guide_set_position (guide, -1);
g_object_unref (G_OBJECT (guide));
}
@ -143,9 +143,9 @@ gimp_image_move_guide (GimpImage *image,
if (push_undo)
gimp_image_undo_push_guide (image, C_("undo-type", "Move Guide"), guide);
gimp_image_update_guide (image, guide);
gimp_guide_set_position (guide, position);
gimp_image_update_guide (image, guide);
gimp_image_guide_moved (image, guide);
}
GList *

View File

@ -100,8 +100,10 @@ enum
DIRTY,
SAVED,
EXPORTED,
UPDATE_GUIDE,
UPDATE_VECTORS,
GUIDE_ADDED,
GUIDE_REMOVED,
GUIDE_MOVED,
SAMPLE_POINT_ADDED,
SAMPLE_POINT_REMOVED,
SAMPLE_POINT_MOVED,
@ -422,16 +424,6 @@ gimp_image_class_init (GimpImageClass *klass)
G_TYPE_NONE, 1,
G_TYPE_STRING);
gimp_image_signals[UPDATE_GUIDE] =
g_signal_new ("update-guide",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpImageClass, update_guide),
NULL, NULL,
gimp_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
gimp_image_signals[UPDATE_VECTORS] =
g_signal_new ("update-vectors",
G_TYPE_FROM_CLASS (klass),
@ -442,6 +434,36 @@ gimp_image_class_init (GimpImageClass *klass)
G_TYPE_NONE, 1,
GIMP_TYPE_VECTORS);
gimp_image_signals[GUIDE_ADDED] =
g_signal_new ("guide-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpImageClass, guide_added),
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_GUIDE);
gimp_image_signals[GUIDE_REMOVED] =
g_signal_new ("guide-removed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpImageClass, guide_removed),
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_GUIDE);
gimp_image_signals[GUIDE_MOVED] =
g_signal_new ("guide-moved",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpImageClass, guide_moved),
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_GUIDE);
gimp_image_signals[SAMPLE_POINT_ADDED] =
g_signal_new ("sample-point-added",
G_TYPE_FROM_CLASS (klass),
@ -551,8 +573,10 @@ gimp_image_class_init (GimpImageClass *klass)
klass->dirty = NULL;
klass->saved = NULL;
klass->exported = NULL;
klass->update_guide = NULL;
klass->update_vectors = NULL;
klass->guide_added = NULL;
klass->guide_removed = NULL;
klass->guide_moved = NULL;
klass->sample_point_added = NULL;
klass->sample_point_removed = NULL;
klass->sample_point_moved = NULL;
@ -2089,16 +2113,6 @@ gimp_image_invalidate (GimpImage *image,
GIMP_IMAGE_GET_PRIVATE (image)->flush_accum.preview_invalidated = TRUE;
}
void
gimp_image_update_guide (GimpImage *image,
GimpGuide *guide)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (guide != NULL);
g_signal_emit (image, gimp_image_signals[UPDATE_GUIDE], 0, guide);
}
void
gimp_image_update_vectors (GimpImage *image,
GimpVectors *vectors)
@ -2110,6 +2124,39 @@ gimp_image_update_vectors (GimpImage *image,
vectors);
}
void
gimp_image_guide_added (GimpImage *image,
GimpGuide *guide)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_GUIDE (guide));
g_signal_emit (image, gimp_image_signals[GUIDE_ADDED], 0,
guide);
}
void
gimp_image_guide_removed (GimpImage *image,
GimpGuide *guide)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_GUIDE (guide));
g_signal_emit (image, gimp_image_signals[GUIDE_REMOVED], 0,
guide);
}
void
gimp_image_guide_moved (GimpImage *image,
GimpGuide *guide)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_GUIDE (guide));
g_signal_emit (image, gimp_image_signals[GUIDE_MOVED], 0,
guide);
}
void
gimp_image_sample_point_added (GimpImage *image,
GimpSamplePoint *sample_point)

View File

@ -131,10 +131,14 @@ struct _GimpImageClass
void (* exported) (GimpImage *image,
const gchar *uri);
void (* update_guide) (GimpImage *image,
GimpGuide *guide);
void (* update_vectors) (GimpImage *image,
GimpVectors *vectors);
void (* guide_added) (GimpImage *image,
GimpGuide *guide);
void (* guide_removed) (GimpImage *image,
GimpGuide *guide);
void (* guide_moved) (GimpImage *image,
GimpGuide *guide);
void (* sample_point_added) (GimpImage *image,
GimpSamplePoint *sample_point);
void (* sample_point_removed) (GimpImage *image,
@ -249,11 +253,16 @@ void gimp_image_invalidate (GimpImage *image,
gint y,
gint width,
gint height);
void gimp_image_update_guide (GimpImage *image,
GimpGuide *guide);
void gimp_image_update_vectors (GimpImage *image,
GimpVectors *vectors);
void gimp_image_guide_added (GimpImage *image,
GimpGuide *guide);
void gimp_image_guide_removed (GimpImage *image,
GimpGuide *guide);
void gimp_image_guide_moved (GimpImage *image,
GimpGuide *guide);
void gimp_image_sample_point_added (GimpImage *image,
GimpSamplePoint *sample_point);
void gimp_image_sample_point_removed (GimpImage *image,

View File

@ -2340,11 +2340,6 @@ gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
gimp_display_shell_draw_grid (shell, cr);
cairo_restore (cr);
/* draw the guides */
cairo_save (cr);
gimp_display_shell_draw_guides (shell, cr);
cairo_restore (cr);
/* draw canvas items */
cairo_save (cr);
gimp_canvas_item_draw (shell->canvas_item, shell, cr);

View File

@ -27,16 +27,13 @@
#include "display-types.h"
#include "base/boundary.h"
#include "base/tile-manager.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable.h"
#include "core/gimpgrid.h"
#include "core/gimpguide.h"
#include "core/gimpimage.h"
#include "core/gimpimage-grid.h"
#include "core/gimpimage-guides.h"
#include "core/gimpprojection.h"
#include "vectors/gimpstroke.h"
@ -46,7 +43,6 @@
#include "widgets/gimpwidgets-utils.h"
#include "gimpcanvas.h"
#include "gimpcanvasguide.h"
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-appearance.h"
@ -127,48 +123,6 @@ gimp_display_shell_draw_get_scaled_image_size_for_scale (GimpDisplayShell *shell
if (h) *h = PROJ_ROUND (level_height * (scale_y * (1 << level)));
}
void
gimp_display_shell_draw_guides (GimpDisplayShell *shell,
cairo_t *cr)
{
GimpImage *image;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
image = gimp_display_get_image (shell->display);
if (image && gimp_display_shell_get_show_guides (shell))
{
GimpCanvasItem *item;
GList *list;
item = gimp_canvas_guide_new (GIMP_ORIENTATION_HORIZONTAL, 0);
g_object_set (item, "guide-style", TRUE, NULL);
for (list = gimp_image_get_guides (image);
list;
list = g_list_next (list))
{
GimpGuide *guide = list->data;
gint position;
position = gimp_guide_get_position (guide);
if (position >= 0)
{
g_object_set (item,
"orientation", gimp_guide_get_orientation (guide),
"position", position,
NULL);
gimp_canvas_item_draw (item, shell, cr);
}
}
g_object_unref (item);
}
}
void
gimp_display_shell_draw_grid (GimpDisplayShell *shell,
cairo_t *cr)

View File

@ -27,8 +27,6 @@ void gimp_display_shell_draw_get_scaled_image_size_for_scale
gdouble scale,
gint *w,
gint *h);
void gimp_display_shell_draw_guides (GimpDisplayShell *shell,
cairo_t *cr);
void gimp_display_shell_draw_grid (GimpDisplayShell *shell,
cairo_t *cr);
void gimp_display_shell_draw_pen (GimpDisplayShell *shell,

View File

@ -34,6 +34,7 @@
#include "core/gimpguide.h"
#include "core/gimpimage.h"
#include "core/gimpimage-grid.h"
#include "core/gimpimage-guides.h"
#include "core/gimpimage-quick-mask.h"
#include "core/gimpimage-sample-points.h"
#include "core/gimpitem.h"
@ -93,7 +94,13 @@ static void gimp_display_shell_resolution_changed_handler (GimpImage *i
GimpDisplayShell *shell);
static void gimp_display_shell_quick_mask_changed_handler (GimpImage *image,
GimpDisplayShell *shell);
static void gimp_display_shell_update_guide_handler (GimpImage *image,
static void gimp_display_shell_guide_add_handler (GimpImage *image,
GimpGuide *guide,
GimpDisplayShell *shell);
static void gimp_display_shell_guide_remove_handler (GimpImage *image,
GimpGuide *guide,
GimpDisplayShell *shell);
static void gimp_display_shell_guide_move_handler (GimpImage *image,
GimpGuide *guide,
GimpDisplayShell *shell);
static void gimp_display_shell_sample_point_add_handler (GimpImage *image,
@ -187,9 +194,22 @@ gimp_display_shell_connect (GimpDisplayShell *shell)
g_signal_connect (image, "quick-mask-changed",
G_CALLBACK (gimp_display_shell_quick_mask_changed_handler),
shell);
g_signal_connect (image, "update-guide",
G_CALLBACK (gimp_display_shell_update_guide_handler),
g_signal_connect (image, "guide-added",
G_CALLBACK (gimp_display_shell_guide_add_handler),
shell);
g_signal_connect (image, "guide-removed",
G_CALLBACK (gimp_display_shell_guide_remove_handler),
shell);
g_signal_connect (image, "guide-moved",
G_CALLBACK (gimp_display_shell_guide_move_handler),
shell);
for (list = gimp_image_get_guides (image);
list;
list = g_list_next (list))
{
gimp_display_shell_guide_add_handler (image, list->data, shell);
}
g_signal_connect (image, "sample-point-added",
G_CALLBACK (gimp_display_shell_sample_point_add_handler),
@ -348,9 +368,23 @@ gimp_display_shell_disconnect (GimpDisplayShell *shell)
g_signal_handlers_disconnect_by_func (image,
gimp_display_shell_invalidate_preview_handler,
shell);
g_signal_handlers_disconnect_by_func (image,
gimp_display_shell_update_guide_handler,
gimp_display_shell_guide_add_handler,
shell);
g_signal_handlers_disconnect_by_func (image,
gimp_display_shell_guide_remove_handler,
shell);
g_signal_handlers_disconnect_by_func (image,
gimp_display_shell_guide_move_handler,
shell);
for (list = gimp_image_get_guides (image);
list;
list = g_list_next (list))
{
gimp_canvas_proxy_group_remove_item (GIMP_CANVAS_PROXY_GROUP (shell->guides),
list->data);
}
g_signal_handlers_disconnect_by_func (image,
gimp_display_shell_sample_point_add_handler,
@ -502,19 +536,56 @@ gimp_display_shell_quick_mask_changed_handler (GimpImage *image,
}
static void
gimp_display_shell_update_guide_handler (GimpImage *image,
GimpGuide *guide,
GimpDisplayShell *shell)
gimp_display_shell_guide_add_handler (GimpImage *image,
GimpGuide *guide,
GimpDisplayShell *shell)
{
GimpCanvasItem *item;
GimpCanvasProxyGroup *group = GIMP_CANVAS_PROXY_GROUP (shell->guides);
GimpCanvasItem *item;
item = gimp_canvas_guide_new (gimp_guide_get_orientation (guide),
gimp_guide_get_position (guide));
g_object_set (item, "guide-style", TRUE, NULL);
gimp_canvas_proxy_group_add_item (group, guide, item);
g_object_unref (item);
gimp_display_shell_expose_item (shell, item);
}
static void
gimp_display_shell_guide_remove_handler (GimpImage *image,
GimpGuide *guide,
GimpDisplayShell *shell)
{
GimpCanvasProxyGroup *group = GIMP_CANVAS_PROXY_GROUP (shell->guides);
GimpCanvasItem *item;
item = gimp_canvas_proxy_group_get_item (group, guide);
gimp_display_shell_expose_item (shell, item);
g_object_unref (item);
gimp_canvas_proxy_group_remove_item (group, guide);
}
static void
gimp_display_shell_guide_move_handler (GimpImage *image,
GimpGuide *guide,
GimpDisplayShell *shell)
{
GimpCanvasProxyGroup *group = GIMP_CANVAS_PROXY_GROUP (shell->guides);
GimpCanvasItem *item;
item = gimp_canvas_proxy_group_get_item (group, guide);
gimp_display_shell_expose_item (shell, item);
g_object_set (item,
"orientation", gimp_guide_get_orientation (guide),
"position", gimp_guide_get_position (guide),
NULL);
gimp_display_shell_expose_item (shell, item);
}
static void

View File

@ -224,9 +224,8 @@ gimp_measure_tool_button_press (GimpTool *tool,
{
if (state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))
{
GimpGuide *guide;
gboolean create_hguide;
gboolean create_vguide;
gboolean create_hguide;
gboolean create_vguide;
create_hguide = ((state & GDK_CONTROL_MASK) &&
(measure->y[i] ==
@ -240,32 +239,24 @@ gimp_measure_tool_button_press (GimpTool *tool,
0,
gimp_image_get_width (image))));
if (create_hguide && create_vguide)
gimp_image_undo_group_start (image,
GIMP_UNDO_GROUP_GUIDE,
_("Add Guides"));
if (create_hguide)
{
guide = gimp_image_add_hguide (image,
measure->y[i],
TRUE);
gimp_image_update_guide (image, guide);
}
if (create_vguide)
{
guide = gimp_image_add_vguide (image,
measure->x[i],
TRUE);
gimp_image_update_guide (image, guide);
}
if (create_hguide && create_vguide)
gimp_image_undo_group_end (image);
if (create_hguide || create_vguide)
gimp_image_flush (image);
{
if (create_hguide && create_vguide)
gimp_image_undo_group_start (image,
GIMP_UNDO_GROUP_GUIDE,
_("Add Guides"));
if (create_hguide)
gimp_image_add_hguide (image, measure->y[i], TRUE);
if (create_vguide)
gimp_image_add_vguide (image, measure->x[i], TRUE);
if (create_hguide && create_vguide)
gimp_image_undo_group_end (image);
gimp_image_flush (image);
}
measure->function = GUIDING;
break;