guiPopUpCtrlEx.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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. // Revision History:
  23. // January 3, 2004 David Wyand Added onMouseEnter() and onMouseLeave() methods to
  24. // GuiPopUpMenuCtrl class. Also added the bool mMouseOver
  25. // to the same class.
  26. // January 3, 2004 David Wyand Added the bool mBackgroundCancel to the GuiPopUpMenuCtrl
  27. // class.
  28. // May 19, 2004 David Wyand Added the bool usesColorBox and ColorI colorbox to the
  29. // Entry structure of the GuiPopUpMenuCtrl class. These
  30. // are used to draw a colored rectangle beside the text in
  31. // the list.
  32. // November 16, 2005 David Wyand Added the method setNoneSelected() to set none of the
  33. // items as selected. Use this over setSelected(-1); when
  34. // there are negative IDs in the item list.
  35. // January 11, 2006 David Wyand Added the method setFirstSelected() to set the first
  36. // item to be the selected one. Handy when you don't know
  37. // the ID of the first item.
  38. //
  39. #ifndef _GUIPOPUPCTRLEX_H_
  40. #define _GUIPOPUPCTRLEX_H_
  41. #ifndef _GUITEXTCTRL_H_
  42. #include "gui/guiTextCtrl.h"
  43. #endif
  44. #ifndef _GUITEXTLISTCTRL_H_
  45. #include "gui/guiTextListCtrl.h"
  46. #endif
  47. #ifndef _GUIBUTTONCTRL_H_
  48. #include "gui/buttons/guiButtonCtrl.h"
  49. #endif
  50. #ifndef _GUISCROLLCTRL_H_
  51. #include "gui/containers/guiScrollCtrl.h"
  52. #endif
  53. class GuiPopUpMenuCtrlEx;
  54. class GuiPopupTextListCtrlEx;
  55. class GuiPopUpBackgroundCtrlEx : public GuiControl
  56. {
  57. protected:
  58. GuiPopUpMenuCtrlEx *mPopUpCtrl;
  59. GuiPopupTextListCtrlEx *mTextList;
  60. public:
  61. GuiPopUpBackgroundCtrlEx(GuiPopUpMenuCtrlEx *ctrl, GuiPopupTextListCtrlEx* textList);
  62. void onTouchDown(const GuiEvent &event);
  63. };
  64. class GuiPopupTextListCtrlEx : public GuiTextListCtrl
  65. {
  66. private:
  67. typedef GuiTextListCtrl Parent;
  68. bool hasCategories();
  69. protected:
  70. GuiPopUpMenuCtrlEx *mPopUpCtrl;
  71. public:
  72. GuiPopupTextListCtrlEx(); // for inheritance
  73. GuiPopupTextListCtrlEx(GuiPopUpMenuCtrlEx *ctrl);
  74. // GuiArrayCtrl overload:
  75. void onCellSelected(Point2I cell);
  76. // GuiControl overloads:
  77. bool onKeyDown(const GuiEvent &event);
  78. void onTouchUp(const GuiEvent &event);
  79. void onTouchMove(const GuiEvent &event);
  80. void onRenderCell(Point2I offset, Point2I cell, bool selected, bool mouseOver);
  81. };
  82. class GuiPopUpMenuCtrlEx : public GuiControl
  83. {
  84. typedef GuiControl Parent;
  85. public:
  86. struct Entry
  87. {
  88. char buf[256];
  89. S32 id;
  90. U16 ascii;
  91. U16 scheme;
  92. bool usesColorBox; // DAW: Added
  93. ColorI colorbox; // DAW: Added
  94. };
  95. struct Scheme
  96. {
  97. U32 id;
  98. ColorI fontColor;
  99. ColorI fontColorHL;
  100. ColorI fontColorSEL;
  101. };
  102. bool mBackgroundCancel; // DAW: Added
  103. protected:
  104. GuiPopupTextListCtrlEx *mTl;
  105. GuiScrollCtrl *mSc;
  106. GuiPopUpBackgroundCtrlEx *mBackground;
  107. Vector<Entry> mEntries;
  108. Vector<Scheme> mSchemes;
  109. S32 mSelIndex;
  110. S32 mMaxPopupHeight;
  111. F32 mIncValue;
  112. F32 mScrollCount;
  113. S32 mLastYvalue;
  114. GuiEvent mEventSave;
  115. S32 mRevNum;
  116. bool mInAction;
  117. bool mReplaceText;
  118. bool mMouseOver; // DAW: Added
  119. bool mRenderScrollInNA; // DAW: Added
  120. bool mReverseTextList; // DAW: Added - Should we reverse the text list if we display up?
  121. bool mHotTrackItems;
  122. StringTableEntry mBitmapName; // DAW: Added
  123. Point2I mBitmapBounds; // DAW: Added
  124. TextureHandle mTextureNormal; // DAW: Added
  125. TextureHandle mTextureDepressed; // DAW: Added
  126. virtual void addChildren();
  127. virtual void repositionPopup();
  128. public:
  129. GuiPopUpMenuCtrlEx(void);
  130. ~GuiPopUpMenuCtrlEx();
  131. GuiScrollCtrl::Region mScrollDir;
  132. bool onWake(); // DAW: Added
  133. bool onAdd();
  134. void onSleep();
  135. void setBitmap(const char *name); // DAW: Added
  136. void sort();
  137. void sortID(); // DAW: Added
  138. void addEntry(const char *buf, S32 id, U32 scheme = 0);
  139. void addScheme(U32 id, ColorI fontColor, ColorI fontColorHL, ColorI fontColorSEL);
  140. void onRender(Point2I offset, const RectI &updateRect);
  141. void onAction();
  142. virtual void closePopUp();
  143. void clear();
  144. void onTouchDown(const GuiEvent &event);
  145. void onTouchUp(const GuiEvent &event);
  146. void onTouchEnter(const GuiEvent &event); // DAW: Added
  147. void onTouchLeave(const GuiEvent &); // DAW: Added
  148. void setupAutoScroll(const GuiEvent &event);
  149. void autoScroll();
  150. bool onKeyDown(const GuiEvent &event);
  151. void reverseTextList();
  152. bool getFontColor(ColorI &fontColor, S32 id, bool selected, bool mouseOver);
  153. bool getColoredBox(ColorI &boxColor, S32 id); // DAW: Added
  154. S32 getSelected();
  155. void setSelected(S32 id);
  156. void setFirstSelected(); // DAW: Added
  157. void setNoneSelected(); // DAW: Added
  158. const char *getScriptValue();
  159. const char *getTextById(S32 id);
  160. S32 findText( const char* text );
  161. S32 getNumEntries() { return( mEntries.size() ); }
  162. void replaceText(S32);
  163. DECLARE_CONOBJECT(GuiPopUpMenuCtrlEx);
  164. static void initPersistFields(void);
  165. };
  166. #endif //_GUIIMPROVEDPOPUPCTRL_H_