~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to app/tools/gimpfliptool.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "libgimpwidgets/gimpwidgets.h"
 
24
 
 
25
#include "tools-types.h"
 
26
 
 
27
#include "base/tile-manager.h"
 
28
 
 
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"
 
35
 
 
36
#include "widgets/gimphelp-ids.h"
 
37
 
 
38
#include "display/gimpdisplay.h"
 
39
 
 
40
#include "gimpflipoptions.h"
 
41
#include "gimpfliptool.h"
 
42
#include "gimptoolcontrol.h"
 
43
 
 
44
#include "gimp-intl.h"
 
45
 
 
46
 
 
47
/*  local function prototypes  */
 
48
 
 
49
static void          gimp_flip_tool_class_init    (GimpFlipToolClass *klass);
 
50
static void          gimp_flip_tool_init          (GimpFlipTool      *flip_tool);
 
51
 
 
52
static void          gimp_flip_tool_modifier_key  (GimpTool          *tool,
 
53
                                                   GdkModifierType    key,
 
54
                                                   gboolean           press,
 
55
                                                   GdkModifierType    state,
 
56
                                                   GimpDisplay       *gdisp);
 
57
static void          gimp_flip_tool_cursor_update (GimpTool          *tool,
 
58
                                                   GimpCoords        *coords,
 
59
                                                   GdkModifierType    state,
 
60
                                                   GimpDisplay       *gdisp);
 
61
 
 
62
static TileManager * gimp_flip_tool_transform     (GimpTransformTool *tool,
 
63
                                                   GimpItem          *item,
 
64
                                                   gboolean           mask_empty,
 
65
                                                   GimpDisplay       *gdisp);
 
66
 
 
67
 
 
68
static GimpTransformToolClass *parent_class = NULL;
 
69
 
 
70
 
 
71
/*  public functions  */
 
72
 
 
73
void
 
74
gimp_flip_tool_register (GimpToolRegisterCallback  callback,
 
75
                         gpointer                  data)
 
76
{
 
77
  (* callback) (GIMP_TYPE_FLIP_TOOL,
 
78
                GIMP_TYPE_FLIP_OPTIONS,
 
79
                gimp_flip_options_gui,
 
80
                0,
 
81
                "gimp-flip-tool",
 
82
                _("Flip"),
 
83
                _("Flip the layer or selection"),
 
84
                N_("_Flip"), "<shift>F",
 
85
                NULL, GIMP_HELP_TOOL_FLIP,
 
86
                GIMP_STOCK_TOOL_FLIP,
 
87
                data);
 
88
}
 
89
 
 
90
GType
 
91
gimp_flip_tool_get_type (void)
 
92
{
 
93
  static GType tool_type = 0;
 
94
 
 
95
  if (! tool_type)
 
96
    {
 
97
      static const GTypeInfo tool_info =
 
98
      {
 
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),
 
106
        0,              /* n_preallocs    */
 
107
        (GInstanceInitFunc) gimp_flip_tool_init,
 
108
      };
 
109
 
 
110
      tool_type = g_type_register_static (GIMP_TYPE_TRANSFORM_TOOL,
 
111
                                          "GimpFlipTool",
 
112
                                          &tool_info, 0);
 
113
    }
 
114
 
 
115
  return tool_type;
 
116
}
 
117
 
 
118
 
 
119
/*  private functions  */
 
120
 
 
121
static void
 
122
gimp_flip_tool_class_init (GimpFlipToolClass *klass)
 
123
{
 
124
  GimpToolClass          *tool_class  = GIMP_TOOL_CLASS (klass);
 
125
  GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
 
126
 
 
127
  parent_class = g_type_class_peek_parent (klass);
 
128
 
 
129
  tool_class->modifier_key  = gimp_flip_tool_modifier_key;
 
130
  tool_class->cursor_update = gimp_flip_tool_cursor_update;
 
131
 
 
132
  trans_class->transform    = gimp_flip_tool_transform;
 
133
}
 
134
 
 
135
static void
 
136
gimp_flip_tool_init (GimpFlipTool *flip_tool)
 
137
{
 
138
  GimpTool          *tool           = GIMP_TOOL (flip_tool);
 
139
  GimpTransformTool *transform_tool = GIMP_TRANSFORM_TOOL (flip_tool);
 
140
 
 
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);
 
150
 
 
151
  transform_tool->use_grid = FALSE;
 
152
}
 
153
 
 
154
static void
 
155
gimp_flip_tool_modifier_key (GimpTool        *tool,
 
156
                             GdkModifierType  key,
 
157
                             gboolean         press,
 
158
                             GdkModifierType  state,
 
159
                             GimpDisplay     *gdisp)
 
