1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2005 Sven Neumann <sven@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
#include "libgimpcolor/gimpcolor.h"
29
#include "libgimpwidgets/gimpwidgets.h"
31
#include "widgets-types.h"
33
#include "core/gimpcontext.h"
34
#include "core/gimpmarshal.h"
37
#include "gimpfgbgview.h"
47
static void gimp_fg_bg_view_set_property (GObject *object,
51
static void gimp_fg_bg_view_get_property (GObject *object,
56
static void gimp_fg_bg_view_destroy (GtkObject *object);
57
static gboolean gimp_fg_bg_view_expose (GtkWidget *widget,
58
GdkEventExpose *eevent);
61
G_DEFINE_TYPE (GimpFgBgView, gimp_fg_bg_view, GTK_TYPE_DRAWING_AREA)
63
#define parent_class gimp_fg_bg_view_parent_class
67
gimp_fg_bg_view_class_init (GimpFgBgViewClass *klass)
69
GObjectClass *object_class = G_OBJECT_CLASS (klass);
70
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
71
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
73
object_class->set_property = gimp_fg_bg_view_set_property;
74
object_class->get_property = gimp_fg_bg_view_get_property;
76
gtk_object_class->destroy = gimp_fg_bg_view_destroy;
78
widget_class->expose_event = gimp_fg_bg_view_expose;
80
g_object_class_install_property (object_class, PROP_CONTEXT,
81
g_param_spec_object ("context",
84
GIMP_PARAM_READWRITE));
88
gimp_fg_bg_view_init (GimpFgBgView *view)
94
gimp_fg_bg_view_set_property (GObject *object,
99
GimpFgBgView *view = GIMP_FG_BG_VIEW (object);
104
gimp_fg_bg_view_set_context (view, g_value_get_object (value));
107
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
113
gimp_fg_bg_view_get_property (GObject *object,
118
GimpFgBgView *view = GIMP_FG_BG_VIEW (object);
123
g_value_set_object (value, view->context);
126
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
132
gimp_fg_bg_view_destroy (GtkObject *object)
134
GimpFgBgView *view = GIMP_FG_BG_VIEW (object);
137
gimp_fg_bg_view_set_context (view, NULL);
139
if (view->render_buf)
141
g_free (view->render_buf);
142
view->render_buf = NULL;
143
view->render_buf_size = 0;
146
GTK_OBJECT_CLASS (parent_class)->destroy (object);
150
gimp_fg_bg_view_draw_rect (GimpFgBgView *view,
151
GdkDrawable *drawable,
157
const GimpRGB *color)
164
if (! (width > 0 && height > 0))
167
gimp_rgb_get_uchar (color, &r, &g, &b);
169
rowstride = 3 * ((width + 3) & -4);
171
if (! view->render_buf || view->render_buf_size < height * rowstride)
173
view->render_buf_size = rowstride * height;
175
g_free (view->render_buf);
176
view->render_buf = g_malloc (view->render_buf_size);
179
bp = view->render_buf;
180
for (xx = 0; xx < width; xx++)
187
bp = view->render_buf;
189
for (yy = 1; yy < height; yy++)
192
memcpy (bp, view->render_buf, rowstride);
195
gdk_draw_rgb_image (drawable, gc, x, y, width, height,
202
gimp_fg_bg_view_expose (GtkWidget *widget,
203
GdkEventExpose *eevent)
205
GimpFgBgView *view = GIMP_FG_BG_VIEW (widget);
210
if (! GTK_WIDGET_DRAWABLE (widget))
213
width = widget->allocation.width;
214
height = widget->allocation.height;
216
rect_w = width * 3 / 4;
217
rect_h = height * 3 / 4;
219
/* draw the background area */
223
gimp_context_get_background (view->context, &color);
224
gimp_fg_bg_view_draw_rect (view,
226
widget->style->fg_gc[0],
227
width - rect_w + 1, height - rect_h + 1,
228
rect_w - 2, rect_h - 2,
232
gtk_paint_shadow (widget->style, widget->window, GTK_STATE_NORMAL,
235
width - rect_w, height - rect_h, rect_w, rect_h);
237
/* draw the foreground area */
241
gimp_context_get_foreground (view->context, &color);
242
gimp_fg_bg_view_draw_rect (view,
244
widget->style->fg_gc[0],
246
rect_w - 2, rect_h - 2,
250
gtk_paint_shadow (widget->style, widget->window, GTK_STATE_NORMAL,
253
0, 0, rect_w, rect_h);
258
/* public functions */
261
gimp_fg_bg_view_new (GimpContext *context)
263
g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
265
return g_object_new (GIMP_TYPE_FG_BG_VIEW,
271
gimp_fg_bg_view_set_context (GimpFgBgView *view,
272
GimpContext *context)
274
g_return_if_fail (GIMP_IS_FG_BG_VIEW (view));
275
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
277
if (context == view->context)
282
g_signal_handlers_disconnect_by_func (view->context,
283
gtk_widget_queue_draw,
285
g_object_unref (view->context);
286
view->context = NULL;
289
view->context = context;
293
g_object_ref (context);
295
g_signal_connect_swapped (context, "foreground-changed",
296
G_CALLBACK (gtk_widget_queue_draw),
298
g_signal_connect_swapped (context, "background-changed",
299
G_CALLBACK (gtk_widget_queue_draw),
303
g_object_notify (G_OBJECT (view), "context");