1 ///@file 2 /// An OpenVG path on the Canvas 3 // 4 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com> 5 // 6 // This library is free software; you can redistribute it and/or 7 // modify it under the terms of the GNU Library General Public 8 // License as published by the Free Software Foundation; either 9 // version 2 of the License, or (at your option) any later version. 10 // 11 // This library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 // Library General Public License for more details. 15 // 16 // You should have received a copy of the GNU Library General Public 17 // License along with this library; if not, write to the Free Software 18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 20 #ifndef CANVAS_PATH_HXX_ 21 #define CANVAS_PATH_HXX_ 22 23 #include "CanvasElement.hxx" 24 #include <simgear/math/SGRect.hxx> 25 #include <initializer_list> 26 27 namespace simgear 28 { 29 namespace canvas 30 { 31 class Path: 32 public Element 33 { 34 public: 35 static const std::string TYPE_NAME; 36 static void staticInit(); 37 38 Path( const CanvasWeakPtr& canvas, 39 const SGPropertyNode_ptr& node, 40 const Style& parent_style, 41 ElementWeakPtr parent = 0 ); 42 virtual ~Path(); 43 44 osg::BoundingBox 45 getTransformedBounds(const osg::Matrix& m) const override; 46 47 /** Add a segment with the given command and coordinates */ 48 Path& addSegment(uint8_t cmd, std::initializer_list<float> coords = {}); 49 50 /** Move path cursor */ 51 Path& moveTo(float x_abs, float y_abs); 52 Path& move(float x_rel, float y_rel); 53 54 /** Add a line */ 55 Path& lineTo(float x_abs, float y_abs); 56 Path& line(float x_rel, float y_rel); 57 58 /** Add a horizontal line */ 59 Path& horizTo(float x_abs); 60 Path& horiz(float x_rel); 61 62 /** Add a vertical line */ 63 Path& vertTo(float y_abs); 64 Path& vert(float y_rel); 65 66 /** Close the path (implicit lineTo to first point of path) */ 67 Path& close(); 68 69 void setSVGPath(const std::string& svgPath); 70 71 void setRect(const SGRectf& r); 72 void setRoundRect(const SGRectf& r, float radiusX, float radiusY = -1.0); 73 74 protected: 75 enum PathAttributes 76 { 77 CMDS = LAST_ATTRIBUTE << 1, 78 COORDS = CMDS << 1, 79 SVG = COORDS << 1, 80 RECT = SVG << 1 81 }; 82 83 class PathDrawable; 84 typedef osg::ref_ptr<PathDrawable> PathDrawableRef; 85 PathDrawableRef _path; 86 87 bool _hasSVG : 1; 88 bool _hasRect : 1; 89 SGRectf _rect; 90 91 void updateImpl(double dt) override; 92 93 void childRemoved(SGPropertyNode * child) override; 94 void childChanged(SGPropertyNode * child) override; 95 96 void parseRectToVGPath(); 97 }; 98 99 } // namespace canvas 100 } // namespace simgear 101 102 #endif /* CANVAS_PATH_HXX_ */ 103