guiDropDownCtrl.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 _GUIDROPDOWNCTRL_H_
  23. #define _GUIDROPDOWNCTRL_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/guiControl.h"
  26. #endif
  27. #ifndef _GUIBUTTONCTRL_H_
  28. #include "gui/buttons/guiButtonCtrl.h"
  29. #endif
  30. #ifndef _GUISCROLLCTRL_H_
  31. #include "gui/containers/guiScrollCtrl.h"
  32. #endif
  33. #ifndef _GUILISTBOXCTRL_H_
  34. #include "gui/guiListBoxCtrl.h"
  35. #endif
  36. class GuiDropDownCtrl;
  37. class GuiDropDownBGCtrl : public GuiControl
  38. {
  39. protected:
  40. GuiDropDownCtrl *mDropDownCtrl;
  41. public:
  42. GuiDropDownBGCtrl(GuiDropDownCtrl *ctrl);
  43. void onTouchUp(const GuiEvent &event);
  44. };
  45. class GuiDropDownListBoxCtrl : public GuiListBoxCtrl
  46. {
  47. private:
  48. typedef GuiListBoxCtrl Parent;
  49. protected:
  50. GuiDropDownCtrl *mDropDownCtrl;
  51. public:
  52. GuiDropDownListBoxCtrl(GuiDropDownCtrl *ctrl);
  53. void addSelection(LBItem *item, S32 index);
  54. void setCurSel(S32 index);
  55. void onTouchUp(const GuiEvent &event);
  56. };
  57. class GuiDropDownCtrl : public GuiButtonCtrl
  58. {
  59. private:
  60. typedef GuiButtonCtrl Parent;
  61. const static S32 DEFAULT_MAX_HEIGHT = 300;
  62. const static S32 DEFAULT_THICKNESS = 12;
  63. S32 mMaxHeight;
  64. bool mIsOpen;
  65. GuiDropDownBGCtrl *mBackground;
  66. GuiDropDownListBoxCtrl *mListBox;
  67. GuiScrollCtrl *mScroll;
  68. GuiControlProfile *mBackgroundProfile; //Used to render the background when the drop down is open
  69. GuiControlProfile *mListBoxProfile; //Used to render the list box items
  70. GuiControlProfile *mScrollProfile; //Used to render the scroll content area
  71. GuiControlProfile *mThumbProfile; //Used to render the thumb and arrow buttons
  72. GuiControlProfile *mTrackProfile; //Used to render the tracks
  73. GuiControlProfile *mArrowProfile; //Used to render the arrow buttons
  74. S32 mScrollBarThickness;
  75. bool mShowArrowButtons;
  76. bool mUseConstantHeightThumb;
  77. protected:
  78. public:
  79. GuiDropDownCtrl();
  80. static void initPersistFields();
  81. virtual void onTouchUp(const GuiEvent &event);
  82. GuiControlState getCurrentState();
  83. void onRender(Point2I offset, const RectI &updateRect);
  84. bool onKeyDown(const GuiEvent &event);
  85. virtual void onAction();
  86. void itemSelected();
  87. void openDropDown();
  88. void closeDropDown();
  89. bool onWake();
  90. void onSleep();
  91. void setControlBackgroundProfile(GuiControlProfile* prof);
  92. void setControlListBoxProfile(GuiControlProfile* prof);
  93. void setControlScrollProfile(GuiControlProfile* prof);
  94. void setControlThumbProfile(GuiControlProfile* prof);
  95. void setControlTrackProfile(GuiControlProfile* prof);
  96. void setControlArrowProfile(GuiControlProfile* prof);
  97. void setConstantThumbHeight(bool isConstant) { mUseConstantHeightThumb = isConstant; }
  98. void setShowArrowButtons(bool show) { mShowArrowButtons = show; }
  99. void setScrollBarThickness(S32 thickness) { mScrollBarThickness = thickness; }
  100. inline GuiListBoxCtrl* getList() { return mListBox; }
  101. static bool writeMaxHeightFn(void* obj, StringTableEntry pFieldName) { return static_cast<GuiDropDownCtrl*>(obj)->mMaxHeight != DEFAULT_MAX_HEIGHT; }
  102. static bool writeConstantThumbHeightFn(void* obj, StringTableEntry pFieldName) { return static_cast<GuiDropDownCtrl*>(obj)->mUseConstantHeightThumb; }
  103. static bool writeShowArrowButtonsFn(void* obj, StringTableEntry pFieldName) { return static_cast<GuiDropDownCtrl*>(obj)->mShowArrowButtons; }
  104. static bool writeScrollBarThicknessFn(void* obj, StringTableEntry pFieldName) { return static_cast<GuiDropDownCtrl*>(obj)->mScrollBarThickness != DEFAULT_THICKNESS; }
  105. DECLARE_CONOBJECT(GuiDropDownCtrl);
  106. };
  107. #endif