You.i Engine
YiPath.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_PATH_H_
3 #define _YI_PATH_H_
4 
5 #include "framework/YiPredef.h"
7 #include <glm/gtc/type_ptr.hpp>
8 
14 typedef enum
15 {
20 }
22 
23 typedef struct
24 {
25  glm::vec2 p1;
26  glm::vec2 p2;
27  glm::vec2 p3;
28  glm::vec2 p4;
29 }
31 
32 typedef enum
33 {
38 }
40 
50 class CYIPath
51 {
52 
53 public:
59  class Segment
60  {
61  public:
62  Segment(YI_PATH_CMD nType, uint32_t nCountHint);
63  virtual ~Segment();
64 
68  int32_t GetPointCount();
69 
73  const glm::vec2 &GetPoint(uint32_t nIndex) const;
74 
81 
85  bool AddPoint(const glm::vec2 &vPoint);
86 
87  private:
88 
89  YI_PATH_CMD m_nType;
90  uint32_t m_nCountHint;
91  std::vector<glm::vec2> m_Points;
92  };
93 
94  CYIPath();
95  CYIPath(uint32_t nSegCountHint, uint32_t nVertexCountHint);
96  virtual ~CYIPath();
97 
101  void Clear();
102 
110  bool MoveTo(const glm::vec2 &vPoint);
111 
119  bool LineTo(const glm::vec2 &vPoint);
120 
128  bool CubicTo(const glm::vec2 &vStart, const glm::vec2 &vMid, const glm::vec2 &vEnd);
129 
136  bool Close();
137 
141  static std::unique_ptr<CYIPath> CreateLine(float fX1, float fY1, float fX2, float fY2);
142 
146  static std::unique_ptr<CYIPath> CreateRectangle(float fX, float fY, float fWidth, float fHeight);
147 
153  static std::unique_ptr<CYIPath> CreateRoundedRectangle(float fX, float fY, float fWidth, float fHeight, float fRX, float fRY);
154 
158  int32_t GetSegmentCount();
159 
163  Segment *GetSegment(int32_t nIndex);
164 
168  bool GeneratePolygonData();
169 
173  uint32_t GetPolygonCount() const;
174 
178  const CYIPolygonData *GetPolygonData() const;
179 
184 
192  void CalculateBounds();
193 
199  glm::vec4 GetFloatBounds() const;
200 
206  YI_RECT GetIntBounds() const;
207 
208 private:
209  void GenerateCubic(YI_PATH_CUBIC *pCubic, int32_t *pnIndex);
210 
211  std::vector<std::unique_ptr<Segment>> m_Segments;
212  CYIPolygonData m_PolygonData;
213  glm::vec4 m_PolygonBounds;
214  uint32_t m_nSegCountHint;
215  uint32_t m_nVertexCountHint;
216 };
217 
220 #endif // _YI_PATH_H_
glm::vec2 p3
Definition: YiPath.h:27
const glm::vec2 & GetPoint(uint32_t nIndex) const
bool GeneratePolygonData()
Definition: YiPath.h:37
void Clear()
bool Close()
void CalculateBounds()
Definition: YiPath.h:34
bool AddPoint(const glm::vec2 &vPoint)
static std::unique_ptr< CYIPath > CreateRectangle(float fX, float fY, float fWidth, float fHeight)
Definition: YiPredef.h:183
static std::unique_ptr< CYIPath > CreateRoundedRectangle(float fX, float fY, float fWidth, float fHeight, float fRX, float fRY)
Command that moves the cursor to the starting point while drawing a line along the path...
Definition: YiPath.h:19
std::vector< YI_POLYGON_VERTEX > CYIPolygonData
A type representing multiple vertices of a polygon.
Definition: YiPolygonFill.h:32
int32_t GetPointCount()
Definition: YiPath.h:36
Command that moves the cursor to a position while drawing a line along the path.
Definition: YiPath.h:17
virtual ~Segment()
YI_PATH_CMD GetType()
Segment(YI_PATH_CMD nType, uint32_t nCountHint)
glm::vec2 p1
Definition: YiPath.h:25
const CYIPolygonData * GetPolygonData() const
YI_PATH_BOUNDS_INDEX
Definition: YiPath.h:32
bool CubicTo(const glm::vec2 &vStart, const glm::vec2 &vMid, const glm::vec2 &vEnd)
A class representing one segment of a path.
Definition: YiPath.h:59
uint32_t GetPolygonCount() const
Definition: YiPath.h:35
Command that moves the cursor along a bezier curve while drawing a line along the path...
Definition: YiPath.h:18
YI_PATH_CMD
Definition: YiPath.h:14
Definition: YiPath.h:23
virtual ~CYIPath()
bool LineTo(const glm::vec2 &vPoint)
A class that contains information on how a path will be drawn.
Definition: YiPath.h:50
Command that moves the cursor instantaneously to a position.
Definition: YiPath.h:16
glm::vec4 GetFloatBounds() const
YI_RECT GetIntBounds() const
int32_t GetSegmentCount()
Segment * GetSegment(int32_t nIndex)
bool MoveTo(const glm::vec2 &vPoint)
glm::vec2 p2
Definition: YiPath.h:26
static std::unique_ptr< CYIPath > CreateLine(float fX1, float fY1, float fX2, float fY2)
glm::vec2 p4
Definition: YiPath.h:28