[gimp] lighting: port to cairo, replace wireframe with live preview



commit 49fc3a125e30b9ff630d958707f3dc088691d398
Author: Mikael Magnusson <mikachu src gnome org>
Date:   Sun Feb 13 10:00:48 2011 +0100

    lighting: port to cairo, replace wireframe with live preview

 plug-ins/map-object/map-object-image.c   |   13 +-
 plug-ins/map-object/map-object-image.h   |    4 +-
 plug-ins/map-object/map-object-main.c    |    2 +-
 plug-ins/map-object/map-object-main.h    |    2 +-
 plug-ins/map-object/map-object-preview.c |  823 ++++--------------------------
 plug-ins/map-object/map-object-preview.h |   23 -
 plug-ins/map-object/map-object-ui.c      |  139 ++----
 plug-ins/map-object/map-object-ui.h      |    1 -
 8 files changed, 155 insertions(+), 852 deletions(-)
---
diff --git a/plug-ins/map-object/map-object-image.c b/plug-ins/map-object/map-object-image.c
index 25e29b8..a38efae 100644
--- a/plug-ins/map-object/map-object-image.c
+++ b/plug-ins/map-object/map-object-image.c
@@ -32,7 +32,9 @@ GimpPixelRgn box_regions[6];
 GimpDrawable *cylinder_drawables[2];
 GimpPixelRgn cylinder_regions[2];
 
-guchar   *preview_rgb_data = NULL;
+guchar          *preview_rgb_data = NULL;
+gint             preview_rgb_stride;
+cairo_surface_t *preview_surface = NULL;
 
 glong   maxcounter,old_depth,max_depth;
 gint    imgtype,width,height,in_channels,out_channels;
@@ -389,7 +391,14 @@ image_setup (GimpDrawable *drawable,
 
   if (interactive == TRUE)
     {
-      preview_rgb_data = g_new0 (guchar, PREVIEW_HEIGHT * PREVIEW_WIDTH * 3);
+      preview_rgb_stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24,
+                                                          PREVIEW_WIDTH);
+      preview_rgb_data = g_new0 (guchar, preview_rgb_stride * PREVIEW_HEIGHT);
+      preview_surface = cairo_image_surface_create_for_data (preview_rgb_data,
+                                                             CAIRO_FORMAT_RGB24,
+                                                             PREVIEW_WIDTH,
+                                                             PREVIEW_HEIGHT,
+                                                             preview_rgb_stride);
     }
 
   return TRUE;
diff --git a/plug-ins/map-object/map-object-image.h b/plug-ins/map-object/map-object-image.h
index e883511..db9bb31 100644
--- a/plug-ins/map-object/map-object-image.h
+++ b/plug-ins/map-object/map-object-image.h
@@ -13,7 +13,9 @@ extern GimpPixelRgn  box_regions[6];
 extern GimpDrawable *cylinder_drawables[2];
 extern GimpPixelRgn  cylinder_regions[2];
 
-extern guchar   *preview_rgb_data;
+extern guchar          *preview_rgb_data;
+extern gint             preview_rgb_stride;
+extern cairo_surface_t *preview_surface;
 
 extern glong   maxcounter, old_depth, max_depth;
 extern gint    imgtype, width,height, in_channels, out_channels;
diff --git a/plug-ins/map-object/map-object-main.c b/plug-ins/map-object/map-object-main.c
index a88e9e7..8d75ad6 100644
--- a/plug-ins/map-object/map-object-main.c
+++ b/plug-ins/map-object/map-object-main.c
@@ -80,7 +80,7 @@ set_default_settings (void)
   mapvals.create_new_image       = FALSE;
   mapvals.transparent_background = FALSE;
   mapvals.tiled                  = FALSE;
-  mapvals.showgrid               = FALSE;
+  mapvals.livepreview            = TRUE;
 
   mapvals.lightsource.intensity = 1.0;
   gimp_rgba_set (&mapvals.lightsource.color, 1.0, 1.0, 1.0, 1.0);
diff --git a/plug-ins/map-object/map-object-main.h b/plug-ins/map-object/map-object-main.h
index ac685b6..5766907 100644
--- a/plug-ins/map-object/map-object-main.h
+++ b/plug-ins/map-object/map-object-main.h
@@ -63,7 +63,7 @@ typedef struct
   gint create_new_image;
   gint transparent_background;
   gint tiled;
-  gint showgrid;
+  gint livepreview;
   gint showcaps;
 
   gdouble zoom;
diff --git a/plug-ins/map-object/map-object-preview.c b/plug-ins/map-object/map-object-preview.c
index 7bb8017..89c3890 100644
--- a/plug-ins/map-object/map-object-preview.c
+++ b/plug-ins/map-object/map-object-preview.c
@@ -17,11 +17,17 @@
 #include "map-object-preview.h"
 
 
-line    linetab[WIRESIZE*2+8];
+typedef struct
+{
+  gint x, y, w, h;
+  cairo_surface_t *image;
+} BackBuffer;
+
 gdouble mat[3][4];
 
 gint       lightx, lighty;
-BackBuffer backbuf = { 0, 0, 0, 0, NULL };
+
+static BackBuffer backbuf = { 0, 0, 0, 0, NULL };
 
 /* Protos */
 /* ====== */
@@ -30,122 +36,6 @@ static void draw_light_marker       (gint        xpos,
 				     gint        ypos);
 static void clear_light_marker      (void);
 
