2
0

guiPopUpCtrlEx.h 6.4 KB

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