List.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. #ifndef Liste_H
  2. #define Liste_H
  3. #include "Array.h"
  4. #include "Drawing.h"
  5. namespace Framework
  6. {
  7. class Border; //! Border.h
  8. class AlphaField; //! AlphaField.h
  9. class Image; //! Image.h
  10. class Text; //! Text.h
  11. class TextField; //! TextField.h
  12. class VScrollBar; //! Scroll.h
  13. struct KeyboardEvent; //! KeyboardEvent.h
  14. struct MouseEvent; //! MouseEvent.h
  15. class Font; //! Font.h
  16. class SelectionList; //! from this file
  17. //! A drawing of the 2D GUI Framework that displays a list from which
  18. //! the user can select and deselect elements
  19. class SelectionList : public DrawableBackground
  20. {
  21. public:
  22. class Style : public DrawableBackground::Style
  23. {
  24. public:
  25. //! Specifies whether the list entries have a border
  26. static const __int64 FieldBorder = 0x0001000;
  27. //! Specifies whether the entries have a background
  28. static const __int64 FieldBackground = 0x0002000;
  29. //! Specifies whether the entries have a background image
  30. static const __int64 FieldHImage = 0x0004000;
  31. //! Specifies whether alpha blending is used when drawing
  32. //! entry backgrounds
  33. static const __int64 FieldHAlpha = 0x0008000;
  34. //! Specifies whether the entries have a color gradient
  35. static const __int64 FieldBuffer = 0x0010000;
  36. //! Specifies whether selected entries have a background
  37. static const __int64 SelectionBackground = 0x0020000;
  38. //! Specifies whether selected entries have a background image
  39. static const __int64 SelectionHImage = 0x0040000;
  40. //! Specifies whether alpha blending is used for drawing
  41. //! backgrounds of selected entries
  42. static const __int64 SelectionHAlpha = 0x0080000;
  43. //! Specifies whether selected entries have a color gradient
  44. static const __int64 SelectionBuffer = 0x0100000;
  45. //! Specifies whether selected entries have a border
  46. static const __int64 SelectionBorder = 0x0200000;
  47. //! Specifies whether each entry has its own background,
  48. //! color gradient, and border when selected
  49. static const __int64 MultiStyled = 0x0400000;
  50. //! Specifies that multiple entries can be selected simultaneously
  51. static const __int64 MultiSelect = 0x0800000;
  52. //! Specifies whether a specific entry is selected, if
  53. //! MultiSelect was set.
  54. static const __int64 Selected = 0x1000000;
  55. //! Combines the flags Visible, Allowed, Border, FieldHAlpha,
  56. //! FieldBackground, FieldBorder, SelectionBuffer, SelectionBorder
  57. static const __int64 Normal
  58. = Visible | Allowed | Border | FieldHAlpha | FieldBackground
  59. | FieldBorder | SelectionBuffer | SelectionBorder;
  60. };
  61. private:
  62. RCArray<TextField>* tfListe;
  63. int selection;
  64. int ahColor;
  65. Image* ahImage;
  66. AlphaField* aBuffer;
  67. Border* aBorder;
  68. Array<__int64>* styles;
  69. Array<int>* ahColorListe;
  70. RCArray<Image>* ahImageListe;
  71. RCArray<AlphaField>* aBufferListe;
  72. RCArray<Border>* aBorderList;
  73. Font* font;
  74. //! Processes mouse messages
  75. //! \param me The event triggered by the mouse input
  76. DLLEXPORT void doMouseEvent(MouseEvent& me, bool userRet) override;
  77. DLLEXPORT bool hasStyle(int styleSet, int styleCheck) const;
  78. public:
  79. //! Constructor
  80. DLLEXPORT SelectionList();
  81. //! Destructor
  82. DLLEXPORT virtual ~SelectionList();
  83. //! Updates the styles, size and position of the entries
  84. DLLEXPORT void update();
  85. //! Adds an entry
  86. //! \param txt The text of the entry
  87. DLLEXPORT void addEntry(Text* txt);
  88. //! Adds an entry
  89. //! \param txt The text of the entry
  90. DLLEXPORT void addEntry(const char* txt);
  91. //! Adds a pointer to an entry
  92. //! \param tf The TextField used to draw the entry
  93. DLLEXPORT void addEntryZ(TextField* tf);
  94. //! Adds an entry at a specific position
  95. //! \param pos The index of the new entry
  96. //! \param txt The text of the entry
  97. DLLEXPORT void addEntry(int pos, Text* txt);
  98. //! Adds an entry at a specific position
  99. //! \param pos The index of the new entry
  100. //! \param txt The text of the entry
  101. DLLEXPORT void addEntry(int pos, const char* txt);
  102. //! Adds a pointer to an entry at a specific position
  103. //! \param pos The index of the new entry \param tf The TextField
  104. //! used to draw the entry
  105. DLLEXPORT void addEntryZ(int pos, TextField* tf);
  106. //! Changes an entry
  107. //! \param pos The index of the entry
  108. //! \param txt The new text of the entry
  109. DLLEXPORT void setEntry(int pos, Text* txt);
  110. //! Changes an entry
  111. //! \param pos The index of the entry
  112. //! \param txt The new text of the entry
  113. DLLEXPORT void setEntry(int pos, const char* txt);
  114. //! Changes the pointer of an entry
  115. //! \param pos The index of the entry
  116. //! \param tf The new entry
  117. DLLEXPORT void setEntryZ(int pos, TextField* tf);
  118. //! Swaps the positions of two entries
  119. //! \param vpos The index of the first entry
  120. //! \param npos The index of the second entry
  121. DLLEXPORT void swapEntryPos(int vpos, int npos);
  122. //! Sets the position of an entry
  123. //! \param vpos The index of the entry
  124. //! \param npos The index the entry should have
  125. DLLEXPORT void setEntryPos(int vpos, int npos);
  126. //! Deletes an entry
  127. //! pos: The index of the entry
  128. DLLEXPORT void removeEntry(int pos);
  129. //! Sets the font to use
  130. //! \param font The font
  131. DLLEXPORT void setFontZ(Font* font);
  132. //! Scrolls to a specific entry
  133. //! \param entry The index of the entry
  134. DLLEXPORT void setVScrollToEntry(int entry);
  135. //! Updates the maximum scroll height by adding the heights of all entries
  136. DLLEXPORT void updateVScroll();
  137. //! Sets a pointer to the border used for selected entries
  138. //! if MultiStyled is not set \param border The border
  139. DLLEXPORT void setALRZ(Border* border);
  140. //! Sets the width of the border used for selected entries
  141. //! if MultiStyled is not set \param br The width in pixels
  142. DLLEXPORT void setALRWidth(int br);
  143. //! Sets the color of the border used for selected entries
  144. //! if MultiStyled is not set \param fc The color in A8R8G8B8 format
  145. DLLEXPORT void setALRColor(int fc);
  146. //! Sets a pointer to the color gradient used for selected entries
  147. //! if MultiStyled is not set \param buffer The color gradient
  148. DLLEXPORT void setAAFZ(AlphaField* buffer);
  149. //! Sets the strength of the color gradient used for selected entries
  150. //! if MultiStyled is not set \param st The strength
  151. DLLEXPORT void setAAFStrength(int st);
  152. //! Sets the color of the color gradient used for selected entries
  153. //! if MultiStyled is not set \param fc The color in A8R8G8B8 format
  154. DLLEXPORT void setAAFColor(int fc);
  155. //! Sets the background image by copying, used for selected entries
  156. //! if MultiStyled is not set \param bild The image to copy
  157. DLLEXPORT void setAHImage(Image* bild);
  158. //! Sets a pointer to the background image used for selected entries
  159. //! if MultiStyled is not set \param bild The image
  160. DLLEXPORT void setAHImageZ(Image* bild);
  161. //! Sets the background color used for selected entries
  162. //! if MultiStyled is not set \param fc The color in A8R8G8B8 format
  163. DLLEXPORT void setAHColor(int fc);
  164. //! Sets a pointer to the border used for a selected entry
  165. //! if MultiStyled is set \param pos The index of the entry
  166. //! \param border The border
  167. DLLEXPORT void setALRZ(int pos, Border* border);
  168. //! Sets the width of the border used for a selected entry
  169. //! if MultiStyled is set \param pos The index of the entry
  170. //! \param br The width in pixels
  171. DLLEXPORT void setALRWidth(int pos, int br);
  172. //! Sets the color of the border used for a selected entry
  173. //! if MultiStyled is set \param pos The index of the entry
  174. //! \param fc The color in A8R8G8B8 format
  175. DLLEXPORT void setALRColor(int pos, int fc);
  176. //! Sets a pointer to the color gradient used for a selected entry
  177. //! if MultiStyled is set \param pos The index of the entry
  178. //! \param buffer The color gradient
  179. DLLEXPORT void setAAFZ(int pos, AlphaField* buffer);
  180. //! Sets the strength of the color gradient used for a selected entry
  181. //! if MultiStyled is set \param pos The index of the entry
  182. //! \param st The strength
  183. DLLEXPORT void setAAFStrength(int pos, int st);
  184. //! Sets the color of the color gradient used for a selected entry
  185. //! if MultiStyled is set \param pos The index of the entry
  186. //! \param fc The color in A8R8G8B8 format
  187. DLLEXPORT void setAAFColor(int pos, int fc);
  188. //! Sets the background image by copying, used for a selected entry
  189. //! if MultiStyled is set
  190. //! \param pos The index of the entry
  191. //! \param bild The image to copy
  192. DLLEXPORT void setAHImage(int pos, Image* bild);
  193. //! Sets a pointer to the background image used for a selected entry
  194. //! if MultiStyled is set
  195. //! \param pos The index of the entry
  196. //! \param bild The image
  197. DLLEXPORT void setAHImageZ(int pos, Image* bild);
  198. //! Sets the background color used for a selected entry
  199. //! if MultiStyled is set \param pos The index of the entry
  200. //! \param fc The color in A8R8G8B8 format
  201. DLLEXPORT void setAHColor(int pos, int fc);
  202. //! Sets the style of an entry if MultiStyled is set, and specifies
  203. //! whether an entry is selected if MultiSelect is set
  204. //! \param pos The index of the entry \param style The new style
  205. DLLEXPORT void setMsStyle(int pos, __int64 style);
  206. //! Changes the style of an entry if MultiStyled is set, and specifies
  207. //! whether an entry is selected if MultiSelect is set
  208. //! \param pos The index of the entry \param style The style
  209. //! add_remove: 1 if the style should be added. 0 if the style
  210. //! should be removed
  211. DLLEXPORT void setMsStyle(int pos, __int64 style, bool add_remove);
  212. //! Adds styles to an entry if MultiStyled is set, and specifies
  213. //! whether an entry is selected if MultiSelect is set
  214. //! \param pos The index of the entry \param style The style to add
  215. DLLEXPORT void addMsStyle(int pos, __int64 style);
  216. //! Removes styles from an entry if MultiStyled is set, and specifies
  217. //! whether an entry is selected if MultiSelect is set
  218. //! \param pos The index of the entry \param style The style to remove
  219. DLLEXPORT void removeMsStyle(int pos, __int64 style);
  220. //! Processes a keyboard event. Called automatically by the framework
  221. //! \param te The event
  222. DLLEXPORT void doKeyboardEvent(KeyboardEvent& te) override;
  223. //! Draws the object to zRObj if it is visible
  224. //! \param zRObj The image to draw into
  225. DLLEXPORT void render(Image& zRObj) override;
  226. //! Returns the index of an entry the mouse points to
  227. //! \param my The position of the mouse on the Y axis relative to
  228. //! the top edge of the list
  229. DLLEXPORT int getClickEntry(int my);
  230. //! Selects an entry
  231. //! \param sel The index of the entry
  232. DLLEXPORT void setSelection(int sel);
  233. //! Deselects all selected entries
  234. DLLEXPORT void deselect();
  235. //! Returns the number of entries
  236. DLLEXPORT int getEntryCount() const;
  237. //! Returns the index of the selected entry if MultiSelect is not
  238. //! set. If MultiSelect is set, the selection of an entry can be
  239. //! checked with hasMsStyle( entry index,
  240. //! SelectionList::Style::Ausgewaehlt )
  241. DLLEXPORT int getSelection() const;
  242. //! Returns the index of an entry
  243. //! \param entryText The text of the entry
  244. DLLEXPORT int getEntryPos(Text* entryText);
  245. //! Returns an entry
  246. //! \param pos The index of the entry
  247. DLLEXPORT TextField* getEntry(int pos) const;
  248. //! Returns an entry without increased reference counter
  249. //! \param pos The index of the entry
  250. DLLEXPORT TextField* zEntry(int pos) const;
  251. //! Returns the border used for selected entries
  252. //! if MultiStyled is not set
  253. DLLEXPORT Border* getABorder() const;
  254. //! Returns the border without increased reference counter used for
  255. //! selected entries if MultiStyled is not set
  256. DLLEXPORT Border* zABorder() const;
  257. //! Returns the background color in A8R8G8B8 format used for
  258. //! selected entries if MultiStyled is not set
  259. DLLEXPORT int getAHColor() const;
  260. //! Returns the background image used for selected entries
  261. //! if MultiStyled is not set
  262. DLLEXPORT Image* getAHImage() const;
  263. //! Returns the background image without increased reference counter
  264. //! used for selected entries if MultiStyled is not set
  265. DLLEXPORT Image* zAHImage() const;
  266. //! Returns the color gradient used for selected entries
  267. //! if MultiStyled is not set
  268. DLLEXPORT AlphaField* getABuffer() const;
  269. //! Returns the color gradient without increased reference counter
  270. //! used for selected entries if MultiStyled is not set
  271. DLLEXPORT AlphaField* zABuffer() const;
  272. //! Returns the border used for a selected entry
  273. //! if MultiStyled is set
  274. DLLEXPORT Border* getABorder(int pos) const;
  275. //! Returns the border without increased reference counter used for
  276. //! a selected entry if MultiStyled is set
  277. DLLEXPORT Border* zABorder(int pos) const;
  278. //! Returns the background color in A8R8G8B8 format used for a
  279. //! selected entry if MultiStyled is set
  280. DLLEXPORT int getAHColor(int pos) const;
  281. //! Returns the background image used for a selected entry
  282. //! if MultiStyled is set
  283. DLLEXPORT Image* getAHImage(int pos) const;
  284. //! Returns the background image without increased reference counter
  285. //! used for a selected entry if MultiStyled is set
  286. DLLEXPORT Image* zAHImage(int pos) const;
  287. //! Returns the color gradient used for a selected entry
  288. //! if MultiStyled is set
  289. DLLEXPORT AlphaField* getABuffer(int pos) const;
  290. //! Returns the color gradient without increased reference counter
  291. //! used for a selected entry if MultiStyled is set
  292. DLLEXPORT AlphaField* zABuffer(int pos) const;
  293. //! Checks whether specific styles are set for a specific entry
  294. //! if MultiStyled is set. Also checks whether an entry is selected
  295. //! if MultiSelect is set \param pos The index of the entry
  296. //! \param style The styles to check
  297. DLLEXPORT inline bool hasMsStyle(int pos, __int64 style) const;
  298. //! Checks whether specific styles are not set for a specific entry
  299. //! if MultiStyled is set. Also checks whether an entry is not selected
  300. //! if MultiSelect is set
  301. //! \param pos The index of the entry
  302. //! \param style The styles to check
  303. DLLEXPORT inline bool hasMsStyleNot(int pos, __int64 style) const;
  304. };
  305. class DrawableList : public DrawableBackground
  306. {
  307. public:
  308. class Style : public DrawableBackground::Style
  309. {
  310. public:
  311. //! draws a seperation line between the entries
  312. static const __int64 EntrySeperator = 0x0001000;
  313. //! Combines the flags Visible, Allowed,
  314. //! Border, Background
  315. static const __int64 Normal
  316. = Visible | Allowed | Border | Background | EntrySeperator;
  317. };
  318. private:
  319. int entrySeperatorSize;
  320. int entrySeperatorColor;
  321. RCArray<Drawable> list;
  322. protected:
  323. //! Processes mouse messages
  324. //! \param me The event triggered by the mouse input
  325. DLLEXPORT void doMouseEvent(MouseEvent& me, bool userRet) override;
  326. public:
  327. //! Constructor
  328. DLLEXPORT DrawableList();
  329. //! Destructor
  330. DLLEXPORT virtual ~DrawableList();
  331. //! Adds an entry
  332. //! \param entry The drawing to add
  333. DLLEXPORT void addEntry(Drawable* entry);
  334. //! Changes an entry
  335. //! \param pos The index of the entry
  336. //! \param entry The new drawing
  337. DLLEXPORT void setEntry(int pos, Drawable* entry);
  338. //! Swaps the positions of two entries
  339. //! \param vpos The index of the first entry
  340. //! \param npos The index of the second entry
  341. DLLEXPORT void swapEntryPos(int vpos, int npos);
  342. //! Sets the position of an entry
  343. //! \param vpos The index of the entry
  344. //! \param npos The index the entry should have
  345. DLLEXPORT void setEntryPos(int vpos, int npos);
  346. //! Deletes an entry
  347. //! pos: The index of the entry
  348. DLLEXPORT void removeEntry(int pos);
  349. //! Scrolls to a specific entry
  350. //! \param entry The index of the entry
  351. DLLEXPORT void setVScrollToEntry(int entry);
  352. //! Updates the maximum scroll height by adding the heights of all entries
  353. DLLEXPORT void updateVScroll();
  354. //! sets the size of the entry seperator
  355. DLLEXPORT void setEntrySeperatorSize(int size);
  356. //! sets the color of the entry seperator
  357. DLLEXPORT void setEntrySeperatorColor(int color);
  358. //! Processes a keyboard event. Called automatically by the framework
  359. //! \param te The event
  360. DLLEXPORT void doKeyboardEvent(KeyboardEvent& te) override;
  361. //! Updates the drawing
  362. //! \param tickVal The elapsed time in seconds since the last
  363. //! call of this function \return 1 if the drawing has changed
  364. //! since the last call
  365. DLLEXPORT bool tick(double tickVal) override;
  366. //! Draws the object to zRObj if it is visible
  367. //! \param zRObj The image to draw into
  368. DLLEXPORT void render(Image& rObj) override;
  369. //! Returns the index of an entry the mouse points to
  370. //! \param my The position of the mouse on the Y axis relative to
  371. //! the top edge of the list
  372. DLLEXPORT int getClickEntry(int my);
  373. //! Returns the number of entries
  374. DLLEXPORT int getEntryCount() const;
  375. //! Returns the index of an entry
  376. //! \param zEntry The drawing
  377. DLLEXPORT int getEntryPos(Drawable* zEntry);
  378. //! Returns an entry
  379. //! \param pos The index of the entry
  380. DLLEXPORT Drawable* getEntry(int pos) const;
  381. //! Returns an entry without increased reference counter
  382. //! \param pos The index of the entry
  383. DLLEXPORT Drawable* zEntry(int pos) const;
  384. //! Returns the needed height
  385. DLLEXPORT int getNeededHeight() const;
  386. //! returns the size of the entry seperator
  387. DLLEXPORT int getEntrySeperatorSize() const;
  388. //! returns the color of the entry seperator
  389. DLLEXPORT int getEntrySeperatorColor() const;
  390. };
  391. } // namespace Framework
  392. #endif