drawable-actions.c 6.77 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
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
 * 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"

#include "actions-types.h"

#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
30
#include "core/gimplayermask.h"
31 32 33 34

#include "widgets/gimpactiongroup.h"
#include "widgets/gimphelp-ids.h"

35
#include "actions.h"
36
#include "drawable-actions.h"
Michael Natterer's avatar
Michael Natterer committed
37
#include "drawable-commands.h"
38 39 40 41

#include "gimp-intl.h"


42
static const GimpActionEntry drawable_actions[] =
43 44
{
  { "drawable-desaturate", GIMP_STOCK_CONVERT_GRAYSCALE,
45 46
    N_("_Desaturate..."), NULL,
    N_("Turn colors into shades of gray"),
47 48 49 50
    G_CALLBACK (drawable_desaturate_cmd_callback),
    GIMP_HELP_LAYER_DESATURATE },

  { "drawable-equalize", NULL,
51 52
    N_("_Equalize"), NULL,
    N_("Automatic contrast enhancement"),
53 54 55
    G_CALLBACK (drawable_equalize_cmd_callback),
    GIMP_HELP_LAYER_EQUALIZE },

56
  { "drawable-invert", GIMP_STOCK_INVERT,
57 58
    N_("In_vert"), NULL,
    N_("Invert the colors"),
59 60 61
    G_CALLBACK (drawable_invert_cmd_callback),
    GIMP_HELP_LAYER_INVERT },

62
  { "drawable-levels-stretch", NULL,
63 64
    N_("_White Balance"), NULL,
    N_("Automatic white balance correction"),
65 66 67
    G_CALLBACK (drawable_levels_stretch_cmd_callback),
    GIMP_HELP_LAYER_WHITE_BALANCE},

68
  { "drawable-offset", NULL,
69 70
    N_("_Offset..."), "<control><shift>O",
    N_("Shift the pixels, optionally wrapping them at the borders"),
71 72 73 74
    G_CALLBACK (drawable_offset_cmd_callback),
    GIMP_HELP_LAYER_OFFSET }
};

75
static const GimpToggleActionEntry drawable_toggle_actions[] =
76 77
{
  { "drawable-linked", GIMP_STOCK_LINKED,
78 79
    N_("_Linked"), NULL,
    N_("Toggle the linked state"),
80 81
    G_CALLBACK (drawable_linked_cmd_callback),
    FALSE,
82
    GIMP_HELP_LAYER_LINKED },
Michael Natterer's avatar
Michael Natterer committed
83

84
  { "drawable-visible", GIMP_STOCK_VISIBLE,
85 86
    N_("_Visible"), NULL,
    N_("Toggle visibility"),
87 88 89
    G_CALLBACK (drawable_visible_cmd_callback),
    FALSE,
    GIMP_HELP_LAYER_VISIBLE }
90 91
};

92
static const GimpEnumActionEntry drawable_flip_actions[] =
93 94
{
  { "drawable-flip-horizontal", GIMP_STOCK_FLIP_HORIZONTAL,
95 96
    N_("Flip _Horizontally"), NULL,
    N_("Flip horizontally"),
97
    GIMP_ORIENTATION_HORIZONTAL, FALSE,
98 99 100
    GIMP_HELP_LAYER_FLIP_HORIZONTAL },

  { "drawable-flip-vertical", GIMP_STOCK_FLIP_VERTICAL,
101 102
    N_("Flip _Vertically"), NULL,
    N_("Flip vertically"),
103
    GIMP_ORIENTATION_VERTICAL, FALSE,
104 105 106
    GIMP_HELP_LAYER_FLIP_VERTICAL }
};

107
static const GimpEnumActionEntry drawable_rotate_actions[] =
108 109
{
  { "drawable-rotate-90", GIMP_STOCK_ROTATE_90,
110 111
    N_("Rotate 90° _clockwise"), NULL,
    N_("Rotate 90 degrees to the right"),
112
    GIMP_ROTATE_90, FALSE,
113 114 115
    GIMP_HELP_LAYER_ROTATE_90 },

  { "drawable-rotate-180", GIMP_STOCK_ROTATE_180,
116 117
    N_("Rotate _180°"), NULL,
    N_("Turn upside-down"),
118
    GIMP_ROTATE_180, FALSE,
119 120 121
    GIMP_HELP_LAYER_ROTATE_180 },

  { "drawable-rotate-270", GIMP_STOCK_ROTATE_270,
122 123
    N_("Rotate 90° counter-clock_wise"), NULL,
    N_("Rotate 90 degrees to the left"),
124
    GIMP_ROTATE_270, FALSE,
125 126 127 128 129
    GIMP_HELP_LAYER_ROTATE_270 }
};


