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

« back to all changes in this revision

Viewing changes to app/widgets/gimpdasheditor.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
 * gimpdasheditor.c
24
24
#include <gtk/gtk.h>
25
25
 
26
26
#include "libgimpmath/gimpmath.h"
 
27
#include "libgimpconfig/gimpconfig.h"
27
28
 
28
29
#include "widgets-types.h"
29
30
 
30
 
#include "config/gimpconfig-params.h"
31
 
 
 
31
#include "core/gimpdashpattern.h"
32
32
#include "core/gimpstrokeoptions.h"
33
33
 
34
34
#include "gimpdasheditor.h"
49
49
};
50
50
 
51
51
 
52
 
static void gimp_dash_editor_class_init    (GimpDashEditorClass *klass);
53
 
static void gimp_dash_editor_init          (GimpDashEditor      *editor);
54
 
 
55
52
static void gimp_dash_editor_finalize           (GObject        *object);
56
53
static void gimp_dash_editor_set_property       (GObject        *object,
57
54
                                                 guint           property_id,
81
78
                                                 gint            x);
82
79
 
83
80
 
84
 
static GtkDrawingAreaClass *parent_class = NULL;
85
 
 
86
 
 
87
 
GType
88
 
gimp_dash_editor_get_type (void)
89
 
{
90
 
  static GType editor_type = 0;
91
 
 
92
 
  if (! editor_type)
93
 
    {
94
 
      static const GTypeInfo editor_info =
95
 
      {
96
 
        sizeof (GimpDashEditorClass),
97
 
        NULL,           /* base_init */
98
 
        NULL,           /* base_finalize */
99
 
        (GClassInitFunc) gimp_dash_editor_class_init,
100
 
        NULL,           /* class_finalize */
101
 
        NULL,           /* class_data */
102
 
        sizeof (GimpDashEditor),
103
 
        0,              /* n_preallocs */
104
 
        (GInstanceInitFunc) gimp_dash_editor_init,
105
 
      };
106
 
 
107
 
      editor_type = g_type_register_static (GTK_TYPE_DRAWING_AREA,
108
 
                                            "GimpDashEditor",
109
 
                                            &editor_info, 0);
110
 
    }
111
 
 
112
 
  return editor_type;
113
 
}
 
81
G_DEFINE_TYPE (GimpDashEditor, gimp_dash_editor, GTK_TYPE_DRAWING_AREA)
 
82
 
 
83
#define parent_class gimp_dash_editor_parent_class
 
84
 
114
85
 
115
86
static void
116
87
gimp_dash_editor_class_init (GimpDashEditorClass *klass)
118
89
  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
119
90
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
120
91
 
121
 
  parent_class = g_type_class_peek_parent (klass);
122
 
 
123
92
  object_class->finalize     = gimp_dash_editor_finalize;
124
93
  object_class->get_property = gimp_dash_editor_get_property;
125
94
  object_class->set_property = gimp_dash_editor_set_property;
134
103
                                   g_param_spec_object ("stroke-options",
135
104
                                                        NULL, NULL,
136
105
                                                        GIMP_TYPE_STROKE_OPTIONS,
137
 
                                                        G_PARAM_READWRITE |
 
106
                                                        GIMP_PARAM_READWRITE |
138
107
                                                        G_PARAM_CONSTRUCT_ONLY));
139
108
 
140
109
  g_object_class_install_property (object_class, PROP_N_SEGMENTS,
141
110
                                   g_param_spec_int ("n-segments",
142
111
                                                     NULL, NULL,
143
112
                                                     2, 120, DEFAULT_N_SEGMENTS,
144
 
                                                     G_PARAM_READWRITE |
 
113
                                                     GIMP_PARAM_READWRITE |
145
114
                                                     G_PARAM_CONSTRUCT));
146
115
 
147
116
  g_object_class_install_property (object_class, PROP_LENGTH,
149
118
                                                        NULL, NULL,
150
119
                                                        0.0, 2000.0,
151
120
                                                        0.5 * DEFAULT_N_SEGMENTS,
152
 
                                                        G_PARAM_READWRITE |
 
121
                                                        GIMP_PARAM_READWRITE |
153
122
                                                        G_PARAM_CONSTRUCT));
154
123
}
155
124
 
360
329
  if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS)
361
330
    {
362
331
      gdk_pointer_grab (widget->window, FALSE,
363
 
                        GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK,
364
 
                        NULL, NULL, bevent->time);
 
332
                        GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK,
 
333
                        NULL, NULL, bevent->time);
