[gimp] plug-ins: port nova cursor drawing to cairo and simplify drawing a lot
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: port nova cursor drawing to cairo and simplify drawing a lot
- Date: Wed, 8 Sep 2010 18:52:34 +0000 (UTC)
commit 9970a2b14bf7659cfbc12030376c6171806925c5
Author: Michael Natterer <mitch gimp org>
Date: Wed Sep 8 20:52:02 2010 +0200
plug-ins: port nova cursor drawing to cairo and simplify drawing a lot
plug-ins/common/nova.c | 119 ++++++++++++++----------------------------------
1 files changed, 34 insertions(+), 85 deletions(-)
---
diff --git a/plug-ins/common/nova.c b/plug-ins/common/nova.c
index 8f8a2e9..c0d4cbc 100644
--- a/plug-ins/common/nova.c
+++ b/plug-ins/common/nova.c
@@ -89,9 +89,6 @@ typedef struct
GimpDrawable *drawable;
GimpPreview *preview;
GtkWidget *coords;
- gint cursor_drawn;
- gint curx, cury; /* x,y of cursor in preview */
- gint oldx, oldy;
} NovaCenter;
@@ -111,10 +108,8 @@ static gboolean nova_dialog (GimpDrawable *drawable);
static GtkWidget * nova_center_create (GimpDrawable *drawable,
GimpPreview *preview);
-static void nova_center_cursor_draw (NovaCenter *center);
static void nova_center_coords_update (GimpSizeEntry *coords,
NovaCenter *center);
-static void nova_center_cursor_update (NovaCenter *center);
static void nova_center_preview_realize (GtkWidget *widget,
NovaCenter *center);
static gboolean nova_center_preview_expose (GtkWidget *widget,
@@ -435,13 +430,8 @@ nova_center_create (GimpDrawable *drawable,
center = g_new0 (NovaCenter, 1);
- center->drawable = drawable;
- center->preview = preview;
- center->cursor_drawn = FALSE;
- center->curx = 0;
- center->cury = 0;
- center->oldx = 0;
- center->oldy = 0;
+ center->drawable = drawable;
+ center->preview = preview;
frame = gimp_frame_new (_("Center of Nova"));
@@ -491,8 +481,8 @@ nova_center_create (GimpDrawable *drawable,
G_CALLBACK (gimp_toggle_button_update),
&show_cursor);
g_signal_connect_swapped (check, "toggled",
- G_CALLBACK (gimp_preview_invalidate),
- preview);
+ G_CALLBACK (gtk_widget_queue_draw),
+ preview->area);
g_signal_connect (preview->area, "realize",
G_CALLBACK (nova_center_preview_realize),
@@ -504,61 +494,10 @@ nova_center_create (GimpDrawable *drawable,
G_CALLBACK (nova_center_preview_events),
center);
- nova_center_cursor_update (center);
-
return frame;
}
/*
- * Drawing CenterFrame
- * if update & PREVIEW, draw preview
- * if update & CURSOR, draw cross cursor
- */
-
-static void
-nova_center_cursor_draw (NovaCenter *center)
-{
- GtkWidget *prvw = center->preview->area;
- GtkStyle *style = gtk_widget_get_style (prvw);
- gint width, height;
-
- gimp_preview_get_size (center->preview, &width, &height);
-
- gdk_gc_set_function (style->black_gc, GDK_INVERT);
-
- if (show_cursor)
- {
- if (center->cursor_drawn)
- {
- gdk_draw_line (gtk_widget_get_window (prvw),
- style->black_gc,
- center->oldx, 1, center->oldx,
- height - 1);
- gdk_draw_line (gtk_widget_get_window (prvw),
- style->black_gc,
- 1, center->oldy,
- width - 1, center->oldy);
- }
-
- gdk_draw_line (gtk_widget_get_window (prvw),
- style->black_gc,
- center->curx, 1, center->curx,
- height - 1);
- gdk_draw_line (gtk_widget_get_window (prvw),
- style->black_gc,
- 1, center->cury,
- width - 1, center->cury);
- }
-
- /* current position of cursor is updated */
- center->oldx = center->curx;
- center->oldy = center->cury;
- center->cursor_drawn = TRUE;
-
- gdk_gc_set_function (style->black_gc, GDK_COPY);
-}
-
-/*
* CenterFrame entry callback
*/
static void
@@ -568,25 +507,10 @@ nova_center_coords_update (GimpSizeEntry *coords,
pvals.xcenter = gimp_size_entry_get_refval (coords, 0);
pvals.ycenter = gimp_size_entry_get_refval (coords, 1);
- nova_center_cursor_update (center);
- nova_center_cursor_draw (center);
-
gimp_preview_invalidate (center->preview);
}
/*
- * Update the cross cursor's coordinates accoding to pvals.[xy]center
- * but do not redraw it.
- */
-static void
-nova_center_cursor_update (NovaCenter *center)
-{
- gimp_preview_transform (center->preview,
- pvals.xcenter, pvals.ycenter,
- ¢er->curx, ¢er->cury);
-}
-
-/*
* Set the preview area'a cursor on realize
*/
static void
@@ -608,10 +532,35 @@ nova_center_preview_expose (GtkWidget *widget,
GdkEvent *event,
NovaCenter *center)
{
- center->cursor_drawn = FALSE;
+ if (show_cursor)
+ {
+ GtkWidget *prvw = center->preview->area;
+ cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (prvw));
+ gint width, height;
+ gint x, y;
- nova_center_cursor_update (center);
- nova_center_cursor_draw (center);
+ gimp_preview_transform (center->preview,
+ pvals.xcenter, pvals.ycenter,
+ &x, &y);
+
+ gimp_preview_get_size (center->preview, &width, &height);
+
+ cairo_move_to (cr, x + 0.5, 1);
+ cairo_line_to (cr, x + 0.5, height - 1);
+
+ cairo_move_to (cr, 1, y + 0.5);
+ cairo_line_to (cr, width - 1, y + 0.5);
+
+ cairo_set_line_width (cr, 3.0);
+ cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.3);
+ cairo_stroke_preserve (cr);
+
+ cairo_set_line_width (cr, 1.0);
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.7);
+ cairo_stroke (cr);
+
+ cairo_destroy (cr);
+ }
return FALSE;
}
@@ -630,8 +579,6 @@ nova_center_update (GtkWidget *widget,
gimp_preview_untransform (center->preview, x, y, &tx, &ty);
- nova_center_cursor_draw (center);
-
g_signal_handlers_block_by_func (center->coords,
nova_center_coords_update,
center);
@@ -645,6 +592,8 @@ nova_center_update (GtkWidget *widget,
nova_center_coords_update (GIMP_SIZE_ENTRY (center->coords), center);
+ gtk_widget_queue_draw (center->preview->area);
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]