Commit 49fc3a12 authored by Mikael Magnusson's avatar Mikael Magnusson

lighting: port to cairo, replace wireframe with live preview

parent 221f6d00
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -63,7 +63,7 @@ typedef struct
gint create_new_image;
gint transparent_background;
gint tiled;
gint showgrid;
gint livepreview;
gint showcaps;
gdouble zoom;
......
This diff is collapsed.
......@@ -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,
......
......@@ -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;
}
......@@ -4,7 +4,6 @@
/* Externally visible variables */
/* ============================ */
extern GdkGC *gc;
extern GtkWidget *previewarea;
/* Externally visible functions */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment