From 087ea4c5f3876e15e95224e98349a6f0710d0e53 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sat, 27 Jan 2018 21:51:57 +0100 Subject: [PATCH] canvas: Refactor with C++11 --- simgear/canvas/Canvas.cxx | 26 +-- simgear/canvas/Canvas.hxx | 24 +-- simgear/canvas/CanvasWindow.cxx | 9 +- simgear/canvas/CanvasWindow.hxx | 6 +- simgear/canvas/elements/CanvasElement.cxx | 29 ++-- simgear/canvas/elements/CanvasElement.hxx | 19 ++- simgear/canvas/elements/CanvasGroup.cxx | 17 +- simgear/canvas/elements/CanvasImage.cxx | 8 +- simgear/canvas/elements/CanvasImage.hxx | 8 +- simgear/canvas/elements/CanvasMap.cxx | 53 +++--- simgear/canvas/elements/CanvasMap.hxx | 30 ++-- simgear/canvas/elements/CanvasPath.cxx | 198 +++++++++++----------- simgear/canvas/elements/CanvasPath.hxx | 6 +- simgear/props/PropertyBasedElement.cxx | 4 +- simgear/props/PropertyBasedElement.hxx | 17 +- 15 files changed, 211 insertions(+), 243 deletions(-) diff --git a/simgear/canvas/Canvas.cxx b/simgear/canvas/Canvas.cxx index a94dd679..1beef721 100644 --- a/simgear/canvas/Canvas.cxx +++ b/simgear/canvas/Canvas.cxx @@ -22,8 +22,10 @@ #include "CanvasEventManager.hxx" #include "CanvasEventVisitor.hxx" #include "CanvasPlacement.hxx" + #include #include +#include #include #include @@ -32,9 +34,6 @@ #include #include -#include -#include - namespace simgear { namespace canvas @@ -64,18 +63,9 @@ namespace canvas //---------------------------------------------------------------------------- Canvas::Canvas(SGPropertyNode* node): PropertyBasedElement(node), - _canvas_mgr(0), _event_manager(new EventManager), - _size_x(-1), - _size_y(-1), - _view_width(-1), - _view_height(-1), _status(node, "status"), - _status_msg(node, "status-msg"), - _sampling_dirty(false), - _render_dirty(true), - _visible(true), - _render_always(false) + _status_msg(node, "status-msg") { _status = 0; setStatusFlags(MISSING_SIZE_X | MISSING_SIZE_Y); @@ -281,7 +271,7 @@ namespace canvas if( _visible || _render_always ) { - BOOST_FOREACH(CanvasWeakPtr canvas_weak, _child_canvases) + for(auto& canvas_weak: _child_canvases) { // TODO should we check if the image the child canvas is displayed // within is really visible? @@ -293,7 +283,7 @@ namespace canvas if( _render_dirty ) { // Also mark all canvases this canvas is displayed within as dirty - BOOST_FOREACH(CanvasWeakPtr canvas_weak, _parent_canvases) + for(auto& canvas_weak: _parent_canvases) { CanvasPtr canvas = canvas_weak.lock(); if( canvas ) @@ -522,8 +512,8 @@ namespace canvas { const std::string& name = node->getNameString(); - if( boost::starts_with(name, "status") - || boost::starts_with(name, "data-") ) + if( strutils::starts_with(name, "status") + || strutils::starts_with(name, "data-") ) return; _render_dirty = true; @@ -538,7 +528,7 @@ namespace canvas if( !placements.empty() ) { bool placement_dirty = false; - BOOST_FOREACH(PlacementPtr& placement, placements) + for(auto& placement: placements) { // check if change can be directly handled by placement if( placement->getProps() == node->getParent() diff --git a/simgear/canvas/Canvas.hxx b/simgear/canvas/Canvas.hxx index efcb0a47..6e02b247 100644 --- a/simgear/canvas/Canvas.hxx +++ b/simgear/canvas/Canvas.hxx @@ -33,7 +33,7 @@ #include #include -#include +#include #include namespace simgear @@ -211,21 +211,21 @@ namespace canvas protected: - CanvasMgr *_canvas_mgr; + CanvasMgr *_canvas_mgr {nullptr}; - boost::scoped_ptr _event_manager; + std::unique_ptr _event_manager; - int _size_x, - _size_y, - _view_width, - _view_height; + int _size_x {-1}, + _size_y {-1}, + _view_width {-1}, + _view_height {-1}; PropertyObject _status; PropertyObject _status_msg; - bool _sampling_dirty, - _render_dirty, - _visible; + bool _sampling_dirty {false}, + _render_dirty {true}, + _visible {true}; ODGauge _texture; @@ -235,7 +235,9 @@ namespace canvas ElementWeakPtr _focus_element; CullCallbackPtr _cull_callback; - bool _render_always; //!< Used to disable automatic lazy rendering (culling) + + /** Used to disable automatic lazy rendering (culling) */ + bool _render_always {false}; std::vector _dirty_placements; std::vector _placements; diff --git a/simgear/canvas/CanvasWindow.cxx b/simgear/canvas/CanvasWindow.cxx index 46774a6e..65dc9fbb 100644 --- a/simgear/canvas/CanvasWindow.cxx +++ b/simgear/canvas/CanvasWindow.cxx @@ -22,13 +22,11 @@ #include "CanvasWindow.hxx" #include +#include #include #include -#include -#include - namespace simgear { namespace canvas @@ -43,9 +41,6 @@ namespace canvas const Style& parent_style, Element* parent ): Image(canvas, node, parent_style, parent), - _attributes_dirty(0), - _resizable(false), - _capture_events(true), _resize_top(node, "resize-top"), _resize_right(node, "resize-right"), _resize_bottom(node, "resize-bottom"), @@ -92,7 +87,7 @@ namespace canvas _capture_events = node->getBoolValue(); else if( name == "decoration-border" ) parseDecorationBorder(node->getStringValue()); - else if( boost::starts_with(name, "shadow-") + else if( strutils::starts_with(name, "shadow-") || name == "content-size" ) _attributes_dirty |= DECORATION; else diff --git a/simgear/canvas/CanvasWindow.hxx b/simgear/canvas/CanvasWindow.hxx index 330b6fb8..8d08a56a 100644 --- a/simgear/canvas/CanvasWindow.hxx +++ b/simgear/canvas/CanvasWindow.hxx @@ -104,7 +104,7 @@ namespace canvas DECORATION = 1 }; - uint32_t _attributes_dirty; + uint32_t _attributes_dirty {0}; CanvasPtr _canvas_decoration; CanvasWeakPtr _canvas_content; @@ -113,8 +113,8 @@ namespace canvas ImagePtr _image_content, _image_shadow; - bool _resizable, - _capture_events; + bool _resizable {false}, + _capture_events {true}; PropertyObject _resize_top, _resize_right, diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx index a8557a06..795a1d95 100644 --- a/simgear/canvas/elements/CanvasElement.cxx +++ b/simgear/canvas/elements/CanvasElement.cxx @@ -31,10 +31,6 @@ #include #include -#include -#include -#include - #include #include #include @@ -219,7 +215,7 @@ namespace canvas // The transform node keeps a reference on this element, so ensure it is // deleted. - BOOST_FOREACH(osg::Group* parent, _transform->getParents()) + for(osg::Group* parent: group->getParents()) { parent->removeChild(_transform.get()); } @@ -228,8 +224,8 @@ namespace canvas setVisible(false); removeListener(); - _parent = 0; - _transform = 0; + _parent = nullptr; + _transform = nullptr; } //---------------------------------------------------------------------------- @@ -341,7 +337,8 @@ namespace canvas if( listeners == _listener.end() ) return false; - BOOST_FOREACH(EventListener const& listener, listeners->second) + for(auto const& listener: listeners->second) + { try { listener(event); @@ -354,6 +351,7 @@ namespace canvas "canvas::Element: event handler error: '" << ex.what() << "'" ); } + } return true; } @@ -526,7 +524,7 @@ namespace canvas if( parent == _node ) { const std::string& name = child->getNameString(); - if( boost::starts_with(name, "data-") ) + if( strutils::starts_with(name, "data-") ) return; else if( StyleInfo const* style_info = getStyleInfo(name) ) { @@ -541,7 +539,7 @@ namespace canvas } else if( name == "update" ) return update(0); - else if( boost::starts_with(name, "blend-") ) + else if( strutils::starts_with(name, "blend-") ) return (void)(_attributes_dirty |= BLEND_FUNC); } else if( parent @@ -578,8 +576,8 @@ namespace canvas // TODO generalize CSS property parsing const std::string RECT("rect("); - if( !boost::ends_with(clip, ")") - || !boost::starts_with(clip, RECT) ) + if( !strutils::ends_with(clip, ")") + || !strutils::starts_with(clip, RECT) ) { SG_LOG(SG_GENERAL, SG_WARN, "Canvas: invalid clip: " << clip); return; @@ -791,11 +789,8 @@ namespace canvas PropertyBasedElement(node), _canvas( canvas ), _parent( parent ), - _attributes_dirty( 0 ), _transform( new osg::MatrixTransform ), - _style( parent_style ), - _scissor( 0 ), - _drawable( 0 ) + _style( parent_style ) { staticInit(); @@ -924,7 +919,7 @@ namespace canvas //---------------------------------------------------------------------------- void Element::setupStyle() { - BOOST_FOREACH( Style::value_type style, _style ) + for(auto const& style: _style) setStyle(style.second); } diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx index 8782362b..d7944b36 100644 --- a/simgear/canvas/elements/CanvasElement.hxx +++ b/simgear/canvas/elements/CanvasElement.hxx @@ -24,13 +24,13 @@ #include #include #include // for uint32_t +#include #include #include #include #include -#include namespace osg { @@ -217,13 +217,14 @@ namespace canvas */ template static - typename boost::enable_if< - boost::is_base_of, + std::enable_if_t< + std::is_base_of::value, ElementPtr - >::type create( const CanvasWeakPtr& canvas, - const SGPropertyNode_ptr& node, - const Style& style = Style(), - Element* parent = NULL ) + > + create( const CanvasWeakPtr& canvas, + const SGPropertyNode_ptr& node, + const Style& style = Style(), + Element* parent = NULL ) { return ElementPtr( new Derived(canvas, node, style, parent) ); } @@ -251,13 +252,13 @@ namespace canvas CanvasWeakPtr _canvas; ElementWeakPtr _parent; - mutable uint32_t _attributes_dirty; + mutable uint32_t _attributes_dirty = 0; osg::observer_ptr _transform; std::vector _transform_types; Style _style; - RelativeScissor *_scissor; + RelativeScissor *_scissor = nullptr; typedef std::vector Listener; typedef std::map ListenerMap; diff --git a/simgear/canvas/elements/CanvasGroup.cxx b/simgear/canvas/elements/CanvasGroup.cxx index d398fe2e..922985b8 100644 --- a/simgear/canvas/elements/CanvasGroup.cxx +++ b/simgear/canvas/elements/CanvasGroup.cxx @@ -23,13 +23,10 @@ #include "CanvasMap.hxx" #include "CanvasPath.hxx" #include "CanvasText.hxx" + #include #include -#include -#include -#include - namespace simgear { namespace canvas @@ -138,7 +135,7 @@ namespace canvas if( !_transform.valid() ) { warnTransformExpired("getElementById"); - return ElementPtr(); + return {}; } std::vector groups; @@ -153,14 +150,14 @@ namespace canvas groups.push_back(group); } - BOOST_FOREACH( GroupPtr group, groups ) + for(auto group: groups) { ElementPtr el = group->getElementById(id); if( el ) return el; } - return ElementPtr(); + return {}; } //---------------------------------------------------------------------------- @@ -323,7 +320,7 @@ namespace canvas void Group::childChanged(SGPropertyNode* node) { SGPropertyNode* parent = node->getParent(); - SGPropertyNode* grand_parent = parent ? parent->getParent() : NULL; + SGPropertyNode* grand_parent = parent ? parent->getParent() : nullptr; if( grand_parent == _node && node->getNameString() == "z-index" ) @@ -399,7 +396,7 @@ namespace canvas if( !_transform.valid() ) { warnTransformExpired("findChild"); - return ElementPtr(); + return {}; } for(size_t i = 0; i < _transform->getNumChildren(); ++i) @@ -418,7 +415,7 @@ namespace canvas } } - return ElementPtr(); + return {}; } } // namespace canvas diff --git a/simgear/canvas/elements/CanvasImage.cxx b/simgear/canvas/elements/CanvasImage.cxx index 0286a4bc..e2166b30 100644 --- a/simgear/canvas/elements/CanvasImage.cxx +++ b/simgear/canvas/elements/CanvasImage.cxx @@ -117,9 +117,7 @@ namespace canvas ElementWeakPtr parent ): Element(canvas, node, parent_style, parent), _texture(new osg::Texture2D), - _node_src_rect( node->getNode("source", 0, true) ), - _src_rect(0,0), - _region(0,0) + _node_src_rect( node->getNode("source", 0, true) ) { staticInit(); @@ -634,7 +632,9 @@ namespace canvas // Abort pending request if( _http_request ) { - Canvas::getSystemAdapter()->getHTTPClient()->cancelRequest(_http_request, "setting new image"); + Canvas::getSystemAdapter() + ->getHTTPClient() + ->cancelRequest(_http_request, "setting new image"); _http_request.reset(); } diff --git a/simgear/canvas/elements/CanvasImage.hxx b/simgear/canvas/elements/CanvasImage.hxx index b7ddfb8f..5ec50ab4 100644 --- a/simgear/canvas/elements/CanvasImage.hxx +++ b/simgear/canvas/elements/CanvasImage.hxx @@ -100,8 +100,8 @@ namespace canvas * */ void setSourceRect(const SGRect& sourceRect); - protected: + protected: enum ImageAttributes { SRC_RECT = LAST_ATTRIBUTE << 1, // Source image rectangle @@ -134,9 +134,9 @@ namespace canvas osg::ref_ptr _texCoords; osg::ref_ptr _colors; - SGPropertyNode *_node_src_rect; - SGRect _src_rect, - _region; + SGPropertyNode *_node_src_rect = nullptr; + SGRect _src_rect {0, 0}, + _region {0, 0}; SVGpreserveAspectRatio _preserve_aspect_ratio; diff --git a/simgear/canvas/elements/CanvasMap.cxx b/simgear/canvas/elements/CanvasMap.cxx index e15dc13b..2100cd31 100644 --- a/simgear/canvas/elements/CanvasMap.cxx +++ b/simgear/canvas/elements/CanvasMap.cxx @@ -18,13 +18,14 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA #include + #include "CanvasMap.hxx" #include "map/geo_node_pair.hxx" #include "map/projection.hxx" -#include +#include -#include +#include #define LOG_GEO_RET(msg) \ {\ @@ -73,13 +74,8 @@ namespace canvas Group(canvas, node, parent_style, parent) { staticInit(); - if (node->getChild(PROJECTION) && - (node->getChild(PROJECTION)->getStringValue() == WEB_MERCATOR)) { - _projection = (boost::shared_ptr) new WebMercatorProjection(); - } else { - _projection = (boost::shared_ptr) new SansonFlamsteedProjection(); - } - _projection_dirty = true; + + projectionNodeChanged(node->getChild(PROJECTION)); } //---------------------------------------------------------------------------- @@ -124,7 +120,7 @@ namespace canvas //---------------------------------------------------------------------------- void Map::childAdded(SGPropertyNode* parent, SGPropertyNode* child) { - if( boost::ends_with(child->getNameString(), GEO) ) + if( strutils::ends_with(child->getNameString(), GEO) ) _geo_nodes[child].reset(new GeoNodePair()); else if( parent != _node && child->getNameString() == HDG ) _hdg_nodes.insert(child); @@ -135,7 +131,7 @@ namespace canvas //---------------------------------------------------------------------------- void Map::childRemoved(SGPropertyNode* parent, SGPropertyNode* child) { - if( boost::ends_with(child->getNameString(), GEO) ) + if( strutils::ends_with(child->getNameString(), GEO) ) // TODO remove from other node _geo_nodes.erase(child); else if( parent != _node && child->getName() == HDG ) @@ -157,7 +153,7 @@ namespace canvas { const std::string& name = child->getNameString(); - if( boost::ends_with(name, GEO) ) + if( strutils::ends_with(name, GEO) ) return geoNodeChanged(child); else if( name == HDG ) return hdgNodeChanged(child); @@ -188,24 +184,31 @@ namespace canvas _projection->setRange(child->getDoubleValue()); else if( child->getNameString() == SCREEN_RANGE ) _projection->setScreenRange(child->getDoubleValue()); - else if( child->getNameString() == PROJECTION ) { - if (child->getStringValue() == WEB_MERCATOR) { - _projection = (boost::shared_ptr) new WebMercatorProjection(); - } else { - _projection = (boost::shared_ptr) new SansonFlamsteedProjection(); - } - _projection->setWorldPosition(_node->getDoubleValue(REF_LAT), - _node->getDoubleValue(REF_LON) ); - _projection->setOrientation(_node->getFloatValue(HDG)); - _projection->setScreenRange(_node->getDoubleValue(SCREEN_RANGE)); - _projection->setRange(_node->getDoubleValue(RANGE)); - _projection_dirty = true; - } else + else if( child->getNameString() == PROJECTION ) + projectionNodeChanged(child); + else return Group::childChanged(child); _projection_dirty = true; } + //---------------------------------------------------------------------------- + void Map::projectionNodeChanged(SGPropertyNode* child) + { + if(child && child->getStringValue() == WEB_MERCATOR) + _projection = std::make_shared(); + else + _projection = std::make_shared(); + + _projection->setWorldPosition(_node->getDoubleValue(REF_LAT), + _node->getDoubleValue(REF_LON) ); + _projection->setOrientation(_node->getFloatValue(HDG)); + _projection->setScreenRange(_node->getDoubleValue(SCREEN_RANGE)); + _projection->setRange(_node->getDoubleValue(RANGE)); + + _projection_dirty = true; + } + //---------------------------------------------------------------------------- void Map::geoNodeChanged(SGPropertyNode* child) { diff --git a/simgear/canvas/elements/CanvasMap.hxx b/simgear/canvas/elements/CanvasMap.hxx index 993d45da..f1e61ed9 100644 --- a/simgear/canvas/elements/CanvasMap.hxx +++ b/simgear/canvas/elements/CanvasMap.hxx @@ -22,9 +22,9 @@ #include "CanvasGroup.hxx" -#include -#include -#include +#include +#include +#include namespace simgear { @@ -57,33 +57,29 @@ namespace canvas virtual void childChanged(SGPropertyNode * child); - typedef boost::unordered_map< SGPropertyNode*, - boost::shared_ptr - > GeoNodes; - typedef boost::unordered_set NodeSet; + using GeoNodes = + std::unordered_map>; + using NodeSet = std::unordered_set; GeoNodes _geo_nodes; NodeSet _hdg_nodes; - boost::shared_ptr _projection; - bool _projection_dirty; + std::shared_ptr _projection; + bool _projection_dirty = false; struct GeoCoord { - GeoCoord(): - type(INVALID), - value(0) - {} enum { INVALID, LATITUDE, LONGITUDE - } type; - double value; + } type = INVALID; + double value = 0; }; - void geoNodeChanged(SGPropertyNode * child); - void hdgNodeChanged(SGPropertyNode * child); + void projectionNodeChanged(SGPropertyNode* child); + void geoNodeChanged(SGPropertyNode* child); + void hdgNodeChanged(SGPropertyNode* child); GeoCoord parseGeoCoord(const std::string& val) const; }; diff --git a/simgear/canvas/elements/CanvasPath.cxx b/simgear/canvas/elements/CanvasPath.cxx index 188f70d6..c8b6414c 100644 --- a/simgear/canvas/elements/CanvasPath.cxx +++ b/simgear/canvas/elements/CanvasPath.cxx @@ -206,23 +206,13 @@ namespace canvas return SGVec2f(-1.0f, -1.0f); } - //---------------------------------------------------------------------------- - + //---------------------------------------------------------------------------- class Path::PathDrawable: public osg::Drawable { public: PathDrawable(Path* path): - _path_element(path), - _path(VG_INVALID_HANDLE), - _paint(VG_INVALID_HANDLE), - _paint_fill(VG_INVALID_HANDLE), - _attributes_dirty(~0), - _mode(0), - _fill_rule(VG_EVEN_ODD), - _stroke_width(1), - _stroke_linecap(VG_CAP_BUTT), - _stroke_linejoin(VG_JOIN_MITER) + _path_element(path) { setSupportsDisplayList(false); setDataVariance(Object::DYNAMIC); @@ -579,22 +569,22 @@ namespace canvas Path *_path_element; - mutable VGPath _path; - mutable VGPaint _paint; - mutable VGPaint _paint_fill; - mutable uint32_t _attributes_dirty; + mutable VGPath _path {VG_INVALID_HANDLE}; + mutable VGPaint _paint {VG_INVALID_HANDLE}; + mutable VGPaint _paint_fill {VG_INVALID_HANDLE}; + mutable uint32_t _attributes_dirty {~0u}; CmdList _cmds; CoordList _coords; - VGbitfield _mode; + VGbitfield _mode {0}; osg::Vec4f _fill_color; - VGFillRule _fill_rule; + VGFillRule _fill_rule {VG_EVEN_ODD}; osg::Vec4f _stroke_color; - VGfloat _stroke_width; + VGfloat _stroke_width {1}; std::vector _stroke_dash; - VGCapStyle _stroke_linecap; - VGJoinStyle _stroke_linejoin; + VGCapStyle _stroke_linecap {VG_CAP_BUTT}; + VGJoinStyle _stroke_linejoin {VG_JOIN_MITER}; osg::Vec3f transformPoint( const osg::Matrix& m, osg::Vec2f pos ) const @@ -842,33 +832,34 @@ namespace canvas //---------------------------------------------------------------------------- void Path::childChanged(SGPropertyNode* child) { - const std::string& name = child->getNameString(); - const std::string &prName = child->getParent()->getNameString(); + const std::string& name = child->getNameString(); + const std::string &prName = child->getParent()->getNameString(); - if (simgear::strutils::starts_with(name, "border-")) - { - _attributes_dirty |= RECT; - return; - } + if( strutils::starts_with(name, "border-") ) + { + _attributes_dirty |= RECT; + return; + } - if (prName == "rect") { - _hasRect = true; - if (name == "left") { - _rect.setLeft(child->getDoubleValue()); - } else if (name == "top") { - _rect.setTop(child->getDoubleValue()); - } else if (name == "right") { - _rect.setRight(child->getDoubleValue()); - } else if (name == "bottom") { - _rect.setBottom(child->getDoubleValue()); - } else if (name == "width") { - _rect.setWidth(child->getDoubleValue()); - } else if (name == "height") { - _rect.setHeight(child->getDoubleValue()); - } - _attributes_dirty |= RECT; - return; + if (prName == "rect") + { + _hasRect = true; + if (name == "left") { + _rect.setLeft(child->getDoubleValue()); + } else if (name == "top") { + _rect.setTop(child->getDoubleValue()); + } else if (name == "right") { + _rect.setRight(child->getDoubleValue()); + } else if (name == "bottom") { + _rect.setBottom(child->getDoubleValue()); + } else if (name == "width") { + _rect.setWidth(child->getDoubleValue()); + } else if (name == "height") { + _rect.setHeight(child->getDoubleValue()); } + _attributes_dirty |= RECT; + return; + } if( child->getParent() != _node ) return; @@ -904,67 +895,68 @@ namespace canvas return values; } - //---------------------------------------------------------------------------- + //---------------------------------------------------------------------------- + void operator+=(CoordList& base, const std::initializer_list& other) + { + base.insert(base.end(), other.begin(), other.end()); + } - void operator+=(CoordList& base, const std::initializer_list& other) - { - base.insert(base.end(), other.begin(), other.end()); + //---------------------------------------------------------------------------- + void Path::parseRectToVGPath() + { + CmdList commands; + CoordList coords; + commands.reserve(4); + coords.reserve(8); + + bool haveCorner = false; + SGVec2f topLeft = parseRectCornerRadius(_node, "left", "top", haveCorner); + if (haveCorner) { + commands.push_back(VG_MOVE_TO_ABS); + coords += {_rect.l(), _rect.t() + topLeft.y()}; + commands.push_back(VG_SCCWARC_TO_REL); + coords += {topLeft.x(), topLeft.y(), 0.0, topLeft.x(), -topLeft.y()}; + } else { + commands.push_back(VG_MOVE_TO_ABS); + coords += {_rect.l(), _rect.t()}; } - void Path::parseRectToVGPath() - { - CmdList commands; - CoordList coords; - commands.reserve(4); - coords.reserve(8); - - bool haveCorner = false; - SGVec2f topLeft = parseRectCornerRadius(_node, "left", "top", haveCorner); - if (haveCorner) { - commands.push_back(VG_MOVE_TO_ABS); - coords += {_rect.l(), _rect.t() + topLeft.y()}; - commands.push_back(VG_SCCWARC_TO_REL); - coords += {topLeft.x(), topLeft.y(), 0.0, topLeft.x(), -topLeft.y()}; - } else { - commands.push_back(VG_MOVE_TO_ABS); - coords += {_rect.l(), _rect.t()}; - } - - SGVec2f topRight = parseRectCornerRadius(_node, "right", "top", haveCorner); - if (haveCorner) { - commands.push_back(VG_HLINE_TO_ABS); - coords += {_rect.r() - topRight.x()}; - commands.push_back(VG_SCCWARC_TO_REL); - coords += {topRight.x(), topRight.y(), 0.0, topRight.x(), topRight.y()}; - } else { - commands.push_back(VG_HLINE_TO_ABS); - coords += {_rect.r()}; - } - - SGVec2f bottomRight = parseRectCornerRadius(_node, "right", "bottom", haveCorner); - if (haveCorner) { - commands.push_back(VG_VLINE_TO_ABS); - coords += {_rect.b() - bottomRight.y()}; - commands.push_back(VG_SCCWARC_TO_REL); - coords += {bottomRight.x(), bottomRight.y(), 0.0, -bottomRight.x(), bottomRight.y()}; - } else { - commands.push_back(VG_VLINE_TO_ABS); - coords += {_rect.b()}; - } - - SGVec2f bottomLeft = parseRectCornerRadius(_node, "left", "bottom", haveCorner); - if (haveCorner) { - commands.push_back(VG_HLINE_TO_ABS); - coords += {_rect.l() + bottomLeft.x()}; - commands.push_back(VG_SCCWARC_TO_REL); - coords += {bottomLeft.x(), bottomLeft.y(), 0.0, -bottomLeft.x(), -bottomLeft.y()}; - } else { - commands.push_back(VG_HLINE_TO_ABS); - coords += {_rect.l()}; - } - - commands.push_back(VG_CLOSE_PATH); - _path->setSegments(commands, coords); + SGVec2f topRight = parseRectCornerRadius(_node, "right", "top", haveCorner); + if (haveCorner) { + commands.push_back(VG_HLINE_TO_ABS); + coords += {_rect.r() - topRight.x()}; + commands.push_back(VG_SCCWARC_TO_REL); + coords += {topRight.x(), topRight.y(), 0.0, topRight.x(), topRight.y()}; + } else { + commands.push_back(VG_HLINE_TO_ABS); + coords += {_rect.r()}; } + + SGVec2f bottomRight = parseRectCornerRadius(_node, "right", "bottom", haveCorner); + if (haveCorner) { + commands.push_back(VG_VLINE_TO_ABS); + coords += {_rect.b() - bottomRight.y()}; + commands.push_back(VG_SCCWARC_TO_REL); + coords += {bottomRight.x(), bottomRight.y(), 0.0, -bottomRight.x(), bottomRight.y()}; + } else { + commands.push_back(VG_VLINE_TO_ABS); + coords += {_rect.b()}; + } + + SGVec2f bottomLeft = parseRectCornerRadius(_node, "left", "bottom", haveCorner); + if (haveCorner) { + commands.push_back(VG_HLINE_TO_ABS); + coords += {_rect.l() + bottomLeft.x()}; + commands.push_back(VG_SCCWARC_TO_REL); + coords += {bottomLeft.x(), bottomLeft.y(), 0.0, -bottomLeft.x(), -bottomLeft.y()}; + } else { + commands.push_back(VG_HLINE_TO_ABS); + coords += {_rect.l()}; + } + + commands.push_back(VG_CLOSE_PATH); + _path->setSegments(commands, coords); + } + } // namespace canvas } // namespace simgear diff --git a/simgear/canvas/elements/CanvasPath.hxx b/simgear/canvas/elements/CanvasPath.hxx index 2b7804f9..1c2d2878 100644 --- a/simgear/canvas/elements/CanvasPath.hxx +++ b/simgear/canvas/elements/CanvasPath.hxx @@ -68,10 +68,10 @@ namespace canvas void setSVGPath(const std::string& svgPath); - void setRect(const SGRect& r); - void setRoundRect(const SGRect& r, float radiusX, float radiusY = -1.0); - protected: + void setRect(const SGRectf& r); + void setRoundRect(const SGRectf& r, float radiusX, float radiusY = -1.0); + protected: enum PathAttributes { CMDS = LAST_ATTRIBUTE << 1, diff --git a/simgear/props/PropertyBasedElement.cxx b/simgear/props/PropertyBasedElement.cxx index b53a3876..621a1b91 100644 --- a/simgear/props/PropertyBasedElement.cxx +++ b/simgear/props/PropertyBasedElement.cxx @@ -18,7 +18,7 @@ #include #include "PropertyBasedElement.hxx" -#include +#include namespace simgear { @@ -130,7 +130,7 @@ namespace simgear // character that followed it by the same character converted to ASCII // uppercase. - if( !boost::starts_with(name, DATA_PREFIX) ) + if( !strutils::starts_with(name, DATA_PREFIX) ) return std::string(); std::string data_name; diff --git a/simgear/props/PropertyBasedElement.hxx b/simgear/props/PropertyBasedElement.hxx index c43fef2a..ad019805 100644 --- a/simgear/props/PropertyBasedElement.hxx +++ b/simgear/props/PropertyBasedElement.hxx @@ -20,6 +20,7 @@ #define SG_PROPERTY_BASED_ELEMENT_HXX_ #include +#include #include namespace simgear @@ -120,11 +121,9 @@ namespace simgear * @see setDataProp */ template - typename boost::disable_if< - boost::is_same, - T - >::type getDataProp( const std::string& name, - const T& def = T() ) const + std::enable_if_t::value, T> + getDataProp( const std::string& name, + const T& def = {} ) const { SGPropertyNode* node = getDataProp(name); if( node ) @@ -140,11 +139,9 @@ namespace simgear * @see setDataProp */ template - typename boost::enable_if< - boost::is_same, - T - >::type getDataProp( const std::string& name, - SGPropertyNode* = NULL ) const + std::enable_if_t::value, T> + getDataProp( const std::string& name, + SGPropertyNode* = nullptr ) const { const std::string& attr = dataPropToAttrName(name); if( attr.empty() )