160
{
 
161
  GimpFlipOptions *options = GIMP_FLIP_OPTIONS (tool->tool_info->tool_options);
 
162
 
 
163
  if (key == GDK_CONTROL_MASK)
 
164
    {
 
165
      switch (options->flip_type)
 
166
        {
 
167
        case GIMP_ORIENTATION_HORIZONTAL:
 
168
          g_object_set (options,
 
169
                        "flip-type", GIMP_ORIENTATION_VERTICAL,
 
170
                        NULL);
 
171
          break;
 
172
 
 
173
        case GIMP_ORIENTATION_VERTICAL:
 
174
          g_object_set (options,
 
175
                        "flip-type", GIMP_ORIENTATION_HORIZONTAL,
 
176
                        NULL);
 
177
          break;
 
178
 
 
179
        default:
 
180
          break;
 
181
        }
 
182
    }
 
183
}
 
184
 
 
185
static void
 
186
gimp_flip_tool_cursor_update (GimpTool        *tool,
 
187
                              GimpCoords      *coords,
 
188
                              GdkModifierType  state,
 
189
                              GimpDisplay     *gdisp)
 
190
{
 
191
  GimpFlipOptions *options;
 
192
  gboolean         bad_cursor = TRUE;
 
193
 
 
194
  options = GIMP_FLIP_OPTIONS (tool->tool_info->tool_options);
 
195
 
 
196
  if (gimp_image_coords_in_active_drawable (gdisp->gimage, coords))
 
197
    {
 
198
      GimpChannel *selection = gimp_image_get_mask (gdisp->gimage);
 
199
 
 
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))
 
203
        {
 
204
          bad_cursor = FALSE;
 
205
        }
 
206
    }
 
207
 
 
208
  if (bad_cursor)
 
209
    {
 
210
      gimp_tool_control_set_cursor        (tool->control, GIMP_CURSOR_BAD);
 
211
      gimp_tool_control_set_toggle_cursor (tool->control, GIMP_CURSOR_BAD);
 
212
    }
 
213
  else
 
214
    {
 
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);
 
217
    }
 
218
 
 
219
  gimp_tool_control_set_toggle (tool->control,
 
220
                                options->flip_type == GIMP_ORIENTATION_VERTICAL);
 
221
 
 
222
  GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
 
223
}
 
224
 
 
225
static TileManager *
 
226
gimp_flip_tool_transform (GimpTransformTool *trans_tool,
 
227
                          GimpItem          *active_item,
 
228
                          gboolean           mask_empty,
 
229
                          GimpDisplay       *gdisp)
 
230
{
 
231
  GimpTransformOptions *tr_options;
 
232
  GimpFlipOptions      *options;
 
233
  GimpContext          *context;
 
234
  gdouble               axis = 0.0;
 
235
  TileManager          *ret  = NULL;
 
236
 
 
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);
 
240
 
 
241
  switch (options->flip_type)
 
242
    {
 
243
    case GIMP_ORIENTATION_HORIZONTAL:
 
244
      axis = ((gdouble) trans_tool->x1 +
 
245
              (gdouble) (trans_tool->x2 - trans_tool->x1) / 2.0);
 
246
      break;
 
247
 
 
248
    case GIMP_ORIENTATION_VERTICAL:
 
249
      axis = ((gdouble) trans_tool->y1 +
 
250
              (gdouble) (trans_tool->y2 - trans_tool->y1) / 2.0);
 
251
      break;
 
252
 
 
253
    default:
 
254
      break;
 
255
    }
 
256
 
 
257
  if (gimp_item_get_linked (active_item))
 
258
    gimp_item_linked_flip (active_item, context, options->flip_type, axis,
 
259
                           FALSE);
 
260
 
 
261
  if (GIMP_IS_LAYER (active_item) &&
 
262
      gimp_layer_get_mask (GIMP_LAYER (active_item)) &&
 
263
      mask_empty)
 
264
    {
 
265
      GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (active_item));
 
266
 
 
267
      gimp_item_flip (GIMP_ITEM (mask), context,
 
268
                      options->flip_type, axis, FALSE);
 
269
    }
 
270
 
 
271
  switch (tr_options->type)
 
272
    {
 
273
    case GIMP_TRANSFORM_TYPE_LAYER:
 
274
    case GIMP_TRANSFORM_TYPE_SELECTION:
 
275
      ret = gimp_drawable_transform_tiles_flip (GIMP_DRAWABLE (active_item),
 
276
                                                context,
 
277
                                                trans_tool->original,
 
278
                                                options->flip_type, axis,
 
279
                                                FALSE);
 
280
      break;
 
281
 
 
282
    case GIMP_TRANSFORM_TYPE_PATH:
 
283
      gimp_item_flip (active_item, context, options->flip_type, axis, FALSE);
 
284
      break;
 
285
    }
 
286
 
 
287
  return ret;
 
288
}