2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-12-28 03:25:19 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpdasheditor.c
|
|
|
|
* Copyright (C) 2003 Simon Budig <simon@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-12-28 03:25:19 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-12-28 03:25:19 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-12-28 03:25:19 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2003-12-28 03:25:19 +08:00
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2005-05-19 07:59:35 +08:00
|
|
|
#include "core/gimpdashpattern.h"
|
2003-12-28 03:25:19 +08:00
|
|
|
#include "core/gimpstrokeoptions.h"
|
|
|
|
|
|
|
|
#include "gimpdasheditor.h"
|
|
|
|
|
|
|
|
|
2003-12-28 06:04:51 +08:00
|
|
|
#define MIN_WIDTH 64
|
|
|
|
#define MIN_HEIGHT 20
|
2003-12-28 03:25:19 +08:00
|
|
|
|
|
|
|
#define DEFAULT_N_SEGMENTS 24
|
|
|
|
|
2004-02-20 00:42:24 +08:00
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_STROKE_OPTIONS,
|
|
|
|
PROP_N_SEGMENTS,
|
2004-07-30 08:57:22 +08:00
|
|
|
PROP_LENGTH
|
2003-12-28 03:25:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-02-20 00:42:24 +08:00
|
|
|
static void gimp_dash_editor_finalize (GObject *object);
|
2003-12-28 03:25:19 +08:00
|
|
|
static void gimp_dash_editor_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_dash_editor_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2004-02-20 00:42:24 +08:00
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
static void gimp_dash_editor_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition);
|
|
|
|
static gboolean gimp_dash_editor_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
|
|
|
static gboolean gimp_dash_editor_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent);
|
|
|
|
static gboolean gimp_dash_editor_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent);
|
|
|
|
static gboolean gimp_dash_editor_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *bevent);
|
|
|
|
|
|
|
|
/* helper function */
|
2004-02-20 00:42:24 +08:00
|
|
|
static void update_segments_from_options (GimpDashEditor *editor);
|
|
|
|
static void update_options_from_segments (GimpDashEditor *editor);
|
|
|
|
static void update_blocksize (GimpDashEditor *editor);
|
|
|
|
static gint dash_x_to_index (GimpDashEditor *editor,
|
|
|
|
gint x);
|
2003-12-28 03:25:19 +08:00
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpDashEditor, gimp_dash_editor, GTK_TYPE_DRAWING_AREA)
|
2003-12-28 03:25:19 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
#define parent_class gimp_dash_editor_parent_class
|
2003-12-28 03:25:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_dash_editor_class_init (GimpDashEditorClass *klass)
|
|
|
|
{
|
2004-02-20 00:42:24 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2003-12-28 03:25:19 +08:00
|
|
|
|
2004-02-20 00:42:24 +08:00
|
|
|
object_class->finalize = gimp_dash_editor_finalize;
|
2003-12-28 03:25:19 +08:00
|
|
|
object_class->get_property = gimp_dash_editor_get_property;
|
|
|
|
object_class->set_property = gimp_dash_editor_set_property;
|
|
|
|
|
|
|
|
widget_class->size_request = gimp_dash_editor_size_request;
|
|
|
|
widget_class->expose_event = gimp_dash_editor_expose;
|
|
|
|
widget_class->button_press_event = gimp_dash_editor_button_press;
|
|
|
|
widget_class->button_release_event = gimp_dash_editor_button_release;
|
|
|
|
widget_class->motion_notify_event = gimp_dash_editor_motion_notify;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_STROKE_OPTIONS,
|
2004-02-20 00:42:24 +08:00
|
|
|
g_param_spec_object ("stroke-options",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_STROKE_OPTIONS,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-02-20 00:42:24 +08:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_N_SEGMENTS,
|
|
|
|
g_param_spec_int ("n-segments",
|
|
|
|
NULL, NULL,
|
|
|
|
2, 120, DEFAULT_N_SEGMENTS,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-02-20 00:42:24 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_LENGTH,
|
|
|
|
g_param_spec_double ("dash-length",
|
|
|
|
NULL, NULL,
|
|
|
|
0.0, 2000.0,
|
|
|
|
0.5 * DEFAULT_N_SEGMENTS,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-02-20 00:42:24 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
2003-12-28 03:25:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_dash_editor_init (GimpDashEditor *editor)
|
|
|
|
{
|
2004-02-20 00:42:24 +08:00
|
|
|
editor->segments = NULL;
|
|
|
|
editor->block_width = 6;
|
|
|
|
editor->block_height = 6;
|
|
|
|
editor->edit_mode = TRUE;
|
|
|
|
editor->edit_button_x0 = 0;
|
2003-12-28 06:04:51 +08:00
|
|
|
|
|
|
|
gtk_widget_add_events (GTK_WIDGET (editor),
|
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK);
|
2003-12-28 03:25:19 +08:00
|
|
|
}
|
|
|
|
|
2004-02-20 00:42:24 +08:00
|
|
|
static void
|
|
|
|
gimp_dash_editor_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpDashEditor *editor = GIMP_DASH_EDITOR (object);
|
|
|
|
|
|
|
|
if (editor->stroke_options)
|
|
|
|
{
|
|
|
|
g_object_unref (editor->stroke_options);
|
|
|
|
editor->stroke_options = NULL;
|
|
|
|
}
|
|
|
|
|
2004-11-03 22:31:51 +08:00
|
|
|
if (editor->segments)
|
|
|
|
{
|
|
|
|
g_free (editor->segments);
|
|
|
|
editor->segments = NULL;
|
|
|
|
}
|
|
|
|
|
2004-02-20 00:42:24 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
static void
|
|
|
|
gimp_dash_editor_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpDashEditor *editor = GIMP_DASH_EDITOR (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_STROKE_OPTIONS:
|
2003-12-28 06:04:51 +08:00
|
|
|
g_return_if_fail (editor->stroke_options == NULL);
|
|
|
|
|
2008-07-23 15:47:10 +08:00
|
|
|
editor->stroke_options = g_value_dup_object (value);
|
2003-12-28 03:25:19 +08:00
|
|
|
g_signal_connect_object (editor->stroke_options, "notify::dash-info",
|
2003-12-28 06:04:51 +08:00
|
|
|
G_CALLBACK (update_segments_from_options),
|
|
|
|
editor, G_CONNECT_SWAPPED);
|
2003-12-28 03:25:19 +08:00
|
|
|
break;
|
2003-12-28 06:04:51 +08:00
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
case PROP_N_SEGMENTS:
|
|
|
|
editor->n_segments = g_value_get_int (value);
|
2003-12-28 06:04:51 +08:00
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
if (editor->segments)
|
|
|
|
g_free (editor->segments);
|
|
|
|
editor->segments = g_new0 (gboolean, editor->n_segments);
|
|
|
|
break;
|
2003-12-28 06:04:51 +08:00
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
case PROP_LENGTH:
|
|
|
|
editor->dash_length = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2003-12-28 06:04:51 +08:00
|
|
|
|
|
|
|
update_segments_from_options (editor);
|
2003-12-28 03:25:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_dash_editor_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpDashEditor *editor = GIMP_DASH_EDITOR (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_STROKE_OPTIONS:
|
|
|
|
g_value_set_object (value, editor->stroke_options);
|
|
|
|
break;
|
|
|
|
case PROP_N_SEGMENTS:
|
|
|
|
g_value_set_int (value, editor->n_segments);
|
|
|
|
break;
|
|
|
|
case PROP_LENGTH:
|
|
|
|
g_value_set_double (value, editor->dash_length);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_dash_editor_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition)
|
|
|
|
{
|
|
|
|
GimpDashEditor *editor = GIMP_DASH_EDITOR (widget);
|
|
|
|
|
|
|
|
requisition->width = MAX (editor->block_width * editor->n_segments + 20,
|
|
|
|
MIN_WIDTH);
|
|
|
|
requisition->height = MAX (editor->block_height + 10, MIN_HEIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_dash_editor_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event)
|
|
|
|
{
|
|
|
|
GimpDashEditor *editor = GIMP_DASH_EDITOR (widget);
|
2008-06-28 23:50:27 +08:00
|
|
|
GtkStyle *style = gtk_widget_get_style (widget);
|
2007-11-02 03:51:22 +08:00
|
|
|
cairo_t *cr = gdk_cairo_create (widget->window);
|
|
|
|
gint x;
|
|
|
|
gint w, h;
|
2003-12-28 03:25:19 +08:00
|
|
|
|
|
|
|
update_blocksize (editor);
|
|
|
|
|
2007-11-02 03:51:22 +08:00
|
|
|
gdk_cairo_rectangle (cr, &event->area);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
/* draw the background */
|
|
|
|
|
2008-06-28 23:50:27 +08:00
|
|
|
gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]);
|
2007-11-02 03:51:22 +08:00
|
|
|
cairo_paint (cr);
|
2003-12-28 03:25:19 +08:00
|
|
|
|
|
|
|
w = editor->block_width;
|
|
|
|
h = editor->block_height;
|
|
|
|
|
|
|
|
editor->x0 = (widget->allocation.width - w * editor->n_segments) / 2;
|
|
|
|
editor->y0 = (widget->allocation.height - h) / 2;
|
2003-12-28 06:04:51 +08:00
|
|
|
|
2007-11-02 03:51:22 +08:00
|
|
|
/* draw the dash segments */
|
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
x = editor->x0 % w;
|
|
|
|
|
|
|
|
if (x > 0)
|
|
|
|
x -= w;
|
|
|
|
|
2007-11-02 03:51:22 +08:00
|
|
|
for (; x < editor->x0; x += w)
|
|
|
|
{
|
|
|
|
gint index = dash_x_to_index (editor, x);
|
|
|
|
|
|
|
|
if (editor->segments[index])
|
|
|
|
cairo_rectangle (cr, x, editor->y0, w, h);
|
|
|
|
}
|
|
|
|
|
2008-06-28 23:50:27 +08:00
|
|
|
gdk_cairo_set_source_color (cr, &style->text_aa[GTK_STATE_NORMAL]);
|
2007-11-02 03:51:22 +08:00
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
for (; x < editor->x0 + editor->n_segments * w; x += w)
|
|
|
|
{
|
|
|
|
gint index = dash_x_to_index (editor, x);
|
|
|
|
|
|
|
|
if (editor->segments[index])
|
|
|
|
cairo_rectangle (cr, x, editor->y0, w, h);
|
|
|
|
}
|
|
|
|
|
2008-06-28 23:50:27 +08:00
|
|
|
gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]);
|
2007-11-02 03:51:22 +08:00
|
|
|
cairo_fill (cr);
|
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
for (; x < widget->allocation.width + w; x += w)
|
|
|
|
{
|
2007-11-02 03:51:22 +08:00
|
|
|
gint index = dash_x_to_index (editor, x);
|
|
|
|
|
|
|
|
if (editor->segments[index])
|
|
|
|
cairo_rectangle (cr, x, editor->y0, w, h);
|
|
|
|
}
|
2003-12-28 03:25:19 +08:00
|
|
|
|
2008-06-28 23:50:27 +08:00
|
|
|
gdk_cairo_set_source_color (cr, &style->text_aa[GTK_STATE_NORMAL]);
|
2007-11-02 03:51:22 +08:00
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
/* draw rulers */
|
|
|
|
|
|
|
|
x = editor->x0 % w;
|
|
|
|
|
|
|
|
if (x > 0)
|
|
|
|
x -= w;
|
|
|
|
|
|
|
|
for (; x < widget->allocation.width + w; x += w)
|
|
|
|
{
|
|
|
|
gint index = dash_x_to_index (editor, x);
|
|
|
|
|
|
|
|
if (editor->n_segments % 4 == 0 &&
|
|
|
|
(index + 1) % (editor->n_segments / 4) == 0)
|
2003-12-28 03:25:19 +08:00
|
|
|
{
|
2007-11-02 03:51:22 +08:00
|
|
|
cairo_move_to (cr, x + w - 0.5, editor->y0 - 2);
|
|
|
|
cairo_line_to (cr, x + w - 0.5, editor->y0 + h + 2);
|
|
|
|
}
|
|
|
|
else if (index % 2 == 1)
|
|
|
|
{
|
|
|
|
cairo_move_to (cr, x + w - 0.5, editor->y0 + 1);
|
|
|
|
cairo_line_to (cr, x + w - 0.5, editor->y0 + h - 1);
|
2003-12-28 03:25:19 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-02 03:51:22 +08:00
|
|
|
cairo_move_to (cr, x + w - 0.5, editor->y0 + h / 2 - 1);
|
|
|
|
cairo_line_to (cr, x + w - 0.5, editor->y0 + h / 2 + 1);
|
2003-12-28 03:25:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-02 03:51:22 +08:00
|
|
|
cairo_move_to (cr, editor->x0 - 0.5, editor->y0 - 1);
|
|
|
|
cairo_move_to (cr, editor->x0 - 0.5, editor->y0 + h);
|
|
|
|
|
2008-06-28 23:50:27 +08:00
|
|
|
gdk_cairo_set_source_color (cr, &style->text_aa[GTK_STATE_NORMAL]);
|
2007-11-02 03:51:22 +08:00
|
|
|
cairo_set_line_width (cr, 1.0);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
2003-12-28 03:25:19 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_dash_editor_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
|
|
|
{
|
|
|
|
GimpDashEditor *editor = GIMP_DASH_EDITOR (widget);
|
|
|
|
gint index;
|
|
|
|
|
2004-02-20 00:42:24 +08:00
|
|
|
if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS)
|
2003-12-28 03:25:19 +08:00
|
|
|
{
|
|
|
|
gdk_pointer_grab (widget->window, FALSE,
|
2006-04-12 20:49:29 +08:00
|
|
|
GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK,
|
|
|
|
NULL, NULL, bevent->time);
|
2003-12-28 03:25:19 +08:00
|
|
|
index = dash_x_to_index (editor, bevent->x);
|
|
|
|
|
2004-02-20 00:42:24 +08:00
|
|
|
editor->edit_mode = ! editor->segments [index];
|
|
|
|
editor->edit_button_x0 = bevent->x;
|
2003-12-28 03:25:19 +08:00
|
|
|
|
2004-02-20 00:42:24 +08:00
|
|
|
editor->segments [index] = editor->edit_mode;
|
2003-12-28 03:25:19 +08:00
|
|
|
|
|
|
|
gtk_widget_queue_draw (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_dash_editor_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
|
|
|
{
|
|
|
|
GimpDashEditor *editor = GIMP_DASH_EDITOR (widget);
|
|
|
|
|
|
|
|
if (bevent->button == 1)
|
|
|
|
{
|
|
|
|
gdk_display_pointer_ungrab (gtk_widget_get_display (GTK_WIDGET (editor)),
|
|
|
|
bevent->time);
|
|
|
|
|
|
|
|
update_options_from_segments (editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_dash_editor_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *mevent)
|
|
|
|
{
|
|
|
|
GimpDashEditor *editor = GIMP_DASH_EDITOR (widget);
|
|
|
|
gint x, index;
|
|
|
|
|
|
|
|
index = dash_x_to_index (editor, mevent->x);
|
2004-02-20 00:42:24 +08:00
|
|
|
editor->segments [index] = editor->edit_mode;
|
2003-12-28 03:25:19 +08:00
|
|
|
|
2004-02-20 00:42:24 +08:00
|
|
|
if (mevent->x > editor->edit_button_x0)
|
2003-12-28 03:25:19 +08:00
|
|
|
{
|
2004-02-20 00:42:24 +08:00
|
|
|
for (x = editor->edit_button_x0; x < mevent->x; x += editor->block_width)
|
2003-12-28 03:25:19 +08:00
|
|
|
{
|
|
|
|
index = dash_x_to_index (editor, x);
|
2004-02-20 00:42:24 +08:00
|
|
|
editor->segments[index] = editor->edit_mode;
|
2003-12-28 03:25:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-20 00:42:24 +08:00
|
|
|
if (mevent->x < editor->edit_button_x0)
|
2003-12-28 03:25:19 +08:00
|
|
|
{
|
2004-02-20 00:42:24 +08:00
|
|
|
for (x = editor->edit_button_x0; x > mevent->x; x -= editor->block_width)
|
2003-12-28 03:25:19 +08:00
|
|
|
{
|
|
|
|
index = dash_x_to_index (editor, x);
|
2004-02-20 00:42:24 +08:00
|
|
|
editor->segments[index] = editor->edit_mode;
|
2003-12-28 03:25:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (widget);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gimp_dash_editor_new (GimpStrokeOptions *stroke_options)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE_OPTIONS (stroke_options), NULL);
|
|
|
|
|
2004-01-06 18:04:31 +08:00
|
|
|
return g_object_new (GIMP_TYPE_DASH_EDITOR,
|
|
|
|
"stroke-options", stroke_options,
|
|
|
|
NULL);
|
2003-12-28 03:25:19 +08:00
|
|
|
}
|
|
|
|
|
2003-12-28 10:18:25 +08:00
|
|
|
void
|
|
|
|
gimp_dash_editor_shift_right (GimpDashEditor *editor)
|
|
|
|
{
|
|
|
|
gboolean swap;
|
2004-02-20 00:42:24 +08:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DASH_EDITOR (editor));
|
2003-12-28 10:18:25 +08:00
|
|
|
g_return_if_fail (editor->n_segments > 0);
|
|
|
|
|
|
|
|
swap = editor->segments[editor->n_segments - 1];
|
|
|
|
for (i = editor->n_segments - 1; i > 0; i--)
|
|
|
|
editor->segments[i] = editor->segments[i-1];
|
|
|
|
editor->segments[0] = swap;
|
|
|
|
|
|
|
|
update_options_from_segments (editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_dash_editor_shift_left (GimpDashEditor *editor)
|
|
|
|
{
|
|
|
|
gboolean swap;
|
2004-02-20 00:42:24 +08:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DASH_EDITOR (editor));
|
2003-12-28 10:18:25 +08:00
|
|
|
g_return_if_fail (editor->n_segments > 0);
|
|
|
|
|
|
|
|
swap = editor->segments[0];
|
|
|
|
for (i = 1; i < editor->n_segments; i++)
|
|
|
|
editor->segments[i-1] = editor->segments[i];
|
|
|
|
editor->segments[editor->n_segments - 1] = swap;
|
|
|
|
|
|
|
|
update_options_from_segments (editor);
|
|
|
|
}
|
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
static void
|
|
|
|
update_segments_from_options (GimpDashEditor *editor)
|
|
|
|
{
|
2003-12-28 06:04:51 +08:00
|
|
|
if (editor->stroke_options == NULL || editor->segments == NULL)
|
|
|
|
return;
|
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
g_return_if_fail (GIMP_IS_STROKE_OPTIONS (editor->stroke_options));
|
2003-12-28 06:04:51 +08:00
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (editor));
|
2003-12-28 03:25:19 +08:00
|
|
|
|
2007-01-13 04:27:40 +08:00
|
|
|
gimp_dash_pattern_fill_segments (editor->stroke_options->dash_info,
|
|
|
|
editor->segments, editor->n_segments);
|
2003-12-28 03:25:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_options_from_segments (GimpDashEditor *editor)
|
|
|
|
{
|
2007-01-13 04:27:40 +08:00
|
|
|
GArray *pattern = gimp_dash_pattern_new_from_segments (editor->segments,
|
|
|
|
editor->n_segments,
|
|
|
|
editor->dash_length);
|
2005-05-19 08:40:48 +08:00
|
|
|
|
2008-05-18 23:15:07 +08:00
|
|
|
gimp_stroke_options_take_dash_pattern (editor->stroke_options,
|
|
|
|
GIMP_DASH_CUSTOM, pattern);
|
2003-12-28 03:25:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_blocksize (GimpDashEditor *editor)
|
|
|
|
{
|
2003-12-28 06:04:51 +08:00
|
|
|
GtkWidget *widget = GTK_WIDGET (editor);
|
2003-12-28 03:25:19 +08:00
|
|
|
|
|
|
|
editor->block_height = 6;
|
|
|
|
|
|
|
|
editor->block_width = MAX (ROUND (editor->dash_length /
|
|
|
|
editor->n_segments * editor->block_height),
|
|
|
|
4);
|
|
|
|
editor->block_height = MIN (ROUND (((float) editor->block_width) *
|
|
|
|
editor->n_segments / editor->dash_length),
|
|
|
|
widget->allocation.height - 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
dash_x_to_index (GimpDashEditor *editor,
|
|
|
|
gint x)
|
|
|
|
{
|
2003-12-28 06:04:51 +08:00
|
|
|
gint index = x - editor->x0;
|
2003-12-28 03:25:19 +08:00
|
|
|
|
|
|
|
while (index < 0)
|
|
|
|
index += editor->n_segments * editor->block_width;
|
|
|
|
|
|
|
|
index = (index / editor->block_width) % editor->n_segments;
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|