draw-context.cpp revision d37634d73670180f99a3e0ea583621373d90ec4f
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Generic drawing context
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Lauris Kaplinski <lauris@kaplinski.com>
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Abhishek Sharma
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Copyright (C) 2000 Lauris Kaplinski
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Copyright (C) 2000-2001 Ximian, Inc.
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Copyright (C) 2002 Lauris Kaplinski
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Released under GNU GPL, read the file 'COPYING' for more information
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński#include "live_effects/lpe-patternalongpath.h"
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void sp_draw_context_class_init(SPDrawContextClass *klass);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void sp_draw_context_init(SPDrawContext *dc);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void sp_draw_context_dispose(GObject *object);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void sp_draw_context_setup(SPEventContext *ec);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void sp_draw_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void sp_draw_context_finish(SPEventContext *ec);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic gint sp_draw_context_root_handler(SPEventContext *event_context, GdkEvent *event);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void spdc_selection_modified(Inkscape::Selection *sel, guint flags, SPDrawContext *dc);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection *sel);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void spdc_flush_white(SPDrawContext *dc, SPCurve *gc);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void spdc_reset_white(SPDrawContext *dc);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic void spdc_free_colors(SPDrawContext *dc);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskistatic SPEventContextClass *draw_parent_class;
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński (GClassInitFunc) sp_draw_context_class_init,
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński (GInstanceInitFunc) sp_draw_context_init,
a16a494f042310ee849a6f717ffea70846f1f22cKrzysztof Kosiński type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPDrawContext", &info, (GTypeFlags)0);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskisp_draw_context_class_init(SPDrawContextClass *klass)
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński ec_class = (SPEventContextClass *) klass;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński draw_parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński object_class->dispose = sp_draw_context_dispose;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński ec_class->finish = sp_draw_context_finish;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński ec_class->root_handler = sp_draw_context_root_handler;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński dc->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE;
76addc201c409e81eaaa73fe27cc0f79c4db097cKrzysztof Kosiński new (&dc->sel_changed_connection) sigc::connection();
76addc201c409e81eaaa73fe27cc0f79c4db097cKrzysztof Kosiński new (&dc->sel_modified_connection) sigc::connection();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński SPDrawContext *dc = SP_DRAW_CONTEXT(object);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński dc->sel_changed_connection.~connection();
76addc201c409e81eaaa73fe27cc0f79c4db097cKrzysztof Kosiński dc->sel_modified_connection.~connection();
76addc201c409e81eaaa73fe27cc0f79c4db097cKrzysztof Kosiński sp_canvas_item_ungrab(dc->grab, GDK_CURRENT_TIME);
76addc201c409e81eaaa73fe27cc0f79c4db097cKrzysztof Kosiński G_OBJECT_CLASS(draw_parent_class)->dispose(object);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński if (((SPEventContextClass *) draw_parent_class)->setup) {
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński ((SPEventContextClass *) draw_parent_class)->setup(ec);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński dc->selection = sp_desktop_selection(dt);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński /* Connect signals to track selection changes */
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński dc->sel_changed_connection = dc->selection->connectChanged(
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński sigc::bind(sigc::ptr_fun(&spdc_selection_changed), dc)
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->red_bpath), dc->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->blue_bpath), dc->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
case GDK_KEY_PRESS:
case GDK_Up:
case GDK_Down:
case GDK_KP_Up:
case GDK_KP_Down:
if (!MOD__CTRL_ONLY) {
if (!ret) {
return ret;
bool shape_applied = false;
switch (shape) {
c->moveto(0,0);
c->closepath();
c->unref();
shape_applied = true;
c->closepath();
c->unref();
shape_applied = true;
c->curveto((1 + C1) * SHAPE_LENGTH/2, 0, SHAPE_LENGTH, (1 - C1) * SHAPE_HEIGHT/2, SHAPE_LENGTH, SHAPE_HEIGHT/2);
c->curveto(SHAPE_LENGTH, (1 + C1) * SHAPE_HEIGHT/2, (1 + C1) * SHAPE_LENGTH/2, SHAPE_HEIGHT, SHAPE_LENGTH/2, SHAPE_HEIGHT);
c->curveto((1 - C1) * SHAPE_LENGTH/2, SHAPE_HEIGHT, 0, (1 + C1) * SHAPE_HEIGHT/2, 0, SHAPE_HEIGHT/2);
c->closepath();
c->unref();
shape_applied = true;
shape_applied = true;
if (shape_applied) {
SPCurve *c;
if ( !c->is_closed() ) {
SPDrawAnchor *a;
* Snaps node or handle to PI/rotationsnapsperpi degree increments.
void spdc_endpoint_snap_rotation(SPEventContext const *const ec, Geom::Point &p, Geom::Point const &o,
// SHIFT disables all snapping, except the angular snapping. After all, the user explicitly asked for angular
// snapping by pressing CTRL, otherwise we wouldn't have arrived here. But although we temporarily disable
// the snapping here, we must still call for a constrained snap in order to apply the constraints (i.e. round
Inkscape::SnappedPoint dummy = m.constrainedAngularSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE), boost::optional<Geom::Point>(), o, snaps);
m.unSetup();
void spdc_endpoint_snap_free(SPEventContext const * const ec, Geom::Point& p, guint const /*state*/)
// selection->singleItem() is the item that is currently being drawn. This item will not be snapped to (to avoid self-snapping)
m.unSetup();
static SPCurve *
return ret;
if (c->is_empty()) {
c->unref();
SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Path is closed."));
c->closepath_current();
c->unref();
c = reverse_then_unref(c);
c->unref();
s = reverse_then_unref(s);
c->unref();
e = reverse_then_unref(e);
e->unref();
c->unref();
SPCurve *c;
if (gc) {
} else if (gc) {
c = gc;
c->ref();
if ( c && !c->is_empty() ) {
bool has_lpe = false;
if (has_lpe)
c->unref();
return active;
void spdc_create_single_dot(SPEventContext *ec, Geom::Point const &pt, char const *tool, guint event_state) {
if (style_str) {
str = g_strdup_printf("fill:#%06x;stroke:none;", sp_desktop_get_color_tool(desktop, tool, false) >> 8);