void
130
drawable_actions_setup (GimpActionGroup *group)
131 132 133
{
  gimp_action_group_add_actions (group,
                                 drawable_actions,
134
                                 G_N_ELEMENTS (drawable_actions));
135

136 137 138 139
  gimp_action_group_add_toggle_actions (group,
                                        drawable_toggle_actions,
                                        G_N_ELEMENTS (drawable_toggle_actions));

140 141 142
  gimp_action_group_add_enum_actions (group,
                                      drawable_flip_actions,
                                      G_N_ELEMENTS (drawable_flip_actions),
143
                                      G_CALLBACK (drawable_flip_cmd_callback));
144 145 146 147

  gimp_action_group_add_enum_actions (group,
                                      drawable_rotate_actions,
                                      G_N_ELEMENTS (drawable_rotate_actions),
148
                                      G_CALLBACK (drawable_rotate_cmd_callback));
149 150 151 152 153 154
}

void
drawable_actions_update (GimpActionGroup *group,
                         gpointer         data)
{
155
  GimpImage    *image;
156 157 158 159
  GimpDrawable *drawable   = NULL;
  gboolean      is_rgb     = FALSE;
  gboolean      is_gray    = FALSE;
  gboolean      is_indexed = FALSE;
160 161
  gboolean      visible    = FALSE;
  gboolean      linked     = FALSE;
162

163
  image = action_data_get_image (data);
164

165
  if (image)
166
    {
167
      drawable = gimp_image_get_active_drawable (image);
168 169 170

      if (drawable)
        {
171
          GimpImageType  drawable_type = gimp_drawable_type (drawable);
172
          GimpItem      *item;
173

174 175
          is_rgb     = GIMP_IMAGE_TYPE_IS_RGB     (drawable_type);
          is_gray    = GIMP_IMAGE_TYPE_IS_GRAY    (drawable_type);
176
          is_indexed = GIMP_IMAGE_TYPE_IS_INDEXED (drawable_type);
177

178 179 180 181 182
          if (GIMP_IS_LAYER_MASK (drawable))
            item = GIMP_ITEM (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)));
          else
            item = GIMP_ITEM (drawable);

183 184
          visible = gimp_item_get_visible (item);
          linked  = gimp_item_get_linked  (item);
185 186 187 188 189
        }
    }

#define SET_SENSITIVE(action,condition) \
        gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
190 191
#define SET_ACTIVE(action,condition) \
        gimp_action_group_set_action_active (group, action, (condition) != 0)
192

193 194 195 196 197
  SET_SENSITIVE ("drawable-desaturate",     drawable &&   is_rgb);
  SET_SENSITIVE ("drawable-equalize",       drawable && ! is_indexed);
  SET_SENSITIVE ("drawable-invert",         drawable && ! is_indexed);
  SET_SENSITIVE ("drawable-levels-stretch", drawable &&   is_rgb);
  SET_SENSITIVE ("drawable-offset",         drawable);
198

199 200 201 202 203 204
  SET_SENSITIVE ("drawable-visible", drawable);
  SET_SENSITIVE ("drawable-linked",  drawable);

  SET_ACTIVE ("drawable-visible", visible);
  SET_ACTIVE ("drawable-linked",  linked);

205 206 207 208 209 210 211 212
  SET_SENSITIVE ("drawable-flip-horizontal", drawable);
  SET_SENSITIVE ("drawable-flip-vertical",   drawable);

  SET_SENSITIVE ("drawable-rotate-90",  drawable);
  SET_SENSITIVE ("drawable-rotate-180", drawable);
  SET_SENSITIVE ("drawable-rotate-270", drawable);

#undef SET_SENSITIVE
213
#undef SET_ACTIVE
214
}