1
/* The GIMP -- an image manipulation program
1
/* GIMP - The GNU Image Manipulation Program
2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
4
* This program is free software; you can redistribute it and/or modify
21
21
#include <gtk/gtk.h>
23
#include "libgimpcolor/gimpcolor.h"
23
25
#include "display-types.h"
27
#include "config/gimpdisplayconfig.h"
29
#include "core/gimp.h"
25
31
#include "widgets/gimpwidgets-utils.h"
27
33
#include "gimpcanvas.h"
30
43
/* local function prototypes */
32
static void gimp_canvas_class_init (GimpCanvasClass *klass);
33
static void gimp_canvas_init (GimpCanvas *gdisp);
34
static void gimp_canvas_realize (GtkWidget *widget);
35
static void gimp_canvas_unrealize (GtkWidget *widget);
36
static GdkGC * gimp_canvas_gc_new (GimpCanvas *canvas,
37
GimpCanvasStyle style);
40
static GtkDrawingAreaClass *parent_class = NULL;
45
static void gimp_canvas_set_property (GObject *object,
49
static void gimp_canvas_get_property (GObject *object,
54
static void gimp_canvas_realize (GtkWidget *widget);
55
static void gimp_canvas_unrealize (GtkWidget *widget);
57
static GdkGC * gimp_canvas_gc_new (GimpCanvas *canvas,
58
GimpCanvasStyle style);
61
G_DEFINE_TYPE (GimpCanvas, gimp_canvas, GTK_TYPE_DRAWING_AREA)
63
#define parent_class gimp_canvas_parent_class
42
66
static const guchar stipples[GIMP_CANVAS_NUM_STIPPLES][8] =
128
gimp_canvas_get_type (void)
130
static GType canvas_type = 0;
134
static const GTypeInfo canvas_info =
136
sizeof (GimpCanvasClass),
137
(GBaseInitFunc) NULL,
138
(GBaseFinalizeFunc) NULL,
139
(GClassInitFunc) gimp_canvas_class_init,
140
NULL, /* class_finalize */
141
NULL, /* class_data */
144
(GInstanceInitFunc) gimp_canvas_init,
147
canvas_type = g_type_register_static (GTK_TYPE_DRAWING_AREA,
156
152
gimp_canvas_class_init (GimpCanvasClass *klass)
154
GObjectClass *object_class = G_OBJECT_CLASS (klass);
158
155
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
160
parent_class = g_type_class_peek_parent (klass);
162
widget_class->realize = gimp_canvas_realize;
163
widget_class->unrealize = gimp_canvas_unrealize;
157
object_class->set_property = gimp_canvas_set_property;
158
object_class->get_property = gimp_canvas_get_property;
160
widget_class->realize = gimp_canvas_realize;
161
widget_class->unrealize = gimp_canvas_unrealize;
163
g_object_class_install_property (object_class, PROP_GIMP,
164
g_param_spec_object ("gimp", NULL, NULL,
166
GIMP_PARAM_READWRITE |
167
G_PARAM_CONSTRUCT_ONLY));
183
gimp_canvas_set_property (GObject *object,
188
GimpCanvas *canvas = GIMP_CANVAS (object);
193
canvas->gimp = g_value_get_object (value);
196
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
202
gimp_canvas_get_property (GObject *object,
207
GimpCanvas *canvas = GIMP_CANVAS (object);
212
g_value_set_object (value, canvas->gimp);
215
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
179
221
gimp_canvas_realize (GtkWidget *widget)
181
223
GimpCanvas *canvas = GIMP_CANVAS (widget);
232
280
case GIMP_CANVAS_STYLE_BLACK:
233
281
case GIMP_CANVAS_STYLE_WHITE:
282
case GIMP_CANVAS_STYLE_SAMPLE_POINT_NORMAL:
283
case GIMP_CANVAS_STYLE_SAMPLE_POINT_ACTIVE:
236
286
case GIMP_CANVAS_STYLE_RENDER:
238
288
values.graphics_exposures = TRUE;
291
case GIMP_CANVAS_STYLE_XOR_DOTTED:
241
292
case GIMP_CANVAS_STYLE_XOR_DASHED:
242
293
mask |= GDK_GC_LINE_STYLE;
243
294
values.line_style = GDK_LINE_ON_OFF_DASH;
246
297
case GIMP_CANVAS_STYLE_XOR:
247
298
mask |= GDK_GC_FUNCTION | GDK_GC_CAP_STYLE | GDK_GC_JOIN_STYLE;
248
values.function = GDK_INVERT;
299
values.function = GDK_XOR;
249
300
values.cap_style = GDK_CAP_NOT_LAST;
250
301
values.join_style = GDK_JOIN_MITER;
269
320
gc = gdk_gc_new_with_values (GTK_WIDGET (canvas)->window, &values, mask);
322
if (style == GIMP_CANVAS_STYLE_XOR_DOTTED)
325
gdk_gc_set_dashes (gc, 0, &one, 1);
337
case GIMP_CANVAS_STYLE_XOR_DOTTED:
338
case GIMP_CANVAS_STYLE_XOR_DASHED:
339
case GIMP_CANVAS_STYLE_XOR:
341
GimpDisplayConfig *config = GIMP_DISPLAY_CONFIG (canvas->gimp->config);
344
gimp_rgb_get_uchar (&config->xor_color, &r, &g, &b);
346
fg.red = (r << 8) | r;
347
fg.green = (g << 8) | g;
348
fg.blue = (b << 8) | b;
276
352
case GIMP_CANVAS_STYLE_WHITE:
278
354
fg.green = 0xffff;
279
355
fg.blue = 0xffff;
286
358
case GIMP_CANVAS_STYLE_BLACK:
369
453
* Return value: a new #GimpCanvas widget
372
gimp_canvas_new (void)
456
gimp_canvas_new (Gimp *gimp)
458
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
374
460
return g_object_new (GIMP_TYPE_CANVAS,
375
461
"name", "gimp-canvas",
616
703
num_segments -= 32000;
617
704
segments += 32000;
619
707
gdk_draw_segments (GTK_WIDGET (canvas)->window, canvas->gc[style],
620
708
segments, num_segments);
712
* gimp_canvas_draw_text:
713
* @canvas: a #GimpCanvas widget
714
* @style: one of the enumerated #GimpCanvasStyle's.
715
* @x: X coordinate of the left of the layout.
716
* @y: Y coordinate of the top of the layout.
717
* @format: a standard printf() format string.
718
* @Varargs: the parameters to insert into the format string.
720
* Draws a layout, in the specified style.
723
gimp_canvas_draw_text (GimpCanvas *canvas,
724
GimpCanvasStyle style,
733
if (! gimp_canvas_ensure_style (canvas, style))
736
if (! canvas->layout)
737
canvas->layout = gtk_widget_create_pango_layout (GTK_WIDGET (canvas),
740
va_start (args, format);
741
text = g_strdup_vprintf (format, args);
744
pango_layout_set_text (canvas->layout, text, -1);
747
gdk_draw_layout (GTK_WIDGET (canvas)->window, canvas->gc[style],
748
x, y, canvas->layout);
624
752
* gimp_canvas_draw_rgb:
625
753
* @canvas: a #GimpCanvas widget
626
754
* @style: one of the enumerated #GimpCanvasStyle's.
755
883
gimp_canvas_set_custom_gc (GimpCanvas *canvas,
758
889
if (canvas->gc[GIMP_CANVAS_STYLE_CUSTOM])
759
890
g_object_unref (canvas->gc[GIMP_CANVAS_STYLE_CUSTOM]);
761
892
canvas->gc[GIMP_CANVAS_STYLE_CUSTOM] = gc;