365
334
      index = dash_x_to_index (editor, bevent->x);
366
335
 
367
336
      editor->edit_mode = ! editor->segments [index];
472
441
static void
473
442
update_segments_from_options (GimpDashEditor *editor)
474
443
{
475
 
  gdouble   factor, sum = 0;
476
 
  gint      i, j;
477
 
  gboolean  paint;
478
 
  GArray   *dash_info;
479
 
 
480
444
  if (editor->stroke_options == NULL || editor->segments == NULL)
481
445
    return;
482
446
 
484
448
 
485
449
  gtk_widget_queue_draw (GTK_WIDGET (editor));
486
450
 
487
 
  dash_info = editor->stroke_options->dash_info;
488
 
 
489
 
  if (dash_info == NULL || dash_info->len <= 1)
490
 
    {
491
 
      for (i = 0; i < editor->n_segments; i++)
492
 
        editor->segments[i] = TRUE;
493
 
 
494
 
      return;
495
 
    }
496
 
 
497
 
  for (i = 0; i < dash_info->len ; i++)
498
 
    {
499
 
      sum += g_array_index (dash_info, gdouble, i);
500
 
    }
501
 
 
502
 
  factor = ((gdouble) editor->n_segments) / sum;
503
 
 
504
 
  j = 0;
505
 
  sum = g_array_index (dash_info, gdouble, j) * factor;
506
 
  paint = TRUE;
507
 
 
508
 
  for (i = 0; i < editor->n_segments ; i++)
509
 
    {
510
 
      while (j < dash_info->len && sum <= i)
511
 
        {
512
 
          paint = ! paint;
513
 
          j++;
514
 
          sum += g_array_index (dash_info, gdouble, j) * factor;
515
 
        }
516
 
 
517
 
      editor->segments[i] = paint;
518
 
    }
 
451
  gimp_dash_pattern_fill_segments (editor->stroke_options->dash_info,
 
452
                                   editor->segments, editor->n_segments);
519
453
}
520
454
 
521
455
static void
522
456
update_options_from_segments (GimpDashEditor *editor)
523
457
{
524
 
  gint      i, count = 0;
525
 
  gboolean  state;
526
 
  GArray   *dash_array;
527
 
 
528
 
  dash_array = g_array_new (FALSE, FALSE, sizeof (gdouble));
529
 
 
530
 
  state = TRUE;
531
 
 
532
 
  for (i = 0; i <= editor->n_segments; i++)
533
 
    {
534
 
      if (i < editor->n_segments && editor->segments[i] == state)
535
 
        {
536
 
          count++;
537
 
        }
538
 
      else
539
 
        {
540
 
          gdouble l = (editor->dash_length * count) / editor->n_segments;
541
 
          dash_array = g_array_append_val (dash_array, l);
542
 
 
543
 
          count = 1;
544
 
          state = ! state;
545
 
        }
546
 
    }
547
 
 
548
 
  if (dash_array->len > 1)
549
 
    {
550
 
      GValueArray *val_array;
551
 
      GValue       item = { 0, };
552
 
 
553
 
      val_array = g_value_array_new (dash_array->len);
554
 
 
555
 
      g_value_init (&item, G_TYPE_DOUBLE);
556
 
 
557
 
      for (i = 0; i < dash_array->len; i++)
558
 
        {
559
 
          g_value_set_double (&item,
560
 
                              g_array_index (dash_array, gdouble, i));
561
 
          g_value_array_append (val_array, &item);
562
 
        }
563
 
 
564
 
      g_object_set (editor->stroke_options,
565
 
                    "dash-info", val_array,
566
 
                    NULL);
567
 
 
568
 
      g_value_array_free (val_array);
569
 
    }
570
 
  else
571
 
    {
572
 
      g_object_set (editor->stroke_options,
573
 
                    "dash-info", NULL,
574
 
                    NULL);
575
 
    }
576
 
 
577
 
  g_array_free (dash_array, TRUE);
 
458
  GArray *pattern = gimp_dash_pattern_new_from_segments (editor->segments,
 
459
                                                         editor->n_segments,
 
460
                                                         editor->dash_length);
 
461
 
 
462
  gimp_stroke_options_set_dash_pattern (editor->stroke_options,
 
463
                                        GIMP_DASH_CUSTOM, pattern);
578
464
}
579
465
 
580
466
static void