Added functionality to create an imagemap using the standard GIMP guides, kindly requested by carol :)

This commit is contained in:
Maurits Rijk 2002-08-21 20:48:14 +00:00
parent 728778ca32
commit ca8b830162
13 changed files with 362 additions and 36 deletions

View file

@ -1,3 +1,27 @@
2002-08-21 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/imagemap/imap_cmd_guides.c (make_guides_dialog)
* plug-ins/imagemap/imap_settings.c (create_settings_dialog)
* plug-ins/imagemap/imap_grid.c (create_grid_settings_dialog): replaced
some code by default_dialog_add_table convenience func.
* plug-ins/imagemap/imap_default_dialog.h
* plug-ins/imagemap/imap_default_dialog.c: added convenience func
default_dialog_add_table.
* plug-ins/imagemap/imap_grid.c: fixed warning for missing prototype
of abs.
* plug-ins/imagemap/imap_about.c: updated copyright date
* plug-ins/imagemap/imap_main.c
* plug-ins/imagemap/imap_menu.h
* plug-ins/imagemap/imap_menu.c
* plug-ins/imagemap/Makefile.am
* plug-ins/imagemap/imap_cmd_gimp_guides.h
* plug-ins/imagemap/imap_cmd_gimp_guides.c: new functionality to allow
creation of imagemap's using GIMP guides.
2002-08-21 Michael Natterer <mitch@gimp.org>
* app/gui/menus.c (menus_last_opened_add): don't g_free() static

View file

@ -53,6 +53,8 @@ imagemap_SOURCES = \
imap_cmd_delete_point.h \
imap_cmd_edit_object.c \
imap_cmd_edit_object.h \
imap_cmd_gimp_guides.c \
imap_cmd_gimp_guides.h \
imap_cmd_guides.c \
imap_cmd_guides.h \
imap_cmd_insert_point.c \

View file

@ -23,11 +23,6 @@
#include "config.h"
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include "imap_about.h"
@ -46,7 +41,7 @@ do_about_dialog(void)
default_dialog_hide_help_button(dialog);
default_dialog_set_label(dialog, _("Imagemap plug-in 2.0"));
default_dialog_set_label(
dialog, _("Copyright(c) 1999 by Maurits Rijk"));
dialog, _("Copyright(c) 1999-2002 by Maurits Rijk"));
default_dialog_set_label(dialog, _("lpeek.mrijk@consunet.nl"));
default_dialog_set_label(
dialog, _(" Released under the GNU General Public License "));

View file

