Cornell Cocos
Cornell Extensions to Cocos2d
All Classes Functions Variables Enumerations Enumerator Friends
CUPathNode.h
1 //
2 // CUPathNode.h
3 // Cornell Extensions to Cocos2D
4 //
5 // This module provides a scene graph node for paths and polygon boundaries. It is
6 // similar to a wireframe, except that the lines have width. Because of how the
7 // lines are extruded, a path cannot make an interior traversal (like a wireframe).
8 // The only path options are open or closed.
9 //
10 // This class infinitely better than the horrible DrawNode, which is outside the Cocos2d
11 // render pipeline, and hence incredibly slow. You should avoid that class whenever
12 // possible.
13 //
14 // Author: Walker White
15 // Version: 11/15/15
16 //
17 #ifndef __CU_PATHNODE_H__
18 #define __CU_PATHNODE_H__
19 
20 
21 #include <string>
22 #include "CUPoly2.h"
23 #include "CUTexturedNode.h"
24 #include <renderer/CCTrianglesCommand.h>
25 
26 NS_CC_BEGIN
27 
28 #pragma mark -
29 #pragma mark PathNode
30 
69 class CC_DLL PathNode : public TexturedNode {
70 
71 #pragma mark Internal Helpers
72 private:
74  CC_DISALLOW_COPY_AND_ASSIGN(PathNode);
75 
76 protected:
80  bool _closed;
82  float _stroke;
87 
94  virtual void generateRenderData() override;
95 
96 
97 
98 public:
99 #pragma mark Static Constructors
100 
107  static PathNode* create();
108 
122  static PathNode* createWithVertices(float* vertices, int size, float stroke, bool closed=true);
123 
136  static PathNode* createWithPoly(const Poly2& poly, float stroke, bool closed=true);
137 
148  static PathNode* createWithRect(const Rect& rect, float stroke);
149 
159  static PathNode* createWithLine(const Vec2 &origin, const Vec2 &dest, float stroke);
160 
173  static PathNode* createWithCircle( const Vec2& center, const Size& size, float stroke, unsigned int segments);
174 
175 
176 #pragma mark Attribute Accessors
177 
183  void setStroke(float stroke);
184 
190  float getStroke() const { return _stroke; }
191 
197  void setClosed(bool closed);
198 
204  bool getClosed() const { return _closed; }
205 
211  void setJoint(Poly2::Joint joint);
212 
218  Poly2::Joint getJoint() const { return _joint; }
219 
225  void setCap(Poly2::Cap cap);
226 
232  Poly2::Cap getCap() const { return _endcap; }
233 
241  virtual std::string getDescription() const override;
242 
248  virtual void setPolygon(const Poly2& poly) override;
249 
260  virtual void setPolygon(const Rect& rect) override;
261 
262 
263 #pragma mark Rendering Methods
264 
277  virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
278 
279 
280 CC_CONSTRUCTOR_ACCESS:
281 #pragma mark Hidden Constructors
282 
292  PathNode(float stroke, bool closed=true);
293 
300  virtual ~PathNode(void) { }
301 };
302 
303 NS_CC_END
304 
305 #endif /* defined(__CU_PATHNODE_H__) */
Definition: CUTexturedNode.h:71
virtual void setPolygon(float *vertices, int size, int offset=0)
Definition: CUTexturedNode.cpp:417
virtual void generateRenderData()
Definition: CUTexturedNode.h:146
Poly2::Cap _endcap
Definition: CUPathNode.h:86
Poly2::Joint getJoint() const
Definition: CUPathNode.h:218
Poly2::Joint _joint
Definition: CUPathNode.h:84
Definition: CUPathNode.h:69
bool getClosed() const
Definition: CUPathNode.h:204
float getStroke() const
Definition: CUPathNode.h:190
Poly2::Cap getCap() const
Definition: CUPathNode.h:232
float _stroke
Definition: CUPathNode.h:82
Cap
Definition: CUPoly2.h:77
bool _closed
Definition: CUPathNode.h:80
Joint
Definition: CUPoly2.h:66
virtual ~PathNode(void)
Definition: CUPathNode.h:300
Definition: CUPoly2.h:53
Poly2 _extrusion
Definition: CUPathNode.h:78