app: Refactor path code to support styles and add outline style for use in brush outline
This commit is contained in:
@ -154,6 +154,37 @@ gimp_handle_anchor_get_type (void)
|
||||
return type;
|
||||
}
|
||||
|
||||
GType
|
||||
gimp_path_style_get_type (void)
|
||||
{
|
||||
static const GEnumValue values[] =
|
||||
{
|
||||
{ GIMP_PATH_STYLE_DEFAULT, "GIMP_PATH_STYLE_DEFAULT", "default" },
|
||||
{ GIMP_PATH_STYLE_VECTORS, "GIMP_PATH_STYLE_VECTORS", "vectors" },
|
||||
{ GIMP_PATH_STYLE_OUTLINE, "GIMP_PATH_STYLE_OUTLINE", "outline" },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
static const GimpEnumDesc descs[] =
|
||||
{
|
||||
{ GIMP_PATH_STYLE_DEFAULT, "GIMP_PATH_STYLE_DEFAULT", NULL },
|
||||
{ GIMP_PATH_STYLE_VECTORS, "GIMP_PATH_STYLE_VECTORS", NULL },
|
||||
{ GIMP_PATH_STYLE_OUTLINE, "GIMP_PATH_STYLE_OUTLINE", NULL },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
static GType type = 0;
|
||||
|
||||
if (G_UNLIKELY (! type))
|
||||
{
|
||||
type = g_enum_register_static ("GimpPathStyle", values);
|
||||
gimp_type_set_translation_context (type, "path-style");
|
||||
gimp_enum_set_value_descriptions (type, descs);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
GType
|
||||
gimp_zoom_focus_get_type (void)
|
||||
{
|
||||
|
@ -77,6 +77,17 @@ typedef enum
|
||||
GIMP_HANDLE_ANCHOR_EAST
|
||||
} GimpHandleAnchor;
|
||||
|
||||
#define GIMP_TYPE_PATH_STYLE (gimp_path_style_get_type ())
|
||||
|
||||
GType gimp_path_style_get_type (void) G_GNUC_CONST;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GIMP_PATH_STYLE_DEFAULT = 0,
|
||||
GIMP_PATH_STYLE_VECTORS,
|
||||
GIMP_PATH_STYLE_OUTLINE
|
||||
} GimpPathStyle;
|
||||
|
||||
|
||||
#define GIMP_TYPE_ZOOM_FOCUS (gimp_zoom_focus_get_type ())
|
||||
|
||||
|
@ -56,7 +56,7 @@ struct _GimpCanvasPathPrivate
|
||||
gdouble x;
|
||||
gdouble y;
|
||||
gboolean filled;
|
||||
gboolean path_style;
|
||||
GimpPathStyle path_style;
|
||||
};
|
||||
|
||||
#define GET_PRIVATE(path) \
|
||||
@ -64,7 +64,6 @@ struct _GimpCanvasPathPrivate
|
||||
GIMP_TYPE_CANVAS_PATH, \
|
||||
GimpCanvasPathPrivate)
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static void gimp_canvas_path_finalize (GObject *object);
|
||||
@ -128,11 +127,12 @@ gimp_canvas_path_class_init (GimpCanvasPathClass *klass)
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
|
||||
g_object_class_install_property (object_class, PROP_PATH_STYLE,
|
||||
g_param_spec_boolean ("path-style",
|
||||
NULL, NULL,
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
g_param_spec_enum ("path-style", NULL, NULL,
|
||||
GIMP_TYPE_PATH_STYLE,
|
||||
GIMP_PATH_STYLE_DEFAULT,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GimpCanvasPathPrivate));
|
||||
}
|
||||
@ -181,7 +181,7 @@ gimp_canvas_path_set_property (GObject *object,
|
||||
private->filled = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_PATH_STYLE:
|
||||
private->path_style = g_value_get_boolean (value);
|
||||
private->path_style = g_value_get_enum (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -213,7 +213,7 @@ gimp_canvas_path_get_property (GObject *object,
|
||||
g_value_set_boolean (value, private->filled);
|
||||
break;
|
||||
case PROP_PATH_STYLE:
|
||||
g_value_set_boolean (value, private->path_style);
|
||||
g_value_set_enum (value, private->path_style);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -299,40 +299,50 @@ gimp_canvas_path_stroke (GimpCanvasItem *item,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GimpCanvasPathPrivate *private = GET_PRIVATE (item);
|
||||
gboolean active;
|
||||
cairo_pattern_t *pattern;
|
||||
|
||||
if (private->path_style)
|
||||
switch (private->path_style)
|
||||
{
|
||||
gboolean active = gimp_canvas_item_get_highlight (item);
|
||||
case GIMP_PATH_STYLE_VECTORS:
|
||||
active = gimp_canvas_item_get_highlight (item);
|
||||
|
||||
gimp_display_shell_set_vectors_bg_style (shell, cr, active);
|
||||
cairo_stroke_preserve (cr);
|
||||
|
||||
gimp_display_shell_set_vectors_fg_style (shell, cr, active);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
case GIMP_PATH_STYLE_OUTLINE:
|
||||
gimp_display_shell_set_outline_bg_style (shell, cr);
|
||||
cairo_stroke_preserve (cr);
|
||||
|
||||
gimp_display_shell_set_outline_fg_style (shell, cr);
|
||||
cairo_stroke (cr);
|
||||
break;
|
||||
case GIMP_PATH_STYLE_DEFAULT:
|
||||
GIMP_CANVAS_ITEM_CLASS (parent_class)->stroke (item, shell, cr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GimpCanvasItem *
|
||||
gimp_canvas_path_new (GimpDisplayShell *shell,
|
||||
const GimpBezierDesc *bezier,
|
||||
GimpPathStyle path_style,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gboolean filled,
|
||||
gboolean path_style)
|
||||
gboolean filled)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);
|
||||
|
||||
return g_object_new (GIMP_TYPE_CANVAS_PATH,
|
||||
"shell", shell,
|
||||
"path", bezier,
|
||||
"path-style", path_style,
|
||||
"x", x,
|
||||
"y", y,
|
||||
"filled", filled,
|
||||
"path-style", path_style,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
@ -51,10 +51,10 @@ GType gimp_canvas_path_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GimpCanvasItem * gimp_canvas_path_new (GimpDisplayShell *shell,
|
||||
const GimpBezierDesc *bezier,
|
||||
GimpPathStyle type,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gboolean filled,
|
||||
gboolean path_style);
|
||||
gboolean filled);
|
||||
|
||||
void gimp_canvas_path_set (GimpCanvasItem *path,
|
||||
const GimpBezierDesc *bezier);
|
||||
|
@ -875,9 +875,9 @@ gimp_display_shell_vectors_add_handler (GimpContainer *container,
|
||||
|
||||
item = gimp_canvas_path_new (shell,
|
||||
gimp_vectors_get_bezier (vectors),
|
||||
GIMP_PATH_STYLE_VECTORS,
|
||||
0, 0,
|
||||
FALSE,
|
||||
TRUE);
|
||||
FALSE);
|
||||
gimp_canvas_item_set_visible (item,
|
||||
gimp_item_get_visible (GIMP_ITEM (vectors)));
|
||||
|
||||
|
@ -67,6 +67,9 @@ static const GimpRGB vectors_normal_fg = { 0.0, 0.0, 1.0, 0.8 };
|
||||
static const GimpRGB vectors_active_bg = { 1.0, 1.0, 1.0, 0.6 };
|
||||
static const GimpRGB vectors_active_fg = { 1.0, 0.0, 0.0, 0.8 };
|
||||
|
||||
static const GimpRGB outline_bg = { 1.0, 1.0, 1.0, 0.6 };
|
||||
static const GimpRGB outline_fg = { 0.0, 0.0, 0.0, 0.8 };
|
||||
|
||||
static const GimpRGB passe_partout = { 0.0, 0.0, 0.0, 0.5 };
|
||||
|
||||
static const GimpRGB tool_bg = { 0.0, 0.0, 0.0, 0.4 };
|
||||
@ -297,6 +300,31 @@ gimp_display_shell_set_vectors_fg_style (GimpDisplayShell *shell,
|
||||
gimp_cairo_set_source_rgba (cr, &vectors_normal_fg);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_display_shell_set_outline_bg_style (GimpDisplayShell *shell,
|
||||
cairo_t *cr)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
||||
g_return_if_fail (cr != NULL);
|
||||
|
||||
cairo_set_line_width (cr, 1.0);
|
||||
gimp_cairo_set_source_rgba (cr, &outline_bg);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_display_shell_set_outline_fg_style (GimpDisplayShell *shell,
|
||||
cairo_t *cr)
|
||||
{
|
||||
static const double dashes[] = {4.0, 4.0};
|
||||
|
||||
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
||||
g_return_if_fail (cr != NULL);
|
||||
|
||||
cairo_set_line_width (cr, 1.0);
|
||||
gimp_cairo_set_source_rgba (cr, &outline_fg);
|
||||
cairo_set_dash(cr, dashes, 2, 0);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_display_shell_set_passe_partout_style (GimpDisplayShell *shell,
|
||||
cairo_t *cr)
|
||||
|
@ -49,7 +49,10 @@ void gimp_display_shell_set_vectors_bg_style (GimpDisplayShell *shell,
|
||||
void gimp_display_shell_set_vectors_fg_style (GimpDisplayShell *shell,
|
||||
cairo_t *cr,
|
||||
gboolean active);
|
||||
|
||||
void gimp_display_shell_set_outline_bg_style (GimpDisplayShell *shell,
|
||||
cairo_t *cr);
|
||||
void gimp_display_shell_set_outline_fg_style (GimpDisplayShell *shell,
|
||||
cairo_t *cr);
|
||||
void gimp_display_shell_set_passe_partout_style (GimpDisplayShell *shell,
|
||||
cairo_t *cr);
|
||||
|
||||
|
@ -356,7 +356,7 @@ gimp_brush_tool_create_outline (GimpBrushTool *brush_tool,
|
||||
#undef EPSILON
|
||||
}
|
||||
|
||||
return gimp_canvas_path_new (shell, boundary, x, y, FALSE, FALSE);
|
||||
return gimp_canvas_path_new (shell, boundary, GIMP_PATH_STYLE_OUTLINE, x, y, FALSE);
|
||||
}
|
||||
else if (draw_fallback)
|
||||
{
|
||||
|
@ -774,7 +774,7 @@ gimp_draw_tool_add_path (GimpDrawTool *draw_tool,
|
||||
g_return_val_if_fail (desc != NULL, NULL);
|
||||
|
||||
item = gimp_canvas_path_new (gimp_display_get_shell (draw_tool->display),
|
||||
desc, x, y, FALSE, FALSE);
|
||||
desc, GIMP_PATH_STYLE_DEFAULT, x, y, FALSE);
|
||||
|
||||
gimp_draw_tool_add_item (draw_tool, item);
|
||||
g_object_unref (item);
|
||||
|
Reference in New Issue
Block a user