From f873250f0c426d7b281acd37d65c4e549eb204a3 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Fri, 24 Jul 2015 21:38:06 +0200 Subject: Make persistence of snap indicator configurable, and clean up the snapping tab in the preferences dialog Fixed bugs: - https://launchpad.net/bugs/1420301 (bzr r14253) --- src/display/snap-indicator.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/display') diff --git a/src/display/snap-indicator.cpp b/src/display/snap-indicator.cpp index 926b35599..17deea16d 100644 --- a/src/display/snap-indicator.cpp +++ b/src/display/snap-indicator.cpp @@ -256,7 +256,12 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap "shape", SP_KNOT_SHAPE_CROSS, NULL ); - const int timeout_val = 4000; + double timeout_val = prefs->getDouble("/options/snapindicatorpersistence/value", 2.0); + if (timeout_val < 0.1) { + timeout_val = 0.1; // a zero value would mean infinite persistence (i.e. until new snap occurs) + // Besides, negatives values would ....? + } + // The snap indicator will be deleted after some time-out, and sp_canvas_item_dispose // will be called. This will set canvas->current_item to NULL if the snap indicator was @@ -272,7 +277,7 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap SP_CTRL(canvasitem)->pickable = false; SP_CTRL(canvasitem)->moveto(p.getPoint()); - _snaptarget = _desktop->add_temporary_canvasitem(canvasitem, timeout_val); + _snaptarget = _desktop->add_temporary_canvasitem(canvasitem, timeout_val*1000.0); _snaptarget_is_presnap = pre_snap; // Display the tooltip, which reveals the type of snap source and the type of snap target @@ -307,7 +312,7 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap SP_CANVASTEXT(canvas_tooltip)->anchor_position = TEXT_ANCHOR_CENTER; g_free(tooltip_str); - _snaptarget_tooltip = _desktop->add_temporary_canvasitem(canvas_tooltip, timeout_val); + _snaptarget_tooltip = _desktop->add_temporary_canvasitem(canvas_tooltip, timeout_val*1000.0); } // Display the bounding box, if we snapped to one -- cgit v1.2.3 From 2b6e2bc4e7541bcda149f8ed68c2e07336fb573e Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Mon, 17 Aug 2015 01:38:25 +0200 Subject: Fixes doubled transparency computation on bitmaps for some reason Fixed bugs: - https://launchpad.net/bugs/1434122 (bzr r14306) --- src/display/drawing-image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/display') diff --git a/src/display/drawing-image.cpp b/src/display/drawing-image.cpp index 1594614ac..2a943d16c 100644 --- a/src/display/drawing-image.cpp +++ b/src/display/drawing-image.cpp @@ -132,7 +132,7 @@ unsigned DrawingImage::_renderItem(DrawingContext &dc, Geom::IntRect const &/*ar } } - dc.paint(_opacity); + dc.paint(1); } else { // outline; draw a rect instead -- cgit v1.2.3 From 3005a32786badbc125628fd30f03ccdc32bb03d4 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 15 Sep 2015 12:13:14 +0200 Subject: Don't need bounding box if 'primitiveUnits' not 'objectBoundingBox'. (bzr r14368) --- src/display/nr-filter-primitive.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/display') diff --git a/src/display/nr-filter-primitive.cpp b/src/display/nr-filter-primitive.cpp index c8b569036..ea72efff0 100644 --- a/src/display/nr-filter-primitive.cpp +++ b/src/display/nr-filter-primitive.cpp @@ -110,17 +110,12 @@ void FilterPrimitive::set_subregion(SVGLength const &x, SVGLength const &y, Geom::Rect FilterPrimitive::filter_primitive_area(FilterUnits const &units) { - Geom::OptRect const bb_opt = units.get_item_bbox(); Geom::OptRect const fa_opt = units.get_filter_area(); - Geom::Rect bb; - Geom::Rect fa; - if (!bb_opt || !fa_opt) { + if (!fa_opt) { + std::cerr << "FilterPrimitive::filter_primitive_area: filter area undefined." << std::endl; return Geom::Rect (Geom::Point(0.,0.), Geom::Point(0.,0.)); - } else { - bb = *bb_opt; - fa = *fa_opt; } - + Geom::Rect fa = *fa_opt; // x, y, width, and height are independently defined (i.e. one can be defined, by default, to // the filter area (via default value ) while another is defined relative to the bounding @@ -138,6 +133,14 @@ Geom::Rect FilterPrimitive::filter_primitive_area(FilterUnits const &units) if( units.get_primitive_units() == SP_FILTER_UNITS_OBJECTBOUNDINGBOX ) { + Geom::OptRect const bb_opt = units.get_item_bbox(); + if (!bb_opt) { + std::cerr << "FilterPrimitive::filter_primitive_area: bounding box undefined and 'primitiveUnits' is 'objectBoundingBox'." << std::endl; + return Geom::Rect (Geom::Point(0.,0.), Geom::Point(0.,0.)); + } + Geom::Rect bb = *bb_opt; + + // Update computed values for ex, em, %. // For %, assumes primitive unit is objectBoundingBox. // TODO: fetch somehow the object ex and em lengths; 12, 6 are just dummy values. -- cgit v1.2.3 From 27ca90885f3f4dde9886780ff0cc0f40a34f4e7e Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 20 Sep 2015 15:54:59 +0200 Subject: Crude partial implementation of feTile filter primitive. (bzr r14377) --- src/display/nr-filter-image.cpp | 2 + src/display/nr-filter-offset.cpp | 4 +- src/display/nr-filter-slot.cpp | 21 +++++++++ src/display/nr-filter-slot.h | 8 ++++ src/display/nr-filter-tile.cpp | 99 ++++++++++++++++++++++++++++++++++++++-- src/display/nr-filter-tile.h | 1 + 6 files changed, 130 insertions(+), 5 deletions(-) (limited to 'src/display') diff --git a/src/display/nr-filter-image.cpp b/src/display/nr-filter-image.cpp index 179ba0e0a..af89d98e0 100644 --- a/src/display/nr-filter-image.cpp +++ b/src/display/nr-filter-image.cpp @@ -56,6 +56,8 @@ void FilterImage::render_cairo(FilterSlot &slot) // Note: viewport calculation in non-trivial. Do not rely // on get_matrix_primitiveunits2pb(). Geom::Rect vp = filter_primitive_area( slot.get_units() ); + slot.set_primitive_area(_output, vp); // Needed for tiling + double feImageX = vp.min()[Geom::X]; double feImageY = vp.min()[Geom::Y]; double feImageWidth = vp.width(); diff --git a/src/display/nr-filter-offset.cpp b/src/display/nr-filter-offset.cpp index af1081abe..93bab7d39 100644 --- a/src/display/nr-filter-offset.cpp +++ b/src/display/nr-filter-offset.cpp @@ -37,9 +37,11 @@ void FilterOffset::render_cairo(FilterSlot &slot) cairo_surface_t *out = ink_cairo_surface_create_identical(in); // color_interpolation_filters for out same as in. See spec (DisplacementMap). copy_cairo_surface_ci(in, out); - cairo_t *ct = cairo_create(out); + Geom::Rect vp = filter_primitive_area( slot.get_units() ); + slot.set_primitive_area(_output, vp); // Needed for tiling + // Handle bounding box case double x = dx; double y = dy; diff --git a/src/display/nr-filter-slot.cpp b/src/display/nr-filter-slot.cpp index e4c2f048e..a6e0c5c4e 100644 --- a/src/display/nr-filter-slot.cpp +++ b/src/display/nr-filter-slot.cpp @@ -232,6 +232,27 @@ void FilterSlot::set(int slot_nr, cairo_surface_t *surface) _last_out = slot_nr; } +void FilterSlot::set_primitive_area(int slot_nr, Geom::Rect &area) +{ + if (slot_nr == NR_FILTER_SLOT_NOT_SET) + slot_nr = NR_FILTER_UNNAMED_SLOT; + + _primitiveAreas[slot_nr] = area; +} + +Geom::Rect FilterSlot::get_primitive_area(int slot_nr) +{ + if (slot_nr == NR_FILTER_SLOT_NOT_SET) + slot_nr = _last_out; + + PrimitiveAreaMap::iterator s = _primitiveAreas.find(slot_nr); + + if (s == _primitiveAreas.end()) { + return *(_units.get_filter_area()); + } + return s->second; +} + int FilterSlot::get_slot_count() { return _slots.size(); diff --git a/src/display/nr-filter-slot.h b/src/display/nr-filter-slot.h index 987dedfd1..166b2e718 100644 --- a/src/display/nr-filter-slot.h +++ b/src/display/nr-filter-slot.h @@ -54,6 +54,9 @@ public: cairo_surface_t *get_result(int slot_nr); + void set_primitive_area(int slot, Geom::Rect &area); + Geom::Rect get_primitive_area(int slot); + /** Returns the number of slots in use. */ int get_slot_count(); @@ -75,6 +78,11 @@ public: private: typedef std::map SlotMap; SlotMap _slots; + + // We need to keep track of the primitive area as this is needed in feTile + typedef std::map PrimitiveAreaMap; + PrimitiveAreaMap _primitiveAreas; + DrawingItem *_item; //Geom::Rect _source_bbox; ///< bounding box of source graphic surface diff --git a/src/display/nr-filter-tile.cpp b/src/display/nr-filter-tile.cpp index 93ca50210..913812828 100644 --- a/src/display/nr-filter-tile.cpp +++ b/src/display/nr-filter-tile.cpp @@ -10,6 +10,8 @@ */ #include + +#include "display/cairo-utils.h" #include "display/nr-filter-tile.h" #include "display/nr-filter-slot.h" #include "display/nr-filter-units.h" @@ -30,16 +32,105 @@ FilterTile::~FilterTile() void FilterTile::render_cairo(FilterSlot &slot) { + // FIX ME! static bool tile_warning = false; - -//IMPLEMENT ME! if (!tile_warning) { - g_warning("Renderer for feTile is not implemented."); + g_warning("Renderer for feTile has non-optimal implementation, expect slowness and bugs."); tile_warning = true; } + // Fixing isn't so easy as the Inkscape renderer breaks the canvas into "rendering" tiles for + // faster rendering. (The "rendering" tiles are not the same as the tiles in this primitive.) + // Only if the the feTile tile source falls inside the current "rendering" tile will the tile + // image be available. + + // This input source contains only the "rendering" tile. cairo_surface_t *in = slot.getcairo(_input); - slot.set(_output, in); + + // For debugging + // static int i = 0; + // ++i; + // std::stringstream filename; + // filename << "dump." << i << ".png"; + // cairo_surface_write_to_png( in, filename.str().c_str() ); + + // This is the feTile source area as determined by the input primitive area (see SVG spec). + Geom::Rect tile_area = slot.get_primitive_area(_input); + + if( tile_area.width() == 0.0 || tile_area.height() == 0.0 ) { + + slot.set(_output, in); + std::cerr << "FileTile::render_cairo: tile has zero width or height" << std::endl; + + } else { + + cairo_surface_t *out = ink_cairo_surface_create_identical(in); + // color_interpolation_filters for out same as in. + copy_cairo_surface_ci(in, out); + cairo_t *ct = cairo_create(out); + + // The rectangle of the "rendering" tile. + Geom::Rect sa = slot.get_slot_area(); + + Geom::Affine trans = slot.get_units().get_matrix_user2pb(); + + // Create feTile tile ---------------- + + // Get tile area in pixbuf units (tile transformed). + Geom::Rect tt = tile_area * trans; + + // Shift between "rendering" tile and feTile tile + Geom::Point shift = sa.min() - tt.min(); + + // Create feTile tile surface + cairo_surface_t *tile = cairo_surface_create_similar(in, cairo_surface_get_content(in), + tt.width(), tt.height()); + cairo_t *ct_tile = cairo_create(tile); + cairo_set_source_surface(ct_tile, in, shift[Geom::X], shift[Geom::Y]); + cairo_paint(ct_tile); + + // Paint tiles ------------------ + + // For debugging + // std::stringstream filename; + // filename << "tile." << i << ".png"; + // cairo_surface_write_to_png( tile, filename.str().c_str() ); + + // Determine number of feTile rows and columns + Geom::Rect pr = filter_primitive_area( slot.get_units() ); + int tile_cols = ceil( pr.width() / tile_area.width() ); + int tile_rows = ceil( pr.height() / tile_area.height() ); + + // Do tiling (TO DO: restrict to slot area.) + for( int col=0; col < tile_cols; ++col ) { + for( int row=0; row < tile_rows; ++row ) { + + Geom::Point offset( col*tile_area.width(), row*tile_area.height() ); + offset *= trans; + offset[Geom::X] -= trans[4]; + offset[Geom::Y] -= trans[5]; + + cairo_set_source_surface(ct, tile, offset[Geom::X], offset[Geom::Y]); + cairo_paint(ct); + } + } + slot.set(_output, out); + + // Clean up + cairo_destroy(ct); + cairo_surface_destroy(out); + cairo_destroy(ct_tile); + cairo_surface_destroy(tile); + } +} + +void FilterTile::area_enlarge(Geom::IntRect &area, Geom::Affine const &trans) +{ + // We need to enlarge enough to get tile source... we don't the area of the source tile in this + // function so we guess. This is VERY inefficient. + Geom::Point enlarge(200, 200); + enlarge *= trans; + area.expandBy( enlarge[Geom::X] < 100 ? 100: enlarge[Geom::X] ); } double FilterTile::complexity(Geom::Affine const &) diff --git a/src/display/nr-filter-tile.h b/src/display/nr-filter-tile.h index 29087f2d6..239ecff4b 100644 --- a/src/display/nr-filter-tile.h +++ b/src/display/nr-filter-tile.h @@ -26,6 +26,7 @@ public: virtual ~FilterTile(); virtual void render_cairo(FilterSlot &slot); + virtual void area_enlarge(Geom::IntRect &area, Geom::Affine const &trans); virtual double complexity(Geom::Affine const &ctm); }; -- cgit v1.2.3 From ce697d7ebfb1e4affce10805c89445244d29388a Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 28 Oct 2015 14:40:01 +0100 Subject: Implement 'text-orientation' with user interface. Update 'writing-mode', adding 'vertical-lr'. Overhaul vertical text. Eliminate any use of "internal" leading in glyph metrics. Etc. (bzr r14430.1.1) --- src/display/nr-style.cpp | 2 -- src/display/nr-style.h | 1 - 2 files changed, 3 deletions(-) (limited to 'src/display') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index 1740785e2..8b82a1dff 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -68,7 +68,6 @@ NRStyle::NRStyle() , tspan_width(0) , ascender(0) , descender(0) - , line_gap(0) , underline_thickness(0) , underline_position(0) , line_through_thickness(0) @@ -330,7 +329,6 @@ void NRStyle::set(SPStyle *style, SPStyle *context_style) tspan_width = style->text_decoration_data.tspan_width; ascender = style->text_decoration_data.ascender; descender = style->text_decoration_data.descender; - line_gap = style->text_decoration_data.line_gap; underline_thickness = style->text_decoration_data.underline_thickness; underline_position = style->text_decoration_data.underline_position; line_through_thickness = style->text_decoration_data.line_through_thickness; diff --git a/src/display/nr-style.h b/src/display/nr-style.h index 5f78795d3..6c652311a 100644 --- a/src/display/nr-style.h +++ b/src/display/nr-style.h @@ -115,7 +115,6 @@ struct NRStyle { float tspan_width; float ascender; float descender; - float line_gap; float underline_thickness; float underline_position; float line_through_thickness; -- cgit v1.2.3 From 2e1f86061452fc6cad648a3370236bf2cb1f1a7d Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 28 Oct 2015 21:43:30 +0100 Subject: static code analysis (bzr r14432) --- src/display/canvas-text.cpp | 6 +++++- src/display/curve.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/display') diff --git a/src/display/canvas-text.cpp b/src/display/canvas-text.cpp index 5ad87b4ef..2c29fc207 100644 --- a/src/display/canvas-text.cpp +++ b/src/display/canvas-text.cpp @@ -266,10 +266,14 @@ sp_canvastext_set_coords (SPCanvasText *ct, gdouble x0, gdouble y0) void sp_canvastext_set_coords (SPCanvasText *ct, const Geom::Point start) { - Geom::Point pos = ct->desktop->doc2dt(start); + Geom::Point pos; g_return_if_fail (ct != NULL); g_return_if_fail (SP_IS_CANVASTEXT (ct)); + + if (ct && ct->desktop) { + pos = ct->desktop->doc2dt(start); + } if (DIFFER (pos[0], ct->s[Geom::X]) || DIFFER (pos[1], ct->s[Geom::Y])) { ct->s[Geom::X] = pos[0]; diff --git a/src/display/curve.cpp b/src/display/curve.cpp index 3024d1276..b6c387034 100644 --- a/src/display/curve.cpp +++ b/src/display/curve.cpp @@ -496,7 +496,7 @@ SPCurve::append(SPCurve const *curve2, _pathv.push_back( (*it) ); } - for (it++; it != curve2->_pathv.end(); ++it) { + for (++it; it != curve2->_pathv.end(); ++it) { _pathv.push_back( (*it) ); } } else { -- cgit v1.2.3 From fd5fce801e86b3e9ab0d56a702e89b11dbf7484e Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Thu, 29 Oct 2015 23:24:26 +0100 Subject: static code analysis (bzr r14436) --- src/display/canvas-text.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/display') diff --git a/src/display/canvas-text.cpp b/src/display/canvas-text.cpp index 2c29fc207..7c019caf5 100644 --- a/src/display/canvas-text.cpp +++ b/src/display/canvas-text.cpp @@ -266,14 +266,10 @@ sp_canvastext_set_coords (SPCanvasText *ct, gdouble x0, gdouble y0) void sp_canvastext_set_coords (SPCanvasText *ct, const Geom::Point start) { - Geom::Point pos; - - g_return_if_fail (ct != NULL); + g_return_if_fail (ct && ct->desktop); g_return_if_fail (SP_IS_CANVASTEXT (ct)); - if (ct && ct->desktop) { - pos = ct->desktop->doc2dt(start); - } + Geom::Point pos = ct->desktop->doc2dt(start); if (DIFFER (pos[0], ct->s[Geom::X]) || DIFFER (pos[1], ct->s[Geom::Y])) { ct->s[Geom::X] = pos[0]; -- cgit v1.2.3 From 067752b1cf216b8aa55c9e52926496553673cdb7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 2 Dec 2015 18:24:10 +0100 Subject: Add lock to guides (bzr r14500.1.1) --- src/display/guideline.cpp | 8 ++++++++ src/display/guideline.h | 2 ++ 2 files changed, 10 insertions(+) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 44bbd14bd..0a564f550 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -53,6 +53,7 @@ static void sp_guideline_init(SPGuideLine *gl) { gl->rgba = 0x0000ff7f; + gl->locked = false; gl->normal_to_line = Geom::Point(0,1); gl->angle = 3.14159265358979323846/2; gl->point_on_line = Geom::Point(0,0); @@ -219,6 +220,7 @@ SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point p normal.normalize(); gl->label = label; + gl->locked = false; gl->normal_to_line = normal; gl->angle = tan( -gl->normal_to_line[Geom::X] / gl->normal_to_line[Geom::Y]); sp_guideline_set_position(gl, point_on_line); @@ -238,6 +240,12 @@ void sp_guideline_set_label(SPGuideLine *gl, const char* label) sp_canvas_item_request_update(SP_CANVAS_ITEM (gl)); } +void sp_guideline_set_locked(SPGuideLine *gl, const bool locked) +{ + gl->locked = locked; + sp_canvas_item_request_update(SP_CANVAS_ITEM (gl)); +} + void sp_guideline_set_position(SPGuideLine *gl, Geom::Point point_on_line) { gl->point_on_line = point_on_line; diff --git a/src/display/guideline.h b/src/display/guideline.h index 2d9a87d9b..778517f1d 100644 --- a/src/display/guideline.h +++ b/src/display/guideline.h @@ -32,6 +32,7 @@ struct SPGuideLine { guint32 rgba; char* label; + bool locked; Geom::Point normal_to_line; Geom::Point point_on_line; double angle; @@ -51,6 +52,7 @@ GType sp_guideline_get_type(); SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point point_on_line, Geom::Point normal); void sp_guideline_set_label(SPGuideLine *gl, const char* label); +void sp_guideline_set_locked(SPGuideLine *gl, const bool locked); void sp_guideline_set_position(SPGuideLine *gl, Geom::Point point_on_line); void sp_guideline_set_normal(SPGuideLine *gl, Geom::Point normal_to_line); void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba); -- cgit v1.2.3 From af5c1ec831e2f225364717c7dc03d88579850b85 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 3 Dec 2015 18:55:52 +0100 Subject: Added no highlight and cross icon on locked guides (bzr r14500.1.4) --- src/display/guideline.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 0a564f550..24353c681 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -18,6 +18,7 @@ #include <2geom/transforms.h> #include "sp-canvas-util.h" #include "sp-ctrlpoint.h" +#include "sp-ctrlquadr.h" #include "guideline.h" #include "display/cairo-utils.h" @@ -180,7 +181,7 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, sp_ctrlpoint_set_coords(gl->origin, gl->point_on_line); sp_canvas_item_request_update(SP_CANVAS_ITEM (gl->origin)); - + Geom::Point pol_transformed = gl->point_on_line*affine; if (gl->is_horizontal()) { sp_canvas_update_bbox (item, -1000000, round(pol_transformed[Geom::Y] - 16), 1000000, round(pol_transformed[Geom::Y] + 1)); -- cgit v1.2.3 From e649a1d9cd29f39b2d1cf343cec97ccebce9cf08 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 5 Dec 2015 23:55:57 +0100 Subject: Changed from Desktop to namedview to handle multiples documents (bzr r14500.1.8) --- src/display/guideline.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 24353c681..2df0b3f26 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -18,7 +18,6 @@ #include <2geom/transforms.h> #include "sp-canvas-util.h" #include "sp-ctrlpoint.h" -#include "sp-ctrlquadr.h" #include "guideline.h" #include "display/cairo-utils.h" -- cgit v1.2.3 From 21c7070f90ef59fb5b6782e7adabd3d0f79e174d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 7 Dec 2015 19:58:44 +0100 Subject: Add Martin Owens radious patch (bzr r14500.1.11) --- src/display/guideline.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 2df0b3f26..e1a115353 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -178,6 +178,11 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, gl->affine = affine; + if (gl->locked) { + gl->origin->radius = 1; + } else { + gl->origin->radius = 3; + } sp_ctrlpoint_set_coords(gl->origin, gl->point_on_line); sp_canvas_item_request_update(SP_CANVAS_ITEM (gl->origin)); @@ -190,6 +195,7 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, //TODO: labels in angled guidelines are not showing up for some reason. sp_canvas_update_bbox (item, -1000000, -1000000, 1000000, 1000000); } + } // Returns 0.0 if point is on the guideline -- cgit v1.2.3 From 351afb17c6a579d3d1bb03500433b92b00123c03 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 7 Dec 2015 20:59:06 +0100 Subject: Add rect to SP Control point on locked guides (bzr r14500.1.13) --- src/display/guideline.cpp | 6 ++++-- src/display/sp-ctrlpoint.cpp | 28 +++++++++++++++++++--------- src/display/sp-ctrlpoint.h | 6 ++++-- 3 files changed, 27 insertions(+), 13 deletions(-) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index e1a115353..4b7ea59ab 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -179,9 +179,11 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, gl->affine = affine; if (gl->locked) { - gl->origin->radius = 1; + sp_ctrlpoint_set_circle(gl->origin, false); + sp_ctrlpoint_set_lenght(gl->origin, 6); } else { - gl->origin->radius = 3; + sp_ctrlpoint_set_circle(gl->origin, true); + sp_ctrlpoint_set_lenght(gl->origin, 4); } sp_ctrlpoint_set_coords(gl->origin, gl->point_on_line); sp_canvas_item_request_update(SP_CANVAS_ITEM (gl->origin)); diff --git a/src/display/sp-ctrlpoint.cpp b/src/display/sp-ctrlpoint.cpp index 1082cb1b3..19dbbc130 100644 --- a/src/display/sp-ctrlpoint.cpp +++ b/src/display/sp-ctrlpoint.cpp @@ -42,7 +42,8 @@ sp_ctrlpoint_init (SPCtrlPoint *ctrlpoint) ctrlpoint->rgba = 0x0000ff7f; ctrlpoint->pt[Geom::X] = ctrlpoint->pt[Geom::Y] = 0.0; ctrlpoint->item=NULL; - ctrlpoint->radius = 2; + ctrlpoint->lenght = 4; + ctrlpoint->is_circle = true; } static void sp_ctrlpoint_destroy(SPCanvasItem *object) @@ -75,8 +76,11 @@ sp_ctrlpoint_render (SPCanvasItem *item, SPCanvasBuf *buf) cairo_new_path(buf->ct); Geom::Point pt = cp->pt * cp->affine; - - cairo_arc(buf->ct, pt[Geom::X] - buf->rect.left(), pt[Geom::Y] - buf->rect.top(), cp->radius, 0.0, 2 * M_PI); + if( cp->is_circle ) { + cairo_arc(buf->ct, pt[Geom::X] - buf->rect.left(), pt[Geom::Y] - buf->rect.top(), cp->lenght/2.0, 0.0, 2 * M_PI); + } else { + cairo_rectangle(buf->ct, pt[Geom::X] - buf->rect.left() - cp->lenght/2.0, pt[Geom::Y] - buf->rect.top() - cp->lenght/2.0 , cp->lenght, cp->lenght); + } cairo_stroke(buf->ct); } @@ -96,10 +100,10 @@ static void sp_ctrlpoint_update(SPCanvasItem *item, Geom::Affine const &affine, Geom::Point pt = cp->pt * affine; - item->x1 = pt[Geom::X] - cp->radius; - item->y1 = pt[Geom::Y] - cp->radius; - item->x2 = pt[Geom::X] + cp->radius; - item->y2 = pt[Geom::Y] + cp->radius; + item->x1 = pt[Geom::X] - cp->lenght; + item->y1 = pt[Geom::Y] - cp->lenght; + item->x2 = pt[Geom::X] + cp->lenght; + item->y2 = pt[Geom::Y] + cp->lenght; item->canvas->requestRedraw((int)item->x1 - 15, (int)item->y1 - 15, (int)item->x1 + 15, (int)item->y1 + 15); @@ -142,9 +146,15 @@ sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const Geom::Point pt) } void -sp_ctrlpoint_set_radius (SPCtrlPoint *cp, const double r) +sp_ctrlpoint_set_lenght (SPCtrlPoint *cp, const double r) +{ + cp->lenght = r; +} + +void +sp_ctrlpoint_set_circle (SPCtrlPoint *cp, const bool circle) { - cp->radius = r; + cp->is_circle = circle; } /* diff --git a/src/display/sp-ctrlpoint.h b/src/display/sp-ctrlpoint.h index a7a5475b7..02e61caf0 100644 --- a/src/display/sp-ctrlpoint.h +++ b/src/display/sp-ctrlpoint.h @@ -25,7 +25,8 @@ struct SPCtrlPoint : public SPCanvasItem { guint32 rgba; Geom::Point pt; Geom::Affine affine; - double radius; + double lenght; + bool is_circle; }; struct SPCtrlPointClass : public SPCanvasItemClass{}; @@ -34,7 +35,8 @@ GType sp_ctrlpoint_get_type (void); void sp_ctrlpoint_set_color (SPCtrlPoint *cp, guint32 rgba); void sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const gdouble x, const gdouble y); void sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const Geom::Point pt); -void sp_ctrlpoint_set_radius (SPCtrlPoint *cp, const double r); +void sp_ctrlpoint_set_lenght (SPCtrlPoint *cp, const double r); +void sp_ctrlpoint_set_circle (SPCtrlPoint *cp, const bool circle); -- cgit v1.2.3 From 1b5e5271ae41e3ab4e2d352118e66ccafc608a6f Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 10 Dec 2015 00:43:23 -0500 Subject: Remove CtrlPoint and replace with SPKnot (bzr r14523) --- src/display/CMakeLists.txt | 2 - src/display/Makefile_insert | 2 - src/display/guideline.cpp | 49 ++++++++----- src/display/guideline.h | 4 +- src/display/sp-ctrlpoint.cpp | 169 ------------------------------------------- src/display/sp-ctrlpoint.h | 54 -------------- 6 files changed, 33 insertions(+), 247 deletions(-) delete mode 100644 src/display/sp-ctrlpoint.cpp delete mode 100644 src/display/sp-ctrlpoint.h (limited to 'src/display') diff --git a/src/display/CMakeLists.txt b/src/display/CMakeLists.txt index d4f8c16ff..0bf1d6e45 100644 --- a/src/display/CMakeLists.txt +++ b/src/display/CMakeLists.txt @@ -54,7 +54,6 @@ set(display_SRC sp-canvas.cpp sp-ctrlcurve.cpp sp-ctrlline.cpp - sp-ctrlpoint.cpp sp-ctrlquadr.cpp @@ -120,7 +119,6 @@ set(display_SRC sp-canvas.h sp-ctrlcurve.h sp-ctrlline.h - sp-ctrlpoint.h sp-ctrlquadr.h ) diff --git a/src/display/Makefile_insert b/src/display/Makefile_insert index 20e498981..419852f7d 100644 --- a/src/display/Makefile_insert +++ b/src/display/Makefile_insert @@ -115,8 +115,6 @@ ink_common_sources += \ display/sp-ctrlcurve.h \ display/sp-ctrlline.cpp \ display/sp-ctrlline.h \ - display/sp-ctrlpoint.cpp \ - display/sp-ctrlpoint.h \ display/sp-ctrlquadr.cpp \ display/sp-ctrlquadr.h diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 4b7ea59ab..820a61d4d 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -17,7 +17,7 @@ #include <2geom/coord.h> #include <2geom/transforms.h> #include "sp-canvas-util.h" -#include "sp-ctrlpoint.h" +#include "knot.h" #include "guideline.h" #include "display/cairo-utils.h" @@ -25,6 +25,7 @@ #include "desktop.h" #include "sp-namedview.h" #include "display/sp-canvas.h" +#include "display/sodipodi-ctrl.h" #include "ui/control-manager.h" using Inkscape::ControlManager; @@ -36,6 +37,7 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf); static double sp_guideline_point(SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item); +static gboolean sp_guideline_origin_move(SPKnot *knot, Geom::Point *position, guint state, SPGuideLine *data); static void sp_guideline_drawline (SPCanvasBuf *buf, gint x0, gint y0, gint x1, gint y1, guint32 rgba); G_DEFINE_TYPE(SPGuideLine, sp_guideline, SP_TYPE_CANVAS_ITEM); @@ -72,8 +74,8 @@ static void sp_guideline_destroy(SPCanvasItem *object) SPGuideLine *gl = SP_GUIDELINE(object); - if (gl->origin != NULL && SP_IS_CTRLPOINT(gl->origin)) { - sp_canvas_item_destroy(gl->origin); + if (gl->origin != NULL && SP_IS_KNOT(gl->origin)) { + knot_unref(gl->origin); } else { // FIXME: This branch shouldn't be reached (although it seems to be harmless). //g_error("Why can it be that gl->origin is not a valid SPCtrlPoint?\n"); @@ -179,14 +181,16 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, gl->affine = affine; if (gl->locked) { - sp_ctrlpoint_set_circle(gl->origin, false); - sp_ctrlpoint_set_lenght(gl->origin, 6); + gl->origin->setStroke(0x0000ff88, 0x0000ff88, 0x0000ff88); + gl->origin->setShape(SP_CTRL_SHAPE_CROSS); + gl->origin->setSize(6); } else { - sp_ctrlpoint_set_circle(gl->origin, true); - sp_ctrlpoint_set_lenght(gl->origin, 4); + gl->origin->setStroke(0xff000088, 0xff0000ff, 0xff0000ff); + gl->origin->setShape(SP_CTRL_SHAPE_CIRCLE); + gl->origin->setSize(4); } - sp_ctrlpoint_set_coords(gl->origin, gl->point_on_line); - sp_canvas_item_request_update(SP_CANVAS_ITEM (gl->origin)); + gl->origin->moveto(gl->point_on_line); + gl->origin->updateCtrl(); Geom::Point pol_transformed = gl->point_on_line*affine; if (gl->is_horizontal()) { @@ -219,12 +223,15 @@ static double sp_guideline_point(SPCanvasItem *item, Geom::Point p, SPCanvasItem SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point point_on_line, Geom::Point normal) { SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_GUIDELINE, NULL); - SPCanvasItem *origin = ControlManager::getManager().createControl(parent, Inkscape::CTRL_TYPE_ORIGIN); - ControlManager::getManager().track(origin); - SPGuideLine *gl = SP_GUIDELINE(item); - SPCtrlPoint *cp = SP_CTRLPOINT(origin); - gl->origin = cp; + gl->origin = new SPKnot(SP_ACTIVE_DESKTOP, "No tip yet!! XXX"); + + gl->origin->setAnchor(SP_ANCHOR_CENTER); + gl->origin->setMode(SP_CTRL_MODE_COLOR); + gl->origin->setFill(0xffffff80, 0xffffffff, 0xffffff80); + gl->origin->moveto(point_on_line); + gl->origin->request_signal.connect(sigc::bind(sigc::ptr_fun(sp_guideline_origin_move), gl)); + gl->origin->updateCtrl(); normal.normalize(); gl->label = label; @@ -233,11 +240,18 @@ SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point p gl->angle = tan( -gl->normal_to_line[Geom::X] / gl->normal_to_line[Geom::Y]); sp_guideline_set_position(gl, point_on_line); - sp_ctrlpoint_set_coords(cp, point_on_line); - return item; } +static gboolean sp_guideline_origin_move(SPKnot *knot, Geom::Point *position, guint state, SPGuideLine *gl) +{ + if(gl->locked) { + return true; + } + sp_guideline_set_position(gl, *position); + return false; +} + void sp_guideline_set_label(SPGuideLine *gl, const char* label) { if (gl->label) { @@ -271,8 +285,6 @@ void sp_guideline_set_normal(SPGuideLine *gl, Geom::Point normal_to_line) void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba) { gl->rgba = rgba; - sp_ctrlpoint_set_color(gl->origin, rgba); - sp_canvas_item_request_update(SP_CANVAS_ITEM(gl)); } @@ -283,7 +295,6 @@ void sp_guideline_set_sensitive(SPGuideLine *gl, int sensitive) void sp_guideline_delete(SPGuideLine *gl) { - //gtk_object_destroy(GTK_OBJECT(gl->origin)); sp_canvas_item_destroy(SP_CANVAS_ITEM(gl)); } diff --git a/src/display/guideline.h b/src/display/guideline.h index 778517f1d..143a57622 100644 --- a/src/display/guideline.h +++ b/src/display/guideline.h @@ -16,6 +16,7 @@ #include <2geom/point.h> #include "sp-canvas-item.h" +#include "knot.h" #define SP_TYPE_GUIDELINE (sp_guideline_get_type()) #define SP_GUIDELINE(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_GUIDELINE, SPGuideLine)) @@ -27,7 +28,8 @@ struct SPGuideLine { SPCanvasItem item; Geom::Affine affine; - SPCtrlPoint *origin; // unlike 'item', this is only held locally + //SPCtrlPoint *origin; // unlike 'item', this is only held locally + SPKnot *origin; guint32 rgba; diff --git a/src/display/sp-ctrlpoint.cpp b/src/display/sp-ctrlpoint.cpp deleted file mode 100644 index 19dbbc130..000000000 --- a/src/display/sp-ctrlpoint.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Simple point - * - * Author: - * Maximilian Albert - * Jon A. Cruz - * - * Copyright (C) 2008 Maximilian Albert - * - * Released under GNU GPL - */ - -#include "sp-canvas-util.h" -#include "sp-ctrlpoint.h" - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include -#include "display/cairo-utils.h" -#include "display/sp-canvas.h" - -static void sp_ctrlpoint_destroy(SPCanvasItem *object); - -static void sp_ctrlpoint_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned int flags); -static void sp_ctrlpoint_render (SPCanvasItem *item, SPCanvasBuf *buf); - -G_DEFINE_TYPE(SPCtrlPoint, sp_ctrlpoint, SP_TYPE_CANVAS_ITEM); - -static void sp_ctrlpoint_class_init(SPCtrlPointClass *klass) -{ - SPCanvasItemClass *item_class = SP_CANVAS_ITEM_CLASS(klass); - - item_class->destroy = sp_ctrlpoint_destroy; - item_class->update = sp_ctrlpoint_update; - item_class->render = sp_ctrlpoint_render; -} - -static void -sp_ctrlpoint_init (SPCtrlPoint *ctrlpoint) -{ - ctrlpoint->rgba = 0x0000ff7f; - ctrlpoint->pt[Geom::X] = ctrlpoint->pt[Geom::Y] = 0.0; - ctrlpoint->item=NULL; - ctrlpoint->lenght = 4; - ctrlpoint->is_circle = true; -} - -static void sp_ctrlpoint_destroy(SPCanvasItem *object) -{ - g_return_if_fail (object != NULL); - g_return_if_fail (SP_IS_CTRLPOINT (object)); - - SPCtrlPoint *ctrlpoint = SP_CTRLPOINT (object); - - ctrlpoint->item=NULL; - - if (SP_CANVAS_ITEM_CLASS(sp_ctrlpoint_parent_class)->destroy) - SP_CANVAS_ITEM_CLASS(sp_ctrlpoint_parent_class)->destroy(object); -} - -static void -sp_ctrlpoint_render (SPCanvasItem *item, SPCanvasBuf *buf) -{ - SPCtrlPoint *cp = SP_CTRLPOINT (item); - - if (!buf->ct) - return; - - sp_canvas_prepare_buffer (buf); - - guint32 rgba = cp->rgba; - cairo_set_source_rgba(buf->ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba)); - - cairo_set_line_width(buf->ct, 1); - cairo_new_path(buf->ct); - - Geom::Point pt = cp->pt * cp->affine; - if( cp->is_circle ) { - cairo_arc(buf->ct, pt[Geom::X] - buf->rect.left(), pt[Geom::Y] - buf->rect.top(), cp->lenght/2.0, 0.0, 2 * M_PI); - } else { - cairo_rectangle(buf->ct, pt[Geom::X] - buf->rect.left() - cp->lenght/2.0, pt[Geom::Y] - buf->rect.top() - cp->lenght/2.0 , cp->lenght, cp->lenght); - } - cairo_stroke(buf->ct); -} - -static void sp_ctrlpoint_update(SPCanvasItem *item, Geom::Affine const &affine, unsigned int flags) -{ - SPCtrlPoint *cp = SP_CTRLPOINT(item); - - item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2); - - if (SP_CANVAS_ITEM_CLASS(sp_ctrlpoint_parent_class)->update) { - SP_CANVAS_ITEM_CLASS(sp_ctrlpoint_parent_class)->update(item, affine, flags); - } - - sp_canvas_item_reset_bounds (item); - - cp->affine = affine; - - Geom::Point pt = cp->pt * affine; - - item->x1 = pt[Geom::X] - cp->lenght; - item->y1 = pt[Geom::Y] - cp->lenght; - item->x2 = pt[Geom::X] + cp->lenght; - item->y2 = pt[Geom::Y] + cp->lenght; - - item->canvas->requestRedraw((int)item->x1 - 15, (int)item->y1 - 15, - (int)item->x1 + 15, (int)item->y1 + 15); -} - -void -sp_ctrlpoint_set_color (SPCtrlPoint *cp, guint32 rgba) -{ - g_return_if_fail (cp != NULL); - g_return_if_fail (SP_IS_CTRLPOINT (cp)); - - if (rgba != cp->rgba) { - SPCanvasItem *item; - cp->rgba = rgba; - item = SP_CANVAS_ITEM (cp); - item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2); - } -} - -#define EPSILON 1e-6 -#define DIFFER(a,b) (fabs ((a) - (b)) > EPSILON) - -void -sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const gdouble x, const gdouble y) -{ - g_return_if_fail (cp != NULL); - g_return_if_fail (SP_IS_CTRLPOINT (cp)); - - if (DIFFER (x, cp->pt[Geom::X]) || DIFFER (y, cp->pt[Geom::Y])) { - cp->pt[Geom::X] = x; - cp->pt[Geom::Y] = y; - sp_canvas_item_request_update (SP_CANVAS_ITEM (cp)); - } -} - -void -sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const Geom::Point pt) -{ - sp_ctrlpoint_set_coords(cp, pt[Geom::X], pt[Geom::Y]); -} - -void -sp_ctrlpoint_set_lenght (SPCtrlPoint *cp, const double r) -{ - cp->lenght = r; -} - -void -sp_ctrlpoint_set_circle (SPCtrlPoint *cp, const bool circle) -{ - cp->is_circle = circle; -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/display/sp-ctrlpoint.h b/src/display/sp-ctrlpoint.h deleted file mode 100644 index 02e61caf0..000000000 --- a/src/display/sp-ctrlpoint.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef SEEN_INKSCAPE_CTRLPOINT_H -#define SEEN_INKSCAPE_CTRLPOINT_H - -/* - * A simple point - * - * Author: - * Maximilian Albert - * - * Copyright (C) 2008 Maximilian Albert - * - * Released under GNU GPL - */ - -#include "sp-canvas-item.h" - -class SPItem; - -#define SP_TYPE_CTRLPOINT (sp_ctrlpoint_get_type ()) -#define SP_CTRLPOINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_CTRLPOINT, SPCtrlPoint)) -#define SP_IS_CTRLPOINT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_CTRLPOINT)) - -struct SPCtrlPoint : public SPCanvasItem { - SPItem *item; // the item to which this line belongs in some sense; may be NULL for some users - guint32 rgba; - Geom::Point pt; - Geom::Affine affine; - double lenght; - bool is_circle; -}; -struct SPCtrlPointClass : public SPCanvasItemClass{}; - -GType sp_ctrlpoint_get_type (void); - -void sp_ctrlpoint_set_color (SPCtrlPoint *cp, guint32 rgba); -void sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const gdouble x, const gdouble y); -void sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const Geom::Point pt); -void sp_ctrlpoint_set_lenght (SPCtrlPoint *cp, const double r); -void sp_ctrlpoint_set_circle (SPCtrlPoint *cp, const bool circle); - - - -#endif // SEEN_INKSCAPE_CTRLPOINT_H - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3 From e151d5d9804624f69d037e708c6a2bd35058e467 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 11 Dec 2015 02:24:16 +0100 Subject: Fix bug launching a document by commandline with guides (bzr r14525) --- src/display/guideline.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 820a61d4d..1c28149a9 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -180,6 +180,15 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, gl->affine = affine; + if (!gl->origin){ + gl->origin = new SPKnot(SP_ACTIVE_DESKTOP, "No tip yet!! XXX"); + + gl->origin->setAnchor(SP_ANCHOR_CENTER); + gl->origin->setMode(SP_CTRL_MODE_COLOR); + gl->origin->setFill(0xffffff80, 0xffffffff, 0xffffff80); + gl->origin->request_signal.connect(sigc::bind(sigc::ptr_fun(sp_guideline_origin_move), gl)); + } + if (gl->locked) { gl->origin->setStroke(0x0000ff88, 0x0000ff88, 0x0000ff88); gl->origin->setShape(SP_CTRL_SHAPE_CROSS); @@ -191,7 +200,7 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, } gl->origin->moveto(gl->point_on_line); gl->origin->updateCtrl(); - + Geom::Point pol_transformed = gl->point_on_line*affine; if (gl->is_horizontal()) { sp_canvas_update_bbox (item, -1000000, round(pol_transformed[Geom::Y] - 16), 1000000, round(pol_transformed[Geom::Y] + 1)); @@ -224,15 +233,16 @@ SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point p { SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_GUIDELINE, NULL); SPGuideLine *gl = SP_GUIDELINE(item); - gl->origin = new SPKnot(SP_ACTIVE_DESKTOP, "No tip yet!! XXX"); - - gl->origin->setAnchor(SP_ANCHOR_CENTER); - gl->origin->setMode(SP_CTRL_MODE_COLOR); - gl->origin->setFill(0xffffff80, 0xffffffff, 0xffffff80); - gl->origin->moveto(point_on_line); - gl->origin->request_signal.connect(sigc::bind(sigc::ptr_fun(sp_guideline_origin_move), gl)); - gl->origin->updateCtrl(); - + if ( SP_ACTIVE_DESKTOP ){ + gl->origin = new SPKnot(SP_ACTIVE_DESKTOP, "No tip yet!! XXX"); + + gl->origin->setAnchor(SP_ANCHOR_CENTER); + gl->origin->setMode(SP_CTRL_MODE_COLOR); + gl->origin->setFill(0xffffff80, 0xffffffff, 0xffffff80); + gl->origin->moveto(point_on_line); + gl->origin->request_signal.connect(sigc::bind(sigc::ptr_fun(sp_guideline_origin_move), gl)); + gl->origin->updateCtrl(); + } normal.normalize(); gl->label = label; gl->locked = false; -- cgit v1.2.3 From 0732d8cfbf843dac04be27f45b8102d6df216410 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 10 Dec 2015 21:47:16 -0500 Subject: Clean up some code, only init the SPKnot in one place. (bzr r14526) --- src/display/guideline.cpp | 14 -------------- src/display/guideline.h | 5 +---- 2 files changed, 1 insertion(+), 18 deletions(-) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 1c28149a9..fd6ccf164 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -69,16 +69,11 @@ static void sp_guideline_destroy(SPCanvasItem *object) { g_return_if_fail (object != NULL); g_return_if_fail (SP_IS_GUIDELINE (object)); - //g_return_if_fail (SP_GUIDELINE(object)->origin != NULL); - //g_return_if_fail (SP_IS_CTRLPOINT(SP_GUIDELINE(object)->origin)); SPGuideLine *gl = SP_GUIDELINE(object); if (gl->origin != NULL && SP_IS_KNOT(gl->origin)) { knot_unref(gl->origin); - } else { - // FIXME: This branch shouldn't be reached (although it seems to be harmless). - //g_error("Why can it be that gl->origin is not a valid SPCtrlPoint?\n"); } if (gl->label) { @@ -233,16 +228,7 @@ SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point p { SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_GUIDELINE, NULL); SPGuideLine *gl = SP_GUIDELINE(item); - if ( SP_ACTIVE_DESKTOP ){ - gl->origin = new SPKnot(SP_ACTIVE_DESKTOP, "No tip yet!! XXX"); - gl->origin->setAnchor(SP_ANCHOR_CENTER); - gl->origin->setMode(SP_CTRL_MODE_COLOR); - gl->origin->setFill(0xffffff80, 0xffffffff, 0xffffff80); - gl->origin->moveto(point_on_line); - gl->origin->request_signal.connect(sigc::bind(sigc::ptr_fun(sp_guideline_origin_move), gl)); - gl->origin->updateCtrl(); - } normal.normalize(); gl->label = label; gl->locked = false; diff --git a/src/display/guideline.h b/src/display/guideline.h index 143a57622..d58821fc8 100644 --- a/src/display/guideline.h +++ b/src/display/guideline.h @@ -22,14 +22,11 @@ #define SP_GUIDELINE(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_GUIDELINE, SPGuideLine)) #define SP_IS_GUIDELINE(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_GUIDELINE)) -struct SPCtrlPoint; - struct SPGuideLine { SPCanvasItem item; Geom::Affine affine; - //SPCtrlPoint *origin; // unlike 'item', this is only held locally - SPKnot *origin; + SPKnot *origin; // unlike 'item', this is only held locally guint32 rgba; -- cgit v1.2.3 From 678ace57cb2e98572d3e5c30138b3100aceef1ed Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 11 Dec 2015 10:16:30 +0100 Subject: Fix crash on hidden guides (bzr r14527) --- src/display/guideline.cpp | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index fd6ccf164..4b573a586 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -172,31 +172,32 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, if ((SP_CANVAS_ITEM_CLASS(sp_guideline_parent_class))->update) { (SP_CANVAS_ITEM_CLASS(sp_guideline_parent_class))->update(item, affine, flags); } + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if (desktop && item->visible) { + if (!gl->origin) { + gl->origin = new SPKnot(desktop, "No tip yet!! XXX"); + + gl->origin->setAnchor(SP_ANCHOR_CENTER); + gl->origin->setMode(SP_CTRL_MODE_COLOR); + gl->origin->setFill(0xffffff80, 0xffffffff, 0xffffff80); + gl->origin->request_signal.connect(sigc::bind(sigc::ptr_fun(sp_guideline_origin_move), gl)); + } - gl->affine = affine; - - if (!gl->origin){ - gl->origin = new SPKnot(SP_ACTIVE_DESKTOP, "No tip yet!! XXX"); - - gl->origin->setAnchor(SP_ANCHOR_CENTER); - gl->origin->setMode(SP_CTRL_MODE_COLOR); - gl->origin->setFill(0xffffff80, 0xffffffff, 0xffffff80); - gl->origin->request_signal.connect(sigc::bind(sigc::ptr_fun(sp_guideline_origin_move), gl)); - } - - if (gl->locked) { - gl->origin->setStroke(0x0000ff88, 0x0000ff88, 0x0000ff88); - gl->origin->setShape(SP_CTRL_SHAPE_CROSS); - gl->origin->setSize(6); - } else { - gl->origin->setStroke(0xff000088, 0xff0000ff, 0xff0000ff); - gl->origin->setShape(SP_CTRL_SHAPE_CIRCLE); - gl->origin->setSize(4); + if (gl->locked) { + gl->origin->setStroke(0x0000ff88, 0x0000ff88, 0x0000ff88); + gl->origin->setShape(SP_CTRL_SHAPE_CROSS); + gl->origin->setSize(6); + } else { + gl->origin->setStroke(0xff000088, 0xff0000ff, 0xff0000ff); + gl->origin->setShape(SP_CTRL_SHAPE_CIRCLE); + gl->origin->setSize(4); + } + gl->origin->moveto(gl->point_on_line); + gl->origin->updateCtrl(); } - gl->origin->moveto(gl->point_on_line); - gl->origin->updateCtrl(); - Geom::Point pol_transformed = gl->point_on_line*affine; + gl->affine = affine; + Geom::Point pol_transformed = gl->point_on_line * affine; if (gl->is_horizontal()) { sp_canvas_update_bbox (item, -1000000, round(pol_transformed[Geom::Y] - 16), 1000000, round(pol_transformed[Geom::Y] + 1)); } else if (gl->is_vertical()) { @@ -205,7 +206,6 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, //TODO: labels in angled guidelines are not showing up for some reason. sp_canvas_update_bbox (item, -1000000, -1000000, 1000000, 1000000); } - } // Returns 0.0 if point is on the guideline -- cgit v1.2.3 From ab7cc89c4f9f938575e777530c31312cde116208 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sun, 13 Dec 2015 20:23:22 +0100 Subject: cppification and performance (bzr r14529) --- src/display/sp-canvas-item.h | 2 + src/display/sp-canvas-util.cpp | 3 + src/display/sp-canvas.cpp | 195 ++++++++++++++--------------------------- 3 files changed, 71 insertions(+), 129 deletions(-) (limited to 'src/display') diff --git a/src/display/sp-canvas-item.h b/src/display/sp-canvas-item.h index 3e9e085a0..66cd03dd9 100644 --- a/src/display/sp-canvas-item.h +++ b/src/display/sp-canvas-item.h @@ -116,7 +116,9 @@ G_END_DECLS void sp_canvas_item_affine_absolute(SPCanvasItem *item, Geom::Affine const &aff); void sp_canvas_item_raise(SPCanvasItem *item, int positions); +void sp_canvas_item_raise_to_top(SPCanvasItem *item); void sp_canvas_item_lower(SPCanvasItem *item, int positions); +void sp_canvas_item_lower_to_bottom(SPCanvasItem *item); bool sp_canvas_item_is_visible(SPCanvasItem *item); void sp_canvas_item_show(SPCanvasItem *item); void sp_canvas_item_hide(SPCanvasItem *item); diff --git a/src/display/sp-canvas-util.cpp b/src/display/sp-canvas-util.cpp index 79c8c614e..25b70824b 100644 --- a/src/display/sp-canvas-util.cpp +++ b/src/display/sp-canvas-util.cpp @@ -67,6 +67,9 @@ void sp_canvas_item_set_i2w_affine (SPCanvasItem * item, Geom::Affine const &i2 void sp_canvas_item_move_to_z (SPCanvasItem * item, gint z) { g_assert (item != NULL); + + if (z == 0) + return sp_canvas_item_lower_to_bottom(item); gint current_z = sp_canvas_item_order (item); diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 5efc4ce86..6441ea68b 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -58,7 +58,7 @@ struct SPCanvasGroupClass { }; /** - * A group of Items. + * A group of items. */ struct SPCanvasGroup { /** @@ -109,8 +109,8 @@ struct SPCanvasGroup { SPCanvasItem item; - GList *items; - GList *last; + std::list *items; + }; /** @@ -166,13 +166,6 @@ static guint object_signals[LAST_SIGNAL] = { 0 }; */ void sp_canvas_item_construct(SPCanvasItem *item, SPCanvasGroup *parent, gchar const *first_arg_name, va_list args); -/** - * Convenience function to reorder items in a group's child list. - * - * This puts the specified link after the "before" link. - */ -void put_item_after(GList *link, GList *before); - /** * Helper that returns true iff item is descendant of parent. */ @@ -590,64 +583,6 @@ void sp_canvas_item_affine_absolute(SPCanvasItem *item, Geom::Affine const &affi item->canvas->need_repick = TRUE; } -namespace { - -void put_item_after(GList *link, GList *before) -{ - if (link == before) { - return; - } - - SPCanvasGroup *parent = SP_CANVAS_GROUP (SP_CANVAS_ITEM (link->data)->parent); - - if (before == NULL) { - if (link == parent->items) { - return; - } - - link->prev->next = link->next; - - if (link->next) { - link->next->prev = link->prev; - } else { - parent->last = link->prev; - } - - link->prev = before; - link->next = parent->items; - link->next->prev = link; - parent->items = link; - } else { - if ((link == parent->last) && (before == parent->last->prev)) { - return; - } - - if (link->next) { - link->next->prev = link->prev; - } - - if (link->prev) { - link->prev->next = link->next; - } else { - parent->items = link->next; - parent->items->prev = NULL; - } - - link->prev = before; - link->next = before->next; - - link->prev->next = link; - - if (link->next) { - link->next->prev = link; - } else { - parent->last = link; - } - } -} - -} // namespace - /** * Raises the item in its parent's stack by the specified number of positions. * @@ -668,24 +603,34 @@ void sp_canvas_item_raise(SPCanvasItem *item, int positions) } SPCanvasGroup *parent = SP_CANVAS_GROUP (item->parent); - GList *link = g_list_find (parent->items, item); - g_assert (link != NULL); + std::list::iterator l = std::find(parent->items->begin(),parent->items->end(), item); + g_assert (l != parent->items->end()); - GList *before; - for (before = link; positions && before; positions--) - before = before->next; + for (int i=0; iitems->end(); ++i) + l++; - if (!before) { - before = parent->last; - } + parent->items->remove(item); + parent->items->insert(l, item); - put_item_after (link, before); + redraw_if_visible (item); + item->canvas->need_repick = TRUE; +} +void sp_canvas_item_raise_to_top(SPCanvasItem *item) +{ + g_return_if_fail (item != NULL); + g_return_if_fail (SP_IS_CANVAS_ITEM (item)); + if (!item->parent) + return; + SPCanvasGroup *parent = SP_CANVAS_GROUP (item->parent); + parent->items->remove(item); + parent->items->insert(parent->items->end(),item); redraw_if_visible (item); item->canvas->need_repick = TRUE; } + /** * Lowers the item in its parent's stack by the specified number of positions. * @@ -701,28 +646,35 @@ void sp_canvas_item_lower(SPCanvasItem *item, int positions) g_return_if_fail (SP_IS_CANVAS_ITEM (item)); g_return_if_fail (positions >= 1); - if (!item->parent || positions == 0) { + if (!item->parent || positions == 0 || item == SP_CANVAS_GROUP(item->parent)->items->front() ) { return; } SPCanvasGroup *parent = SP_CANVAS_GROUP (item->parent); - GList *link = g_list_find (parent->items, item); - g_assert (link != NULL); + std::list::iterator l = std::find(parent->items->begin(),parent->items->end(), item); + g_assert (l != parent->items->end()); - GList *before; - if (link->prev) { - for (before = link->prev; positions && before; positions--) { - before = before->prev; - } - } else { - before = NULL; - } - - put_item_after (link, before); + for (int i=0; iitems->begin(); ++i) + l--; + + parent->items->remove(item); + parent->items->insert(l, item); redraw_if_visible (item); item->canvas->need_repick = TRUE; } +void sp_canvas_item_lower_to_bottom(SPCanvasItem *item) +{ + g_return_if_fail (item != NULL); + g_return_if_fail (SP_IS_CANVAS_ITEM (item)); + if (!item->parent) + return; + SPCanvasGroup *parent = SP_CANVAS_GROUP (item->parent); + parent->items->remove(item); + parent->items->insert(parent->items->begin(),item); + redraw_if_visible (item); + item->canvas->need_repick = TRUE; +} bool sp_canvas_item_is_visible(SPCanvasItem *item) { @@ -919,7 +871,8 @@ void sp_canvas_item_request_update(SPCanvasItem *item) */ gint sp_canvas_item_order (SPCanvasItem * item) { - return g_list_index (SP_CANVAS_GROUP (item->parent)->items, item); + SPCanvasGroup * p = SP_CANVAS_GROUP(item->parent); + return std::distance(p->items->begin(), std::find(p->items->begin(), p->items->end(), item)); } // SPCanvasGroup @@ -936,9 +889,9 @@ static void sp_canvas_group_class_init(SPCanvasGroupClass *klass) item_class->viewbox_changed = SPCanvasGroup::viewboxChanged; } -static void sp_canvas_group_init(SPCanvasGroup * /*group*/) +static void sp_canvas_group_init(SPCanvasGroup * group) { - // Nothing here + group->items = new std::list; } void SPCanvasGroup::destroy(SPCanvasItem *object) @@ -948,14 +901,15 @@ void SPCanvasGroup::destroy(SPCanvasItem *object) SPCanvasGroup const *group = SP_CANVAS_GROUP(object); - GList *list = group->items; - while (list) { - SPCanvasItem *child = reinterpret_cast(list->data); - list = list->next; - + std::list *list = group->items; + for (std::list::iterator it = list->begin(); it != list->end(); ++it) { + SPCanvasItem *child = *it; sp_canvas_item_destroy(child); } + group->items->clear(); + delete group->items; + if (SP_CANVAS_ITEM_CLASS(sp_canvas_group_parent_class)->destroy) { (* SP_CANVAS_ITEM_CLASS(sp_canvas_group_parent_class)->destroy)(object); } @@ -966,8 +920,8 @@ void SPCanvasGroup::update(SPCanvasItem *item, Geom::Affine const &affine, unsig SPCanvasGroup const *group = SP_CANVAS_GROUP(item); Geom::OptRect bounds; - for (GList *list = group->items; list; list = list->next) { - SPCanvasItem *i = SP_CANVAS_ITEM(list->data); + for (std::list::const_iterator it = group->items->begin(); it != group->items->end(); ++it) { + SPCanvasItem *i = *it; sp_canvas_item_invoke_update (i, affine, flags); @@ -1002,9 +956,8 @@ double SPCanvasGroup::point(SPCanvasItem *item, Geom::Point p, SPCanvasItem **ac *actual_item = NULL; double dist = 0.0; - - for (GList *list = group->items; list; list = list->next) { - SPCanvasItem *child = SP_CANVAS_ITEM(list->data); + for (std::list::const_iterator it = group->items->begin(); it != group->items->end(); ++it) { + SPCanvasItem *child = *it; if ((child->x1 <= x2) && (child->y1 <= y2) && (child->x2 >= x1) && (child->y2 >= y1)) { SPCanvasItem *point_item = NULL; // cater for incomplete item implementations @@ -1037,8 +990,8 @@ void SPCanvasGroup::render(SPCanvasItem *item, SPCanvasBuf *buf) { SPCanvasGroup const *group = SP_CANVAS_GROUP(item); - for (GList *list = group->items; list; list = list->next) { - SPCanvasItem *child = SP_CANVAS_ITEM(list->data); + for (std::list::const_iterator it = group->items->begin(); it != group->items->end(); ++it) { + SPCanvasItem *child = *it; if (child->visible) { if ((child->x1 < buf->rect.right()) && (child->y1 < buf->rect.bottom()) && @@ -1056,8 +1009,8 @@ void SPCanvasGroup::viewboxChanged(SPCanvasItem *item, Geom::IntRect const &new_ { SPCanvasGroup *group = SP_CANVAS_GROUP(item); - for (GList *list = group->items; list; list = list->next) { - SPCanvasItem *child = SP_CANVAS_ITEM(list->data); + for (std::list::const_iterator it = group->items->begin(); it != group->items->end(); ++it) { + SPCanvasItem *child = *it; if (child->visible) { if (SP_CANVAS_ITEM_GET_CLASS(child)->viewbox_changed) { SP_CANVAS_ITEM_GET_CLASS(child)->viewbox_changed(child, new_area); @@ -1071,37 +1024,21 @@ void SPCanvasGroup::add(SPCanvasItem *item) g_object_ref(item); g_object_ref_sink(item); - if (!items) { - items = g_list_append(items, item); - last = items; - } else { - last = g_list_append(last, item)->next; - } + items->push_back(item); sp_canvas_item_request_update(item); } void SPCanvasGroup::remove(SPCanvasItem *item) { + g_return_if_fail(item != NULL); + items->remove(item); - for (GList *children = items; children; children = children->next) { - if (children->data == item) { - - // Unparent the child - item->parent = NULL; - g_object_unref(item); - - // Remove it from the list - if (children == last) { - last = children->prev; - } + // Unparent the child + item->parent = NULL; + g_object_unref(item); - items = g_list_remove_link(items, children); - g_list_free(children); - break; - } - } } static void sp_canvas_dispose (GObject *object); -- cgit v1.2.3 From 78c3176c18c0306aaac30b640e939de9051b3a1f Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 14 Dec 2015 14:45:25 +0100 Subject: Fix two bugs with component transfer filter primitive: 1. Discrete type was ignoring last value in list. 2. Change in alpha was not propogated to pre-multiplied color values leading to "ghosting". (bzr r14532) --- src/display/nr-filter-component-transfer.cpp | 202 +++++++-------------------- 1 file changed, 47 insertions(+), 155 deletions(-) (limited to 'src/display') diff --git a/src/display/nr-filter-component-transfer.cpp b/src/display/nr-filter-component-transfer.cpp index dd90193fe..dd37ab873 100644 --- a/src/display/nr-filter-component-transfer.cpp +++ b/src/display/nr-filter-component-transfer.cpp @@ -30,6 +30,32 @@ FilterPrimitive * FilterComponentTransfer::create() { FilterComponentTransfer::~FilterComponentTransfer() {} +struct UnmultiplyAlpha { + guint32 operator()(guint32 in) { + EXTRACT_ARGB32(in, a, r, g, b); + if (a == 0 ) + return in; + r = unpremul_alpha(r, a); + g = unpremul_alpha(g, a); + b = unpremul_alpha(b, a); + ASSEMBLE_ARGB32(out, a, r, g, b); + return out; + } +}; + +struct MultiplyAlpha { + guint32 operator()(guint32 in) { + EXTRACT_ARGB32(in, a, r, g, b); + if (a == 0 ) + return in; + r = premul_alpha(r, a); + g = premul_alpha(g, a); + b = premul_alpha(b, a); + ASSEMBLE_ARGB32(out, a, r, g, b); + return out; + } +}; + struct ComponentTransfer { ComponentTransfer(guint32 color) : _shift(color * 8) @@ -40,11 +66,7 @@ protected: guint32 _mask; }; -template -struct ComponentTransferTable; - -template <> -struct ComponentTransferTable : public ComponentTransfer { +struct ComponentTransferTable : public ComponentTransfer { ComponentTransferTable(guint32 color, std::vector const &values) : ComponentTransfer(color) , _v(values.size()) @@ -55,49 +77,17 @@ struct ComponentTransferTable : public ComponentTransfer { } guint32 operator()(guint32 in) { guint32 component = (in & _mask) >> _shift; - guint32 alpha = (in & 0xff000000) >> 24; - if (alpha == 0) return in; - - component = (255 * component + alpha/2) / alpha; guint32 k = (_v.size() - 1) * component; guint32 dx = k % 255; k /= 255; component = _v[k]*255 + (_v[k+1] - _v[k])*dx; component = (component + 127) / 255; - component = premul_alpha(component, alpha); return (in & ~_mask) | (component << _shift); } private: std::vector _v; }; -template <> -struct ComponentTransferTable { - ComponentTransferTable(std::vector const &values) - : _v(values.size()) - { - for (unsigned i = 0; i< values.size(); ++i) { - _v[i] = round(CLAMP(values[i], 0.0, 1.0) * 255); - } - } - guint32 operator()(guint32 in) { - guint32 alpha = (in & 0xff000000) >> 24; - if (alpha == 0) return in; - - guint32 k = (_v.size() - 1) * alpha; - guint32 dx = k % 255; k /= 255; - alpha = _v[k]*255 + (_v[k+1] - _v[k])*dx; - alpha = (alpha + 127) / 255; - return (in & 0x00ffffff) | (alpha << 24); - } -private: - std::vector _v; -}; - -template -struct ComponentTransferDiscrete; - -template <> -struct ComponentTransferDiscrete : public ComponentTransfer { +struct ComponentTransferDiscrete : public ComponentTransfer { ComponentTransferDiscrete(guint32 color, std::vector const &values) : ComponentTransfer(color) , _v(values.size()) @@ -108,45 +98,15 @@ struct ComponentTransferDiscrete : public ComponentTransfer { } guint32 operator()(guint32 in) { guint32 component = (in & _mask) >> _shift; - guint32 alpha = (in & 0xff000000) >> 24; - if (alpha == 0) return in; - - component = (255 * component + alpha/2) / alpha; - guint32 k = (_v.size() - 1) * component / 255; + guint32 k = (_v.size()) * component / 255; component = _v[k]; - component = premul_alpha(component, alpha); - return (in & ~_mask) | (component << _shift); + return (in & ~_mask) | ((guint32)component << _shift); } private: std::vector _v; }; -template <> -struct ComponentTransferDiscrete { - ComponentTransferDiscrete(std::vector const &values) - : _v(values.size()) - { - for (unsigned i = 0; i< values.size(); ++i) { - _v[i] = round(CLAMP(values[i], 0.0, 1.0) * 255); - } - } - guint32 operator()(guint32 in) { - guint32 alpha = (in & 0xff000000) >> 24; - if (alpha == 0) return in; - - guint32 k = (_v.size() - 1) * alpha / 255; - alpha = _v[k]; - return (in & 0x00ffffff) | (alpha << 24); - } -private: - std::vector _v; -}; - -template -struct ComponentTransferLinear; - -template <> -struct ComponentTransferLinear : public ComponentTransfer { +struct ComponentTransferLinear : public ComponentTransfer { ComponentTransferLinear(guint32 color, double intercept, double slope) : ComponentTransfer(color) , _intercept(round(intercept*255*255)) @@ -154,14 +114,10 @@ struct ComponentTransferLinear : public ComponentTransfer { {} guint32 operator()(guint32 in) { gint32 component = (in & _mask) >> _shift; - guint32 alpha = (in & 0xff000000) >> 24; - if (alpha == 0) return 0; // TODO: this can probably be reduced to something simpler - component = (255 * component + alpha/2) / alpha; component = pxclamp(_slope * component + _intercept, 0, 255*255); component = (component + 127) / 255; - component = premul_alpha(component, alpha); return (in & ~_mask) | (component << _shift); } private: @@ -169,28 +125,7 @@ private: gint32 _slope; }; -template <> -struct ComponentTransferLinear { - ComponentTransferLinear(double intercept, double slope) - : _intercept(round(intercept*255*255)) - , _slope(round(slope*255)) - {} - guint32 operator()(guint32 in) { - gint32 alpha = (in & 0xff000000) >> 24; - alpha = pxclamp(_slope * alpha + _intercept, 0, 255*255); - alpha = (alpha + 127) / 255; - return (in & 0x00ffffff) | (alpha << 24); - } -private: - gint32 _intercept; - gint32 _slope; -}; - -template -struct ComponentTransferGamma; - -template <> -struct ComponentTransferGamma : public ComponentTransfer { +struct ComponentTransferGamma : public ComponentTransfer { ComponentTransferGamma(guint32 color, double amplitude, double exponent, double offset) : ComponentTransfer(color) , _amplitude(amplitude) @@ -199,13 +134,9 @@ struct ComponentTransferGamma : public ComponentTransfer { {} guint32 operator()(guint32 in) { double component = (in & _mask) >> _shift; - guint32 alpha = (in & 0xff000000) >> 24; - if (alpha == 0) return 0; - - double alphaf = alpha; - component /= alphaf; + component /= 255.0; component = _amplitude * pow(component, _exponent) + _offset; - guint32 cpx = pxclamp(component * alphaf, 0, 255); + guint32 cpx = pxclamp(component * 255.0, 0, 255); return (in & ~_mask) | (cpx << _shift); } private: @@ -214,26 +145,6 @@ private: double _offset; }; -template <> -struct ComponentTransferGamma { - ComponentTransferGamma(double amplitude, double exponent, double offset) - : _amplitude(amplitude) - , _exponent(exponent) - , _offset(offset) - {} - guint32 operator()(guint32 in) { - double alpha = (in & 0xff000000) >> 24; - alpha /= 255.0; - alpha = _amplitude * pow(alpha, _exponent) + _offset; - guint32 cpx = pxclamp(alpha * 255.0, 0, 255); - return (in & 0x00ffffff) | (cpx << 24); - } -private: - double _amplitude; - double _exponent; - double _offset; -}; - void FilterComponentTransfer::render_cairo(FilterSlot &slot) { cairo_surface_t *input = slot.getcairo(_input); @@ -252,31 +163,38 @@ void FilterComponentTransfer::render_cairo(FilterSlot &slot) //cairo_surface_t *outtemp = ink_cairo_surface_create_identical(out); ink_cairo_surface_blit(input, out); + // We need to operate on unmultipled by alpha color values otherwise a change in alpha screws + // up the premultiplied by alpha r, g, b values. + ink_cairo_surface_filter(out, out, UnmultiplyAlpha()); + // parameters: R = 0, G = 1, B = 2, A = 3 // Cairo: R = 2, G = 1, B = 0, A = 3 // If tableValues is empty, use identity. - for (unsigned i = 0; i < 3; ++i) { + for (unsigned i = 0; i < 4; ++i) { + guint32 color = 2 - i; + if(i==3) color = 3; // alpha + switch (type[i]) { case COMPONENTTRANSFER_TYPE_TABLE: if(!tableValues[i].empty()) { ink_cairo_surface_filter(out, out, - ComponentTransferTable(color, tableValues[i])); + ComponentTransferTable(color, tableValues[i])); } break; case COMPONENTTRANSFER_TYPE_DISCRETE: if(!tableValues[i].empty()) { ink_cairo_surface_filter(out, out, - ComponentTransferDiscrete(color, tableValues[i])); + ComponentTransferDiscrete(color, tableValues[i])); } break; case COMPONENTTRANSFER_TYPE_LINEAR: ink_cairo_surface_filter(out, out, - ComponentTransferLinear(color, intercept[i], slope[i])); + ComponentTransferLinear(color, intercept[i], slope[i])); break; case COMPONENTTRANSFER_TYPE_GAMMA: ink_cairo_surface_filter(out, out, - ComponentTransferGamma(color, amplitude[i], exponent[i], offset[i])); + ComponentTransferGamma(color, amplitude[i], exponent[i], offset[i])); break; case COMPONENTTRANSFER_TYPE_ERROR: case COMPONENTTRANSFER_TYPE_IDENTITY: @@ -286,33 +204,7 @@ void FilterComponentTransfer::render_cairo(FilterSlot &slot) //ink_cairo_surface_blit(out, outtemp); } - // fast paths for alpha channel - switch (type[3]) { - case COMPONENTTRANSFER_TYPE_TABLE: - if(!tableValues[3].empty()) { - ink_cairo_surface_filter(out, out, - ComponentTransferTable(tableValues[3])); - } - break; - case COMPONENTTRANSFER_TYPE_DISCRETE: - if(!tableValues[3].empty()) { - ink_cairo_surface_filter(out, out, - ComponentTransferDiscrete(tableValues[3])); - } - break; - case COMPONENTTRANSFER_TYPE_LINEAR: - ink_cairo_surface_filter(out, out, - ComponentTransferLinear(intercept[3], slope[3])); - break; - case COMPONENTTRANSFER_TYPE_GAMMA: - ink_cairo_surface_filter(out, out, - ComponentTransferGamma(amplitude[3], exponent[3], offset[3])); - break; - case COMPONENTTRANSFER_TYPE_ERROR: - case COMPONENTTRANSFER_TYPE_IDENTITY: - default: - break; - } + ink_cairo_surface_filter(out, out, MultiplyAlpha()); slot.set(_output, out); cairo_surface_destroy(out); -- cgit v1.2.3 From 4d2fef1da189759823cf4792e4d9f875fbb1d2c6 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 14 Dec 2015 16:31:46 +0100 Subject: Small bug fix related to previous check-in. (bzr r14533) --- src/display/nr-filter-component-transfer.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/display') diff --git a/src/display/nr-filter-component-transfer.cpp b/src/display/nr-filter-component-transfer.cpp index dd37ab873..b2545b76f 100644 --- a/src/display/nr-filter-component-transfer.cpp +++ b/src/display/nr-filter-component-transfer.cpp @@ -99,6 +99,7 @@ struct ComponentTransferDiscrete : public ComponentTransfer { guint32 operator()(guint32 in) { guint32 component = (in & _mask) >> _shift; guint32 k = (_v.size()) * component / 255; + if( k == _v.size() ) --k; component = _v[k]; return (in & ~_mask) | ((guint32)component << _shift); } -- cgit v1.2.3 From 6f817f71119774c09888fddf8ba28a96c4546165 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 21 Dec 2015 10:48:56 +0100 Subject: Add option for checkerboard background. Fixed bugs: - https://launchpad.net/bugs/397723 (bzr r14539) --- src/display/sodipodi-ctrlrect.cpp | 15 +++++++++++++++ src/display/sodipodi-ctrlrect.h | 3 +++ 2 files changed, 18 insertions(+) (limited to 'src/display') diff --git a/src/display/sodipodi-ctrlrect.cpp b/src/display/sodipodi-ctrlrect.cpp index 75789ff50..ecc952c48 100644 --- a/src/display/sodipodi-ctrlrect.cpp +++ b/src/display/sodipodi-ctrlrect.cpp @@ -74,6 +74,8 @@ void CtrlRect::init() { _has_fill = false; _dashed = false; + _checkerboard = false; + _shadow = 0; _area = Geom::OptIntRect(); @@ -109,10 +111,17 @@ void CtrlRect::render(SPCanvasBuf *buf) cairo_rectangle(buf->ct, 0.5 + area[X].min(), 0.5 + area[Y].min(), area[X].max() - area[X].min(), area[Y].max() - area[Y].min()); + if (_checkerboard) { + cairo_pattern_t *cb = ink_cairo_pattern_create_checkerboard(); + cairo_set_source(buf->ct, cb); + cairo_pattern_destroy(cb); + cairo_fill_preserve(buf->ct); + } if (_has_fill) { ink_cairo_set_source_rgba32(buf->ct, _fill_color); cairo_fill_preserve(buf->ct); } + ink_cairo_set_source_rgba32(buf->ct, _border_color); cairo_stroke(buf->ct); @@ -297,6 +306,12 @@ void CtrlRect::setDashed(bool d) _requestUpdate(); } +void CtrlRect::setCheckerboard(bool d) +{ + _checkerboard = d; + _requestUpdate(); +} + void CtrlRect::_requestUpdate() { sp_canvas_item_request_update(SP_CANVAS_ITEM(this)); diff --git a/src/display/sodipodi-ctrlrect.h b/src/display/sodipodi-ctrlrect.h index ff6c55b06..08a085649 100644 --- a/src/display/sodipodi-ctrlrect.h +++ b/src/display/sodipodi-ctrlrect.h @@ -39,6 +39,7 @@ public: void setShadow(int s, guint c); void setRectangle(Geom::Rect const &r); void setDashed(bool d); + void setCheckerboard(bool d); void render(SPCanvasBuf *buf); void update(Geom::Affine const &affine, unsigned int flags); @@ -49,6 +50,8 @@ private: Geom::Rect _rect; bool _has_fill; bool _dashed; + bool _checkerboard; + Geom::OptIntRect _area; gint _shadow_size; guint32 _border_color; -- cgit v1.2.3 From cbf36bcb4c4458c0eb9db0f4ffdf158611ee52c8 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 15 Jan 2016 11:16:12 +0100 Subject: More subtle checkerboard pattern centered around 50% gray. Makes editing nodes more visible. Note, input values are in sRGB. (bzr r14584) --- src/display/cairo-utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/display') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 59e190676..24a75de4c 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -1120,9 +1120,9 @@ ink_cairo_pattern_create_checkerboard() cairo_t *ct = cairo_create(s); cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); - cairo_set_source_rgb(ct, 0.75, 0.75, 0.75); + cairo_set_source_rgb(ct, 0.77, 0.77, 0.77); cairo_paint(ct); - cairo_set_source_rgb(ct, 0.5, 0.5, 0.5); + cairo_set_source_rgb(ct, 0.69, 0.69, 0.69); cairo_rectangle(ct, 0, 0, w, h); cairo_rectangle(ct, w, h, w, h); cairo_fill(ct); -- cgit v1.2.3 From 1aa94f627221dff927966c6df8f9e53d917b57df Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Fri, 15 Jan 2016 22:17:48 -0500 Subject: Remove buggy and presumptuous usage of SP_ACTIVE_DESKTOP in renderer code; fixes 1526701 Fixed bugs: - https://launchpad.net/bugs/1526701 (bzr r14585.1.1) --- src/display/guideline.cpp | 48 +++++++++++++++++++++-------------------------- src/display/guideline.h | 5 +++-- 2 files changed, 24 insertions(+), 29 deletions(-) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 4b573a586..00fcfea6a 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -17,13 +17,8 @@ #include <2geom/coord.h> #include <2geom/transforms.h> #include "sp-canvas-util.h" -#include "knot.h" #include "guideline.h" #include "display/cairo-utils.h" - -#include "inkscape.h" // for inkscape_active_desktop() -#include "desktop.h" -#include "sp-namedview.h" #include "display/sp-canvas.h" #include "display/sodipodi-ctrl.h" #include "ui/control-manager.h" @@ -37,7 +32,7 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf); static double sp_guideline_point(SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item); -static gboolean sp_guideline_origin_move(SPKnot *knot, Geom::Point *position, guint state, SPGuideLine *data); +//static gboolean sp_guideline_origin_move(SPKnot *knot, Geom::Point *position, guint state, SPGuideLine *data); static void sp_guideline_drawline (SPCanvasBuf *buf, gint x0, gint y0, gint x1, gint y1, guint32 rgba); G_DEFINE_TYPE(SPGuideLine, sp_guideline, SP_TYPE_CANVAS_ITEM); @@ -72,8 +67,8 @@ static void sp_guideline_destroy(SPCanvasItem *object) SPGuideLine *gl = SP_GUIDELINE(object); - if (gl->origin != NULL && SP_IS_KNOT(gl->origin)) { - knot_unref(gl->origin); + if (gl->origin) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(gl->origin)); } if (gl->label) { @@ -172,28 +167,19 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, if ((SP_CANVAS_ITEM_CLASS(sp_guideline_parent_class))->update) { (SP_CANVAS_ITEM_CLASS(sp_guideline_parent_class))->update(item, affine, flags); } - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (desktop && item->visible) { - if (!gl->origin) { - gl->origin = new SPKnot(desktop, "No tip yet!! XXX"); - - gl->origin->setAnchor(SP_ANCHOR_CENTER); - gl->origin->setMode(SP_CTRL_MODE_COLOR); - gl->origin->setFill(0xffffff80, 0xffffffff, 0xffffff80); - gl->origin->request_signal.connect(sigc::bind(sigc::ptr_fun(sp_guideline_origin_move), gl)); - } + if (item->visible) { if (gl->locked) { - gl->origin->setStroke(0x0000ff88, 0x0000ff88, 0x0000ff88); - gl->origin->setShape(SP_CTRL_SHAPE_CROSS); - gl->origin->setSize(6); + g_object_set(G_OBJECT(gl->origin), "stroke_color", 0x0000ff88, + "shape", SP_CTRL_SHAPE_CROSS, + "size", 6., NULL); } else { - gl->origin->setStroke(0xff000088, 0xff0000ff, 0xff0000ff); - gl->origin->setShape(SP_CTRL_SHAPE_CIRCLE); - gl->origin->setSize(4); + g_object_set(G_OBJECT(gl->origin), "stroke_color", 0xff000088, + "shape", SP_CTRL_SHAPE_CIRCLE, + "size", 4., NULL); } gl->origin->moveto(gl->point_on_line); - gl->origin->updateCtrl(); + sp_canvas_item_request_update(SP_CANVAS_ITEM(gl->origin)); } gl->affine = affine; @@ -236,17 +222,24 @@ SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point p gl->angle = tan( -gl->normal_to_line[Geom::X] / gl->normal_to_line[Geom::Y]); sp_guideline_set_position(gl, point_on_line); + gl->origin = (SPCtrl *)sp_canvas_item_new(parent, SP_TYPE_CTRL, NULL); + g_object_set(G_OBJECT(gl->origin), "anchor", SP_ANCHOR_CENTER, + "mode", SP_CTRL_MODE_COLOR, + "filled", FALSE, + "stroked", TRUE, + "stroke_color", 0x01000000, NULL); + return item; } -static gboolean sp_guideline_origin_move(SPKnot *knot, Geom::Point *position, guint state, SPGuideLine *gl) +/*static gboolean sp_guideline_origin_move(SPKnot *knot, Geom::Point *position, guint state, SPGuideLine *gl) { if(gl->locked) { return true; } sp_guideline_set_position(gl, *position); return false; -} +}*/ void sp_guideline_set_label(SPGuideLine *gl, const char* label) { @@ -281,6 +274,7 @@ void sp_guideline_set_normal(SPGuideLine *gl, Geom::Point normal_to_line) void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba) { gl->rgba = rgba; + g_object_set(G_OBJECT(gl->origin), "stroke_color", rgba, NULL); sp_canvas_item_request_update(SP_CANVAS_ITEM(gl)); } diff --git a/src/display/guideline.h b/src/display/guideline.h index d58821fc8..44aed88d9 100644 --- a/src/display/guideline.h +++ b/src/display/guideline.h @@ -16,17 +16,18 @@ #include <2geom/point.h> #include "sp-canvas-item.h" -#include "knot.h" #define SP_TYPE_GUIDELINE (sp_guideline_get_type()) #define SP_GUIDELINE(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_GUIDELINE, SPGuideLine)) #define SP_IS_GUIDELINE(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_GUIDELINE)) +struct SPCtrl; + struct SPGuideLine { SPCanvasItem item; Geom::Affine affine; - SPKnot *origin; // unlike 'item', this is only held locally + SPCtrl *origin; // unlike 'item', this is only held locally guint32 rgba; -- cgit v1.2.3 From b4153318caa10997f2288bba57fce9fab106b0dc Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Fri, 15 Jan 2016 22:19:49 -0500 Subject: Dead code cleanup (bzr r14585.1.2) --- src/display/guideline.cpp | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 00fcfea6a..b3b0869b6 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -32,7 +32,6 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf); static double sp_guideline_point(SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item); -//static gboolean sp_guideline_origin_move(SPKnot *knot, Geom::Point *position, guint state, SPGuideLine *data); static void sp_guideline_drawline (SPCanvasBuf *buf, gint x0, gint y0, gint x1, gint y1, guint32 rgba); G_DEFINE_TYPE(SPGuideLine, sp_guideline, SP_TYPE_CANVAS_ITEM); @@ -232,15 +231,6 @@ SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point p return item; } -/*static gboolean sp_guideline_origin_move(SPKnot *knot, Geom::Point *position, guint state, SPGuideLine *gl) -{ - if(gl->locked) { - return true; - } - sp_guideline_set_position(gl, *position); - return false; -}*/ - void sp_guideline_set_label(SPGuideLine *gl, const char* label) { if (gl->label) { -- cgit v1.2.3 From 99c7ac2b88a264d1415dacb073b5b1a8da4bf85e Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Sat, 16 Jan 2016 10:56:00 -0500 Subject: Header cleanup (bzr r14585.1.3) --- src/display/guideline.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index b3b0869b6..d34112046 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -21,9 +21,6 @@ #include "display/cairo-utils.h" #include "display/sp-canvas.h" #include "display/sodipodi-ctrl.h" -#include "ui/control-manager.h" - -using Inkscape::ControlManager; static void sp_guideline_destroy(SPCanvasItem *object); -- cgit v1.2.3 From d7f53de7a19a00bf0f01f4824498ae64d9cd12a6 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Sat, 16 Jan 2016 11:13:25 -0500 Subject: Coalesce g_object_new/g_object_set calls; change guide origin pickable to false so that guides can be grabbed by the origin again (bzr r14593) --- src/display/guideline.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/display') diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index d34112046..126fcf87c 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -218,12 +218,13 @@ SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point p gl->angle = tan( -gl->normal_to_line[Geom::X] / gl->normal_to_line[Geom::Y]); sp_guideline_set_position(gl, point_on_line); - gl->origin = (SPCtrl *)sp_canvas_item_new(parent, SP_TYPE_CTRL, NULL); - g_object_set(G_OBJECT(gl->origin), "anchor", SP_ANCHOR_CENTER, - "mode", SP_CTRL_MODE_COLOR, - "filled", FALSE, - "stroked", TRUE, - "stroke_color", 0x01000000, NULL); + gl->origin = (SPCtrl *) sp_canvas_item_new(parent, SP_TYPE_CTRL, + "anchor", SP_ANCHOR_CENTER, + "mode", SP_CTRL_MODE_COLOR, + "filled", FALSE, + "stroked", TRUE, + "stroke_color", 0x01000000, NULL); + gl->origin->pickable = false; return item; } -- cgit v1.2.3 From 90577b7848b02830973da377bc9ceff09aa1f039 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Sun, 17 Jan 2016 11:05:43 -0500 Subject: Follow-up commit to 14529. From std::list documentation: list::insert - The container is extended by inserting new elements before the element at the specified position. (bzr r14601) --- src/display/sp-canvas.cpp | 73 ++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 33 deletions(-) (limited to 'src/display') diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 6441ea68b..e94133b28 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -109,7 +109,7 @@ struct SPCanvasGroup { SPCanvasItem item; - std::list *items; + std::list items; }; @@ -603,14 +603,14 @@ void sp_canvas_item_raise(SPCanvasItem *item, int positions) } SPCanvasGroup *parent = SP_CANVAS_GROUP (item->parent); - std::list::iterator l = std::find(parent->items->begin(),parent->items->end(), item); - g_assert (l != parent->items->end()); + std::list::iterator l = std::find(parent->items.begin(),parent->items.end(), item); + g_assert (l != parent->items.end()); - for (int i=0; iitems->end(); ++i) + for (int i=0; iitems.end(); ++i) l++; - parent->items->remove(item); - parent->items->insert(l, item); + parent->items.remove(item); + parent->items.insert(++l, item); redraw_if_visible (item); item->canvas->need_repick = TRUE; @@ -623,8 +623,8 @@ void sp_canvas_item_raise_to_top(SPCanvasItem *item) if (!item->parent) return; SPCanvasGroup *parent = SP_CANVAS_GROUP (item->parent); - parent->items->remove(item); - parent->items->insert(parent->items->end(),item); + parent->items.remove(item); + parent->items.push_back(item); redraw_if_visible (item); item->canvas->need_repick = TRUE; } @@ -646,23 +646,25 @@ void sp_canvas_item_lower(SPCanvasItem *item, int positions) g_return_if_fail (SP_IS_CANVAS_ITEM (item)); g_return_if_fail (positions >= 1); - if (!item->parent || positions == 0 || item == SP_CANVAS_GROUP(item->parent)->items->front() ) { + SPCanvasGroup *parent = SP_CANVAS_GROUP(item->parent); + + if (!parent || positions == 0 || item == parent->items.front() ) { return; } - SPCanvasGroup *parent = SP_CANVAS_GROUP (item->parent); - std::list::iterator l = std::find(parent->items->begin(),parent->items->end(), item); - g_assert (l != parent->items->end()); + std::list::iterator l = std::find(parent->items.begin(), parent->items.end(), item); + g_assert (l != parent->items.end()); - for (int i=0; iitems->begin(); ++i) + for (int i=0; iitems.begin(); ++i) l--; - parent->items->remove(item); - parent->items->insert(l, item); + parent->items.remove(item); + parent->items.insert(l, item); redraw_if_visible (item); item->canvas->need_repick = TRUE; } + void sp_canvas_item_lower_to_bottom(SPCanvasItem *item) { g_return_if_fail (item != NULL); @@ -670,15 +672,15 @@ void sp_canvas_item_lower_to_bottom(SPCanvasItem *item) if (!item->parent) return; SPCanvasGroup *parent = SP_CANVAS_GROUP (item->parent); - parent->items->remove(item); - parent->items->insert(parent->items->begin(),item); + parent->items.remove(item); + parent->items.push_front(item); redraw_if_visible (item); item->canvas->need_repick = TRUE; } bool sp_canvas_item_is_visible(SPCanvasItem *item) { - return item->visible; + return item->visible; } /** @@ -872,7 +874,14 @@ void sp_canvas_item_request_update(SPCanvasItem *item) gint sp_canvas_item_order (SPCanvasItem * item) { SPCanvasGroup * p = SP_CANVAS_GROUP(item->parent); - return std::distance(p->items->begin(), std::find(p->items->begin(), p->items->end(), item)); + size_t index = 0; + for (std::list::const_iterator it = p->items.begin(); it != p->items.end(); ++it, ++index) { + if ((*it) == item) { + return index; + } + } + + return -1; } // SPCanvasGroup @@ -891,7 +900,7 @@ static void sp_canvas_group_class_init(SPCanvasGroupClass *klass) static void sp_canvas_group_init(SPCanvasGroup * group) { - group->items = new std::list; + new (&group->items) std::list; } void SPCanvasGroup::destroy(SPCanvasItem *object) @@ -899,16 +908,14 @@ void SPCanvasGroup::destroy(SPCanvasItem *object) g_return_if_fail(object != NULL); g_return_if_fail(SP_IS_CANVAS_GROUP(object)); - SPCanvasGroup const *group = SP_CANVAS_GROUP(object); + SPCanvasGroup *group = SP_CANVAS_GROUP(object); - std::list *list = group->items; - for (std::list::iterator it = list->begin(); it != list->end(); ++it) { - SPCanvasItem *child = *it; - sp_canvas_item_destroy(child); + for (std::list::iterator it = group->items.begin(); it != group->items.end(); ++it) { + sp_canvas_item_destroy(*it); } - group->items->clear(); - delete group->items; + group->items.clear(); + group->items.~list(); // invoke manually if (SP_CANVAS_ITEM_CLASS(sp_canvas_group_parent_class)->destroy) { (* SP_CANVAS_ITEM_CLASS(sp_canvas_group_parent_class)->destroy)(object); @@ -920,7 +927,7 @@ void SPCanvasGroup::update(SPCanvasItem *item, Geom::Affine const &affine, unsig SPCanvasGroup const *group = SP_CANVAS_GROUP(item); Geom::OptRect bounds; - for (std::list::const_iterator it = group->items->begin(); it != group->items->end(); ++it) { + for (std::list::const_iterator it = group->items.begin(); it != group->items.end(); ++it) { SPCanvasItem *i = *it; sp_canvas_item_invoke_update (i, affine, flags); @@ -956,7 +963,7 @@ double SPCanvasGroup::point(SPCanvasItem *item, Geom::Point p, SPCanvasItem **ac *actual_item = NULL; double dist = 0.0; - for (std::list::const_iterator it = group->items->begin(); it != group->items->end(); ++it) { + for (std::list::const_iterator it = group->items.begin(); it != group->items.end(); ++it) { SPCanvasItem *child = *it; if ((child->x1 <= x2) && (child->y1 <= y2) && (child->x2 >= x1) && (child->y2 >= y1)) { @@ -990,7 +997,7 @@ void SPCanvasGroup::render(SPCanvasItem *item, SPCanvasBuf *buf) { SPCanvasGroup const *group = SP_CANVAS_GROUP(item); - for (std::list::const_iterator it = group->items->begin(); it != group->items->end(); ++it) { + for (std::list::const_iterator it = group->items.begin(); it != group->items.end(); ++it) { SPCanvasItem *child = *it; if (child->visible) { if ((child->x1 < buf->rect.right()) && @@ -1009,7 +1016,7 @@ void SPCanvasGroup::viewboxChanged(SPCanvasItem *item, Geom::IntRect const &new_ { SPCanvasGroup *group = SP_CANVAS_GROUP(item); - for (std::list::const_iterator it = group->items->begin(); it != group->items->end(); ++it) { + for (std::list::const_iterator it = group->items.begin(); it != group->items.end(); ++it) { SPCanvasItem *child = *it; if (child->visible) { if (SP_CANVAS_ITEM_GET_CLASS(child)->viewbox_changed) { @@ -1024,7 +1031,7 @@ void SPCanvasGroup::add(SPCanvasItem *item) g_object_ref(item); g_object_ref_sink(item); - items->push_back(item); + items.push_back(item); sp_canvas_item_request_update(item); } @@ -1033,7 +1040,7 @@ void SPCanvasGroup::remove(SPCanvasItem *item) { g_return_if_fail(item != NULL); - items->remove(item); + items.remove(item); // Unparent the child item->parent = NULL; -- cgit v1.2.3 From dc064a944edab7902196389912222b63826ee3a9 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Sun, 17 Jan 2016 11:17:12 -0500 Subject: Less derp, can't iterate past the end of the list (bzr r14602) --- src/display/sp-canvas.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/display') diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index e94133b28..f33428295 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -606,11 +606,11 @@ void sp_canvas_item_raise(SPCanvasItem *item, int positions) std::list::iterator l = std::find(parent->items.begin(),parent->items.end(), item); g_assert (l != parent->items.end()); - for (int i=0; iitems.end(); ++i) + for (int i=0; i<=positions && l != parent->items.end(); ++i) l++; parent->items.remove(item); - parent->items.insert(++l, item); + parent->items.insert(l, item); redraw_if_visible (item); item->canvas->need_repick = TRUE; -- cgit v1.2.3 From 0a2477feea6e1df586b926b8482afbf79e2355e1 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 7 Feb 2016 23:32:51 -0800 Subject: Sync 2Geom to commit 5ee51c1c4f2066faa3e2c82021fc92671ad44ba4 (bzr r14639) --- src/display/canvas-axonomgrid.cpp | 8 ++++---- src/display/nr-filter.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/display') diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 1794ccbab..14f36376f 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -172,9 +172,9 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r angle_deg[Z] = prefs->getDouble("/options/grids/axonom/angle_z", 30.0); angle_deg[Y] = 0; - angle_rad[X] = Geom::deg_to_rad(angle_deg[X]); + angle_rad[X] = Geom::rad_from_deg(angle_deg[X]); tan_angle[X] = tan(angle_rad[X]); - angle_rad[Z] = Geom::deg_to_rad(angle_deg[Z]); + angle_rad[Z] = Geom::rad_from_deg(angle_deg[Z]); tan_angle[Z] = tan(angle_rad[Z]); snapper = new CanvasAxonomGridSnapper(this, &namedview->snap_manager, 0); @@ -272,7 +272,7 @@ CanvasAxonomGrid::readRepr() angle_deg[X] = g_ascii_strtod(value, NULL); if (angle_deg[X] < 0.) angle_deg[X] = 0.; if (angle_deg[X] > 89.0) angle_deg[X] = 89.0; - angle_rad[X] = Geom::deg_to_rad(angle_deg[X]); + angle_rad[X] = Geom::rad_from_deg(angle_deg[X]); tan_angle[X] = tan(angle_rad[X]); } @@ -280,7 +280,7 @@ CanvasAxonomGrid::readRepr() angle_deg[Z] = g_ascii_strtod(value, NULL); if (angle_deg[Z] < 0.) angle_deg[Z] = 0.; if (angle_deg[Z] > 89.0) angle_deg[Z] = 89.0; - angle_rad[Z] = Geom::deg_to_rad(angle_deg[Z]); + angle_rad[Z] = Geom::rad_from_deg(angle_deg[Z]); tan_angle[Z] = tan(angle_rad[Z]); } diff --git a/src/display/nr-filter.cpp b/src/display/nr-filter.cpp index dec5b1f57..8591be7eb 100644 --- a/src/display/nr-filter.cpp +++ b/src/display/nr-filter.cpp @@ -200,7 +200,7 @@ void Filter::area_enlarge(Geom::IntRect &bbox, Inkscape::DrawingItem const *item Geom::Rect item_bbox; Geom::OptRect maybe_bbox = item->itemBounds(); - if (maybe_bbox.isEmpty()) { + if (maybe_bbox.empty()) { // Code below needs a bounding box return; } -- cgit v1.2.3 From 225c64ac7604b0d64c93702c723d52b7d53539e1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 10 Feb 2016 12:02:21 +0100 Subject: Remove artifacts when remove canvas items, for example in measure tool (bzr r14645) --- src/display/sp-canvas.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/display') diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index f33428295..22765cb9d 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -419,7 +419,7 @@ static void redraw_if_visible(SPCanvasItem *item) int y1 = (int)(item->y2); if (x0 !=0 || x1 !=0 || y0 !=0 || y1 !=0) { - item->canvas->requestRedraw((int)(item->x1), (int)(item->y1), (int)(item->x2 + 1), (int)(item->y2 + 1)); + item->canvas->requestRedraw((int)(item->x1 - 1), (int)(item->y1 -1), (int)(item->x2 + 1), (int)(item->y2 + 1)); } } } -- cgit v1.2.3 From e16f1a053c67a8c42172f5186f247f11c3b6e777 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 22 Feb 2016 20:49:03 +0100 Subject: static code analysis (bzr r14664) --- src/display/sp-canvas.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/display') diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 22765cb9d..ef47613e4 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -607,7 +607,7 @@ void sp_canvas_item_raise(SPCanvasItem *item, int positions) g_assert (l != parent->items.end()); for (int i=0; i<=positions && l != parent->items.end(); ++i) - l++; + ++l; parent->items.remove(item); parent->items.insert(l, item); @@ -656,7 +656,7 @@ void sp_canvas_item_lower(SPCanvasItem *item, int positions) g_assert (l != parent->items.end()); for (int i=0; iitems.begin(); ++i) - l--; + ++l; parent->items.remove(item); parent->items.insert(l, item); -- cgit v1.2.3 From df60915bd9b41940cd58b5d0016e7746cf85cb95 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 29 Feb 2016 18:37:19 +0100 Subject: type in commit r14664 (bzr r14676) --- src/display/sp-canvas.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/display') diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index ef47613e4..d17271752 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -656,7 +656,7 @@ void sp_canvas_item_lower(SPCanvasItem *item, int positions) g_assert (l != parent->items.end()); for (int i=0; iitems.begin(); ++i) - ++l; + --l; parent->items.remove(item); parent->items.insert(l, item); -- cgit v1.2.3