1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/*
* This is a plug-in for the GIMP.
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2003 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 <gtk/gtk.h>
#include "libgimp/gimp.h"
#include "imap_commands.h"
#include "imap_main.h"
#include "libgimp/stdplugins-intl.h"
static void move_command_destruct(Command_t *parent);
static CmdExecuteValue_t move_command_execute(Command_t *parent);
CommandClass_t move_command_class = {
move_command_destruct,
move_command_execute,
NULL, /* move_command_undo */
NULL /* move_command_redo */
};
typedef struct {
Command_t parent;
PreferencesData_t *preferences;
Preview_t *preview;
Object_t *obj;
gint start_x;
gint start_y;
gint obj_start_x;
gint obj_start_y;
gint obj_x;
gint obj_y;
gint obj_width;
gint obj_height;
gint image_width;
gint image_height;
GdkCursorType cursor; /* Remember previous cursor */
gboolean moved_first_time;
} MoveCommand_t;
Command_t*
move_command_new(Preview_t *preview, Object_t *obj, gint x, gint y)
{
MoveCommand_t *command = g_new(MoveCommand_t, 1);
command->preferences = get_preferences();
command->preview = preview;
command->obj = object_ref(obj);
command->start_x = x;
command->start_y = y;
object_get_dimensions(obj, &command->obj_x, &command->obj_y,
&command->obj_width, &command->obj_height);
command->obj_start_x = command->obj_x;
command->obj_start_y = command->obj_y;
command->image_width = get_image_width();
command->image_height = get_image_height();
command->moved_first_time = TRUE;
return command_init(&command->parent, _("Move"), &move_command_class);
}
static void
move_command_destruct(Command_t *parent)
{
MoveCommand_t *command = (MoveCommand_t*) parent;
object_unref(command->obj);
}
static void
button_motion(GtkWidget *widget, GdkEventMotion *event, gpointer data)
{
MoveCommand_t *command = (MoveCommand_t*) data;
Object_t *obj = command->obj;
gint dx = get_real_coord((gint) event->x) - command->start_x;
gint dy = get_real_coord((gint) event->y) - command->start_y;
if (command->moved_first_time) {
command->moved_first_time = FALSE;
command->cursor = preview_set_cursor(command->preview, GDK_FLEUR);
gdk_gc_set_function(command->preferences->normal_gc, GDK_EQUIV);
gdk_gc_set_function(command->preferences->selected_gc, GDK_EQUIV);
hide_url();
}
if (command->obj_x + dx < 0)
dx = -command->obj_x;
if (command->obj_x + command->obj_width + dx > command->image_width)
dx = command->image_width - command->obj_width - command->obj_x;
if (command->obj_y + dy < 0)
dy = -command->obj_y;
if (command->obj_y + command->obj_height + dy > command->image_height)
dy = command->image_height - command->obj_height - command->obj_y;
if (dx || dy) {
command->start_x = get_real_coord((gint) event->x);
command->start_y = get_real_coord((gint) event->y);
command->obj_x += dx;
command->obj_y += dy;
object_draw(obj, widget->window);
object_move(obj, dx, dy);
object_draw(obj, widget->window);
}
}
static void
button_release(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
MoveCommand_t *command = (MoveCommand_t*) data;
g_signal_handlers_disconnect_by_func (widget,
button_motion, data);
g_signal_handlers_disconnect_by_func (widget,
button_release, data);
if (!command->moved_first_time) {
preview_set_cursor(command->preview, command->cursor);
gdk_gc_set_function(command->preferences->normal_gc, GDK_COPY);
gdk_gc_set_function(command->preferences->selected_gc, GDK_COPY);
show_url();
}
command->obj_x -= command->obj_start_x;
command->obj_y -= command->obj_start_y;
if (command->obj_x || command->obj_y)
command_list_add(object_move_command_new(command->obj, command->obj_x,
command->obj_y));
/* preview_thaw(); */
}
static CmdExecuteValue_t
move_command_execute(Command_t *parent)
{
MoveCommand_t *command = (MoveCommand_t*) parent;
GtkWidget *widget = command->preview->preview;
/* preview_freeze(); */
g_signal_connect(widget, "button_release_event",
G_CALLBACK (button_release), command);
g_signal_connect(widget, "motion_notify_event",
G_CALLBACK (button_motion), command);
return CMD_DESTRUCT;
}
|