diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-07-30 21:17:21 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-07-30 21:17:21 +0000 |
| commit | b2dd3583e7372d23d18bbc6e861f4f645ec3dc37 (patch) | |
| tree | 659f5549fc533cebec5326615b6e385ffdde5453 /src | |
| parent | Merge from trunk (r12439). (diff) | |
| download | inkscape-b2dd3583e7372d23d18bbc6e861f4f645ec3dc37.tar.gz inkscape-b2dd3583e7372d23d18bbc6e861f4f645ec3dc37.zip | |
Further refactoring of EventContexts.
(bzr r11608.1.109)
Diffstat (limited to 'src')
60 files changed, 1147 insertions, 1176 deletions
diff --git a/src/arc-context.cpp b/src/arc-context.cpp index ade624365..827a0eb35 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -143,7 +143,7 @@ void SPArcContext::setup() { this->_message_context = new Inkscape::MessageContext(this->desktop->messageStack()); } -gint SPArcContext::item_handler(SPItem* item, GdkEvent* event) { +bool SPArcContext::item_handler(SPItem* item, GdkEvent* event) { gint ret = FALSE; switch (event->type) { @@ -167,7 +167,7 @@ gint SPArcContext::item_handler(SPItem* item, GdkEvent* event) { return ret; } -gint SPArcContext::root_handler(GdkEvent* event) { +bool SPArcContext::root_handler(GdkEvent* event) { static bool dragging; Inkscape::Selection *selection = sp_desktop_selection(desktop); diff --git a/src/arc-context.h b/src/arc-context.h index f544dd322..25b8762b2 100644 --- a/src/arc-context.h +++ b/src/arc-context.h @@ -35,8 +35,8 @@ public: virtual void setup(); virtual void finish(); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); + virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index 6d1a3dde4..f0bb67dcc 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -182,7 +182,7 @@ void Box3DContext::setup() { this->_message_context = new Inkscape::MessageContext(this->desktop->messageStack()); } -gint Box3DContext::item_handler(SPItem* item, GdkEvent* event) { +bool Box3DContext::item_handler(SPItem* item, GdkEvent* event) { gint ret = FALSE; switch (event->type) { @@ -206,7 +206,7 @@ gint Box3DContext::item_handler(SPItem* item, GdkEvent* event) { return ret; } -gint Box3DContext::root_handler(GdkEvent* event) { +bool Box3DContext::root_handler(GdkEvent* event) { static bool dragging; SPDocument *document = sp_desktop_document (desktop); diff --git a/src/box3d-context.h b/src/box3d-context.h index 0c7630eb4..7f910158e 100644 --- a/src/box3d-context.h +++ b/src/box3d-context.h @@ -37,8 +37,8 @@ public: virtual void setup(); virtual void finish(); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); + virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/common-context.cpp b/src/common-context.cpp index 5ccbaaf5a..e6b82cf82 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -9,6 +9,7 @@ #include "streq.h" #include "preferences.h" #include "display/sp-canvas-item.h" +#include "desktop.h" #define MIN_PRESSURE 0.0 #define MAX_PRESSURE 1.0 @@ -19,130 +20,145 @@ #define DRAG_MAX 1.0 SPCommonContext::SPCommonContext() : SPEventContext() { - SPCommonContext* ctx = this; - - ctx->_message_context = 0; - ctx->tremor = 0; - ctx->usetilt = 0; - ctx->is_drawing = false; - ctx->xtilt = 0; - ctx->ytilt = 0; - ctx->usepressure = 0; + this->_message_context = 0; + this->tremor = 0; + this->usetilt = 0; + this->is_drawing = false; + this->xtilt = 0; + this->ytilt = 0; + this->usepressure = 0; // ctx->cursor_shape = cursor_eraser_xpm; // ctx->hot_x = 4; // ctx->hot_y = 4; - ctx->accumulated = 0; - ctx->segments = 0; - ctx->currentcurve = 0; - ctx->currentshape = 0; - ctx->npoints = 0; - ctx->cal1 = 0; - ctx->cal2 = 0; - ctx->repr = 0; + this->accumulated = 0; + this->segments = 0; + this->currentcurve = 0; + this->currentshape = 0; + this->npoints = 0; + this->cal1 = 0; + this->cal2 = 0; + this->repr = 0; /* Common values */ - ctx->cur = Geom::Point(0,0); - ctx->last = Geom::Point(0,0); - ctx->vel = Geom::Point(0,0); - ctx->vel_max = 0; - ctx->acc = Geom::Point(0,0); - ctx->ang = Geom::Point(0,0); - ctx->del = Geom::Point(0,0); + this->cur = Geom::Point(0,0); + this->last = Geom::Point(0,0); + this->vel = Geom::Point(0,0); + this->vel_max = 0; + this->acc = Geom::Point(0,0); + this->ang = Geom::Point(0,0); + this->del = Geom::Point(0,0); /* attributes */ - ctx->dragging = FALSE; + this->dragging = FALSE; - ctx->mass = 0.3; - ctx->drag = DRAG_DEFAULT; - ctx->angle = 30.0; - ctx->width = 0.2; - ctx->pressure = DEFAULT_PRESSURE; + this->mass = 0.3; + this->drag = DRAG_DEFAULT; + this->angle = 30.0; + this->width = 0.2; + this->pressure = DEFAULT_PRESSURE; - ctx->vel_thin = 0.1; - ctx->flatness = 0.9; - ctx->cap_rounding = 0.0; + this->vel_thin = 0.1; + this->flatness = 0.9; + this->cap_rounding = 0.0; - ctx->abs_width = false; + this->abs_width = false; } SPCommonContext::~SPCommonContext() { - SPCommonContext *ctx = SP_COMMON_CONTEXT(this); - - if (ctx->accumulated) { - ctx->accumulated = ctx->accumulated->unref(); - ctx->accumulated = 0; + if (this->accumulated) { + this->accumulated = this->accumulated->unref(); + this->accumulated = 0; } - while (ctx->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(ctx->segments->data)); - ctx->segments = g_slist_remove(ctx->segments, ctx->segments->data); + while (this->segments) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); + this->segments = g_slist_remove(this->segments, this->segments->data); } - if (ctx->currentcurve) { - ctx->currentcurve = ctx->currentcurve->unref(); - ctx->currentcurve = 0; + if (this->currentcurve) { + this->currentcurve = this->currentcurve->unref(); + this->currentcurve = 0; } - if (ctx->cal1) { - ctx->cal1 = ctx->cal1->unref(); - ctx->cal1 = 0; + + if (this->cal1) { + this->cal1 = this->cal1->unref(); + this->cal1 = 0; } - if (ctx->cal2) { - ctx->cal2 = ctx->cal2->unref(); - ctx->cal2 = 0; + + if (this->cal2) { + this->cal2 = this->cal2->unref(); + this->cal2 = 0; } - if (ctx->currentshape) { - sp_canvas_item_destroy(ctx->currentshape); - ctx->currentshape = 0; + if (this->currentshape) { + sp_canvas_item_destroy(this->currentshape); + this->currentshape = 0; } - if (ctx->_message_context) { - delete ctx->_message_context; - ctx->_message_context = 0; + if (this->_message_context) { + delete this->_message_context; + this->_message_context = 0; } //G_OBJECT_CLASS(sp_common_context_parent_class)->dispose(object); } void SPCommonContext::set(const Inkscape::Preferences::Entry& value) { - SPEventContext* ec = this; - - SPCommonContext *ctx = SP_COMMON_CONTEXT(ec); Glib::ustring path = value.getEntryName(); // ignore preset modifications - static Glib::ustring const presets_path = ec->pref_observer->observed_path + "/preset"; + static Glib::ustring const presets_path = this->pref_observer->observed_path + "/preset"; Glib::ustring const &full_path = value.getPath(); - if (full_path.compare(0, presets_path.size(), presets_path) == 0) return; + + if (full_path.compare(0, presets_path.size(), presets_path) == 0) { + return; + } if (path == "mass") { - ctx->mass = 0.01 * CLAMP(value.getInt(10), 0, 100); + this->mass = 0.01 * CLAMP(value.getInt(10), 0, 100); } else if (path == "wiggle") { - ctx->drag = CLAMP((1 - 0.01 * value.getInt()), - DRAG_MIN, DRAG_MAX); // drag is inverse to wiggle + this->drag = CLAMP((1 - 0.01 * value.getInt()), DRAG_MIN, DRAG_MAX); // drag is inverse to wiggle } else if (path == "angle") { - ctx->angle = CLAMP(value.getDouble(), -90, 90); + this->angle = CLAMP(value.getDouble(), -90, 90); } else if (path == "width") { - ctx->width = 0.01 * CLAMP(value.getInt(10), 1, 100); + this->width = 0.01 * CLAMP(value.getInt(10), 1, 100); } else if (path == "thinning") { - ctx->vel_thin = 0.01 * CLAMP(value.getInt(10), -100, 100); + this->vel_thin = 0.01 * CLAMP(value.getInt(10), -100, 100); } else if (path == "tremor") { - ctx->tremor = 0.01 * CLAMP(value.getInt(), 0, 100); + this->tremor = 0.01 * CLAMP(value.getInt(), 0, 100); } else if (path == "flatness") { - ctx->flatness = 0.01 * CLAMP(value.getInt(), 0, 100); + this->flatness = 0.01 * CLAMP(value.getInt(), 0, 100); } else if (path == "usepressure") { - ctx->usepressure = value.getBool(); + this->usepressure = value.getBool(); } else if (path == "usetilt") { - ctx->usetilt = value.getBool(); + this->usetilt = value.getBool(); } else if (path == "abs_width") { - ctx->abs_width = value.getBool(); + this->abs_width = value.getBool(); } else if (path == "cap_rounding") { - ctx->cap_rounding = value.getDouble(); + this->cap_rounding = value.getDouble(); } } +/* Get normalized point */ +Geom::Point SPCommonContext::getNormalizedPoint(Geom::Point v) const { + Geom::Rect drect = this->desktop->get_display_area(); + + double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); + + return Geom::Point(( v[Geom::X] - drect.min()[Geom::X] ) / max, ( v[Geom::Y] - drect.min()[Geom::Y] ) / max); +} + +/* Get view point */ +Geom::Point SPCommonContext::getViewPoint(Geom::Point n) const { + Geom::Rect drect = this->desktop->get_display_area(); + + double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); + + return Geom::Point(n[Geom::X] * max + drect.min()[Geom::X], n[Geom::Y] * max + drect.min()[Geom::Y]); +} + /* Local Variables: mode:c++ diff --git a/src/common-context.h b/src/common-context.h index ffcf8de38..dc4c82251 100644 --- a/src/common-context.h +++ b/src/common-context.h @@ -23,9 +23,6 @@ #include "display/curve.h" #include <2geom/point.h> -#define SP_COMMON_CONTEXT(obj) ((SPCommonContext*)obj) -#define SP_IS_COMMON_CONTEXT(obj) (dynamic_cast<const SPCommonContext*>((const SPEventContext*)obj)) - #define SAMPLING_SIZE 8 /* fixme: ?? */ class SPCommonContext : public SPEventContext { @@ -33,6 +30,9 @@ public: SPCommonContext(); virtual ~SPCommonContext(); + virtual void set(const Inkscape::Preferences::Entry& val); + +protected: /** accumulated shape which ultimately goes in svg:path */ SPCurve *accumulated; @@ -89,14 +89,15 @@ public: double tremor; double cap_rounding; - Inkscape::MessageContext *_message_context; + //Inkscape::MessageContext *_message_context; bool is_drawing; /** uses absolute width independent of zoom */ bool abs_width; - virtual void set(const Inkscape::Preferences::Entry& val); + Geom::Point getViewPoint(Geom::Point n) const; + Geom::Point getNormalizedPoint(Geom::Point v) const; }; #endif // COMMON_CONTEXT_H_SEEN diff --git a/src/connector-context.cpp b/src/connector-context.cpp index 12d9e41b8..72a01dee9 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -417,7 +417,7 @@ cc_deselect_handle(SPKnot* knot) sp_knot_update_ctrl(knot); } -gint SPConnectorContext::item_handler(SPItem* item, GdkEvent* event) { +bool SPConnectorContext::item_handler(SPItem* item, GdkEvent* event) { gint ret = FALSE; Geom::Point p(event->button.x, event->button.y); @@ -472,7 +472,7 @@ gint SPConnectorContext::item_handler(SPItem* item, GdkEvent* event) { return ret; } -gint SPConnectorContext::root_handler(GdkEvent* event) { +bool SPConnectorContext::root_handler(GdkEvent* event) { gint ret = FALSE; switch (event->type) { @@ -1096,7 +1096,7 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) static gboolean endpt_handler(SPKnot */*knot*/, GdkEvent *event, SPConnectorContext *cc) { - g_assert( SP_IS_CONNECTOR_CONTEXT(cc) ); + //g_assert( SP_IS_CONNECTOR_CONTEXT(cc) ); gboolean consumed = FALSE; diff --git a/src/connector-context.h b/src/connector-context.h index 1071bdced..3e8c89f14 100644 --- a/src/connector-context.h +++ b/src/connector-context.h @@ -21,7 +21,7 @@ #include <glibmm/i18n.h> #define SP_CONNECTOR_CONTEXT(obj) ((SPConnectorContext*)obj) -#define SP_IS_CONNECTOR_CONTEXT(obj) (dynamic_cast<const SPConnectorContext*>((const SPEventContext*)obj)) +//#define SP_IS_CONNECTOR_CONTEXT(obj) (dynamic_cast<const SPConnectorContext*>((const SPEventContext*)obj)) struct SPKnot; class SPCurve; @@ -99,8 +99,8 @@ public: virtual void setup(); virtual void finish(); virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); + virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/desktop-handles.cpp b/src/desktop-handles.cpp index f7ffbed70..ebfa22c3e 100644 --- a/src/desktop-handles.cpp +++ b/src/desktop-handles.cpp @@ -15,13 +15,13 @@ #include "desktop.h" #include "desktop-handles.h" -SPEventContext * -sp_desktop_event_context (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->event_context; -} +//SPEventContext * +//sp_desktop_event_context (SPDesktop const * desktop) +//{ +// g_return_val_if_fail (desktop != NULL, NULL); +// +// return desktop->event_context; +//} Inkscape::Selection * sp_desktop_selection (SPDesktop const * desktop) diff --git a/src/desktop-handles.h b/src/desktop-handles.h index cca929369..7cd903b83 100644 --- a/src/desktop-handles.h +++ b/src/desktop-handles.h @@ -34,7 +34,7 @@ namespace Inkscape { #define SP_COORDINATES_UNDERLINE_X (1 << Geom::X) #define SP_COORDINATES_UNDERLINE_Y (1 << Geom::Y) -SPEventContext * sp_desktop_event_context (SPDesktop const * desktop); +//SPEventContext * sp_desktop_event_context (SPDesktop const * desktop); Inkscape::Selection * sp_desktop_selection (SPDesktop const * desktop); SPDocument * sp_desktop_document (SPDesktop const * desktop); SPCanvas * sp_desktop_canvas (SPDesktop const * desktop); diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index c632f9033..f8fad9711 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -200,7 +200,7 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write if (!intercepted) { // If we have an event context, update its cursor (TODO: it could be neater to do this with the signal sent above, but what if the signal gets intercepted?) if (desktop->event_context) { - sp_event_context_update_cursor(desktop->event_context); + desktop->event_context->sp_event_context_update_cursor(); } // Remove text attributes if not text... diff --git a/src/desktop.cpp b/src/desktop.cpp index 029e58c59..332ae5996 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -401,6 +401,65 @@ SPDesktop::~SPDesktop() { } + +SPEventContext* SPDesktop::getEventContext() const { + return event_context; +} + +Inkscape::Selection* SPDesktop::getSelection() const { + return selection; +} + +SPDocument* SPDesktop::getDocument() const { + return doc(); +} + +SPCanvas* SPDesktop::getCanvas() const { + return SP_CANVAS_ITEM(main)->canvas; +} + +SPCanvasItem* SPDesktop::getAcetate() const { + return acetate; +} + +SPCanvasGroup* SPDesktop::getMain() const { + return main; +} + +SPCanvasGroup* SPDesktop::getGridGroup() const { + return gridgroup; +} + +SPCanvasGroup* SPDesktop::getGuides() const { + return guides; +} + +SPCanvasItem* SPDesktop::getDrawing() const { + return drawing; +} + +SPCanvasGroup* SPDesktop::getSketch() const { + return sketch; +} + +SPCanvasGroup* SPDesktop::getControls() const { + return controls; +} + +SPCanvasGroup* SPDesktop::getTempGroup() const { + return tempgroup; +} + +Inkscape::MessageStack* SPDesktop::getMessageStack() const { + return messageStack(); +} + +SPNamedView* SPDesktop::getNamedView() const { + return namedview; +} + + + //-------------------------------------------------------------------- /* Public methods */ @@ -1444,10 +1503,10 @@ void SPDesktop::setWaitingCursor() waiting_cursor = true; } -void SPDesktop::clearWaitingCursor() -{ - if (waiting_cursor) - sp_event_context_update_cursor(sp_desktop_event_context(this)); +void SPDesktop::clearWaitingCursor() { + if (waiting_cursor) { + this->event_context->sp_event_context_update_cursor(); + } } void SPDesktop::toggleColorProfAdjust() diff --git a/src/desktop.h b/src/desktop.h index d971b5bb2..3d4513425 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -135,6 +135,21 @@ public: Inkscape::Display::TemporaryItemList *temporary_item_list; Inkscape::Display::SnapIndicator *snapindicator; + SPEventContext* getEventContext() const; + Inkscape::Selection* getSelection() const; + SPDocument* getDocument() const; + SPCanvas* getCanvas() const; + SPCanvasItem* getAcetate() const; + SPCanvasGroup* getMain() const; + SPCanvasGroup* getGridGroup() const; + SPCanvasGroup* getGuides() const; + SPCanvasItem* getDrawing() const; + SPCanvasGroup* getSketch() const; + SPCanvasGroup* getControls() const; + SPCanvasGroup* getTempGroup() const; + Inkscape::MessageStack* getMessageStack() const; + SPNamedView* getNamedView() const; + SPCanvasItem *acetate; SPCanvasGroup *main; SPCanvasGroup *gridgroup; diff --git a/src/draw-context.cpp b/src/draw-context.cpp index bb2468b98..fed757c0e 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -192,7 +192,7 @@ void SPDrawContext::finish() { void SPDrawContext::set(const Inkscape::Preferences::Entry& value) { } -gint SPDrawContext::root_handler(GdkEvent* event) { +bool SPDrawContext::root_handler(GdkEvent* event) { SPEventContext* ec = this; gint ret = FALSE; diff --git a/src/draw-context.h b/src/draw-context.h index af21d7ec3..96f38ea27 100644 --- a/src/draw-context.h +++ b/src/draw-context.h @@ -83,7 +83,7 @@ public: virtual void setup(); virtual void finish(); virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); + virtual bool root_handler(GdkEvent* event); }; /** diff --git a/src/dropper-context.cpp b/src/dropper-context.cpp index 1f10dffa7..7dfe203ba 100644 --- a/src/dropper-context.cpp +++ b/src/dropper-context.cpp @@ -166,7 +166,7 @@ guint32 SPDropperContext::get_color() { (pick == SP_DROPPER_PICK_ACTUAL && setalpha) ? this->alpha : 1.0); } -gint SPDropperContext::root_handler(GdkEvent* event) { +bool SPDropperContext::root_handler(GdkEvent* event) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int ret = FALSE; diff --git a/src/dropper-context.h b/src/dropper-context.h index a95b4662e..a6ddf7305 100644 --- a/src/dropper-context.h +++ b/src/dropper-context.h @@ -31,7 +31,7 @@ public: virtual void setup(); virtual void finish(); - virtual gint root_handler(GdkEvent* event); + virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp index 894fa91b5..da90d926f 100644 --- a/src/dyna-draw-context.cpp +++ b/src/dyna-draw-context.cpp @@ -81,17 +81,7 @@ using Inkscape::DocumentUndo; #define DYNA_MIN_WIDTH 1.0e-6 -static void clear_current(SPDynaDrawContext *dc); -static void set_to_accumulated(SPDynaDrawContext *dc, bool unionize, bool subtract); static void add_cap(SPCurve *curve, Geom::Point const &from, Geom::Point const &to, double rounding); -static bool accumulate_calligraphic(SPDynaDrawContext *dc); - -static void fit_and_split(SPDynaDrawContext *ddc, gboolean release); - -static void sp_dyna_draw_reset(SPDynaDrawContext *ddc, Geom::Point p); -static Geom::Point sp_dyna_draw_get_npoint(SPDynaDrawContext const *ddc, Geom::Point v); -static Geom::Point sp_dyna_draw_get_vpoint(SPDynaDrawContext const *ddc, Geom::Point n); -static void draw_temporary_box(SPDynaDrawContext *dc); #include "tool-factory.h" @@ -145,98 +135,82 @@ SPDynaDrawContext::SPDynaDrawContext() : SPCommonContext() { } SPDynaDrawContext::~SPDynaDrawContext() { - SPDynaDrawContext *ddc = SP_DYNA_DRAW_CONTEXT(this); - - if (ddc->hatch_area) { - sp_canvas_item_destroy(ddc->hatch_area); - ddc->hatch_area = NULL; + if (this->hatch_area) { + sp_canvas_item_destroy(this->hatch_area); + this->hatch_area = NULL; } - - - //G_OBJECT_CLASS(sp_dyna_draw_context_parent_class)->dispose(object); - -// ddc->hatch_pointer_past.~list(); -// ddc->hatch_nearest_past.~list(); -// ddc->inertia_vectors.~list(); -// ddc->hatch_vectors.~list(); } void SPDynaDrawContext::setup() { - SPEventContext* ec = this; - - SPDynaDrawContext *ddc = SP_DYNA_DRAW_CONTEXT(ec); - -// if ((SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->setup) -// (SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->setup(ec); SPCommonContext::setup(); - ddc->accumulated = new SPCurve(); - ddc->currentcurve = new SPCurve(); + this->accumulated = new SPCurve(); + this->currentcurve = new SPCurve(); - ddc->cal1 = new SPCurve(); - ddc->cal2 = new SPCurve(); + this->cal1 = new SPCurve(); + this->cal2 = new SPCurve(); + + this->currentshape = sp_canvas_item_new(sp_desktop_sketch(this->desktop), SP_TYPE_CANVAS_BPATH, NULL); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->currentshape), DDC_RED_RGBA, SP_WIND_RULE_EVENODD); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->currentshape), 0x00000000, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - ddc->currentshape = sp_canvas_item_new(sp_desktop_sketch(ec->desktop), SP_TYPE_CANVAS_BPATH, NULL); - sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(ddc->currentshape), DDC_RED_RGBA, SP_WIND_RULE_EVENODD); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(ddc->currentshape), 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(ddc->currentshape), "event", G_CALLBACK(sp_desktop_root_handler), ec->desktop); + g_signal_connect(G_OBJECT(this->currentshape), "event", G_CALLBACK(sp_desktop_root_handler), this->desktop); { /* TODO: this can be done either with an arcto, and should maybe also be put in a general file (other tools use this as well) */ SPCurve *c = new SPCurve(); + const double C1 = 0.552; + c->moveto(-1,0); c->curveto(-1, C1, -C1, 1, 0, 1 ); c->curveto(C1, 1, 1, C1, 1, 0 ); c->curveto(1, -C1, C1, -1, 0, -1 ); c->curveto(-C1, -1, -1, -C1, -1, 0 ); c->closepath(); - ddc->hatch_area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c); + + this->hatch_area = sp_canvas_bpath_new(sp_desktop_controls(this->desktop), c); + c->unref(); - sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(ddc->hatch_area), 0x00000000,(SPWindRule)0); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(ddc->hatch_area), 0x0000007f, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_item_hide(ddc->hatch_area); + + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->hatch_area), 0x00000000,(SPWindRule)0); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->hatch_area), 0x0000007f, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_item_hide(this->hatch_area); } - sp_event_context_read(ec, "mass"); - sp_event_context_read(ec, "wiggle"); - sp_event_context_read(ec, "angle"); - sp_event_context_read(ec, "width"); - sp_event_context_read(ec, "thinning"); - sp_event_context_read(ec, "tremor"); - sp_event_context_read(ec, "flatness"); - sp_event_context_read(ec, "tracebackground"); - 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"); - sp_event_context_read(ec, "cap_rounding"); - - ddc->is_drawing = false; - ddc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); + sp_event_context_read(this, "mass"); + sp_event_context_read(this, "wiggle"); + sp_event_context_read(this, "angle"); + sp_event_context_read(this, "width"); + sp_event_context_read(this, "thinning"); + sp_event_context_read(this, "tremor"); + sp_event_context_read(this, "flatness"); + sp_event_context_read(this, "tracebackground"); + sp_event_context_read(this, "usepressure"); + sp_event_context_read(this, "usetilt"); + sp_event_context_read(this, "abs_width"); + sp_event_context_read(this, "keep_selected"); + sp_event_context_read(this, "cap_rounding"); + + this->is_drawing = false; + this->_message_context = new Inkscape::MessageContext((this->desktop)->messageStack()); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/calligraphic/selcue")) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } } void SPDynaDrawContext::set(const Inkscape::Preferences::Entry& val) { - SPEventContext* ec = this; - - SPDynaDrawContext *ddc = SP_DYNA_DRAW_CONTEXT(ec); Glib::ustring path = val.getEntryName(); if (path == "tracebackground") { - ddc->trace_bg = val.getBool(); + this->trace_bg = val.getBool(); } else if (path == "keep_selected") { - ddc->keep_selected = val.getBool(); + this->keep_selected = val.getBool(); } else { //pass on up to parent class to handle common attributes. -// if ( SP_COMMON_CONTEXT_CLASS(sp_dyna_draw_context_parent_class)->set ) { -// SP_COMMON_CONTEXT_CLASS(sp_dyna_draw_context_parent_class)->set(ec, val); -// } SPCommonContext::set(val); } @@ -249,66 +223,64 @@ flerp(double f0, double f1, double p) return f0 + ( f1 - f0 ) * p; } -/* Get normalized point */ -static Geom::Point -sp_dyna_draw_get_npoint(SPDynaDrawContext const *dc, Geom::Point v) -{ - Geom::Rect drect = SP_EVENT_CONTEXT(dc)->desktop->get_display_area(); - double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); - return Geom::Point(( v[Geom::X] - drect.min()[Geom::X] ) / max, ( v[Geom::Y] - drect.min()[Geom::Y] ) / max); +///* Get normalized point */ +//Geom::Point SPDynaDrawContext::getNormalizedPoint(Geom::Point v) const { +// Geom::Rect drect = desktop->get_display_area(); +// +// double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); +// +// return Geom::Point(( v[Geom::X] - drect.min()[Geom::X] ) / max, ( v[Geom::Y] - drect.min()[Geom::Y] ) / max); +//} +// +///* Get view point */ +//Geom::Point SPDynaDrawContext::getViewPoint(Geom::Point n) const { +// Geom::Rect drect = desktop->get_display_area(); +// +// double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); +// +// return Geom::Point(n[Geom::X] * max + drect.min()[Geom::X], n[Geom::Y] * max + drect.min()[Geom::Y]); +//} + +void SPDynaDrawContext::reset(Geom::Point p) { + this->last = this->cur = this->getNormalizedPoint(p); + + this->vel = Geom::Point(0,0); + this->vel_max = 0; + this->acc = Geom::Point(0,0); + this->ang = Geom::Point(0,0); + this->del = Geom::Point(0,0); } -/* Get view point */ -static Geom::Point -sp_dyna_draw_get_vpoint(SPDynaDrawContext const *dc, Geom::Point n) -{ - Geom::Rect drect = SP_EVENT_CONTEXT(dc)->desktop->get_display_area(); - double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); - return Geom::Point(n[Geom::X] * max + drect.min()[Geom::X], n[Geom::Y] * max + drect.min()[Geom::Y]); -} +void SPDynaDrawContext::extinput(GdkEvent *event) { + if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &this->pressure)) { + this->pressure = CLAMP (this->pressure, DDC_MIN_PRESSURE, DDC_MAX_PRESSURE); + } else { + this->pressure = DDC_DEFAULT_PRESSURE; + } -static void -sp_dyna_draw_reset(SPDynaDrawContext *dc, Geom::Point p) -{ - dc->last = dc->cur = sp_dyna_draw_get_npoint(dc, p); - dc->vel = Geom::Point(0,0); - dc->vel_max = 0; - dc->acc = Geom::Point(0,0); - dc->ang = Geom::Point(0,0); - dc->del = Geom::Point(0,0); -} + if (gdk_event_get_axis (event, GDK_AXIS_XTILT, &this->xtilt)) { + this->xtilt = CLAMP (this->xtilt, DDC_MIN_TILT, DDC_MAX_TILT); + } else { + this->xtilt = DDC_DEFAULT_TILT; + } -static void -sp_dyna_draw_extinput(SPDynaDrawContext *dc, GdkEvent *event) -{ - if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &dc->pressure)) - dc->pressure = CLAMP (dc->pressure, DDC_MIN_PRESSURE, DDC_MAX_PRESSURE); - else - dc->pressure = DDC_DEFAULT_PRESSURE; - - if (gdk_event_get_axis (event, GDK_AXIS_XTILT, &dc->xtilt)) - dc->xtilt = CLAMP (dc->xtilt, DDC_MIN_TILT, DDC_MAX_TILT); - else - dc->xtilt = DDC_DEFAULT_TILT; - - if (gdk_event_get_axis (event, GDK_AXIS_YTILT, &dc->ytilt)) - dc->ytilt = CLAMP (dc->ytilt, DDC_MIN_TILT, DDC_MAX_TILT); - else - dc->ytilt = DDC_DEFAULT_TILT; + if (gdk_event_get_axis (event, GDK_AXIS_YTILT, &this->ytilt)) { + this->ytilt = CLAMP (this->ytilt, DDC_MIN_TILT, DDC_MAX_TILT); + } else { + this->ytilt = DDC_DEFAULT_TILT; + } } -static gboolean -sp_dyna_draw_apply(SPDynaDrawContext *dc, Geom::Point p) -{ - Geom::Point n = sp_dyna_draw_get_npoint(dc, p); +bool SPDynaDrawContext::apply(Geom::Point p) { + Geom::Point n = this->getNormalizedPoint(p); /* Calculate mass and drag */ - double const mass = flerp(1.0, 160.0, dc->mass); - double const drag = flerp(0.0, 0.5, dc->drag * dc->drag); + double const mass = flerp(1.0, 160.0, this->mass); + double const drag = flerp(0.0, 0.5, this->drag * this->drag); /* Calculate force and acceleration */ - Geom::Point force = n - dc->cur; + Geom::Point force = n - this->cur; // If force is below the absolute threshold DYNA_EPSILON, // or we haven't yet reached DYNA_VEL_START (i.e. at the beginning of stroke) @@ -317,27 +289,27 @@ sp_dyna_draw_apply(SPDynaDrawContext *dc, Geom::Point p) // This prevents flips, blobs, and jerks caused by microscopic tremor of the tablet pen, // especially bothersome at the start of the stroke where we don't yet have the inertia to // smooth them out. - if ( Geom::L2(force) < DYNA_EPSILON || (dc->vel_max < DYNA_VEL_START && Geom::L2(force) < DYNA_EPSILON_START)) { + if ( Geom::L2(force) < DYNA_EPSILON || (this->vel_max < DYNA_VEL_START && Geom::L2(force) < DYNA_EPSILON_START)) { return FALSE; } - dc->acc = force / mass; + this->acc = force / mass; /* Calculate new velocity */ - dc->vel += dc->acc; + this->vel += this->acc; - if (Geom::L2(dc->vel) > dc->vel_max) - dc->vel_max = Geom::L2(dc->vel); + if (Geom::L2(this->vel) > this->vel_max) + this->vel_max = Geom::L2(this->vel); /* Calculate angle of drawing tool */ double a1; - if (dc->usetilt) { + if (this->usetilt) { // 1a. calculate nib angle from input device tilt: - gdouble length = std::sqrt(dc->xtilt*dc->xtilt + dc->ytilt*dc->ytilt);; + gdouble length = std::sqrt(this->xtilt*this->xtilt + this->ytilt*this->ytilt);; if (length > 0) { - Geom::Point ang1 = Geom::Point(dc->ytilt/length, dc->xtilt/length); + Geom::Point ang1 = Geom::Point(this->ytilt/length, this->xtilt/length); a1 = atan2(ang1); } else @@ -345,17 +317,17 @@ sp_dyna_draw_apply(SPDynaDrawContext *dc, Geom::Point p) } else { // 1b. fixed dc->angle (absolutely flat nib): - double const radians = ( (dc->angle - 90) / 180.0 ) * M_PI; + double const radians = ( (this->angle - 90) / 180.0 ) * M_PI; Geom::Point ang1 = Geom::Point(-sin(radians), cos(radians)); a1 = atan2(ang1); } // 2. perpendicular to dc->vel (absolutely non-flat nib): - gdouble const mag_vel = Geom::L2(dc->vel); + gdouble const mag_vel = Geom::L2(this->vel); if ( mag_vel < DYNA_EPSILON ) { return FALSE; } - Geom::Point ang2 = Geom::rot90(dc->vel) / mag_vel; + Geom::Point ang2 = Geom::rot90(this->vel) / mag_vel; // 3. Average them using flatness parameter: // calculate angles @@ -373,53 +345,51 @@ sp_dyna_draw_apply(SPDynaDrawContext *dc, Geom::Point p) a2 += 2*M_PI; // find the flatness-weighted bisector angle, unflip if a2 was flipped // FIXME: when dc->vel is oscillating around the fixed angle, the new_ang flips back and forth. How to avoid this? - double new_ang = a1 + (1 - dc->flatness) * (a2 - a1) - (flipped? M_PI : 0); + double new_ang = a1 + (1 - this->flatness) * (a2 - a1) - (flipped? M_PI : 0); // Try to detect a sudden flip when the new angle differs too much from the previous for the // current velocity; in that case discard this move - double angle_delta = Geom::L2(Geom::Point (cos (new_ang), sin (new_ang)) - dc->ang); - if ( angle_delta / Geom::L2(dc->vel) > 4000 ) { + double angle_delta = Geom::L2(Geom::Point (cos (new_ang), sin (new_ang)) - this->ang); + if ( angle_delta / Geom::L2(this->vel) > 4000 ) { return FALSE; } // convert to point - dc->ang = Geom::Point (cos (new_ang), sin (new_ang)); + this->ang = Geom::Point (cos (new_ang), sin (new_ang)); // g_print ("force %g acc %g vel_max %g vel %g a1 %g a2 %g new_ang %g\n", Geom::L2(force), Geom::L2(dc->acc), dc->vel_max, Geom::L2(dc->vel), a1, a2, new_ang); /* Apply drag */ - dc->vel *= 1.0 - drag; + this->vel *= 1.0 - drag; /* Update position */ - dc->last = dc->cur; - dc->cur += dc->vel; + this->last = this->cur; + this->cur += this->vel; return TRUE; } -static void -sp_dyna_draw_brush(SPDynaDrawContext *dc) -{ - g_assert( dc->npoints >= 0 && dc->npoints < SAMPLING_SIZE ); +void SPDynaDrawContext::brush() { + g_assert( this->npoints >= 0 && this->npoints < SAMPLING_SIZE ); // How much velocity thins strokestyle - double vel_thin = flerp (0, 160, dc->vel_thin); + double vel_thin = flerp (0, 160, this->vel_thin); // Influence of pressure on thickness - double pressure_thick = (dc->usepressure ? dc->pressure : 1.0); + double pressure_thick = (this->usepressure ? this->pressure : 1.0); // get the real brush point, not the same as pointer (affected by hatch tracking and/or mass // drag) - Geom::Point brush = sp_dyna_draw_get_vpoint(dc, dc->cur); - Geom::Point brush_w = SP_EVENT_CONTEXT(dc)->desktop->d2w(brush); + Geom::Point brush = this->getViewPoint(this->cur); + Geom::Point brush_w = SP_EVENT_CONTEXT(this)->desktop->d2w(brush); double trace_thick = 1; - if (dc->trace_bg) { + if (this->trace_bg) { // pick single pixel double R, G, B, A; Geom::IntRect area = Geom::IntRect::from_xywh(brush_w.floor(), Geom::IntPoint(1, 1)); cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); - sp_canvas_arena_render_surface(SP_CANVAS_ARENA(sp_desktop_drawing(SP_EVENT_CONTEXT(dc)->desktop)), s, area); + sp_canvas_arena_render_surface(SP_CANVAS_ARENA(sp_desktop_drawing(SP_EVENT_CONTEXT(this)->desktop)), s, area); ink_cairo_surface_average_color_premul(s, R, G, B, A); cairo_surface_destroy(s); double max = MAX (MAX (R, G), B); @@ -429,10 +399,10 @@ sp_dyna_draw_brush(SPDynaDrawContext *dc) //g_print ("L %g thick %g\n", L, trace_thick); } - double width = (pressure_thick * trace_thick - vel_thin * Geom::L2(dc->vel)) * dc->width; + double width = (pressure_thick * trace_thick - vel_thin * Geom::L2(this->vel)) * this->width; double tremble_left = 0, tremble_right = 0; - if (dc->tremor > 0) { + if (this->tremor > 0) { // obtain two normally distributed random variables, using polar Box-Muller transform double x1, x2, w, y1, y2; do { @@ -449,28 +419,28 @@ sp_dyna_draw_brush(SPDynaDrawContext *dc) // (2) deflection depends on width, but is upped for small widths for better visual uniformity across widths; // (3) deflection somewhat depends on speed, to prevent fast strokes looking // comparatively smooth and slow ones excessively jittery - tremble_left = (y1)*dc->tremor * (0.15 + 0.8*width) * (0.35 + 14*Geom::L2(dc->vel)); - tremble_right = (y2)*dc->tremor * (0.15 + 0.8*width) * (0.35 + 14*Geom::L2(dc->vel)); + tremble_left = (y1)*this->tremor * (0.15 + 0.8*width) * (0.35 + 14*Geom::L2(this->vel)); + tremble_right = (y2)*this->tremor * (0.15 + 0.8*width) * (0.35 + 14*Geom::L2(this->vel)); } - if ( width < 0.02 * dc->width ) { - width = 0.02 * dc->width; + if ( width < 0.02 * this->width ) { + width = 0.02 * this->width; } double dezoomify_factor = 0.05 * 1000; - if (!dc->abs_width) { - dezoomify_factor /= SP_EVENT_CONTEXT(dc)->desktop->current_zoom(); + if (!this->abs_width) { + dezoomify_factor /= SP_EVENT_CONTEXT(this)->desktop->current_zoom(); } - Geom::Point del_left = dezoomify_factor * (width + tremble_left) * dc->ang; - Geom::Point del_right = dezoomify_factor * (width + tremble_right) * dc->ang; + Geom::Point del_left = dezoomify_factor * (width + tremble_left) * this->ang; + Geom::Point del_right = dezoomify_factor * (width + tremble_right) * this->ang; - dc->point1[dc->npoints] = brush + del_left; - dc->point2[dc->npoints] = brush - del_right; + this->point1[this->npoints] = brush + del_left; + this->point2[this->npoints] = brush - del_right; - dc->del = 0.5*(del_left + del_right); + this->del = 0.5*(del_left + del_right); - dc->npoints++; + this->npoints++; } static void @@ -479,51 +449,45 @@ sp_ddc_update_toolbox (SPDesktop *desktop, const gchar *id, double value) desktop->setToolboxAdjustmentValue (id, value); } -static void -calligraphic_cancel(SPDynaDrawContext *dc) -{ - SPDesktop *desktop = SP_EVENT_CONTEXT(dc)->desktop; - dc->dragging = FALSE; - dc->is_drawing = false; +void SPDynaDrawContext::cancel() { + this->dragging = false; + this->is_drawing = false; + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0); - /* Remove all temporary line segments */ - while (dc->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(dc->segments->data)); - dc->segments = g_slist_remove(dc->segments, dc->segments->data); - } - /* reset accumulated curve */ - dc->accumulated->reset(); - clear_current(dc); - if (dc->repr) { - dc->repr = NULL; - } -} -gint SPDynaDrawContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; + /* Remove all temporary line segments */ + while (this->segments) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); + this->segments = g_slist_remove(this->segments, this->segments->data); + } + + /* reset accumulated curve */ + this->accumulated->reset(); + this->clear_current(); - SPDynaDrawContext *dc = SP_DYNA_DRAW_CONTEXT(event_context); - SPDesktop *desktop = event_context->desktop; + if (this->repr) { + this->repr = NULL; + } +} +bool SPDynaDrawContext::root_handler(GdkEvent* event) { gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: - if (event->button.button == 1 && !event_context->space_panning) { - - SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc); - - if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) { + if (event->button.button == 1 && !this->space_panning) { + if (Inkscape::have_viable_layer(desktop, this->_message_context) == false) { return TRUE; } - dc->accumulated->reset(); - if (dc->repr) { - dc->repr = NULL; + this->accumulated->reset(); + + if (this->repr) { + this->repr = NULL; } /* initialize first point */ - dc->npoints = 0; + this->npoints = 0; sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), ( GDK_KEY_PRESS_MASK | @@ -536,8 +500,8 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { ret = TRUE; desktop->canvas->forceFullRedrawAfterInterruptions(3); - dc->is_drawing = true; - dc->just_started_drawing = true; + this->is_drawing = true; + this->just_started_drawing = true; } break; case GDK_MOTION_NOTIFY: @@ -545,9 +509,9 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { Geom::Point const motion_w(event->motion.x, event->motion.y); Geom::Point motion_dt(desktop->w2d(motion_w)); - sp_dyna_draw_extinput(dc, event); + this->extinput(event); - dc->_message_context->clear(); + this->_message_context->clear(); // for hatching: double hatch_dist = 0; @@ -563,12 +527,12 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { // One item selected, and it's a path; // let's try to track it as a guide - if (selected != dc->hatch_item) { - dc->hatch_item = selected; - if (dc->hatch_livarot_path) - delete dc->hatch_livarot_path; - dc->hatch_livarot_path = Path_for_item (dc->hatch_item, true, true); - dc->hatch_livarot_path->ConvertWithBackData(0.01); + if (selected != this->hatch_item) { + this->hatch_item = selected; + if (this->hatch_livarot_path) + delete this->hatch_livarot_path; + this->hatch_livarot_path = Path_for_item (this->hatch_item, true, true); + this->hatch_livarot_path->ConvertWithBackData(0.01); } // calculate pointer point in the guide item's coords @@ -576,8 +540,8 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { pointer = motion_dt * motion_to_curve; // calculate the nearest point on the guide path - boost::optional<Path::cut_position> position = get_nearest_position_on_Path(dc->hatch_livarot_path, pointer); - nearest = get_point_on_Path(dc->hatch_livarot_path, position->piece, position->t); + boost::optional<Path::cut_position> position = get_nearest_position_on_Path(this->hatch_livarot_path, pointer); + nearest = get_point_on_Path(this->hatch_livarot_path, position->piece, position->t); // distance from pointer to nearest @@ -585,16 +549,16 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { // unit-length vector hatch_unit_vector = (pointer - nearest)/hatch_dist; - dc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Guide path selected</b>; start drawing along the guide with <b>Ctrl</b>")); + this->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Guide path selected</b>; start drawing along the guide with <b>Ctrl</b>")); } else { - dc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Select a guide path</b> to track with <b>Ctrl</b>")); + this->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Select a guide path</b> to track with <b>Ctrl</b>")); } } - if ( dc->is_drawing && (event->motion.state & GDK_BUTTON1_MASK) && !event_context->space_panning) { - dc->dragging = TRUE; + if ( this->is_drawing && (event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) { + this->dragging = TRUE; - if (event->motion.state & GDK_CONTROL_MASK && dc->hatch_item) { // hatching + if (event->motion.state & GDK_CONTROL_MASK && this->hatch_item) { // hatching #define HATCH_VECTOR_ELEMENTS 12 #define INERTIA_ELEMENTS 24 @@ -616,33 +580,33 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { // mass recommended; with zero mass, jerks are still quite noticeable). double speed = 1; - if (Geom::L2(dc->hatch_last_nearest) != 0) { + if (Geom::L2(this->hatch_last_nearest) != 0) { // the distance nearest moved since the last motion event - double nearest_moved = Geom::L2(nearest - dc->hatch_last_nearest); + double nearest_moved = Geom::L2(nearest - this->hatch_last_nearest); // the distance pointer moved since the last motion event - double pointer_moved = Geom::L2(pointer - dc->hatch_last_pointer); + double pointer_moved = Geom::L2(pointer - this->hatch_last_pointer); // store them in stacks limited to SPEED_ELEMENTS - dc->hatch_nearest_past.push_front(nearest_moved); - if (dc->hatch_nearest_past.size() > SPEED_ELEMENTS) - dc->hatch_nearest_past.pop_back(); - dc->hatch_pointer_past.push_front(pointer_moved); - if (dc->hatch_pointer_past.size() > SPEED_ELEMENTS) - dc->hatch_pointer_past.pop_back(); + this->hatch_nearest_past.push_front(nearest_moved); + if (this->hatch_nearest_past.size() > SPEED_ELEMENTS) + this->hatch_nearest_past.pop_back(); + this->hatch_pointer_past.push_front(pointer_moved); + if (this->hatch_pointer_past.size() > SPEED_ELEMENTS) + this->hatch_pointer_past.pop_back(); // If the stacks are full, - if (dc->hatch_nearest_past.size() == SPEED_ELEMENTS) { + if (this->hatch_nearest_past.size() == SPEED_ELEMENTS) { // calculate the sums of all stored movements - double nearest_sum = std::accumulate (dc->hatch_nearest_past.begin(), dc->hatch_nearest_past.end(), 0.0); - double pointer_sum = std::accumulate (dc->hatch_pointer_past.begin(), dc->hatch_pointer_past.end(), 0.0); + double nearest_sum = std::accumulate (this->hatch_nearest_past.begin(), this->hatch_nearest_past.end(), 0.0); + double pointer_sum = std::accumulate (this->hatch_pointer_past.begin(), this->hatch_pointer_past.end(), 0.0); // and divide to get the speed speed = nearest_sum/pointer_sum; //g_print ("nearest sum %g pointer_sum %g speed %g\n", nearest_sum, pointer_sum, speed); } } - if ( dc->hatch_escaped // already escaped, do not reattach + if ( this->hatch_escaped // already escaped, do not reattach || (speed < SPEED_MIN) // stuck; most likely reached end of traced stroke - || (dc->hatch_spacing > 0 && hatch_dist > 50 * dc->hatch_spacing) // went too far from the guide + || (this->hatch_spacing > 0 && hatch_dist > 50 * this->hatch_spacing) // went too far from the guide ) { // We are NOT attracted to the guide! @@ -650,12 +614,12 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { // Remember hatch_escaped so we don't get // attracted again until the end of this stroke - dc->hatch_escaped = true; + this->hatch_escaped = true; - if (dc->inertia_vectors.size() >= INERTIA_ELEMENTS/2) { // move by inertia - Geom::Point moved_past_escape = motion_dt - dc->inertia_vectors.front(); + if (this->inertia_vectors.size() >= INERTIA_ELEMENTS/2) { // move by inertia + Geom::Point moved_past_escape = motion_dt - this->inertia_vectors.front(); Geom::Point inertia = - dc->inertia_vectors.front() - dc->inertia_vectors.back(); + this->inertia_vectors.front() - this->inertia_vectors.back(); double dot = Geom::dot (moved_past_escape, inertia); dot /= Geom::L2(moved_past_escape) * Geom::L2(inertia); @@ -663,7 +627,7 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { if (dot > 0) { // mouse is still moving in approx the same direction Geom::Point should_have_moved = (inertia) * (1/Geom::L2(inertia)) * Geom::L2(moved_past_escape); - motion_dt = dc->inertia_vectors.front() + + motion_dt = this->inertia_vectors.front() + (INERTIA_FORCE * should_have_moved + (1 - INERTIA_FORCE) * moved_past_escape); } } @@ -674,19 +638,19 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { // summed, to detect if we accidentally flipped to the other side of the // guide Geom::Point hatch_vector_accumulated = std::accumulate - (dc->hatch_vectors.begin(), dc->hatch_vectors.end(), Geom::Point(0,0)); + (this->hatch_vectors.begin(), this->hatch_vectors.end(), Geom::Point(0,0)); double dot = Geom::dot (pointer - nearest, hatch_vector_accumulated); dot /= Geom::L2(pointer - nearest) * Geom::L2(hatch_vector_accumulated); - if (dc->hatch_spacing != 0) { // spacing was already set + if (this->hatch_spacing != 0) { // spacing was already set double target; if (speed > SPEED_NORMAL) { // all ok, strictly obey the spacing - target = dc->hatch_spacing; + target = this->hatch_spacing; } else { // looks like we're starting to lose speed, // so _gradually_ let go attraction to prevent jerks - target = (dc->hatch_spacing * speed + hatch_dist * (SPEED_NORMAL - speed))/SPEED_NORMAL; + target = (this->hatch_spacing * speed + hatch_dist * (SPEED_NORMAL - speed))/SPEED_NORMAL; } if (!IS_NAN(dot) && dot < -0.5) {// flip target = -target; @@ -697,91 +661,91 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { // some limited feedback: allow persistent pulling to slightly change // the spacing - dc->hatch_spacing += (hatch_dist - dc->hatch_spacing)/3500; + this->hatch_spacing += (hatch_dist - this->hatch_spacing)/3500; // return it to the desktop coords motion_dt = new_pointer * motion_to_curve.inverse(); if (speed >= SPEED_NORMAL) { - dc->inertia_vectors.push_front(motion_dt); - if (dc->inertia_vectors.size() > INERTIA_ELEMENTS) - dc->inertia_vectors.pop_back(); + this->inertia_vectors.push_front(motion_dt); + if (this->inertia_vectors.size() > INERTIA_ELEMENTS) + this->inertia_vectors.pop_back(); } } else { // this is the first motion event, set the dist - dc->hatch_spacing = hatch_dist; + this->hatch_spacing = hatch_dist; } // remember last points - dc->hatch_last_pointer = pointer; - dc->hatch_last_nearest = nearest; + this->hatch_last_pointer = pointer; + this->hatch_last_nearest = nearest; - dc->hatch_vectors.push_front(pointer - nearest); - if (dc->hatch_vectors.size() > HATCH_VECTOR_ELEMENTS) - dc->hatch_vectors.pop_back(); + this->hatch_vectors.push_front(pointer - nearest); + if (this->hatch_vectors.size() > HATCH_VECTOR_ELEMENTS) + this->hatch_vectors.pop_back(); } - dc->_message_context->set(Inkscape::NORMAL_MESSAGE, dc->hatch_escaped? _("Tracking: <b>connection to guide path lost!</b>") : _("<b>Tracking</b> a guide path")); + this->_message_context->set(Inkscape::NORMAL_MESSAGE, this->hatch_escaped? _("Tracking: <b>connection to guide path lost!</b>") : _("<b>Tracking</b> a guide path")); } else { - dc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Drawing</b> a calligraphic stroke")); + this->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Drawing</b> a calligraphic stroke")); } - if (dc->just_started_drawing) { - dc->just_started_drawing = false; - sp_dyna_draw_reset(dc, motion_dt); + if (this->just_started_drawing) { + this->just_started_drawing = false; + this->reset(motion_dt); } - if (!sp_dyna_draw_apply(dc, motion_dt)) { + if (!this->apply(motion_dt)) { ret = TRUE; break; } - if ( dc->cur != dc->last ) { - sp_dyna_draw_brush(dc); - g_assert( dc->npoints > 0 ); - fit_and_split(dc, FALSE); + if ( this->cur != this->last ) { + this->brush(); + g_assert( this->npoints > 0 ); + this->fit_and_split(false); } ret = TRUE; } // Draw the hatching circle if necessary if (event->motion.state & GDK_CONTROL_MASK) { - if (dc->hatch_spacing == 0 && hatch_dist != 0) { + if (this->hatch_spacing == 0 && hatch_dist != 0) { // Haven't set spacing yet: gray, center free, update radius live Geom::Point c = desktop->w2d(motion_w); Geom::Affine const sm (Geom::Scale(hatch_dist, hatch_dist) * Geom::Translate(c)); - sp_canvas_item_affine_absolute(dc->hatch_area, sm); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->hatch_area), 0x7f7f7fff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_item_show(dc->hatch_area); - } else if (dc->dragging && !dc->hatch_escaped) { + sp_canvas_item_affine_absolute(this->hatch_area, sm); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->hatch_area), 0x7f7f7fff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_item_show(this->hatch_area); + } else if (this->dragging && !this->hatch_escaped) { // Tracking: green, center snapped, fixed radius Geom::Point c = motion_dt; - Geom::Affine const sm (Geom::Scale(dc->hatch_spacing, dc->hatch_spacing) * Geom::Translate(c)); - sp_canvas_item_affine_absolute(dc->hatch_area, sm); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->hatch_area), 0x00FF00ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_item_show(dc->hatch_area); - } else if (dc->dragging && dc->hatch_escaped) { + Geom::Affine const sm (Geom::Scale(this->hatch_spacing, this->hatch_spacing) * Geom::Translate(c)); + sp_canvas_item_affine_absolute(this->hatch_area, sm); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->hatch_area), 0x00FF00ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_item_show(this->hatch_area); + } else if (this->dragging && this->hatch_escaped) { // Tracking escaped: red, center free, fixed radius Geom::Point c = motion_dt; - Geom::Affine const sm (Geom::Scale(dc->hatch_spacing, dc->hatch_spacing) * Geom::Translate(c)); + Geom::Affine const sm (Geom::Scale(this->hatch_spacing, this->hatch_spacing) * Geom::Translate(c)); - sp_canvas_item_affine_absolute(dc->hatch_area, sm); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->hatch_area), 0xFF0000ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_item_show(dc->hatch_area); + sp_canvas_item_affine_absolute(this->hatch_area, sm); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->hatch_area), 0xFF0000ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_item_show(this->hatch_area); } else { // Not drawing but spacing set: gray, center snapped, fixed radius - Geom::Point c = (nearest + dc->hatch_spacing * hatch_unit_vector) * motion_to_curve.inverse(); + Geom::Point c = (nearest + this->hatch_spacing * hatch_unit_vector) * motion_to_curve.inverse(); if (!IS_NAN(c[Geom::X]) && !IS_NAN(c[Geom::Y])) { - Geom::Affine const sm (Geom::Scale(dc->hatch_spacing, dc->hatch_spacing) * Geom::Translate(c)); - sp_canvas_item_affine_absolute(dc->hatch_area, sm); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->hatch_area), 0x7f7f7fff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_item_show(dc->hatch_area); + Geom::Affine const sm (Geom::Scale(this->hatch_spacing, this->hatch_spacing) * Geom::Translate(c)); + sp_canvas_item_affine_absolute(this->hatch_area, sm); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->hatch_area), 0x7f7f7fff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_item_show(this->hatch_area); } } } else { - sp_canvas_item_hide(dc->hatch_area); + sp_canvas_item_hide(this->hatch_area); } } break; @@ -794,54 +758,54 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); desktop->canvas->endForcedFullRedraws(); - dc->is_drawing = false; + this->is_drawing = false; - if (dc->dragging && event->button.button == 1 && !event_context->space_panning) { - dc->dragging = FALSE; + if (this->dragging && event->button.button == 1 && !this->space_panning) { + this->dragging = FALSE; - sp_dyna_draw_apply(dc, motion_dt); + this->apply(motion_dt); /* Remove all temporary line segments */ - while (dc->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(dc->segments->data)); - dc->segments = g_slist_remove(dc->segments, dc->segments->data); + while (this->segments) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); + this->segments = g_slist_remove(this->segments, this->segments->data); } /* Create object */ - fit_and_split(dc, TRUE); - if (accumulate_calligraphic(dc)) - set_to_accumulated(dc, event->button.state & GDK_SHIFT_MASK, event->button.state & GDK_MOD1_MASK); // performs document_done + this->fit_and_split(true); + if (this->accumulate()) + this->set_to_accumulated(event->button.state & GDK_SHIFT_MASK, event->button.state & GDK_MOD1_MASK); // performs document_done else g_warning ("Failed to create path: invalid data in dc->cal1 or dc->cal2"); /* reset accumulated curve */ - dc->accumulated->reset(); + this->accumulated->reset(); - clear_current(dc); - if (dc->repr) { - dc->repr = NULL; + this->clear_current(); + if (this->repr) { + this->repr = NULL; } - if (!dc->hatch_pointer_past.empty()) dc->hatch_pointer_past.clear(); - if (!dc->hatch_nearest_past.empty()) dc->hatch_nearest_past.clear(); - if (!dc->inertia_vectors.empty()) dc->inertia_vectors.clear(); - if (!dc->hatch_vectors.empty()) dc->hatch_vectors.clear(); - dc->hatch_last_nearest = Geom::Point(0,0); - dc->hatch_last_pointer = Geom::Point(0,0); - dc->hatch_escaped = false; - dc->hatch_item = NULL; - dc->hatch_livarot_path = NULL; - dc->just_started_drawing = false; - - if (dc->hatch_spacing != 0 && !dc->keep_selected) { + if (!this->hatch_pointer_past.empty()) this->hatch_pointer_past.clear(); + if (!this->hatch_nearest_past.empty()) this->hatch_nearest_past.clear(); + if (!this->inertia_vectors.empty()) this->inertia_vectors.clear(); + if (!this->hatch_vectors.empty()) this->hatch_vectors.clear(); + this->hatch_last_nearest = Geom::Point(0,0); + this->hatch_last_pointer = Geom::Point(0,0); + this->hatch_escaped = false; + this->hatch_item = NULL; + this->hatch_livarot_path = NULL; + this->just_started_drawing = false; + + if (this->hatch_spacing != 0 && !this->keep_selected) { // we do not select the newly drawn path, so increase spacing by step - if (dc->hatch_spacing_step == 0) { - dc->hatch_spacing_step = dc->hatch_spacing; + if (this->hatch_spacing_step == 0) { + this->hatch_spacing_step = this->hatch_spacing; } - dc->hatch_spacing += dc->hatch_spacing_step; + this->hatch_spacing += this->hatch_spacing_step; } - dc->_message_context->clear(); + this->_message_context->clear(); ret = TRUE; } break; @@ -852,53 +816,53 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { case GDK_KEY_Up: case GDK_KEY_KP_Up: if (!MOD__CTRL_ONLY(event)) { - dc->angle += 5.0; - if (dc->angle > 90.0) - dc->angle = 90.0; - sp_ddc_update_toolbox (desktop, "calligraphy-angle", dc->angle); + this->angle += 5.0; + if (this->angle > 90.0) + this->angle = 90.0; + sp_ddc_update_toolbox (desktop, "calligraphy-angle", this->angle); ret = TRUE; } break; case GDK_KEY_Down: case GDK_KEY_KP_Down: if (!MOD__CTRL_ONLY(event)) { - dc->angle -= 5.0; - if (dc->angle < -90.0) - dc->angle = -90.0; - sp_ddc_update_toolbox (desktop, "calligraphy-angle", dc->angle); + this->angle -= 5.0; + if (this->angle < -90.0) + this->angle = -90.0; + sp_ddc_update_toolbox (desktop, "calligraphy-angle", this->angle); ret = TRUE; } break; case GDK_KEY_Right: case GDK_KEY_KP_Right: if (!MOD__CTRL_ONLY(event)) { - dc->width += 0.01; - if (dc->width > 1.0) - dc->width = 1.0; - sp_ddc_update_toolbox (desktop, "altx-calligraphy", dc->width * 100); // the same spinbutton is for alt+x + this->width += 0.01; + if (this->width > 1.0) + this->width = 1.0; + sp_ddc_update_toolbox (desktop, "altx-calligraphy", this->width * 100); // the same spinbutton is for alt+x ret = TRUE; } break; case GDK_KEY_Left: case GDK_KEY_KP_Left: if (!MOD__CTRL_ONLY(event)) { - dc->width -= 0.01; - if (dc->width < 0.01) - dc->width = 0.01; - sp_ddc_update_toolbox (desktop, "altx-calligraphy", dc->width * 100); + this->width -= 0.01; + if (this->width < 0.01) + this->width = 0.01; + sp_ddc_update_toolbox (desktop, "altx-calligraphy", this->width * 100); ret = TRUE; } break; case GDK_KEY_Home: case GDK_KEY_KP_Home: - dc->width = 0.01; - sp_ddc_update_toolbox (desktop, "altx-calligraphy", dc->width * 100); + this->width = 0.01; + sp_ddc_update_toolbox (desktop, "altx-calligraphy", this->width * 100); ret = TRUE; break; case GDK_KEY_End: case GDK_KEY_KP_End: - dc->width = 1.0; - sp_ddc_update_toolbox (desktop, "altx-calligraphy", dc->width * 100); + this->width = 1.0; + sp_ddc_update_toolbox (desktop, "altx-calligraphy", this->width * 100); ret = TRUE; break; case GDK_KEY_x: @@ -909,17 +873,17 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { } break; case GDK_KEY_Escape: - if (dc->is_drawing) { + if (this->is_drawing) { // if drawing, cancel, otherwise pass it up for deselecting - calligraphic_cancel (dc); + this->cancel(); ret = TRUE; } break; case GDK_KEY_z: case GDK_KEY_Z: - if (MOD__CTRL_ONLY(event) && dc->is_drawing) { + if (MOD__CTRL_ONLY(event) && this->is_drawing) { // if drawing, cancel, otherwise pass it up for undo - calligraphic_cancel (dc); + this->cancel(); ret = TRUE; } break; @@ -932,13 +896,14 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { switch (get_group0_keyval(&event->key)) { case GDK_KEY_Control_L: case GDK_KEY_Control_R: - dc->_message_context->clear(); - dc->hatch_spacing = 0; - dc->hatch_spacing_step = 0; + this->_message_context->clear(); + this->hatch_spacing = 0; + this->hatch_spacing_step = 0; break; default: break; } + break; default: break; @@ -955,26 +920,20 @@ gint SPDynaDrawContext::root_handler(GdkEvent* event) { } -static void -clear_current(SPDynaDrawContext *dc) -{ +void SPDynaDrawContext::clear_current() { /* reset bpath */ - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->currentshape), NULL); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), NULL); /* reset curve */ - dc->currentcurve->reset(); - dc->cal1->reset(); - dc->cal2->reset(); + this->currentcurve->reset(); + this->cal1->reset(); + this->cal2->reset(); /* reset points */ - dc->npoints = 0; + this->npoints = 0; } -static void -set_to_accumulated(SPDynaDrawContext *dc, bool unionize, bool subtract) -{ - SPDesktop *desktop = SP_EVENT_CONTEXT(dc)->desktop; - - if (!dc->accumulated->is_empty()) { - if (!dc->repr) { +void SPDynaDrawContext::set_to_accumulated(bool unionize, bool subtract) { + if (!this->accumulated->is_empty()) { + if (!this->repr) { /* Create object */ Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); @@ -982,36 +941,37 @@ set_to_accumulated(SPDynaDrawContext *dc, bool unionize, bool subtract) /* Set style */ sp_desktop_apply_style_tool (desktop, repr, "/tools/calligraphic", false); - dc->repr = repr; + this->repr = repr; - SPItem *item=SP_ITEM(desktop->currentLayer()->appendChildRepr(dc->repr)); - Inkscape::GC::release(dc->repr); + SPItem *item=SP_ITEM(desktop->currentLayer()->appendChildRepr(this->repr)); + Inkscape::GC::release(this->repr); item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); item->updateRepr(); } - Geom::PathVector pathv = dc->accumulated->get_pathvector() * desktop->dt2doc(); + + Geom::PathVector pathv = this->accumulated->get_pathvector() * desktop->dt2doc(); gchar *str = sp_svg_write_path(pathv); g_assert( str != NULL ); - dc->repr->setAttribute("d", str); + this->repr->setAttribute("d", str); g_free(str); if (unionize) { - sp_desktop_selection(desktop)->add(dc->repr); + sp_desktop_selection(desktop)->add(this->repr); sp_selected_path_union_skip_undo(sp_desktop_selection(desktop), desktop); } else if (subtract) { - sp_desktop_selection(desktop)->add(dc->repr); + sp_desktop_selection(desktop)->add(this->repr); sp_selected_path_diff_skip_undo(sp_desktop_selection(desktop), desktop); } else { - if (dc->keep_selected) { - sp_desktop_selection(desktop)->set(dc->repr); + if (this->keep_selected) { + sp_desktop_selection(desktop)->set(this->repr); } } - } else { - if (dc->repr) { - sp_repr_unparent(dc->repr); + if (this->repr) { + sp_repr_unparent(this->repr); } - dc->repr = NULL; + + this->repr = NULL; } DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_CALLIGRAPHIC, @@ -1033,54 +993,54 @@ add_cap(SPCurve *curve, } } -static bool -accumulate_calligraphic(SPDynaDrawContext *dc) -{ - if ( - dc->cal1->is_empty() || - dc->cal2->is_empty() || - (dc->cal1->get_segment_count() <= 0) || - dc->cal1->first_path()->closed() - ) { - dc->cal1->reset(); - dc->cal2->reset(); - return false; // failure - } +bool SPDynaDrawContext::accumulate() { + if ( + this->cal1->is_empty() || + this->cal2->is_empty() || + (this->cal1->get_segment_count() <= 0) || + this->cal1->first_path()->closed() + ) { - SPCurve *rev_cal2 = dc->cal2->create_reverse(); - if ( - (rev_cal2->get_segment_count() <= 0) || - rev_cal2->first_path()->closed() - ) { - rev_cal2->unref(); - dc->cal1->reset(); - dc->cal2->reset(); - return false; // failure - } + this->cal1->reset(); + this->cal2->reset(); + + return false; // failure + } + + SPCurve *rev_cal2 = this->cal2->create_reverse(); + + if ((rev_cal2->get_segment_count() <= 0) || rev_cal2->first_path()->closed()) { + rev_cal2->unref(); + + this->cal1->reset(); + this->cal2->reset(); + + return false; // failure + } - Geom::Curve const * dc_cal1_firstseg = dc->cal1->first_segment(); - Geom::Curve const * rev_cal2_firstseg = rev_cal2->first_segment(); - Geom::Curve const * dc_cal1_lastseg = dc->cal1->last_segment(); - Geom::Curve const * rev_cal2_lastseg = rev_cal2->last_segment(); + Geom::Curve const * dc_cal1_firstseg = this->cal1->first_segment(); + Geom::Curve const * rev_cal2_firstseg = rev_cal2->first_segment(); + Geom::Curve const * dc_cal1_lastseg = this->cal1->last_segment(); + Geom::Curve const * rev_cal2_lastseg = rev_cal2->last_segment(); - dc->accumulated->reset(); /* Is this required ?? */ + this->accumulated->reset(); /* Is this required ?? */ - dc->accumulated->append(dc->cal1, false); + this->accumulated->append(this->cal1, false); - add_cap(dc->accumulated, dc_cal1_lastseg->finalPoint(), rev_cal2_firstseg->initialPoint(), dc->cap_rounding); + add_cap(this->accumulated, dc_cal1_lastseg->finalPoint(), rev_cal2_firstseg->initialPoint(), this->cap_rounding); - dc->accumulated->append(rev_cal2, true); + this->accumulated->append(rev_cal2, true); - add_cap(dc->accumulated, rev_cal2_lastseg->finalPoint(), dc_cal1_firstseg->initialPoint(), dc->cap_rounding); + add_cap(this->accumulated, rev_cal2_lastseg->finalPoint(), dc_cal1_firstseg->initialPoint(), this->cap_rounding); - dc->accumulated->closepath(); + this->accumulated->closepath(); - rev_cal2->unref(); + rev_cal2->unref(); - dc->cal1->reset(); - dc->cal2->reset(); + this->cal1->reset(); + this->cal2->reset(); - return true; // success + return true; // success } static double square(double const x) @@ -1088,48 +1048,45 @@ static double square(double const x) return x * x; } -static void -fit_and_split(SPDynaDrawContext *dc, gboolean release) -{ - SPDesktop *desktop = SP_EVENT_CONTEXT(dc)->desktop; - +void SPDynaDrawContext::fit_and_split(bool release) { double const tolerance_sq = square( desktop->w2d().descrim() * TOLERANCE_CALLIGRAPHIC ); #ifdef DYNA_DRAW_VERBOSE g_print("[F&S:R=%c]", release?'T':'F'); #endif - if (!( dc->npoints > 0 && dc->npoints < SAMPLING_SIZE )) + if (!( this->npoints > 0 && this->npoints < SAMPLING_SIZE )) { return; // just clicked + } - if ( dc->npoints == SAMPLING_SIZE - 1 || release ) { + if ( this->npoints == SAMPLING_SIZE - 1 || release ) { #define BEZIER_SIZE 4 #define BEZIER_MAX_BEZIERS 8 #define BEZIER_MAX_LENGTH ( BEZIER_SIZE * BEZIER_MAX_BEZIERS ) #ifdef DYNA_DRAW_VERBOSE g_print("[F&S:#] dc->npoints:%d, release:%s\n", - dc->npoints, release ? "TRUE" : "FALSE"); + this->npoints, release ? "TRUE" : "FALSE"); #endif /* Current calligraphic */ - if ( dc->cal1->is_empty() || dc->cal2->is_empty() ) { + if ( this->cal1->is_empty() || this->cal2->is_empty() ) { /* dc->npoints > 0 */ /* g_print("calligraphics(1|2) reset\n"); */ - dc->cal1->reset(); - dc->cal2->reset(); + this->cal1->reset(); + this->cal2->reset(); - dc->cal1->moveto(dc->point1[0]); - dc->cal2->moveto(dc->point2[0]); + this->cal1->moveto(this->point1[0]); + this->cal2->moveto(this->point2[0]); } Geom::Point b1[BEZIER_MAX_LENGTH]; - gint const nb1 = Geom::bezier_fit_cubic_r(b1, dc->point1, dc->npoints, + gint const nb1 = Geom::bezier_fit_cubic_r(b1, this->point1, this->npoints, tolerance_sq, BEZIER_MAX_BEZIERS); g_assert( nb1 * BEZIER_SIZE <= gint(G_N_ELEMENTS(b1)) ); Geom::Point b2[BEZIER_MAX_LENGTH]; - gint const nb2 = Geom::bezier_fit_cubic_r(b2, dc->point2, dc->npoints, + gint const nb2 = Geom::bezier_fit_cubic_r(b2, this->point2, this->npoints, tolerance_sq, BEZIER_MAX_BEZIERS); g_assert( nb2 * BEZIER_SIZE <= gint(G_N_ELEMENTS(b2)) ); @@ -1140,56 +1097,56 @@ fit_and_split(SPDynaDrawContext *dc, gboolean release) #endif /* CanvasShape */ if (! release) { - dc->currentcurve->reset(); - dc->currentcurve->moveto(b1[0]); + this->currentcurve->reset(); + this->currentcurve->moveto(b1[0]); for (Geom::Point *bp1 = b1; bp1 < b1 + BEZIER_SIZE * nb1; bp1 += BEZIER_SIZE) { - dc->currentcurve->curveto(bp1[1], bp1[2], bp1[3]); + this->currentcurve->curveto(bp1[1], bp1[2], bp1[3]); } - dc->currentcurve->lineto(b2[BEZIER_SIZE*(nb2-1) + 3]); + this->currentcurve->lineto(b2[BEZIER_SIZE*(nb2-1) + 3]); for (Geom::Point *bp2 = b2 + BEZIER_SIZE * ( nb2 - 1 ); bp2 >= b2; bp2 -= BEZIER_SIZE) { - dc->currentcurve->curveto(bp2[2], bp2[1], bp2[0]); + this->currentcurve->curveto(bp2[2], bp2[1], bp2[0]); } // FIXME: dc->segments is always NULL at this point?? - if (!dc->segments) { // first segment - add_cap(dc->currentcurve, b2[0], b1[0], dc->cap_rounding); + if (!this->segments) { // first segment + add_cap(this->currentcurve, b2[0], b1[0], this->cap_rounding); } - dc->currentcurve->closepath(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->currentshape), dc->currentcurve); + this->currentcurve->closepath(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve); } /* Current calligraphic */ for (Geom::Point *bp1 = b1; bp1 < b1 + BEZIER_SIZE * nb1; bp1 += BEZIER_SIZE) { - dc->cal1->curveto(bp1[1], bp1[2], bp1[3]); + this->cal1->curveto(bp1[1], bp1[2], bp1[3]); } for (Geom::Point *bp2 = b2; bp2 < b2 + BEZIER_SIZE * nb2; bp2 += BEZIER_SIZE) { - dc->cal2->curveto(bp2[1], bp2[2], bp2[3]); + this->cal2->curveto(bp2[1], bp2[2], bp2[3]); } } else { /* fixme: ??? */ #ifdef DYNA_DRAW_VERBOSE g_print("[fit_and_split] failed to fit-cubic.\n"); #endif - draw_temporary_box(dc); + this->draw_temporary_box(); - for (gint i = 1; i < dc->npoints; i++) { - dc->cal1->lineto(dc->point1[i]); + for (gint i = 1; i < this->npoints; i++) { + this->cal1->lineto(this->point1[i]); } - for (gint i = 1; i < dc->npoints; i++) { - dc->cal2->lineto(dc->point2[i]); + for (gint i = 1; i < this->npoints; i++) { + this->cal2->lineto(this->point2[i]); } } /* Fit and draw and copy last point */ #ifdef DYNA_DRAW_VERBOSE - g_print("[%d]Yup\n", dc->npoints); + g_print("[%d]Yup\n", this->npoints); #endif if (!release) { - g_assert(!dc->currentcurve->is_empty()); + g_assert(!this->currentcurve->is_empty()); SPCanvasItem *cbp = sp_canvas_item_new(sp_desktop_sketch(desktop), SP_TYPE_CANVAS_BPATH, NULL); - SPCurve *curve = dc->currentcurve->copy(); + SPCurve *curve = this->currentcurve->copy(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH (cbp), curve); curve->unref(); @@ -1205,36 +1162,36 @@ fit_and_split(SPDynaDrawContext *dc, gboolean release) /* fixme: Cannot we cascade it to root more clearly? */ g_signal_connect(G_OBJECT(cbp), "event", G_CALLBACK(sp_desktop_root_handler), desktop); - dc->segments = g_slist_prepend(dc->segments, cbp); + this->segments = g_slist_prepend(this->segments, cbp); } - dc->point1[0] = dc->point1[dc->npoints - 1]; - dc->point2[0] = dc->point2[dc->npoints - 1]; - dc->npoints = 1; + this->point1[0] = this->point1[this->npoints - 1]; + this->point2[0] = this->point2[this->npoints - 1]; + this->npoints = 1; } else { - draw_temporary_box(dc); + this->draw_temporary_box(); } } -static void -draw_temporary_box(SPDynaDrawContext *dc) -{ - dc->currentcurve->reset(); +void SPDynaDrawContext::draw_temporary_box() { + this->currentcurve->reset(); - dc->currentcurve->moveto(dc->point2[dc->npoints-1]); - for (gint i = dc->npoints-2; i >= 0; i--) { - dc->currentcurve->lineto(dc->point2[i]); + this->currentcurve->moveto(this->point2[this->npoints-1]); + + for (gint i = this->npoints-2; i >= 0; i--) { + this->currentcurve->lineto(this->point2[i]); } - for (gint i = 0; i < dc->npoints; i++) { - dc->currentcurve->lineto(dc->point1[i]); + + for (gint i = 0; i < this->npoints; i++) { + this->currentcurve->lineto(this->point1[i]); } - if (dc->npoints >= 2) { - add_cap(dc->currentcurve, dc->point1[dc->npoints-1], dc->point2[dc->npoints-1], dc->cap_rounding); + if (this->npoints >= 2) { + add_cap(this->currentcurve, this->point1[this->npoints-1], this->point2[this->npoints-1], this->cap_rounding); } - dc->currentcurve->closepath(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->currentshape), dc->currentcurve); + this->currentcurve->closepath(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve); } /* diff --git a/src/dyna-draw-context.h b/src/dyna-draw-context.h index cfb6b2b12..36a429a8d 100644 --- a/src/dyna-draw-context.h +++ b/src/dyna-draw-context.h @@ -21,10 +21,6 @@ #include "common-context.h" #include "splivarot.h" -#define SP_DYNA_DRAW_CONTEXT(obj) ((SPDynaDrawContext*)obj) -#define SP_IS_DYNA_DRAW_CONTEXT(obj) (dynamic_cast<const SPDynaDrawContext*>((const SPEventContext*)obj)) - - #define DDC_MIN_PRESSURE 0.0 #define DDC_MAX_PRESSURE 1.0 #define DDC_DEFAULT_PRESSURE 1.0 @@ -38,6 +34,15 @@ public: SPDynaDrawContext(); virtual ~SPDynaDrawContext(); + static const std::string prefsPath; + + virtual void setup(); + virtual void set(const Inkscape::Preferences::Entry& val); + virtual bool root_handler(GdkEvent* event); + + virtual const std::string& getPrefsPath(); + +private: /** newly created object remain selected */ bool keep_selected; @@ -55,13 +60,16 @@ public: bool just_started_drawing; bool trace_bg; - static const std::string prefsPath; - - virtual void setup(); - virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); - - virtual const std::string& getPrefsPath(); + void clear_current(); + void set_to_accumulated(bool unionize, bool subtract); + bool accumulate(); + void fit_and_split(bool release); + void draw_temporary_box(); + void cancel(); + void brush(); + bool apply(Geom::Point p); + void extinput(GdkEvent *event); + void reset(Geom::Point p); }; #endif // SP_DYNA_DRAW_CONTEXT_H_SEEN diff --git a/src/eraser-context.cpp b/src/eraser-context.cpp index 63737da61..6391419eb 100644 --- a/src/eraser-context.cpp +++ b/src/eraser-context.cpp @@ -83,18 +83,6 @@ using Inkscape::DocumentUndo; #define DRAG_DEFAULT 1.0 #define DRAG_MAX 1.0 -static void clear_current(SPEraserContext *dc); -static void set_to_accumulated(SPEraserContext *dc); -static void add_cap(SPCurve *curve, Geom::Point const &pre, Geom::Point const &from, Geom::Point const &to, Geom::Point const &post, double rounding); -static void accumulate_eraser(SPEraserContext *dc); - -static void fit_and_split(SPEraserContext *erc, gboolean release); - -static void sp_eraser_reset(SPEraserContext *erc, Geom::Point p); -static Geom::Point sp_eraser_get_npoint(SPEraserContext const *erc, Geom::Point v); -static Geom::Point sp_eraser_get_vpoint(SPEraserContext const *erc, Geom::Point n); -static void draw_temporary_box(SPEraserContext *dc); - #include "tool-factory.h" namespace { @@ -181,66 +169,42 @@ flerp(double f0, double f1, double p) return f0 + ( f1 - f0 ) * p; } -/* Get normalized point */ -static Geom::Point -sp_eraser_get_npoint(SPEraserContext const *dc, Geom::Point v) -{ - Geom::Rect drect = SP_EVENT_CONTEXT(dc)->desktop->get_display_area(); - double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); - return Geom::Point(( v[Geom::X] - drect.min()[Geom::X] ) / max, ( v[Geom::Y] - drect.min()[Geom::Y] ) / max); -} - -/* Get view point */ -static Geom::Point -sp_eraser_get_vpoint(SPEraserContext const *dc, Geom::Point n) -{ - Geom::Rect drect = SP_EVENT_CONTEXT(dc)->desktop->get_display_area(); - double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); - return Geom::Point(n[Geom::X] * max + drect.min()[Geom::X], n[Geom::Y] * max + drect.min()[Geom::Y]); -} - -static void -sp_eraser_reset(SPEraserContext *dc, Geom::Point p) -{ - dc->last = dc->cur = sp_eraser_get_npoint(dc, p); - dc->vel = Geom::Point(0,0); - dc->vel_max = 0; - dc->acc = Geom::Point(0,0); - dc->ang = Geom::Point(0,0); - dc->del = Geom::Point(0,0); +void SPEraserContext::reset(Geom::Point p) { + this->last = this->cur = getNormalizedPoint(p); + this->vel = Geom::Point(0,0); + this->vel_max = 0; + this->acc = Geom::Point(0,0); + this->ang = Geom::Point(0,0); + this->del = Geom::Point(0,0); } -static void -sp_eraser_extinput(SPEraserContext *dc, GdkEvent *event) -{ - if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &dc->pressure)) - dc->pressure = CLAMP (dc->pressure, ERC_MIN_PRESSURE, ERC_MAX_PRESSURE); +void SPEraserContext::extinput(GdkEvent *event) { + if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &this->pressure)) + this->pressure = CLAMP (this->pressure, ERC_MIN_PRESSURE, ERC_MAX_PRESSURE); else - dc->pressure = ERC_DEFAULT_PRESSURE; + this->pressure = ERC_DEFAULT_PRESSURE; - if (gdk_event_get_axis (event, GDK_AXIS_XTILT, &dc->xtilt)) - dc->xtilt = CLAMP (dc->xtilt, ERC_MIN_TILT, ERC_MAX_TILT); + if (gdk_event_get_axis (event, GDK_AXIS_XTILT, &this->xtilt)) + this->xtilt = CLAMP (this->xtilt, ERC_MIN_TILT, ERC_MAX_TILT); else - dc->xtilt = ERC_DEFAULT_TILT; + this->xtilt = ERC_DEFAULT_TILT; - if (gdk_event_get_axis (event, GDK_AXIS_YTILT, &dc->ytilt)) - dc->ytilt = CLAMP (dc->ytilt, ERC_MIN_TILT, ERC_MAX_TILT); + if (gdk_event_get_axis (event, GDK_AXIS_YTILT, &this->ytilt)) + this->ytilt = CLAMP (this->ytilt, ERC_MIN_TILT, ERC_MAX_TILT); else - dc->ytilt = ERC_DEFAULT_TILT; + this->ytilt = ERC_DEFAULT_TILT; } -static gboolean -sp_eraser_apply(SPEraserContext *dc, Geom::Point p) -{ - Geom::Point n = sp_eraser_get_npoint(dc, p); +bool SPEraserContext::apply(Geom::Point p) { + Geom::Point n = getNormalizedPoint(p); /* Calculate mass and drag */ - double const mass = flerp(1.0, 160.0, dc->mass); - double const drag = flerp(0.0, 0.5, dc->drag * dc->drag); + double const mass = flerp(1.0, 160.0, this->mass); + double const drag = flerp(0.0, 0.5, this->drag * this->drag); /* Calculate force and acceleration */ - Geom::Point force = n - dc->cur; + Geom::Point force = n - this->cur; // If force is below the absolute threshold ERASER_EPSILON, // or we haven't yet reached ERASER_VEL_START (i.e. at the beginning of stroke) @@ -249,27 +213,27 @@ sp_eraser_apply(SPEraserContext *dc, Geom::Point p) // This prevents flips, blobs, and jerks caused by microscopic tremor of the tablet pen, // especially bothersome at the start of the stroke where we don't yet have the inertia to // smooth them out. - if ( Geom::L2(force) < ERASER_EPSILON || (dc->vel_max < ERASER_VEL_START && Geom::L2(force) < ERASER_EPSILON_START)) { + if ( Geom::L2(force) < ERASER_EPSILON || (this->vel_max < ERASER_VEL_START && Geom::L2(force) < ERASER_EPSILON_START)) { return FALSE; } - dc->acc = force / mass; + this->acc = force / mass; /* Calculate new velocity */ - dc->vel += dc->acc; + this->vel += this->acc; - if (Geom::L2(dc->vel) > dc->vel_max) - dc->vel_max = Geom::L2(dc->vel); + if (Geom::L2(this->vel) > this->vel_max) + this->vel_max = Geom::L2(this->vel); /* Calculate angle of drawing tool */ double a1; - if (dc->usetilt) { + if (this->usetilt) { // 1a. calculate nib angle from input device tilt: - gdouble length = std::sqrt(dc->xtilt*dc->xtilt + dc->ytilt*dc->ytilt);; + gdouble length = std::sqrt(this->xtilt*this->xtilt + this->ytilt*this->ytilt);; if (length > 0) { - Geom::Point ang1 = Geom::Point(dc->ytilt/length, dc->xtilt/length); + Geom::Point ang1 = Geom::Point(this->ytilt/length, this->xtilt/length); a1 = atan2(ang1); } else @@ -277,17 +241,17 @@ sp_eraser_apply(SPEraserContext *dc, Geom::Point p) } else { // 1b. fixed dc->angle (absolutely flat nib): - double const radians = ( (dc->angle - 90) / 180.0 ) * M_PI; + double const radians = ( (this->angle - 90) / 180.0 ) * M_PI; Geom::Point ang1 = Geom::Point(-sin(radians), cos(radians)); a1 = atan2(ang1); } // 2. perpendicular to dc->vel (absolutely non-flat nib): - gdouble const mag_vel = Geom::L2(dc->vel); + gdouble const mag_vel = Geom::L2(this->vel); if ( mag_vel < ERASER_EPSILON ) { return FALSE; } - Geom::Point ang2 = Geom::rot90(dc->vel) / mag_vel; + Geom::Point ang2 = Geom::rot90(this->vel) / mag_vel; // 3. Average them using flatness parameter: // calculate angles @@ -305,52 +269,50 @@ sp_eraser_apply(SPEraserContext *dc, Geom::Point p) a2 += 2*M_PI; // find the flatness-weighted bisector angle, unflip if a2 was flipped // FIXME: when dc->vel is oscillating around the fixed angle, the new_ang flips back and forth. How to avoid this? - double new_ang = a1 + (1 - dc->flatness) * (a2 - a1) - (flipped? M_PI : 0); + double new_ang = a1 + (1 - this->flatness) * (a2 - a1) - (flipped? M_PI : 0); // Try to detect a sudden flip when the new angle differs too much from the previous for the // current velocity; in that case discard this move - double angle_delta = Geom::L2(Geom::Point (cos (new_ang), sin (new_ang)) - dc->ang); - if ( angle_delta / Geom::L2(dc->vel) > 4000 ) { + double angle_delta = Geom::L2(Geom::Point (cos (new_ang), sin (new_ang)) - this->ang); + if ( angle_delta / Geom::L2(this->vel) > 4000 ) { return FALSE; } // convert to point - dc->ang = Geom::Point (cos (new_ang), sin (new_ang)); + this->ang = Geom::Point (cos (new_ang), sin (new_ang)); // g_print ("force %g acc %g vel_max %g vel %g a1 %g a2 %g new_ang %g\n", Geom::L2(force), Geom::L2(dc->acc), dc->vel_max, Geom::L2(dc->vel), a1, a2, new_ang); /* Apply drag */ - dc->vel *= 1.0 - drag; + this->vel *= 1.0 - drag; /* Update position */ - dc->last = dc->cur; - dc->cur += dc->vel; + this->last = this->cur; + this->cur += this->vel; return TRUE; } -static void -sp_eraser_brush(SPEraserContext *dc) -{ - g_assert( dc->npoints >= 0 && dc->npoints < SAMPLING_SIZE ); +void SPEraserContext::brush() { + g_assert( this->npoints >= 0 && this->npoints < SAMPLING_SIZE ); // How much velocity thins strokestyle - double vel_thin = flerp (0, 160, dc->vel_thin); + double vel_thin = flerp (0, 160, this->vel_thin); // Influence of pressure on thickness - double pressure_thick = (dc->usepressure ? dc->pressure : 1.0); + double pressure_thick = (this->usepressure ? this->pressure : 1.0); // get the real brush point, not the same as pointer (affected by hatch tracking and/or mass // drag) - Geom::Point brush = sp_eraser_get_vpoint(dc, dc->cur); + Geom::Point brush = getViewPoint(this->cur); //Geom::Point brush_w = SP_EVENT_CONTEXT(dc)->desktop->d2w(brush); double trace_thick = 1; - double width = (pressure_thick * trace_thick - vel_thin * Geom::L2(dc->vel)) * dc->width; + double width = (pressure_thick * trace_thick - vel_thin * Geom::L2(this->vel)) * this->width; double tremble_left = 0, tremble_right = 0; - if (dc->tremor > 0) { + if (this->tremor > 0) { // obtain two normally distributed random variables, using polar Box-Muller transform double x1, x2, w, y1, y2; do { @@ -367,28 +329,28 @@ sp_eraser_brush(SPEraserContext *dc) // (2) deflection depends on width, but is upped for small widths for better visual uniformity across widths; // (3) deflection somewhat depends on speed, to prevent fast strokes looking // comparatively smooth and slow ones excessively jittery - tremble_left = (y1)*dc->tremor * (0.15 + 0.8*width) * (0.35 + 14*Geom::L2(dc->vel)); - tremble_right = (y2)*dc->tremor * (0.15 + 0.8*width) * (0.35 + 14*Geom::L2(dc->vel)); + tremble_left = (y1)*this->tremor * (0.15 + 0.8*width) * (0.35 + 14*Geom::L2(this->vel)); + tremble_right = (y2)*this->tremor * (0.15 + 0.8*width) * (0.35 + 14*Geom::L2(this->vel)); } - if ( width < 0.02 * dc->width ) { - width = 0.02 * dc->width; + if ( width < 0.02 * this->width ) { + width = 0.02 * this->width; } double dezoomify_factor = 0.05 * 1000; - if (!dc->abs_width) { - dezoomify_factor /= SP_EVENT_CONTEXT(dc)->desktop->current_zoom(); + if (!this->abs_width) { + dezoomify_factor /= SP_EVENT_CONTEXT(this)->desktop->current_zoom(); } - Geom::Point del_left = dezoomify_factor * (width + tremble_left) * dc->ang; - Geom::Point del_right = dezoomify_factor * (width + tremble_right) * dc->ang; + Geom::Point del_left = dezoomify_factor * (width + tremble_left) * this->ang; + Geom::Point del_right = dezoomify_factor * (width + tremble_right) * this->ang; - dc->point1[dc->npoints] = brush + del_left; - dc->point2[dc->npoints] = brush - del_right; + this->point1[this->npoints] = brush + del_left; + this->point2[this->npoints] = brush - del_right; - dc->del = 0.5*(del_left + del_right); + this->del = 0.5*(del_left + del_right); - dc->npoints++; + this->npoints++; } static void @@ -397,27 +359,25 @@ sp_erc_update_toolbox (SPDesktop *desktop, const gchar *id, double value) desktop->setToolboxAdjustmentValue (id, value); } -static void -eraser_cancel(SPEraserContext *dc) -{ - SPDesktop *desktop = SP_EVENT_CONTEXT(dc)->desktop; - dc->dragging = FALSE; - dc->is_drawing = false; +void SPEraserContext::cancel() { + SPDesktop *desktop = SP_EVENT_CONTEXT(this)->desktop; + this->dragging = FALSE; + this->is_drawing = false; sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0); /* Remove all temporary line segments */ - while (dc->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(dc->segments->data)); - dc->segments = g_slist_remove(dc->segments, dc->segments->data); + while (this->segments) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); + this->segments = g_slist_remove(this->segments, this->segments->data); } /* reset accumulated curve */ - dc->accumulated->reset(); - clear_current(dc); - if (dc->repr) { - dc->repr = NULL; + this->accumulated->reset(); + this->clear_current(); + if (this->repr) { + this->repr = NULL; } } -gint SPEraserContext::root_handler(GdkEvent* event) { +bool SPEraserContext::root_handler(GdkEvent* event) { gint ret = FALSE; switch (event->type) { @@ -430,9 +390,9 @@ gint SPEraserContext::root_handler(GdkEvent* event) { Geom::Point const button_w(event->button.x, event->button.y); Geom::Point const button_dt(desktop->w2d(button_w)); - sp_eraser_reset(this, button_dt); - sp_eraser_extinput(this, event); - sp_eraser_apply(this, button_dt); + this->reset(button_dt); + this->extinput(event); + this->apply(button_dt); this->accumulated->reset(); @@ -465,7 +425,7 @@ gint SPEraserContext::root_handler(GdkEvent* event) { Geom::Point const motion_w(event->motion.x, event->motion.y); Geom::Point motion_dt(desktop->w2d(motion_w) ); - sp_eraser_extinput(this, event); + this->extinput(event); this->_message_context->clear(); @@ -474,15 +434,15 @@ gint SPEraserContext::root_handler(GdkEvent* event) { this->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Drawing</b> an eraser stroke")); - if (!sp_eraser_apply(this, motion_dt)) { + if (!this->apply(motion_dt)) { ret = TRUE; break; } if ( this->cur != this->last ) { - sp_eraser_brush(this); + this->brush(); g_assert( this->npoints > 0 ); - fit_and_split(this, FALSE); + this->fit_and_split(false); } ret = TRUE; @@ -503,7 +463,7 @@ gint SPEraserContext::root_handler(GdkEvent* event) { if (this->dragging && event->button.button == 1 && !this->space_panning) { this->dragging = FALSE; - sp_eraser_apply(this, motion_dt); + this->apply(motion_dt); /* Remove all temporary line segments */ while (this->segments) { @@ -512,14 +472,14 @@ gint SPEraserContext::root_handler(GdkEvent* event) { } /* Create object */ - fit_and_split(this, TRUE); - accumulate_eraser(this); - set_to_accumulated(this); // performs document_done + this->fit_and_split(true); + this->accumulate(); + this->set_to_accumulated(); // performs document_done /* reset accumulated curve */ this->accumulated->reset(); - clear_current(this); + this->clear_current(); if (this->repr) { this->repr = NULL; } @@ -620,7 +580,7 @@ gint SPEraserContext::root_handler(GdkEvent* event) { if (this->is_drawing) { // if drawing, cancel, otherwise pass it up for deselecting - eraser_cancel (this); + this->cancel(); ret = TRUE; } break; @@ -629,7 +589,7 @@ gint SPEraserContext::root_handler(GdkEvent* event) { case GDK_KEY_Z: if (MOD__CTRL_ONLY(event) && this->is_drawing) { // if drawing, cancel, otherwise pass it up for undo - eraser_cancel (this); + this->cancel(); ret = TRUE; } break; @@ -662,29 +622,24 @@ gint SPEraserContext::root_handler(GdkEvent* event) { return ret; } -static void -clear_current(SPEraserContext *dc) -{ +void SPEraserContext::clear_current() { // reset bpath - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->currentshape), NULL); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), NULL); // reset curve - dc->currentcurve->reset(); - dc->cal1->reset(); - dc->cal2->reset(); + this->currentcurve->reset(); + this->cal1->reset(); + this->cal2->reset(); // reset points - dc->npoints = 0; + this->npoints = 0; } -static void -set_to_accumulated(SPEraserContext *dc) -{ - SPDesktop *desktop = SP_EVENT_CONTEXT(dc)->desktop; +void SPEraserContext::set_to_accumulated() { bool workDone = false; - if (!dc->accumulated->is_empty()) { - if (!dc->repr) { + if (!this->accumulated->is_empty()) { + if (!this->repr) { /* Create object */ Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); @@ -692,22 +647,22 @@ set_to_accumulated(SPEraserContext *dc) /* Set style */ sp_desktop_apply_style_tool (desktop, repr, "/tools/eraser", false); - dc->repr = repr; + this->repr = repr; - SPItem *item=SP_ITEM(desktop->currentLayer()->appendChildRepr(dc->repr)); - Inkscape::GC::release(dc->repr); + SPItem *item=SP_ITEM(desktop->currentLayer()->appendChildRepr(this->repr)); + Inkscape::GC::release(this->repr); item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); item->updateRepr(); } - Geom::PathVector pathv = dc->accumulated->get_pathvector() * desktop->dt2doc(); + Geom::PathVector pathv = this->accumulated->get_pathvector() * desktop->dt2doc(); gchar *str = sp_svg_write_path(pathv); g_assert( str != NULL ); - dc->repr->setAttribute("d", str); + this->repr->setAttribute("d", str); g_free(str); - if ( dc->repr ) { + if ( this->repr ) { bool wasSelection = false; Inkscape::Selection *selection = sp_desktop_selection(desktop); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -715,7 +670,7 @@ set_to_accumulated(SPEraserContext *dc) gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0; Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - SPItem* acid = SP_ITEM(desktop->doc()->getObjectByRepr(dc->repr)); + SPItem* acid = SP_ITEM(desktop->doc()->getObjectByRepr(this->repr)); Geom::OptRect eraserBbox = acid->visualBounds(); Geom::Rect bounds = (*eraserBbox) * desktop->doc2dt(); std::vector<SPItem*> remainingItems; @@ -744,8 +699,8 @@ set_to_accumulated(SPEraserContext *dc) Geom::OptRect bbox = item->visualBounds(); if (bbox && bbox->intersects(*eraserBbox)) { - Inkscape::XML::Node* dup = dc->repr->duplicate(xml_doc); - dc->repr->parent()->appendChild(dup); + Inkscape::XML::Node* dup = this->repr->duplicate(xml_doc); + this->repr->parent()->appendChild(dup); Inkscape::GC::release(dup); // parent takes over selection->set(item); @@ -798,13 +753,13 @@ set_to_accumulated(SPEraserContext *dc) } // Remove the eraser stroke itself: - sp_repr_unparent( dc->repr ); - dc->repr = 0; + sp_repr_unparent( this->repr ); + this->repr = 0; } } else { - if (dc->repr) { - sp_repr_unparent(dc->repr); - dc->repr = 0; + if (this->repr) { + sp_repr_unparent(this->repr); + this->repr = 0; } } @@ -848,21 +803,19 @@ add_cap(SPCurve *curve, } } -static void -accumulate_eraser(SPEraserContext *dc) -{ - if ( !dc->cal1->is_empty() && !dc->cal2->is_empty() ) { - dc->accumulated->reset(); /* Is this required ?? */ - SPCurve *rev_cal2 = dc->cal2->create_reverse(); +void SPEraserContext::accumulate() { + if ( !this->cal1->is_empty() && !this->cal2->is_empty() ) { + this->accumulated->reset(); /* Is this required ?? */ + SPCurve *rev_cal2 = this->cal2->create_reverse(); - g_assert(dc->cal1->get_segment_count() > 0); + g_assert(this->cal1->get_segment_count() > 0); g_assert(rev_cal2->get_segment_count() > 0); - g_assert( ! dc->cal1->first_path()->closed() ); + g_assert( ! this->cal1->first_path()->closed() ); g_assert( ! rev_cal2->first_path()->closed() ); - Geom::CubicBezier const * dc_cal1_firstseg = dynamic_cast<Geom::CubicBezier const *>( dc->cal1->first_segment() ); + Geom::CubicBezier const * dc_cal1_firstseg = dynamic_cast<Geom::CubicBezier const *>( this->cal1->first_segment() ); Geom::CubicBezier const * rev_cal2_firstseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->first_segment() ); - Geom::CubicBezier const * dc_cal1_lastseg = dynamic_cast<Geom::CubicBezier const *>( dc->cal1->last_segment() ); + Geom::CubicBezier const * dc_cal1_lastseg = dynamic_cast<Geom::CubicBezier const *>( this->cal1->last_segment() ); Geom::CubicBezier const * rev_cal2_lastseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->last_segment() ); g_assert( dc_cal1_firstseg ); @@ -870,20 +823,20 @@ accumulate_eraser(SPEraserContext *dc) g_assert( dc_cal1_lastseg ); g_assert( rev_cal2_lastseg ); - dc->accumulated->append(dc->cal1, FALSE); + this->accumulated->append(this->cal1, FALSE); - add_cap(dc->accumulated, (*dc_cal1_lastseg)[2], (*dc_cal1_lastseg)[3], (*rev_cal2_firstseg)[0], (*rev_cal2_firstseg)[1], dc->cap_rounding); + add_cap(this->accumulated, (*dc_cal1_lastseg)[2], (*dc_cal1_lastseg)[3], (*rev_cal2_firstseg)[0], (*rev_cal2_firstseg)[1], this->cap_rounding); - dc->accumulated->append(rev_cal2, TRUE); + this->accumulated->append(rev_cal2, TRUE); - add_cap(dc->accumulated, (*rev_cal2_lastseg)[2], (*rev_cal2_lastseg)[3], (*dc_cal1_firstseg)[0], (*dc_cal1_firstseg)[1], dc->cap_rounding); + add_cap(this->accumulated, (*rev_cal2_lastseg)[2], (*rev_cal2_lastseg)[3], (*dc_cal1_firstseg)[0], (*dc_cal1_firstseg)[1], this->cap_rounding); - dc->accumulated->closepath(); + this->accumulated->closepath(); rev_cal2->unref(); - dc->cal1->reset(); - dc->cal2->reset(); + this->cal1->reset(); + this->cal2->reset(); } } @@ -892,47 +845,43 @@ static double square(double const x) return x * x; } -static void -fit_and_split(SPEraserContext *dc, gboolean release) -{ - SPDesktop *desktop = SP_EVENT_CONTEXT(dc)->desktop; - +void SPEraserContext::fit_and_split(bool release) { double const tolerance_sq = square( desktop->w2d().descrim() * TOLERANCE_ERASER ); #ifdef ERASER_VERBOSE g_print("[F&S:R=%c]", release?'T':'F'); #endif - if (!( dc->npoints > 0 && dc->npoints < SAMPLING_SIZE )) + if (!( this->npoints > 0 && this->npoints < SAMPLING_SIZE )) return; // just clicked - if ( dc->npoints == SAMPLING_SIZE - 1 || release ) { + if ( this->npoints == SAMPLING_SIZE - 1 || release ) { #define BEZIER_SIZE 4 #define BEZIER_MAX_BEZIERS 8 #define BEZIER_MAX_LENGTH ( BEZIER_SIZE * BEZIER_MAX_BEZIERS ) #ifdef ERASER_VERBOSE - g_print("[F&S:#] dc->npoints:%d, release:%s\n", + g_print("[F&S:#] this->npoints:%d, release:%s\n", dc->npoints, release ? "TRUE" : "FALSE"); #endif /* Current eraser */ - if ( dc->cal1->is_empty() || dc->cal2->is_empty() ) { + if ( this->cal1->is_empty() || this->cal2->is_empty() ) { /* dc->npoints > 0 */ /* g_print("erasers(1|2) reset\n"); */ - dc->cal1->reset(); - dc->cal2->reset(); + this->cal1->reset(); + this->cal2->reset(); - dc->cal1->moveto(dc->point1[0]); - dc->cal2->moveto(dc->point2[0]); + this->cal1->moveto(this->point1[0]); + this->cal2->moveto(this->point2[0]); } Geom::Point b1[BEZIER_MAX_LENGTH]; - gint const nb1 = Geom::bezier_fit_cubic_r(b1, dc->point1, dc->npoints, tolerance_sq, BEZIER_MAX_BEZIERS); + gint const nb1 = Geom::bezier_fit_cubic_r(b1, this->point1, this->npoints, tolerance_sq, BEZIER_MAX_BEZIERS); g_assert( nb1 * BEZIER_SIZE <= gint(G_N_ELEMENTS(b1)) ); Geom::Point b2[BEZIER_MAX_LENGTH]; - gint const nb2 = Geom::bezier_fit_cubic_r(b2, dc->point2, dc->npoints, tolerance_sq, BEZIER_MAX_BEZIERS); + gint const nb2 = Geom::bezier_fit_cubic_r(b2, this->point2, this->npoints, tolerance_sq, BEZIER_MAX_BEZIERS); g_assert( nb2 * BEZIER_SIZE <= gint(G_N_ELEMENTS(b2)) ); if ( nb1 != -1 && nb2 != -1 ) { @@ -943,63 +892,63 @@ fit_and_split(SPEraserContext *dc, gboolean release) /* CanvasShape */ if (! release) { - dc->currentcurve->reset(); - dc->currentcurve->moveto(b1[0]); + this->currentcurve->reset(); + this->currentcurve->moveto(b1[0]); for (Geom::Point *bp1 = b1; bp1 < b1 + BEZIER_SIZE * nb1; bp1 += BEZIER_SIZE) { - dc->currentcurve->curveto(bp1[1], bp1[2], bp1[3]); + this->currentcurve->curveto(bp1[1], bp1[2], bp1[3]); } - dc->currentcurve->lineto(b2[BEZIER_SIZE*(nb2-1) + 3]); + this->currentcurve->lineto(b2[BEZIER_SIZE*(nb2-1) + 3]); for (Geom::Point *bp2 = b2 + BEZIER_SIZE * ( nb2 - 1 ); bp2 >= b2; bp2 -= BEZIER_SIZE) { - dc->currentcurve->curveto(bp2[2], bp2[1], bp2[0]); + this->currentcurve->curveto(bp2[2], bp2[1], bp2[0]); } - // FIXME: dc->segments is always NULL at this point?? - if (!dc->segments) { // first segment - add_cap(dc->currentcurve, b2[1], b2[0], b1[0], b1[1], dc->cap_rounding); + // FIXME: this->segments is always NULL at this point?? + if (!this->segments) { // first segment + add_cap(this->currentcurve, b2[1], b2[0], b1[0], b1[1], this->cap_rounding); } - dc->currentcurve->closepath(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->currentshape), dc->currentcurve); + this->currentcurve->closepath(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve); } /* Current eraser */ for (Geom::Point *bp1 = b1; bp1 < b1 + BEZIER_SIZE * nb1; bp1 += BEZIER_SIZE) { - dc->cal1->curveto(bp1[1], bp1[2], bp1[3]); + this->cal1->curveto(bp1[1], bp1[2], bp1[3]); } for (Geom::Point *bp2 = b2; bp2 < b2 + BEZIER_SIZE * nb2; bp2 += BEZIER_SIZE) { - dc->cal2->curveto(bp2[1], bp2[2], bp2[3]); + this->cal2->curveto(bp2[1], bp2[2], bp2[3]); } } else { /* fixme: ??? */ #ifdef ERASER_VERBOSE g_print("[fit_and_split] failed to fit-cubic.\n"); #endif - draw_temporary_box(dc); + this->draw_temporary_box(); - for (gint i = 1; i < dc->npoints; i++) { - dc->cal1->lineto(dc->point1[i]); + for (gint i = 1; i < this->npoints; i++) { + this->cal1->lineto(this->point1[i]); } - for (gint i = 1; i < dc->npoints; i++) { - dc->cal2->lineto(dc->point2[i]); + for (gint i = 1; i < this->npoints; i++) { + this->cal2->lineto(this->point2[i]); } } /* Fit and draw and copy last point */ #ifdef ERASER_VERBOSE - g_print("[%d]Yup\n", dc->npoints); + g_print("[%d]Yup\n", this->npoints); #endif if (!release) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0; - g_assert(!dc->currentcurve->is_empty()); + g_assert(!this->currentcurve->is_empty()); SPCanvasItem *cbp = sp_canvas_item_new(sp_desktop_sketch(desktop), SP_TYPE_CANVAS_BPATH, NULL); - SPCurve *curve = dc->currentcurve->copy(); + SPCurve *curve = this->currentcurve->copy(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH (cbp), curve); curve->unref(); @@ -1015,43 +964,41 @@ fit_and_split(SPEraserContext *dc, gboolean release) /* fixme: Cannot we cascade it to root more clearly? */ g_signal_connect(G_OBJECT(cbp), "event", G_CALLBACK(sp_desktop_root_handler), desktop); - dc->segments = g_slist_prepend(dc->segments, cbp); + this->segments = g_slist_prepend(this->segments, cbp); if ( !eraserMode ) { sp_canvas_item_hide(cbp); - sp_canvas_item_hide(dc->currentshape); + sp_canvas_item_hide(this->currentshape); } } - dc->point1[0] = dc->point1[dc->npoints - 1]; - dc->point2[0] = dc->point2[dc->npoints - 1]; - dc->npoints = 1; + this->point1[0] = this->point1[this->npoints - 1]; + this->point2[0] = this->point2[this->npoints - 1]; + this->npoints = 1; } else { - draw_temporary_box(dc); + this->draw_temporary_box(); } } -static void -draw_temporary_box(SPEraserContext *dc) -{ - dc->currentcurve->reset(); +void SPEraserContext::draw_temporary_box() { + this->currentcurve->reset(); - dc->currentcurve->moveto(dc->point1[dc->npoints-1]); + this->currentcurve->moveto(this->point1[this->npoints-1]); - for (gint i = dc->npoints-2; i >= 0; i--) { - dc->currentcurve->lineto(dc->point1[i]); + for (gint i = this->npoints-2; i >= 0; i--) { + this->currentcurve->lineto(this->point1[i]); } - for (gint i = 0; i < dc->npoints; i++) { - dc->currentcurve->lineto(dc->point2[i]); + for (gint i = 0; i < this->npoints; i++) { + this->currentcurve->lineto(this->point2[i]); } - if (dc->npoints >= 2) { - add_cap(dc->currentcurve, dc->point2[dc->npoints-2], dc->point2[dc->npoints-1], dc->point1[dc->npoints-1], dc->point1[dc->npoints-2], dc->cap_rounding); + if (this->npoints >= 2) { + add_cap(this->currentcurve, this->point2[this->npoints-2], this->point2[this->npoints-1], this->point1[this->npoints-1], this->point1[this->npoints-2], this->cap_rounding); } - dc->currentcurve->closepath(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->currentshape), dc->currentcurve); + this->currentcurve->closepath(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve); } /* diff --git a/src/eraser-context.h b/src/eraser-context.h index 7c9ef7f50..7ff1cf712 100644 --- a/src/eraser-context.h +++ b/src/eraser-context.h @@ -21,9 +21,6 @@ #include "common-context.h" -#define SP_ERASER_CONTEXT(obj) ((SPEraserContext*)obj) -#define SP_IS_ERASER_CONTEXT(obj) (dynamic_cast<const SPEraserContext*>((const SPEventContext*)obj)) - #define ERC_MIN_PRESSURE 0.0 #define ERC_MAX_PRESSURE 1.0 #define ERC_DEFAULT_PRESSURE 1.0 @@ -40,9 +37,21 @@ public: static const std::string prefsPath; virtual void setup(); - virtual gint root_handler(GdkEvent* event); + virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); + +private: + void reset(Geom::Point p); + void extinput(GdkEvent *event); + bool apply(Geom::Point p); + void brush(); + void cancel(); + void clear_current(); + void set_to_accumulated(); + void accumulate(); + void fit_and_split(bool release); + void draw_temporary_box(); }; #endif // SP_ERASER_CONTEXT_H_SEEN diff --git a/src/event-context.cpp b/src/event-context.cpp index edf34b923..bea5f63f6 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -166,60 +166,60 @@ static void sp_event_context_set_cursor(SPEventContext *event_context, GdkCursor /** * Recreates and draws cursor on desktop related to SPEventContext. */ -void sp_event_context_update_cursor(SPEventContext *ec) { - GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(ec->desktop)); +void SPEventContext::sp_event_context_update_cursor() { + GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(this->desktop)); if (gtk_widget_get_window (w)) { GtkStyle *style = gtk_widget_get_style(w); /* fixme: */ - if (ec->cursor_shape) { + if (this->cursor_shape) { GdkDisplay *display = gdk_display_get_default(); if (gdk_display_supports_cursor_alpha(display) && gdk_display_supports_cursor_color(display)) { bool fillHasColor=false, strokeHasColor=false; - guint32 fillColor = sp_desktop_get_color_tool(ec->desktop, ec->getPrefsPath(), true, &fillHasColor); - guint32 strokeColor = sp_desktop_get_color_tool(ec->desktop, ec->getPrefsPath(), false, &strokeHasColor); - double fillOpacity = fillHasColor ? sp_desktop_get_opacity_tool(ec->desktop, ec->getPrefsPath(), true) : 0; - double strokeOpacity = strokeHasColor ? sp_desktop_get_opacity_tool(ec->desktop, ec->getPrefsPath(), false) : 0; + guint32 fillColor = sp_desktop_get_color_tool(this->desktop, this->getPrefsPath(), true, &fillHasColor); + guint32 strokeColor = sp_desktop_get_color_tool(this->desktop, this->getPrefsPath(), false, &strokeHasColor); + double fillOpacity = fillHasColor ? sp_desktop_get_opacity_tool(this->desktop, this->getPrefsPath(), true) : 0; + double strokeOpacity = strokeHasColor ? sp_desktop_get_opacity_tool(this->desktop, this->getPrefsPath(), false) : 0; GdkPixbuf *pixbuf = sp_cursor_pixbuf_from_xpm( - ec->cursor_shape, + this->cursor_shape, style->black, style->white, SP_RGBA32_U_COMPOSE(SP_RGBA32_R_U(fillColor),SP_RGBA32_G_U(fillColor),SP_RGBA32_B_U(fillColor),SP_COLOR_F_TO_U(fillOpacity)), SP_RGBA32_U_COMPOSE(SP_RGBA32_R_U(strokeColor),SP_RGBA32_G_U(strokeColor),SP_RGBA32_B_U(strokeColor),SP_COLOR_F_TO_U(strokeOpacity)) ); if (pixbuf != NULL) { - if (ec->cursor) { + if (this->cursor) { #if GTK_CHECK_VERSION(3,0,0) - g_object_unref(ec->cursor); + g_object_unref(this->cursor); #else - gdk_cursor_unref(ec->cursor); + gdk_cursor_unref(this->cursor); #endif } - ec->cursor = gdk_cursor_new_from_pixbuf(display, pixbuf, ec->hot_x, ec->hot_y); + this->cursor = gdk_cursor_new_from_pixbuf(display, pixbuf, this->hot_x, this->hot_y); g_object_unref(pixbuf); } } else { - GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)ec->cursor_shape); + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)this->cursor_shape); if (pixbuf) { - if (ec->cursor) { + if (this->cursor) { #if GTK_CHECK_VERSION(3,0,0) - g_object_unref(ec->cursor); + g_object_unref(this->cursor); #else - gdk_cursor_unref(ec->cursor); + gdk_cursor_unref(this->cursor); #endif } - ec->cursor = gdk_cursor_new_from_pixbuf(display, - pixbuf, ec->hot_x, ec->hot_y); + this->cursor = gdk_cursor_new_from_pixbuf(display, + pixbuf, this->hot_x, this->hot_y); g_object_unref(pixbuf); } } } - gdk_window_set_cursor(gtk_widget_get_window (w), ec->cursor); + gdk_window_set_cursor(gtk_widget_get_window (w), this->cursor); gdk_flush(); } - ec->desktop->waiting_cursor = false; + this->desktop->waiting_cursor = false; } /** @@ -234,7 +234,7 @@ void SPEventContext::setup() { this->pref_observer = new ToolPrefObserver(this->getPrefsPath(), this); Inkscape::Preferences::get()->addObserver(*(this->pref_observer)); - sp_event_context_update_cursor(this); + this->sp_event_context_update_cursor(); } /** @@ -361,7 +361,7 @@ static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration, // return event_context->ceventcontext->root_handler(event); //} -gint SPEventContext::root_handler(GdkEvent* event) { +bool SPEventContext::root_handler(GdkEvent* event) { static Geom::Point button_w; static unsigned int panning = 0; static unsigned int panning_cursor = 0; @@ -872,7 +872,7 @@ gint SPEventContext::root_handler(GdkEvent* event) { // return ec->ceventcontext->item_handler(item, event); //} -gint SPEventContext::item_handler(SPItem* item, GdkEvent* event) { +bool SPEventContext::item_handler(SPItem* item, GdkEvent* event) { int ret = FALSE; switch (event->type) { diff --git a/src/event-context.h b/src/event-context.h index 15cab4bf0..38474a208 100644 --- a/src/event-context.h +++ b/src/event-context.h @@ -148,8 +148,8 @@ public: virtual void activate(); virtual void deactivate(); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); + virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath() = 0; @@ -170,6 +170,9 @@ public: SPEventContext * const ec; }; +//protected: + void sp_event_context_update_cursor(); + private: SPEventContext(const SPEventContext&); SPEventContext& operator=(const SPEventContext&); @@ -196,7 +199,7 @@ void sp_event_root_menu_popup(SPDesktop *desktop, SPItem *item, GdkEvent *event) gint gobble_key_events(guint keyval, gint mask); gint gobble_motion_events(gint mask); -void sp_event_context_update_cursor(SPEventContext *ec); +//void sp_event_context_update_cursor(SPEventContext *ec); void sp_event_show_modifier_tip(Inkscape::MessageContext *message_context, GdkEvent *event, gchar const *ctrl_tip, gchar const *shift_tip, gchar const *alt_tip); @@ -208,14 +211,14 @@ SPItem *sp_event_context_over_item (SPDesktop *desktop, SPItem *item, Geom::Poin void sp_toggle_dropper(SPDesktop *dt); -ShapeEditor *sp_event_context_get_shape_editor (SPEventContext *ec); +//ShapeEditor *sp_event_context_get_shape_editor (SPEventContext *ec); bool sp_event_context_knot_mouseover(SPEventContext *ec); -void ec_shape_event_attr_changed(Inkscape::XML::Node *shape_repr, - gchar const *name, gchar const *old_value, gchar const *new_value, - bool const is_interactive, gpointer const data); - -void event_context_print_event_info(GdkEvent *event, bool print_return = true); +//void ec_shape_event_attr_changed(Inkscape::XML::Node *shape_repr, +// gchar const *name, gchar const *old_value, gchar const *new_value, +// bool const is_interactive, gpointer const data); +// +//void event_context_print_event_info(GdkEvent *event, bool print_return = true); #endif // SEEN_SP_EVENT_CONTEXT_H diff --git a/src/flood-context.cpp b/src/flood-context.cpp index 3d2975e41..824c6e329 100644 --- a/src/flood-context.cpp +++ b/src/flood-context.cpp @@ -1092,7 +1092,7 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even DocumentUndo::done(document, SP_VERB_CONTEXT_PAINTBUCKET, _("Fill bounded area")); } -gint SPFloodContext::item_handler(SPItem* item, GdkEvent* event) { +bool SPFloodContext::item_handler(SPItem* item, GdkEvent* event) { gint ret = FALSE; switch (event->type) { @@ -1124,7 +1124,7 @@ gint SPFloodContext::item_handler(SPItem* item, GdkEvent* event) { return ret; } -gint SPFloodContext::root_handler(GdkEvent* event) { +bool SPFloodContext::root_handler(GdkEvent* event) { static bool dragging; gint ret = FALSE; diff --git a/src/flood-context.h b/src/flood-context.h index 5a60aa0f3..accfd1e40 100644 --- a/src/flood-context.h +++ b/src/flood-context.h @@ -41,8 +41,8 @@ public: static const std::string prefsPath; virtual void setup(); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); + virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index a0c20c609..7dcbdf98c 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -1571,7 +1571,7 @@ void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTa void sp_gradient_reverse_selected_gradients(SPDesktop *desktop) { Inkscape::Selection *selection = sp_desktop_selection(desktop); - SPEventContext *ev = sp_desktop_event_context(desktop); + SPEventContext *ev = desktop->getEventContext(); if (!ev) { return; diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index 4fa1f263d..1e9bef354 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -475,7 +475,7 @@ sp_gradient_context_add_stop_near_point (SPGradientContext *rc, SPItem *item, G ec->get_drag()->selectByStop(newstop); } -gint SPGradientContext::root_handler(GdkEvent* event) { +bool SPGradientContext::root_handler(GdkEvent* event) { static bool dragging; Inkscape::Selection *selection = sp_desktop_selection (desktop); @@ -608,11 +608,11 @@ gint SPGradientContext::root_handler(GdkEvent* event) { if (this->cursor_addnode && !over_line) { this->cursor_shape = cursor_gradient_xpm; - sp_event_context_update_cursor(this); + this->sp_event_context_update_cursor(); this->cursor_addnode = false; } else if (!this->cursor_addnode && over_line) { this->cursor_shape = cursor_gradient_add_xpm; - sp_event_context_update_cursor(this); + this->sp_event_context_update_cursor(); this->cursor_addnode = true; } } diff --git a/src/gradient-context.h b/src/gradient-context.h index 21418f89e..0c2a7eb3d 100644 --- a/src/gradient-context.h +++ b/src/gradient-context.h @@ -43,7 +43,7 @@ public: static const std::string prefsPath; virtual void setup(); - virtual gint root_handler(GdkEvent* event); + virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/inkscape.cpp b/src/inkscape.cpp index a24bd2b8a..e1cabd2d5 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -1013,7 +1013,7 @@ inkscape_add_desktop (SPDesktop * desktop) inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop); g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop)); + g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, desktop->getEventContext()); g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop)); g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop)); } @@ -1035,7 +1035,7 @@ inkscape_remove_desktop (SPDesktop * desktop) inkscape->desktops = g_slist_remove (inkscape->desktops, new_desktop); inkscape->desktops = g_slist_prepend (inkscape->desktops, new_desktop); g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, new_desktop); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (new_desktop)); + g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, new_desktop->getEventContext()); g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (new_desktop)); g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (new_desktop)); } else { @@ -1075,7 +1075,7 @@ inkscape_activate_desktop (SPDesktop * desktop) inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop); g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop)); + g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, desktop->getEventContext()); g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop)); g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop)); } @@ -1342,7 +1342,7 @@ SPEventContext * inkscape_active_event_context (void) { if (SP_ACTIVE_DESKTOP) { - return sp_desktop_event_context (SP_ACTIVE_DESKTOP); + return SP_ACTIVE_DESKTOP->getEventContext(); } return NULL; diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index 26d52767d..7ff262a3c 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -182,7 +182,7 @@ void SPLPEToolContext::set(const Inkscape::Preferences::Entry& val) { */ } -gint SPLPEToolContext::item_handler(SPItem* item, GdkEvent* event) { +bool SPLPEToolContext::item_handler(SPItem* item, GdkEvent* event) { SPEventContext* ec = this; gint ret = FALSE; @@ -214,7 +214,7 @@ gint SPLPEToolContext::item_handler(SPItem* item, GdkEvent* event) { return ret; } -gint SPLPEToolContext::root_handler(GdkEvent* event) { +bool SPLPEToolContext::root_handler(GdkEvent* event) { SPEventContext* event_context = this; SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(event_context); diff --git a/src/lpe-tool-context.h b/src/lpe-tool-context.h index 18eaedf69..657916342 100644 --- a/src/lpe-tool-context.h +++ b/src/lpe-tool-context.h @@ -62,8 +62,8 @@ public: virtual void setup(); virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); + virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); }; diff --git a/src/measure-context.cpp b/src/measure-context.cpp index 99f1d8d06..9ee728bc8 100644 --- a/src/measure-context.cpp +++ b/src/measure-context.cpp @@ -311,7 +311,7 @@ static void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom: } } -gint SPMeasureContext::root_handler(GdkEvent* event) { +bool SPMeasureContext::root_handler(GdkEvent* event) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); diff --git a/src/measure-context.h b/src/measure-context.h index 76509e91c..2449d5735 100644 --- a/src/measure-context.h +++ b/src/measure-context.h @@ -25,7 +25,7 @@ public: static const std::string prefsPath; virtual void finish(); - virtual gint root_handler(GdkEvent* event); + virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/mesh-context.cpp b/src/mesh-context.cpp index fce4cbb9a..915ac0f7f 100644 --- a/src/mesh-context.cpp +++ b/src/mesh-context.cpp @@ -443,7 +443,7 @@ sp_mesh_context_corner_operation (SPMeshContext *rc, MeshCornerOperation operati /** Handles all keyboard and mouse input for meshs. */ -gint SPMeshContext::root_handler(GdkEvent* event) { +bool SPMeshContext::root_handler(GdkEvent* event) { static bool dragging; Inkscape::Selection *selection = sp_desktop_selection (desktop); @@ -615,11 +615,11 @@ gint SPMeshContext::root_handler(GdkEvent* event) { if (this->cursor_addnode && !over_line) { this->cursor_shape = cursor_gradient_xpm; - sp_event_context_update_cursor(this); + this->sp_event_context_update_cursor(); this->cursor_addnode = false; } else if (!this->cursor_addnode && over_line) { this->cursor_shape = cursor_gradient_add_xpm; - sp_event_context_update_cursor(this); + this->sp_event_context_update_cursor(); this->cursor_addnode = true; } } diff --git a/src/mesh-context.h b/src/mesh-context.h index 19614a41b..69eef1086 100644 --- a/src/mesh-context.h +++ b/src/mesh-context.h @@ -45,7 +45,7 @@ public: static const std::string prefsPath; virtual void setup(); - virtual gint root_handler(GdkEvent* event); + virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 21fc4fc51..690b520bc 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -291,7 +291,7 @@ static void spdc_endpoint_snap_handle(SPPenContext const *const pc, Geom::Point } } -gint SPPenContext::item_handler(SPItem* item, GdkEvent* event) { +bool SPPenContext::item_handler(SPItem* item, GdkEvent* event) { SPEventContext* ec = this; SPPenContext *const pc = SP_PEN_CONTEXT(ec); @@ -321,7 +321,7 @@ gint SPPenContext::item_handler(SPItem* item, GdkEvent* event) { /** * Callback to handle all pen events. */ -gint SPPenContext::root_handler(GdkEvent* event) { +bool SPPenContext::root_handler(GdkEvent* event) { SPEventContext* ec = this; SPPenContext *const pc = SP_PEN_CONTEXT(ec); diff --git a/src/pen-context.h b/src/pen-context.h index f8549035b..070d33a26 100644 --- a/src/pen-context.h +++ b/src/pen-context.h @@ -63,8 +63,8 @@ public: virtual void setup(); virtual void finish(); virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); + virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); }; diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 28ae41974..b81580f3a 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -143,7 +143,7 @@ spdc_endpoint_snap(SPPencilContext const *pc, Geom::Point &p, guint const state) /** * Callback for handling all pencil context events. */ -gint SPPencilContext::root_handler(GdkEvent* event) { +bool SPPencilContext::root_handler(GdkEvent* event) { SPEventContext* ec = this; SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec); diff --git a/src/pencil-context.h b/src/pencil-context.h index 198242f76..a0d2effe6 100644 --- a/src/pencil-context.h +++ b/src/pencil-context.h @@ -40,7 +40,7 @@ public: static const std::string prefsPath; virtual void setup(); - virtual gint root_handler(GdkEvent* event); + virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); }; diff --git a/src/rect-context.cpp b/src/rect-context.cpp index f93ddf6c3..23c4794c1 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -159,7 +159,7 @@ void SPRectContext::set(const Inkscape::Preferences::Entry& val) { } } -gint SPRectContext::item_handler(SPItem* item, GdkEvent* event) { +bool SPRectContext::item_handler(SPItem* item, GdkEvent* event) { gint ret = FALSE; switch (event->type) { @@ -181,7 +181,7 @@ gint SPRectContext::item_handler(SPItem* item, GdkEvent* event) { return ret; } -gint SPRectContext::root_handler(GdkEvent* event) { +bool SPRectContext::root_handler(GdkEvent* event) { static bool dragging; SPDesktop *desktop = this->desktop; diff --git a/src/rect-context.h b/src/rect-context.h index ab65a3b7a..1856a3d7e 100644 --- a/src/rect-context.h +++ b/src/rect-context.h @@ -34,8 +34,8 @@ public: virtual void setup(); virtual void finish(); virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); + virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/select-context.cpp b/src/select-context.cpp index 4badac3d8..efedb23e2 100644 --- a/src/select-context.cpp +++ b/src/select-context.cpp @@ -277,7 +277,7 @@ sp_select_context_up_one_layer(SPDesktop *desktop) } } -gint SPSelectContext::item_handler(SPItem* item, GdkEvent* event) { +bool SPSelectContext::item_handler(SPItem* item, GdkEvent* event) { gint ret = FALSE; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -455,7 +455,7 @@ sp_select_context_reset_opacities(SPEventContext *event_context) sc->cycling_items_cmp = NULL; } -gint SPSelectContext::root_handler(GdkEvent* event) { +bool SPSelectContext::root_handler(GdkEvent* event) { SPItem *item = NULL; SPItem *item_at_point = NULL, *group_at_point = NULL, *item_in_group = NULL; gint ret = FALSE; diff --git a/src/select-context.h b/src/select-context.h index 2f9406a8c..ab60083b1 100644 --- a/src/select-context.h +++ b/src/select-context.h @@ -52,8 +52,8 @@ public: virtual void setup(); virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); + virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); }; diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index cf0e81dbe..6b060b424 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -163,7 +163,7 @@ void SPSpiralContext::set(const Inkscape::Preferences::Entry& val) { } } -gint SPSpiralContext::root_handler(GdkEvent* event) { +bool SPSpiralContext::root_handler(GdkEvent* event) { static gboolean dragging; SPDesktop *desktop = this->desktop; diff --git a/src/spiral-context.h b/src/spiral-context.h index c2f579e28..518d8ad41 100644 --- a/src/spiral-context.h +++ b/src/spiral-context.h @@ -36,7 +36,7 @@ public: virtual void setup(); virtual void finish(); virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); + virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/spray-context.cpp b/src/spray-context.cpp index 66cc30c6d..c96df20b2 100644 --- a/src/spray-context.cpp +++ b/src/spray-context.cpp @@ -130,62 +130,49 @@ static void sp_spray_scale_rel(Geom::Point c, SPDesktop */*desktop*/, SPItem *it } SPSprayContext::SPSprayContext() : SPEventContext() { - SPSprayContext* tc = this; - - tc->usetilt = 0; - tc->_message_context = 0; - tc->dilate_area = 0; - tc->usetext = false; - tc->population = 0; - tc->is_drawing = false; - tc->mode = 0; - tc->usepressure = 0; - - SPEventContext *event_context = SP_EVENT_CONTEXT(tc); - - event_context->cursor_shape = cursor_spray_xpm; - event_context->hot_x = 4; - event_context->hot_y = 4; + this->usetilt = 0; + this->message_context = 0; + this->dilate_area = 0; + this->usetext = false; + this->population = 0; + this->is_drawing = false; + this->mode = 0; + this->usepressure = 0; + + this->cursor_shape = cursor_spray_xpm; + this->hot_x = 4; + this->hot_y = 4; /* attributes */ - tc->dragging = FALSE; - tc->distrib = 1; - tc->width = 0.2; - tc->force = 0.2; - tc->ratio = 0; - tc->tilt = 0; - tc->mean = 0.2; - tc->rotation_variation = 0; - tc->standard_deviation = 0.2; - tc->scale = 1; - tc->scale_variation = 1; - tc->pressure = TC_DEFAULT_PRESSURE; - - tc->is_dilating = false; - tc->has_dilated = false; - - //new (&tc->style_set_connection) sigc::connection(); + this->dragging = FALSE; + this->distrib = 1; + this->width = 0.2; + this->force = 0.2; + this->ratio = 0; + this->tilt = 0; + this->mean = 0.2; + this->rotation_variation = 0; + this->standard_deviation = 0.2; + this->scale = 1; + this->scale_variation = 1; + this->pressure = TC_DEFAULT_PRESSURE; + + this->is_dilating = false; + this->has_dilated = false; } SPSprayContext::~SPSprayContext() { - SPSprayContext *tc = SP_SPRAY_CONTEXT(this); - SPEventContext *ec = SP_EVENT_CONTEXT(this); + this->enableGrDrag(false); + this->style_set_connection.disconnect(); - ec->enableGrDrag(false); - - tc->style_set_connection.disconnect(); - //tc->style_set_connection.~connection(); - - if (tc->dilate_area) { - sp_canvas_item_destroy(tc->dilate_area); - tc->dilate_area = NULL; + if (this->dilate_area) { + sp_canvas_item_destroy(this->dilate_area); + this->dilate_area = NULL; } - if (tc->_message_context) { - delete tc->_message_context; + if (this->message_context) { + delete this->message_context; } - - //G_OBJECT_CLASS(sp_spray_context_parent_class)->dispose(object); } static bool is_transform_modes(gint mode) @@ -213,29 +200,22 @@ static void sp_spray_update_cursor(SPSprayContext *tc, bool /*with_shift*/) switch (tc->mode) { case SPRAY_MODE_COPY: - tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray <b>copies</b> of the initial selection."), sel_message); + tc->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray <b>copies</b> of the initial selection."), sel_message); break; case SPRAY_MODE_CLONE: - tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray <b>clones</b> of the initial selection."), sel_message); + tc->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray <b>clones</b> of the initial selection."), sel_message); break; case SPRAY_MODE_SINGLE_PATH: - tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray in a <b>single path</b> of the initial selection."), sel_message); + tc->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray in a <b>single path</b> of the initial selection."), sel_message); break; default: break; } - sp_event_context_update_cursor(event_context); + event_context->sp_event_context_update_cursor(); g_free(sel_message); } void SPSprayContext::setup() { - SPEventContext* ec = this; - - SPSprayContext *tc = SP_SPRAY_CONTEXT(ec); - -// if ((SP_EVENT_CONTEXT_CLASS(sp_spray_context_parent_class))->setup) { -// (SP_EVENT_CONTEXT_CLASS(sp_spray_context_parent_class))->setup(ec); -// } SPEventContext::setup(); { @@ -248,72 +228,69 @@ void SPSprayContext::setup() { c->curveto(1, -C1, C1, -1, 0, -1 ); c->curveto(-C1, -1, -1, -C1, -1, 0 ); c->closepath(); - tc->dilate_area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c); + this->dilate_area = sp_canvas_bpath_new(sp_desktop_controls(this->desktop), c); c->unref(); - sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(tc->dilate_area), 0x00000000,(SPWindRule)0); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(tc->dilate_area), 0xff9900ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_item_hide(tc->dilate_area); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->dilate_area), 0x00000000,(SPWindRule)0); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->dilate_area), 0xff9900ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_item_hide(this->dilate_area); } - tc->is_drawing = false; + this->is_drawing = false; - tc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); + this->message_context = new Inkscape::MessageContext((this->desktop)->messageStack()); - sp_event_context_read(ec, "distrib"); - sp_event_context_read(ec, "width"); - sp_event_context_read(ec, "ratio"); - sp_event_context_read(ec, "tilt"); - sp_event_context_read(ec, "rotation_variation"); - sp_event_context_read(ec, "scale_variation"); - sp_event_context_read(ec, "mode"); - sp_event_context_read(ec, "population"); - sp_event_context_read(ec, "force"); - sp_event_context_read(ec, "mean"); - sp_event_context_read(ec, "standard_deviation"); - sp_event_context_read(ec, "usepressure"); - sp_event_context_read(ec, "Scale"); + sp_event_context_read(this, "distrib"); + sp_event_context_read(this, "width"); + sp_event_context_read(this, "ratio"); + sp_event_context_read(this, "tilt"); + sp_event_context_read(this, "rotation_variation"); + sp_event_context_read(this, "scale_variation"); + sp_event_context_read(this, "mode"); + sp_event_context_read(this, "population"); + sp_event_context_read(this, "force"); + sp_event_context_read(this, "mean"); + sp_event_context_read(this, "standard_deviation"); + sp_event_context_read(this, "usepressure"); + sp_event_context_read(this, "Scale"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/spray/selcue")) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } if (prefs->getBool("/tools/spray/gradientdrag")) { - ec->enableGrDrag(); + this->enableGrDrag(); } } void SPSprayContext::set(const Inkscape::Preferences::Entry& val) { - SPEventContext* ec = this; - - SPSprayContext *tc = SP_SPRAY_CONTEXT(ec); Glib::ustring path = val.getEntryName(); if (path == "mode") { - tc->mode = val.getInt(); - sp_spray_update_cursor(tc, false); + this->mode = val.getInt(); + sp_spray_update_cursor(this, false); } else if (path == "width") { - tc->width = 0.01 * CLAMP(val.getInt(10), 1, 100); + this->width = 0.01 * CLAMP(val.getInt(10), 1, 100); } else if (path == "usepressure") { - tc->usepressure = val.getBool(); + this->usepressure = val.getBool(); } else if (path == "population") { - tc->population = 0.01 * CLAMP(val.getInt(10), 1, 100); + this->population = 0.01 * CLAMP(val.getInt(10), 1, 100); } else if (path == "rotation_variation") { - tc->rotation_variation = CLAMP(val.getDouble(0.0), 0, 100.0); + this->rotation_variation = CLAMP(val.getDouble(0.0), 0, 100.0); } else if (path == "scale_variation") { - tc->scale_variation = CLAMP(val.getDouble(1.0), 0, 100.0); + this->scale_variation = CLAMP(val.getDouble(1.0), 0, 100.0); } else if (path == "standard_deviation") { - tc->standard_deviation = 0.01 * CLAMP(val.getInt(10), 1, 100); + this->standard_deviation = 0.01 * CLAMP(val.getInt(10), 1, 100); } else if (path == "mean") { - tc->mean = 0.01 * CLAMP(val.getInt(10), 1, 100); + this->mean = 0.01 * CLAMP(val.getInt(10), 1, 100); // Not implemented in the toolbar and preferences yet } else if (path == "distribution") { - tc->distrib = val.getInt(1); + this->distrib = val.getInt(1); } else if (path == "tilt") { - tc->tilt = CLAMP(val.getDouble(0.1), 0, 1000.0); + this->tilt = CLAMP(val.getDouble(0.1), 0, 1000.0); } else if (path == "ratio") { - tc->ratio = CLAMP(val.getDouble(), 0.0, 0.9); + this->ratio = CLAMP(val.getDouble(), 0.0, 0.9); } else if (path == "force") { - tc->force = CLAMP(val.getDouble(1.0), 0, 1.0); + this->force = CLAMP(val.getDouble(1.0), 0, 1.0); } } @@ -618,43 +595,38 @@ static void sp_spray_switch_mode(SPSprayContext *tc, gint mode, bool with_shift) sp_spray_update_cursor(tc, with_shift); } -gint SPSprayContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - - SPSprayContext *tc = SP_SPRAY_CONTEXT(event_context); - SPDesktop *desktop = event_context->desktop; - +bool SPSprayContext::root_handler(GdkEvent* event) { gint ret = FALSE; switch (event->type) { case GDK_ENTER_NOTIFY: - sp_canvas_item_show(tc->dilate_area); + sp_canvas_item_show(this->dilate_area); break; case GDK_LEAVE_NOTIFY: - sp_canvas_item_hide(tc->dilate_area); + sp_canvas_item_hide(this->dilate_area); break; case GDK_BUTTON_PRESS: - if (event->button.button == 1 && !event_context->space_panning) { - if (Inkscape::have_viable_layer(desktop, tc->_message_context) == false) { + if (event->button.button == 1 && !this->space_panning) { + if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { return TRUE; } Geom::Point const motion_w(event->button.x, event->button.y); Geom::Point const motion_dt(desktop->w2d(motion_w)); - tc->last_push = desktop->dt2doc(motion_dt); + this->last_push = desktop->dt2doc(motion_dt); - sp_spray_extinput(tc, event); + sp_spray_extinput(this, event); desktop->canvas->forceFullRedrawAfterInterruptions(3); - tc->is_drawing = true; - tc->is_dilating = true; - tc->has_dilated = false; + this->is_drawing = true; + this->is_dilating = true; + this->has_dilated = false; - if(tc->is_dilating && event->button.button == 1 && !event_context->space_panning) { - sp_spray_dilate(tc, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event)); + if(this->is_dilating && event->button.button == 1 && !this->space_panning) { + sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event)); } - tc->has_dilated = true; + this->has_dilated = true; ret = TRUE; } break; @@ -663,27 +635,27 @@ gint SPSprayContext::root_handler(GdkEvent* event) { event->motion.y); Geom::Point motion_dt(desktop->w2d(motion_w)); Geom::Point motion_doc(desktop->dt2doc(motion_dt)); - sp_spray_extinput(tc, event); + sp_spray_extinput(this, event); // draw the dilating cursor - double radius = get_dilate_radius(tc); - Geom::Affine const sm (Geom::Scale(radius/(1-tc->ratio), radius/(1+tc->ratio)) ); - sp_canvas_item_affine_absolute(tc->dilate_area, (sm*Geom::Rotate(tc->tilt))*Geom::Translate(desktop->w2d(motion_w))); - sp_canvas_item_show(tc->dilate_area); + double radius = get_dilate_radius(this); + Geom::Affine const sm (Geom::Scale(radius/(1-this->ratio), radius/(1+this->ratio)) ); + sp_canvas_item_affine_absolute(this->dilate_area, (sm*Geom::Rotate(this->tilt))*Geom::Translate(desktop->w2d(motion_w))); + sp_canvas_item_show(this->dilate_area); guint num = 0; if (!desktop->selection->isEmpty()) { num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList())); } if (num == 0) { - tc->_message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to spray.")); + this->message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to spray.")); } // dilating: - if (tc->is_drawing && ( event->motion.state & GDK_BUTTON1_MASK )) { - sp_spray_dilate(tc, motion_w, motion_doc, motion_doc - tc->last_push, event->button.state & GDK_SHIFT_MASK? true : false); - //tc->last_push = motion_doc; - tc->has_dilated = true; + if (this->is_drawing && ( event->motion.state & GDK_BUTTON1_MASK )) { + sp_spray_dilate(this, motion_w, motion_doc, motion_doc - this->last_push, event->button.state & GDK_SHIFT_MASK? true : false); + //this->last_push = motion_doc; + this->has_dilated = true; // it's slow, so prevent clogging up with events gobble_motion_events(GDK_BUTTON1_MASK); @@ -695,31 +667,31 @@ gint SPSprayContext::root_handler(GdkEvent* event) { case GDK_SCROLL: { if (event->scroll.state & GDK_BUTTON1_MASK) { double temp ; - temp = tc->population; - tc->population = 1.0; - desktop->setToolboxAdjustmentValue("population", tc->population * 100); + temp = this->population; + this->population = 1.0; + desktop->setToolboxAdjustmentValue("population", this->population * 100); Geom::Point const scroll_w(event->button.x, event->button.y); Geom::Point const scroll_dt = desktop->point();; Geom::Point motion_doc(desktop->dt2doc(scroll_dt)); switch (event->scroll.direction) { case GDK_SCROLL_DOWN: case GDK_SCROLL_UP: { - if (Inkscape::have_viable_layer(desktop, tc->_message_context) == false) { + if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { return TRUE; } - tc->last_push = desktop->dt2doc(scroll_dt); - sp_spray_extinput(tc, event); + this->last_push = desktop->dt2doc(scroll_dt); + sp_spray_extinput(this, event); desktop->canvas->forceFullRedrawAfterInterruptions(3); - tc->is_drawing = true; - tc->is_dilating = true; - tc->has_dilated = false; - if(tc->is_dilating && !event_context->space_panning) { - sp_spray_dilate(tc, scroll_w, desktop->dt2doc(scroll_dt), Geom::Point(0,0), false); + this->is_drawing = true; + this->is_dilating = true; + this->has_dilated = false; + if(this->is_dilating && !this->space_panning) { + sp_spray_dilate(this, scroll_w, desktop->dt2doc(scroll_dt), Geom::Point(0,0), false); } - tc->has_dilated = true; + this->has_dilated = true; - tc->population = temp; - desktop->setToolboxAdjustmentValue("population", tc->population * 100); + this->population = temp; + desktop->setToolboxAdjustmentValue("population", this->population * 100); ret = TRUE; } @@ -738,27 +710,27 @@ gint SPSprayContext::root_handler(GdkEvent* event) { Geom::Point const motion_dt(desktop->w2d(motion_w)); desktop->canvas->endForcedFullRedraws(); - tc->is_drawing = false; + this->is_drawing = false; - if (tc->is_dilating && event->button.button == 1 && !event_context->space_panning) { - if (!tc->has_dilated) { + if (this->is_dilating && event->button.button == 1 && !this->space_panning) { + if (!this->has_dilated) { // if we did not rub, do a light tap - tc->pressure = 0.03; - sp_spray_dilate(tc, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event)); + this->pressure = 0.03; + sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event)); } - tc->is_dilating = false; - tc->has_dilated = false; - switch (tc->mode) { + this->is_dilating = false; + this->has_dilated = false; + switch (this->mode) { case SPRAY_MODE_COPY: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_SPRAY, _("Spray with copies")); break; case SPRAY_MODE_CLONE: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_SPRAY, _("Spray with clones")); break; case SPRAY_MODE_SINGLE_PATH: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_SPRAY, _("Spray in single path")); break; } @@ -771,83 +743,83 @@ gint SPSprayContext::root_handler(GdkEvent* event) { case GDK_KEY_j: case GDK_KEY_J: if (MOD__SHIFT_ONLY(event)) { - sp_spray_switch_mode(tc, SPRAY_MODE_COPY, MOD__SHIFT(event)); + sp_spray_switch_mode(this, SPRAY_MODE_COPY, MOD__SHIFT(event)); ret = TRUE; } break; case GDK_KEY_k: case GDK_KEY_K: if (MOD__SHIFT_ONLY(event)) { - sp_spray_switch_mode(tc, SPRAY_MODE_CLONE, MOD__SHIFT(event)); + sp_spray_switch_mode(this, SPRAY_MODE_CLONE, MOD__SHIFT(event)); ret = TRUE; } break; case GDK_KEY_l: case GDK_KEY_L: if (MOD__SHIFT_ONLY(event)) { - sp_spray_switch_mode(tc, SPRAY_MODE_SINGLE_PATH, MOD__SHIFT(event)); + sp_spray_switch_mode(this, SPRAY_MODE_SINGLE_PATH, MOD__SHIFT(event)); ret = TRUE; } break; case GDK_KEY_Up: case GDK_KEY_KP_Up: if (!MOD__CTRL_ONLY(event)) { - tc->population += 0.01; - if (tc->population > 1.0) { - tc->population = 1.0; + this->population += 0.01; + if (this->population > 1.0) { + this->population = 1.0; } - desktop->setToolboxAdjustmentValue("spray-population", tc->population * 100); + desktop->setToolboxAdjustmentValue("spray-population", this->population * 100); ret = TRUE; } break; case GDK_KEY_Down: case GDK_KEY_KP_Down: if (!MOD__CTRL_ONLY(event)) { - tc->population -= 0.01; - if (tc->population < 0.0) { - tc->population = 0.0; + this->population -= 0.01; + if (this->population < 0.0) { + this->population = 0.0; } - desktop->setToolboxAdjustmentValue("spray-population", tc->population * 100); + desktop->setToolboxAdjustmentValue("spray-population", this->population * 100); ret = TRUE; } break; case GDK_KEY_Right: case GDK_KEY_KP_Right: if (!MOD__CTRL_ONLY(event)) { - tc->width += 0.01; - if (tc->width > 1.0) { - tc->width = 1.0; + this->width += 0.01; + if (this->width > 1.0) { + this->width = 1.0; } // the same spinbutton is for alt+x - desktop->setToolboxAdjustmentValue("altx-spray", tc->width * 100); - sp_spray_update_area(tc); + desktop->setToolboxAdjustmentValue("altx-spray", this->width * 100); + sp_spray_update_area(this); ret = TRUE; } break; case GDK_KEY_Left: case GDK_KEY_KP_Left: if (!MOD__CTRL_ONLY(event)) { - tc->width -= 0.01; - if (tc->width < 0.01) { - tc->width = 0.01; + this->width -= 0.01; + if (this->width < 0.01) { + this->width = 0.01; } - desktop->setToolboxAdjustmentValue("altx-spray", tc->width * 100); - sp_spray_update_area(tc); + desktop->setToolboxAdjustmentValue("altx-spray", this->width * 100); + sp_spray_update_area(this); ret = TRUE; } break; case GDK_KEY_Home: case GDK_KEY_KP_Home: - tc->width = 0.01; - desktop->setToolboxAdjustmentValue("altx-spray", tc->width * 100); - sp_spray_update_area(tc); + this->width = 0.01; + desktop->setToolboxAdjustmentValue("altx-spray", this->width * 100); + sp_spray_update_area(this); ret = TRUE; break; case GDK_KEY_End: case GDK_KEY_KP_End: - tc->width = 1.0; - desktop->setToolboxAdjustmentValue("altx-spray", tc->width * 100); - sp_spray_update_area(tc); + this->width = 1.0; + desktop->setToolboxAdjustmentValue("altx-spray", this->width * 100); + sp_spray_update_area(this); ret = TRUE; break; case GDK_KEY_x: @@ -859,7 +831,7 @@ gint SPSprayContext::root_handler(GdkEvent* event) { break; case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: - sp_spray_update_cursor(tc, true); + sp_spray_update_cursor(this, true); break; case GDK_KEY_Control_L: case GDK_KEY_Control_R: @@ -867,7 +839,7 @@ gint SPSprayContext::root_handler(GdkEvent* event) { case GDK_KEY_Delete: case GDK_KEY_KP_Delete: case GDK_KEY_BackSpace: - ret = event_context->deleteSelectedDrag(MOD__CTRL_ONLY(event)); + ret = this->deleteSelectedDrag(MOD__CTRL_ONLY(event)); break; default: @@ -880,15 +852,15 @@ gint SPSprayContext::root_handler(GdkEvent* event) { switch (get_group0_keyval(&event->key)) { case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: - sp_spray_update_cursor(tc, false); + sp_spray_update_cursor(this, false); break; case GDK_KEY_Control_L: case GDK_KEY_Control_R: - sp_spray_switch_mode (tc, prefs->getInt("/tools/spray/mode"), MOD__SHIFT(event)); - tc->_message_context->clear(); + sp_spray_switch_mode (this, prefs->getInt("/tools/spray/mode"), MOD__SHIFT(event)); + this->message_context->clear(); break; default: - sp_spray_switch_mode (tc, prefs->getInt("/tools/spray/mode"), MOD__SHIFT(event)); + sp_spray_switch_mode (this, prefs->getInt("/tools/spray/mode"), MOD__SHIFT(event)); break; } } diff --git a/src/spray-context.h b/src/spray-context.h index 327402945..1bae7c4e4 100644 --- a/src/spray-context.h +++ b/src/spray-context.h @@ -77,7 +77,7 @@ public: gint mode; - Inkscape::MessageContext *_message_context; + Inkscape::MessageContext *message_context; bool is_drawing; @@ -92,7 +92,7 @@ public: virtual void setup(); virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); + virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); }; diff --git a/src/star-context.cpp b/src/star-context.cpp index 4272fb1a0..3601a4d49 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -67,35 +67,30 @@ const std::string& SPStarContext::getPrefsPath() { const std::string SPStarContext::prefsPath = "/tools/shapes/star"; SPStarContext::SPStarContext() : SPEventContext() { - SPStarContext* star_context = this; + this->randomized = 0; + this->message_context = 0; + this->rounded = 0; - star_context->randomized = 0; - star_context->_message_context = 0; - star_context->rounded = 0; - - SPEventContext *event_context = SP_EVENT_CONTEXT (star_context); - - event_context->cursor_shape = cursor_star_xpm; - event_context->hot_x = 4; - event_context->hot_y = 4; - event_context->xp = 0; - event_context->yp = 0; - event_context->tolerance = 0; - event_context->within_tolerance = false; - event_context->item_to_select = NULL; - //event_context->tool_url = "/tools/shapes/star"; + this->cursor_shape = cursor_star_xpm; + this->hot_x = 4; + this->hot_y = 4; + this->xp = 0; + this->yp = 0; + this->tolerance = 0; + this->within_tolerance = false; + this->item_to_select = NULL; + //this->tool_url = "/tools/shapes/star"; - star_context->star = NULL; + this->star = NULL; - star_context->magnitude = 5; - star_context->proportion = 0.5; - star_context->isflatsided = false; + this->magnitude = 5; + this->proportion = 0.5; + this->isflatsided = false; } void SPStarContext::finish() { - SPDesktop *desktop = this->desktop; - sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME); + this->finishItem(); this->sel_changed_connection.disconnect(); @@ -115,8 +110,8 @@ SPStarContext::~SPStarContext() { this->finishItem(); } - if (this->_message_context) { - delete this->_message_context; + if (this->message_context) { + delete this->message_context; } } @@ -164,7 +159,7 @@ void SPStarContext::setup() { this->enableGrDrag(); } - this->_message_context = new Inkscape::MessageContext(this->desktop->messageStack()); + this->message_context = new Inkscape::MessageContext(this->desktop->messageStack()); } void SPStarContext::set(const Inkscape::Preferences::Entry& val) { @@ -183,7 +178,7 @@ void SPStarContext::set(const Inkscape::Preferences::Entry& val) { } } -gint SPStarContext::root_handler(GdkEvent* event) { +bool SPStarContext::root_handler(GdkEvent* event) { static bool dragging; SPDesktop *desktop = this->desktop; @@ -383,7 +378,7 @@ void SPStarContext::drag(Geom::Point p, guint state) int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12); if (!this->star) { - if (Inkscape::have_viable_layer(desktop, this->_message_context) == false) { + if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { return; } @@ -430,7 +425,7 @@ void SPStarContext::drag(Geom::Point p, guint state) /* status text */ GString *rads = SP_PX_TO_METRIC_STRING(r1, desktop->namedview->getDefaultMetric()); - this->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, + this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, ( this->isflatsided? _("<b>Polygon</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle") : _("<b>Star</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle") ), @@ -440,7 +435,7 @@ void SPStarContext::drag(Geom::Point p, guint state) } void SPStarContext::finishItem() { - this->_message_context->clear(); + this->message_context->clear(); if (this->star != NULL) { if (this->star->r[1] == 0) { diff --git a/src/star-context.h b/src/star-context.h index 8902b5450..a068e4441 100644 --- a/src/star-context.h +++ b/src/star-context.h @@ -21,9 +21,6 @@ #include "sp-star.h" -#define SP_STAR_CONTEXT(obj) ((SPStarContext*)obj) -#define SP_IS_STAR_CONTEXT(obj) (dynamic_cast<const SPStarContext*>((const SPEventContext*)obj)) - class SPStarContext : public SPEventContext { public: SPStarContext(); @@ -34,7 +31,7 @@ public: virtual void setup(); virtual void finish(); virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); + virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); @@ -60,7 +57,7 @@ private: sigc::connection sel_changed_connection; - Inkscape::MessageContext *_message_context; + Inkscape::MessageContext *message_context; void drag(Geom::Point p, guint state); void finishItem(); diff --git a/src/text-context.cpp b/src/text-context.cpp index 254fafe6b..fea159834 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -299,7 +299,7 @@ void SPTextContext::finish() { tc->text_selection_quads.clear(); } -gint SPTextContext::item_handler(SPItem* item, GdkEvent* event) { +bool SPTextContext::item_handler(SPItem* item, GdkEvent* event) { SPEventContext* event_context = this; SPTextContext *tc = SP_TEXT_CONTEXT(event_context); @@ -421,7 +421,7 @@ gint SPTextContext::item_handler(SPItem* item, GdkEvent* event) { event_context->cursor_shape = cursor_text_insert_xpm; event_context->hot_x = 7; event_context->hot_y = 10; - sp_event_context_update_cursor(event_context); + event_context->sp_event_context_update_cursor(); sp_text_context_update_text_selection(tc); if (SP_IS_TEXT (item_ungrouped)) { @@ -563,7 +563,7 @@ static void show_curr_uni_char(SPTextContext *const tc) } } -gint SPTextContext::root_handler(GdkEvent* event) { +bool SPTextContext::root_handler(GdkEvent* event) { SPEventContext* event_context = this; SPTextContext *const tc = SP_TEXT_CONTEXT(event_context); @@ -617,7 +617,7 @@ gint SPTextContext::root_handler(GdkEvent* event) { event_context->cursor_shape = cursor_text_xpm; event_context->hot_x = 7; event_context->hot_y = 7; - sp_event_context_update_cursor(event_context); + event_context->sp_event_context_update_cursor(); desktop->event_context->defaultMessageContext()->clear(); } diff --git a/src/text-context.h b/src/text-context.h index adcd92991..8da7af7e5 100644 --- a/src/text-context.h +++ b/src/text-context.h @@ -76,8 +76,8 @@ public: virtual void setup(); virtual void finish(); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); + virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); }; diff --git a/src/tools-switch.cpp b/src/tools-switch.cpp index ec917f331..fd160e518 100644 --- a/src/tools-switch.cpp +++ b/src/tools-switch.cpp @@ -129,131 +129,131 @@ tools_switch(SPDesktop *dt, int num) //dt->set_event_context(SP_TYPE_SELECT_CONTEXT, tool_names[num]); /* fixme: This is really ugly hack. We should bind and unbind class methods */ dt->activate_guides(true); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); break; case TOOLS_NODES: //dt->set_event_context(INK_TYPE_NODE_TOOL, tool_names[num]); dt->activate_guides(true); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); break; case TOOLS_TWEAK: //dt->set_event_context(SP_TYPE_TWEAK_CONTEXT, tool_names[num]); dt->activate_guides(true); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("To tweak a path by pushing, select it and drag over it.")); break; case TOOLS_SPRAY: //dt->set_event_context(SP_TYPE_SPRAY_CONTEXT, tool_names[num]); dt->activate_guides(true); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b>, <b>click</b> or <b>click and scroll</b> to spray the selected objects.")); break; case TOOLS_SHAPES_RECT: //dt->set_event_context(SP_TYPE_RECT_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a rectangle. <b>Drag controls</b> to round corners and resize. <b>Click</b> to select.")); break; case TOOLS_SHAPES_3DBOX: //dt->set_event_context(SP_TYPE_BOX3D_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a 3D box. <b>Drag controls</b> to resize in perspective. <b>Click</b> to select (with <b>Ctrl+Alt</b> for single faces).")); break; case TOOLS_SHAPES_ARC: //dt->set_event_context(SP_TYPE_ARC_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create an ellipse. <b>Drag controls</b> to make an arc or segment. <b>Click</b> to select.")); break; case TOOLS_SHAPES_STAR: //dt->set_event_context(SP_TYPE_STAR_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a star. <b>Drag controls</b> to edit the star shape. <b>Click</b> to select.")); break; case TOOLS_SHAPES_SPIRAL: //dt->set_event_context(SP_TYPE_SPIRAL_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a spiral. <b>Drag controls</b> to edit the spiral shape. <b>Click</b> to select.")); break; case TOOLS_FREEHAND_PENCIL: //dt->set_event_context(SP_TYPE_PENCIL_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a freehand line. <b>Shift</b> appends to selected path, <b>Alt</b> activates sketch mode.")); break; case TOOLS_FREEHAND_PEN: //dt->set_event_context(SP_TYPE_PEN_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to start a path; with <b>Shift</b> to append to selected path. <b>Ctrl+click</b> to create single dots (straight line modes only).")); break; case TOOLS_CALLIGRAPHIC: //dt->set_event_context(SP_TYPE_DYNA_DRAW_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to draw a calligraphic stroke; with <b>Ctrl</b> to track a guide path. <b>Arrow keys</b> adjust width (left/right) and angle (up/down).")); break; case TOOLS_TEXT: //dt->set_event_context(SP_TYPE_TEXT_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to select or create text, <b>drag</b> to create flowed text; then type.")); break; case TOOLS_GRADIENT: //dt->set_event_context(SP_TYPE_GRADIENT_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> or <b>double click</b> to create a gradient on selected objects, <b>drag handles</b> to adjust gradients.")); break; case TOOLS_MESH: //dt->set_event_context(SP_TYPE_MESH_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> or <b>double click</b> to create a mesh on selected objects, <b>drag handles</b> to adjust meshes.")); break; case TOOLS_ZOOM: //dt->set_event_context(SP_TYPE_ZOOM_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>drag around an area</b> to zoom in, <b>Shift+click</b> to zoom out.")); break; case TOOLS_MEASURE: //dt->set_event_context(SP_TYPE_MEASURE_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to measure the dimensions of objects.")); break; case TOOLS_DROPPER: //dt->set_event_context(SP_TYPE_DROPPER_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to set fill, <b>Shift+click</b> to set stroke; <b>drag</b> to average color in area; with <b>Alt</b> to pick inverse color; <b>Ctrl+C</b> to copy the color under mouse to clipboard")); break; case TOOLS_CONNECTOR: //dt->set_event_context(SP_TYPE_CONNECTOR_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click and drag</b> between shapes to create a connector.")); break; case TOOLS_PAINTBUCKET: //dt->set_event_context(SP_TYPE_FLOOD_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to paint a bounded area, <b>Shift+click</b> to union the new fill with the current selection, <b>Ctrl+click</b> to change the clicked object's fill and stroke to the current setting.")); break; case TOOLS_ERASER: //dt->set_event_context(SP_TYPE_ERASER_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to erase.")); break; case TOOLS_LPETOOL: //dt->set_event_context(SP_TYPE_LPETOOL_CONTEXT, tool_names[num]); dt->activate_guides(false); - inkscape_eventcontext_set(sp_desktop_event_context(dt)); + inkscape_eventcontext_set(dt->getEventContext()); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Choose a subtool from the toolbar")); break; } diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp index 4e842abbb..74e2e12e2 100644 --- a/src/tweak-context.cpp +++ b/src/tweak-context.cpp @@ -258,7 +258,7 @@ sp_tweak_update_cursor (SPTweakContext *tc, bool with_shift) event_context->cursor_shape = cursor_color_xpm; break; } - sp_event_context_update_cursor(event_context); + event_context->sp_event_context_update_cursor(); g_free(sel_message); } @@ -1154,7 +1154,7 @@ sp_tweak_switch_mode_temporarily (SPTweakContext *tc, gint mode, bool with_shift sp_tweak_update_cursor (tc, with_shift); } -gint SPTweakContext::root_handler(GdkEvent* event) { +bool SPTweakContext::root_handler(GdkEvent* event) { gint ret = FALSE; switch (event->type) { diff --git a/src/tweak-context.h b/src/tweak-context.h index 1ca279ca1..2d3eaa1e4 100644 --- a/src/tweak-context.h +++ b/src/tweak-context.h @@ -15,9 +15,6 @@ #include "event-context.h" #include <2geom/point.h> -#define SP_TWEAK_CONTEXT(obj) ((SPTweakContext*)obj) -#define SP_IS_TWEAK_CONTEXT(obj) (dynamic_cast<const SPTweakContext*>((const SPEventContext*)obj)) - #define SAMPLING_SIZE 8 /* fixme: ?? */ #define TC_MIN_PRESSURE 0.0 @@ -79,7 +76,7 @@ public: virtual void setup(); virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); + virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 8845b60e5..38f10c59c 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -47,6 +47,7 @@ #include "widgets/icon.h" #include "sp-root.h" #include "document-undo.h" +#include "desktop.h" #include <glibmm/i18n.h> @@ -367,19 +368,25 @@ public : private : Geom::Dim2 _orientation; bool _distribute; - virtual void on_button_click() - { - if (!_dialog.getDesktop()) return; - SPEventContext *event_context = sp_desktop_event_context(_dialog.getDesktop()); - if (!INK_IS_NODE_TOOL (event_context)) return; + virtual void on_button_click() { + if (!_dialog.getDesktop()) { + return; + } + + SPEventContext *event_context = _dialog.getDesktop()->getEventContext(); + + if (!INK_IS_NODE_TOOL(event_context)) { + return; + } + InkNodeTool *nt = INK_NODE_TOOL(event_context); - if (_distribute) + if (_distribute) { nt->_multipath->distributeNodes(_orientation); - else + } else { nt->_multipath->alignNodes(_orientation); - + } } }; @@ -825,7 +832,7 @@ private : static void on_tool_changed(Inkscape::Application */*inkscape*/, SPEventContext */*context*/, AlignAndDistribute *daad) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (desktop && sp_desktop_event_context(desktop)) + if (desktop && desktop->getEventContext()) daad->setMode(tools_active(desktop) == TOOLS_NODES); } diff --git a/src/ui/tool/node-tool.cpp b/src/ui/tool/node-tool.cpp index b65ca22b9..d424c1fdb 100644 --- a/src/ui/tool/node-tool.cpp +++ b/src/ui/tool/node-tool.cpp @@ -411,7 +411,7 @@ void InkNodeTool::selection_changed(Inkscape::Selection *sel) { this->desktop->updateNow(); } -gint InkNodeTool::root_handler(GdkEvent* event) { +bool InkNodeTool::root_handler(GdkEvent* event) { /* things to handle here: * 1. selection of items * 2. passing events to manipulators @@ -613,7 +613,7 @@ void InkNodeTool::update_tip(GdkEvent *event) { } } -gint InkNodeTool::item_handler(SPItem* item, GdkEvent* event) { +bool InkNodeTool::item_handler(SPItem* item, GdkEvent* event) { SPEventContext::item_handler(item, event); return FALSE; @@ -684,13 +684,13 @@ void InkNodeTool::mouseover_changed(Inkscape::UI::ControlPoint *p) { this->cursor_shape = cursor_node_d_xpm; this->hot_x = 1; this->hot_y = 1; - sp_event_context_update_cursor(this); + this->sp_event_context_update_cursor(); this->cursor_drag = true; } else if (!cdp && this->cursor_drag) { this->cursor_shape = cursor_node_xpm; this->hot_x = 1; this->hot_y = 1; - sp_event_context_update_cursor(this); + this->sp_event_context_update_cursor(); this->cursor_drag = false; } } diff --git a/src/ui/tool/node-tool.h b/src/ui/tool/node-tool.h index df8b5d782..313cc0561 100644 --- a/src/ui/tool/node-tool.h +++ b/src/ui/tool/node-tool.h @@ -15,22 +15,23 @@ #include <glib.h> #include "event-context.h" -#define INK_NODE_TOOL(obj) ((InkNodeTool*)obj) -#define INK_IS_NODE_TOOL(obj) (dynamic_cast<const InkNodeTool*>((const SPEventContext*)obj)) - namespace Inkscape { + namespace Display { + class TemporaryItem; + } + + namespace UI { + class MultiPathManipulator; + class ControlPointSelection; + class Selector; + class ControlPoint; -namespace Display { -class TemporaryItem; -} // namespace Display -namespace UI { -class MultiPathManipulator; -class ControlPointSelection; -class Selector; -struct PathSharedData; -class ControlPoint; -} // namespace UI -} // namespace Inkscape + struct PathSharedData; + } +} + +#define INK_NODE_TOOL(obj) ((InkNodeTool*)obj) +#define INK_IS_NODE_TOOL(obj) (dynamic_cast<const InkNodeTool*>((const SPEventContext*)obj)) class InkNodeTool : public SPEventContext { public: @@ -47,8 +48,8 @@ public: virtual void setup(); virtual void set(const Inkscape::Preferences::Entry& val); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); + virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index 291e19016..ecb9df4c4 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -373,7 +373,7 @@ static void gr_tb_selection_changed(Inkscape::Selection * /*selection*/, gpointe Inkscape::Selection *selection = sp_desktop_selection(desktop); // take from desktop, not from args if (selection) { - SPEventContext *ev = sp_desktop_event_context(desktop); + SPEventContext *ev = desktop->getEventContext(); GrDrag *drag = NULL; if (ev) { drag = ev->get_drag(); @@ -585,7 +585,7 @@ static void gr_add_stop(GtkWidget * /*button*/, GtkWidget *vb) return; } - SPEventContext *ev = sp_desktop_event_context(desktop); + SPEventContext *ev = desktop->getEventContext(); SPGradientContext *rc = SP_GRADIENT_CONTEXT(ev); if (rc) { @@ -607,7 +607,7 @@ static void gr_remove_stop(GtkWidget * /*button*/, GtkWidget *vb) return; } - SPEventContext *ev = sp_desktop_event_context(desktop); + SPEventContext *ev = desktop->getEventContext(); GrDrag *drag = NULL; if (ev) { drag = ev->get_drag(); @@ -939,7 +939,7 @@ static void gr_gradient_combo_changed(EgeSelectOneAction *act, gpointer data) SPDesktop *desktop = static_cast<SPDesktop *>(data); Inkscape::Selection *selection = sp_desktop_selection(desktop); - SPEventContext *ev = sp_desktop_event_context(desktop); + SPEventContext *ev = desktop->getEventContext(); gr_apply_gradient(selection, ev? ev->get_drag() : NULL, gr); @@ -981,7 +981,7 @@ static void gr_stop_combo_changed(GtkComboBox * /*widget*/, GtkWidget *data) } SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(G_OBJECT(data), "desktop")); - SPEventContext *ev = sp_desktop_event_context(desktop); + SPEventContext *ev = desktop->getEventContext(); SPGradient *gr = gr_get_selected_gradient(data); select_drag_by_stop(data, gr, ev); diff --git a/src/zoom-context.cpp b/src/zoom-context.cpp index 99577648f..6efc122f7 100644 --- a/src/zoom-context.cpp +++ b/src/zoom-context.cpp @@ -25,12 +25,6 @@ #include "selection-chemistry.h" #include "zoom-context.h" - -//static gint xp = 0, yp = 0; // where drag started -//static gint tolerance = 0; -//static bool within_tolerance = false; -static bool escaped; - #include "tool-factory.h" namespace { @@ -52,6 +46,7 @@ SPZoomContext::SPZoomContext() : SPEventContext() { this->cursor_shape = cursor_zoom_xpm; this->hot_x = 6; this->hot_y = 6; + this->escaped = false; } SPZoomContext::~SPZoomContext() { @@ -80,21 +75,13 @@ void SPZoomContext::setup() { SPEventContext::setup(); } -//gint SPZoomContext::item_handler(SPItem* item, GdkEvent* event) { -// gint ret = FALSE; -// -// ret = SPEventContext::item_handler(item, event); -// -// return ret; -//} - -gint SPZoomContext::root_handler(GdkEvent* event) { +bool SPZoomContext::root_handler(GdkEvent* event) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); double const zoom_inc = prefs->getDoubleLimited("/options/zoomincrement/value", M_SQRT2, 1.01, 10); - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -112,14 +99,14 @@ gint SPZoomContext::root_handler(GdkEvent* event) { escaped = false; - ret = TRUE; + ret = true; } else if (event->button.button == 3) { double const zoom_rel( (event->button.state & GDK_SHIFT_MASK) ? zoom_inc : 1 / zoom_inc ); desktop->zoom_relative_keep_point(button_dt, zoom_rel); - ret = TRUE; + ret = true; } sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), @@ -132,7 +119,7 @@ gint SPZoomContext::root_handler(GdkEvent* event) { case GDK_MOTION_NOTIFY: if ((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) { - ret = TRUE; + ret = true; if ( within_tolerance && ( abs( (gint) event->motion.x - xp ) < tolerance ) @@ -169,7 +156,7 @@ gint SPZoomContext::root_handler(GdkEvent* event) { desktop->zoom_relative_keep_point(button_dt, zoom_rel); } - ret = TRUE; + ret = true; } Inkscape::Rubberband::get(desktop)->stop(); @@ -193,7 +180,7 @@ gint SPZoomContext::root_handler(GdkEvent* event) { Inkscape::Rubberband::get(desktop)->stop(); xp = yp = 0; escaped = true; - ret = TRUE; + ret = true; break; case GDK_KEY_Up: @@ -202,13 +189,13 @@ gint SPZoomContext::root_handler(GdkEvent* event) { case GDK_KEY_KP_Down: // prevent the zoom field from activation if (!MOD__CTRL_ONLY(event)) - ret = TRUE; + ret = true; break; case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: this->cursor_shape = cursor_zoom_out_xpm; - sp_event_context_update_cursor(this); + this->sp_event_context_update_cursor(); break; case GDK_KEY_Delete: @@ -226,7 +213,7 @@ gint SPZoomContext::root_handler(GdkEvent* event) { case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: this->cursor_shape = cursor_zoom_xpm; - sp_event_context_update_cursor(this); + this->sp_event_context_update_cursor(); break; default: break; diff --git a/src/zoom-context.h b/src/zoom-context.h index f5f2145b1..b5d022e5e 100644 --- a/src/zoom-context.h +++ b/src/zoom-context.h @@ -23,17 +23,17 @@ public: SPZoomContext(); virtual ~SPZoomContext(); - //SPEventContext event_context; - SPCanvasItem *grabbed; - static const std::string prefsPath; virtual void setup(); virtual void finish(); - virtual gint root_handler(GdkEvent* event); - //virtual gint item_handler(SPItem* item, GdkEvent* event); + virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); + +private: + SPCanvasItem *grabbed; + bool escaped; }; #endif |
