guiPopUpCtrlEx.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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, GFXDefaultGUIProfile, NumBitmapModes)
  117. Point2I mBitmapBounds; // Added
  118. S32 mIdMax;
  119. GuiTextEditCtrl* mSearchEdit; // Added
  120. virtual void addChildren();
  121. virtual void removeChildren();
  122. virtual void repositionPopup();
  123. static bool _setBitmaps(void* obj, const char* index, const char* data);
  124. public:
  125. GuiPopUpMenuCtrlEx(void);
  126. ~GuiPopUpMenuCtrlEx();
  127. GuiScrollCtrl::Region mScrollDir;
  128. bool onWake() override; // Added
  129. void onRemove() override;
  130. bool onAdd() override;
  131. void onSleep() override;
  132. void setBitmap(const char *name); // Added
  133. void sort();
  134. void sortID(); // Added
  135. void addEntry(const char *buf, S32 id = -1, U32 scheme = 0, const bool& indented = false);
  136. void addCategory(const char *buf)
  137. {
  138. addEntry(buf, -2, 0);
  139. }
  140. void addScheme(U32 id, ColorI fontColor, ColorI fontColorHL, ColorI fontColorSEL);
  141. void onRender(Point2I offset, const RectI &updateRect) override;
  142. void onAction() override;
  143. virtual void closePopUp();
  144. void clear() override;
  145. void clearEntry( S32 entry ); // Added
  146. void onMouseDown(const GuiEvent &event) override;
  147. void onMouseUp(const GuiEvent &event) override;
  148. void onMouseEnter(const GuiEvent &event) override; // Added
  149. void onMouseLeave(const GuiEvent &) override; // Added
  150. void setupAutoScroll(const GuiEvent &event);
  151. void autoScroll();
  152. bool onKeyDown(const GuiEvent &event) override;
  153. void reverseTextList();
  154. bool getFontColor(ColorI &fontColor, S32 id, bool selected, bool mouseOver);
  155. bool getColoredBox(ColorI &boxColor, S32 id); // Added
  156. S32 getSelected();
  157. void setSelected(S32 id, bool bNotifyScript = true);
  158. void setFirstSelected(bool bNotifyScript = true); // Added
  159. void setNoneSelected(); // Added
  160. const char *getScriptValue() override;
  161. const char *getTextById(S32 id);
  162. S32 findText( const char* text );
  163. S32 getNumEntries() { return( mEntries.size() ); }
  164. void replaceText(S32);
  165. void setCanSearch(const bool& canSearch) { mTextSearchItems = canSearch; }
  166. void setSearchText(String searchTxt) { mSearchText = String::ToLower(searchTxt); onAction(); }
  167. DECLARE_CONOBJECT(GuiPopUpMenuCtrlEx);
  168. DECLARE_CATEGORY( "Gui Lists" );
  169. DECLARE_DESCRIPTION( "A control that allows to select a value from a drop-down list." );
  170. static void initPersistFields(void);
  171. };
  172. #endif //_GUIIMPROVEDPOPUPCTRL_H_