gimptoolbox-indicator-area.c 9.04 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

Sven Neumann's avatar
Sven Neumann committed
18 19
#include "config.h"

20 21
#include <stdlib.h>
#include <string.h>
22

23
#include <gegl.h>
24
#include <gtk/gtk.h>
Sven Neumann's avatar
Sven Neumann committed
25

26 27
#include "libgimpwidgets/gimpwidgets.h"

28
#include "widgets-types.h"
Sven Neumann's avatar
Sven Neumann committed
29

30
#include "core/gimp.h"
31 32 33 34 35
#include "core/gimpbrush.h"
#include "core/gimpcontext.h"
#include "core/gimpgradient.h"
#include "core/gimppattern.h"

36
#include "gimpdnd.h"
37
#include "gimpview.h"
38 39
#include "gimptoolbox.h"
#include "gimptoolbox-indicator-area.h"
40
#include "gimpwidgets-utils.h"
41
#include "gimpwindowstrategy.h"
42

43
#include "gimp-intl.h"
44

45

46 47 48
#define CELL_SIZE        24  /*  The size of the previews                  */
#define GRAD_CELL_WIDTH  52  /*  The width of the gradient preview         */
#define GRAD_CELL_HEIGHT 12  /*  The height of the gradient preview        */
49
#define CELL_SPACING      2  /*  How much between brush and pattern cells  */
50

51

52
static void
53 54
brush_preview_clicked (GtkWidget       *widget,
                       GdkModifierType  state,
55
                       GimpToolbox     *toolbox)
56
{
57 58 59 60 61 62
  GimpContext *context = gimp_toolbox_get_context (toolbox);

  gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy (context->gimp)),
                                             context->gimp,
                                             gimp_dock_get_dialog_factory (GIMP_DOCK (toolbox)),
                                             gtk_widget_get_screen (widget),
63
                                             gimp_widget_get_monitor (widget),
64
                                             "gimp-brush-grid|gimp-brush-list");
65 66
}

67
static void
68
brush_preview_drop_brush (GtkWidget    *widget,
69 70
                          gint          x,
                          gint          y,
71 72
                          GimpViewable *viewable,
                          gpointer      data)
73
{
74
  GimpContext *context = GIMP_CONTEXT (data);
75 76

  gimp_context_set_brush (context, GIMP_BRUSH (viewable));
77 78
}

79
static void
80 81
pattern_preview_clicked (GtkWidget       *widget,
                         GdkModifierType  state,
82
                         GimpToolbox     *toolbox)
83
{
84 85 86 87 88 89
  GimpContext *context = gimp_toolbox_get_context (toolbox);

  gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy (context->gimp)),
                                             context->gimp,
                                             gimp_dock_get_dialog_factory (GIMP_DOCK (toolbox)),
                                             gtk_widget_get_screen (widget),
90
                                             gimp_widget_get_monitor (widget),
91
                                             "gimp-pattern-grid|gimp-pattern-list");
92 93
}

94
static void
95
pattern_preview_drop_pattern (GtkWidget    *widget,
96 97
                              gint          x,
                              gint          y,
98 99
                              GimpViewable *viewable,
                              gpointer      data)
100
{
101
  GimpContext *context = GIMP_CONTEXT (data);
102 103

  gimp_context_set_pattern (context, GIMP_PATTERN (viewable));
104 105
}

106
static void
107 108
gradient_preview_clicked (GtkWidget       *widget,
                          GdkModifierType  state,
109
                          GimpToolbox     *toolbox)
110
{
111 112 113 114 115 116
  GimpContext *context = gimp_toolbox_get_context (toolbox);

  gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy (context->gimp)),
                                             context->gimp,
                                             gimp_dock_get_dialog_factory (GIMP_DOCK (toolbox)),
                                             gtk_widget_get_screen (widget),
117
                                             gimp_widget_get_monitor (widget),
118
                                             "gimp-gradient-list|gimp-gradient-grid");
119 120 121
}

static void
122
gradient_preview_drop_gradient (GtkWidget    *widget,
123 124
                                gint          x,
                                gint          y,
125 126
                                GimpViewable *viewable,
                                gpointer      data)
127
{
128
  GimpContext *context = GIMP_CONTEXT (data);
129 130

  gimp_context_set_gradient (context, GIMP_GRADIENT (viewable));
131 132
}

133 134 135

/*  public functions  */