@ -0,0 +1,261 @@
/*
* This is a plug-in for the GIMP.
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2002 Maurits Rijk lpeek.mrijk@consunet.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <stdio.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include "imap_cmd_create.h"
#include "imap_default_dialog.h"
#include "imap_cmd_gimp_guides.h"
#include "imap_main.h"
#include "imap_rectangle.h"
#include "imap_table.h"
#include "libgimp/stdplugins-intl.h"
typedef struct {
DefaultDialog_t *dialog;
ObjectList_t *list;
GimpDrawable *drawable;
GtkWidget *alternate;
GtkWidget *all;
GtkWidget *left_border;
GtkWidget *right_border;
GtkWidget *upper_border;
GtkWidget *lower_border;
GtkWidget *url;
} GimpGuidesDialog_t;
static gint
guide_sort_func(gconstpointer a, gconstpointer b)
{
return GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b);
}
static void
gimp_guides_ok_cb(gpointer data)
{
GimpGuidesDialog_t *param = (GimpGuidesDialog_t*) data;
gint guide_num;
GSList *hguides, *hg;
GSList *vguides, *vg;
gboolean all;
const gchar *url;
gint32 image_ID = gimp_drawable_image(param->drawable->drawable_id);
/* First get some dialog values */
all = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->all));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->left_border)))
vguides = g_slist_append(NULL, GINT_TO_POINTER(0));
else
vguides = NULL;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->right_border)))
vguides = g_slist_append(vguides,
GINT_TO_POINTER(gimp_image_width(image_ID)));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->upper_border)))
hguides = g_slist_append(NULL, GINT_TO_POINTER(0));
else
hguides = NULL;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->lower_border)))
hguides = g_slist_append(hguides,
GINT_TO_POINTER(gimp_image_height(image_ID)));
url = gtk_entry_get_text(GTK_ENTRY(param->url));
/* Next get all the GIMP guides */
guide_num = gimp_image_find_next_guide(image_ID, 0);
while (guide_num > 0) {
gint position = gimp_image_get_guide_position(image_ID, guide_num);
if (gimp_image_get_guide_orientation(image_ID, guide_num)
== GIMP_HORIZONTAL) {
hguides = g_slist_insert_sorted(hguides, GINT_TO_POINTER(position),
guide_sort_func);
} else { /* GIMP_VERTICAL */
vguides = g_slist_insert_sorted(vguides, GINT_TO_POINTER(position),
guide_sort_func);
}
guide_num = gimp_image_find_next_guide(image_ID, guide_num);
}
/* Create the areas */
subcommand_start(_("Use Gimp Guides"));
for (hg = hguides; hg && hg->next;
hg = (all) ? hg->next : hg->next->next) {
gint y = GPOINTER_TO_INT(hg->data);
gint height = GPOINTER_TO_INT(hg->next->data) - y;
for (vg = vguides; vg && vg->next;
vg = (all) ? vg->next : vg->next->next) {
gint x = GPOINTER_TO_INT(vg->data);
gint width = GPOINTER_TO_INT(vg->next->data) - x;
Object_t *obj = create_rectangle(x, y, width, height);
Command_t *command = create_command_new(param->list, obj);
object_set_url(obj, url);
command_execute(command);
}
}
subcommand_end();
redraw_preview();
}
static GimpGuidesDialog_t*
make_gimp_guides_dialog(void)
{
GimpGuidesDialog_t *data = g_new(GimpGuidesDialog_t, 1);
DefaultDialog_t *dialog;
GtkWidget *table, *frame, *hbox, *vbox;
GtkWidget *label;
dialog = data->dialog = make_default_dialog(_("Use Gimp Guides"));
default_dialog_set_ok_cb(dialog, gimp_guides_ok_cb, data);
table = default_dialog_add_table(dialog, 3, 2);
frame = gtk_frame_new(_("Create"));
gtk_widget_show(frame);
gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 1, 0, 1);
hbox = gtk_hbox_new(FALSE, 1);
gtk_container_add(GTK_CONTAINER(frame), hbox);
gtk_widget_show(hbox);
data->alternate =
gtk_radio_button_new_with_mnemonic_from_widget(NULL, _("Al_ternate"));
gtk_box_pack_start(GTK_BOX(hbox), data->alternate, TRUE, TRUE, 10);
gtk_widget_show(data->alternate);
data->all = gtk_radio_button_new_with_mnemonic_from_widget(
GTK_RADIO_BUTTON(data->alternate), _("A_ll"));
gtk_box_pack_start(GTK_BOX(hbox), data->all, TRUE, TRUE, 10);
gtk_widget_show(data->all);
frame = gtk_frame_new(_("Add Additional Guides"));
gtk_widget_show(frame);
gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 1, 1, 2);
vbox = gtk_vbox_new(FALSE, 1);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
gtk_container_add(GTK_CONTAINER(frame), vbox);
gtk_widget_show(vbox);
data->left_border = gtk_check_button_new_with_mnemonic(_("L_eft Border"));
gtk_container_add(GTK_CONTAINER(vbox), data->left_border);
gtk_widget_show(data->left_border);
data->right_border = gtk_check_button_new_with_mnemonic(_("_Right Border"));
gtk_container_add(GTK_CONTAINER(vbox), data->right_border);
gtk_widget_show(data->right_border);
data->upper_border = gtk_check_button_new_with_mnemonic(_("_Upper Border"));
gtk_container_add(GTK_CONTAINER(vbox), data->upper_border);
gtk_widget_show(data->upper_border);
data->lower_border = gtk_check_button_new_with_mnemonic(_("Lo_wer Border"));
gtk_container_add(GTK_CONTAINER(vbox), data->lower_border);
gtk_widget_show(data->lower_border);
hbox = gtk_hbox_new(FALSE, 1);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 10);
gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 2, 2, 3);
gtk_widget_show(hbox);
label = gtk_label_new_with_mnemonic(_("_Base URL:"));
gtk_widget_show(label);
gtk_container_add(GTK_CONTAINER(hbox), label);
data->url = gtk_entry_new();
gtk_container_add(GTK_CONTAINER(hbox), data->url);
gtk_widget_show(data->url);
return data;
}
static void
init_gimp_guides_dialog(GimpGuidesDialog_t *dialog, ObjectList_t *list,
GimpDrawable *drawable)
{
dialog->list = list;
dialog->drawable = drawable;
}
static void
do_create_gimp_guides_dialog(ObjectList_t *list, GimpDrawable *drawable)
{
static GimpGuidesDialog_t *dialog;
if (!dialog)
dialog = make_gimp_guides_dialog();
init_gimp_guides_dialog(dialog, list, drawable);
default_dialog_show(dialog->dialog);
}
static CmdExecuteValue_t gimp_guides_command_execute(Command_t *parent);
static CommandClass_t gimp_guides_command_class = {
NULL, /* guides_command_destruct */
gimp_guides_command_execute,
NULL, /* guides_command_undo */
NULL /* guides_command_redo */
};
typedef struct {
Command_t parent;
ObjectList_t *list;
GimpDrawable *drawable;
} GimpGuidesCommand_t;
Command_t*
gimp_guides_command_new(ObjectList_t *list, GimpDrawable *drawable)
{
GimpGuidesCommand_t *command = g_new(GimpGuidesCommand_t, 1);
command->list = list;
command->drawable = drawable;
return command_init(&command->parent, _("Use Gimp Guides"),
&gimp_guides_command_class);
}
static CmdExecuteValue_t
gimp_guides_command_execute(Command_t *parent)
{
GimpGuidesCommand_t *command = (GimpGuidesCommand_t*) parent;
do_create_gimp_guides_dialog(command->list, command->drawable);
return CMD_DESTRUCT;
}

