Commit 52e9d75d authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

applied another patch from David Necas <yeti@physics.muni.cz> that fixes

2003-02-03  Sven Neumann  <sven@gimp.org>

	* plug-ins/ifscompose/ifscompose.c: applied another patch from
	David Necas <yeti@physics.muni.cz> that fixes #82470. Added some
	stock icons and mnemonics.
parent c5b1f98a
2003-02-03 Sven Neumann <sven@gimp.org>
* plug-ins/ifscompose/ifscompose.c: applied another patch from
David Necas <yeti@physics.muni.cz> that fixes #82470. Added some
stock icons and mnemonics.
2003-02-03 Michael Natterer <mitch@gimp.org>
 
* app/undo.c: unified some comments, some cleanup.
......
......@@ -32,6 +32,7 @@
* brushes.
* 4. (minor) Make undo work correctly when focus is in entry widget.
*/
#include "config.h"
#include <stdlib.h>
......@@ -55,11 +56,11 @@
#define SCALE_WIDTH 150
#define ENTRY_WIDTH 60
#define DESIGN_AREA_MAX_SIZE 256
#define DESIGN_AREA_MAX_SIZE 300
#define PREVIEW_RENDER_CHUNK 10000
#define UNDO_LEVELS 10
#define UNDO_LEVELS 24
#define IFSCOMPOSE_PARASITE "ifscompose-parasite"
#define IFSCOMPOSE_DATA "plug_in_ifscompose"
......@@ -174,6 +175,7 @@ typedef struct
GtkWidget *redo_button;
GtkWidget *redo_menu_item;
GtkWidget *delete_button;
GtkWidget *delete_menu_item;
GtkWidget *preview;
guchar *preview_data;
......@@ -194,7 +196,7 @@ typedef struct
typedef struct
{
gint run;
gboolean run;
} IfsComposeInterface;
/* Declare local functions.
......@@ -295,32 +297,32 @@ static void ifs_compose_ok_callback (GtkWidget *widget,
* Some static variables
*/
IfsDialog *ifsD = NULL;
IfsOptionsDialog *ifsOptD = NULL;
IfsDesignArea *ifsDesign = NULL;
static IfsDialog *ifsD = NULL;
static IfsOptionsDialog *ifsOptD = NULL;
static IfsDesignArea *ifsDesign = NULL;
static AffElement **elements = NULL;
static gint *element_selected = NULL;
/* labels are generated by printing this int */
static gint count_for_naming = 0;
static UndoItem undo_ring[UNDO_LEVELS];
static gint undo_cur = -1;
static gint undo_num = 0;
static gint undo_start = 0;
static UndoItem undo_ring[UNDO_LEVELS];
static gint undo_cur = -1;
static gint undo_num = 0;
static gint undo_start = 0;
/* num_elements = 0, signals not inited */
static IfsComposeVals ifsvals =
{
0, /* num_elements */
50000, /* iterations */
4096, /* max_memory */
4, /* subdivide */
0.75, /* radius */
1.0, /* aspect ratio */
0.5, /* center_x */
0.5, /* center_y */
0, /* num_elements */
50000, /* iterations */
4096, /* max_memory */
4, /* subdivide */
0.75, /* radius */
1.0, /* aspect ratio */
0.5, /* center_x */
0.5, /* center_y */
};
static IfsComposeInterface ifscint =
......@@ -382,7 +384,7 @@ run (gchar *name,
{
static GimpParam values[1];
GimpDrawable *active_drawable;
GimpRunMode run_mode;
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpParasite *parasite = NULL;
gboolean found_parasite;
......@@ -474,7 +476,8 @@ run (gchar *name,
gimp_drawable_is_gray (active_drawable->drawable_id)))
{
/* set the tile cache size so that the operation works well */
gimp_tile_cache_ntiles (2 * (MAX (active_drawable->width, active_drawable->height) /
gimp_tile_cache_ntiles (2 * (MAX (active_drawable->width,
active_drawable->height) /
gimp_tile_width () + 1));
/* run the effect */
......@@ -497,7 +500,8 @@ run (gchar *name,
GIMP_PARASITE_PERSISTENT |
GIMP_PARASITE_UNDOABLE,
strlen(str)+1, str);
gimp_drawable_parasite_attach (active_drawable->drawable_id, parasite);
gimp_drawable_parasite_attach (active_drawable->drawable_id,
parasite);
gimp_parasite_free (parasite);
g_free (str);
......@@ -861,7 +865,7 @@ ifs_compose_dialog (GimpDrawable *drawable)
hbox = gtk_hbox_new (TRUE, 4);
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
alignment = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
util_hbox = gtk_hbox_new (FALSE, 4);
......@@ -899,7 +903,7 @@ ifs_compose_dialog (GimpDrawable *drawable)
gtk_widget_show (alignment);
gtk_widget_show (util_hbox);
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
alignment = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
util_hbox = gtk_hbox_new (FALSE, 4);
......@@ -936,13 +940,25 @@ ifs_compose_dialog (GimpDrawable *drawable)
hbox = gtk_hbox_new (TRUE, 4);
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
alignment = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
util_hbox = gtk_hbox_new (FALSE, 4);
gtk_container_add (GTK_CONTAINER (alignment), util_hbox);
ifsD->undo_button = gtk_button_new_with_label (_("Undo"));
button = gtk_button_new_from_stock (GTK_STOCK_NEW);
g_signal_connect (button, "clicked",
G_CALLBACK (ifs_compose_new_callback), NULL);
gtk_box_pack_start (GTK_BOX (util_hbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
ifsD->delete_button = gtk_button_new_from_stock (GTK_STOCK_DELETE);
g_signal_connect (ifsD->delete_button, "clicked",
G_CALLBACK (ifs_compose_delete_callback), NULL);
gtk_box_pack_start (GTK_BOX (util_hbox), ifsD->delete_button, TRUE, TRUE, 0);
gtk_widget_show (ifsD->delete_button);
ifsD->undo_button = gtk_button_new_from_stock (GTK_STOCK_UNDO);
gtk_box_pack_start (GTK_BOX (util_hbox), ifsD->undo_button,
TRUE, TRUE, 0);
g_signal_connect (ifsD->undo_button, "clicked",
......@@ -950,7 +966,7 @@ ifs_compose_dialog (GimpDrawable *drawable)
gtk_widget_set_sensitive (ifsD->undo_button, FALSE);
gtk_widget_show (ifsD->undo_button);
ifsD->redo_button = gtk_button_new_with_label (_("Redo"));
ifsD->redo_button = gtk_button_new_from_stock (GTK_STOCK_REDO);
gtk_box_pack_start (GTK_BOX (util_hbox), ifsD->redo_button,
TRUE, TRUE, 0);
g_signal_connect (ifsD->redo_button, "clicked",
......@@ -958,35 +974,14 @@ ifs_compose_dialog (GimpDrawable *drawable)
gtk_widget_set_sensitive (ifsD->redo_button, FALSE);
gtk_widget_show (ifsD->redo_button);
button = gtk_button_new_with_label (_("Select All"));
button = gtk_button_new_with_mnemonic (_("Select _All"));
gtk_box_pack_start (GTK_BOX (util_hbox), button,
TRUE, TRUE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (design_area_select_all_callback), NULL);
gtk_widget_show (button);
gtk_widget_show (alignment);
gtk_widget_show (util_hbox);
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
util_hbox = gtk_hbox_new (FALSE, 4);
gtk_container_add (GTK_CONTAINER (alignment), util_hbox);
ifsD->delete_button = gtk_button_new_with_label (_("Delete"));
g_signal_connect (ifsD->delete_button, "clicked",
G_CALLBACK (ifs_compose_delete_callback), NULL);
gtk_box_pack_start (GTK_BOX (util_hbox), ifsD->delete_button, TRUE, TRUE, 0);
gtk_widget_show (ifsD->delete_button);
button = gtk_button_new_with_label (_("New"));
g_signal_connect (button, "clicked",
G_CALLBACK (ifs_compose_new_callback), NULL);
gtk_box_pack_start (GTK_BOX (util_hbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
button = gtk_button_new_with_label (_("Recompute center"));
button = gtk_button_new_with_mnemonic (_("Recompute _Center"));
gtk_box_pack_start (GTK_BOX (util_hbox), button, TRUE, TRUE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (recompute_center_cb), NULL);
......@@ -1186,105 +1181,49 @@ design_area_create (GtkWidget *window,
static void
design_op_menu_create (GtkWidget *window)
{
GtkWidget *menu_item;
GtkAccelGroup *accel_group;
static GtkItemFactoryEntry menu_items[] = {
{ "/Move", "M", design_op_update_callback,
OP_TRANSLATE, "<RadioItem>", NULL },
{ "/Rotate\\/Scale", "R", design_op_update_callback,
OP_ROTATE, "/Move", NULL },
{ "/Stretch", "S", design_op_update_callback,
OP_STRETCH, "/Move", NULL },
{ "/sep1", NULL, NULL, 0, "<Separator>", NULL },
{ "/New", "<control>N", ifs_compose_new_callback,
0, "<StockItem>", GTK_STOCK_NEW },
{ "/Delete", "<control>D", ifs_compose_delete_callback,
0, "<StockItem>", GTK_STOCK_DELETE },
{ "/Undo", "<control>Z", undo,
0, "<StockItem>", GTK_STOCK_UNDO },
{ "/Redo", "<control>R", redo,
0, "<StockItem>", GTK_STOCK_REDO },
{ "/Select All", "<control>A", design_area_select_all_callback,
0, NULL, NULL },
{ "/Recompute Center", "<control>C", recompute_center_cb,
0, NULL, NULL },
};
ifsDesign->op_menu = gtk_menu_new ();
g_object_ref (ifsDesign->op_menu);
gtk_object_sink (GTK_OBJECT (ifsDesign->op_menu));
GtkAccelGroup *accel_group;
GtkItemFactory *item_factory;
accel_group = gtk_accel_group_new ();
gtk_menu_set_accel_group (GTK_MENU (ifsDesign->op_menu), accel_group);
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
menu_item = gtk_menu_item_new_with_label (_("Move"));
gtk_menu_shell_append (GTK_MENU_SHELL (ifsDesign->op_menu), menu_item);
gtk_widget_show (menu_item);
g_signal_connect (menu_item,"activate",
G_CALLBACK (design_op_update_callback),
GINT_TO_POINTER (OP_TRANSLATE));
gtk_widget_add_accelerator (menu_item,
"activate",
accel_group,
'M', 0,
GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED);
menu_item = gtk_menu_item_new_with_label (_("Rotate/Scale"));
gtk_menu_shell_append (GTK_MENU_SHELL (ifsDesign->op_menu), menu_item);
gtk_widget_show (menu_item);
g_signal_connect (menu_item, "activate",
G_CALLBACK (design_op_update_callback),
GINT_TO_POINTER (OP_ROTATE));
gtk_widget_add_accelerator (menu_item,
"activate",
accel_group,
'R', 0,
GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED);
menu_item = gtk_menu_item_new_with_label (_("Stretch"));
gtk_menu_shell_append (GTK_MENU_SHELL (ifsDesign->op_menu), menu_item);
gtk_widget_show (menu_item);
g_signal_connect (menu_item, "activate",
G_CALLBACK (design_op_update_callback),
GINT_TO_POINTER (OP_STRETCH));
gtk_widget_add_accelerator (menu_item,
"activate",
accel_group,
'S', 0,
GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED);
/* A separator */
menu_item = gtk_menu_item_new ();
gtk_menu_shell_append (GTK_MENU_SHELL (ifsDesign->op_menu), menu_item);
gtk_widget_show (menu_item);
menu_item = gtk_menu_item_new_with_label (_("Select All"));
gtk_menu_shell_append (GTK_MENU_SHELL (ifsDesign->op_menu), menu_item);
gtk_widget_show (menu_item);
g_signal_connect (menu_item, "activate",
G_CALLBACK (design_area_select_all_callback),
NULL);
gtk_widget_add_accelerator (menu_item,
"activate",
accel_group,
'A', GDK_CONTROL_MASK,
GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED);
menu_item = gtk_menu_item_new_with_label (_("Recompute Center"));
gtk_menu_shell_append (GTK_MENU_SHELL (ifsDesign->op_menu), menu_item);
gtk_widget_show (menu_item);
g_signal_connect (menu_item, "activate",
G_CALLBACK (recompute_center_cb),
NULL);
gtk_widget_add_accelerator (menu_item,
"activate",
accel_group,
'R', GDK_MOD1_MASK,
GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED);
ifsD->undo_menu_item = menu_item = gtk_menu_item_new_with_label (_("Undo"));
gtk_menu_shell_append (GTK_MENU_SHELL (ifsDesign->op_menu), menu_item);
gtk_widget_show (menu_item);
g_signal_connect (menu_item, "activate",
G_CALLBACK (undo),
NULL);
gtk_widget_add_accelerator (menu_item,
"activate",
accel_group,
'Z', GDK_CONTROL_MASK,
GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED);
ifsD->redo_menu_item = menu_item = gtk_menu_item_new_with_label (_("Redo"));
gtk_menu_shell_append (GTK_MENU_SHELL (ifsDesign->op_menu), menu_item);
gtk_widget_show (menu_item);
g_signal_connect (menu_item, "activate",
G_CALLBACK (redo),
NULL);
gtk_widget_add_accelerator (menu_item,
"activate",
accel_group,
'R', GDK_CONTROL_MASK,
GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED);
item_factory = gtk_item_factory_new (GTK_TYPE_MENU, "<main>",
accel_group);
gtk_item_factory_create_items (item_factory,
sizeof(menu_items)/sizeof(GtkItemFactoryEntry),
menu_items, NULL);
ifsDesign->op_menu = gtk_item_factory_get_widget (item_factory, "<main>");
g_object_ref (ifsDesign->op_menu);
gtk_object_sink (GTK_OBJECT (ifsDesign->op_menu));
gtk_accel_group_lock (accel_group);
ifsD->undo_menu_item = gtk_item_factory_get_widget (item_factory, "/Undo");
gtk_widget_set_sensitive (ifsD->undo_menu_item, FALSE);
ifsD->redo_menu_item = gtk_item_factory_get_widget (item_factory, "/Redo");
gtk_widget_set_sensitive (ifsD->redo_menu_item, FALSE);
ifsD->delete_menu_item = gtk_item_factory_get_widget (item_factory, "/Delete");
}
static void
......@@ -1714,7 +1653,7 @@ design_area_button_press (GtkWidget *widget,
/* Find out where the button press was */
for (i = 0; i < ifsvals.num_elements; i++)
{
if ( ipolygon_contains (elements[i]->click_boundary, event->x, event->y) )
if (ipolygon_contains (elements[i]->click_boundary, event->x, event->y))
{
set_current_element (i);
break;
......@@ -1756,8 +1695,8 @@ design_area_button_press (GtkWidget *widget,
}
ifsDesign->op_xcenter /= ifsDesign->num_selected;
ifsDesign->op_ycenter /= ifsDesign->num_selected;
ifsDesign->op_x = (gdouble)event->x/width;
ifsDesign->op_y = (gdouble)event->y/width;
ifsDesign->op_x = (gdouble)event->x / width;
ifsDesign->op_y = (gdouble)event->y / width;
ifsDesign->op_center_x = ifsvals.center_x;
ifsDesign->op_center_y = ifsvals.center_y;
}
......@@ -1909,7 +1848,7 @@ undo_begin (void)
if (undo_cur == UNDO_LEVELS-1)
{
to_delete = 1;
undo_start = (undo_start + 1)%UNDO_LEVELS;
undo_start = (undo_start + 1) % UNDO_LEVELS;
}
else
{
......@@ -1918,10 +1857,10 @@ undo_begin (void)
}
undo_num = undo_num - to_delete + 1;
new_index = (undo_start+undo_cur)%UNDO_LEVELS;
new_index = (undo_start + undo_cur) % UNDO_LEVELS;
/* remove any redo elements or the oldest element if necessary */
for (j = new_index; to_delete > 0; j = (j+1)%UNDO_LEVELS, to_delete--)
for (j = new_index; to_delete > 0; j = (j+1) % UNDO_LEVELS, to_delete--)
{
for (i = 0; i < undo_ring[j].ifsvals.num_elements; i++)
if (undo_ring[j].elements[i])
......@@ -1941,9 +1880,9 @@ undo_begin (void)
undo_ring[new_index].element_selected[i] = element_selected[i];
}
gtk_widget_set_sensitive (ifsD->undo_button, undo_cur >= 0);
gtk_widget_set_sensitive (ifsD->undo_button, undo_cur >= 0);
gtk_widget_set_sensitive (ifsD->undo_menu_item, undo_cur >= 0);
gtk_widget_set_sensitive (ifsD->redo_button, undo_cur != undo_num-1);
gtk_widget_set_sensitive (ifsD->redo_button, undo_cur != undo_num-1);
gtk_widget_set_sensitive (ifsD->redo_menu_item, undo_cur != undo_num-1);
}
......@@ -1955,8 +1894,8 @@ undo_update (gint el)
elem = NULL;
if (!undo_ring[(undo_start+undo_cur)%UNDO_LEVELS].elements[el])
undo_ring[(undo_start+undo_cur)%UNDO_LEVELS].elements[el]
if (!undo_ring[(undo_start + undo_cur) % UNDO_LEVELS].elements[el])
undo_ring[(undo_start + undo_cur) % UNDO_LEVELS].elements[el]
= elem = g_new (AffElement, 1);
*elem = *elements[el];
......@@ -2016,13 +1955,13 @@ undo (void)
{
if (undo_cur >= 0)
{
undo_exchange ((undo_start+undo_cur)%UNDO_LEVELS);
undo_exchange ((undo_start + undo_cur) % UNDO_LEVELS);
undo_cur--;
}
gtk_widget_set_sensitive (ifsD->undo_button, undo_cur >= 0);
gtk_widget_set_sensitive (ifsD->undo_button, undo_cur >= 0);
gtk_widget_set_sensitive (ifsD->undo_menu_item, undo_cur >= 0);
gtk_widget_set_sensitive (ifsD->redo_button, undo_cur != undo_num-1);
gtk_widget_set_sensitive (ifsD->redo_button, undo_cur != undo_num-1);
gtk_widget_set_sensitive (ifsD->redo_menu_item, undo_cur != undo_num-1);
}
......@@ -2032,12 +1971,12 @@ redo (void)
if (undo_cur != undo_num - 1)
{
undo_cur++;
undo_exchange ((undo_start+undo_cur)%UNDO_LEVELS);
undo_exchange ((undo_start + undo_cur) % UNDO_LEVELS);
}
gtk_widget_set_sensitive (ifsD->undo_button, undo_cur >= 0);
gtk_widget_set_sensitive (ifsD->undo_button, undo_cur >= 0);
gtk_widget_set_sensitive (ifsD->undo_menu_item, undo_cur >= 0);
gtk_widget_set_sensitive (ifsD->redo_button, undo_cur != undo_num-1);
gtk_widget_set_sensitive (ifsD->redo_button, undo_cur != undo_num-1);
gtk_widget_set_sensitive (ifsD->redo_menu_item, undo_cur != undo_num-1);
}
......@@ -2174,16 +2113,16 @@ simple_color_set_sensitive (void)
{
gint sc = elements[ifsD->current_element]->v.simple_color;
gtk_widget_set_sensitive (ifsD->target_cmap->hbox, sc);
gtk_widget_set_sensitive (ifsD->hue_scale_pair->scale, sc);
gtk_widget_set_sensitive (ifsD->hue_scale_pair->entry, sc);
gtk_widget_set_sensitive (ifsD->target_cmap->hbox, sc);
gtk_widget_set_sensitive (ifsD->hue_scale_pair->scale, sc);
gtk_widget_set_sensitive (ifsD->hue_scale_pair->entry, sc);
gtk_widget_set_sensitive (ifsD->value_scale_pair->scale, sc);
gtk_widget_set_sensitive (ifsD->value_scale_pair->entry, sc);
gtk_widget_set_sensitive (ifsD->red_cmap->hbox,!sc);
gtk_widget_set_sensitive (ifsD->green_cmap->hbox,!sc);
gtk_widget_set_sensitive (ifsD->blue_cmap->hbox,!sc);
gtk_widget_set_sensitive (ifsD->black_cmap->hbox,!sc);
gtk_widget_set_sensitive (ifsD->red_cmap->hbox, !sc);
gtk_widget_set_sensitive (ifsD->green_cmap->hbox, !sc);
gtk_widget_set_sensitive (ifsD->blue_cmap->hbox, !sc);
gtk_widget_set_sensitive (ifsD->black_cmap->hbox, !sc);
}
static void
......@@ -2788,7 +2727,7 @@ ifs_compose_save_callback (GtkWidget *widget,
file_select);
g_signal_connect_swapped (GTK_FILE_SELECTION (file_select)->cancel_button,
"clicked",
G_CALLBACK (gtk_widget_destroy),
G_CALLBACK (gtk_widget_hide),
file_select);
}
......@@ -2860,7 +2799,10 @@ ifs_compose_new_callback (GtkWidget *widget,
ifs_compose_preview ();
if (ifsvals.num_elements > 2)
gtk_widget_set_sensitive (ifsD->delete_button, TRUE);
{
gtk_widget_set_sensitive (ifsD->delete_button, TRUE);
gtk_widget_set_sensitive (ifsD->delete_menu_item, TRUE);
}
}
static void
......@@ -2902,7 +2844,10 @@ ifs_compose_delete_callback (GtkWidget *widget,
ifs_compose_preview ();
if (ifsvals.num_elements == 2)
gtk_widget_set_sensitive (ifsD->delete_button, FALSE);
{
gtk_widget_set_sensitive (ifsD->delete_button, FALSE);
gtk_widget_set_sensitive (ifsD->delete_menu_item, FALSE);
}
}
static gint
......
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