app: add a "custom" guide concept.

With gimp_guide_custom_new(), you can create a custom guide with a different
style on canvas (other pattern/color/width). A custom guide won't be saved
and could be used, for instance, for specific GEGL op guiding.
This commit is contained in:
Jehan
2015-12-15 02:54:04 +01:00
parent b6a756f284
commit b8fadf3ad7
12 changed files with 348 additions and 79 deletions

View File

@ -38,7 +38,9 @@ enum
PROP_0,
PROP_ORIENTATION,
PROP_POSITION,
PROP_GUIDE_STYLE
PROP_NORMAL_STYLE,
PROP_ACTIVE_STYLE,
PROP_LINE_WIDTH
};
@ -46,9 +48,12 @@ typedef struct _GimpCanvasGuidePrivate GimpCanvasGuidePrivate;
struct _GimpCanvasGuidePrivate
{
GimpOrientationType orientation;
gint position;
gboolean guide_style;
GimpOrientationType orientation;
gint position;
cairo_pattern_t *active_style;
cairo_pattern_t *normal_style;
gdouble line_width;
};
#define GET_PRIVATE(guide) \
@ -59,6 +64,7 @@ struct _GimpCanvasGuidePrivate
/* local function prototypes */
static void gimp_canvas_guide_finalize (GObject *object);
static void gimp_canvas_guide_set_property (GObject *object,
guint property_id,
const GValue *value,
@ -85,6 +91,7 @@ gimp_canvas_guide_class_init (GimpCanvasGuideClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpCanvasItemClass *item_class = GIMP_CANVAS_ITEM_CLASS (klass);
object_class->finalize = gimp_canvas_guide_finalize;
object_class->set_property = gimp_canvas_guide_set_property;
object_class->get_property = gimp_canvas_guide_get_property;
@ -104,11 +111,20 @@ gimp_canvas_guide_class_init (GimpCanvasGuideClass *klass)
GIMP_MAX_IMAGE_SIZE, 0,
GIMP_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_GUIDE_STYLE,
g_param_spec_boolean ("guide-style",
NULL, NULL,
FALSE,
GIMP_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_NORMAL_STYLE,
g_param_spec_pointer ("normal-style", NULL, NULL,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_ACTIVE_STYLE,
g_param_spec_pointer ("active-style", NULL, NULL,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_LINE_WIDTH,
g_param_spec_double ("line-width", NULL, NULL,
0, GIMP_MAX_IMAGE_SIZE,
1.0,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (klass, sizeof (GimpCanvasGuidePrivate));
}
@ -118,6 +134,17 @@ gimp_canvas_guide_init (GimpCanvasGuide *guide)
{
}
static void
gimp_canvas_guide_finalize (GObject *object)
{
GimpCanvasGuidePrivate *private = GET_PRIVATE (object);
cairo_pattern_destroy (private->normal_style);
cairo_pattern_destroy (private->active_style);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_canvas_guide_set_property (GObject *object,
guint property_id,
@ -134,8 +161,18 @@ gimp_canvas_guide_set_property (GObject *object,
case PROP_POSITION:
private->position = g_value_get_int (value);
break;
case PROP_GUIDE_STYLE:
private->guide_style = g_value_get_boolean (value);
case PROP_NORMAL_STYLE:
if (private->normal_style)
cairo_pattern_destroy (private->normal_style);
private->normal_style = g_value_get_pointer (value);
break;
case PROP_ACTIVE_STYLE:
if (private->active_style)
cairo_pattern_destroy (private->active_style);
private->active_style = g_value_get_pointer (value);
break;
case PROP_LINE_WIDTH:
private->line_width = g_value_get_double (value);
break;
default:
@ -160,8 +197,14 @@ gimp_canvas_guide_get_property (GObject *object,
case PROP_POSITION:
g_value_set_int (value, private->position);
break;
case PROP_GUIDE_STYLE:
g_value_set_boolean (value, private->guide_style);
case PROP_NORMAL_STYLE:
g_value_set_pointer (value, private->normal_style);
break;
case PROP_ACTIVE_STYLE:
g_value_set_pointer (value, private->active_style);
break;
case PROP_LINE_WIDTH:
g_value_set_double (value, private->line_width);
break;
default:
@ -247,10 +290,18 @@ gimp_canvas_guide_stroke (GimpCanvasItem *item,
{
GimpCanvasGuidePrivate *private = GET_PRIVATE (item);
if (private->guide_style)
if (private->active_style &&
gimp_canvas_item_get_highlight (item))
{
gimp_canvas_set_guide_style (gimp_canvas_item_get_canvas (item), cr,
gimp_canvas_item_get_highlight (item));
cairo_set_line_width (cr, private->line_width);
cairo_set_source (cr, private->active_style);
cairo_stroke (cr);
}
else if (private->normal_style &&
! gimp_canvas_item_get_highlight (item))
{
cairo_set_line_width (cr, private->line_width);
cairo_set_source (cr, private->normal_style);
cairo_stroke (cr);
}
else
@ -263,15 +314,19 @@ GimpCanvasItem *
gimp_canvas_guide_new (GimpDisplayShell *shell,
GimpOrientationType orientation,
gint position,
gboolean guide_style)
cairo_pattern_t *normal_style,
cairo_pattern_t *active_style,
gdouble line_width)
{
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);
return g_object_new (GIMP_TYPE_CANVAS_GUIDE,
"shell", shell,
"orientation", orientation,
"position", position,
"guide-style", guide_style,
"shell", shell,
"orientation", orientation,
"position", position,
"normal-style", normal_style,
"active-style", active_style,
"line-width", line_width,
NULL);
}