quick-mask-commands.c 4.37 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * 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 3 of the License, or
7 8 9 10 11 12 13 14
 * (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
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17 18 19

#include "config.h"

20
#include <gegl.h>
Sven Neumann's avatar
Sven Neumann committed
21 22
#include <gtk/gtk.h>

23
#include "libgimpcolor/gimpcolor.h"
24
#include "libgimpwidgets/gimpwidgets.h"
25

Michael Natterer's avatar
Michael Natterer committed
26
#include "actions-types.h"
Sven Neumann's avatar
Sven Neumann committed
27

28
#include "core/gimp.h"
29 30
#include "core/gimpchannel.h"
#include "core/gimpimage.h"
31
#include "core/gimpimage-quick-mask.h"
32

33
#include "widgets/gimphelp-ids.h"
34

35
#include "dialogs/channel-options-dialog.h"
Michael Natterer's avatar
Michael Natterer committed
36

37
#include "actions.h"
38
#include "quick-mask-commands.h"
39

40
#include "gimp-intl.h"
Sven Neumann's avatar
Sven Neumann committed
41

42

Michael Natterer's avatar
Michael Natterer committed
43 44
/*  local function prototypes  */

45 46 47
static void   quick_mask_configure_response (GtkWidget            *widget,
                                             gint                  response_id,
                                             ChannelOptionsDialog *options);
48 49 50 51 52


/*  public functionss */

void
53 54
quick_mask_toggle_cmd_callback (GtkAction *action,
                                gpointer   data)
55
{
56
  GimpImage *image;
57
  gboolean   active;
58
  return_if_no_image (image, data);
59

60 61
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

62
  if (active != gimp_image_get_quick_mask_state (image))
63
    {
64 65
      gimp_image_set_quick_mask_state (image, active);
      gimp_image_flush (image);
66
    }
67 68
}

69
void
70 71 72
quick_mask_invert_cmd_callback (GtkAction *action,
                                GtkAction *current,
                                gpointer   data)
73
{
74
  GimpImage *image;
75
  gint       value;
76
  return_if_no_image (image, data);
77

78
  value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
79

80
  if (value != gimp_image_get_quick_mask_inverted (image))
81
    {
82 83
      gimp_image_quick_mask_invert (image);
      gimp_image_flush (image);
84 85
    }
}
86

87
void
88 89
quick_mask_configure_cmd_callback (GtkAction *action,
                                   gpointer   data)
90
{
91
  ChannelOptionsDialog *options;
92
  GimpImage            *image;
93 94
  GtkWidget            *widget;
  GimpRGB               color;
95
  return_if_no_image (image, data);
96 97
  return_if_no_widget (widget, data);

98
  gimp_image_get_quick_mask_color (image, &color);
99

100
  options = channel_options_dialog_new (image, NULL,
101 102
                                        action_data_get_context (data),
                                        widget,
103
                                       _("Quick Mask Attributes"),
104 105
                                        "gimp-quick-mask-edit",
                                        GIMP_STOCK_QUICK_MASK_ON,
106
                                        _("Edit Quick Mask Attributes"),
107
                                        GIMP_HELP_QUICK_MASK_EDIT,
108 109 110
                                        &color,
                                        NULL,
                                         _("Edit Quick Mask Color"),
111
                                        _("_Mask opacity:"),
112
                                        FALSE);
113 114

  g_signal_connect (options->dialog, "response",
115
                    G_CALLBACK (quick_mask_configure_response),
116
                    options);
117

118
  gtk_widget_show (options->dialog);
119
}
Michael Natterer's avatar
Michael Natterer committed
120

Michael Natterer's avatar
Michael Natterer committed
121 122 123

/*  private functions  */

124
static void
125 126 127
quick_mask_configure_response (GtkWidget            *widget,
                               gint                  response_id,
                               ChannelOptionsDialog *options)
128
{
129 130
  if (response_id == GTK_RESPONSE_OK)
    {
131 132
      GimpRGB old_color;
      GimpRGB new_color;
133

134
      gimp_image_get_quick_mask_color (options->image, &old_color);
135 136
      gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
                                   &new_color);
137

138 139
      if (gimp_rgba_distance (&old_color, &new_color) > 0.0001)
        {
140
          gimp_image_set_quick_mask_color (options->image, &new_color);
141

142
          gimp_image_flush (options->image);
143
        }
144
    }
145

146
  gtk_widget_destroy (options->dialog);
Michael Natterer's avatar
Michael Natterer committed
147
}