Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cXSpriteMgr.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cXSpriteMgr_H
7 #define _INC_cXSpriteMgr_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayGUI.h"
14 
15 #ifdef USE_DX
21 
22 namespace Gray3D
23 {
24  class cDXSpriteElem;
25 }
26 
27 namespace GrayGUI
28 {
29 
30  class GRAY3D_LINK cXSpriteMap : public cXTextureFile, public cSpriteMap
31  {
33 
34  public:
35  cXSpriteMap(const FILECHAR_t* pszFilePath);
36  virtual ~cXSpriteMap();
37 
38  void ClearMap()
39  {
40  DeleteDeviceObjects();
42  }
43 
44  virtual HRESULT put_TextureName(cStringF sFileName) override;
45 
46  virtual HRESULT LoadResource();
47 
48  HRESULT GetSpriteElem(ELEM_t nElem, OUT cDXSpriteElem& elem);
49  };
50 
51  typedef cRefPtr<cXSpriteMap> cXSpriteMapPtr;
52 
53  enum SPRITEMAP_t;
54  static const SPRITEMAP_t SPRITEMAP_INVALID = (SPRITEMAP_t)0xFFFF;
55  typedef WORD SPRITEID_t;
56  static const SPRITEID_t SPRITEID_0 = 0;
57 
58  class cXSpriteId
59  {
63  public:
64  typedef int ELEM_t;
65 
66  protected:
67  SPRITEID_t m_nSpriteId;
68 
69  public:
70  cXSpriteId(SPRITEID_t nSpriteId = SPRITEID_0)
71  : m_nSpriteId(nSpriteId)
72  {
73  }
74  cXSpriteId(SPRITEMAP_t eMap, ELEM_t nElem)
75  : m_nSpriteId(GetId(eMap, nElem))
76  {
77  }
78  bool isValidId() const noexcept
79  {
80  return m_nSpriteId != SPRITEID_0;
81  }
82  static inline SPRITEID_t GetId(SPRITEMAP_t eMap, ELEM_t nElem)
83  {
85  return (((SPRITEID_t)eMap) << 10) | (nElem & 0x3ff);
86  }
87  SPRITEID_t get_Id() const
88  {
89  return m_nSpriteId;
90  }
91  void put_Id(SPRITEID_t id)
92  {
93  m_nSpriteId = id;
94  }
95  static inline SPRITEMAP_t GetMap(SPRITEID_t nSpriteId)
96  {
98  return (SPRITEMAP_t)(nSpriteId >> 10);
99  }
100  SPRITEMAP_t get_Map() const
101  {
103  return GetMap(m_nSpriteId);
104  }
105  void put_Map(SPRITEMAP_t eMap)
106  {
107  m_nSpriteId = GetId(eMap, get_Elem());
108  }
109  static inline ELEM_t GetElem(SPRITEID_t nSpriteId)
110  {
112  return (ELEM_t)(nSpriteId & 0x3ff);
113  }
114  ELEM_t get_Elem() const
115  {
117  return GetElem(m_nSpriteId);
118  }
119  void put_Elem(ELEM_t nElem)
120  {
121  m_nSpriteId = GetId(get_Map(), nElem);
122  }
123  };
124 
125  class GRAY3D_LINK cXSpriteAnim : public cXSpriteId
126  {
129 
130  public:
131  cXSpriteAnim(SPRITEMAP_t eSheet = SPRITEMAP_INVALID, ELEM_t iElemBegin = 0, ELEM_t iElemEnd = 0, TIMESYSD_t timeElemRateMS = 0, bool bLoop = true);
132  ~cXSpriteAnim();
133 
134  void SetAnimation(SPRITEMAP_t eSheet, ELEM_t iElemBegin, ELEM_t iElemEnd, TIMESYSD_t timeElemRateMS, bool bLoop = true);
135 
136  void put_CurrentElem(ELEM_t nElem)
137  {
138  Calc::ClampRef(nElem, m_ElemRange.get_Min(), m_ElemRange.get_Max() + 1);
139  m_nSpriteId = GetId(get_Map(), nElem);
140  m_timeLastElem.InitTimeNow();
141  }
142 
143  void UpdateElemTime();
144 
145  public:
146  cValueRange<ELEM_t> m_ElemRange;
147  TIMESYSD_t m_timeElemRate;
148  bool m_bLoop;
149  cTimeSys m_timeLastElem;
150  };
151 
152  struct GRAY3D_LINK cXSpriteMgr // cSingleton
153  {
154  // Manage the sprint maps for the app. enum SPRITEMAP_t
155  HRESULT SetSpriteMap(SPRITEMAP_t eSheet, const FILECHAR_t* pszFileName);
156  cRefPtr<cXSpriteMap> GetSpriteMap(SPRITEMAP_t eSheet) const;
157  HRESULT GetSpriteElem(SPRITEID_t nSpriteId, OUT cDXSpriteElem& elem) const;
158  cArrayRef<cXSpriteMap> m_aSpriteMaps;
159  };
160 
161 }
162 #endif
163 #endif
#define GRAY3D_LINK
Definition: Gray3D.h:15
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
void ClearMap()
Definition: cSpriteMap.h:60
Definition: Gray3D.cpp:12
Definition: GrayGUI.cpp:11
SPRITEMAP_t
Definition: cXDesktopMgr.h:35
cStringT< FILECHAR_t > cStringF
A file name. checks USE_UNICODE_FN. related to cFilePath.
Definition: cFilePath.h:17
INT32 TIMESYSD_t
Time delta. signed milli-Seconds Span. cTimeSys::k_DMAX, cTimeSys::k_INF = MAILSLOT_WAIT_FOREVER.
Definition: cTimeSys.h:28
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
static void ClampRef(TYPE &rValue, TYPE low, TYPE high)
Definition: Calc.h:123