[gimp] app: Refactor path code to support styles and add outline style for use in brush outline
- From: Alexia Death <alexiade src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: Refactor path code to support styles and add outline style for use in brush outline
- Date: Wed, 29 Jun 2011 20:53:05 +0000 (UTC)
commit 3c3657f780abdb281514ba93af51a518bacb4054
Author: Alexia Death <alexiadeath gmail com>
Date: Wed Jun 29 21:00:28 2011 +0300
app: Refactor path code to support styles and add outline style for use in brush outline
app/display/display-enums.c | 31 ++++++++++++++++++++++
app/display/display-enums.h | 11 ++++++++
app/display/gimpcanvaspath.c | 42 +++++++++++++++++++-----------
app/display/gimpcanvaspath.h | 4 +-
app/display/gimpdisplayshell-handlers.c | 4 +-
app/display/gimpdisplayshell-style.c | 28 ++++++++++++++++++++
app/display/gimpdisplayshell-style.h | 5 +++-
app/tools/gimpbrushtool.c | 2 +-
app/tools/gimpdrawtool.c | 2 +-
9 files changed, 106 insertions(+), 23 deletions(-)
---
diff --git a/app/display/display-enums.c b/app/display/display-enums.c
index 9810441..83c7423 100644
--- a/app/display/display-enums.c
+++ b/app/display/display-enums.c
@@ -155,6 +155,37 @@ gimp_handle_anchor_get_type (void)
}
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)
{
static const GEnumValue values[] =
diff --git a/app/display/display-enums.h b/app/display/display-enums.h
index f1a794b..eb2236e 100644
--- a/app/display/display-enums.h
+++ b/app/display/display-enums.h
@@ -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 ())
diff --git a/app/display/gimpcanvaspath.c b/app/display/gimpcanvaspath.c
index cd5ab83..fabb9c0 100644
--- a/app/display/gimpcanvaspath.c
+++ b/app/display/gimpcanvaspath.c
@@ -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);
}
diff --git a/app/display/gimpcanvaspath.h b/app/display/gimpcanvaspath.h
index 92a45bf..905b441 100644
--- a/app/display/gimpcanvaspath.h
+++ b/app/display/gimpcanvaspath.h
@@ -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);
diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c
index b3e4983..8c670eb 100644
--- a/app/display/gimpdisplayshell-handlers.c
+++ b/app/display/gimpdisplayshell-handlers.c
@@ -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)));
diff --git a/app/display/gimpdisplayshell-style.c b/app/display/gimpdisplayshell-style.c
index 1cad1d2..8e86658 100644
--- a/app/display/gimpdisplayshell-style.c
+++ b/app/display/gimpdisplayshell-style.c
@@ -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 };
@@ -298,6 +301,31 @@ gimp_display_shell_set_vectors_fg_style (GimpDisplayShell *shell,
}
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)
{
diff --git a/app/display/gimpdisplayshell-style.h b/app/display/gimpdisplayshell-style.h
index 89a2762..7b30595 100644
--- a/app/display/gimpdisplayshell-style.h
+++ b/app/display/gimpdisplayshell-style.h
@@ -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);
diff --git a/app/tools/gimpbrushtool.c b/app/tools/gimpbrushtool.c
index 6202aa0..43dfc2f 100644
--- a/app/tools/gimpbrushtool.c
+++ b/app/tools/gimpbrushtool.c
@@ -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)
{
diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c
index 9433023..d29547f 100644
--- a/app/tools/gimpdrawtool.c
+++ b/app/tools/gimpdrawtool.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]