~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to plug-ins/imagemap/imap_cmd_gimp_guides.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This is a plug-in for the GIMP.
 
3
 *
 
4
 * Generates clickable image maps.
 
5
 *
 
6
 * Copyright (C) 1998-2004 Maurits Rijk  m.rijk@chello.nl
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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.
 
21
 *
 
22
 */
 
23
 
 
24
#include "config.h"
 
25
 
 
26
#include <stdio.h>
 
27
 
 
28
#include <gtk/gtk.h>
 
29
 
 
30
#include "libgimp/gimp.h"
 
31
#include "libgimpwidgets/gimpwidgets.h"
 
32
 
 
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"
 
38
 
 
39
#include "libgimp/stdplugins-intl.h"
 
40
 
 
41
typedef struct {
 
42
   DefaultDialog_t      *dialog;
 
43
 
 
44
   ObjectList_t         *list;
 
45
   GimpDrawable         *drawable;
 
46
 
 
47
   GtkWidget            *alternate;
 
48
   GtkWidget            *all;
 
49
   GtkWidget            *left_border;
 
50
   GtkWidget            *right_border;
 
51
   GtkWidget            *upper_border;
 
52
   GtkWidget            *lower_border;
 
53
   GtkWidget            *url;
 
54
} GimpGuidesDialog_t;
 
55
 
 
56
static gint
 
57
guide_sort_func(gconstpointer a, gconstpointer b)
 
58
{
 
59
   return GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b);
 
60
}
 
61
 
 
62
static void
 
63
gimp_guides_ok_cb(gpointer data)
 
64
{
 
65
   GimpGuidesDialog_t *param = (GimpGuidesDialog_t*) data;
 
66
   gint  guide_num;
 
67
   GSList *hguides, *hg;
 
68
   GSList *vguides, *vg;
 
69
   gboolean all;
 
70
   const gchar *url;
 
71
   gint32 image_ID = gimp_drawable_get_image (param->drawable->drawable_id);
 
72
 
 
73
   /* First get some dialog values */
 
74
 
 
75
   all = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->all));
 
76
 
 
77
   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->left_border)))
 
78
      vguides = g_slist_append(NULL, GINT_TO_POINTER(0));
 
79
   else
 
80
      vguides = NULL;
 
81
 
 
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)));
 
85
 
 
86
   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->upper_border)))
 
87
      hguides = g_slist_append(NULL, GINT_TO_POINTER(0));
 
88
   else
 
89
      hguides = NULL;
 
90
 
 
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)));
 
94
 
 
95
   url = gtk_entry_get_text(GTK_ENTRY(param->url));
 
96
 
 
97
   /* Next get all the GIMP guides */
 
98
 
 
99
   guide_num = gimp_image_find_next_guide(image_ID, 0);
 
100
 
 
101
   while (guide_num > 0) {
 
102
      gint position = gimp_image_get_guide_position(image_ID, guide_num);
 
103
 
 
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),
 
107
                                         guide_sort_func);
 
108
      } else {                  /* GIMP_ORIENTATION_VERTICAL */
 
109
         vguides = g_slist_insert_sorted(vguides, GINT_TO_POINTER(position),
 
110
                                         guide_sort_func);
 
111
      }
 
112
      guide_num = gimp_image_find_next_guide(image_ID, guide_num);
 
113
   }
 
114
 
 
115
   /* Create the areas */
 
116
 
 
117
   subcommand_start(_("Use Gimp Guides"));
 
118
 
 
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);
 
129
 
 
130
         object_set_url(obj, url);
 
131
         command_execute(command);
 
132
      }
 
133
   }
 
134
 
 
135
   subcommand_end();
 
136
   redraw_preview();
 
137
}
 
138
 
 
139
static GimpGuidesDialog_t*
 
140
make_gimp_guides_dialog(void)
 
141
{
 
142
   GimpGuidesDialog_t *data = g_new(GimpGuidesDialog_t, 1);
 
143
   DefaultDialog_t *dialog;
 
144
   GtkWidget *table, *frame, *hbox, *vbox;
 
145
   GtkWidget *label;
 
146
 
 
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);
 
150
 
 
151
   frame = gimp_frame_new(_("Create"));
 
152
   gtk_widget_show(frame);
 
153
   gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 1, 0, 1);
 
154
 
 
155
   hbox = gtk_hbox_new( FALSE, 6);
 
156
   gtk_container_add(GTK_CONTAINER(frame), hbox);
 
157
   gtk_widget_show(hbox);
 
158
 
 
159
   data->alternate =
 
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);
 
163
 
 
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);
 
168
 
 
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);
 
172
 
 
173
   vbox = gtk_vbox_new(FALSE, 2);
 
174
   gtk_container_add(GTK_CONTAINER(frame), vbox);
 
175
   gtk_widget_show(vbox);
 
176
 
 
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);
 
180
 
 
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);
 
184
 
 
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);
 
188
 
 
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);
 
192
 
 
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);
 
196
 
 
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);
 
200
 
 
201
   data->url = gtk_entry_new();
 
202
   gtk_container_add(GTK_CONTAINER(hbox), data->url);
 
203
   gtk_widget_show(data->url);
 
204
 
 
205
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), data->url);
 
206
 
 
207
   return data;
 
208
}
 
209
 
 
210
static void
 
211
init_gimp_guides_dialog(GimpGuidesDialog_t *dialog, ObjectList_t *list,
 
212
                        GimpDrawable *drawable)
 
213
{
 
214
   dialog->list = list;
 
215
   dialog->drawable = drawable;
 
216
}
 
217
 
 
218
static void
 
219
do_create_gimp_guides_dialog(ObjectList_t *list, GimpDrawable *drawable)
 
220
{
 
221
   static GimpGuidesDialog_t *dialog;
 
222
 
 
223
   if (!dialog)
 
224
      dialog = make_gimp_guides_dialog();
 
225
 
 
226
   init_gimp_guides_dialog(dialog, list, drawable);
 
227
   default_dialog_show(dialog->dialog);
 
228
}
 
229
 
 
230
static CmdExecuteValue_t gimp_guides_command_execute(Command_t *parent);
 
231
 
 
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 */
 
237
};
 
238
 
 
239
typedef struct {
 
240
   Command_t parent;
 
241
   ObjectList_t *list;
 
242
   GimpDrawable *drawable;
 
243
} GimpGuidesCommand_t;
 
244
 
 
245
Command_t*
 
246
gimp_guides_command_new(ObjectList_t *list, GimpDrawable *drawable)
 
247
{
 
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);
 
253
}
 
254
 
 
255
static CmdExecuteValue_t
 
256
gimp_guides_command_execute(Command_t *parent)
 
257
{
 
258
   GimpGuidesCommand_t *command = (GimpGuidesCommand_t*) parent;
 
259
   do_create_gimp_guides_dialog(command->list, command->drawable);
 
260
   return CMD_DESTRUCT;
 
261
}