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

« back to all changes in this revision

Viewing changes to app/display/gimpdisplayshell-draw.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 "libgimpbase/gimpbase.h"
 
24
#include "libgimpmath/gimpmath.h"
 
25
 
23
26
#include "display-types.h"
24
27
 
25
 
#include "core/gimp-utils.h"
 
28
#include "core/gimpcontext.h"
26
29
#include "core/gimpgrid.h"
 
30
#include "core/gimpguide.h"
27
31
#include "core/gimpimage.h"
28
 
#include "core/gimpimage-guides.h"
29
32
#include "core/gimplist.h"
 
33
#include "core/gimpsamplepoint.h"
30
34
 
31
35
#include "vectors/gimpstroke.h"
32
36
#include "vectors/gimpvectors.h"
33
37
 
 
38
#include "widgets/gimprender.h"
34
39
#include "widgets/gimpwidgets-utils.h"
35
40
 
36
41
#include "gimpcanvas.h"
46
51
 
47
52
static GdkGC * gimp_display_shell_get_grid_gc (GimpDisplayShell *shell,
48
53
                                               GimpGrid         *grid);
 
54
static GdkGC * gimp_display_shell_get_pen_gc  (GimpDisplayShell *shell,
 
55
                                               GimpContext      *context,
 
56
                                               GimpActiveColor   active);
49
57
 
50
58
 
51
59
/*  public functions  */
55
63
                               GimpGuide        *guide,
56
64
                               gboolean          active)
