guiPopUpCtrl.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 _GUIPOPUPCTRL_H_
  23. #define _GUIPOPUPCTRL_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 _GUIBACKGROUNDCTRL_H_
  34. #include "gui/controls/guiBackgroundCtrl.h"
  35. #endif
  36. #ifndef _GUISCROLLCTRL_H_
  37. #include "gui/containers/guiScrollCtrl.h"
  38. #endif
  39. #include "T3D/assets/ImageAsset.h"
  40. class GuiPopUpMenuCtrl;
  41. class GuiPopupTextListCtrl;
  42. class GuiPopUpBackgroundCtrl : public GuiControl
  43. {
  44. protected:
  45. GuiPopUpMenuCtrl *mPopUpCtrl;
  46. GuiPopupTextListCtrl *mTextList;
  47. public:
  48. GuiPopUpBackgroundCtrl(GuiPopUpMenuCtrl *ctrl, GuiPopupTextListCtrl* textList);
  49. void onMouseDown(const GuiEvent &event);
  50. };
  51. class GuiPopupTextListCtrl : public GuiTextListCtrl
  52. {
  53. private:
  54. typedef GuiTextListCtrl Parent;
  55. protected:
  56. GuiPopUpMenuCtrl *mPopUpCtrl;
  57. public:
  58. GuiPopupTextListCtrl(); // for inheritance
  59. GuiPopupTextListCtrl(GuiPopUpMenuCtrl *ctrl);
  60. // GuiArrayCtrl overload:
  61. void onCellSelected(Point2I cell);
  62. // GuiControl overloads:
  63. bool onKeyDown(const GuiEvent &event);
  64. void onMouseUp(const GuiEvent &event);
  65. void onRenderCell(Point2I offset, Point2I cell, bool selected, bool mouseOver);
  66. };
  67. class GuiPopUpMenuCtrl : 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. };
  80. struct Scheme
  81. {
  82. U32 id;
  83. ColorI fontColor;
  84. ColorI fontColorHL;
  85. ColorI fontColorSEL;
  86. };
  87. bool mBackgroundCancel; // Added
  88. protected:
  89. GuiPopupTextListCtrl *mTl;
  90. GuiScrollCtrl *mSc;
  91. GuiPopUpBackgroundCtrl *mBackground;
  92. Vector<Entry> mEntries;
  93. Vector<Scheme> mSchemes;
  94. S32 mSelIndex;
  95. S32 mMaxPopupHeight;
  96. F32 mIncValue;
  97. F32 mScrollCount;
  98. S32 mLastYvalue;
  99. GuiEvent mEventSave;
  100. S32 mRevNum;
  101. bool mInAction;
  102. bool mReplaceText;
  103. bool mMouseOver; // Added
  104. bool mRenderScrollInNA; // Added
  105. bool mReverseTextList; // Added - Should we reverse the text list if we display up?
  106. enum BitmapModes
  107. {
  108. Normal,
  109. Depressed,
  110. NumBitmapModes = 2
  111. };
  112. DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrl, Bitmap, NumBitmapModes);
  113. DECLARE_IMAGEASSET_ARRAY_SETGET(GuiPopUpMenuCtrl, 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. GuiPopUpMenuCtrl(void);
  121. ~GuiPopUpMenuCtrl();
  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. bool setEntryText( S32 id, const char* buf );
  147. S32 getSelected();
  148. void setSelected(S32 id, bool bNotifyScript = true);
  149. void setFirstSelected(bool bNotifyScript = true); // Added
  150. void setNoneSelected(); // Added
  151. const char *getScriptValue();
  152. const char *getTextById(S32 id);
  153. S32 findText( const char* text );
  154. S32 getNumEntries() { return( mEntries.size() ); }
  155. void replaceText(S32);
  156. DECLARE_CONOBJECT( GuiPopUpMenuCtrl );
  157. DECLARE_CATEGORY( "Gui Lists" );
  158. DECLARE_DESCRIPTION( "A control that allows to select a value from a drop-down list." );
  159. static void initPersistFields(void);
  160. };
  161. #endif //_GUI_POPUPMENU_CTRL_H