guiPopUpCtrlEx.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUIPOPUPCTRLEX_H_
  23. #define _GUIPOPUPCTRLEX_H_
  24. #ifndef _GUITEXTCTRL_H_
  25. #include "gui/controls/guiTextCtrl.h"
  26. #endif
  27. #ifndef _GUITEXTLISTCTRL_H_
  28. #include "gui/controls/guiTextListCtrl.h"
  29. #endif
  30. #ifndef _GUIBUTTONCTRL_H_
  31. #include "gui/buttons/guiButtonCtrl.h"
  32. #endif
  33. #ifndef _GUISCROLLCTRL_H_
  34. #include "gui/containers/guiScrollCtrl.h"
  35. #endif
  36. #include "guiTextEditCtrl.h"
  37. class GuiPopUpMenuCtrlEx;
  38. class GuiPopupTextListCtrlEx;
  39. #include "T3D/assets/ImageAsset.h"
  40. class GuiPopUpBackgroundCtrlEx : public GuiControl
  41. {
  42. protected:
  43. GuiPopUpMenuCtrlEx *mPopUpCtrl;
  44. GuiPopupTextListCtrlEx *mTextList;
  45. public:
  46. GuiPopUpBackgroundCtrlEx(GuiPopUpMenuCtrlEx *ctrl, GuiPopupTextListCtrlEx* textList);
  47. void onMouseDown(const GuiEvent &event) override;
  48. };
  49. class GuiPopupTextListCtrlEx : public GuiTextListCtrl
  50. {
  51. private:
  52. typedef GuiTextListCtrl Parent;
  53. bool hasCategories();
  54. protected:
  55. GuiPopUpMenuCtrlEx *mPopUpCtrl;
  56. public:
  57. GuiPopupTextListCtrlEx(); // for inheritance
  58. GuiPopupTextListCtrlEx(GuiPopUpMenuCtrlEx *ctrl);
  59. // GuiArrayCtrl overload:
  60. void onCellSelected(Point2I cell) override;
  61. // GuiControl overloads:
  62. bool onKeyDown(const GuiEvent &event) override;
  63. void onMouseUp(const GuiEvent &event) override;
  64. void onMouseMove(const GuiEvent &event) override;
  65. void onRenderCell(Point2I offset, Point2I cell, bool selected, bool mouseOver) override;
  66. };
  67. class GuiPopUpMenuCtrlEx : public GuiTextCtrl
  68. {
  69. typedef GuiTextCtrl Parent;
  70. public:
  71. struct Entry
  72. {
  73. char buf[256];
  74. S32 id;
  75. U16 ascii;
  76. U16 scheme;
  77. bool usesColorBox; // Added
  78. ColorI colorbox; // Added
  79. bool indented; // Added
  80. };
  81. struct Scheme
  82. {
  83. U32 id;
  84. ColorI fontColor;
  85. ColorI fontColorHL;
  86. ColorI fontColorSEL;
  87. };
  88. bool mBackgroundCancel; // Added
  89. protected:
  90. GuiPopupTextListCtrlEx *mTl;
  91. GuiScrollCtrl *mSc;
  92. GuiPopUpBackgroundCtrlEx *mBackground;
  93. Vector<Entry> mEntries;
  94. Vector<Scheme> mSchemes;
  95. S32 mSelIndex;
  96. S32 mMaxPopupHeight;
  97. F32 mIncValue;
  98. F32 mScrollCount;
  99. S32 mLastYvalue;
  100. GuiEvent mEventSave;
  101. S32 mRevNum;
  102. bool mInAction;
  103. bool mReplaceText;
  104. bool mMouseOver; // Added
  105. bool mRenderScrollInNA; // Added
  106. bool mReverseTextList; // Added - Should we reverse the text list if we display up?
  107. bool mHotTrackItems;
  108. bool mTextSearchItems;
  109. String mSearchText;
  110. enum BitmapModes
  111. {
  112. Normal,
  113. Depressed,
  114. NumBitmapModes = 2
  115. };
  116. DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrlEx, Bitmap, NumBitmapModes, onBitmapChanged);
  117. DECLARE_IMAGEASSET_ARRAY_SETGET(GuiPopUpMenuCtrlEx, Bitmap);
  118. void onBitmapChanged() {}
  119. Point2I mBitmapBounds; // Added
  120. S32 mIdMax;
  121. GuiTextEditCtrl* mSearchEdit; // Added
  122. virtual void addChildren();
  123. virtual void removeChildren();
  124. virtual void repositionPopup();
  125. static bool _setBitmaps(void* obj, const char* index, const char* data);
  126. public:
  127. GuiPopUpMenuCtrlEx(void);
  128. ~GuiPopUpMenuCtrlEx();
  129. GuiScrollCtrl::Region mScrollDir;
  130. bool onWake() override; // Added
  131. void onRemove() override;
  132. bool onAdd() override;
  133. void onSleep() override;
  134. void setBitmap(const char *name); // Added
  135. void sort();
  136. void sortID(); // Added
  137. void addEntry(const char *buf, S32 id = -1, U32 scheme = 0, const bool& indented = false);
  138. void addCategory(const char *buf)
  139. {
  140. addEntry(buf, -2, 0);
  141. }
  142. void addScheme(U32 id, ColorI fontColor, ColorI fontColorHL, ColorI fontColorSEL);
  143. void onRender(Point2I offset, const RectI &updateRect) override;
  144. void onAction() override;
  145. virtual void closePopUp();
  146. void clear() override;
  147. void clearEntry( S32 entry ); // Added
  148. void onMouseDown(const GuiEvent &event) override;
  149. void onMouseUp(const GuiEvent &event) override;
  150. void onMouseEnter(const GuiEvent &event) override; // Added
  151. void onMouseLeave(const GuiEvent &) override; // Added
  152. void setupAutoScroll(const GuiEvent &event);
  153. void autoScroll();
  154. bool onKeyDown(const GuiEvent &event) override;
  155. void reverseTextList();
  156. bool getFontColor(ColorI &fontColor, S32 id, bool selected, bool mouseOver);
  157. bool getColoredBox(ColorI &boxColor, S32 id); // Added
  158. S32 getSelected();
  159. void setSelected(S32 id, bool bNotifyScript = true);
  160. void setFirstSelected(bool bNotifyScript = true); // Added
  161. void setNoneSelected(); // Added
  162. const char *getScriptValue() override;
  163. const char *getTextById(S32 id);
  164. S32 findText( const char* text );
  165. S32 getNumEntries() { return( mEntries.size() ); }
  166. void replaceText(S32);
  167. void setCanSearch(const bool& canSearch) { mTextSearchItems = canSearch; }
  168. void setSearchText(String searchTxt) { mSearchText = String::ToLower(searchTxt); onAction(); }
  169. DECLARE_CONOBJECT(GuiPopUpMenuCtrlEx);
  170. DECLARE_CATEGORY( "Gui Lists" );
  171. DECLARE_DESCRIPTION( "A control that allows to select a value from a drop-down list." );
  172. static void initPersistFields(void);
  173. };
  174. #endif //_GUIIMPROVEDPOPUPCTRL_H_