View file

@ -0,0 +1,33 @@
/*
* This is a plug-in for the GIMP.
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2002 Maurits Rijk lpeek.mrijk@consunet.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef _IMAP_CMD_GIMP_GUIDES_H
#define _IMAP_CMD_GIMP_GUIDES_H
#include "imap_command.h"
#include "imap_object.h"
Command_t *gimp_guides_command_new(ObjectList_t *list,
GimpDrawable *_drawable);
#endif /* _IMAP_CMD_GUIDES_H */

View file

@ -158,12 +158,7 @@ make_guides_dialog()
data->guide_bounds);
gtk_widget_show(data->guide_bounds);
table = gtk_table_new(4, 4, FALSE);
gtk_container_set_border_width(GTK_CONTAINER(table), 10);
gtk_table_set_row_spacings(GTK_TABLE(table), 10);
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog->dialog)->vbox), table);
gtk_widget_show(table);
table = default_dialog_add_table(dialog, 4, 4);
label = create_label_in_table(table, 0, 0, _("_Width:"));
data->width = create_spin_button_in_table(table, label, 0, 1, 32, 1, 100);

View file

@ -194,3 +194,15 @@ default_dialog_set_label(DefaultDialog_t *dialog, gchar *text)
TRUE, TRUE, 5);
gtk_widget_show(label);
}
GtkWidget*
default_dialog_add_table(DefaultDialog_t *dialog, gint rows, gint cols)
{
GtkWidget *table = gtk_table_new(rows, cols, FALSE);
gtk_container_set_border_width(GTK_CONTAINER(table), 10);
gtk_table_set_row_spacings(GTK_TABLE(table), 10);
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog->dialog)->vbox), table);
gtk_widget_show(table);
return table;
}

View file

@ -3,7 +3,7 @@
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2000 Maurits Rijk lpeek.mrijk@consunet.nl
* Copyright (C) 1998-2002 Maurits Rijk lpeek.mrijk@consunet.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -55,5 +55,7 @@ void default_dialog_set_title(DefaultDialog_t *dialog, const gchar *title);
void default_dialog_set_ok_sensitivity(DefaultDialog_t *dialog,
gint sensitive);
void default_dialog_set_label(DefaultDialog_t *dialog, gchar *text);
GtkWidget *default_dialog_add_table(DefaultDialog_t *dialog, gint rows,
gint cols);
#endif /* _IMAP_DEFAULT_DIALOG_H */

View file

@ -23,6 +23,8 @@
#include "config.h"
#include <stdlib.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
@ -73,7 +75,7 @@ static void
grid_settings_ok_cb(gpointer data)
{
GridDialog_t *param = (GridDialog_t*) data;
gint new_snap;
gboolean new_snap;
new_snap = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->snap));
grid_width = gtk_spin_button_get_value_as_int(
@ -198,15 +200,8 @@ create_grid_settings_dialog()
data->dialog = dialog = make_default_dialog(_("Grid Settings"));
default_dialog_set_ok_cb(dialog, grid_settings_ok_cb, (gpointer) data);
main_table = gtk_table_new(4, 2, FALSE);
gtk_container_set_border_width(GTK_CONTAINER(main_table), 10);
gtk_table_set_row_spacings(GTK_TABLE(main_table), 10);
gtk_table_set_col_spacings(GTK_TABLE(main_table), 10);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog->dialog)->vbox),
main_table, TRUE, TRUE, 10);
gtk_widget_show(main_table);
main_table = default_dialog_add_table(dialog, 4, 2);
data->snap = gtk_check_button_new_with_mnemonic(_("_Snap-To Grid Enabled"));
g_signal_connect(G_OBJECT(data->snap), "toggled",
G_CALLBACK (snap_toggled_cb), data);

