From 3545be745454076f11970b98d39e5004b3380f40 Mon Sep 17 00:00:00 2001 From: cilix42 Date: Fri, 15 Aug 2008 19:53:10 +0000 Subject: [PATCH] Eliminate more of SP_ACTIVE_DESKTOP --- src/dyna-draw-context.cpp | 20 +++---- src/eraser-context.cpp | 2 +- src/flood-context.cpp | 2 +- src/splivarot.cpp | 108 +++++++++++++++++--------------------- src/splivarot.h | 40 +++++++------- src/tweak-context.cpp | 2 +- src/verbs.cpp | 32 +++++------ 7 files changed, 98 insertions(+), 108 deletions(-) diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp index c56ba7a4c..e29865ff6 100644 --- a/src/dyna-draw-context.cpp +++ b/src/dyna-draw-context.cpp @@ -990,7 +990,7 @@ set_to_accumulated(SPDynaDrawContext *dc, bool unionize) if (unionize) { sp_desktop_selection(desktop)->add(dc->repr); - sp_selected_path_union_skip_undo(); + sp_selected_path_union_skip_undo(desktop); } else { if (dc->keep_selected) { sp_desktop_selection(desktop)->set(dc->repr); @@ -1093,7 +1093,9 @@ static double square(double const x) static void fit_and_split(SPDynaDrawContext *dc, gboolean release) { - double const tolerance_sq = square( NR::expansion(SP_EVENT_CONTEXT(dc)->desktop->w2d()) * TOLERANCE_CALLIGRAPHIC ); + SPDesktop *desktop = SP_EVENT_CONTEXT(dc)->desktop; + + double const tolerance_sq = square( NR::expansion(desktop->w2d()) * TOLERANCE_CALLIGRAPHIC ); #ifdef DYNA_DRAW_VERBOSE g_print("[F&S:R=%c]", release?'T':'F'); @@ -1186,24 +1188,24 @@ fit_and_split(SPDynaDrawContext *dc, gboolean release) if (!release) { g_assert(!dc->currentcurve->is_empty()); - SPCanvasItem *cbp = sp_canvas_item_new(sp_desktop_sketch(SP_EVENT_CONTEXT(dc)->desktop), + SPCanvasItem *cbp = sp_canvas_item_new(sp_desktop_sketch(desktop), SP_TYPE_CANVAS_BPATH, NULL); SPCurve *curve = dc->currentcurve->copy(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH (cbp), curve); curve->unref(); - guint32 fillColor = sp_desktop_get_color_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", true); - //guint32 strokeColor = sp_desktop_get_color_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", false); - double opacity = sp_desktop_get_master_opacity_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic"); - double fillOpacity = sp_desktop_get_opacity_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", true); - //double strokeOpacity = sp_desktop_get_opacity_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", false); + guint32 fillColor = sp_desktop_get_color_tool (desktop, "tools.calligraphic", true); + //guint32 strokeColor = sp_desktop_get_color_tool (desktop, "tools.calligraphic", false); + double opacity = sp_desktop_get_master_opacity_tool (desktop, "tools.calligraphic"); + double fillOpacity = sp_desktop_get_opacity_tool (desktop, "tools.calligraphic", true); + //double strokeOpacity = sp_desktop_get_opacity_tool (desktop, "tools.calligraphic", false); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cbp), ((fillColor & 0xffffff00) | SP_COLOR_F_TO_U(opacity*fillOpacity)), SP_WIND_RULE_EVENODD); //on second thougtht don't do stroke yet because we don't have stoke-width yet and because stoke appears between segments while drawing //sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cbp), ((strokeColor & 0xffffff00) | SP_COLOR_F_TO_U(opacity*strokeOpacity)), 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cbp), 0x00000000, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); /* fixme: Cannot we cascade it to root more clearly? */ - g_signal_connect(G_OBJECT(cbp), "event", G_CALLBACK(sp_desktop_root_handler), SP_EVENT_CONTEXT(dc)->desktop); + g_signal_connect(G_OBJECT(cbp), "event", G_CALLBACK(sp_desktop_root_handler), desktop); dc->segments = g_slist_prepend(dc->segments, cbp); } diff --git a/src/eraser-context.cpp b/src/eraser-context.cpp index bec3326d6..ccbb87790 100644 --- a/src/eraser-context.cpp +++ b/src/eraser-context.cpp @@ -771,7 +771,7 @@ set_to_accumulated(SPEraserContext *dc) selection->set(item); selection->add(dup); - sp_selected_path_diff_skip_undo(); + sp_selected_path_diff_skip_undo(desktop); workDone = true; // TODO set this only if something was cut. if ( !selection->isEmpty() ) { // If the item was not completely erased, track the new remainder. diff --git a/src/flood-context.cpp b/src/flood-context.cpp index a9ca7073f..1057fd4be 100644 --- a/src/flood-context.cpp +++ b/src/flood-context.cpp @@ -530,7 +530,7 @@ static void do_trace(bitmap_coords_info bci, guchar *trace_px, SPDesktop *deskto if (union_with_selection) { desktop->messageStack()->flashF(Inkscape::WARNING_MESSAGE, ngettext("Area filled, path with %d node created and unioned with selection.","Area filled, path with %d nodes created and unioned with selection.",sp_nodes_in_path(SP_PATH(reprobj))), sp_nodes_in_path(SP_PATH(reprobj))); selection->add(reprobj); - sp_selected_path_union_skip_undo(); + sp_selected_path_union_skip_undo(desktop); } else { desktop->messageStack()->flashF(Inkscape::WARNING_MESSAGE, ngettext("Area filled, path with %d node created.","Area filled, path with %d nodes created.",sp_nodes_in_path(SP_PATH(reprobj))), sp_nodes_in_path(SP_PATH(reprobj))); selection->set(reprobj); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index e66bc6a68..77675000f 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -33,7 +33,6 @@ #include "text-editing.h" #include "sp-item-group.h" #include "style.h" -#include "inkscape.h" #include "document.h" #include "message-stack.h" #include "selection.h" @@ -63,64 +62,62 @@ bool Ancetre(Inkscape::XML::Node *a, Inkscape::XML::Node *who); -void sp_selected_path_boolop(bool_op bop, const unsigned int verb=SP_VERB_NONE, const Glib::ustring description=""); -void sp_selected_path_do_offset(bool expand, double prefOffset); -void sp_selected_path_create_offset_object(int expand, bool updating); +void sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb=SP_VERB_NONE, const Glib::ustring description=""); +void sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset); +void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updating); void -sp_selected_path_union() +sp_selected_path_union(SPDesktop *desktop) { - sp_selected_path_boolop(bool_op_union, SP_VERB_SELECTION_UNION, _("Union")); + sp_selected_path_boolop(desktop, bool_op_union, SP_VERB_SELECTION_UNION, _("Union")); } void -sp_selected_path_union_skip_undo() +sp_selected_path_union_skip_undo(SPDesktop *desktop) { - sp_selected_path_boolop(bool_op_union, SP_VERB_NONE, _("Union")); + sp_selected_path_boolop(desktop, bool_op_union, SP_VERB_NONE, _("Union")); } void -sp_selected_path_intersect() +sp_selected_path_intersect(SPDesktop *desktop) { - sp_selected_path_boolop(bool_op_inters, SP_VERB_SELECTION_INTERSECT, _("Intersection")); + sp_selected_path_boolop(desktop, bool_op_inters, SP_VERB_SELECTION_INTERSECT, _("Intersection")); } void -sp_selected_path_diff() +sp_selected_path_diff(SPDesktop *desktop) { - sp_selected_path_boolop(bool_op_diff, SP_VERB_SELECTION_DIFF, _("Difference")); + sp_selected_path_boolop(desktop, bool_op_diff, SP_VERB_SELECTION_DIFF, _("Difference")); } void -sp_selected_path_diff_skip_undo() +sp_selected_path_diff_skip_undo(SPDesktop *desktop) { - sp_selected_path_boolop(bool_op_diff, SP_VERB_NONE, _("Difference")); + sp_selected_path_boolop(desktop, bool_op_diff, SP_VERB_NONE, _("Difference")); } void -sp_selected_path_symdiff() +sp_selected_path_symdiff(SPDesktop *desktop) { - sp_selected_path_boolop(bool_op_symdiff, SP_VERB_SELECTION_SYMDIFF, _("Exclusion")); + sp_selected_path_boolop(desktop, bool_op_symdiff, SP_VERB_SELECTION_SYMDIFF, _("Exclusion")); } void -sp_selected_path_cut() +sp_selected_path_cut(SPDesktop *desktop) { - sp_selected_path_boolop(bool_op_cut, SP_VERB_SELECTION_CUT, _("Division")); + sp_selected_path_boolop(desktop, bool_op_cut, SP_VERB_SELECTION_CUT, _("Division")); } void -sp_selected_path_slice() +sp_selected_path_slice(SPDesktop *desktop) { - sp_selected_path_boolop(bool_op_slice, SP_VERB_SELECTION_SLICE, _("Cut path")); + sp_selected_path_boolop(desktop, bool_op_slice, SP_VERB_SELECTION_SLICE, _("Cut path")); } // boolean operations // take the source paths from the file, do the operation, delete the originals and add the results void -sp_selected_path_boolop(bool_op bop, const unsigned int verb, const Glib::ustring description) +sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb, const Glib::ustring description) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::Selection *selection = sp_desktop_selection(desktop); GSList *il = (GSList *) selection->itemList(); @@ -625,10 +622,8 @@ void sp_selected_path_outline_add_marker( SPObject *marker_object, Geom::Matrix } void -sp_selected_path_outline() +sp_selected_path_outline(SPDesktop *desktop) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::Selection *selection = sp_desktop_selection(desktop); if (selection->isEmpty()) { @@ -937,78 +932,75 @@ sp_selected_path_outline() void -sp_selected_path_offset() +sp_selected_path_offset(SPDesktop *desktop) { double prefOffset = prefs_get_double_attribute("options.defaultoffsetwidth", "value", 1.0); - sp_selected_path_do_offset(true, prefOffset); + sp_selected_path_do_offset(desktop, true, prefOffset); } void -sp_selected_path_inset() +sp_selected_path_inset(SPDesktop *desktop) { double prefOffset = prefs_get_double_attribute("options.defaultoffsetwidth", "value", 1.0); - sp_selected_path_do_offset(false, prefOffset); + sp_selected_path_do_offset(desktop, false, prefOffset); } void -sp_selected_path_offset_screen(double pixels) +sp_selected_path_offset_screen(SPDesktop *desktop, double pixels) { - sp_selected_path_do_offset(true, pixels / SP_ACTIVE_DESKTOP->current_zoom()); + sp_selected_path_do_offset(desktop, true, pixels / desktop->current_zoom()); } void -sp_selected_path_inset_screen(double pixels) +sp_selected_path_inset_screen(SPDesktop *desktop, double pixels) { - sp_selected_path_do_offset(false, pixels / SP_ACTIVE_DESKTOP->current_zoom()); + sp_selected_path_do_offset(desktop, false, pixels / desktop->current_zoom()); } -void sp_selected_path_create_offset_object_zero() +void sp_selected_path_create_offset_object_zero(SPDesktop *desktop) { - sp_selected_path_create_offset_object(0, false); + sp_selected_path_create_offset_object(desktop, 0, false); } -void sp_selected_path_create_offset() +void sp_selected_path_create_offset(SPDesktop *desktop) { - sp_selected_path_create_offset_object(1, false); + sp_selected_path_create_offset_object(desktop, 1, false); } -void sp_selected_path_create_inset() +void sp_selected_path_create_inset(SPDesktop *desktop) { - sp_selected_path_create_offset_object(-1, false); + sp_selected_path_create_offset_object(desktop, -1, false); } -void sp_selected_path_create_updating_offset_object_zero() +void sp_selected_path_create_updating_offset_object_zero(SPDesktop *desktop) { - sp_selected_path_create_offset_object(0, true); + sp_selected_path_create_offset_object(desktop, 0, true); } -void sp_selected_path_create_updating_offset() +void sp_selected_path_create_updating_offset(SPDesktop *desktop) { - sp_selected_path_create_offset_object(1, true); + sp_selected_path_create_offset_object(desktop, 1, true); } -void sp_selected_path_create_updating_inset() +void sp_selected_path_create_updating_inset(SPDesktop *desktop) { - sp_selected_path_create_offset_object(-1, true); + sp_selected_path_create_offset_object(desktop, -1, true); } void -sp_selected_path_create_offset_object(int expand, bool updating) +sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updating) { Inkscape::Selection *selection; Inkscape::XML::Node *repr; SPItem *item; SPCurve *curve; gchar *style, *str; - SPDesktop *desktop; float o_width, o_miter; JoinType o_join; ButtType o_butt; curve = NULL; - desktop = SP_ACTIVE_DESKTOP; - selection = sp_desktop_selection(desktop); item = selection->singleItem(); @@ -1224,10 +1216,8 @@ sp_selected_path_create_offset_object(int expand, bool updating) void -sp_selected_path_do_offset(bool expand, double prefOffset) +sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::Selection *selection = sp_desktop_selection(desktop); if (selection->isEmpty()) { @@ -1669,11 +1659,9 @@ sp_selected_path_simplify_items(SPDesktop *desktop, } void -sp_selected_path_simplify_selection(float threshold, bool justCoalesce, - float angleLimit, bool breakableAngles) +sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool justCoalesce, + float angleLimit, bool breakableAngles) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::Selection *selection = sp_desktop_selection(desktop); if (selection->isEmpty()) { @@ -1704,7 +1692,7 @@ static double previousTime = 0.0; static gdouble simplifyMultiply = 1.0; void -sp_selected_path_simplify(void) +sp_selected_path_simplify(SPDesktop *desktop) { gdouble simplifyThreshold = prefs_get_double_attribute("options.simplifythreshold", "value", 0.003); @@ -1735,8 +1723,8 @@ sp_selected_path_simplify(void) //g_print("%g\n", simplify_threshold); //Make the actual call - sp_selected_path_simplify_selection(simplifyThreshold, - simplifyJustCoalesce, 0.0, false); + sp_selected_path_simplify_selection(desktop, simplifyThreshold, + simplifyJustCoalesce, 0.0, false); } diff --git a/src/splivarot.h b/src/splivarot.h index ad4d9c6e0..755beaa80 100644 --- a/src/splivarot.h +++ b/src/splivarot.h @@ -16,36 +16,36 @@ struct SPItem; // boolean operations // work on the current selection // selection has 2 contain exactly 2 items -void sp_selected_path_union (); -void sp_selected_path_union_skip_undo (); -void sp_selected_path_intersect (); -void sp_selected_path_diff (); -void sp_selected_path_diff_skip_undo (); -void sp_selected_path_symdiff (); -void sp_selected_path_cut (); -void sp_selected_path_slice (); +void sp_selected_path_union (SPDesktop *desktop); +void sp_selected_path_union_skip_undo (SPDesktop *desktop); +void sp_selected_path_intersect (SPDesktop *desktop); +void sp_selected_path_diff (SPDesktop *desktop); +void sp_selected_path_diff_skip_undo (SPDesktop *desktop); +void sp_selected_path_symdiff (SPDesktop *desktop); +void sp_selected_path_cut (SPDesktop *desktop); +void sp_selected_path_slice (SPDesktop *desktop); // offset/inset of a curve // takes the fill-rule in consideration // offset amount is the stroke-width of the curve -void sp_selected_path_offset (); -void sp_selected_path_offset_screen (double pixels); -void sp_selected_path_inset (); -void sp_selected_path_inset_screen (double pixels); -void sp_selected_path_create_offset (); -void sp_selected_path_create_inset (); -void sp_selected_path_create_updating_offset (); -void sp_selected_path_create_updating_inset (); +void sp_selected_path_offset (SPDesktop *desktop); +void sp_selected_path_offset_screen (SPDesktop *desktop, double pixels); +void sp_selected_path_inset (SPDesktop *desktop); +void sp_selected_path_inset_screen (SPDesktop *desktop, double pixels); +void sp_selected_path_create_offset (SPDesktop *desktop); +void sp_selected_path_create_inset (SPDesktop *desktop); +void sp_selected_path_create_updating_offset (SPDesktop *desktop); +void sp_selected_path_create_updating_inset (SPDesktop *desktop); -void sp_selected_path_create_offset_object_zero (); -void sp_selected_path_create_updating_offset_object_zero (); +void sp_selected_path_create_offset_object_zero (SPDesktop *desktop); +void sp_selected_path_create_updating_offset_object_zero (SPDesktop *desktop); // outline of a curve // uses the stroke-width -void sp_selected_path_outline (); +void sp_selected_path_outline (SPDesktop *desktop); // simplifies a path (removes small segments and the like) -void sp_selected_path_simplify (); +void sp_selected_path_simplify (SPDesktop *desktop); Path *Path_for_item(SPItem *item, bool doTransformation, bool transformFull = true); Geom::PathVector* pathvector_for_curve(SPItem *item, SPCurve *curve, bool doTransformation, bool transformFull, Geom::Matrix extraPreAffine, Geom::Matrix extraPostAffine); diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp index 86d7e6da2..9c6981128 100644 --- a/src/tweak-context.cpp +++ b/src/tweak-context.cpp @@ -444,7 +444,7 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, NR::Poi double th_max = (0.6 - 0.59*sqrt(fidelity)) / NR::expansion(i2doc); double threshold = MAX(th_max, th_max*force); res->ConvertEvenLines(threshold); - res->Simplify(threshold / (SP_ACTIVE_DESKTOP->current_zoom())); + res->Simplify(threshold / (selection->desktop()->current_zoom())); if (newrepr) { // converting to path, need to replace the repr bool is_selected = selection->includes(item); diff --git a/src/verbs.cpp b/src/verbs.cpp index cacb0fa07..5947ac2cf 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1031,57 +1031,57 @@ SelectionVerb::perform(SPAction *action, void *data, void */*pdata*/) break; case SP_VERB_SELECTION_UNION: - sp_selected_path_union(); + sp_selected_path_union(dt); break; case SP_VERB_SELECTION_INTERSECT: - sp_selected_path_intersect(); + sp_selected_path_intersect(dt); break; case SP_VERB_SELECTION_DIFF: - sp_selected_path_diff(); + sp_selected_path_diff(dt); break; case SP_VERB_SELECTION_SYMDIFF: - sp_selected_path_symdiff(); + sp_selected_path_symdiff(dt); break; case SP_VERB_SELECTION_CUT: - sp_selected_path_cut(); + sp_selected_path_cut(dt); break; case SP_VERB_SELECTION_SLICE: - sp_selected_path_slice(); + sp_selected_path_slice(dt); break; case SP_VERB_SELECTION_OFFSET: - sp_selected_path_offset(); + sp_selected_path_offset(dt); break; case SP_VERB_SELECTION_OFFSET_SCREEN: - sp_selected_path_offset_screen(1); + sp_selected_path_offset_screen(dt, 1); break; case SP_VERB_SELECTION_OFFSET_SCREEN_10: - sp_selected_path_offset_screen(10); + sp_selected_path_offset_screen(dt, 10); break; case SP_VERB_SELECTION_INSET: - sp_selected_path_inset(); + sp_selected_path_inset(dt); break; case SP_VERB_SELECTION_INSET_SCREEN: - sp_selected_path_inset_screen(1); + sp_selected_path_inset_screen(dt, 1); break; case SP_VERB_SELECTION_INSET_SCREEN_10: - sp_selected_path_inset_screen(10); + sp_selected_path_inset_screen(dt, 10); break; case SP_VERB_SELECTION_DYNAMIC_OFFSET: - sp_selected_path_create_offset_object_zero(); + sp_selected_path_create_offset_object_zero(dt); tools_switch_current(TOOLS_NODES); break; case SP_VERB_SELECTION_LINKED_OFFSET: - sp_selected_path_create_updating_offset_object_zero(); + sp_selected_path_create_updating_offset_object_zero(dt); tools_switch_current(TOOLS_NODES); break; case SP_VERB_SELECTION_OUTLINE: - sp_selected_path_outline(); + sp_selected_path_outline(dt); break; case SP_VERB_SELECTION_SIMPLIFY: - sp_selected_path_simplify(); + sp_selected_path_simplify(dt); break; case SP_VERB_SELECTION_REVERSE: sp_selected_path_reverse(dt); -- 2.30.2