-static gint draw_line               (gint        n,
-				     gint        startx,
-				     gint        starty,
-				     gint        pw,
-				     gint        ph,
-				     gdouble     cx1,
-				     gdouble     cy1,
-				     gdouble     cx2,
-				     gdouble     cy2,
-				     GimpVector3 a,
-				     GimpVector3 b);
-
-static void draw_wireframe_plane    (gint        startx,
-				     gint        starty,
-				     gint        pw,
-				     gint        ph);
-static void draw_wireframe_sphere   (gint        startx,
-				     gint        starty,
-				     gint        pw,
-				     gint        ph);
-static void draw_wireframe_box      (gint        startx,
-				     gint        starty,
-				     gint        pw,
-				     gint        ph);
-static void draw_wireframe_cylinder (gint        startx,
-				     gint        starty,
-				     gint        pw,
-				     gint        ph);
-
-/*************************************************/
-/* Quick and dirty (and slow) line clip routine. */
-/* The function returns FALSE if the line isn't  */
-/* visible according to the limits given.        */
-/*************************************************/
-
-static gboolean
-clip_line (gdouble *x1,
-	   gdouble *y1,
-	   gdouble *x2,
-	   gdouble *y2,
-	   gdouble  minx,
-	   gdouble  miny,
-	   gdouble  maxx,
-	   gdouble  maxy)
-{
-  gdouble tmp;
-
-  g_assert (x1 != NULL);
-  g_assert (y1 != NULL);
-  g_assert (x2 != NULL);
-  g_assert (y2 != NULL);
-
-  /* First, check if line is visible at all */
-  /* ====================================== */
-
-  if (*x1 < minx && *x2 < minx) return FALSE;
-  if (*x1 > maxx && *x2 > maxx) return FALSE;
-  if (*y1 < miny && *y2 < miny) return FALSE;
-  if (*y1 > maxy && *y2 > maxy) return FALSE;
-
-  /* Check for intersection with the four edges. Sort on x first. */
-  /* ============================================================ */
-
-  if (*x2 < *x1)
-    {
-      tmp = *x1;
-      *x1 = *x2;
-      *x2 = tmp;
-      tmp = *y1;
-      *y1 = *y2;
-      *y2 = tmp;
-    }
-
-  if (*x1 < minx)
-    {
-      if (*y1 < *y2) *y1 = *y1 + (minx - *x1) * ((*y2 - *y1) / (*x2 - *x1));
-      else           *y1 = *y1 - (minx - *x1) * ((*y1 - *y2) / (*x2 - *x1));
-
-      *x1 = minx;
-    }
-
-  if (*x2 > maxx)
-    {
-      if (*y1 < *y2) *y2 = *y2 - (*x2 - maxx) * ((*y2 - *y1) / (*x2 - *x1));
-      else           *y2 = *y2 + (*x2 - maxx) * ((*y1 - *y2) / (*x2 - *x1));
-
-      *x2 = maxx;
-    }
-
-  if (*y1 < miny)
-    {
-      *x1 = *x1 + (miny - *y1) * ((*x2 - *x1) / (*y2 - *y1));
-      *y1 = miny;
-    }
-
-  if (*y2 < miny)
-    {
-      *x2 = *x2 - (miny - *y2) * ((*x2 - *x1) / (*y1 - *y2));
-      *y2 = miny;
-    }
-
-  if (*y1 > maxy)
-    {
-      *x1 = *x1 + (*y1 - maxy) * ((*x2 - *x1) / (*y1 - *y2));
-      *y1 = maxy;
-    }
-
-  if (*y2 > maxy)
-    {
-      *x2 = *x2 - (*y2 - maxy) * ((*x2 - *x1) / (*y2 - *y1));
-      *y2 = maxy;
-    }
-
-  return TRUE;
-}
-
 /**************************************************************/
 /* Computes a preview of the rectangle starting at (x,y) with */
 /* dimensions (w,h), placing the result in preview_RGB_data.  */
@@ -167,6 +57,7 @@ compute_preview (gint x,
   GimpRGB      color;
   GimpRGB      lightcheck, darkcheck;
   gint         xcnt, ycnt, f1, f2;
+  guchar       r, g, b;
   glong        index = 0;
 
   init_compute ();
@@ -205,8 +96,11 @@ compute_preview (gint x,
 		 GIMP_CHECK_DARK, GIMP_CHECK_DARK, GIMP_CHECK_DARK, 1.0);
   gimp_vector3_set (&p2, -1.0, -1.0, 0.0);
 
+  cairo_surface_flush (preview_surface);
+
   for (ycnt = 0; ycnt < ph; ycnt++)
     {
+      index = ycnt * preview_rgb_stride;
       for (xcnt = 0; xcnt < pw; xcnt++)
         {
           p1.x = xpostab[xcnt];
@@ -239,13 +133,12 @@ compute_preview (gint x,
                 }
             }
 
-	  gimp_rgb_get_uchar (&color,
-			      preview_rgb_data + index,
-			      preview_rgb_data + index + 1,
-			      preview_rgb_data + index + 2);
-	  index += 3;
+	  gimp_rgb_get_uchar (&color, &r, &g, &b);
+          GIMP_CAIRO_RGB24_SET_PIXEL((preview_rgb_data + index), r, g, b);
+          index += 4;
         }
     }
+  cairo_surface_mark_dirty (preview_surface);
 }
 
 /*************************************************/
