guiPopUpCtrlEx.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. class GuiPopUpMenuCtrlEx;
  37. class GuiPopupTextListCtrlEx;
  38. #include "T3D/assets/ImageAsset.h"
  39. class GuiPopUpBackgroundCtrlEx : public GuiControl
  40. {
  41. protected:
  42. GuiPopUpMenuCtrlEx *mPopUpCtrl;
  43. GuiPopupTextListCtrlEx *mTextList;
  44. public:
  45. GuiPopUpBackgroundCtrlEx(GuiPopUpMenuCtrlEx *ctrl, GuiPopupTextListCtrlEx* textList);
  46. void onMouseDown(const GuiEvent &event);
  47. };
  48. class GuiPopupTextListCtrlEx : public GuiTextListCtrl
  49. {
  50. private:
  51. typedef GuiTextListCtrl Parent;
  52. bool hasCategories();
  53. protected:
  54. GuiPopUpMenuCtrlEx *mPopUpCtrl;
  55. public:
  56. GuiPopupTextListCtrlEx(); // for inheritance
  57. GuiPopupTextListCtrlEx(GuiPopUpMenuCtrlEx *ctrl);
  58. // GuiArrayCtrl overload:
  59. void onCellSelected(Point2I cell);
  60. // GuiControl overloads:
  61. bool onKeyDown(const GuiEvent &event);
  62. void onMouseUp(const GuiEvent &event);
  63. void onMouseMove(const GuiEvent &event);
  64. void onRenderCell(Point2I offset, Point2I cell, bool selected, bool mouseOver);
  65. };
  66. class GuiPopUpMenuCtrlEx : public GuiTextCtrl
  67. {
  68. typedef GuiTextCtrl Parent;
  69. public:
  70. struct Entry
  71. {
  72. char buf[256];
  73. S32 id;
  74. U16 ascii;
  75. U16 scheme;
  76. bool usesColorBox; // Added
  77. ColorI colorbox; // Added
  78. };
  79. struct Scheme
  80. {
  81. U32 id;
  82. ColorI fontColor;
  83. ColorI fontColorHL;
  84. ColorI fontColorSEL;
  85. };
  86. bool mBackgroundCancel; // Added
  87. protected:
  88. GuiPopupTextListCtrlEx *mTl;
  89. GuiScrollCtrl *mSc;
  90. GuiPopUpBackgroundCtrlEx *mBackground;
  91. Vector<Entry> mEntries;
  92. Vector<Scheme> mSchemes;
  93. S32 mSelIndex;
  94. S32 mMaxPopupHeight;
  95. F32 mIncValue;
  96. F32 mScrollCount;
  97. S32 mLastYvalue;
  98. GuiEvent mEventSave;
  99. S32 mRevNum;
  100. bool mInAction;
  101. bool mReplaceText;
  102. bool mMouseOver; // Added
  103. bool mRenderScrollInNA; // Added
  104. bool mReverseTextList; // Added - Should we reverse the text list if we display up?
  105. bool mHotTrackItems;
  106. enum BitmapModes
  107. {
  108. Normal,
  109. Depressed,
  110. NumBitmapModes = 2
  111. };
  112. DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrlEx, Bitmap, NumBitmapModes);
  113. DECLARE_IMAGEASSET_ARRAY_SETGET(GuiPopUpMenuCtrlEx, Bitmap);
  114. Point2I mBitmapBounds; // Added
  115. S32 mIdMax;
  116. virtual void addChildren();
  117. virtual void repositionPopup();
  118. static bool _setBitmaps(void* obj, const char* index, const char* data);
  119. public:
  120. GuiPopUpMenuCtrlEx(void);
  121. ~GuiPopUpMenuCtrlEx();
  122. GuiScrollCtrl::Region mScrollDir;
  123. bool onWake(); // Added
  124. bool onAdd();
  125. void onSleep();
  126. void setBitmap(const char *name); // Added
  127. void sort();
  128. void sortID(); // Added
  129. void addEntry(const char *buf, S32 id = -1, U32 scheme = 0);
  130. void addScheme(U32 id, ColorI fontColor, ColorI fontColorHL, ColorI fontColorSEL);
  131. void onRender(Point2I offset, const RectI &updateRect);
  132. void onAction();
  133. virtual void closePopUp();
  134. void clear();
  135. void clearEntry( S32 entry ); // Added
  136. void onMouseDown(const GuiEvent &event);
  137. void onMouseUp(const GuiEvent &event);
  138. void onMouseEnter(const GuiEvent &event); // Added
  139. void onMouseLeave(const GuiEvent &); // Added
  140. void setupAutoScroll(const GuiEvent &event);
  141. void autoScroll();
  142. bool onKeyDown(const GuiEvent &event);
  143. void reverseTextList();
  144. bool getFontColor(ColorI &fontColor, S32 id, bool selected, bool mouseOver);
  145. bool getColoredBox(ColorI &boxColor, S32 id); // Added
  146. S32 getSelected();
  147. void setSelected(S32 id, bool bNotifyScript = true);
  148. void setFirstSelected(bool bNotifyScript = true); // Added
  149. void setNoneSelected(); // Added
  150. const char *getScriptValue();
  151. const char *getTextById(S32 id);
  152. S32 findText( const char* text );
  153. S32 getNumEntries() { return( mEntries.size() ); }
  154. void replaceText(S32);
  155. DECLARE_CONOBJECT(GuiPopUpMenuCtrlEx);
  156. DECLARE_CATEGORY( "Gui Lists" );
  157. DECLARE_DESCRIPTION( "A control that allows to select a value from a drop-down list." );
  158. static void initPersistFields(void);
  159. };
  160. #endif //_GUIIMPROVEDPOPUPCTRL_H_