57
65
{
58
 
  gint  x1, x2;
59
 
  gint  y1, y2;
60
 
  gint  x, y;
61
 
  gint  w, h;
 
66
  gint  position;
 
67
  gint  x1, x2, y1, y2;
 
68
  gint  x, y, w, h;
62
69
 
63
70
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
64
 
  g_return_if_fail (guide != NULL);
65
 
 
66
 
  if (guide->position < 0)
 
71
  g_return_if_fail (GIMP_IS_GUIDE (guide));
 
72
 
 
73
  position = gimp_guide_get_position (guide);
 
74
 
 
75
  if (position < 0)
67
76
    return;
68
77
 
69
78
  gimp_display_shell_transform_xy (shell, 0, 0, &x1, &y1, FALSE);
70
79
  gimp_display_shell_transform_xy (shell,
71
 
                                   shell->gdisp->gimage->width,
72
 
                                   shell->gdisp->gimage->height,
 
80
                                   shell->display->image->width,
 
81
                                   shell->display->image->height,
73
82
                                   &x2, &y2, FALSE);
74
83
 
75
84
  gdk_drawable_get_size (shell->canvas->window, &w, &h);
76
85
 
77
 
  if (x1 < 0) x1 = 0;
78
 
  if (y1 < 0) y1 = 0;
79
 
  if (x2 > w) x2 = w;
80
 
  if (y2 > h) y2 = h;
 
86
  x1 = MAX (x1, 0);
 
87
  y1 = MAX (y1, 0);
 
88
  x2 = MIN (x2, w);
 
89
  y2 = MIN (y2, h);
81
90
 
82
 
  switch (guide->orientation)
 
91
  switch (gimp_guide_get_orientation (guide))
83
92
    {
84
93
    case GIMP_ORIENTATION_HORIZONTAL:
85
 
      gimp_display_shell_transform_xy (shell,
86
 
                                       0, guide->position, &x, &y, FALSE);
 
94
      gimp_display_shell_transform_xy (shell, 0, position, &x, &y, FALSE);
87
95
      y1 = y2 = y;
88
96
      break;
89
97
 
90
98
    case GIMP_ORIENTATION_VERTICAL:
91
 
      gimp_display_shell_transform_xy (shell,
92
 
                                       guide->position, 0, &x, &y, FALSE);
 
99
      gimp_display_shell_transform_xy (shell, position, 0, &x, &y, FALSE);
93
100
      x1 = x2 = x;
94
101
      break;
95
102
 
112
119
    {
113
120
      GList *list;
114
121
 
115
 
      for (list = shell->gdisp->gimage->guides;
 
122
      for (list = shell->display->image->guides;
116
123
           list;
117
124
           list = g_list_next (list))
118
 
        {
119
 
          gimp_display_shell_draw_guide (shell,
 
125
        {
 
126
          gimp_display_shell_draw_guide (shell,
120
127
                                         (GimpGuide *) list->data,
121
128
                                         FALSE);
122
 
        }
 
129
        }
123
130
    }
124
131
}
125
132
 
143
150
 
144
151
#define CROSSHAIR 2
145
152
 
146
 
      grid = GIMP_GRID (shell->gdisp->gimage->grid);
 
153
      grid = GIMP_GRID (shell->display->image->grid);
147
154
      if (! grid)
148
155
        return;
149
156
 
154
161
      x2 = area->x + area->width;
155
162
      y2 = area->y + area->height;
156
163
 
157
 
      width  = shell->gdisp->gimage->width;
158
 
      height = shell->gdisp->gimage->height;
 
164
      width  = shell->display->image->width;
 
165
      height = shell->display->image->height;
159
166
 
160
167
      x_offset = grid->xoffset;
161
168
      while (x_offset > 0)
292
299
}
293
300
 
294
301
void
 
302
gimp_display_shell_draw_pen (GimpDisplayShell  *shell,
 
303
                             const GimpVector2 *points,
 
304
                             gint               num_points,
 
305
                             GimpContext       *context,
 
306
                             GimpActiveColor    color,
 
307
                             gint               width)
 
308
{
 
309
  GimpCanvas  *canvas;
 
310
  GdkGC       *gc;
 
311
  GdkGCValues  values;
 
312
  GdkPoint    *coords;
 
313
 
 
314
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
315
  g_return_if_fail (GIMP_IS_CONTEXT (context));
 
316
  g_return_if_fail (num_points == 0 || points != NULL);
 
317
 
 
318
  canvas = GIMP_CANVAS (shell->canvas);
 
319
 
 
320
  coords = g_new (GdkPoint, MAX (2, num_points));
 
321
 
 
322
  gimp_display_shell_transform_points (shell,
 
323
                                       (const gdouble *) points, coords,
 
324
                                       num_points, FALSE);
 
325
 
 
326
  if (num_points == 1)
 
327
    {
 
328
      coords[1] = coords[0];
 
329
      num_points = 2;
 
330
    }
 
331
 
 
332
  gc = gimp_display_shell_get_pen_gc (shell, context, color);
 
333
 
 
334
  values.line_width = MAX (1, width);
 
335
  gdk_gc_set_values (gc, &values, GDK_GC_LINE_WIDTH);
 
336
 
 
337
  gimp_canvas_set_custom_gc (canvas, gc);
 
338
 
 
339
  gimp_canvas_draw_lines (canvas, GIMP_CANVAS_STYLE_CUSTOM, coords, num_points);
 
340
 
 
341
  gimp_canvas_set_custom_gc (canvas, NULL);
 
342
 
 
343
  g_free (coords);
 
344
}
 
345
 
 
346
void
 
347
gimp_display_shell_draw_sample_point (GimpDisplayShell *shell,
 
348
                                      GimpSamplePoint  *sample_point,
 
349
                                      gboolean          active)
 
350
{
 
351
  GimpCanvasStyle style;
 
352
  gdouble         x, y;
 
353
  gint            x1, x2;
 
354
  gint            y1, y2;
 
355
  gint            w, h;
 
356
 
 
357
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
358
  g_return_if_fail (sample_point != NULL);
 
359
 
 
360
  if (sample_point->x < 0)
 
361
    return;
 
362
 
 
363
  gimp_display_shell_transform_xy_f (shell,
 
364
                                     sample_point->x + 0.5,
 
365
                                     sample_point->y + 0.5,
 
366
                                     &x, &y, FALSE);
 
367
 
 
368
  x1 = floor (x - GIMP_SAMPLE_POINT_DRAW_SIZE);
 
369
  x2 = ceil  (x + GIMP_SAMPLE_POINT_DRAW_SIZE);
 
370
  y1 = floor (y - GIMP_SAMPLE_POINT_DRAW_SIZE);
 
371
  y2 = ceil  (y + GIMP_SAMPLE_POINT_DRAW_SIZE);
 
372
 
 
373
  gdk_drawable_get_size (shell->canvas->window, &w, &h);
 
374
 
 
375
  if (x < - GIMP_SAMPLE_POINT_DRAW_SIZE   ||
 
376
      y < - GIMP_SAMPLE_POINT_DRAW_SIZE   ||
 
377
      x > w + GIMP_SAMPLE_POINT_DRAW_SIZE ||
 
378
      y > h + GIMP_SAMPLE_POINT_DRAW_SIZE)
 
379
    return;
 
380
 
 
381
  if (active)
 
382
    style = GIMP_CANVAS_STYLE_SAMPLE_POINT_ACTIVE;
 
383
  else
 
384
    style = GIMP_CANVAS_STYLE_SAMPLE_POINT_NORMAL;
 
385
 
 
386
#define HALF_SIZE (GIMP_SAMPLE_POINT_DRAW_SIZE / 2)
 
387
 
 
388
  gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
 
389
                         x, y1, x, y1 + HALF_SIZE);
 
390
  gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
 
391
                         x, y2 - HALF_SIZE, x, y2);
 
392
 
 
393
  gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
 
394
                         x1, y, x1 + HALF_SIZE, y);
 
