gimp/plug-ins/imagemap/imap_tools.c

222 lines
5.5 KiB
C
Raw Normal View History

1999-09-07 08:03:20 +08:00
/*
* This is a plug-in for the GIMP.
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2002 Maurits Rijk lpeek.mrijk@consunet.nl
1999-09-07 08:03:20 +08:00
*
* 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.
*
*/
2000-02-17 16:36:46 +08:00
#include "config.h"
app/gimpprogress.c app/nav_window.c app/ops_buttons.c app/undo_history.c 2001-12-29 Michael Natterer <mitch@gimp.org> * app/gimpprogress.c * app/nav_window.c * app/ops_buttons.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/channels-commands.c * app/gui/color-area.c * app/gui/color-notebook.c * app/gui/color-select.c * app/gui/colormap-dialog.c * app/gui/convert-dialog.c * app/gui/device-status-dialog.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/info-dialog.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/paths-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/toolbox.c * app/gui/user-install-dialog.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpinktool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimprotatetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/selection_options.c * app/widgets/gimpchannellistview.c * app/widgets/gimpcolorpanel.c * app/widgets/gimpcomponentlistitem.c * app/widgets/gimpconstrainedhwrapbox.c * app/widgets/gimpcontainergridview.c * app/widgets/gimpcontainerlistview.c * app/widgets/gimpcontainermenuimpl.c * app/widgets/gimpdialogfactory.c * app/widgets/gimpdnd.c * app/widgets/gimpdock.c * app/widgets/gimpdockbook.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimpdrawablelistview.c * app/widgets/gimpfontselection-dialog.c * app/widgets/gimphistogramview.c * app/widgets/gimpitemfactory.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplistitem.[ch] * app/widgets/gimpmenuitem.c * app/widgets/gimppreview.[ch] * app/widgets/gtkhwrapbox.c * app/widgets/gtkvwrapbox.c * app/widgets/gtkwrapbox.c * libgimp/gimpbrushmenu.c * libgimp/gimpexport.c * libgimp/gimpgradientmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimpwidgets/gimpbutton.c * libgimpwidgets/gimpchainbutton.[ch] * libgimpwidgets/gimpcolorarea.h * libgimpwidgets/gimpcolorbutton.c * libgimpwidgets/gimpfileselection.c * libgimpwidgets/gimphelpui.c * libgimpwidgets/gimpoffsetarea.c * libgimpwidgets/gimppatheditor.c * libgimpwidgets/gimppixmap.h * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpstock.[ch] * libgimpwidgets/gimpwidgets.h * plug-ins/FractalExplorer/Dialogs.c * plug-ins/FractalExplorer/Events.c * plug-ins/FractalExplorer/FractalExplorer.c * plug-ins/Lighting/lighting_ui.c * plug-ins/MapObject/mapobject_ui.c * plug-ins/bmp/bmpwrite.c * plug-ins/dbbrowser/dbbrowser_utils.c * plug-ins/fits/fits.c * plug-ins/flame/flame.c * plug-ins/fp/fp_gtk.c * plug-ins/fp/fp_misc.c * plug-ins/gfig/gfig.c * plug-ins/gflare/gflare.c * plug-ins/gfli/gfli.c * plug-ins/gimpressionist/*.c * plug-ins/imagemap/*.[ch] * plug-ins/maze/maze_face.c * plug-ins/mosaic/mosaic.c * plug-ins/pagecurl/pagecurl.c * plug-ins/print/print_gimp.h * plug-ins/rcm/rcm_callback.c * plug-ins/rcm/rcm_dialog.c * plug-ins/rcm/rcm_misc.c * plug-ins/script-fu/script-fu-console.c * plug-ins/script-fu/script-fu-scripts.c * plug-ins/script-fu/script-fu-server.c * plug-ins/sel2path/sel2path.c * plug-ins/sel2path/sel2path_adv_dialog.c * plug-ins/sgi/sgi.c * plug-ins/webbrowser/webbrowser.c * plug-ins/xjt/xjt.c * plug-ins/common/[A-n]*.c: compile with GTK_DISABLE_DEPRECATED defined. Not everything is fully ported yet, had to #undef GTK_DISABLE_DEPRECATED in many places and added #warnings when doing so. * pixmaps/Makefile.am * pixmaps/chain.xpm: removed. * themes/Default/Makefile.am * themes/Default/images/Makefile.am * themes/Default/images/stock-button-hchain-broken.png * themes/Default/images/stock-button-hchain.png * themes/Default/images/stock-button-vchain-broken.png * themes/Default/images/stock-button-vchain.png: new stock icons.
2001-12-29 21:26:29 +08:00
#include <gtk/gtk.h>
1999-09-07 08:03:20 +08:00
#include "imap_circle.h"
#include "imap_edit_area_info.h"
#include "imap_main.h"
#include "imap_menu.h"
#include "imap_misc.h"
#include "imap_polygon.h"
#include "imap_popup.h"
#include "imap_rectangle.h"
#include "imap_stock.h"
1999-09-07 08:03:20 +08:00
#include "imap_tools.h"
#include "libgimp/stdplugins-intl.h"
#include "libgimpwidgets/gimpstock.h"
1999-09-07 08:03:20 +08:00
static gboolean _callback_lock;
static Tools_t _tools;
static void
tools_command(GtkWidget *widget, gpointer data)
{
CommandFactory_t *factory = (CommandFactory_t*) data;
Command_t *command = (*factory)();
command_execute(command);
}
gboolean
1999-09-07 08:03:20 +08:00
arrow_on_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
if (event->button == 1) {
if (event->type == GDK_2BUTTON_PRESS)
edit_shape((gint) event->x, (gint) event->y);
else
select_shape(widget, event);
} else {
do_popup_menu(event);
}
return FALSE;
1999-09-07 08:03:20 +08:00
}
static void
arrow_clicked(GtkWidget *widget, gpointer data)
{
if (_callback_lock) {
_callback_lock = FALSE;
} else {
set_arrow_func();
menu_select_arrow();
popup_select_arrow();
}
}
static void
fuzzy_select_clicked(GtkWidget *widget, gpointer data)
{
if (_callback_lock) {
_callback_lock = FALSE;
} else {
set_fuzzy_select_func();
/*
menu_select_fuzzy_select();
popup_select_fuzzy_select();
*/
}
}
1999-09-07 08:03:20 +08:00
static void
rectangle_clicked(GtkWidget *widget, gpointer data)
{
if (_callback_lock) {
_callback_lock = FALSE;
} else {
set_rectangle_func();
menu_select_rectangle();
popup_select_rectangle();
}
}
static void
circle_clicked(GtkWidget *widget, gpointer data)
{
if (_callback_lock) {
_callback_lock = FALSE;
} else {
set_circle_func();
menu_select_circle();
popup_select_circle();
}
}
static void
polygon_clicked(GtkWidget *widget, gpointer data)
{
if (_callback_lock) {
_callback_lock = FALSE;
} else {
set_polygon_func();
menu_select_polygon();
popup_select_polygon();
}
}
Tools_t*
make_tools(GtkWidget *window)
{
GtkWidget *handlebox;
GtkWidget *toolbar;
toolbar = gtk_toolbar_new();
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);
1999-09-07 08:03:20 +08:00
_tools.container = handlebox = gtk_handle_box_new();
updated for GTK2 build 2001-07-28 Hans Breuer <hans@breuer.org> * */*/makefile.msc : updated for GTK2 build * app/widgets/makefile.msc : (new file) forgot this one last time * plug-ins/common/animationplay.c : reflect that GTK2 has its gdk<x|win32|fb>.h files in the back-end sub directories * plug-ins/common/gif.c : * plug-ins/common/jpeg.c : * plug-ins/dbbrowser/dbbrowser_utils.c : * plug-ins/gap/gap_dbbrowser_utils.c : * plug-ims/gimpressionist/presets.c : * plug-ims/gimpressionist/imap_setting.c : * plug-ims/gimpressionist/imap_source.c : * plug-ims/script-fu/script-fu-console.c : * plug-ims/script-fu/script-fu-scripts.c : #define GTK_ENABLE_BROKEN and include <gtk/gtktext.h> to make them compile/work again * plug-ins/common/spheredesigner.c : gtk_color_selction_set_opacity renamed to gtk_color_selction_set_current_alpha * plug-ins/gflare/gtkmultioptionmenu.c : ported ny removing the virtual draw function and style->xthickness and ythickness via direct access, klass field isn't available anymore * plug-ins/common/nlfilt.c : * plug-ims/gap/gap_movdialog.c : * plug-ims/gimpressionist/gimpressionist.c : gtk_widget_set_default_visible is neither available nor needed anymore * plug-ins/common/plugindetails.c : ported to GtkTextBuffer and reflect gtk_paned api changes * plug-ims/gimpressionist/imap_preview.c : replace GTK_WIDGET(a)->klass access by GTK_WIDGET_GET_CLASS(a) * plug-ims/gimpressionist/imap_selection.c : * plug-ims/gimpressionist/imap_toolbar.c : * plug-ims/gimpressionist/imap_tools.c : gtk_toolbar api changes
2001-07-29 03:40:07 +08:00
gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_VERTICAL);
1999-09-07 08:03:20 +08:00
gtk_container_set_border_width(GTK_CONTAINER(toolbar), 5);
1999-09-07 08:03:20 +08:00
gtk_container_add(GTK_CONTAINER(handlebox), toolbar);
_tools.arrow = make_toolbar_radio_icon(toolbar, IMAP_STOCK_ARROW,
NULL, _("Select"),
_("Select existing area"),
1999-09-07 08:03:20 +08:00
arrow_clicked, NULL);
_tools.fuzzy_select =
make_toolbar_radio_icon(toolbar, GIMP_STOCK_TOOL_FUZZY_SELECT,
_tools.arrow, _("Fuzzy Select"),
_("Select contiguous regions"),
fuzzy_select_clicked, NULL);
_tools.rectangle = make_toolbar_radio_icon(toolbar, IMAP_STOCK_RECTANGLE,
_tools.fuzzy_select,
_("Rectangle"),
1999-10-25 04:57:17 +08:00
_("Define Rectangle area"),
1999-09-07 08:03:20 +08:00
rectangle_clicked, NULL);
_tools.circle = make_toolbar_radio_icon(toolbar, IMAP_STOCK_CIRCLE,
_tools.rectangle, _("Circle"),
1999-10-25 04:57:17 +08:00
_("Define Circle/Oval area"),
1999-09-07 08:03:20 +08:00
circle_clicked, NULL);
_tools.polygon = make_toolbar_radio_icon(toolbar, IMAP_STOCK_POLYGON,
_tools.circle, _("Polygon"),
1999-10-25 04:57:17 +08:00
_("Define Polygon area"),
1999-09-07 08:03:20 +08:00
polygon_clicked, NULL);
gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
_tools.edit = make_toolbar_stock_icon(toolbar, GTK_STOCK_PROPERTIES,
_("Edit"),
1999-10-25 04:57:17 +08:00
_("Edit selected area info"), tools_command,
1999-09-07 08:03:20 +08:00
&_tools.cmd_edit);
gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
_tools.delete = make_toolbar_stock_icon(toolbar, GTK_STOCK_DELETE,
_("Delete"),
1999-10-25 04:57:17 +08:00
_("Delete selected area"), tools_command,
1999-09-07 08:03:20 +08:00
&_tools.cmd_delete);
gtk_widget_show(toolbar);
gtk_widget_show(handlebox);
tools_set_sensitive(FALSE);
set_arrow_func();
return &_tools;
}
static void
tools_select(GtkWidget *widget)
{
_callback_lock = TRUE;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
gtk_widget_grab_focus(widget);
}
void
tools_select_arrow(void)
{
tools_select(_tools.arrow);
}
void
tools_select_rectangle(void)
{
tools_select(_tools.rectangle);
}
void
tools_select_circle(void)
{
tools_select(_tools.circle);
}
void
tools_select_polygon(void)
{
tools_select(_tools.polygon);
}
void
tools_set_sensitive(gboolean sensitive)
{
gtk_widget_set_sensitive(_tools.edit, sensitive);
gtk_widget_set_sensitive(_tools.delete, sensitive);
}