guiPopUpCtrlEx.h 5.3 KB

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