mirror of https://github.com/GNOME/gimp.git
Dashed stroking is here... :-)
2003-12-27 Simon Budig <simon@gimp.org> Dashed stroking is here... :-) * app/core/gimpdrawable-stroke.c: actually use the dash pattern from the options * app/core/gimpscanconvert.c: Normalize the dash pattern, so that libart does the right thing. * app/core/gimpstrokeoptions.c: Fix default value for dash offset, handle the property_get for PROP_DASH_INFO correct. * app/widgets/gimpdasheditor.[ch] * app/widgets/Makefile.am * app/widgets/widgets-types.h: New widget to edit a dash pattern. * app/widgets/gimpstrokeeditor.c: Use it.
This commit is contained in:
parent
7e6ca9fd7f
commit
c95bca30e9
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,23 @@
|
|||
2003-12-27 Simon Budig <simon@gimp.org>
|
||||
|
||||
Dashed stroking is here... :-)
|
||||
|
||||
* app/core/gimpdrawable-stroke.c: actually use the dash pattern
|
||||
from the options
|
||||
|
||||
* app/core/gimpscanconvert.c: Normalize the dash pattern, so
|
||||
that libart does the right thing.
|
||||
|
||||
* app/core/gimpstrokeoptions.c: Fix default value for dash
|
||||
offset, handle the property_get for PROP_DASH_INFO correct.
|
||||
|
||||
* app/widgets/gimpdasheditor.[ch]
|
||||
* app/widgets/Makefile.am
|
||||
* app/widgets/widgets-types.h: New widget to edit a dash
|
||||
pattern.
|
||||
|
||||
* app/widgets/gimpstrokeeditor.c: Use it.
|
||||
|
||||
2003-12-27 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* app/main.c
|
||||
|
|
|
@ -211,7 +211,6 @@ gimp_drawable_stroke_scan_convert (GimpDrawable *drawable,
|
|||
{
|
||||
/* Stroke options */
|
||||
gdouble width;
|
||||
GArray *dash_array = NULL;
|
||||
TileManager *base;
|
||||
TileManager *mask;
|
||||
gint x, y, w, h;
|
||||
|
@ -260,7 +259,8 @@ gimp_drawable_stroke_scan_convert (GimpDrawable *drawable,
|
|||
options->join_style,
|
||||
options->cap_style,
|
||||
options->miter,
|
||||
0.0, dash_array);
|
||||
options->dash_offset,
|
||||
options->dash_info);
|
||||
|
||||
/* fill a 1-bpp Tilemanager with black, this will describe the shape
|
||||
* of the stroke.
|
||||
|
|
|
@ -295,7 +295,7 @@ gimp_scan_convert_stroke (GimpScanConvert *sc,
|
|||
sc->vpath[i].x *= sc->ratio_xy;
|
||||
}
|
||||
|
||||
if (dash_info)
|
||||
if (dash_info && dash_info->len >= 2)
|
||||
{
|
||||
ArtVpath *dash_vpath;
|
||||
ArtVpathDash dash;
|
||||
|
@ -312,37 +312,94 @@ gimp_scan_convert_stroke (GimpScanConvert *sc,
|
|||
dash.n_dash = dash_info->len;
|
||||
dash.dash = dashes;
|
||||
|
||||
dash_vpath = art_vpath_dash (sc->vpath, &dash);
|
||||
art_free (sc->vpath);
|
||||
sc->vpath = dash_vpath;
|
||||
/* correct 0.0 in the first element (starts with a gap) */
|
||||
|
||||
if (dash.dash[0] == 0.0)
|
||||
{
|
||||
gdouble first;
|
||||
|
||||
first = dash.dash[1];
|
||||
|
||||
/* shift the pattern to really starts with a dash and
|
||||
* use the offset to skip into it.
|
||||
*/
|
||||
for (i=0; i < dash_info->len - 2; i++)
|
||||
{
|
||||
dash.dash[i] = dash.dash[i+2];
|
||||
dash.offset += dash.dash[i];
|
||||
}
|
||||
|
||||
if (dash_info->len % 2 == 1)
|
||||
{
|
||||
dash.dash[dash_info->len - 2] = first;
|
||||
dash.n_dash --;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dash_info->len < 3)
|
||||
{
|
||||
/* empty stroke */
|
||||
art_free (sc->vpath);
|
||||
sc->vpath = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
dash.dash [dash_info->len - 3] += first;
|
||||
dash.n_dash -= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* correct odd number of dash specifiers */
|
||||
|
||||
if (dash.n_dash % 2 == 1)
|
||||
{
|
||||
gdouble last;
|
||||
|
||||
last = dash.dash[dash.n_dash - 1];
|
||||
dash.dash[0] += last;
|
||||
dash.offset += last;
|
||||
dash.n_dash --;
|
||||
}
|
||||
|
||||
|
||||
if (sc->vpath)
|
||||
{
|
||||
dash_vpath = art_vpath_dash (sc->vpath, &dash);
|
||||
art_free (sc->vpath);
|
||||
sc->vpath = dash_vpath;
|
||||
}
|
||||
|
||||
g_free (dashes);
|
||||
}
|
||||
|
||||
stroke = art_svp_vpath_stroke (sc->vpath, artjoin, artcap,
|
||||
width, miter, 0.2);
|
||||
|
||||
if (sc->ratio_xy != 1.0)
|
||||
if (sc->vpath)
|
||||
{
|
||||
ArtSVPSeg *segment;
|
||||
ArtPoint *point;
|
||||
gint i, j;
|
||||
stroke = art_svp_vpath_stroke (sc->vpath, artjoin, artcap,
|
||||
width, miter, 0.2);
|
||||
|
||||
for (i = 0; i < stroke->n_segs; i++)
|
||||
if (sc->ratio_xy != 1.0)
|
||||
{
|
||||
segment = stroke->segs + i;
|
||||
segment->bbox.x0 /= sc->ratio_xy;
|
||||
segment->bbox.x1 /= sc->ratio_xy;
|
||||
ArtSVPSeg *segment;
|
||||
ArtPoint *point;
|
||||
gint i, j;
|
||||
|
||||
for (j=0; j < segment->n_points ; j++)
|
||||
for (i = 0; i < stroke->n_segs; i++)
|
||||
{
|
||||
point = segment->points + j;
|
||||
point->x /= sc->ratio_xy;
|
||||
segment = stroke->segs + i;
|
||||
segment->bbox.x0 /= sc->ratio_xy;
|
||||
segment->bbox.x1 /= sc->ratio_xy;
|
||||
|
||||
for (j=0; j < segment->n_points ; j++)
|
||||
{
|
||||
point = segment->points + j;
|
||||
point->x /= sc->ratio_xy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sc->svp = stroke;
|
||||
sc->svp = stroke;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -367,6 +424,9 @@ gimp_scan_convert_render (GimpScanConvert *sc,
|
|||
|
||||
gimp_scan_convert_finish (sc);
|
||||
|
||||
if (!sc->svp)
|
||||
return;
|
||||
|
||||
pixel_region_init (&maskPR, tile_manager, 0, 0,
|
||||
tile_manager_width (tile_manager),
|
||||
tile_manager_height (tile_manager),
|
||||
|
@ -416,7 +476,9 @@ gimp_scan_convert_finish (GimpScanConvert *sc)
|
|||
ArtVpath *pert_vpath;
|
||||
ArtSVP *svp, *svp2;
|
||||
|
||||
g_return_if_fail (sc->vpath != NULL);
|
||||
/* return gracefully on empty path */
|
||||
if (!sc->vpath)
|
||||
return;
|
||||
|
||||
if (sc->need_closing)
|
||||
gimp_scan_convert_close_add_points (sc);
|
||||
|
|
|
@ -134,7 +134,7 @@ gimp_stroke_options_class_init (GimpStrokeOptionsClass *klass)
|
|||
0);
|
||||
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_DASH_OFFSET,
|
||||
"dash-offset", NULL,
|
||||
0.0, 2000.0, 10.0,
|
||||
0.0, 2000.0, 0.0,
|
||||
0);
|
||||
|
||||
array_spec = g_param_spec_double ("dash-length", NULL, NULL,
|
||||
|
@ -260,11 +260,10 @@ gimp_stroke_options_get_property (GObject *object,
|
|||
case PROP_DASH_INFO:
|
||||
{
|
||||
GValueArray *val_array;
|
||||
GValue item;
|
||||
GValue item = { 0, };
|
||||
gint i;
|
||||
|
||||
if (options->dash_info)
|
||||
g_array_free (options->dash_info, TRUE);
|
||||
g_value_init (&item, G_TYPE_DOUBLE);
|
||||
|
||||
if (options->dash_info == NULL || options->dash_info->len == 0)
|
||||
{
|
||||
|
|
|
@ -63,6 +63,8 @@ libappwidgets_a_sources = \
|
|||
gimpcontainerview-utils.h \
|
||||
gimpcursor.c \
|
||||
gimpcursor.h \
|
||||
gimpdasheditor.c \
|
||||
gimpdasheditor.c \
|
||||
gimpdataeditor.c \
|
||||
gimpdataeditor.h \
|
||||
gimpdatafactoryview.c \
|
||||
|
|
|
@ -0,0 +1,601 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpdasheditor.c
|
||||
* Copyright (C) 2003 Simon Budig <simon@gimp.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpmath/gimpmath.h"
|
||||
|
||||
#include "widgets-types.h"
|
||||
|
||||
#include "config/gimpconfig-params.h"
|
||||
|
||||
#include "core/gimpstrokeoptions.h"
|
||||
|
||||
#include "gimpdasheditor.h"
|
||||
|
||||
|
||||
#define MIN_WIDTH 64
|
||||
#define MIN_HEIGHT 20
|
||||
|
||||
#define DEFAULT_N_SEGMENTS 24
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_STROKE_OPTIONS,
|
||||
PROP_N_SEGMENTS,
|
||||
PROP_LENGTH,
|
||||
};
|
||||
|
||||
|
||||
static void gimp_dash_editor_class_init (GimpDashEditorClass *klass);
|
||||
static void gimp_dash_editor_init (GimpDashEditor *editor);
|
||||
|
||||
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);
|
||||
static void gimp_dash_editor_finalize (GObject *object);
|
||||
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 */
|
||||
static void update_segments_from_options (GimpDashEditor *editor);
|
||||
static void update_options_from_segments (GimpDashEditor *editor);
|
||||
static void update_segments_from_options_cb (GimpStrokeOptions *options,
|
||||
gpointer stuff,
|
||||
GimpDashEditor *editor);
|
||||
static void update_blocksize (GimpDashEditor *editor);
|
||||
static gint dash_x_to_index (GimpDashEditor *editor,
|
||||
gint x);
|
||||
|
||||
|
||||
static gboolean edit_mode = TRUE;
|
||||
static gint edit_button_x0 = 0;
|
||||
|
||||
static GtkDrawingAreaClass *parent_class = NULL;
|
||||
|
||||
|
||||
GType
|
||||
gimp_dash_editor_get_type (void)
|
||||
{
|
||||
static GType editor_type = 0;
|
||||
|
||||
if (! editor_type)
|
||||
{
|
||||
static const GTypeInfo editor_info =
|
||||
{
|
||||
sizeof (GimpDashEditorClass),
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) gimp_dash_editor_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (GimpDashEditor),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) gimp_dash_editor_init,
|
||||
};
|
||||
|
||||
editor_type = g_type_register_static (GTK_TYPE_DRAWING_AREA,
|
||||
"GimpDashEditor",
|
||||
&editor_info, 0);
|
||||
}
|
||||
|
||||
return editor_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_dash_editor_class_init (GimpDashEditorClass *klass)
|
||||
{
|
||||
GObjectClass *object_class;
|
||||
GtkWidgetClass *widget_class;
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class = G_OBJECT_CLASS (klass);
|
||||
widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->get_property = gimp_dash_editor_get_property;
|
||||
object_class->set_property = gimp_dash_editor_set_property;
|
||||
object_class->finalize = gimp_dash_editor_finalize;
|
||||
|
||||
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,
|
||||
g_param_spec_object("stroke-options",
|
||||
NULL, NULL,
|
||||
GIMP_TYPE_STROKE_OPTIONS,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_N_SEGMENTS,
|
||||
"n-segments", NULL,
|
||||
2, 120, DEFAULT_N_SEGMENTS, 0);
|
||||
|
||||
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_LENGTH,
|
||||
"dash-length", NULL,
|
||||
0.0, 2000.0, 0.5 * DEFAULT_N_SEGMENTS,
|
||||
0);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_dash_editor_init (GimpDashEditor *editor)
|
||||
{
|
||||
editor->segments = NULL;
|
||||
|
||||
editor->block_width = 6;
|
||||
editor->block_height = 6;
|
||||
}
|
||||
|
||||
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:
|
||||
editor->stroke_options = GIMP_STROKE_OPTIONS (g_value_dup_object (value));
|
||||
g_object_ref (editor->stroke_options);
|
||||
g_signal_connect_object (editor->stroke_options, "notify::dash-info",
|
||||
(GCallback) update_segments_from_options_cb,
|
||||
editor, 0);
|
||||
break;
|
||||
case PROP_N_SEGMENTS:
|
||||
editor->n_segments = g_value_get_int (value);
|
||||
if (editor->segments)
|
||||
g_free (editor->segments);
|
||||
editor->segments = g_new0 (gboolean, editor->n_segments);
|
||||
update_segments_from_options (editor);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (editor));
|
||||
break;
|
||||
case PROP_LENGTH:
|
||||
editor->dash_length = g_value_get_double (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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_finalize (GObject *object)
|
||||
{
|
||||
GimpDashEditor *editor = GIMP_DASH_EDITOR (object);
|
||||
|
||||
if (editor->stroke_options)
|
||||
{
|
||||
g_object_unref (editor->stroke_options);
|
||||
editor->stroke_options = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
gint x, index, w, h;
|
||||
|
||||
update_blocksize (editor);
|
||||
|
||||
/* Draw the background */
|
||||
gdk_draw_rectangle (widget->window,
|
||||
widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
|
||||
0, 0,
|
||||
widget->allocation.width,
|
||||
widget->allocation.height);
|
||||
|
||||
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;
|
||||
|
||||
x = editor->x0 % w;
|
||||
|
||||
if (x > 0)
|
||||
x -= w;
|
||||
|
||||
for (; x < widget->allocation.width + w; x += w)
|
||||
{
|
||||
index = dash_x_to_index (editor, x);
|
||||
|
||||
if (x < editor->x0 || x >= editor->x0 + editor->n_segments * w)
|
||||
{
|
||||
if (editor->segments[index])
|
||||
{
|
||||
gdk_draw_rectangle (widget->window,
|
||||
widget->style->text_aa_gc[GTK_STATE_NORMAL],
|
||||
TRUE,
|
||||
x, editor->y0,
|
||||
w, h);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (editor->segments[index])
|
||||
{
|
||||
gdk_draw_rectangle (widget->window,
|
||||
widget->style->text_gc[GTK_STATE_NORMAL],
|
||||
TRUE,
|
||||
x, editor->y0,
|
||||
w, h);
|
||||
}
|
||||
|
||||
if (editor->n_segments % 4 == 0 &&
|
||||
(index + 1) % (editor->n_segments / 4) == 0)
|
||||
{
|
||||
gdk_draw_line (widget->window,
|
||||
widget->style->text_aa_gc[GTK_STATE_NORMAL],
|
||||
x + w - 1, editor->y0 - 2,
|
||||
x + w - 1, editor->y0 + h + 1);
|
||||
}
|
||||
else if (index % 2 == 1)
|
||||
{
|
||||
gdk_draw_line (widget->window,
|
||||
widget->style->text_aa_gc[GTK_STATE_NORMAL],
|
||||
x + w - 1, editor->y0 + 1,
|
||||
x + w - 1, editor->y0 + h - 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
gdk_draw_line (widget->window,
|
||||
widget->style->text_aa_gc[GTK_STATE_NORMAL],
|
||||
x + w - 1, editor->y0 + h / 2 - 1,
|
||||
x + w - 1, editor->y0 + h / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gdk_draw_line (widget->window,
|
||||
widget->style->text_aa_gc[GTK_STATE_NORMAL],
|
||||
editor->x0 - 1, editor->y0 - 1,
|
||||
editor->x0 - 1, editor->y0 + h);
|
||||
|
||||
gtk_paint_shadow (widget->style, widget->window,
|
||||
GTK_STATE_NORMAL, GTK_SHADOW_IN,
|
||||
NULL, widget, NULL,
|
||||
0, 0,
|
||||
widget->allocation.width,
|
||||
widget->allocation.height);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_dash_editor_button_press (GtkWidget *widget,
|
||||
GdkEventButton *bevent)
|
||||
{
|
||||
GimpDashEditor *editor = GIMP_DASH_EDITOR (widget);
|
||||
gint index;
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
gdk_pointer_grab (widget->window, FALSE,
|
||||
GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK,
|
||||
NULL, NULL, bevent->time);
|
||||
index = dash_x_to_index (editor, bevent->x);
|
||||
|
||||
edit_mode = ! editor->segments [index];
|
||||
edit_button_x0 = bevent->x;
|
||||
|
||||
editor->segments [index] = edit_mode;
|
||||
|
||||
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);
|
||||
editor->segments [index] = edit_mode;
|
||||
|
||||
if (mevent->x > edit_button_x0)
|
||||
{
|
||||
for (x = edit_button_x0; x < mevent->x; x += editor->block_width)
|
||||
{
|
||||
index = dash_x_to_index (editor, x);
|
||||
editor->segments [index] = edit_mode;
|
||||
}
|
||||
}
|
||||
|
||||
if (mevent->x < edit_button_x0)
|
||||
{
|
||||
for (x = edit_button_x0; x > mevent->x; x -= editor->block_width)
|
||||
{
|
||||
index = dash_x_to_index (editor, x);
|
||||
editor->segments [index] = edit_mode;
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_queue_draw (widget);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gimp_dash_editor_new (GimpStrokeOptions *stroke_options)
|
||||
{
|
||||
GimpDashEditor *editor;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_STROKE_OPTIONS (stroke_options), NULL);
|
||||
|
||||
editor = g_object_new (GIMP_TYPE_DASH_EDITOR,
|
||||
"stroke-options", stroke_options,
|
||||
"n-segments", DEFAULT_N_SEGMENTS,
|
||||
"dash-length", 0.5 * DEFAULT_N_SEGMENTS,
|
||||
NULL);
|
||||
|
||||
update_segments_from_options (editor);
|
||||
|
||||
gtk_widget_add_events (GTK_WIDGET (editor),
|
||||
GDK_BUTTON_PRESS_MASK |
|
||||
GDK_BUTTON_RELEASE_MASK |
|
||||
GDK_BUTTON1_MOTION_MASK);
|
||||
|
||||
return GTK_WIDGET (editor);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
update_segments_from_options (GimpDashEditor *editor)
|
||||
{
|
||||
gdouble factor, sum = 0;
|
||||
gint i, j;
|
||||
gboolean paint;
|
||||
GArray *dash_info;
|
||||
|
||||
g_return_if_fail (GIMP_IS_STROKE_OPTIONS (editor->stroke_options));
|
||||
g_return_if_fail (editor->segments != NULL);
|
||||
|
||||
dash_info = editor->stroke_options->dash_info;
|
||||
|
||||
if (dash_info == NULL || dash_info->len <= 1)
|
||||
{
|
||||
for (i = 0; i < editor->n_segments; i++)
|
||||
editor->segments[i] = TRUE;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < dash_info->len ; i++)
|
||||
{
|
||||
sum += g_array_index (dash_info, gdouble, i);
|
||||
}
|
||||
|
||||
factor = ((gdouble) editor->n_segments) / sum;
|
||||
|
||||
j = 0;
|
||||
sum = g_array_index (dash_info, gdouble, j) * factor;
|
||||
paint = TRUE;
|
||||
|
||||
for (i = 0; i < editor->n_segments ; i++)
|
||||
{
|
||||
while (j < dash_info->len && sum <= i)
|
||||
{
|
||||
paint = ! paint;
|
||||
j++;
|
||||
sum += g_array_index (dash_info, gdouble, j) * factor;
|
||||
}
|
||||
|
||||
editor->segments[i] = paint;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
update_segments_from_options_cb (GimpStrokeOptions *options,
|
||||
gpointer stuff,
|
||||
GimpDashEditor *editor)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_STROKE_OPTIONS (options));
|
||||
g_return_if_fail (GIMP_IS_DASH_EDITOR (editor));
|
||||
|
||||
update_segments_from_options (editor);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (editor));
|
||||
}
|
||||
|
||||
static void
|
||||
update_options_from_segments (GimpDashEditor *editor)
|
||||
{
|
||||
gint i, count = 0;
|
||||
gboolean state;
|
||||
GArray *dash_array;
|
||||
|
||||
GValueArray *val_array;
|
||||
GValue item = { 0, };
|
||||
GValue value = { 0, };
|
||||
|
||||
g_value_init (&item, G_TYPE_DOUBLE);
|
||||
g_value_init (&value, G_TYPE_VALUE_ARRAY);
|
||||
|
||||
dash_array = g_array_new (FALSE, FALSE, sizeof (gdouble));
|
||||
|
||||
state = TRUE;
|
||||
|
||||
for (i = 0; i <= editor->n_segments; i++)
|
||||
{
|
||||
if (i < editor->n_segments && editor->segments[i] == state)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
gdouble l = (editor->dash_length * count) / editor->n_segments;
|
||||
dash_array = g_array_append_val (dash_array, l);
|
||||
|
||||
count = 1;
|
||||
state = ! state;
|
||||
}
|
||||
}
|
||||
|
||||
if (dash_array->len > 1)
|
||||
{
|
||||
val_array = g_value_array_new (dash_array->len);
|
||||
|
||||
for (i=0; i < dash_array->len; i++)
|
||||
{
|
||||
g_value_set_double (&item, g_array_index (dash_array,
|
||||
gdouble,
|
||||
i));
|
||||
g_value_array_append (val_array, &item);
|
||||
}
|
||||
|
||||
g_value_set_boxed (&value, val_array);
|
||||
|
||||
g_object_set_property (G_OBJECT (editor->stroke_options),
|
||||
"dash-info",
|
||||
&value);
|
||||
|
||||
g_value_array_free (val_array);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_value_set_boxed (&value, NULL);
|
||||
g_object_set_property (G_OBJECT (editor->stroke_options),
|
||||
"dash-info",
|
||||
&value);
|
||||
}
|
||||
|
||||
g_array_free (dash_array, TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
update_blocksize (GimpDashEditor *editor)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
|
||||
widget = GTK_WIDGET (editor);
|
||||
|
||||
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)
|
||||
{
|
||||
gint index;
|
||||
|
||||
index = x - editor->x0;
|
||||
while (index < 0)
|
||||
index += editor->n_segments * editor->block_width;
|
||||
|
||||
index = (index / editor->block_width) % editor->n_segments;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpdasheditor.h
|
||||
* Copyright (C) 2003 Simon Budig <simon@gimp.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_DASH_EDITOR_H__
|
||||
#define __GIMP_DASH_EDITOR_H__
|
||||
|
||||
|
||||
#include <gtk/gtkdrawingarea.h>
|
||||
|
||||
|
||||
#define GIMP_TYPE_DASH_EDITOR (gimp_dash_editor_get_type ())
|
||||
#define GIMP_DASH_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_DASH_EDITOR, GimpDashEditor))
|
||||
#define GIMP_DASH_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_DASH_EDITOR, GimpDashEditorClass))
|
||||
#define GIMP_IS_DASH_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_DASH_EDITOR))
|
||||
#define GIMP_IS_DASH_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_DASH_EDITOR))
|
||||
#define GIMP_DASH_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_DASH_EDITOR, GimpDashEditor))
|
||||
|
||||
|
||||
typedef struct _GimpDashEditorClass GimpDashEditorClass;
|
||||
|
||||
struct _GimpDashEditor
|
||||
{
|
||||
GtkDrawingArea parent_instance;
|
||||
|
||||
GimpStrokeOptions *stroke_options;
|
||||
gdouble dash_length;
|
||||
|
||||
/* GUI stuff */
|
||||
gint n_segments;
|
||||
gboolean *segments;
|
||||
|
||||
/* coordinates of the first block main dash pattern */
|
||||
gint x0;
|
||||
gint y0;
|
||||
gint block_width;
|
||||
gint block_height;
|
||||
};
|
||||
|
||||
struct _GimpDashEditorClass
|
||||
{
|
||||
GtkDrawingAreaClass parent_class;
|
||||
|
||||
/*
|
||||
void (* range_changed) (GimpDashEditor *view,
|
||||
gint start,
|
||||
gint end);
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
GType gimp_dash_editor_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget * gimp_dash_editor_new (GimpStrokeOptions *stroke_options);
|
||||
|
||||
#endif /* __GIMP_DASH_EDITOR_H__ */
|
|
@ -28,6 +28,7 @@
|
|||
#include "core/gimpstrokeoptions.h"
|
||||
|
||||
#include "gimppropwidgets.h"
|
||||
#include "gimpdasheditor.h"
|
||||
#include "gimpstrokeeditor.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
@ -148,7 +149,7 @@ gimp_stroke_editor_get_property (GObject *object,
|
|||
case PROP_OPTIONS:
|
||||
g_value_set_object (value, editor->options);
|
||||
break;
|
||||
case PROP_RESOLUTION:
|
||||
case PROP_RESOLUTION:
|
||||
g_value_set_double (value, editor->resolution);
|
||||
break;
|
||||
|
||||
|
@ -167,6 +168,7 @@ gimp_stroke_editor_constructor (GType type,
|
|||
GtkWidget *table;
|
||||
GtkWidget *box;
|
||||
GtkWidget *size;
|
||||
GtkWidget *dash_editor;
|
||||
GtkWidget *button;
|
||||
GObject *object;
|
||||
gint row = 0;
|
||||
|
@ -210,6 +212,11 @@ gimp_stroke_editor_constructor (GType type,
|
|||
1.0, 1.0, 1,
|
||||
FALSE, 0.0, 0.0);
|
||||
|
||||
dash_editor = gimp_dash_editor_new (editor->options);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
|
||||
_("Dash Pattern:"), 1.0, 0.5, dash_editor, 1, FALSE);
|
||||
gtk_widget_show (dash_editor);
|
||||
|
||||
button = gimp_prop_check_button_new (G_OBJECT (editor->options), "antialias",
|
||||
_("_Antialiasing"));
|
||||
gtk_table_attach (GTK_TABLE (table), button, 0, 2, row, row + 1,
|
||||
|
|
|
@ -110,6 +110,8 @@ typedef struct _GimpHistogramView GimpHistogramView;
|
|||
typedef struct _GimpHistogramBox GimpHistogramBox;
|
||||
typedef struct _GimpHistogramEditor GimpHistogramEditor;
|
||||
|
||||
typedef struct _GimpDashEditor GimpDashEditor;
|
||||
|
||||
typedef struct _GimpTextEditor GimpTextEditor;
|
||||
typedef struct _GimpColorDisplayEditor GimpColorDisplayEditor;
|
||||
|
||||
|
|
Loading…
Reference in New Issue