Code

finally getting closer to processing axes and contexts correctly
[inkscape.git] / src / dyna-draw-context.cpp
index 05e4450866eeaafa8317637b882897de97ecfc22..3233198f606ecef0a60322deab9ce52b2372fe33 100644 (file)
@@ -29,6 +29,7 @@
 #include "display/canvas-bpath.h"
 #include "display/bezier-utils.h"
 
+#include <glib/gmem.h>
 #include "macros.h"
 #include "document.h"
 #include "selection.h"
 #include "desktop-style.h"
 #include "message-context.h"
 #include "pixmaps/cursor-calligraphy.xpm"
+#include "pixmaps/cursor-calligraphy.pixbuf"
 #include "dyna-draw-context.h"
 #include "libnr/n-art-bpath.h"
 #include "libnr/nr-path.h"
 #include "xml/repr.h"
 #include "context-fns.h"
 #include "sp-item.h"
+#include "inkscape.h"
+#include "color.h"
 
 #define DDC_RED_RGBA 0xff0000ff
 
@@ -123,6 +127,11 @@ sp_dyna_draw_context_init(SPDynaDrawContext *ddc)
     SPEventContext *event_context = SP_EVENT_CONTEXT(ddc);
 
     event_context->cursor_shape = cursor_calligraphy_xpm;
+    event_context->cursor_pixbuf = gdk_pixbuf_new_from_inline(
+            -1,
+            cursor_calligraphy_pixbuf,
+            FALSE,
+            NULL);  
     event_context->hot_x = 4;
     event_context->hot_y = 4;
 
@@ -155,6 +164,7 @@ sp_dyna_draw_context_init(SPDynaDrawContext *ddc)
     ddc->flatness = 0.9;
 
     ddc->abs_width = false;
+    ddc->keep_selected = true;
 }
 
 static void
@@ -217,6 +227,7 @@ sp_dyna_draw_context_setup(SPEventContext *ec)
     sp_event_context_read(ec, "usepressure");
     sp_event_context_read(ec, "usetilt");
     sp_event_context_read(ec, "abs_width");
+    sp_event_context_read(ec, "keep_selected");
 
     ddc->is_drawing = false;
 
@@ -255,6 +266,8 @@ sp_dyna_draw_context_set(SPEventContext *ec, gchar const *key, gchar const *val)
         ddc->usetilt = (val && strcmp(val, "0"));
     } else if (!strcmp(key, "abs_width")) {
         ddc->abs_width = (val && strcmp(val, "0"));
+    } else if (!strcmp(key, "keep_selected")) {
+        ddc->keep_selected = (val && strcmp(val, "0"));
     }
 
     //g_print("DDC: %g %g %g %g\n", ddc->mass, ddc->drag, ddc->angle, ddc->width);
@@ -653,12 +666,16 @@ set_to_accumulated(SPDynaDrawContext *dc)
             Inkscape::GC::release(dc->repr);
             item->transform = SP_ITEM(desktop->currentRoot())->getRelativeTransform(desktop->currentLayer());
             item->updateRepr();
-            sp_desktop_selection(desktop)->set(dc->repr);
+            if (dc->keep_selected) {
+                sp_desktop_selection(desktop)->set(dc->repr);
+            } else {
+                sp_desktop_selection(desktop)->clear();
+            }
         }
         abp = nr_artpath_affine(sp_curve_first_bpath(dc->accumulated), sp_desktop_dt2root_affine(desktop));
         str = sp_svg_write_path(abp);
         g_assert( str != NULL );
-        nr_free(abp);
+        g_free(abp);
         dc->repr->setAttribute("d", str);
         g_free(str);
     } else {
@@ -668,7 +685,8 @@ set_to_accumulated(SPDynaDrawContext *dc)
         dc->repr = NULL;
     }
 
-    sp_document_done(sp_desktop_document(desktop));
+    sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_CALLIGRAPHIC, 
+                     /* TODO: annotate */ "dyna-draw-context.cpp:689");
 }
 
 static void
@@ -800,7 +818,15 @@ fit_and_split_calligraphics(SPDynaDrawContext *dc, gboolean release)
             SPCurve *curve = sp_curve_copy(dc->currentcurve);
             sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH (cbp), curve);
             sp_curve_unref(curve);
-            sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cbp), 0x000000ff, SP_WIND_RULE_EVENODD);
+
+            guint32 fillColor = sp_desktop_get_color_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", true);
+            //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);