View file

@ -45,6 +45,7 @@
#include "imap_cmd_copy.h"
#include "imap_cmd_cut.h"
#include "imap_cmd_create.h"
#include "imap_cmd_gimp_guides.h"
#include "imap_cmd_guides.h"
#include "imap_cmd_move.h"
#include "imap_cmd_move_down.h"
@ -1396,6 +1397,12 @@ factory_create_guides_dialog(void)
return guides_command_new(_shapes);
}
static Command_t*
factory_use_gimp_guides_dialog(void)
{
return gimp_guides_command_new(_shapes, _drawable);
}
static Command_t*
factory_about_dialog(void)
{
@ -1474,6 +1481,7 @@ dialog(GimpDrawable *drawable)
menu_set_edit_map_info_command(menu, factory_settings_dialog);
menu_set_grid_settings_command(menu, factory_grid_settings_dialog);
menu_set_create_guides_command(menu, factory_create_guides_dialog);
menu_set_use_gimp_guides_command(menu, factory_use_gimp_guides_dialog);
menu_set_about_command(menu, factory_about_dialog);
/* Create popup */

View file

@ -160,9 +160,9 @@ menu_fuzzy_select(GtkWidget *widget, gpointer data)
_menu_callback_lock = FALSE;
} else {
/*
set_arrow_func();
tools_select_arrow();
popup_select_arrow();
set_fuzzy_select_func();
tools_select_fuzzy();
popup_select_fuzzy();
*/
}
}
@ -380,6 +380,9 @@ make_goodies_menu(GtkWidget *menu_bar)
_menu.grid = make_check_item(goodies_menu, _("Grid"), menu_grid, NULL);
make_item_with_label(goodies_menu, _("Grid Settings..."), menu_command,
&_menu.cmd_grid_settings);
make_separator(goodies_menu);
make_item_with_label(goodies_menu, _("Use GIMP Guides..."), menu_command,
&_menu.cmd_use_gimp_guides);
make_item_with_label(goodies_menu, _("Create Guides..."), menu_command,
&_menu.cmd_create_guides);
}

View file

@ -77,6 +77,7 @@ typedef struct {
CommandFactory_t cmd_grid_settings;
CommandFactory_t cmd_create_guides;
CommandFactory_t cmd_use_gimp_guides;
CommandFactory_t cmd_about;
} Menu_t;
@ -127,6 +128,8 @@ typedef struct {
((menu)->cmd_grid_settings = (command))
#define menu_set_create_guides_command(menu, command) \
((menu)->cmd_create_guides = (command))
#define menu_set_use_gimp_guides_command(menu, command) \
((menu)->cmd_use_gimp_guides = (command))
#define menu_set_about_command(menu, command) \
((menu)->cmd_about = (command))

View file

@ -85,7 +85,7 @@ type_toggled_cb(GtkWidget *widget, gpointer data)
}
static SettingsDialog_t*
make_settings_dialog()
create_settings_dialog()
{
SettingsDialog_t *data = g_new(SettingsDialog_t, 1);
GtkWidget *table, *vscrollbar, *frame, *hbox, *label;
@ -93,14 +93,7 @@ make_settings_dialog()
dialog = data->dialog = make_default_dialog(_("Settings for this Mapfile"));
default_dialog_set_ok_cb(dialog, settings_ok_cb, (gpointer) data);
table = gtk_table_new(9, 3, FALSE);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog->dialog)->vbox),
table);
gtk_table_set_row_spacings(GTK_TABLE(table), 10);
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
gtk_container_set_border_width(GTK_CONTAINER(table), 10);
gtk_widget_show(table);
table = default_dialog_add_table(dialog, 9, 3);
create_label_in_table(table, 0, 0, _("Filename:"));
data->filename = create_label_in_table(table, 0, 1, "");
@ -169,7 +162,7 @@ do_settings_dialog(void)
MapInfo_t *info = get_map_info();
if (!dialog)
dialog = make_settings_dialog();
dialog = create_settings_dialog();
gtk_label_set_text(GTK_LABEL(dialog->filename), filename);
browse_widget_set_filename(dialog->imagename, info->image_name);