~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/display/gimpcanvas.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
20
20
 
21
21
#include <gtk/gtk.h>
22
22
 
 
23
#include "libgimpcolor/gimpcolor.h"
 
24
 
23
25
#include "display-types.h"
24
26
 
 
27
#include "config/gimpdisplayconfig.h"
 
28
 
 
29
#include "core/gimp.h"
 
30
 
25
31
#include "widgets/gimpwidgets-utils.h"
26
32
 
27
33
#include "gimpcanvas.h"
28
34
 
29
35
 
 
36
enum
 
37
{
 
38
  PROP_0,
 
39
  PROP_GIMP
 
40
};
 
41
 
 
42
 
30
43
/*  local function prototypes  */
31
44
 
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);
38
 
 
39
 
 
40
 
static GtkDrawingAreaClass *parent_class = NULL;
 
45
static void    gimp_canvas_set_property (GObject         *object,
 
46
                                         guint            property_id,
 
47
                                         const GValue    *value,
 
48
                                         GParamSpec      *pspec);
 
49
static void    gimp_canvas_get_property (GObject         *object,
 
50
                                         guint            property_id,
 
51
                                         GValue          *value,
 
52
                                         GParamSpec      *pspec);
 
53
 
 
54
static void    gimp_canvas_realize      (GtkWidget       *widget);
 
55
static void    gimp_canvas_unrealize    (GtkWidget       *widget);
 
56
 
 
57
static GdkGC * gimp_canvas_gc_new       (GimpCanvas      *canvas,
 
58
                                         GimpCanvasStyle  style);
 
59
 
 
60
 
 
61
G_DEFINE_TYPE (GimpCanvas, gimp_canvas, GTK_TYPE_DRAWING_AREA)
 
62
 
 
63
#define parent_class gimp_canvas_parent_class
 
64
 
41
65
 
42
66
static const guchar stipples[GIMP_CANVAS_NUM_STIPPLES][8] =
43
67
{
124
148
};
125
149
 
126
150
 
127
 
GType
128
 
gimp_canvas_get_type (void)
129
 
{
130
 
  static GType canvas_type = 0;
131
 
 
132
 
  if (! canvas_type)
133
 
    {
134
 
      static const GTypeInfo canvas_info =
135
 
      {
136
 
        sizeof (GimpCanvasClass),
137
 
        (GBaseInitFunc) NULL,
138
 
        (GBaseFinalizeFunc) NULL,
139
 
        (GClassInitFunc) gimp_canvas_class_init,
140
 
        NULL,           /* class_finalize */
141
 
        NULL,           /* class_data     */
142
 
        sizeof (GimpCanvas),
143
 
        0,              /* n_preallocs    */
144
 
        (GInstanceInitFunc) gimp_canvas_init,
145
 
      };
146
 
 
147
 
      canvas_type = g_type_register_static (GTK_TYPE_DRAWING_AREA,
148
 
                                            "GimpCanvas",
149
 
                                            &canvas_info, 0);
150
 
    }
151
 
 
152
 
  return canvas_type;
153
 
}
154
 
 
155
151
static void
156
152
gimp_canvas_class_init (GimpCanvasClass *klass)
157
153
{
 
154
  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
158
155
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
159
156
 
160
 
  parent_class = g_type_class_peek_parent (klass);
161
 
 
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;
 
159
 
 
160
  widget_class->realize      = gimp_canvas_realize;
 
161
  widget_class->unrealize    = gimp_canvas_unrealize;
 
162
 
 
163
  g_object_class_install_property (object_class, PROP_GIMP,
 
164
                                   g_param_spec_object ("gimp", NULL, NULL,
 
165
                                                        GIMP_TYPE_GIMP,
 
166
                                                        GIMP_PARAM_READWRITE |
 
167
                                                        G_PARAM_CONSTRUCT_ONLY));
164
168
}
165
169
 
166
170
static void
176
180
}
177
181
 
178
182
static void
 
183
gimp_canvas_set_property (GObject      *object,
 
184
                           guint         property_id,
 
185
                           const GValue *value,
 
186
                           GParamSpec   *pspec)
 
187
{
 
188
  GimpCanvas *canvas = GIMP_CANVAS (object);
 
189
 
 
190
  switch (property_id)
 
191
    {
 
192
    case PROP_GIMP:
 
193
      canvas->gimp = g_value_get_object (value);
 
194
      break;
 
195
    default:
 
196
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
197
      break;
 
198
    }
 
199
}
 
200
 
 
201
static void
 
202
gimp_canvas_get_property (GObject    *object,
 
203
                          guint       property_id,
 
204
                          GValue     *value,
 
205
                          GParamSpec *pspec)
 
206
{
 
207
  GimpCanvas *canvas = GIMP_CANVAS (object);
 
208
 
 
209
  switch (property_id)
 
210
    {
 
211
    case PROP_GIMP:
 
212
      g_value_set_object (value, canvas->gimp);
 
213
      break;
 
214
    default:
 
215
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
216
      break;
 
217
    }
 
218
}
 
219
 
 
220
static void
179
221
gimp_canvas_realize (GtkWidget *widget)
180
222
{
181
223
  GimpCanvas *canvas = GIMP_CANVAS (widget);
211
253
        }
212
254
    }
213
255
 
 
256
  if (canvas->layout)
 
257
    {
 
258
      g_object_unref (canvas->layout);
 
259
      canvas->layout = NULL;
 
260
    }
 
261
 
214
262
  GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
