1 /*
2  * This is a plug-in for GIMP.
3  *
4  * Generates clickable image maps.
5  *
6  * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.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 3 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, see <https://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #include "config.h"
24 
25 #include <gtk/gtk.h>
26 
27 #include "imap_commands.h"
28 #include "imap_polygon.h"
29 
30 #include "libgimp/stdplugins-intl.h"
31 
32 static CmdExecuteValue_t delete_point_command_execute(Command_t *parent);
33 static void delete_point_command_undo(Command_t *parent);
34 
35 static CommandClass_t delete_point_command_class = {
36    NULL,                        /* delete_point_command_destruct */
37    delete_point_command_execute,
38    delete_point_command_undo,
39    NULL                         /* delete_point_command_redo */
40 };
41 
42 typedef struct {
43    Command_t    parent;
44    Polygon_t   *polygon;
45    GdkPoint    *point;
46    GdkPoint     copy;
47    gint         position;
48 } DeletePointCommand_t;
49 
50 Command_t*
delete_point_command_new(Object_t * obj,GdkPoint * point)51 delete_point_command_new(Object_t *obj, GdkPoint *point)
52 {
53    DeletePointCommand_t *command = g_new(DeletePointCommand_t, 1);
54 
55    command->polygon = ObjectToPolygon(obj);
56    command->point = point;
57    command->copy = *point;
58    command->position = g_list_index(command->polygon->points,
59                                     (gpointer) point);
60    return command_init(&command->parent, _("Delete Point"),
61                        &delete_point_command_class);
62 }
63 
64 static CmdExecuteValue_t
delete_point_command_execute(Command_t * parent)65 delete_point_command_execute(Command_t *parent)
66 {
67    DeletePointCommand_t *command = (DeletePointCommand_t*) parent;
68    Polygon_t *polygon = command->polygon;
69    GList *p = g_list_find(polygon->points, (gpointer) command->point);
70 
71    g_free(p->data);
72    polygon->points = g_list_remove_link(polygon->points, p);
73    return CMD_APPEND;
74 }
75 
76 static void
delete_point_command_undo(Command_t * parent)77 delete_point_command_undo(Command_t *parent)
78 {
79    DeletePointCommand_t *command = (DeletePointCommand_t*) parent;
80    Polygon_t *polygon = command->polygon;
81    GdkPoint *point = &command->copy;
82 
83    command->point = new_point(point->x, point->y);
84    polygon->points = g_list_insert(polygon->points, (gpointer) command->point,
85                                    command->position);
86 }
87