136
GtkWidget *
137
gimp_toolbox_indicator_area_create (GimpToolbox *toolbox)
138
{
139 140
  GimpContext *context;
  GtkWidget   *indicator_table;
141 142 143
  GtkWidget   *brush_view;
  GtkWidget   *pattern_view;
  GtkWidget   *gradient_view;
144 145

  g_return_val_if_fail (GIMP_IS_TOOLBOX (toolbox), NULL);
146

147
  context = gimp_toolbox_get_context (toolbox);
148

149
  indicator_table = gtk_table_new (2, 2, FALSE);
150 151
  gtk_table_set_row_spacings (GTK_TABLE (indicator_table), CELL_SPACING);
  gtk_table_set_col_spacings (GTK_TABLE (indicator_table), CELL_SPACING);
152

153
  /*  brush view  */
154

155
  brush_view =
156 157
    gimp_view_new_full_by_types (context,
                                 GIMP_TYPE_VIEW, GIMP_TYPE_BRUSH,
158
                                 CELL_SIZE, CELL_SIZE, 1,
159 160 161 162
                                 FALSE, TRUE, TRUE);
  gimp_view_set_viewable (GIMP_VIEW (brush_view),
                          GIMP_VIEWABLE (gimp_context_get_brush (context)));
  gtk_table_attach_defaults (GTK_TABLE (indicator_table), brush_view,
163
                             0, 1, 0, 1);
164
  gtk_widget_show (brush_view);
165

166
  gimp_help_set_help_data (brush_view,
167 168
                           _("The active brush.\n"
                             "Click to open the Brush Dialog."), NULL);
169

170
  g_signal_connect_object (context, "brush-changed",
171 172
                           G_CALLBACK (gimp_view_set_viewable),
                           brush_view,
173
                           G_CONNECT_SWAPPED);
174

175
  g_signal_connect (brush_view, "clicked",
176 177
                    G_CALLBACK (brush_preview_clicked),
                    toolbox);
178

179
  gimp_dnd_viewable_dest_add (brush_view,
180 181
                              GIMP_TYPE_BRUSH,
                              brush_preview_drop_brush,
182
                              context);
183

184
  /*  pattern view  */
185

186
  pattern_view =
187 188
    gimp_view_new_full_by_types (context,
                                 GIMP_TYPE_VIEW, GIMP_TYPE_PATTERN,
189
                                 CELL_SIZE, CELL_SIZE, 1,
190 191 192
                                 FALSE, TRUE, TRUE);
  gimp_view_set_viewable (GIMP_VIEW (pattern_view),
                          GIMP_VIEWABLE (gimp_context_get_pattern (context)));
193

194
  gtk_table_attach_defaults (GTK_TABLE (indicator_table), pattern_view,
195
                             1, 2, 0, 1);
196
  gtk_widget_show (pattern_view);
197

198
  gimp_help_set_help_data (pattern_view,
199 200
                           _("The active pattern.\n"
                             "Click to open the Pattern Dialog."), NULL);
201

202
  g_signal_connect_object (context, "pattern-changed",
203 204
                           G_CALLBACK (gimp_view_set_viewable),
                           pattern_view,
205
                           G_CONNECT_SWAPPED);
206

207
  g_signal_connect (pattern_view, "clicked",
208 209
                    G_CALLBACK (pattern_preview_clicked),
                    toolbox);
210

211
  gimp_dnd_viewable_dest_add (pattern_view,
212 213
                              GIMP_TYPE_PATTERN,
                              pattern_preview_drop_pattern,
214
                              context);
215

216
  /*  gradient view  */
217

218
  gradient_view =
219 220
    gimp_view_new_full_by_types (context,
                                 GIMP_TYPE_VIEW, GIMP_TYPE_GRADIENT,
221
                                 GRAD_CELL_WIDTH, GRAD_CELL_HEIGHT, 1,
222 223 224
                                 FALSE, TRUE, TRUE);
  gimp_view_set_viewable (GIMP_VIEW (gradient_view),
                          GIMP_VIEWABLE (gimp_context_get_gradient (context)));
225

226
  gtk_table_attach_defaults (GTK_TABLE (indicator_table), gradient_view,
227
                             0, 2, 1, 2);
228
  gtk_widget_show (gradient_view);
229

230
  gimp_help_set_help_data (gradient_view,
231 232
                           _("The active gradient.\n"
                             "Click to open the Gradient Dialog."), NULL);
233

234
  g_signal_connect_object (context, "gradient-changed",
235 236
                           G_CALLBACK (gimp_view_set_viewable),
                           gradient_view,
237
                           G_CONNECT_SWAPPED);
238

239
  g_signal_connect (gradient_view, "clicked",
240 241
                    G_CALLBACK (gradient_preview_clicked),
                    toolbox);
242

243
  gimp_dnd_viewable_dest_add (gradient_view,
244 245
                              GIMP_TYPE_GRADIENT,
                              gradient_preview_drop_gradient,
246
                              context);
247

248 249
  gtk_widget_show (indicator_table);

250
  return indicator_table;
251
}