@@ -283,54 +176,67 @@ draw_light_marker (gint xpos,
 		   gint ypos)
 {
   GdkColor  color;
+  cairo_t *cr, *cr_p;
+  gint pw, ph, startx, starty;
 
-  color.red   = 0x0;
-  color.green = 0x0;
-  color.blue  = 0x0;
-  gdk_gc_set_rgb_bg_color (gc, &color);
+  if (mapvals.lightsource.type != POINT_LIGHT)
+    return;
+
+  pw = PREVIEW_WIDTH * mapvals.zoom;
+  ph = PREVIEW_HEIGHT * mapvals.zoom;
+  startx = (PREVIEW_WIDTH - pw) / 2;
+  starty = (PREVIEW_HEIGHT - ph) / 2;
+
+  cr = gdk_cairo_create (gtk_widget_get_window (previewarea));
+
+  cairo_set_line_width (cr, 1.0);
 
   color.red   = 0x0;
   color.green = 0x4000;
   color.blue  = 0xFFFF;
-  gdk_gc_set_rgb_fg_color (gc, &color);
+  gdk_cairo_set_source_color (cr, &color);
 
-  gdk_gc_set_function (gc, GDK_COPY);
+  lightx = xpos;
+  lighty = ypos;
 
-  if (mapvals.lightsource.type == POINT_LIGHT)
-    {
-      lightx = xpos;
-      lighty = ypos;
-
-      /* Save background */
-      /* =============== */
-
-      backbuf.x = lightx - 7;
-      backbuf.y = lighty - 7;
-      backbuf.w = 14;
-      backbuf.h = 14;
-
-      /* X doesn't like images that's outside a window, make sure */
-      /* we get the backbuffer image from within the boundaries   */
-      /* ======================================================== */
-
-      if (backbuf.x < 0)
-        backbuf.x = 0;
-      else if ((backbuf.x + backbuf.w) > PREVIEW_WIDTH)
-        backbuf.w = (PREVIEW_WIDTH - backbuf.x);
-      if (backbuf.y < 0)
-        backbuf.y = 0;
-      else if ((backbuf.y + backbuf.h) > PREVIEW_HEIGHT)
-        backbuf.h = (PREVIEW_WIDTH - backbuf.y);
-
-      backbuf.image = gdk_drawable_get_image (gtk_widget_get_window (previewarea),
-                                              backbuf.x, backbuf.y,
-                                              backbuf.w, backbuf.h);
-
-      gdk_draw_arc (gtk_widget_get_window (previewarea), gc,
-		    TRUE,
-		    lightx - 7, lighty - 7, 14, 14,
-		    0, 360 * 64);
-    }
+  /* Save background */
+  /* =============== */
+
+  backbuf.x = lightx - 7;
+  backbuf.y = lighty - 7;
+  backbuf.w = 14;
+  backbuf.h = 14;
+
+  /* X doesn't like images that's outside a window, make sure */
+  /* we get the backbuffer image from within the boundaries   */
+  /* ======================================================== */
+
+  if (backbuf.x < startx)
+    backbuf.x = startx;
+  else if ((backbuf.x + backbuf.w) > startx + pw)
+    backbuf.w = MAX(startx + pw - backbuf.x, 0);
+  if (backbuf.y < starty)
+    backbuf.y = starty;
+  else if ((backbuf.y + backbuf.h) > starty + ph)
+    backbuf.h = MAX(starty + ph - backbuf.y, 0);
+
+  if (backbuf.image)
+    cairo_surface_destroy (backbuf.image);
+
+  backbuf.image = cairo_surface_create_similar (preview_surface,
+                                                CAIRO_CONTENT_COLOR,
+                                                PREVIEW_WIDTH, PREVIEW_HEIGHT);
+  cr_p = cairo_create (backbuf.image);
+  cairo_rectangle (cr_p, backbuf.x, backbuf.y, backbuf.w, backbuf.h);
+  cairo_clip (cr_p);
+  cairo_set_source_surface (cr_p, preview_surface, startx, starty);
+  cairo_paint (cr_p);
+  cairo_destroy (cr_p);
+
+  cairo_arc (cr, lightx, lighty, 7, 0, 2 * M_PI);
+  cairo_fill (cr);
+
+  cairo_destroy (cr);
 }
 
 static void
@@ -339,31 +245,42 @@ clear_light_marker (void)
   /* Restore background if it has been saved */
   /* ======================================= */
 
+  gint pw, ph, startx, starty;
+
   if (backbuf.image != NULL)
     {
-      GdkColor  color;
+      cairo_t *cr;
 
-      color.red   = 0x0;
-      color.green = 0x0;
-      color.blue  = 0x0;
-      gdk_gc_set_rgb_bg_color (gc, &color);
+      cr = gdk_cairo_create (gtk_widget_get_window (previewarea));
 
-      color.red   = 0xFFFF;
-      color.green = 0xFFFF;
-      color.blue  = 0xFFFF;
-      gdk_gc_set_rgb_fg_color (gc, &color);
+      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);
 
-      gdk_gc_set_function (gc, GDK_COPY);
+      cairo_destroy (cr);
 
-      gdk_draw_image (gtk_widget_get_window (previewarea), gc,
-		      backbuf.image,
-		      0, 0,
-		      backbuf.x, backbuf.y,
-		      backbuf.w, backbuf.h);
-
-      g_object_unref (backbuf.image);
+      cairo_surface_destroy (backbuf.image);
       backbuf.image = NULL;
     }
+
+  pw = PREVIEW_WIDTH * mapvals.zoom;
+  ph = PREVIEW_HEIGHT * mapvals.zoom;
+
+  if (pw != PREVIEW_WIDTH || ph != PREVIEW_HEIGHT)
+    {
+      startx = (PREVIEW_WIDTH - pw) / 2;
+      starty = (PREVIEW_HEIGHT - ph) / 2;
+
+      gdk_window_clear_area (gtk_widget_get_window (previewarea),
+                             0, 0, startx, PREVIEW_HEIGHT);
+      gdk_window_clear_area (gtk_widget_get_window (previewarea),
+                             startx, 0, pw, starty);
+      gdk_window_clear_area (gtk_widget_get_window (previewarea),
+                             pw + startx, 0, startx, PREVIEW_HEIGHT);
+      gdk_window_clear_area (gtk_widget_get_window (previewarea),
+                             startx, ph + starty, pw, starty);
+    }
 }
 
 static void
@@ -417,19 +334,14 @@ draw_preview_image (gint docompute)
 {
   gint startx, starty, pw, ph;
   GdkColor  color;
+  cairo_t *cr;
 
-  color.red   = 0x0;
-  color.green = 0x0;
-  color.blue  = 0x0;
-  gdk_gc_set_rgb_bg_color (gc, &color);
+  cr = gdk_cairo_create (gtk_widget_get_window (previewarea));
 
   color.red   = 0xFFFF;
   color.green = 0xFFFF;
   color.blue  = 0xFFFF;
-  gdk_gc_set_rgb_fg_color (gc, &color);
-
-  gdk_gc_set_function (gc, GDK_COPY);
-  linetab[0].x1 = -1;
+  gdk_cairo_set_source_color (cr, &color);
 
   pw = PREVIEW_WIDTH * mapvals.zoom;
   ph = PREVIEW_HEIGHT * mapvals.zoom;
@@ -457,534 +369,13 @@ draw_preview_image (gint docompute)
   if (pw != PREVIEW_WIDTH || ph != PREVIEW_HEIGHT)
     gdk_window_clear (gtk_widget_get_window (previewarea));
 
-  gdk_draw_rgb_image (gtk_widget_get_window (previewarea), gc,
-                      startx, starty, pw, ph,
-                      GDK_RGB_DITHER_MAX,
-                      preview_rgb_data, 3 * pw);
-
-  draw_lights (startx, starty, pw, ph);
-}
-
-/**************************/
-/* Draw preview wireframe */
-/**************************/
-
-void
-draw_preview_wireframe (void)
-{
-  gint      startx, starty, pw, ph;
-  GdkColor  color;
-
-  color.red   = 0x0;
-  color.green = 0x0;
-  color.blue  = 0x0;
-  gdk_gc_set_rgb_bg_color (gc, &color);
-
-  color.red   = 0xFFFF;
-  color.green = 0xFFFF;
-  color.blue  = 0xFFFF;
-  gdk_gc_set_rgb_fg_color (gc, &color);
-
-  gdk_gc_set_function (gc, GDK_INVERT);
-
-  pw     = PREVIEW_WIDTH  * mapvals.zoom;
-  ph     = PREVIEW_HEIGHT * mapvals.zoom;
-  startx = (PREVIEW_WIDTH  - pw) / 2;
-  starty = (PREVIEW_HEIGHT - ph) / 2;
-
-  clear_wireframe ();
-  draw_wireframe (startx, starty, pw, ph);
-}
-
-/****************************/
-/* Draw a wireframe preview */
-/****************************/
+  cairo_set_source_surface (cr, preview_surface, startx, starty);
+  cairo_rectangle (cr, startx, starty, pw, ph);
+  cairo_clip (cr);
 
