You.i Engine
YiNPatchSceneNode.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_NPATCH_SCENE_NODE_H_
3 #define _YI_NPATCH_SCENE_NODE_H_
4 
5 #include "framework/YiPredef.h"
7 
14 class CYIBitmap;
15 class CYISceneNode;
16 class CYISceneManager;
17 
29 {
30 public:
32  virtual ~CYINPatchSceneNode();
33 
34  virtual bool Init() override;
35 
39  bool SetNPatch(const std::shared_ptr<CYIBitmap> &pNPatch);
40 
48  void ScaleToSize(const glm::vec2 &vlsSize);
49 
57  void ScaleToWidth(float nWidth);
58 
66  void ScaleToHeight(float nHeight);
67 
68  virtual void SetSize(const glm::vec3 &vSize, bool bDirtyLayout = true) override;
69 
70 protected:
71  virtual void WorldSurfaceScaleUpdated() override;
72  glm::vec3 GetSizeScaleAdjustment() const;
73 
74 private:
78  struct PATCH_INFO
79  {
80  float fSize;
81  float fUVSum;
82  float fScalingWeight;
83  };
84 
85 
87  static const uint32_t CONTENT_PATCH_PIXEL_MARKER = 0xFF000000;
88  static const uint32_t SCALE_PATCH_PIXEL_MARKER = 0xFF000000;
89  static const uint32_t FIXED_PATCH_PIXEL_MARKER = 0x00000000;
90  static const uint32_t EMPTY_PIXEL_MARKER = 0x00000000;
91 
92  void RebuildMesh(const glm::vec3 &vwsScale);
93 
94  void BuildPatches();
95  bool IsValidNPatch(const std::shared_ptr<CYIBitmap> &pNPatch);
96  void RemoveMarkers();
97  void InitColumnInfo(int32_t col, uint32_t nHorizontalPatchType, int32_t nLeftMark, int32_t nRightMark);
98  void InitRowInfo(int32_t row, uint32_t nVerticalPatchType, int32_t nTopMark, int32_t nBottomMark);
99  void PreProcessWidthSectionMarkers();
100  void PreProcessHeightSectionMarkers();
101  bool HasValidTopMarkers(const std::shared_ptr<CYIBitmap> &pNPatch);
102  bool HasValidLeftMarkers(const std::shared_ptr<CYIBitmap> &pNPatch);
103  bool HasValidBottomMarkers(const std::shared_ptr<CYIBitmap> &pNPatch);
104  bool HasValidRightMarkers(const std::shared_ptr<CYIBitmap> &pNPatch);
105  static std::shared_ptr<CYIAssetBufferObjectData> BuildNPatchVertices(const std::vector<CYINPatchSceneNode::PATCH_INFO> &rColumnInfo, std::vector<CYINPatchSceneNode::PATCH_INFO> &rRowInfo, float fTotalImageWidth, float fTotalImageHeight, float fHorizontalRemainder, float fVerticalRemainder, float &rWidthSum, float &rHeightSum);
106  static std::shared_ptr<CYIAssetBufferObjectData> BuildNPatchTriangles(uint16_t uNumHorizontalPatches, uint16_t uNumVerticalPatches, int32_t &rIndicesCount);
107  static std::shared_ptr<CYIMesh> CreateNPatchMesh(const std::vector<CYINPatchSceneNode::PATCH_INFO> &rColumnInfo, std::vector<CYINPatchSceneNode::PATCH_INFO> &rRowInfo, float fTotalImageWidth, float fTotalImageHeight, float fScaleX = 1.0f, float fScaleY = 1.0f);
108 
109  int32_t m_nHorizontalPatches;
110  int32_t m_nVerticalPatches;
111 
112  std::vector<PATCH_INFO> m_columnsInfo;
113  std::vector<PATCH_INFO> m_rowsInfo;
114 
115  uint32_t m_nTotalScalableWidth;
116  uint32_t m_nTotalScalableHeight;
117 
122  YI_RECT m_nContentAreaRect;
123 
124  std::shared_ptr<CYIBitmap> m_pNPatch;
125  bool m_bSizeValid;
126 
128 };
129 
132 #ifdef YI_FUNCTION_SPECIALIZATION_FULLY_SUPPORTED
133 template <>
134 inline const CYINPatchSceneNode *YiDynamicCast<CYINPatchSceneNode>(const CYISceneNode *pObject)
135 {
136  return pObject ? (pObject->CanCastTo<CYINPatchSceneNode>() ? static_cast<const CYINPatchSceneNode *>(pObject) : nullptr) : nullptr;
137 }
138 #endif
139 
140 #endif // _YI_NPATCH_SCENE_NODE_H_
glm::vec3 GetSizeScaleAdjustment() const
bool SetNPatch(const std::shared_ptr< CYIBitmap > &pNPatch)
virtual bool Init() override
Scene trees composed of CYISceneNode objects are registered with the scene manager in order for them ...
Definition: YiSceneManager.h:73
virtual void WorldSurfaceScaleUpdated() override
void ScaleToHeight(float nHeight)
Definition: YiPredef.h:183
The core bitmap container class used by You.i Engine.
Definition: YiBitmap.h:20
Specialized CYISceneNode holding a scalable N-Patch object.
Definition: YiNPatchSceneNode.h:28
#define YI_TYPE_BASES(...)
Definition: YiRtti.h:350
virtual ~CYINPatchSceneNode()
void ScaleToWidth(float nWidth)
A scene node is the base type for all nodes which are used by the scene manager; it is an integral pa...
Definition: YiSceneNode.h:114
virtual void SetSize(const glm::vec3 &vSize, bool bDirtyLayout=true) override
As asset container which wraps shared index or vertex buffer object data.
Definition: YiAssetBufferObjectData.h:17
void ScaleToSize(const glm::vec2 &vlsSize)