395
  gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
 
396
                         x2 - HALF_SIZE, y, x2, y);
 
397
 
 
398
  gimp_canvas_draw_arc (GIMP_CANVAS (shell->canvas), style,
 
399
                        FALSE,
 
400
                        x - HALF_SIZE, y - HALF_SIZE,
 
401
                        GIMP_SAMPLE_POINT_DRAW_SIZE,
 
402
                        GIMP_SAMPLE_POINT_DRAW_SIZE,
 
403
                        0, 64 * 270);
 
404
 
 
405
  gimp_canvas_draw_text (GIMP_CANVAS (shell->canvas), style,
 
406
                         x + 2, y + 2,
 
407
                         "%d",
 
408
                         g_list_index (shell->display->image->sample_points,
 
409
                                       sample_point) + 1);
 
410
}
 
411
 
 
412
void
 
413
gimp_display_shell_draw_sample_points (GimpDisplayShell *shell)
 
414
{
 
415
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
416
 
 
417
  if (gimp_display_shell_get_show_sample_points (shell))
 
418
    {
 
419
      GList *list;
 
420
 
 
421
      for (list = shell->display->image->sample_points;
 
422
           list;
 
423
           list = g_list_next (list))
 
424
        {
 
425
          gimp_display_shell_draw_sample_point (shell, list->data, FALSE);
 
426
        }
 
427
    }
 
428
}
 
429
 
 
430
void
295
431
gimp_display_shell_draw_vector (GimpDisplayShell *shell,
296
432
                                GimpVectors      *vectors)
