2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-09-26 23:37:53 +08:00
|
|
|
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpstrokeoptions.c
|
|
|
|
* Copyright (C) 2003 Simon Budig
|
|
|
|
*
|
|
|
|
* 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 <glib-object.h>
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2003-09-26 23:37:53 +08:00
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
2005-05-19 06:50:54 +08:00
|
|
|
#include "gimpdashpattern.h"
|
2003-12-29 01:09:41 +08:00
|
|
|
#include "gimpmarshal.h"
|
2003-09-26 23:37:53 +08:00
|
|
|
#include "gimpstrokeoptions.h"
|
|
|
|
|
2005-05-19 23:17:30 +08:00
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
2004-05-24 22:51:15 +08:00
|
|
|
|
2003-09-26 23:37:53 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2003-09-28 04:04:07 +08:00
|
|
|
PROP_STYLE,
|
2003-09-26 23:37:53 +08:00
|
|
|
PROP_WIDTH,
|
2003-09-29 19:13:21 +08:00
|
|
|
PROP_UNIT,
|
2003-09-26 23:37:53 +08:00
|
|
|
PROP_CAP_STYLE,
|
|
|
|
PROP_JOIN_STYLE,
|
2005-05-19 23:17:30 +08:00
|
|
|
PROP_MITER_LIMIT,
|
2003-09-26 23:37:53 +08:00
|
|
|
PROP_ANTIALIAS,
|
2003-09-27 22:58:46 +08:00
|
|
|
PROP_DASH_UNIT,
|
2003-09-26 23:37:53 +08:00
|
|
|
PROP_DASH_OFFSET,
|
|
|
|
PROP_DASH_INFO
|
|
|
|
};
|
|
|
|
|
2003-12-29 01:09:41 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
DASH_INFO_CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
2003-09-26 23:37:53 +08:00
|
|
|
|
2004-05-24 22:51:15 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static void gimp_stroke_options_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_stroke_options_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2005-05-19 07:26:53 +08:00
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpStrokeOptions, gimp_stroke_options, GIMP_TYPE_CONTEXT)
|
2003-09-26 23:37:53 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static guint stroke_options_signals[LAST_SIGNAL] = { 0 };
|
2003-09-26 23:37:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_stroke_options_class_init (GimpStrokeOptionsClass *klass)
|
|
|
|
{
|
2004-05-24 22:51:15 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2003-09-26 23:37:53 +08:00
|
|
|
GParamSpec *array_spec;
|
|
|
|
|
2004-05-24 22:51:15 +08:00
|
|
|
object_class->set_property = gimp_stroke_options_set_property;
|
|
|
|
object_class->get_property = gimp_stroke_options_get_property;
|
2003-12-29 01:09:41 +08:00
|
|
|
|
|
|
|
klass->dash_info_changed = NULL;
|
|
|
|
|
2004-05-24 22:51:15 +08:00
|
|
|
stroke_options_signals[DASH_INFO_CHANGED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_new ("dash-info-changed",
|
2004-05-24 22:51:15 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpStrokeOptionsClass, dash_info_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__ENUM,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
GIMP_TYPE_DASH_PRESET);
|
2003-09-26 23:37:53 +08:00
|
|
|
|
2003-09-28 04:04:07 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_STYLE,
|
|
|
|
"style", NULL,
|
|
|
|
GIMP_TYPE_STROKE_STYLE,
|
|
|
|
GIMP_STROKE_STYLE_SOLID,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2003-09-27 22:58:46 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_WIDTH,
|
|
|
|
"width", NULL,
|
2003-11-13 11:27:21 +08:00
|
|
|
0.0, 2000.0, 6.0,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2003-09-29 19:13:21 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_UNIT (object_class, PROP_UNIT,
|
2006-04-12 20:49:29 +08:00
|
|
|
"unit", NULL,
|
|
|
|
TRUE, FALSE, GIMP_UNIT_PIXEL,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2003-09-27 22:58:46 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_CAP_STYLE,
|
|
|
|
"cap-style", NULL,
|
|
|
|
GIMP_TYPE_CAP_STYLE, GIMP_CAP_BUTT,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2003-09-27 22:58:46 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_JOIN_STYLE,
|
|
|
|
"join-style", NULL,
|
|
|
|
GIMP_TYPE_JOIN_STYLE, GIMP_JOIN_MITER,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2005-05-19 23:17:30 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_MITER_LIMIT,
|
|
|
|
"miter-limit",
|
|
|
|
_("Convert a mitered join to a bevelled "
|
|
|
|
"join if the miter would extend to a "
|
|
|
|
"distance of more than miter-limit * "
|
|
|
|
"line-width from the actual join point."),
|
2003-09-27 22:58:46 +08:00
|
|
|
0.0, 100.0, 10.0,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2003-09-27 22:58:46 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_ANTIALIAS,
|
|
|
|
"antialias", NULL,
|
|
|
|
TRUE,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2003-09-27 22:58:46 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_DASH_OFFSET,
|
|
|
|
"dash-offset", NULL,
|
2003-12-28 03:25:19 +08:00
|
|
|
0.0, 2000.0, 0.0,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2003-09-26 23:37:53 +08:00
|
|
|
|
|
|
|
array_spec = g_param_spec_double ("dash-length", NULL, NULL,
|
2006-01-19 04:29:40 +08:00
|
|
|
0.0, 2000.0, 1.0, GIMP_PARAM_READWRITE);
|
2003-09-26 23:37:53 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_DASH_INFO,
|
|
|
|
g_param_spec_value_array ("dash-info",
|
|
|
|
NULL, NULL,
|
|
|
|
array_spec,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
2003-09-27 22:58:46 +08:00
|
|
|
GIMP_CONFIG_PARAM_FLAGS));
|
2003-09-26 23:37:53 +08:00
|
|
|
}
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static void
|
|
|
|
gimp_stroke_options_init (GimpStrokeOptions *options)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-09-26 23:37:53 +08:00
|
|
|
static void
|
|
|
|
gimp_stroke_options_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2003-09-28 04:04:07 +08:00
|
|
|
GimpStrokeOptions *options = GIMP_STROKE_OPTIONS (object);
|
2003-09-26 23:37:53 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2003-09-28 04:04:07 +08:00
|
|
|
case PROP_STYLE:
|
|
|
|
options->style = g_value_get_enum (value);
|
|
|
|
break;
|
2003-09-26 23:37:53 +08:00
|
|
|
case PROP_WIDTH:
|
|
|
|
options->width = g_value_get_double (value);
|
|
|
|
break;
|
2003-09-29 19:13:21 +08:00
|
|
|
case PROP_UNIT:
|
|
|
|
options->unit = g_value_get_int (value);
|
2003-09-27 22:58:46 +08:00
|
|
|
break;
|
2003-09-26 23:37:53 +08:00
|
|
|
case PROP_CAP_STYLE:
|
2003-09-27 10:34:18 +08:00
|
|
|
options->cap_style = g_value_get_enum (value);
|
2003-09-26 23:37:53 +08:00
|
|
|
break;
|
|
|
|
case PROP_JOIN_STYLE:
|
2003-09-27 10:34:18 +08:00
|
|
|
options->join_style = g_value_get_enum (value);
|
2003-09-26 23:37:53 +08:00
|
|
|
break;
|
2005-05-19 23:17:30 +08:00
|
|
|
case PROP_MITER_LIMIT:
|
|
|
|
options->miter_limit = g_value_get_double (value);
|
2003-09-26 23:37:53 +08:00
|
|
|
break;
|
|
|
|
case PROP_ANTIALIAS:
|
|
|
|
options->antialias = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case PROP_DASH_OFFSET:
|
|
|
|
options->dash_offset = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
case PROP_DASH_INFO:
|
2007-01-13 04:27:40 +08:00
|
|
|
{
|
|
|
|
GValueArray *value_array = g_value_get_boxed (value);
|
|
|
|
GArray *pattern;
|
|
|
|
|
|
|
|
pattern = gimp_dash_pattern_from_value_array (value_array);
|
|
|
|
gimp_stroke_options_set_dash_pattern (options, GIMP_DASH_CUSTOM,
|
|
|
|
pattern);
|
|
|
|
}
|
2003-09-26 23:37:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_stroke_options_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2003-09-28 04:04:07 +08:00
|
|
|
GimpStrokeOptions *options = GIMP_STROKE_OPTIONS (object);
|
2003-09-26 23:37:53 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2003-09-28 04:04:07 +08:00
|
|
|
case PROP_STYLE:
|
|
|
|
g_value_set_enum (value, options->style);
|
|
|
|
break;
|
2003-09-26 23:37:53 +08:00
|
|
|
case PROP_WIDTH:
|
|
|
|
g_value_set_double (value, options->width);
|
|
|
|
break;
|
2003-09-29 19:13:21 +08:00
|
|
|
case PROP_UNIT:
|
|
|
|
g_value_set_int (value, options->unit);
|
2003-09-27 22:58:46 +08:00
|
|
|
break;
|
2003-09-26 23:37:53 +08:00
|
|
|
case PROP_CAP_STYLE:
|
2003-09-27 10:34:18 +08:00
|
|
|
g_value_set_enum (value, options->cap_style);
|
2003-09-26 23:37:53 +08:00
|
|
|
break;
|
|
|
|
case PROP_JOIN_STYLE:
|
2003-09-27 10:34:18 +08:00
|
|
|
g_value_set_enum (value, options->join_style);
|
2003-09-26 23:37:53 +08:00
|
|
|
break;
|
2005-05-19 23:17:30 +08:00
|
|
|
case PROP_MITER_LIMIT:
|
|
|
|
g_value_set_double (value, options->miter_limit);
|
2003-09-26 23:37:53 +08:00
|
|
|
break;
|
|
|
|
case PROP_ANTIALIAS:
|
|
|
|
g_value_set_boolean (value, options->antialias);
|
|
|
|
break;
|
|
|
|
case PROP_DASH_OFFSET:
|
|
|
|
g_value_set_double (value, options->dash_offset);
|
|
|
|
break;
|
|
|
|
case PROP_DASH_INFO:
|
2007-01-13 04:27:40 +08:00
|
|
|
{
|
|
|
|
GValueArray *value_array;
|
|
|
|
|
|
|
|
value_array = gimp_dash_pattern_to_value_array (options->dash_info);
|
|
|
|
g_value_take_boxed (value, value_array);
|
|
|
|
}
|
2003-09-26 23:37:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-12-29 01:09:41 +08:00
|
|
|
|
2005-05-19 19:08:50 +08:00
|
|
|
/**
|
|
|
|
* gimp_stroke_options_set_dash_pattern:
|
|
|
|
* @options: a #GimpStrokeOptions object
|
|
|
|
* @preset: a value out of the #GimpDashPreset enum
|
|
|
|
* @pattern: a #GArray or %NULL if @preset is not %GIMP_DASH_CUSTOM
|
|
|
|
*
|
|
|
|
* Sets the dash pattern. Either a @preset is passed and @pattern is
|
|
|
|
* %NULL or @preset is %GIMP_DASH_CUSTOM and @pattern is the #GArray
|
|
|
|
* to use as the dash pattern. Note that this function takes ownership
|
|
|
|
* of the passed pattern.
|
|
|
|
*/
|
2003-12-29 01:09:41 +08:00
|
|
|
void
|
2005-05-19 19:08:50 +08:00
|
|
|
gimp_stroke_options_set_dash_pattern (GimpStrokeOptions *options,
|
|
|
|
GimpDashPreset preset,
|
|
|
|
GArray *pattern)
|
2003-12-29 01:09:41 +08:00
|
|
|
{
|
2005-05-19 19:08:50 +08:00
|
|
|
g_return_if_fail (GIMP_IS_STROKE_OPTIONS (options));
|
|
|
|
g_return_if_fail (preset == GIMP_DASH_CUSTOM || pattern == NULL);
|
2003-12-29 01:09:41 +08:00
|
|
|
|
2005-05-19 19:08:50 +08:00
|
|
|
if (preset != GIMP_DASH_CUSTOM)
|
2007-01-13 04:27:40 +08:00
|
|
|
pattern = gimp_dash_pattern_new_from_preset (preset);
|
2005-05-19 07:26:53 +08:00
|
|
|
|
|
|
|
if (options->dash_info)
|
2007-01-13 04:27:40 +08:00
|
|
|
gimp_dash_pattern_free (options->dash_info);
|
2003-12-29 01:09:41 +08:00
|
|
|
|
2005-05-19 07:26:53 +08:00
|
|
|
options->dash_info = pattern;
|
2003-12-29 01:09:41 +08:00
|
|
|
|
2005-05-19 19:08:50 +08:00
|
|
|
g_object_notify (G_OBJECT (options), "dash-info");
|
|
|
|
|
2007-01-13 04:27:40 +08:00
|
|
|
g_signal_emit (options, stroke_options_signals [DASH_INFO_CHANGED], 0,
|
2003-12-29 01:09:41 +08:00
|
|
|
preset);
|
|
|
|
}
|