2
* This is a plug-in for the GIMP.
4
* Generates clickable image maps.
6
* Copyright (C) 1998-2004 Maurits Rijk m.rijk@chello.nl
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30
#include "libgimp/gimp.h"
31
#include "libgimpwidgets/gimpwidgets.h"
33
#include "imap_commands.h"
34
#include "imap_default_dialog.h"
35
#include "imap_main.h"
36
#include "imap_rectangle.h"
37
#include "imap_table.h"
39
#include "libgimp/stdplugins-intl.h"
42
DefaultDialog_t *dialog;
45
GimpDrawable *drawable;
49
GtkWidget *left_border;
50
GtkWidget *right_border;
51
GtkWidget *upper_border;
52
GtkWidget *lower_border;
57
guide_sort_func(gconstpointer a, gconstpointer b)
59
return GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b);
63
gimp_guides_ok_cb(gpointer data)
65
GimpGuidesDialog_t *param = (GimpGuidesDialog_t*) data;
71
gint32 image_ID = gimp_drawable_get_image (param->drawable->drawable_id);
73
/* First get some dialog values */
75
all = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->all));
77
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->left_border)))
78
vguides = g_slist_append(NULL, GINT_TO_POINTER(0));
82
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->right_border)))
83
vguides = g_slist_append(vguides,
84
GINT_TO_POINTER(gimp_image_width(image_ID)));
86
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->upper_border)))
87
hguides = g_slist_append(NULL, GINT_TO_POINTER(0));
91
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->lower_border)))
92
hguides = g_slist_append(hguides,
93
GINT_TO_POINTER(gimp_image_height(image_ID)));
95
url = gtk_entry_get_text(GTK_ENTRY(param->url));
97
/* Next get all the GIMP guides */
99
guide_num = gimp_image_find_next_guide(image_ID, 0);
101
while (guide_num > 0) {
102
gint position = gimp_image_get_guide_position(image_ID, guide_num);
104
if (gimp_image_get_guide_orientation(image_ID, guide_num)
105
== GIMP_ORIENTATION_HORIZONTAL) {
106
hguides = g_slist_insert_sorted(hguides, GINT_TO_POINTER(position),
108
} else { /* GIMP_ORIENTATION_VERTICAL */
109
vguides = g_slist_insert_sorted(vguides, GINT_TO_POINTER(position),
112
guide_num = gimp_image_find_next_guide(image_ID, guide_num);
115
/* Create the areas */
117
subcommand_start(_("Use Gimp Guides"));
119
for (hg = hguides; hg && hg->next;
120
hg = (all) ? hg->next : hg->next->next) {
121
gint y = GPOINTER_TO_INT(hg->data);
122
gint height = GPOINTER_TO_INT(hg->next->data) - y;
123
for (vg = vguides; vg && vg->next;
124
vg = (all) ? vg->next : vg->next->next) {
125
gint x = GPOINTER_TO_INT(vg->data);
126
gint width = GPOINTER_TO_INT(vg->next->data) - x;
127
Object_t *obj = create_rectangle(x, y, width, height);
128
Command_t *command = create_command_new(param->list, obj);
130
object_set_url(obj, url);
131
command_execute(command);
139
static GimpGuidesDialog_t*
140
make_gimp_guides_dialog(void)
142
GimpGuidesDialog_t *data = g_new(GimpGuidesDialog_t, 1);
143
DefaultDialog_t *dialog;
144
GtkWidget *table, *frame, *hbox, *vbox;
147
dialog = data->dialog = make_default_dialog(_("Use Gimp Guides"));
148
default_dialog_set_ok_cb(dialog, gimp_guides_ok_cb, data);
149
table = default_dialog_add_table(dialog, 3, 2);
151
frame = gimp_frame_new(_("Create"));
152
gtk_widget_show(frame);
153
gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 1, 0, 1);
155
hbox = gtk_hbox_new( FALSE, 6);
156
gtk_container_add(GTK_CONTAINER(frame), hbox);
157
gtk_widget_show(hbox);
160
gtk_radio_button_new_with_mnemonic_from_widget(NULL, _("Al_ternate"));
161
gtk_box_pack_start(GTK_BOX(hbox), data->alternate, FALSE, FALSE, 0);
162
gtk_widget_show(data->alternate);
164
data->all = gtk_radio_button_new_with_mnemonic_from_widget(
165
GTK_RADIO_BUTTON(data->alternate), _("A_ll"));
166
gtk_box_pack_start(GTK_BOX(hbox), data->all, FALSE, FALSE, 0);
167
gtk_widget_show(data->all);
169
frame = gimp_frame_new(_("Add Additional Guides"));
170
gtk_widget_show(frame);
171
gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 1, 1, 2);
173
vbox = gtk_vbox_new(FALSE, 2);
174
gtk_container_add(GTK_CONTAINER(frame), vbox);
175
gtk_widget_show(vbox);
177
data->left_border = gtk_check_button_new_with_mnemonic(_("L_eft Border"));
178
gtk_container_add(GTK_CONTAINER(vbox), data->left_border);
179
gtk_widget_show(data->left_border);
181
data->right_border = gtk_check_button_new_with_mnemonic(_("_Right Border"));
182
gtk_container_add(GTK_CONTAINER(vbox), data->right_border);
183
gtk_widget_show(data->right_border);
185
data->upper_border = gtk_check_button_new_with_mnemonic(_("_Upper Border"));
186
gtk_container_add(GTK_CONTAINER(vbox), data->upper_border);
187
gtk_widget_show(data->upper_border);
189
data->lower_border = gtk_check_button_new_with_mnemonic(_("Lo_wer Border"));
190
gtk_container_add(GTK_CONTAINER(vbox), data->lower_border);
191
gtk_widget_show(data->lower_border);
193
hbox = gtk_hbox_new (FALSE, 6);
194
gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 2, 2, 3);
195
gtk_widget_show(hbox);
197
label = gtk_label_new_with_mnemonic(_("_Base URL:"));
198
gtk_widget_show(label);
199
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
201
data->url = gtk_entry_new();
202
gtk_container_add(GTK_CONTAINER(hbox), data->url);
203
gtk_widget_show(data->url);
205
gtk_label_set_mnemonic_widget (GTK_LABEL (label), data->url);
211
init_gimp_guides_dialog(GimpGuidesDialog_t *dialog, ObjectList_t *list,
212
GimpDrawable *drawable)
215
dialog->drawable = drawable;
219
do_create_gimp_guides_dialog(ObjectList_t *list, GimpDrawable *drawable)
221
static GimpGuidesDialog_t *dialog;
224
dialog = make_gimp_guides_dialog();
226
init_gimp_guides_dialog(dialog, list, drawable);
227
default_dialog_show(dialog->dialog);
230
static CmdExecuteValue_t gimp_guides_command_execute(Command_t *parent);
232
static CommandClass_t gimp_guides_command_class = {
233
NULL, /* guides_command_destruct */
234
gimp_guides_command_execute,
235
NULL, /* guides_command_undo */
236
NULL /* guides_command_redo */
242
GimpDrawable *drawable;
243
} GimpGuidesCommand_t;
246
gimp_guides_command_new(ObjectList_t *list, GimpDrawable *drawable)
248
GimpGuidesCommand_t *command = g_new(GimpGuidesCommand_t, 1);
249
command->list = list;
250
command->drawable = drawable;
251
return command_init(&command->parent, _("Use Gimp Guides"),
252
&gimp_guides_command_class);
255
static CmdExecuteValue_t
256
gimp_guides_command_execute(Command_t *parent)
258
GimpGuidesCommand_t *command = (GimpGuidesCommand_t*) parent;
259
do_create_gimp_guides_dialog(command->list, command->drawable);