297
433
{
307
443
 
308
444
      coords = gimp_stroke_interpolate (stroke, 1.0, &closed);
309
445
 
310
 
      if (coords && coords->len)
 
446
      if (coords && coords->len > 0)
311
447
        {
312
 
          GimpCoords *coord;
313
 
          GdkPoint   *gdk_coords;
314
 
          gint        i;
315
 
          gint        sx, sy;
316
 
 
317
 
          gdk_coords = g_new (GdkPoint, coords->len);
318
 
 
319
 
          for (i = 0; i < coords->len; i++)
320
 
            {
321
 
              coord = &g_array_index (coords, GimpCoords, i);
322
 
 
323
 
              gimp_display_shell_transform_xy (shell,
324
 
                                               coord->x, coord->y,
325
 
                                               &sx, &sy,
 
448
          GdkPoint *gdk_coords = g_new (GdkPoint, coords->len);
 
449
 
 
450
          gimp_display_shell_transform_coords (shell,
 
451
                                               &g_array_index (coords,
 
452
                                                               GimpCoords, 0),
 
453
                                               gdk_coords,
 
454
                                               coords->len,
326
455
                                               FALSE);
327
 
              gdk_coords[i].x = sx;
328
 
              gdk_coords[i].y = sy;
329
 
            }
330
456
 
331
457
          gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
332
458
                                  GIMP_CANVAS_STYLE_XOR,
349
475
    {
350
476
      GList *list;
351
477
 
352
 
      for (list = GIMP_LIST (shell->gdisp->gimage->vectors)->list;
 
478
      for (list = GIMP_LIST (shell->display->image->vectors)->list;
353
479
           list;
354
480
           list = list->next)
355
 
        {
 
481
        {
356
482
          GimpVectors *vectors = list->data;
357
483
 
358
484
          if (gimp_item_get_visible (GIMP_ITEM (vectors)))
359
485
            gimp_display_shell_draw_vector (shell, vectors);
360
 
        }
 
486
        }
361
487
    }
362
488
}
363
489
 
384
510
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
385
511
 
386
512
  /*  the image's size in display coordinates  */
387
 
  sx = shell->disp_xoffset > 0 ? shell->disp_xoffset : - shell->offset_x;
388
 
  sy = shell->disp_yoffset > 0 ? shell->disp_yoffset : - shell->offset_y;
389
 
  sw = SCALEX (shell, shell->gdisp->gimage->width);
390
 
  sh = SCALEY (shell, shell->gdisp->gimage->height);
 
513
  sx = shell->disp_xoffset - shell->offset_x;
 
514
  sy = shell->disp_yoffset - shell->offset_y;
 
515
  sw = SCALEX (shell, shell->display->image->width);
 
516
  sh = SCALEY (shell, shell->display->image->height);
391
517
 
392
518
  /*  check if the passed in area intersects with
393
519
   *  both the display and the image
394
520
   */
395
521
  if (gimp_rectangle_intersect (x, y, w, h,
396
522
                                0, 0, shell->disp_width,  shell->disp_height,
397
 
                                &x, &y, &w, &h) &&
 
523
                                &x, &y, &w, &h)
 
524
      &&
398
525
      gimp_rectangle_intersect (x, y, w, h,
399
526
                                sx, sy, sw, sh,
400
527
                                &x, &y, &w, &h))
417
544
      /*  display the image in RENDER_BUF_WIDTH x RENDER_BUF_HEIGHT
418
545
       *  sized chunks
419
546
       */
420
 
      for (i = y; i < y2; i += GIMP_DISPLAY_SHELL_RENDER_BUF_HEIGHT)
 
547
      for (i = y; i < y2; i += GIMP_RENDER_BUF_HEIGHT)
421
548
        {
422
 
          for (j = x; j < x2; j += GIMP_DISPLAY_SHELL_RENDER_BUF_WIDTH)
 
549
          for (j = x; j < x2; j += GIMP_RENDER_BUF_WIDTH)
423
550
            {
424
551
              gint dx, dy;
425
552
 
426
 
              dx = MIN (x2 - j, GIMP_DISPLAY_SHELL_RENDER_BUF_WIDTH);
427
 
              dy = MIN (y2 - i, GIMP_DISPLAY_SHELL_RENDER_BUF_HEIGHT);
 
553
              dx = MIN (x2 - j, GIMP_RENDER_BUF_WIDTH);
 
554
              dy = MIN (y2 - i, GIMP_RENDER_BUF_HEIGHT);
428
555
 
429
556
              gimp_display_shell_render (shell,
430
557
                                         j - shell->disp_xoffset,
434
561
 
435
562
#ifdef STRESS_TEST
436
563
              /* Invalidate the projection just after we render it! */
437
 
              gimp_image_invalidate_without_render (shell->gdisp->gimage,
 
564
              gimp_image_invalidate_without_render (shell->display->image,
438
565
                                                    j - shell->disp_xoffset,
439
566
                                                    i - shell->disp_yoffset,
440
567
                                                    dx, dy,
482
609
                                                     GDK_GC_JOIN_STYLE));
483
610
 
484
611
  gimp_rgb_get_gdk_color (&grid->fgcolor, &fg);
 
612
  gdk_gc_set_rgb_fg_color (shell->grid_gc, &fg);
 
613
 
485
614
  gimp_rgb_get_gdk_color (&grid->bgcolor, &bg);
486
 
 
487
 
  gdk_gc_set_rgb_fg_color (shell->grid_gc, &fg);
488
615
  gdk_gc_set_rgb_bg_color (shell->grid_gc, &bg);
489
616
 
490
617
  return shell->grid_gc;
491
618
}
 
619
 
 
620
static GdkGC *
 
621
gimp_display_shell_get_pen_gc (GimpDisplayShell *shell,
 
622
                               GimpContext      *context,
 
623
                               GimpActiveColor   active)
 
624
{
 
625
  GdkGCValues  values;
 
626
  GimpRGB      rgb;
 
627
  GdkColor     color;
 
628
 
 
629
  if (shell->pen_gc)
 
630
    return shell->pen_gc;
 
631
 
 
632
  values.line_style = GDK_LINE_SOLID;
 
633
  values.cap_style  = GDK_CAP_ROUND;
 
634
  values.join_style = GDK_JOIN_ROUND;
 
635
 
 
636
  shell->pen_gc = gdk_gc_new_with_values (shell->canvas->window,
 
637
                                          &values, (GDK_GC_LINE_STYLE |
 
638
                                                    GDK_GC_CAP_STYLE  |
 
639
                                                    GDK_GC_JOIN_STYLE));
 
640
 
 
641
  switch (active)
 
642
    {
 
643
    case GIMP_ACTIVE_COLOR_FOREGROUND:
 
644
      gimp_context_get_foreground (context, &rgb);
 
645
      break;
 
646
 
 
647
    case GIMP_ACTIVE_COLOR_BACKGROUND:
 
648
      gimp_context_get_background (context, &rgb);
 
649
      break;
 
650
    }
 
651
 
 
652
  gimp_rgb_get_gdk_color (&rgb, &color);
 
653
  gdk_gc_set_rgb_fg_color (shell->pen_gc, &color);
 
654
 
 
655
  g_object_add_weak_pointer (G_OBJECT (shell->pen_gc),
 
656
                             (gpointer) &shell->pen_gc);
 
657
 
 
658
  g_signal_connect_object (context, "notify",
 
659
                           G_CALLBACK (g_object_unref),
 
660
                           shell->pen_gc, G_CONNECT_SWAPPED);
 
661
 
 
662
  return shell->pen_gc;
 
663
}