1999-09-07 08:03:20 +08:00
|
|
|
/*
|
2007-06-06 16:44:52 +08:00
|
|
|
* This is a plug-in for GIMP.
|
1999-09-07 08:03:20 +08:00
|
|
|
*
|
|
|
|
* Generates clickable image maps.
|
|
|
|
*
|
2003-01-03 04:35:33 +08:00
|
|
|
* Copyright (C) 1998-2003 Maurits Rijk lpeek.mrijk@consunet.nl
|
1999-09-07 08:03:20 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1999-09-07 08:03:20 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1999-09-07 08:03:20 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1999-09-07 08:03:20 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-11-05 10:47:39 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2003-01-03 04:35:33 +08:00
|
|
|
#include "imap_commands.h"
|
1999-09-07 08:03:20 +08:00
|
|
|
#include "imap_rectangle.h"
|
|
|
|
#include "imap_main.h"
|
|
|
|
|
2001-11-05 10:47:39 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
1999-10-25 04:57:17 +08:00
|
|
|
static CmdExecuteValue_t select_region_command_execute(Command_t *parent);
|
1999-09-07 08:03:20 +08:00
|
|
|
|
|
|
|
static CommandClass_t select_region_command_class = {
|
2011-02-21 18:51:47 +08:00
|
|
|
NULL, /* select_region_command_destruct, */
|
1999-09-07 08:03:20 +08:00
|
|
|
select_region_command_execute,
|
2011-02-21 18:51:47 +08:00
|
|
|
NULL, /* select_region_command_undo */
|
|
|
|
NULL /* select_region_command_redo */
|
1999-09-07 08:03:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
2011-02-21 18:51:47 +08:00
|
|
|
Command_t parent;
|
|
|
|
GtkWidget *widget;
|
1999-09-07 08:03:20 +08:00
|
|
|
ObjectList_t *list;
|
2011-02-21 18:51:47 +08:00
|
|
|
gint x;
|
|
|
|
gint y;
|
|
|
|
Object_t *obj;
|
|
|
|
Command_t *unselect_command;
|
1999-09-07 08:03:20 +08:00
|
|
|
} SelectRegionCommand_t;
|
|
|
|
|
2006-01-17 20:43:50 +08:00
|
|
|
Command_t*
|
|
|
|
select_region_command_new(GtkWidget *widget, ObjectList_t *list, gint x,
|
2011-02-21 18:51:47 +08:00
|
|
|
gint y)
|
1999-09-07 08:03:20 +08:00
|
|
|
{
|
|
|
|
SelectRegionCommand_t *command = g_new(SelectRegionCommand_t, 1);
|
|
|
|
Command_t *sub_command;
|
|
|
|
|
|
|
|
command->widget = widget;
|
|
|
|
command->list = list;
|
|
|
|
command->x = x;
|
|
|
|
command->y = y;
|
2006-01-17 20:43:50 +08:00
|
|
|
(void) command_init(&command->parent, _("Select Region"),
|
2011-02-21 18:51:47 +08:00
|
|
|
&select_region_command_class);
|
1999-09-07 08:03:20 +08:00
|
|
|
|
|
|
|
sub_command = unselect_all_command_new(list, NULL);
|
|
|
|
command_add_subcommand(&command->parent, sub_command);
|
1999-10-25 04:57:17 +08:00
|
|
|
command->unselect_command = sub_command;
|
1999-09-07 08:03:20 +08:00
|
|
|
|
|
|
|
return &command->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
select_one_object(Object_t *obj, gpointer data)
|
|
|
|
{
|
|
|
|
SelectRegionCommand_t *command = (SelectRegionCommand_t*) data;
|
|
|
|
command_add_subcommand(&command->parent, select_command_new(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
select_motion(GtkWidget *widget, GdkEventMotion *event, gpointer data)
|
|
|
|
{
|
|
|
|
SelectRegionCommand_t *command = (SelectRegionCommand_t*) data;
|
|
|
|
Object_t *obj = command->obj;
|
|
|
|
Rectangle_t *rectangle = ObjectToRectangle(obj);
|
2011-02-21 22:45:26 +08:00
|
|
|
|
1999-09-07 08:03:20 +08:00
|
|
|
gint x = get_real_coord((gint) event->x);
|
|
|
|
gint y = get_real_coord((gint) event->y);
|
|
|
|
|
|
|
|
rectangle->width = x - rectangle->x;
|
|
|
|
rectangle->height = y - rectangle->y;
|
2011-02-21 22:45:26 +08:00
|
|
|
|
|
|
|
preview_redraw ();
|
1999-09-07 08:03:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
select_release(GtkWidget *widget, GdkEventButton *event, gpointer data)
|
|
|
|
{
|
|
|
|
SelectRegionCommand_t *command = (SelectRegionCommand_t*) data;
|
|
|
|
Object_t *obj = command->obj;
|
|
|
|
Rectangle_t *rectangle = ObjectToRectangle(obj);
|
|
|
|
gpointer id;
|
1999-10-25 04:57:17 +08:00
|
|
|
gint count;
|
1999-09-07 08:03:20 +08:00
|
|
|
|
2006-01-17 20:43:50 +08:00
|
|
|
g_signal_handlers_disconnect_by_func(widget,
|
2001-12-29 21:26:29 +08:00
|
|
|
select_motion, data);
|
2006-01-17 20:43:50 +08:00
|
|
|
g_signal_handlers_disconnect_by_func(widget,
|
2001-12-29 21:26:29 +08:00
|
|
|
select_release, data);
|
1999-09-07 08:03:20 +08:00
|
|
|
|
|
|
|
object_normalize(obj);
|
|
|
|
|
|
|
|
id = object_list_add_select_cb(command->list, select_one_object, command);
|
1999-10-25 04:57:17 +08:00
|
|
|
count = object_list_select_region(command->list, rectangle->x, rectangle->y,
|
2011-02-21 18:51:47 +08:00
|
|
|
rectangle->width, rectangle->height);
|
1999-09-07 08:03:20 +08:00
|
|
|
object_list_remove_select_cb(command->list, id);
|
|
|
|
|
1999-10-25 04:57:17 +08:00
|
|
|
if (count) {
|
|
|
|
command_list_add(&command->parent);
|
2011-02-21 18:51:47 +08:00
|
|
|
} else { /* Nothing selected */
|
1999-10-25 04:57:17 +08:00
|
|
|
if (command->unselect_command->sub_commands)
|
2011-02-21 18:51:47 +08:00
|
|
|
command_list_add(&command->parent);
|
1999-10-25 04:57:17 +08:00
|
|
|
}
|
2011-02-21 22:45:26 +08:00
|
|
|
preview_unset_tmp_obj (command->obj);
|
|
|
|
|
|
|
|
preview_redraw ();
|
1999-09-07 08:03:20 +08:00
|
|
|
}
|
|
|
|
|
1999-10-25 04:57:17 +08:00
|
|
|
static CmdExecuteValue_t
|
1999-09-07 08:03:20 +08:00
|
|
|
select_region_command_execute(Command_t *parent)
|
|
|
|
{
|
|
|
|
SelectRegionCommand_t *command = (SelectRegionCommand_t*) parent;
|
|
|
|
|
|
|
|
command->obj = create_rectangle(command->x, command->y, 0, 0);
|
2011-02-21 22:45:26 +08:00
|
|
|
preview_set_tmp_obj (command->obj);
|
|
|
|
|
2006-01-17 20:43:50 +08:00
|
|
|
g_signal_connect(command->widget, "button-release-event",
|
|
|
|
G_CALLBACK (select_release), command);
|
|
|
|
g_signal_connect(command->widget, "motion-notify-event",
|
|
|
|
G_CALLBACK (select_motion), command);
|
1999-09-07 08:03:20 +08:00
|
|
|
|
1999-10-25 04:57:17 +08:00
|
|
|
return CMD_IGNORE;
|
1999-09-07 08:03:20 +08:00
|
|
|
}
|