drawable-commands.c 5.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * 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 "libgimpwidgets/gimpwidgets.h"

Michael Natterer's avatar
Michael Natterer committed
25
#include "actions-types.h"
26 27 28 29 30

#include "core/gimp.h"
#include "core/gimpdrawable.h"
#include "core/gimpdrawable-desaturate.h"
#include "core/gimpdrawable-equalize.h"
31
#include "core/gimpdrawable-invert.h"
32
#include "core/gimpimage.h"
33 34
#include "core/gimpimage-undo.h"
#include "core/gimpitem-linked.h"
35

36
#include "dialogs/offset-dialog.h"
37

38
#include "actions.h"
39 40
#include "drawable-commands.h"

41
#include "gimp-intl.h"
42 43 44 45 46


/*  public functions  */

void
47
drawable_desaturate_cmd_callback (GtkAction *action,
48 49 50
                                  gpointer   data)
{
  GimpImage    *gimage;
51 52
  GimpDrawable *drawable;
  return_if_no_drawable (gimage, drawable, data);
53

54
  if (! gimp_drawable_is_rgb (drawable))
55
    {
56
      g_message (_("Desaturate operates only on RGB color layers."));
57 58 59
      return;
    }

60
  gimp_drawable_desaturate (drawable);
61
  gimp_image_flush (gimage);
62 63 64
}

void
65
drawable_invert_cmd_callback (GtkAction *action,
66 67 68
                              gpointer   data)
{
  GimpImage    *gimage;
69 70
  GimpDrawable *drawable;
  return_if_no_drawable (gimage, drawable, data);
71

72
  if (gimp_drawable_is_indexed (drawable))
73
    {
74
      g_message (_("Invert does not operate on indexed layers."));
75 76 77
      return;
    }

78
  gimp_drawable_invert (drawable);
79
  gimp_image_flush (gimage);
80 81 82
}

void
83
drawable_equalize_cmd_callback (GtkAction *action,
84 85 86
                                gpointer   data)
{
  GimpImage    *gimage;
87 88
  GimpDrawable *drawable;
  return_if_no_drawable (gimage, drawable, data);
89

90
  if (gimp_drawable_is_indexed (drawable))
91
    {
92
      g_message (_("Equalize does not operate on indexed layers."));
93 94 95
      return;
    }

96
  gimp_drawable_equalize (drawable, TRUE);
97
  gimp_image_flush (gimage);
98 99
}

100
void
101 102 103
drawable_flip_cmd_callback (GtkAction *action,
                            gint       value,
                            gpointer   data)
104 105
{
  GimpImage    *gimage;
106
  GimpDrawable *drawable;
107
  GimpItem     *item;
108
  GimpContext  *context;
109 110
  gint          off_x, off_y;
  gdouble       axis = 0.0;
111 112
  return_if_no_drawable (gimage, drawable, data);
  return_if_no_context (context, data);
113

114
  item = GIMP_ITEM (drawable);
115 116 117

  gimp_item_offsets (item, &off_x, &off_y);

118
  switch ((GimpOrientationType) value)
119 120 121 122 123 124 125 126 127 128 129 130 131
    {
    case GIMP_ORIENTATION_HORIZONTAL:
      axis = ((gdouble) off_x + (gdouble) gimp_item_width (item) / 2.0);
      break;

    case GIMP_ORIENTATION_VERTICAL:
      axis = ((gdouble) off_y + (gdouble) gimp_item_height (item) / 2.0);
      break;

    default:
      break;
    }

132 133 134 135
  if (gimp_item_get_linked (item))
    gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_TRANSFORM,
                                 _("Flip Layer"));

136
  gimp_item_flip (item, context, (GimpOrientationType) value, axis, FALSE);
137 138 139

  if (gimp_item_get_linked (item))
    {
140 141
      gimp_item_linked_flip (item, context, (GimpOrientationType) action, axis,
                             FALSE);
142 143 144
      gimp_image_undo_group_end (gimage);
    }

145 146 147
  gimp_image_flush (gimage);
}

148
void
149 150 151
drawable_rotate_cmd_callback (GtkAction *action,
                              gint       value,
                              gpointer   data)
152 153
{
  GimpImage    *gimage;
154
  GimpDrawable *drawable;
155
  GimpContext  *context;
156
  GimpItem     *item;
157 158
  gint          off_x, off_y;
  gdouble       center_x, center_y;
159 160
  return_if_no_drawable (gimage, drawable, data);
  return_if_no_context (context, data);
161

162
  item = GIMP_ITEM (drawable);
163 164 165 166 167 168

  gimp_item_offsets (item, &off_x, &off_y);

  center_x = ((gdouble) off_x + (gdouble) gimp_item_width  (item) / 2.0);
  center_y = ((gdouble) off_y + (gdouble) gimp_item_height (item) / 2.0);

169 170 171 172
  if (gimp_item_get_linked (item))
    gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_TRANSFORM,
                                 _("Rotate Layer"));

173
  gimp_item_rotate (item, context, (GimpRotationType) value,
174
                    center_x, center_y, FALSE);
175 176 177

  if (gimp_item_get_linked (item))
    {
178
      gimp_item_linked_rotate (item, context, (GimpRotationType) value,
179 180 181 182
                               center_x, center_y, FALSE);
      gimp_image_undo_group_end (gimage);
    }

183 184 185
  gimp_image_flush (gimage);
}

186
void
187
drawable_offset_cmd_callback (GtkAction *action,
188 189 190
                              gpointer   data)
{
  GimpImage    *gimage;
191
  GimpDrawable *drawable;
192
  GtkWidget    *widget;
193
  GtkWidget    *dialog;
194
  return_if_no_drawable (gimage, drawable, data);
195
  return_if_no_widget (widget, data);
196

197 198
  dialog = offset_dialog_new (drawable, widget);
  gtk_widget_show (dialog);
199
}