From 3c37a2f5b4779c78ff90f6194dcb5b32244306f3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 13 Apr 2015 23:01:49 +0200 Subject: Fix for the bug 1443039. Now reset old perspective-envelope effects and prevent crash, also when all handles go to the same position Fixed bugs: - https://launchpad.net/bugs/1443039 (bzr r14056) --- src/live_effects/lpe-perspective-envelope.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index 4eac2d6eb..fc59fb333 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -63,6 +63,13 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) { using Geom::X; using Geom::Y; + if(are_near(up_left_point, up_right_point) && + are_near(up_right_point, down_left_point) && + are_near(down_left_point, down_right_point)) { + g_warning("Perspective/Envelope LPE::doBeforeEffect - lpeobj with invalid parameter, the same value in 4 handles!"); + resetGrid(); + return; + } double projmatrix[3][3]; if(deform_type == DEFORMATION_PERSPECTIVE) { std::vector handles(4); -- cgit v1.2.3 From 0f8b775f3a02380dd593ae58ad3b989f58aec643 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 14 Apr 2015 14:44:34 +0200 Subject: Replace GList by std::vector (bzr r14057) --- src/ui/tools/flood-tool.cpp | 54 +++++++++++++++---------------------- src/ui/tools/flood-tool.h | 6 ++--- src/widgets/paintbucket-toolbar.cpp | 21 +++++++-------- 3 files changed, 34 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/ui/tools/flood-tool.cpp b/src/ui/tools/flood-tool.cpp index bb8782dfa..ffd41d97d 100644 --- a/src/ui/tools/flood-tool.cpp +++ b/src/ui/tools/flood-tool.cpp @@ -84,6 +84,28 @@ const std::string& FloodTool::getPrefsPath() { const std::string FloodTool::prefsPath = "/tools/paintbucket"; +// TODO: Replace by C++11 initialization +// Must match PaintBucketChannels enum +Glib::ustring ch_init[8] = { + _("Visible Colors"), + _("Red"), + _("Green"), + _("Blue"), + _("Hue"), + _("Saturation"), + _("Lightness"), + _("Alpha"), +}; +const std::vector FloodTool::channel_list( ch_init, ch_init+8 ); + +Glib::ustring gap_init[4] = { + C_("Flood autogap", "None"), + C_("Flood autogap", "Small"), + C_("Flood autogap", "Medium"), + C_("Flood autogap", "Large") +}; +const std::vector FloodTool::gap_list( gap_init, gap_init+4 ); + FloodTool::FloodTool() : ToolBase(cursor_paintbucket_xpm, 11, 30) , item(NULL) @@ -173,38 +195,6 @@ inline unsigned char * get_trace_pixel(guchar *trace_px, int x, int y, int width return trace_px + (x + y * width); } -/** - * Generate the list of trace channel selection entries. - */ -GList * flood_channels_dropdown_items_list() { - GList *glist = NULL; - - glist = g_list_append (glist, _("Visible Colors")); - glist = g_list_append (glist, _("Red")); - glist = g_list_append (glist, _("Green")); - glist = g_list_append (glist, _("Blue")); - glist = g_list_append (glist, _("Hue")); - glist = g_list_append (glist, _("Saturation")); - glist = g_list_append (glist, _("Lightness")); - glist = g_list_append (glist, _("Alpha")); - - return glist; -} - -/** - * Generate the list of autogap selection entries. - */ -GList * flood_autogap_dropdown_items_list() { - GList *glist = NULL; - - glist = g_list_append (glist, (void*) C_("Flood autogap", "None")); - glist = g_list_append (glist, (void*) C_("Flood autogap", "Small")); - glist = g_list_append (glist, (void*) C_("Flood autogap", "Medium")); - glist = g_list_append (glist, (void*) C_("Flood autogap", "Large")); - - return glist; -} - /** * Compare a pixel in a pixel buffer with another pixel to determine if a point should be included in the fill operation. * @param check The pixel in the pixel buffer to check. diff --git a/src/ui/tools/flood-tool.h b/src/ui/tools/flood-tool.h index 5104a42e9..100875f22 100644 --- a/src/ui/tools/flood-tool.h +++ b/src/ui/tools/flood-tool.h @@ -13,6 +13,7 @@ #include #include "ui/tools/tool-base.h" +#include #define SP_FLOOD_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_FLOOD_CONTEXT(obj) (dynamic_cast((const Inkscape::UI::Tools::ToolBase*)obj) != NULL) @@ -39,15 +40,14 @@ public: virtual const std::string& getPrefsPath(); static void set_channels(gint channels); + static const std::vector channel_list; + static const std::vector gap_list; private: void selection_changed(Inkscape::Selection* selection); void finishItem(); }; -GList* flood_channels_dropdown_items_list (void); -GList* flood_autogap_dropdown_items_list (void); - enum PaintBucketChannels { FLOOD_CHANNELS_RGB, FLOOD_CHANNELS_R, diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp index d8edeb9f6..eb55287c4 100644 --- a/src/widgets/paintbucket-toolbar.cpp +++ b/src/widgets/paintbucket-toolbar.cpp @@ -121,17 +121,16 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions { GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT ); - GList* items = 0; gint count = 0; - for ( items = Inkscape::UI::Tools::flood_channels_dropdown_items_list(); items ; items = g_list_next(items) ) - { + const std::vector& channel_list = Inkscape::UI::Tools::FloodTool::channel_list; + for (std::vector::const_iterator iterator = channel_list.begin(); + iterator != channel_list.end(); ++iterator ) { GtkTreeIter iter; gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, reinterpret_cast(items->data), 1, count, -1 ); + gtk_list_store_set( model, &iter, 0, (*iterator).c_str(), 1, count, -1 ); count++; } - g_list_free( items ); - items = 0; + EgeSelectOneAction* act1 = ege_select_one_action_new( "ChannelsAction", _("Fill by"), (""), NULL, GTK_TREE_MODEL(model) ); g_object_set( act1, "short_label", _("Fill by:"), NULL ); ege_select_one_action_set_appearance( act1, "compact" ); @@ -188,17 +187,15 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions { GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT ); - GList* items = 0; gint count = 0; - for ( items = Inkscape::UI::Tools::flood_autogap_dropdown_items_list(); items ; items = g_list_next(items) ) - { + const std::vector& gap_list = Inkscape::UI::Tools::FloodTool::gap_list; + for (std::vector::const_iterator iterator = gap_list.begin(); + iterator != gap_list.end(); ++iterator ) { GtkTreeIter iter; gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, reinterpret_cast(items->data), 1, count, -1 ); + gtk_list_store_set( model, &iter, 0, (*iterator).c_str(), 1, count, -1 ); count++; } - g_list_free( items ); - items = 0; EgeSelectOneAction* act2 = ege_select_one_action_new( "AutoGapAction", _("Close gaps"), (""), NULL, GTK_TREE_MODEL(model) ); g_object_set( act2, "short_label", _("Close gaps:"), NULL ); ege_select_one_action_set_appearance( act2, "compact" ); -- cgit v1.2.3 From f752dab8b460b9ca069d444930f65b3d41f67695 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 21 Apr 2015 19:46:29 +0200 Subject: Add mirror symmetry to envelope/perspective LPE (bzr r14058) --- src/live_effects/lpe-perspective-envelope.cpp | 57 ++++++++++++++++++++++++++- src/live_effects/lpe-perspective-envelope.h | 6 +++ 2 files changed, 62 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index fc59fb333..08100bb2d 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -40,7 +40,8 @@ static const Util::EnumDataConverter DeformationTypeConverter(Deformat LPEPerspectiveEnvelope::LPEPerspectiveEnvelope(LivePathEffectObject *lpeobject) : Effect(lpeobject), - // initialise your parameters here: + horizontal_mirror(_("Mirror movements in horizontal"), _("Mirror movements in horizontal"), "horizontal_mirror", &wr, this, false), + vertical_mirror(_("Mirror movements in vertical"), _("Mirror movements in vertical"), "vertical_mirror", &wr, this, false), deform_type(_("Type"), _("Select the type of deformation"), "deform_type", DeformationTypeConverter, &wr, this, DEFORMATION_PERSPECTIVE), up_left_point(_("Top Left"), _("Top Left - Ctrl+Alt+Click: reset, Ctrl: move along axes"), "up_left_point", &wr, this), up_right_point(_("Top Right"), _("Top Right - Ctrl+Alt+Click: reset, Ctrl: move along axes"), "up_right_point", &wr, this), @@ -49,6 +50,8 @@ LPEPerspectiveEnvelope::LPEPerspectiveEnvelope(LivePathEffectObject *lpeobject) { // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter(&deform_type); + registerParameter(&horizontal_mirror); + registerParameter(&vertical_mirror); registerParameter(&up_left_point); registerParameter(&up_right_point); registerParameter(&down_left_point); @@ -312,10 +315,62 @@ LPEPerspectiveEnvelope::newWidget() return dynamic_cast(vbox); } +void +LPEPerspectiveEnvelope::vertical(PointParam ¶m_one, PointParam ¶m_two, Geom::Line vert) +{ + Geom::Point A = param_one; + Geom::Point B = param_two; + double Y = (A[Geom::Y] + B[Geom::Y])/2; + A[Geom::Y] = Y; + B[Geom::Y] = Y; + Geom::Point nearest = vert.pointAt(vert.nearestPoint(A)); + double distance_one = Geom::distance(A,nearest); + double distance_two = Geom::distance(B,nearest); + double distance_middle = (distance_one + distance_two)/2; + if(A[Geom::X] > B[Geom::X]) { + distance_middle *= -1; + } + A[Geom::X] = nearest[Geom::X] - distance_middle; + B[Geom::X] = nearest[Geom::X] + distance_middle; + param_one.param_setValue(A, true); + param_two.param_setValue(B, true); +} + +void +LPEPerspectiveEnvelope::horizontal(PointParam ¶m_one, PointParam ¶m_two, Geom::Line horiz) +{ + Geom::Point A = param_one; + Geom::Point B = param_two; + double X = (A[Geom::X] + B[Geom::X])/2; + A[Geom::X] = X; + B[Geom::X] = X; + Geom::Point nearest = horiz.pointAt(horiz.nearestPoint(A)); + double distance_one = Geom::distance(A,nearest); + double distance_two = Geom::distance(B,nearest); + double distance_middle = (distance_one + distance_two)/2; + if(A[Geom::Y] > B[Geom::Y]) { + distance_middle *= -1; + } + A[Geom::Y] = nearest[Geom::Y] - distance_middle; + B[Geom::Y] = nearest[Geom::Y] + distance_middle; + param_one.param_setValue(A, true); + param_two.param_setValue(B, true); +} + void LPEPerspectiveEnvelope::doBeforeEffect (SPLPEItem const* lpeitem) { original_bbox(lpeitem); + Geom::Line vert(Geom::Point(boundingbox_X.middle(),boundingbox_Y.max()), Geom::Point(boundingbox_X.middle(), boundingbox_Y.min())); + Geom::Line horiz(Geom::Point(boundingbox_X.min(),boundingbox_Y.middle()), Geom::Point(boundingbox_X.max(), boundingbox_Y.middle())); + if(vertical_mirror) { + vertical(up_left_point, up_right_point,vert); + vertical(down_left_point, down_right_point,vert); + } + if(horizontal_mirror) { + horizontal(up_left_point, down_left_point,horiz); + horizontal(up_right_point, down_right_point,horiz); + } SPLPEItem * item = const_cast(lpeitem); item->apply_to_clippath(item); item->apply_to_mask(item); diff --git a/src/live_effects/lpe-perspective-envelope.h b/src/live_effects/lpe-perspective-envelope.h index e25f059a3..dd14dc212 100644 --- a/src/live_effects/lpe-perspective-envelope.h +++ b/src/live_effects/lpe-perspective-envelope.h @@ -42,6 +42,10 @@ public: virtual void resetDefaults(SPItem const* item); + virtual void vertical(PointParam ¶mA,PointParam ¶mB, Geom::Line vert); + + virtual void horizontal(PointParam ¶mA,PointParam ¶mB,Geom::Line horiz); + virtual void doBeforeEffect(SPLPEItem const* lpeitem); virtual Gtk::Widget * newWidget(); @@ -54,6 +58,8 @@ protected: void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); private: + BoolParam horizontal_mirror; + BoolParam vertical_mirror; EnumParam deform_type; PointParam up_left_point; PointParam up_right_point; -- cgit v1.2.3