-void
-draw_wireframe (gint startx,
-		gint starty,
-		gint pw,
-		gint ph)
-{
-  switch (mapvals.maptype)
-    {
-    case MAP_PLANE:
-      draw_wireframe_plane (startx, starty, pw, ph);
-      break;
-    case MAP_SPHERE:
-      draw_wireframe_sphere (startx, starty, pw, ph);
-      break;
-    case MAP_BOX:
-      draw_wireframe_box (startx, starty, pw, ph);
-      break;
-    case MAP_CYLINDER:
-      draw_wireframe_cylinder (startx, starty, pw, ph);
-      break;
-    }
-}
-
-static void
-draw_wireframe_plane (gint startx,
-		      gint starty,
-		      gint pw,
-		      gint ph)
-{
-  GimpVector3 v1, v2, a, b, c, d, dir1, dir2;
-  gint        cnt, n = 0;
-  gdouble     x1, y1, x2, y2, cx1, cy1, cx2, cy2, fac;
-
-  /* Find rotated box corners */
-  /* ======================== */
-
-  gimp_vector3_set (&v1, 0.5, 0.0, 0.0);
-  gimp_vector3_set (&v2, 0.0, 0.5, 0.0);
-
-  gimp_vector3_rotate (&v1,
-		       gimp_deg_to_rad (mapvals.alpha),
-		       gimp_deg_to_rad (mapvals.beta),
-		       gimp_deg_to_rad (mapvals.gamma));
-
-  gimp_vector3_rotate (&v2,
-		       gimp_deg_to_rad (mapvals.alpha),
-		       gimp_deg_to_rad (mapvals.beta),
-		       gimp_deg_to_rad (mapvals.gamma));
-
-  dir1 = v1; gimp_vector3_normalize (&dir1);
-  dir2 = v2; gimp_vector3_normalize (&dir2);
-
-  fac = 1.0 / (gdouble) WIRESIZE;
-
-  gimp_vector3_mul (&dir1, fac);
-  gimp_vector3_mul (&dir2, fac);
-
-  gimp_vector3_add (&a, &mapvals.position, &v1);
-  gimp_vector3_sub (&b, &a, &v2);
-  gimp_vector3_add (&a, &a, &v2);
-  gimp_vector3_sub (&d, &mapvals.position, &v1);
-  gimp_vector3_sub (&d, &d, &v2);
-
-  c = b;
-
-  cx1 = (gdouble) startx;
-  cy1 = (gdouble) starty;
-  cx2 = cx1 + (gdouble) pw;
-  cy2 = cy1 + (gdouble) ph;
-
-  for (cnt = 0; cnt <= WIRESIZE; cnt++)
-    {
-      gimp_vector_3d_to_2d (startx, starty, pw, ph,
-			    &x1, &y1, &mapvals.viewpoint, &a);
-      gimp_vector_3d_to_2d (startx, starty, pw, ph,
-			    &x2, &y2, &mapvals.viewpoint, &b);
-
-      if (clip_line (&x1, &y1, &x2, &y2, cx1, cy1, cx2, cy2) == TRUE)
-        {
-          linetab[n].x1 = RINT (x1);
-          linetab[n].y1 = RINT (y1);
-          linetab[n].x2 = RINT (x2);
-          linetab[n].y2 = RINT (y2);
-          linetab[n].linewidth = 1;
-          linetab[n].linestyle = GDK_LINE_SOLID;
-          gdk_gc_set_line_attributes (gc,
-				      linetab[n].linewidth,
-				      linetab[n].linestyle,
-				      GDK_CAP_NOT_LAST,
-				      GDK_JOIN_MITER);
-          gdk_draw_line (gtk_widget_get_window (previewarea), gc,
-			 linetab[n].x1, linetab[n].y1,
-			 linetab[n].x2, linetab[n].y2);
-          n++;
-        }
-
-      gimp_vector_3d_to_2d (startx, starty, pw, ph,
-			    &x1, &y1, &mapvals.viewpoint, &c);
-      gimp_vector_3d_to_2d (startx, starty, pw, ph,
-			    &x2, &y2, &mapvals.viewpoint, &d);
-
-      if (clip_line (&x1, &y1, &x2, &y2, cx1, cy1, cx2, cy2) == TRUE)
-        {
-          linetab[n].x1 = RINT (x1);
-          linetab[n].y1 = RINT (y1);
-          linetab[n].x2 = RINT (x2);
-          linetab[n].y2 = RINT (y2);
-          linetab[n].linewidth = 1;
-          linetab[n].linestyle = GDK_LINE_SOLID;
-          gdk_gc_set_line_attributes (gc,
-				      linetab[n].linewidth,
-				      linetab[n].linestyle,
-				      GDK_CAP_NOT_LAST,
-				      GDK_JOIN_MITER);
-          gdk_draw_line (gtk_widget_get_window (previewarea), gc,
-			 linetab[n].x1, linetab[n].y1,
-			 linetab[n].x2, linetab[n].y2);
-          n++;
-        }
-
-      gimp_vector3_sub (&a, &a, &dir1);
-      gimp_vector3_sub (&b, &b, &dir1);
-      gimp_vector3_add (&c, &c, &dir2);
-      gimp_vector3_add (&d, &d, &dir2);
-    }
+  cairo_paint (cr);
 
-  /* Mark end of lines */
-  /* ================= */
-
-  linetab[n].x1 = -1;
-}
-
-static void
-draw_wireframe_sphere (gint startx,
-		       gint starty,
-		       gint pw,
-		       gint ph)
-{
-  GimpVector3 p[2 * (WIRESIZE + 5)];
-  gint        cnt, cnt2, n = 0;
-  gdouble     x1, y1, x2, y2, twopifac, cx1, cy1, cx2, cy2;
-
-  /* Compute wireframe points */
-  /* ======================== */
-
-  twopifac = (2.0 * G_PI) / WIRESIZE;
-
-  for (cnt = 0; cnt < WIRESIZE; cnt++)
-    {
-      p[cnt].x = mapvals.radius * cos ((gdouble) cnt * twopifac);
-      p[cnt].y = 0.0;
-      p[cnt].z = mapvals.radius * sin ((gdouble) cnt * twopifac);
-      gimp_vector3_rotate (&p[cnt],
-			   gimp_deg_to_rad (mapvals.alpha),
-			   gimp_deg_to_rad (mapvals.beta),
-			   gimp_deg_to_rad (mapvals.gamma));
-      gimp_vector3_add (&p[cnt], &p[cnt], &mapvals.position);
-    }
-
-  p[cnt] = p[0];
-
-  for (cnt = WIRESIZE + 1; cnt < 2 * WIRESIZE + 1; cnt++)
-    {
-      p[cnt].x = mapvals.radius * cos ((gdouble) (cnt-(WIRESIZE+1))*twopifac);
-      p[cnt].y = mapvals.radius * sin ((gdouble) (cnt-(WIRESIZE+1))*twopifac);
-      p[cnt].z = 0.0;
-      gimp_vector3_rotate (&p[cnt],
-			   gimp_deg_to_rad (mapvals.alpha),
-			   gimp_deg_to_rad (mapvals.beta),
-			   gimp_deg_to_rad (mapvals.gamma));
-      gimp_vector3_add (&p[cnt], &p[cnt], &mapvals.position);
-    }
-
-  p[cnt] = p[WIRESIZE+1];
-  cnt++;
-  cnt2 = cnt;
-
-  /* Find rotated axis */
-  /* ================= */
-
-  gimp_vector3_set (&p[cnt], 0.0, -0.35, 0.0);
-  gimp_vector3_rotate (&p[cnt],
-		       gimp_deg_to_rad (mapvals.alpha),
-		       gimp_deg_to_rad (mapvals.beta),
-		       gimp_deg_to_rad (mapvals.gamma));
-  p[cnt+1] = mapvals.position;
-
-  gimp_vector3_set (&p[cnt+2], 0.0, 0.0, -0.35);
-  gimp_vector3_rotate (&p[cnt+2],
-		       gimp_deg_to_rad (mapvals.alpha),
-		       gimp_deg_to_rad (mapvals.beta),
-		       gimp_deg_to_rad (mapvals.gamma));
-  p[cnt+3] = mapvals.position;
-
-  p[cnt + 4] = p[cnt];
-  gimp_vector3_mul (&p[cnt + 4], -1.0);
-  p[cnt + 5] = p[cnt + 1];
-
-  gimp_vector3_add (&p[cnt],     &p[cnt],     &mapvals.position);
-  gimp_vector3_add (&p[cnt + 2], &p[cnt + 2], &mapvals.position);
-  gimp_vector3_add (&p[cnt + 4], &p[cnt + 4], &mapvals.position);
-
-  /* Draw the circles (equator and zero meridian) */
-  /* ============================================ */
-
-  cx1 = (gdouble) startx;
-  cy1 = (gdouble) starty;
-  cx2 = cx1 + (gdouble) pw;
-  cy2 = cy1 + (gdouble) ph;
-
-  for (cnt = 0; cnt < cnt2 - 1; cnt++)
-    {
-      if (p[cnt].z > mapvals.position.z && p[cnt + 1].z > mapvals.position.z)
-        {
-          gimp_vector_3d_to_2d (startx, starty, pw, ph,
-				&x1, &y1, &mapvals.viewpoint, &p[cnt]);
-          gimp_vector_3d_to_2d (startx, starty, pw, ph,
-				&x2, &y2, &mapvals.viewpoint, &p[cnt + 1]);
-
-          if (clip_line (&x1, &y1, &x2, &y2, cx1, cy1, cx2, cy2) == TRUE)
-            {
-              linetab[n].x1 = (gint) (x1 + 0.5);
-              linetab[n].y1 = (gint) (y1 + 0.5);
-              linetab[n].x2 = (gint) (x2 + 0.5);
-              linetab[n].y2 = (gint) (y2 + 0.5);
-              linetab[n].linewidth = 3;
-              linetab[n].linestyle = GDK_LINE_SOLID;
-              gdk_gc_set_line_attributes (gc,
-					  linetab[n].linewidth,
-					  linetab[n].linestyle,
-					  GDK_CAP_NOT_LAST,
-					  GDK_JOIN_MITER);
-              gdk_draw_line (gtk_widget_get_window (previewarea), gc,
-			     linetab[n].x1, linetab[n].y1,
-			     linetab[n].x2, linetab[n].y2);
-              n++;
-            }
-        }
-    }
-
-  /* Draw the axis (pole to pole and center to zero meridian) */
-  /* ======================================================== */
-
-  for (cnt = 0; cnt < 3; cnt++)
-    {
-      gimp_vector_3d_to_2d (startx, starty, pw, ph,
-			    &x1, &y1, &mapvals.viewpoint, &p[cnt2]);
-      gimp_vector_3d_to_2d (startx, starty, pw, ph,
-			    &x2, &y2, &mapvals.viewpoint, &p[cnt2 + 1]);
-
-      if (clip_line (&x1, &y1, &x2, &y2, cx1, cy1, cx2, cy2) == TRUE)
-        {
-          linetab[n].x1 = RINT (x1);
-          linetab[n].y1 = RINT (y1);
-          linetab[n].x2 = RINT (x2);
-          linetab[n].y2 = RINT (y2);
-
-          if (p[cnt2].z < mapvals.position.z || p[cnt2+1].z < mapvals.position.z)
-            {
-              linetab[n].linewidth = 1;
-              linetab[n].linestyle = GDK_LINE_DOUBLE_DASH;
-            }
-          else
-            {
-              linetab[n].linewidth = 3;
-              linetab[n].linestyle = GDK_LINE_SOLID;
-            }
-
-          gdk_gc_set_line_attributes (gc,
-				      linetab[n].linewidth,
-				      linetab[n].linestyle,
-				      GDK_CAP_NOT_LAST,
-				      GDK_JOIN_MITER);
-          gdk_draw_line (gtk_widget_get_window (previewarea), gc,
-			 linetab[n].x1, linetab[n].y1,
-			 linetab[n].x2, linetab[n].y2);
-          n++;
-        }
-
-      cnt2 += 2;
-    }
-
-  /* Mark end of lines */
-  /* ================= */
-
-  linetab[n].x1 = -1;
-}
-
-static gint
-draw_line (gint        n,
-	   gint        startx,
-	   gint        starty,
-	   gint        pw,
-	   gint        ph,
-	   gdouble     cx1,
-	   gdouble     cy1,
-	   gdouble     cx2,
-	   gdouble     cy2,
-	   GimpVector3 a,
-	   GimpVector3 b)
-{
-  gdouble x1, y1, x2, y2;
-  gint    i = n;
-
-  gimp_vector_3d_to_2d (startx, starty, pw, ph,
-			&x1, &y1, &mapvals.viewpoint, &a);
-  gimp_vector_3d_to_2d (startx, starty, pw, ph,
-			&x2, &y2, &mapvals.viewpoint, &b);
-
-  if (clip_line (&x1, &y1, &x2, &y2, cx1, cy1, cx2, cy2) == TRUE)
-    {
-      linetab[i].x1 = RINT (x1);
-      linetab[i].y1 = RINT (y1);
-      linetab[i].x2 = RINT (x2);
-      linetab[i].y2 = RINT (y2);
-      linetab[i].linewidth = 3;
-      linetab[i].linestyle = GDK_LINE_SOLID;
-      gdk_gc_set_line_attributes (gc,
-				  linetab[i].linewidth,
-				  linetab[i].linestyle,
-				  GDK_CAP_NOT_LAST,
-				  GDK_JOIN_MITER);
-      gdk_draw_line (gtk_widget_get_window (previewarea), gc,
-		     linetab[i].x1, linetab[i].y1,
-		     linetab[i].x2, linetab[i].y2);
-      i++;
-    }
-
-  return i;
-}
-
-static void
-draw_wireframe_box (gint startx,
-		    gint starty,
-		    gint pw,
-		    gint ph)
-{
-  GimpVector3 p[8], tmp, scale;
-  gint        n = 0, i;
-  gdouble     cx1, cy1, cx2, cy2;
-
-  /* Compute wireframe points */
-  /* ======================== */
-
-  init_compute ();
-
-  scale = mapvals.scale;
-  gimp_vector3_mul (&scale, 0.5);
-
-  gimp_vector3_set (&p[0], -scale.x, -scale.y, scale.z);
-  gimp_vector3_set (&p[1],  scale.x, -scale.y, scale.z);
-  gimp_vector3_set (&p[2],  scale.x,  scale.y, scale.z);
-  gimp_vector3_set (&p[3], -scale.x,  scale.y, scale.z);
-
-  gimp_vector3_set (&p[4], -scale.x, -scale.y, -scale.z);
-  gimp_vector3_set (&p[5],  scale.x, -scale.y, -scale.z);
-  gimp_vector3_set (&p[6],  scale.x,  scale.y, -scale.z);
-  gimp_vector3_set (&p[7], -scale.x,  scale.y, -scale.z);
-
-  /* Rotate and translate points */
-  /* =========================== */
-
-  for (i = 0; i < 8; i++)
-    {
-      vecmulmat (&tmp, &p[i], rotmat);
-      gimp_vector3_add (&p[i], &tmp, &mapvals.position);
-    }
-
-  /* Draw the box */
-  /* ============ */
-
-  cx1 = (gdouble) startx;
-  cy1 = (gdouble) starty;
-  cx2 = cx1 + (gdouble) pw;
-  cy2 = cy1 + (gdouble) ph;
-
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[0],p[1]);
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[1],p[2]);
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[2],p[3]);
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[3],p[0]);
-
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[4],p[5]);
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[5],p[6]);
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[6],p[7]);
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[7],p[4]);
-
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[0],p[4]);
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[1],p[5]);
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[2],p[6]);
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[3],p[7]);
-
-  /* Mark end of lines */
-  /* ================= */
-
-  linetab[n].x1 = -1;
-}
-
-static void
-draw_wireframe_cylinder (gint startx,
-			 gint starty,
-			 gint pw,
-			 gint ph)
-{
-  GimpVector3 p[2*8], a, axis, scale;
-  gint        n = 0, i;
-  gdouble     cx1, cy1, cx2, cy2;
-  gfloat      m[16], l, angle;
-
-  /* Compute wireframe points */
-  /* ======================== */
-
-  init_compute ();
-
-  scale = mapvals.scale;
-  gimp_vector3_mul (&scale, 0.5);
-
-  l = mapvals.cylinder_length / 2.0;
-  angle = 0;
-
-  gimp_vector3_set (&axis, 0.0, 1.0, 0.0);
-
-  for (i = 0; i < 8; i++)
-    {
-      rotatemat (angle, &axis, m);
-
-      gimp_vector3_set (&a, mapvals.cylinder_radius, 0.0, 0.0);
-
-      vecmulmat (&p[i], &a, m);
-
-      p[i+8] = p[i];
-
-      p[i].y   += l;
-      p[i+8].y -= l;
-
-      angle += 360.0 / 8.0;
-    }
-
-  /* Rotate and translate points */
-  /* =========================== */
-
-  for (i = 0; i < 16; i++)
-    {
-      vecmulmat (&a, &p[i], rotmat);
-      gimp_vector3_add (&p[i], &a, &mapvals.position);
-    }
-
-  /* Draw the box */
-  /* ============ */
-
-  cx1 = (gdouble) startx;
-  cy1 = (gdouble) starty;
-  cx2 = cx1 + (gdouble) pw;
-  cy2 = cy1 + (gdouble) ph;
-
-  for (i = 0; i < 7; i++)
-    {
-      n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[i],p[i+1]);
-      n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[i+8],p[i+9]);
-      n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[i],p[i+8]);
-    }
-
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[7],p[0]);
-  n = draw_line (n, startx,starty,pw,ph, cx1,cy1,cx2,cy2, p[15],p[8]);
-
-  /* Mark end of lines */
-  /* ================= */
-
-  linetab[n].x1 = -1;
-}
-
-void
-clear_wireframe (void)
-{
-  gint n = 0;
+  draw_lights (startx, starty, pw, ph);
 
-  while (linetab[n].x1 != -1)
-    {
-      gdk_gc_set_line_attributes (gc,
-				  linetab[n].linewidth,
-				  linetab[n].linestyle,
-				  GDK_CAP_NOT_LAST,
-				  GDK_JOIN_MITER);
-      gdk_draw_line (gtk_widget_get_window (previewarea), gc,
-		     linetab[n].x1, linetab[n].y1,
-		     linetab[n].x2, linetab[n].y2);
-      n++;
-    }
+  cairo_destroy (cr);
 }
