[gimp] plug-ins: lighting, use an expose handler and remove unneeded backbuf
- From: Mikael Magnusson <mikachu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: lighting, use an expose handler and remove unneeded backbuf
- Date: Sun, 20 Feb 2011 15:45:46 +0000 (UTC)
commit 2260b1556855d518fc9d96c6665f5d1fe9cf2361
Author: Mikael Magnusson <mikachu src gnome org>
Date: Sun Feb 20 16:43:36 2011 +0100
plug-ins: lighting, use an expose handler and remove unneeded backbuf
plug-ins/lighting/lighting-preview.c | 172 ++++++++--------------------------
plug-ins/lighting/lighting-preview.h | 4 +-
plug-ins/lighting/lighting-ui.c | 17 +++-
3 files changed, 56 insertions(+), 137 deletions(-)
---
diff --git a/plug-ins/lighting/lighting-preview.c b/plug-ins/lighting/lighting-preview.c
index 5d2ca08..f3c5dc3 100644
--- a/plug-ins/lighting/lighting-preview.c
+++ b/plug-ins/lighting/lighting-preview.c
@@ -20,16 +20,8 @@
#define LIGHT_SYMBOL_SIZE 8
-typedef struct
-{
- gint x, y, w, h;
- cairo_surface_t *image;
-} BackBuffer;
-
static gint handle_xpos = 0, handle_ypos = 0;
-static BackBuffer backbuf = { 0, 0, 0, 0, NULL };
-
/* g_free()'ed on exit */
gdouble *xpostab = NULL;
gdouble *ypostab = NULL;
@@ -312,83 +304,6 @@ draw_handles (void)
cairo_set_line_width (cr, 1.0);
- /* Restore background if it has been saved */
- /* ======================================= */
-
- if (backbuf.image != NULL)
- {
- cairo_rectangle (cr, backbuf.x, backbuf.y, backbuf.w, backbuf.h);
- cairo_clip (cr);
- cairo_set_source_surface (cr, backbuf.image, 0.0, 0.0);
- cairo_paint (cr);
-
- cairo_surface_destroy (backbuf.image);
- cairo_reset_clip (cr);
- cairo_rectangle (cr, 0, 0, PREVIEW_WIDTH, PREVIEW_HEIGHT);
- cairo_clip (cr);
- backbuf.image = NULL;
- }
-
- /* calculate backbuffer */
- switch (mapvals.lightsource[k].type)
- {
- case POINT_LIGHT:
- backbuf.x = handle_xpos - LIGHT_SYMBOL_SIZE / 2 - 1;
- backbuf.y = handle_ypos - LIGHT_SYMBOL_SIZE / 2 - 1;
- backbuf.w = LIGHT_SYMBOL_SIZE + 2;
- backbuf.h = LIGHT_SYMBOL_SIZE + 2;
- break;
- case DIRECTIONAL_LIGHT:
- if (delta_x <= 0)
- backbuf.x = handle_xpos;
- else
- backbuf.x = startx + pw/2;
- if (delta_y <= 0)
- backbuf.y = handle_ypos;
- else
- backbuf.y = starty + ph/2;
- backbuf.x -= LIGHT_SYMBOL_SIZE/2 + 1;
- backbuf.y -= LIGHT_SYMBOL_SIZE/2 + 1;
- backbuf.w = fabs(delta_x) + LIGHT_SYMBOL_SIZE + 2;
- backbuf.h = fabs(delta_y) + LIGHT_SYMBOL_SIZE + 2;
- break;
- case SPOT_LIGHT:
- backbuf.x = handle_xpos - LIGHT_SYMBOL_SIZE / 2 - 1;
- backbuf.y = handle_ypos - LIGHT_SYMBOL_SIZE / 2 - 1;
- backbuf.w = LIGHT_SYMBOL_SIZE + 2;
- backbuf.h = LIGHT_SYMBOL_SIZE + 2;
- break;
- case NO_LIGHT:
- break;
- }
-
- /* Save background */
- /* =============== */
- if ((backbuf.x + backbuf.w >= 0) &&
- (backbuf.x <= PREVIEW_WIDTH) &&
- (backbuf.y + backbuf.h >= 0) && (backbuf.y <= PREVIEW_HEIGHT))
- {
- cairo_t *cr;
-
- backbuf.image = cairo_surface_create_similar (preview_surface,
- CAIRO_CONTENT_COLOR,
- PREVIEW_WIDTH,
- PREVIEW_HEIGHT);
- cr = cairo_create (backbuf.image);
- /* clip coordinates to preview widget sizes */
- if ((backbuf.x + backbuf.w) > PREVIEW_WIDTH)
- backbuf.w = (PREVIEW_WIDTH - backbuf.x);
-
- if ((backbuf.y + backbuf.h) > PREVIEW_HEIGHT)
- backbuf.h = (PREVIEW_HEIGHT - backbuf.y);
-
- cairo_rectangle (cr, backbuf.x, backbuf.y, backbuf.w, backbuf.h);
- cairo_clip (cr);
- cairo_set_source_surface (cr, preview_surface, 0.0, 0.0);
- cairo_paint (cr);
- cairo_destroy (cr);
- }
-
color.red = 0x0;
color.green = 0x4000;
color.blue = 0xFFFF;
@@ -463,53 +378,27 @@ update_light (gint xpos, gint ypos)
/******************************************************************/
void
-draw_preview_image (gboolean recompute)
+preview_compute (void)
{
- gint startx, starty, pw, ph;
- cairo_t *cr;
+ GdkDisplay *display = gtk_widget_get_display (previewarea);
+ GdkCursor *cursor;
+ gint startx, starty, pw, ph;
compute_preview_rectangle (&startx, &starty, &pw, &ph);
- if (recompute)
- {
- GdkDisplay *display = gtk_widget_get_display (previewarea);
- GdkCursor *cursor;
+ cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
- cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
+ gdk_window_set_cursor (gtk_widget_get_window (previewarea), cursor);
+ gdk_cursor_unref (cursor);
- gdk_window_set_cursor (gtk_widget_get_window (previewarea), cursor);
- gdk_cursor_unref (cursor);
-
- compute_preview (startx, starty, pw, ph);
- cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
- gdk_window_set_cursor (gtk_widget_get_window (previewarea), cursor);
- gdk_cursor_unref (cursor);
- gdk_flush ();
-
- /* if we recompute, clear backbuf, so we don't
- * restore the wrong bitmap */
- if (backbuf.image != NULL)
- {
- cairo_surface_destroy (backbuf.image);
- backbuf.image = NULL;
- }
- }
-
- cr = gdk_cairo_create (gtk_widget_get_window (previewarea));
-
- cairo_set_source_surface (cr, preview_surface, 0.0, 0.0);
-
- cairo_paint (cr);
-
- cairo_destroy (cr);
-
- /* draw symbols if enabled in UI */
- if (mapvals.interactive_preview)
- {
- draw_handles ();
- }
+ compute_preview (startx, starty, pw, ph);
+ cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
+ gdk_window_set_cursor (gtk_widget_get_window (previewarea), cursor);
+ gdk_cursor_unref (cursor);
+ gdk_flush ();
}
+
/******************************/
/* Preview area event handler */
/******************************/
@@ -520,10 +409,6 @@ preview_events (GtkWidget *area,
{
switch (event->type)
{
- case GDK_EXPOSE:
-
- draw_preview_image (FALSE);
- break;
case GDK_ENTER_NOTIFY:
break;
case GDK_LEAVE_NOTIFY:
@@ -540,7 +425,7 @@ preview_events (GtkWidget *area,
light_hit == TRUE &&
mapvals.interactive_preview == TRUE )
{
- draw_handles();
+ gtk_widget_queue_draw (previewarea);
interactive_preview_callback(NULL);
update_light (event->motion.x, event->motion.y);
}
@@ -552,6 +437,29 @@ preview_events (GtkWidget *area,
return FALSE;
}
+gboolean
+preview_expose (GtkWidget *area,
+ GdkEventExpose *eevent)
+{
+ cairo_t *cr;
+
+ cr = gdk_cairo_create (eevent->window);
+
+ cairo_set_source_surface (cr, preview_surface, 0.0, 0.0);
+
+ cairo_paint (cr);
+
+ /* draw symbols if enabled in UI */
+ if (mapvals.interactive_preview)
+ {
+ draw_handles ();
+ }
+
+ cairo_destroy (cr);
+
+ return FALSE;
+}
+
void
interactive_preview_callback (GtkWidget *widget)
{
@@ -565,7 +473,7 @@ interactive_preview_callback (GtkWidget *widget)
}
static gboolean
-interactive_preview_timer_callback ( gpointer data )
+interactive_preview_timer_callback (gpointer data)
{
gint k = mapvals.light_selected;
@@ -586,7 +494,9 @@ interactive_preview_timer_callback ( gpointer data )
mapvals.update_enabled = TRUE;
- draw_preview_image (TRUE);
+ preview_compute ();
+
+ gtk_widget_queue_draw (previewarea);
preview_update_timer = 0;
diff --git a/plug-ins/lighting/lighting-preview.h b/plug-ins/lighting/lighting-preview.h
index d1698e6..f96edb0 100644
--- a/plug-ins/lighting/lighting-preview.h
+++ b/plug-ins/lighting/lighting-preview.h
@@ -26,10 +26,12 @@ extern gdouble *xpostab, *ypostab;
/* Externally visible functions */
-void draw_preview_image (gboolean recompute);
+void preview_compute (void);
void interactive_preview_callback (GtkWidget *widget);
gboolean preview_events (GtkWidget *area,
GdkEvent *event);
+gboolean preview_expose (GtkWidget *area,
+ GdkEventExpose *eevent);
void update_light (gint xpos,
gint ypos);
diff --git a/plug-ins/lighting/lighting-ui.c b/plug-ins/lighting/lighting-ui.c
index 126f6e2..4480f49 100644
--- a/plug-ins/lighting/lighting-ui.c
+++ b/plug-ins/lighting/lighting-ui.c
@@ -101,7 +101,8 @@ toggle_update (GtkWidget *widget,
{
gimp_toggle_button_update (widget, data);
- draw_preview_image (TRUE);
+ preview_compute ();
+ gtk_widget_queue_draw (previewarea);
}
@@ -111,7 +112,8 @@ distance_update (GtkAdjustment *adj,
{
mapvals.viewpoint.z = gtk_adjustment_get_value (adj);
- draw_preview_image (TRUE);
+ preview_compute ();
+ gtk_widget_queue_draw (previewarea);
}
@@ -197,7 +199,8 @@ mapmenu2_callback (GtkWidget *widget,
{
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), (gint *) data);
- draw_preview_image (TRUE);
+ preview_compute ();
+ gtk_widget_queue_draw (previewarea);
}
/******************************************/
@@ -207,7 +210,8 @@ mapmenu2_callback (GtkWidget *widget,
static void
preview_callback (GtkWidget *widget)
{
- draw_preview_image (TRUE);
+ preview_compute ();
+ gtk_widget_queue_draw (previewarea);
}
@@ -1062,6 +1066,9 @@ main_dialog (GimpDrawable *drawable)
g_signal_connect (previewarea, "event",
G_CALLBACK (preview_events),
previewarea);
+ g_signal_connect (previewarea, "expose-event",
+ G_CALLBACK (preview_expose),
+ previewarea);
gtk_container_add (GTK_CONTAINER (frame), previewarea);
gtk_widget_show (previewarea);
@@ -1111,7 +1118,7 @@ main_dialog (GimpDrawable *drawable)
image_setup (drawable, TRUE);
- draw_preview_image (TRUE);
+ preview_compute ();
if (gimp_dialog_run (GIMP_DIALOG (appwin)) == GTK_RESPONSE_OK)
run = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]