Code

adding fill-opacity to dyna-draw
authoracspike <acspike@users.sourceforge.net>
Thu, 18 May 2006 15:36:46 +0000 (15:36 +0000)
committeracspike <acspike@users.sourceforge.net>
Thu, 18 May 2006 15:36:46 +0000 (15:36 +0000)
src/desktop-style.cpp
src/desktop-style.h
src/dyna-draw-context.cpp

index cf8f67442d59941d824090486ee57d7e41af7b75..062607fbff2e561e97173c6ac0701d895ffb89e3 100644 (file)
@@ -222,7 +222,7 @@ sp_desktop_get_color(SPDesktop *desktop, bool is_fill)
 }
 
 double
-sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool)
+sp_desktop_get_master_opacity_tool(SPDesktop *desktop, char const *tool)
 {
     SPCSSAttr *css = NULL;
     gfloat value = 1.0; // default if nothing else found
@@ -247,6 +247,32 @@ sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool)
 
     return value;
 }
+double
+sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool, bool is_fill)
+{
+    SPCSSAttr *css = NULL;
+    gfloat value = 1.0; // default if nothing else found
+    if (prefs_get_double_attribute(tool, "usecurrent", 0) != 0) {
+        css = sp_desktop_get_style(desktop, true);
+    } else { 
+        Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
+        css = sp_repr_css_attr_inherited(tool_repr, "style");
+    }
+   
+    gchar const *property = css ? sp_repr_css_property(css, is_fill ? "fill-opacity": "stroke-opacity", "1.000") : 0;
+           
+    if (desktop->current && property) { // if there is style and the property in it,
+        if ( !sp_svg_number_read_f(property, &value) ) {
+            value = 1.0; // things failed. set back to the default
+        }
+    }
+
+    if (css) {
+        sp_repr_css_attr_unref(css);
+    }
+
+    return value;
+}
 guint32
 sp_desktop_get_color_tool(SPDesktop *desktop, char const *tool, bool is_fill)
 {
index 5171ae627f49842e2770bb67c5bbe1ca5fd12868..8f8388289e8711a821ae7b5f566108b25bcb4a73 100644 (file)
@@ -54,7 +54,8 @@ void sp_desktop_set_color(SPDesktop *desktop, ColorRGBA const &color, bool is_re
 void sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change = true, bool write_current = true);
 SPCSSAttr *sp_desktop_get_style(SPDesktop *desktop, bool with_text);
 guint32 sp_desktop_get_color (SPDesktop *desktop, bool is_fill);
-double sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool);
+double sp_desktop_get_master_opacity_tool(SPDesktop *desktop, char const *tool);
+double sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool, bool is_fill);
 guint32 sp_desktop_get_color_tool(SPDesktop *desktop, char const *tool, bool is_fill);
 double sp_desktop_get_font_size_tool (SPDesktop *desktop);
 void sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, char const *tool, bool with_text);
index ff570fb62b7b6d355eb4803294fe9fb2dbdc760f..f1128c4921231c97edb09f19d83bdd9b55e484c9 100644 (file)
@@ -809,8 +809,13 @@ fit_and_split_calligraphics(SPDynaDrawContext *dc, gboolean release)
             sp_curve_unref(curve);
 
             guint32 fillColor = sp_desktop_get_color_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", true);
-            double opacity = sp_desktop_get_opacity_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic");
-            sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cbp), ((fillColor & 0xffffff00) | SP_COLOR_F_TO_U(opacity)), SP_WIND_RULE_EVENODD);
+            //guint32 strokeColor = sp_desktop_get_color_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", false);
+            double opacity = sp_desktop_get_master_opacity_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic");
+            double fillOpacity = sp_desktop_get_opacity_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", true);
+            //double strokeOpacity = sp_desktop_get_opacity_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", false);
+            sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cbp), ((fillColor & 0xffffff00) | SP_COLOR_F_TO_U(opacity*fillOpacity)), SP_WIND_RULE_EVENODD);
+            //on second thougtht don't do stroke yet because we don't have stoke-width yet and because stoke appears between segments while drawing
+            //sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cbp), ((strokeColor & 0xffffff00) | SP_COLOR_F_TO_U(opacity*strokeOpacity)), 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
             sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cbp), 0x00000000, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
             /* fixme: Cannot we cascade it to root more clearly? */
             g_signal_connect(G_OBJECT(cbp), "event", G_CALLBACK(sp_desktop_root_handler), SP_EVENT_CONTEXT(dc)->desktop);