215
263
}
216
264
 
231
279
    {
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:
234
284
      break;
235
285
 
236
286
    case GIMP_CANVAS_STYLE_RENDER:
238
288
      values.graphics_exposures = TRUE;
239
289
      break;
240
290
 
 
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;
245
296
 
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;
251
302
      break;
268
319
 
269
320
  gc = gdk_gc_new_with_values (GTK_WIDGET (canvas)->window, &values, mask);
270
321
 
 
322
  if (style == GIMP_CANVAS_STYLE_XOR_DOTTED)
 
323
    {
 
324
      gint8 one = 1;
 
325
      gdk_gc_set_dashes (gc, 0, &one, 1);
 
326
    }
 
327
 
 
328
  bg.red   = 0x0;
 
329
  bg.green = 0x0;
 
330
  bg.blue  = 0x0;
 
331
 
271
332
  switch (style)
272
333
    {
273
334
    default:
274
335
      return gc;
275
336
 
 
337
    case GIMP_CANVAS_STYLE_XOR_DOTTED:
 
338
    case GIMP_CANVAS_STYLE_XOR_DASHED:
 
339
    case GIMP_CANVAS_STYLE_XOR:
 
340
      {
 
341
        GimpDisplayConfig *config = GIMP_DISPLAY_CONFIG (canvas->gimp->config);
 
342
        guchar             r, g, b;
 
343
 
 
344
        gimp_rgb_get_uchar (&config->xor_color, &r, &g, &b);
 
345
 
 
346
        fg.red   = (r << 8) | r;
 
347
        fg.green = (g << 8) | g;
 
348
        fg.blue  = (b << 8) | b;
 
349
      }
 
350
      break;
 
351
 
276
352
    case GIMP_CANVAS_STYLE_WHITE:
277
353
      fg.red   = 0xffff;
278
354
      fg.green = 0xffff;
279
355
      fg.blue  = 0xffff;
280
 
 
281
 
      bg.red   = 0x0;
282
 
      bg.green = 0x0;
283
 
      bg.blue  = 0x0;
284
356
      break;
285
357
 
286
358
    case GIMP_CANVAS_STYLE_BLACK:
333
405
      bg.green = 0x0;
334
406
      bg.blue  = 0x0;
335
407
      break;
 
408
 
 
409
    case GIMP_CANVAS_STYLE_SAMPLE_POINT_NORMAL:
 
410
      fg.red   = 0x0;
 
411
      fg.green = 0x7f7f;
 
412
      fg.blue  = 0xffff;
 
413
      break;
 
414
 
 
415
    case GIMP_CANVAS_STYLE_SAMPLE_POINT_ACTIVE:
 
416
      fg.red   = 0xffff;
 
417
      fg.green = 0x0;
 
418
      fg.blue  = 0x0;
 
419
      break;
336
420
    }
337
421
 
338
422
  gdk_gc_set_rgb_fg_color (gc, &fg);
369
453
 * Return value: a new #GimpCanvas widget
370
454
 **/
371
455
GtkWidget *
372
 
gimp_canvas_new (void)
 
456
gimp_canvas_new (Gimp *gimp)
373
457
{
 
458
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
459
 
374
460
  return g_object_new (GIMP_TYPE_CANVAS,
375
461
                       "name", "gimp-canvas",
 
462
                       "gimp", gimp,
376
463
                       NULL);
377
464
}
378
465
 
616
703
      num_segments -= 32000;
617
704
      segments     += 32000;
618
705
    }
 
706
 
619
707
  gdk_draw_segments (GTK_WIDGET (canvas)->window, canvas->gc[style],
620
708
                     segments, num_segments);
621
709
}
622
710
 
623
711
/**
 
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.
 
719
 *
 
720
 * Draws a layout, in the specified style.
 
721
 **/
 
722
void
 
723
gimp_canvas_draw_text (GimpCanvas      *canvas,
 
724
                       GimpCanvasStyle  style,
 
725
                       gint             x,
 
726
                       gint             y,
 
727
                       const gchar     *format,
 
728
                       ...)
 
729
{
 
730
  va_list  args;
 
731
  gchar   *text;
 
732
 
 
733
  if (! gimp_canvas_ensure_style (canvas, style))
 
734
    return;
 
735
 
 
736
  if (! canvas->layout)
 
737
    canvas->layout = gtk_widget_create_pango_layout (GTK_WIDGET (canvas),
 
738
                                                     NULL);
 
739
 
 
740
  va_start (args, format);
 
741
  text = g_strdup_vprintf (format, args);
 
742
  va_end (args);
 
743
 
 
744
  pango_layout_set_text (canvas->layout, text, -1);
 
745
  g_free (text);
 
746
 
 
747
  gdk_draw_layout (GTK_WIDGET (canvas)->window, canvas->gc[style],
 
748
                   x, y, canvas->layout);
 
749
}
 
750
 
 
751
/**
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,
756
884
                           GdkGC      *gc)
757
885
{
 
886
  if (gc)
 
887
    g_object_ref (gc);
 
888
 
758
889
  if (canvas->gc[GIMP_CANVAS_STYLE_CUSTOM])
759
890
    g_object_unref (canvas->gc[GIMP_CANVAS_STYLE_CUSTOM]);
760
891
 
761
892
  canvas->gc[GIMP_CANVAS_STYLE_CUSTOM] = gc;
762
 
 
763
 
  if (gc)
764
 
    g_object_ref (gc);
765
893
}
766
894
 
767
895
/**