45 #ifndef __CU_PATH_NODE_H__
46 #define __CU_PATH_NODE_H__
49 #include <cugl/2d/CUTexturedNode.h>
50 #include <cugl/math/CUPoly2.h>
51 #include <cugl/math/polygon/CUPathExtruder.h>
52 #include <cugl/math/polygon/CUPathOutliner.h>
55 #define PATH_SEGMENTS 8
134 #pragma mark Constructors
176 PathJoint joint = PathJoint::NONE, PathCap cap = PathCap::NONE,
200 PathJoint joint = PathJoint::NONE, PathCap cap = PathCap::NONE);
231 #pragma mark Static Constructors
239 static std::shared_ptr<PathNode>
alloc() {
240 std::shared_ptr<PathNode> node = std::make_shared<PathNode>();
241 return (node->init() ? node :
nullptr);
261 static std::shared_ptr<PathNode>
allocWithVertices(
const std::vector<Vec2>& vertices,
float stroke,
262 PathJoint joint = PathJoint::NONE,
263 PathCap cap = PathCap::NONE,
bool closed =
true) {
264 std::shared_ptr<PathNode> node = std::make_shared<PathNode>();
265 return (node->initWithVertices(vertices,stroke,joint,cap,closed) ? node :
nullptr);
285 PathJoint joint = PathJoint::NONE,
286 PathCap cap = PathCap::NONE) {
287 std::shared_ptr<PathNode> node = std::make_shared<PathNode>();
288 return (node->initWithPoly(poly,stroke,joint,cap) ? node :
nullptr);
307 PathJoint joint = PathJoint::NONE,
308 PathCap cap = PathCap::NONE) {
309 std::shared_ptr<PathNode> node = std::make_shared<PathNode>();
310 return (node->initWithPoly(
Poly2(rect,
false),stroke,joint,cap) ? node :
nullptr);
328 PathJoint joint = PathJoint::NONE,
329 PathCap cap = PathCap::NONE) {
330 std::shared_ptr<PathNode> node = std::make_shared<PathNode>();
331 return (node->initWithPoly(
Poly2::createLine(origin, dest),stroke,joint,cap) ? node :
nullptr);
351 unsigned int segments = PATH_SEGMENTS,
352 PathJoint joint = PathJoint::NONE,
353 PathCap cap = PathCap::NONE) {
354 std::shared_ptr<PathNode> node = std::make_shared<PathNode>();
385 const std::shared_ptr<JsonValue>& data) {
386 std::shared_ptr<PathNode> result = std::make_shared<PathNode>();
387 if (!result->initWithData(loader,data)) { result =
nullptr; }
388 return std::dynamic_pointer_cast<
Node>(result);
393 #pragma mark Attributes
463 #pragma mark Polygons
474 virtual void setPolygon(
const std::vector<Vec2>& vertices)
override;
552 #pragma mark Rendering
576 virtual void draw(
const std::shared_ptr<SpriteBatch>& batch,
const Mat4& transform,
Color4 tint)
override;
580 #pragma mark Internal Helpers
585 virtual void generateRenderData()
override;
590 void updateExtrusion();
593 CU_DISALLOW_COPY_AND_ASSIGN(
PathNode);
static std::shared_ptr< Node > allocWithData(const SceneLoader *loader, const std::shared_ptr< JsonValue > &data)
Definition: CUPathNode.h:384
Definition: CUTexturedNode.h:84
Definition: CUPoly2.h:115
static PathOutliner _outliner
Definition: CUPathNode.h:116
const Size & getExtrudedContentSize() const
Definition: CUPathNode.h:534
static std::shared_ptr< PathNode > allocWithPoly(const Poly2 &poly, float stroke, PathJoint joint=PathJoint::NONE, PathCap cap=PathCap::NONE)
Definition: CUPathNode.h:284
static std::shared_ptr< PathNode > alloc()
Definition: CUPathNode.h:239
const Rect & getExtrudedContentBounds() const
Definition: CUPathNode.h:549
void setStroke(float stroke)
bool initWithVertices(const std::vector< Vec2 > &vertices, float stroke, PathJoint joint=PathJoint::NONE, PathCap cap=PathCap::NONE, bool closed=true)
~PathNode()
Definition: CUPathNode.h:152
Poly2 _extrusion
Definition: CUPathNode.h:119
float _stroke
Definition: CUPathNode.h:126
float getExtrudedContentHeight() const
Definition: CUPathNode.h:522
virtual bool initWithData(const SceneLoader *loader, const std::shared_ptr< JsonValue > &data) override
Rect _extrbounds
Definition: CUPathNode.h:121
Definition: CUPathNode.h:110
float width
Definition: CUSize.h:61
static Poly2 createLine(const Vec2 &origin, const Vec2 &dest)
PathJoint getJoint() const
Definition: CUPathNode.h:443
virtual void dispose() override
PathCap _endcap
Definition: CUPathNode.h:130
Definition: CUPathExtruder.h:129
void setClosed(bool closed)
float height
Definition: CUSize.h:63
PathJoint _joint
Definition: CUPathNode.h:128
static PathExtruder _extruder
Definition: CUPathNode.h:114
static std::shared_ptr< PathNode > allocWithLine(const Vec2 &origin, const Vec2 &dest, float stroke, PathJoint joint=PathJoint::NONE, PathCap cap=PathCap::NONE)
Definition: CUPathNode.h:327
Definition: CUSceneLoader.h:77
static std::shared_ptr< PathNode > allocWithEllipse(const Vec2 ¢er, const Size &size, float stroke, unsigned int segments=PATH_SEGMENTS, PathJoint joint=PathJoint::NONE, PathCap cap=PathCap::NONE)
Definition: CUPathNode.h:350
bool _closed
Definition: CUPathNode.h:124
bool initWithPoly(const Poly2 &poly, float stroke, PathJoint joint=PathJoint::NONE, PathCap cap=PathCap::NONE)
virtual void setPolygon(const std::vector< Vec2 > &vertices) override
Size size
Definition: CURect.h:51
void setJoint(PathJoint joint)
float getStroke() const
Definition: CUPathNode.h:409
Definition: CUColor4.h:1084
Definition: CUPathOutliner.h:79
static std::shared_ptr< PathNode > allocWithVertices(const std::vector< Vec2 > &vertices, float stroke, PathJoint joint=PathJoint::NONE, PathCap cap=PathCap::NONE, bool closed=true)
Definition: CUPathNode.h:261
Definition: CUAction.h:51
bool getClosed() const
Definition: CUPathNode.h:426
virtual void draw(const std::shared_ptr< SpriteBatch > &batch, const Mat4 &transform, Color4 tint) override
float getExtrudedContentWidth() const
Definition: CUPathNode.h:510
PathCap getCap() const
Definition: CUPathNode.h:460
static Poly2 createEllipse(const Vec2 ¢er, const Size &size, unsigned int segments, bool solid=true)
static std::shared_ptr< PathNode > allocWithRect(const Rect &rect, float stroke, PathJoint joint=PathJoint::NONE, PathCap cap=PathCap::NONE)
Definition: CUPathNode.h:306