1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "libgimpwidgets/gimpwidgets.h"
25
#include "tools-types.h"
27
#include "base/tile-manager.h"
29
#include "core/gimpdrawable-transform.h"
30
#include "core/gimpimage.h"
31
#include "core/gimpitem-linked.h"
32
#include "core/gimplayer.h"
33
#include "core/gimplayermask.h"
34
#include "core/gimptoolinfo.h"
36
#include "widgets/gimphelp-ids.h"
38
#include "display/gimpdisplay.h"
40
#include "gimpflipoptions.h"
41
#include "gimpfliptool.h"
42
#include "gimptoolcontrol.h"
44
#include "gimp-intl.h"
47
/* local function prototypes */
49
static void gimp_flip_tool_class_init (GimpFlipToolClass *klass);
50
static void gimp_flip_tool_init (GimpFlipTool *flip_tool);
52
static void gimp_flip_tool_modifier_key (GimpTool *tool,
55
GdkModifierType state,
57
static void gimp_flip_tool_cursor_update (GimpTool *tool,
59
GdkModifierType state,
62
static TileManager * gimp_flip_tool_transform (GimpTransformTool *tool,
68
static GimpTransformToolClass *parent_class = NULL;
71
/* public functions */
74
gimp_flip_tool_register (GimpToolRegisterCallback callback,
77
(* callback) (GIMP_TYPE_FLIP_TOOL,
78
GIMP_TYPE_FLIP_OPTIONS,
79
gimp_flip_options_gui,
83
_("Flip the layer or selection"),
84
N_("_Flip"), "<shift>F",
85
NULL, GIMP_HELP_TOOL_FLIP,
91
gimp_flip_tool_get_type (void)
93
static GType tool_type = 0;
97
static const GTypeInfo tool_info =
99
sizeof (GimpFlipToolClass),
100
(GBaseInitFunc) NULL,
101
(GBaseFinalizeFunc) NULL,
102
(GClassInitFunc) gimp_flip_tool_class_init,
103
NULL, /* class_finalize */
104
NULL, /* class_data */
105
sizeof (GimpFlipTool),
107
(GInstanceInitFunc) gimp_flip_tool_init,
110
tool_type = g_type_register_static (GIMP_TYPE_TRANSFORM_TOOL,
119
/* private functions */
122
gimp_flip_tool_class_init (GimpFlipToolClass *klass)
124
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
125
GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
127
parent_class = g_type_class_peek_parent (klass);
129
tool_class->modifier_key = gimp_flip_tool_modifier_key;
130
tool_class->cursor_update = gimp_flip_tool_cursor_update;
132
trans_class->transform = gimp_flip_tool_transform;
136
gimp_flip_tool_init (GimpFlipTool *flip_tool)
138
GimpTool *tool = GIMP_TOOL (flip_tool);
139
GimpTransformTool *transform_tool = GIMP_TRANSFORM_TOOL (flip_tool);
141
gimp_tool_control_set_snap_to (tool->control, FALSE);
142
gimp_tool_control_set_cursor (tool->control,
143
GDK_SB_H_DOUBLE_ARROW);
144
gimp_tool_control_set_tool_cursor (tool->control,
145
GIMP_TOOL_CURSOR_FLIP_HORIZONTAL);
146
gimp_tool_control_set_toggle_cursor (tool->control,
147
GDK_SB_V_DOUBLE_ARROW);
148
gimp_tool_control_set_toggle_tool_cursor (tool->control,
149
GIMP_TOOL_CURSOR_FLIP_VERTICAL);
151
transform_tool->use_grid = FALSE;
155
gimp_flip_tool_modifier_key (GimpTool *tool,
158
GdkModifierType state,
161
GimpFlipOptions *options = GIMP_FLIP_OPTIONS (tool->tool_info->tool_options);
163
if (key == GDK_CONTROL_MASK)
165
switch (options->flip_type)
167
case GIMP_ORIENTATION_HORIZONTAL:
168
g_object_set (options,
169
"flip-type", GIMP_ORIENTATION_VERTICAL,
173
case GIMP_ORIENTATION_VERTICAL:
174
g_object_set (options,
175
"flip-type", GIMP_ORIENTATION_HORIZONTAL,
186
gimp_flip_tool_cursor_update (GimpTool *tool,
188
GdkModifierType state,
191
GimpFlipOptions *options;
192
gboolean bad_cursor = TRUE;
194
options = GIMP_FLIP_OPTIONS (tool->tool_info->tool_options);
196
if (gimp_image_coords_in_active_drawable (gdisp->gimage, coords))
198
GimpChannel *selection = gimp_image_get_mask (gdisp->gimage);
200
/* Is there a selected region? If so, is cursor inside? */
201
if (gimp_channel_is_empty (selection) ||
202
gimp_channel_value (selection, coords->x, coords->y))
210
gimp_tool_control_set_cursor (tool->control, GIMP_CURSOR_BAD);
211
gimp_tool_control_set_toggle_cursor (tool->control, GIMP_CURSOR_BAD);
215
gimp_tool_control_set_cursor (tool->control, GDK_SB_H_DOUBLE_ARROW);
216
gimp_tool_control_set_toggle_cursor (tool->control, GDK_SB_V_DOUBLE_ARROW);
219
gimp_tool_control_set_toggle (tool->control,
220
options->flip_type == GIMP_ORIENTATION_VERTICAL);
222
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
226
gimp_flip_tool_transform (GimpTransformTool *trans_tool,
227
GimpItem *active_item,
231
GimpTransformOptions *tr_options;
232
GimpFlipOptions *options;
233
GimpContext *context;
235
TileManager *ret = NULL;
237
options = GIMP_FLIP_OPTIONS (GIMP_TOOL (trans_tool)->tool_info->tool_options);
238
tr_options = GIMP_TRANSFORM_OPTIONS (options);
239
context = GIMP_CONTEXT (options);
241
switch (options->flip_type)
243
case GIMP_ORIENTATION_HORIZONTAL:
244
axis = ((gdouble) trans_tool->x1 +
245
(gdouble) (trans_tool->x2 - trans_tool->x1) / 2.0);
248
case GIMP_ORIENTATION_VERTICAL:
249
axis = ((gdouble) trans_tool->y1 +
250
(gdouble) (trans_tool->y2 - trans_tool->y1) / 2.0);
257
if (gimp_item_get_linked (active_item))
258
gimp_item_linked_flip (active_item, context, options->flip_type, axis,
261
if (GIMP_IS_LAYER (active_item) &&
262
gimp_layer_get_mask (GIMP_LAYER (active_item)) &&
265
GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (active_item));
267
gimp_item_flip (GIMP_ITEM (mask), context,
268
options->flip_type, axis, FALSE);
271
switch (tr_options->type)
273
case GIMP_TRANSFORM_TYPE_LAYER:
274
case GIMP_TRANSFORM_TYPE_SELECTION:
275
ret = gimp_drawable_transform_tiles_flip (GIMP_DRAWABLE (active_item),
277
trans_tool->original,
278
options->flip_type, axis,
282
case GIMP_TRANSFORM_TYPE_PATH:
283
gimp_item_flip (active_item, context, options->flip_type, axis, FALSE);