Commit 784dde64 authored by William Skaggs's avatar William Skaggs
Browse files

Bill Skaggs <weskaggs@primate.ucdavis.edu>

	* plug-ins/gfig/gfig-dialog.c
	* plug-ins/gfig/gfig-preview.[ch}
	* plug-ins/gfig/gfig.h: Made Cancel work properly.  Moved "show grid",
	"snap to grid", and "show image" checkbuttons back onto main
	interface.  Eliminated GtkPreview and removed undef of
	GTK_DISABLE_DEPRECATED from gfig-preview.c.  Removed some
	unused code.
parent 93d329db
2004-07-13 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* plug-ins/gfig/gfig-dialog.c
* plug-ins/gfig/gfig-preview.[ch}
* plug-ins/gfig/gfig.h: Made Cancel work properly. Moved "show grid",
"snap to grid", and "show image" checkbuttons back onto main
interface. Eliminated GtkPreview and removed undef of
GTK_DISABLE_DEPRECATED from gfig-preview.c. Removed some
unused code.
2004-07-13 Sven Neumann <sven@gimp.org>
* plug-ins/gflare/gflare.c (preview_handle_idle): use
......
......@@ -164,7 +164,6 @@ static void gfig_new_gc (void);
static void gfig_save_menu_callback (GtkWidget *widget,
gpointer data);
static void gfig_list_load_all (const gchar *path);
static void gfig_save (GtkWidget *parent);
static void gfig_list_free_all (void);
static void create_save_file_chooser (GFigObj *obj,
gchar *tpath,
......@@ -224,6 +223,7 @@ gfig_dialog (void)
gint k;
gint img_width;
gint img_height;
GtkWidget *toggle;
gimp_ui_init ("gfig", TRUE);
......@@ -256,6 +256,7 @@ gfig_dialog (void)
if (parasite)
{
gimp_drawable_fill (gfig_context->drawable_id, GIMP_TRANSPARENT_FILL);
gfig_context->using_new_layer = FALSE;
gimp_parasite_free (parasite);
}
else
......@@ -265,9 +266,9 @@ gfig_dialog (void)
gimp_drawable_fill (newlayer, GIMP_TRANSPARENT_FILL);
gimp_image_add_layer (gfig_context->image_id, newlayer, -1);
gfig_context->drawable_id = newlayer;
gfig_context->using_new_layer = TRUE;
}
gfig_drawable = gimp_drawable_get (gfig_context->drawable_id);
gfig_stock_init ();
......@@ -482,6 +483,40 @@ gfig_dialog (void)
gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
gtk_widget_show (combo);
/* "show image" checkbutton at bottom of style frame */
toggle = gtk_check_button_new_with_label (_("Show image"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
gfig_context->show_background);
gtk_box_pack_end (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&gfig_context->show_background);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gfig_preview_expose),
NULL);
gtk_widget_show (toggle);
/* "snap to grid" checkbutton at bottom of style frame */
toggle = gtk_check_button_new_with_label (_("Snap to grid"));
gtk_box_pack_end (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&selvals.opts.snap2grid);
gtk_widget_show (toggle);
gfig_opt_widget.snap2grid = toggle;
/* "show grid" checkbutton at bottom of style frame */
toggle = gtk_check_button_new_with_label (_("Show grid"));
gtk_box_pack_end (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&selvals.opts.drawgrid);
g_signal_connect (toggle, "toggled",
G_CALLBACK (draw_grid_clear),
NULL);
gtk_widget_show (toggle);
gfig_opt_widget.drawgrid = toggle;
/* Load saved objects */
gfig_list_load_all (gfig_path);
......@@ -494,7 +529,6 @@ gfig_dialog (void)
gtk_widget_show (top_level_dlg);
dialog_update_preview (gfig_drawable);
gfig_new_gc (); /* Need this for drawing */
gfig = gfig_load_from_parasite ();
......@@ -521,6 +555,8 @@ gfig_response (GtkWidget *widget,
gint response_id,
gpointer data)
{
GFigObj *gfig;
switch (response_id)
{
case RESPONSE_UNDO:
......@@ -559,12 +595,33 @@ gfig_response (GtkWidget *widget,
gfig_paint_callback ();
break;
case RESPONSE_SAVE:
gfig_save (widget); /* Save current object */
case GTK_RESPONSE_CANCEL:
/* if we created a new layer, delete it */
if (gfig_context->using_new_layer)
{
gimp_image_remove_layer (gfig_context->image_id,
gfig_context->drawable_id);
}
else /* revert back to the original figure */
{
free_all_objs (gfig_context->current_obj->obj_list);
gfig_context->current_obj->obj_list = NULL;
gfig = gfig_load_from_parasite ();
if (gfig)
{
gfig_list_insert (gfig);
new_obj_2edit (gfig);
}
gfig_context->enable_repaint = TRUE;
gfig_paint_callback ();
}
gtk_widget_destroy (widget);
break;
case GTK_RESPONSE_OK: /* Close button */
gfig_style_copy (&gfig_context->default_style, gfig_context->current_style, "object");
gfig_style_copy (&gfig_context->default_style,
gfig_context->current_style, "object");
gfig_save_as_parasite ();
gtk_widget_destroy (widget);
break;
......@@ -702,12 +759,6 @@ gfig_list_load_all (const gchar *path)
gfig_context->current_obj = gfig_list->data; /* set to first entry */
}
static void
gfig_save (GtkWidget *parent)
{
create_save_file_chooser (gfig_context->current_obj, NULL, parent);
}
static void
gfig_list_free_all (void)
{
......@@ -1184,18 +1235,6 @@ options_dialog_callback (GtkWidget *widget,
/* Put buttons in */
toggle = gtk_check_button_new_with_label (_("Show image"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
gfig_context->show_background);
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 6);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&gfig_context->show_background);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gfig_preview_expose),
NULL);
gtk_widget_show (toggle);
toggle = gtk_check_button_new_with_label (_("Show position"));
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 6);
g_signal_connect (toggle, "toggled",
......@@ -1302,7 +1341,6 @@ adjust_grid_callback (GtkWidget *widget,
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *table;
GtkWidget *toggle;
GtkObject *size_data;
GtkWidget *combo;
......@@ -1320,25 +1358,6 @@ adjust_grid_callback (GtkWidget *widget,
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 6);
gtk_widget_show (hbox);
toggle = gtk_check_button_new_with_label (_("Show grid"));
gtk_box_pack_start (GTK_BOX (hbox), toggle, FALSE, FALSE, 0);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&selvals.opts.drawgrid);
g_signal_connect (toggle, "toggled",
G_CALLBACK (draw_grid_clear),
NULL);
gtk_widget_show (toggle);
gfig_opt_widget.drawgrid = toggle;
toggle = gtk_check_button_new_with_label (_("Snap to grid"));
gtk_box_pack_start (GTK_BOX (hbox), toggle, FALSE, FALSE, 0);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&selvals.opts.snap2grid);
gtk_widget_show (toggle);
gfig_opt_widget.snap2grid = toggle;
table = gtk_table_new (3, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
......@@ -1902,7 +1921,6 @@ void
draw_grid_clear ()
{
/* wipe slate and start again */
dialog_update_preview (gfig_drawable);
gtk_widget_queue_draw (gfig_context->preview);
}
......
......@@ -27,11 +27,6 @@
#include <stdio.h>
#include <string.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
......@@ -57,14 +52,10 @@ static gint pos_tag = -1;
GtkWidget *status_label_dname;
GtkWidget *status_label_fname;
static GtkWidget *pos_label; /* XY pos marker */
static guchar preview_row[PREVIEW_SIZE * 4];
static guchar *pv_cache;
static gint img_bpp;
static void gfig_preview_realize (GtkWidget *widget);
static gboolean gfig_preview_events (GtkWidget *widget,
GdkEvent *event);
static void cache_preview (GimpDrawable *drawable);
static gint gfig_invscale_x (gint x);
static gint gfig_invscale_y (gint y);
......@@ -83,7 +74,7 @@ make_preview (void)
GtkWidget *table;
GtkWidget *ruler;
gfig_context->preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gfig_context->preview = gtk_drawing_area_new ();
gtk_widget_set_events (GTK_WIDGET (gfig_context->preview), PREVIEW_MASK);
g_signal_connect (gfig_context->preview , "realize",
......@@ -98,7 +89,7 @@ make_preview (void)
G_CALLBACK (gfig_preview_expose),
NULL);
gtk_preview_size (GTK_PREVIEW (gfig_context->preview), preview_width,
gtk_drawing_area_size (GTK_DRAWING_AREA (gfig_context->preview), preview_width,
preview_height);
frame = gtk_frame_new (NULL);
......@@ -145,188 +136,6 @@ make_preview (void)
return vbox;
}
/* Given a row then srink it down a bit */
static void
do_gfig_preview (guchar *dest_row,
guchar *src_row,
gint width,
gint dh,
gint height,
gint bpp)
{
memcpy (dest_row, src_row, width * bpp);
}
void
refill_cache (GimpDrawable *drawable)
{
static GdkCursor *preview_cursor1 = NULL;
static GdkCursor *preview_cursor2 = NULL;
if (!preview_cursor1)
{
GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (gfig_context->preview));
preview_cursor1 = gdk_cursor_new_for_display (display, GDK_WATCH);
preview_cursor2 = gdk_cursor_new_for_display (display, GDK_TOP_LEFT_ARROW);
}
gdk_window_set_cursor
(gtk_widget_get_toplevel (GTK_WIDGET (gfig_context->preview))->window,
preview_cursor1);
gdk_window_set_cursor (gfig_context->preview->window, preview_cursor1);
gdk_flush ();
cache_preview (drawable);
gdk_window_set_cursor
(gtk_widget_get_toplevel (GTK_WIDGET (gfig_context->preview))->window,
preview_cursor2);
toggle_obj_type (NULL, GINT_TO_POINTER (selvals.otype));
}
/* Cache the preview image - updates are a lot faster. */
/* The preview_cache will contain the small image */
static void
cache_preview (GimpDrawable *drawable)
{
GimpPixelRgn src_rgn;
gint y, x;
guchar *src_rows;
guchar *p;
gboolean isgrey, has_alpha;
gint bpp, img_bpp;
gint sel_x1, sel_y1, sel_x2, sel_y2;
gint sel_width, sel_height;
gimp_drawable_mask_bounds (drawable->drawable_id,
&sel_x1, &sel_y1, &sel_x2, &sel_y2);
sel_width = sel_x2 - sel_x1;
sel_height = sel_y2 - sel_y1;
gimp_pixel_rgn_init (&src_rgn, drawable,
sel_x1, sel_y1, sel_width, sel_height, FALSE, FALSE);
src_rows = g_new (guchar , sel_width * 4);
p = pv_cache = g_new (guchar , preview_width * preview_height * 4);
bpp = gimp_drawable_bpp (drawable->drawable_id);
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
if (bpp < 3)
{
img_bpp = 3 + has_alpha;
}
else
{
img_bpp = bpp;
}
isgrey = gimp_drawable_is_gray (drawable->drawable_id);
for (y = 0; y < preview_height; y++)
{
gimp_pixel_rgn_get_row (&src_rgn,
src_rows,
sel_x1,
sel_y1 + (y*sel_height)/preview_height,
sel_width);
for (x = 0; x < (preview_width); x ++)
{
/* Get the pixels of each col */
gint i;
for (i = 0 ; i < 3; i++)
p[x*img_bpp+i] =
src_rows[((x*sel_width)/preview_width) * src_rgn.bpp +
((isgrey)?0:i)];
if (has_alpha)
p[x*img_bpp+3] =
src_rows[((x*sel_width)/preview_width) * src_rgn.bpp +
((isgrey)?1:3)];
}
p += (preview_width*img_bpp);
}
g_free (src_rows);
}
void
dialog_update_preview (GimpDrawable *drawable)
{
gint y;
gint check, check_0, check_1;
if (!selvals.showimage)
{
memset (preview_row, -1, preview_width*4);
for (y = 0; y < preview_height; y++)
{
gtk_preview_draw_row (GTK_PREVIEW (gfig_context->preview), preview_row,
0, y, preview_width);
}
return;
}
if (!pv_cache)
{
refill_cache (drawable);
}
for (y = 0; y < preview_height; y++)
{
if ((y / GIMP_CHECK_SIZE) & 1)
{
check_0 = GIMP_CHECK_DARK * 255;
check_1 = GIMP_CHECK_LIGHT * 255;
}
else
{
check_0 = GIMP_CHECK_LIGHT * 255;
check_1 = GIMP_CHECK_DARK * 255;
}
do_gfig_preview (preview_row,
pv_cache + y * preview_width * img_bpp,
preview_width,
y,
preview_height,
img_bpp);
if (img_bpp > 3)
{
int i, j;
for (i = 0, j = 0 ; i < sizeof (preview_row); i += 4, j += 3)
{
gint alphaval;
if (((i/4) / GIMP_CHECK_SIZE) & 1)
check = check_0;
else
check = check_1;
alphaval = preview_row[i + 3];
preview_row[j] =
check + (((preview_row[i] - check)*alphaval)/255);
preview_row[j + 1] =
check + (((preview_row[i + 1] - check)*alphaval)/255);
preview_row[j + 2] =
check + (((preview_row[i + 2] - check)*alphaval)/255);
}
}
gtk_preview_draw_row (GTK_PREVIEW (gfig_context->preview), preview_row,
0, y, preview_width);
}
}
static void
gfig_preview_realize (GtkWidget *widget)
{
......
......@@ -33,6 +33,5 @@ void gfig_update_stat_labels (void);
void gfig_pos_enable (GtkWidget *widget,
gpointer data);
void dialog_update_preview (GimpDrawable *drawable);
void refill_cache (GimpDrawable *drawable);
#endif /* __GFIG_PREVIEW_H__ */
......@@ -315,6 +315,7 @@ typedef struct
GimpRGB *fg_color;
GimpRGB *bg_color;
gboolean enable_repaint;
gboolean using_new_layer;
} GFigContext;
GFigContext *gfig_context;
......
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