diff --git a/plug-ins/map-object/map-object-preview.h b/plug-ins/map-object/map-object-preview.h
index dfb9254..ccf90e1 100644
--- a/plug-ins/map-object/map-object-preview.h
+++ b/plug-ins/map-object/map-object-preview.h
@@ -4,28 +4,11 @@
 #define PREVIEW_WIDTH 200
 #define PREVIEW_HEIGHT 200
 
-#define WIRESIZE 16
-
-typedef struct
-{
-  gint         x1, y1, x2, y2;
-  gint         linewidth;
-  GdkLineStyle linestyle;
-} line;
-
-typedef struct
-{
-  gint      x, y, w, h;
-  GdkImage *image;
-} BackBuffer;
-
 /* Externally visible variables */
 /* ============================ */
 
-extern line       linetab[];
 extern gdouble    mat[3][4];
 extern gint       lightx,lighty;
-extern BackBuffer backbuf;
 
 /* Externally visible functions */
 /* ============================ */
@@ -36,13 +19,7 @@ void compute_preview        (gint x,
 			     gint h,
 			     gint pw,
 			     gint ph);
-void draw_wireframe         (gint startx,
-			     gint starty,
-			     gint pw,
-			     gint ph);
-void clear_wireframe        (void);
 void draw_preview_image     (gint docompute);
-void draw_preview_wireframe (void);
 gint check_light_hit        (gint xpos,
 			     gint ypos);
 void update_light           (gint xpos,
diff --git a/plug-ins/map-object/map-object-ui.c b/plug-ins/map-object/map-object-ui.c
index cfe8884..65d632a 100644
--- a/plug-ins/map-object/map-object-ui.c
+++ b/plug-ins/map-object/map-object-ui.c
@@ -18,7 +18,6 @@
 #include "libgimp/stdplugins-intl.h"
 
 
-GdkGC         *gc          = NULL;
 GtkWidget     *previewarea = NULL;
 
 static GtkWidget   *appwin            = NULL;
@@ -49,9 +48,6 @@ static void double_adjustment_update   (GtkAdjustment *adjustment,
 static void toggle_update              (GtkWidget     *widget,
 					gpointer       data);
 
-static void togglegrid_update          (GtkWidget     *widget,
-					gpointer       data);
-
 static void lightmenu_callback         (GtkWidget     *widget,
 					gpointer       data);
 
@@ -83,8 +79,8 @@ double_adjustment_update (GtkAdjustment *adjustment,
 {
   gimp_double_adjustment_update (adjustment, data);
 
-  if (mapvals.showgrid)
-    draw_preview_wireframe ();
+  if (mapvals.livepreview)
+    draw_preview_image (TRUE);
 }
 
 static void
@@ -129,42 +125,6 @@ toggle_update (GtkWidget *widget,
   gimp_toggle_button_update (widget, data);
 
   draw_preview_image (TRUE);
-  linetab[0].x1 = -1;
-}
-
-/***************************/
-/* Show grid toggle update */
-/***************************/
-
-static void
-togglegrid_update (GtkWidget *widget,
-		   gpointer   data)
-{
-  gimp_toggle_button_update (widget, data);
-
-  if (mapvals.showgrid && linetab[0].x1 == -1)
-    {
-      draw_preview_wireframe ();
-    }
-  else if (!mapvals.showgrid && linetab[0].x1 != -1)
-    {
-      GdkColor  color;
-
-      color.red   = 0x0;
-      color.green = 0x0;
-      color.blue  = 0x0;
-      gdk_gc_set_rgb_bg_color (gc, &color);
-
-      color.red   = 0xFFFF;
-      color.green = 0xFFFF;
-      color.blue  = 0xFFFF;
-      gdk_gc_set_rgb_fg_color (gc, &color);
-
-      gdk_gc_set_function (gc, GDK_INVERT);
-
-      clear_wireframe ();
-      linetab[0].x1 = -1;
-    }
 }
 
 /*****************************************/
@@ -192,6 +152,9 @@ lightmenu_callback (GtkWidget *widget,
       gtk_widget_hide (pointlightwid);
       gtk_widget_hide (dirlightwid);
     }
+
+  if (mapvals.livepreview)
+    draw_preview_image (TRUE);
 }
 
 /***************************************/
@@ -209,30 +172,6 @@ mapmenu_callback (GtkWidget *widget,
 
   draw_preview_image (TRUE);
 
-  if (mapvals.showgrid && linetab[0].x1 == -1)
-    {
-      draw_preview_wireframe ();
-    }
-  else if (!mapvals.showgrid && linetab[0].x1 != -1)
-    {
-      GdkColor  color;
-
-      color.red   = 0x0;
-      color.green = 0x0;
-      color.blue  = 0x0;
-      gdk_gc_set_rgb_bg_color (gc, &color);
-
-      color.red   = 0xFFFF;
-      color.green = 0xFFFF;
-      color.blue  = 0xFFFF;
-      gdk_gc_set_rgb_fg_color (gc, &color);
-
-      gdk_gc_set_function (gc, GDK_INVERT);
-
-      clear_wireframe ();
-      linetab[0].x1 = -1;
-    }
-
   children = gtk_container_get_children (GTK_CONTAINER (options_note_book));
   n_children = g_list_length (children);
   g_list_free (children);
@@ -296,7 +235,6 @@ preview_callback (GtkWidget *widget,
 		  gpointer   data)
 {
   draw_preview_image (TRUE);
-  linetab[0].x1 = -1;
 }
 
 static void
@@ -304,9 +242,6 @@ zoomed_callback (GimpZoomModel *model)
 {
   mapvals.zoom = gimp_zoom_model_get_factor (model);
 
-  if (linetab[0].x1 != -1)
-    clear_wireframe ();
-
   draw_preview_image (TRUE);
 }
 
@@ -354,21 +289,7 @@ preview_events (GtkWidget *area,
   switch (event->type)
     {
       case GDK_EXPOSE:
-
-        /* Is this the first exposure? */
-        /* =========================== */
-
-        if (!gc)
-          {
-            gc = gdk_gc_new (gtk_widget_get_window (area));
-            draw_preview_image (TRUE);
-          }
-        else
-          {
-            draw_preview_image (FALSE);
-            if (mapvals.showgrid == 1 && linetab[0].x1 != -1)
-              draw_preview_wireframe ();
-          }
+        draw_preview_image (FALSE);
         break;
 
       case GDK_ENTER_NOTIFY:
@@ -413,8 +334,12 @@ preview_events (GtkWidget *area,
           {
             if (light_hit == TRUE)
               {
+                gint live = mapvals.livepreview;
+
+                mapvals.livepreview = FALSE;
                 update_light (event->motion.x, event->motion.y);
                 update_light_pos_entries ();
+                mapvals.livepreview = live;
               }
             else
               {
@@ -576,7 +501,7 @@ create_options_page (void)
 			      _("Antialiasing quality. Higher is better, "
 			       "but slower"), NULL);
   g_signal_connect (adj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.maxdepth);
 
   spinbutton = gimp_spin_button_new (&adj, mapvals.pixeltreshold,
@@ -586,7 +511,7 @@ create_options_page (void)
 			     spinbutton, 1, TRUE);
 
   g_signal_connect (adj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.pixeltreshold);
 
   gimp_help_set_help_data (spinbutton,
@@ -676,7 +601,7 @@ create_light_page (void)
 			     spinbutton, 1, TRUE);
 
   g_signal_connect (xadj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.lightsource.position.x);
 
   gimp_help_set_help_data (spinbutton,
@@ -690,7 +615,7 @@ create_light_page (void)
 			     spinbutton, 1, TRUE);
 
   g_signal_connect (yadj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.lightsource.position.y);
 
   gimp_help_set_help_data (spinbutton,
@@ -704,7 +629,7 @@ create_light_page (void)
 			     spinbutton, 1, TRUE);
 
   g_signal_connect (zadj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.lightsource.position.z);
 
   gimp_help_set_help_data (spinbutton,
@@ -730,7 +655,7 @@ create_light_page (void)
 			     spinbutton, 1, TRUE);
 
   g_signal_connect (adj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.lightsource.direction.x);
 
   gimp_help_set_help_data (spinbutton,
@@ -743,7 +668,7 @@ create_light_page (void)
 			     spinbutton, 1, TRUE);
 
   g_signal_connect (adj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.lightsource.direction.y);
 
   gimp_help_set_help_data (spinbutton,
@@ -756,7 +681,7 @@ create_light_page (void)
 			     spinbutton, 1, TRUE);
 
   g_signal_connect (adj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.lightsource.direction.z);
 
   gimp_help_set_help_data (spinbutton,
@@ -817,7 +742,7 @@ create_material_page (void)
   gtk_widget_show (spinbutton);
 
   g_signal_connect (adj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.material.ambient_int);
 
   gimp_help_set_help_data (spinbutton,
@@ -846,7 +771,7 @@ create_material_page (void)
   gtk_widget_show (spinbutton);
 
   g_signal_connect (adj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.material.diffuse_int);
 
   gimp_help_set_help_data (spinbutton,
@@ -889,7 +814,7 @@ create_material_page (void)
   gtk_widget_show (spinbutton);
 
   g_signal_connect (adj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.material.diffuse_ref);
 
   gimp_help_set_help_data (spinbutton,
@@ -918,7 +843,7 @@ create_material_page (void)
   gtk_widget_show (spinbutton);
 
   g_signal_connect (adj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.material.specular_ref);
 
   gimp_help_set_help_data (spinbutton,
@@ -947,7 +872,7 @@ create_material_page (void)
   gtk_widget_show (spinbutton);
 
   g_signal_connect (adj, "value-changed",
-                    G_CALLBACK (gimp_double_adjustment_update),
+                    G_CALLBACK (double_adjustment_update),
                     &mapvals.material.highlight);
 
   gimp_help_set_help_data (spinbutton,
@@ -1412,21 +1337,17 @@ main_dialog (GimpDrawable *drawable)
                     G_CALLBACK (zoomed_callback),
                     NULL);
 
-  toggle = gtk_check_button_new_with_mnemonic (_("Show preview _wireframe"));
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), mapvals.showgrid);
+  toggle = gtk_check_button_new_with_mnemonic (_("Update previe_w live"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), mapvals.livepreview);
   gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
   gtk_widget_show (toggle);
 
   g_signal_connect (toggle, "toggled",
-                    G_CALLBACK (togglegrid_update),
-                    &mapvals.showgrid);
+                    G_CALLBACK (toggle_update),
+                    &mapvals.livepreview);
 
   create_main_notebook (main_hbox);
 
-  /* Endmarkers for line table */
-
-  linetab[0].x1 = -1;
-
   gtk_widget_show (appwin);
 
   {
@@ -1439,12 +1360,16 @@ main_dialog (GimpDrawable *drawable)
   }
 
   image_setup (drawable, TRUE);
+  draw_preview_image (TRUE);
 
   if (gimp_dialog_run (GIMP_DIALOG (appwin)) == GTK_RESPONSE_OK)
     run = TRUE;
 
   gtk_widget_destroy (appwin);
-  g_free (preview_rgb_data);
+  if (preview_rgb_data)
+    g_free (preview_rgb_data);
+  if (preview_surface)
+    cairo_surface_destroy (preview_surface);
 
   return run;
 }
diff --git a/plug-ins/map-object/map-object-ui.h b/plug-ins/map-object/map-object-ui.h
index 89147c1..2c619ac 100644
--- a/plug-ins/map-object/map-object-ui.h
+++ b/plug-ins/map-object/map-object-ui.h
@@ -4,7 +4,6 @@
 /* Externally visible variables */
 /* ============================ */
 
-extern GdkGC     *gc;
 extern GtkWidget *previewarea;
 
 /* Externally visible functions */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]