index 77f32e184dc667e04560283ec81bb88befecefa0..3233198f606ecef0a60322deab9ce52b2372fe33 100644 (file)
#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
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;
ddc->del = NR::Point(0,0);
/* attributes */
- ddc->use_timeout = FALSE;
- ddc->timer_id = 0;
ddc->dragging = FALSE;
ddc->mass = 0.3;
ddc->flatness = 0.9;
ddc->abs_width = false;
+ ddc->keep_selected = true;
}
static void
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;
@@ -257,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);
dc->npoints++;
}
-static gint
-sp_dyna_draw_timeout_handler(gpointer data)
-{
- SPDynaDrawContext *dc = SP_DYNA_DRAW_CONTEXT(data);
- SPDesktop *desktop = SP_EVENT_CONTEXT(dc)->desktop;
- SPCanvas *canvas = SP_CANVAS(sp_desktop_canvas(desktop));
-
- dc->dragging = TRUE;
-
- int x, y;
- gtk_widget_get_pointer(GTK_WIDGET(canvas), &x, &y);
- NR::Point p = sp_canvas_window_to_world(canvas, NR::Point(x, y));
- p = desktop->w2d(p);
- if (! sp_dyna_draw_apply(dc, p)) {
- return TRUE;
- }
-
- if ( dc->cur != dc->last ) {
- sp_dyna_draw_brush(dc);
- g_assert( dc->npoints > 0 );
- fit_and_split(dc, FALSE);
- }
-
- return TRUE;
-}
-
void
sp_ddc_update_toolbox (SPDesktop *desktop, const gchar *id, double value)
{
dc->npoints = 0;
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
- ( dc->use_timeout
- ? ( GDK_KEY_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK )
- : ( GDK_KEY_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_PRESS_MASK ) ),
+ ( GDK_KEY_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_POINTER_MOTION_MASK |
+ GDK_BUTTON_PRESS_MASK ),
NULL,
event->button.time);
- if ( dc->use_timeout && !dc->timer_id ) {
- dc->timer_id = gtk_timeout_add(SAMPLE_TIMEOUT, sp_dyna_draw_timeout_handler, dc);
- }
ret = TRUE;
dc->is_drawing = true;
}
break;
case GDK_MOTION_NOTIFY:
- if ( dc->is_drawing && !dc->use_timeout && ( event->motion.state & GDK_BUTTON1_MASK ) ) {
+ if ( dc->is_drawing && ( event->motion.state & GDK_BUTTON1_MASK ) ) {
dc->dragging = TRUE;
NR::Point const motion_w(event->motion.x,
case GDK_BUTTON_RELEASE:
sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time);
dc->is_drawing = false;
- if ( event->button.button == 1
- && dc->use_timeout
- && dc->timer_id != 0 )
- {
- gtk_timeout_remove(dc->timer_id);
- dc->timer_id = 0;
- }
if ( dc->dragging && event->button.button == 1 ) {
dc->dragging = FALSE;
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 {
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
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);