guiPopUpCtrl.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #ifndef _GUIPOPUPCTRL_H_
  23. #define _GUIPOPUPCTRL_H_
  24. #ifndef _GUITEXTCTRL_H_
  25. #include "gui/guiTextCtrl.h"
  26. #endif
  27. #ifndef _GUITEXTLISTCTRL_H_
  28. #include "gui/guiTextListCtrl.h"
  29. #endif
  30. #ifndef _GUIBUTTONCTRL_H_
  31. #include "gui/buttons/guiButtonCtrl.h"
  32. #endif
  33. #ifndef _GUIBACKGROUNDCTRL_H_
  34. #include "gui/guiBackgroundCtrl.h"
  35. #endif
  36. #ifndef _GUISCROLLCTRL_H_
  37. #include "gui/containers/guiScrollCtrl.h"
  38. #endif
  39. class GuiPopUpMenuCtrl;
  40. class GuiPopupTextListCtrl;
  41. class GuiPopUpBackgroundCtrl : public GuiControl
  42. {
  43. protected:
  44. GuiPopUpMenuCtrl *mPopUpCtrl;
  45. GuiPopupTextListCtrl *mTextList;
  46. public:
  47. GuiPopUpBackgroundCtrl(GuiPopUpMenuCtrl *ctrl, GuiPopupTextListCtrl* textList);
  48. void onMouseDown(const GuiEvent &event);
  49. };
  50. class GuiPopupTextListCtrl : public GuiTextListCtrl
  51. {
  52. private:
  53. typedef GuiTextListCtrl Parent;
  54. protected:
  55. GuiPopUpMenuCtrl *mPopUpCtrl;
  56. public:
  57. GuiPopupTextListCtrl(); // for inheritance
  58. GuiPopupTextListCtrl(GuiPopUpMenuCtrl *ctrl);
  59. // GuiArrayCtrl overload:
  60. void onCellSelected(Point2I cell);
  61. // GuiControl overloads:
  62. bool onKeyDown(const GuiEvent &event);
  63. void onMouseDown(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; // DAW: Added
  78. ColorI colorbox; // DAW: Added
  79. };
  80. struct Scheme
  81. {
  82. U32 id;
  83. ColorI fontColor;
  84. ColorI fontColorHL;
  85. ColorI fontColorSEL;
  86. };
  87. bool mBackgroundCancel; // DAW: 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; // DAW: Added
  104. bool mRenderScrollInNA; // DAW: Added
  105. bool mReverseTextList; // DAW: Added - Should we reverse the text list if we display up?
  106. StringTableEntry mBitmapName; // DAW: Added
  107. Point2I mBitmapBounds; // DAW: Added
  108. TextureHandle mTextureNormal; // DAW: Added
  109. TextureHandle mTextureDepressed; // DAW: Added
  110. virtual void addChildren();
  111. virtual void repositionPopup();
  112. public:
  113. GuiPopUpMenuCtrl(void);
  114. ~GuiPopUpMenuCtrl();
  115. GuiScrollCtrl::Region mScrollDir;
  116. bool onWake(); // DAW: Added
  117. bool onAdd();
  118. void onSleep();
  119. void setBitmap(const char *name); // DAW: Added
  120. void sort();
  121. void sortID(); // DAW: Added
  122. void addEntry(const char *buf, S32 id, 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 onMouseDown(const GuiEvent &event);
  129. void onMouseUp(const GuiEvent &event);
  130. void onMouseEnter(const GuiEvent &event); // DAW: Added
  131. void onMouseLeave(const GuiEvent &); // DAW: Added
  132. void setupAutoScroll(const GuiEvent &event);
  133. void autoScroll();
  134. bool onKeyDown(const GuiEvent &event);
  135. void reverseTextList();
  136. bool getFontColor(ColorI &fontColor, S32 id, bool selected, bool mouseOver);
  137. bool getColoredBox(ColorI &boxColor, S32 id); // DAW: Added
  138. S32 getSelected();
  139. void setSelected(S32 id, bool bNotifyScript = true);
  140. void setFirstSelected(); // DAW: Added
  141. void setNoneSelected(); // DAW: Added
  142. const char *getScriptValue();
  143. const char *getTextById(S32 id);
  144. S32 findText( const char* text );
  145. S32 getNumEntries() { return( mEntries.size() ); }
  146. void replaceText(S32);
  147. DECLARE_CONOBJECT(GuiPopUpMenuCtrl);
  148. static void initPersistFields(void);
  149. };
  150. #endif //_GUI_POPUPMENU_CTRL_H