24
24
#include <gtk/gtk.h>
26
26
#include "libgimpmath/gimpmath.h"
27
#include "libgimpconfig/gimpconfig.h"
28
29
#include "widgets-types.h"
30
#include "config/gimpconfig-params.h"
31
#include "core/gimpdashpattern.h"
32
32
#include "core/gimpstrokeoptions.h"
34
34
#include "gimpdasheditor.h"
84
static GtkDrawingAreaClass *parent_class = NULL;
88
gimp_dash_editor_get_type (void)
90
static GType editor_type = 0;
94
static const GTypeInfo editor_info =
96
sizeof (GimpDashEditorClass),
98
NULL, /* base_finalize */
99
(GClassInitFunc) gimp_dash_editor_class_init,
100
NULL, /* class_finalize */
101
NULL, /* class_data */
102
sizeof (GimpDashEditor),
104
(GInstanceInitFunc) gimp_dash_editor_init,
107
editor_type = g_type_register_static (GTK_TYPE_DRAWING_AREA,
81
G_DEFINE_TYPE (GimpDashEditor, gimp_dash_editor, GTK_TYPE_DRAWING_AREA)
83
#define parent_class gimp_dash_editor_parent_class
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);
121
parent_class = g_type_class_peek_parent (klass);
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",
136
105
GIMP_TYPE_STROKE_OPTIONS,
106
GIMP_PARAM_READWRITE |
138
107
G_PARAM_CONSTRUCT_ONLY));
140
109
g_object_class_install_property (object_class, PROP_N_SEGMENTS,
141
110
g_param_spec_int ("n-segments",
143
112
2, 120, DEFAULT_N_SEGMENTS,
113
GIMP_PARAM_READWRITE |
145
114
G_PARAM_CONSTRUCT));
147
116
g_object_class_install_property (object_class, PROP_LENGTH,
360
329
if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS)
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);
367
336
editor->edit_mode = ! editor->segments [index];
485
449
gtk_widget_queue_draw (GTK_WIDGET (editor));
487
dash_info = editor->stroke_options->dash_info;
489
if (dash_info == NULL || dash_info->len <= 1)
491
for (i = 0; i < editor->n_segments; i++)
492
editor->segments[i] = TRUE;
497
for (i = 0; i < dash_info->len ; i++)
499
sum += g_array_index (dash_info, gdouble, i);
502
factor = ((gdouble) editor->n_segments) / sum;
505
sum = g_array_index (dash_info, gdouble, j) * factor;
508
for (i = 0; i < editor->n_segments ; i++)
510
while (j < dash_info->len && sum <= i)
514
sum += g_array_index (dash_info, gdouble, j) * factor;
517
editor->segments[i] = paint;
451
gimp_dash_pattern_fill_segments (editor->stroke_options->dash_info,
452
editor->segments, editor->n_segments);
522
456
update_options_from_segments (GimpDashEditor *editor)
528
dash_array = g_array_new (FALSE, FALSE, sizeof (gdouble));
532
for (i = 0; i <= editor->n_segments; i++)
534
if (i < editor->n_segments && editor->segments[i] == state)
540
gdouble l = (editor->dash_length * count) / editor->n_segments;
541
dash_array = g_array_append_val (dash_array, l);
548
if (dash_array->len > 1)
550
GValueArray *val_array;
551
GValue item = { 0, };
553
val_array = g_value_array_new (dash_array->len);
555
g_value_init (&item, G_TYPE_DOUBLE);
557
for (i = 0; i < dash_array->len; i++)
559
g_value_set_double (&item,
560
g_array_index (dash_array, gdouble, i));
561
g_value_array_append (val_array, &item);
564
g_object_set (editor->stroke_options,
565
"dash-info", val_array,
568
g_value_array_free (val_array);
572
g_object_set (editor->stroke_options,
577
g_array_free (dash_array, TRUE);
458
GArray *pattern = gimp_dash_pattern_new_from_segments (editor->segments,
460
editor->dash_length);
462
gimp_stroke_options_set_dash_pattern (editor->stroke_options,
463
GIMP_DASH_CUSTOM, pattern);