guiDropDownCtrl.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. S32 mMaxHeight;
  62. bool mIsOpen;
  63. GuiDropDownBGCtrl *mBackground;
  64. GuiDropDownListBoxCtrl *mListBox;
  65. GuiScrollCtrl *mScroll;
  66. GuiControlProfile *mBackgroundProfile; //Used to render the background when the drop down is open
  67. GuiControlProfile *mListBoxProfile; //Used to render the list box items
  68. GuiControlProfile *mScrollProfile; //Used to render the scroll content area
  69. GuiControlProfile *mThumbProfile; //Used to render the thumb and arrow buttons
  70. GuiControlProfile *mTrackProfile; //Used to render the tracks
  71. GuiControlProfile *mArrowProfile; //Used to render the arrow buttons
  72. S32 mScrollBarThickness;
  73. bool mShowArrowButtons;
  74. bool mUseConstantHeightThumb;
  75. protected:
  76. public:
  77. GuiDropDownCtrl();
  78. static void initPersistFields();
  79. virtual void onTouchUp(const GuiEvent &event);
  80. GuiControlState getCurrentState();
  81. void onRender(Point2I offset, const RectI &updateRect);
  82. bool onKeyDown(const GuiEvent &event);
  83. virtual void onAction();
  84. void itemSelected();
  85. void openDropDown();
  86. void closeDropDown();
  87. bool onWake();
  88. void onSleep();
  89. void setControlBackgroundProfile(GuiControlProfile* prof);
  90. void setControlListBoxProfile(GuiControlProfile* prof);
  91. void setControlScrollProfile(GuiControlProfile* prof);
  92. void setControlThumbProfile(GuiControlProfile* prof);
  93. void setControlTrackProfile(GuiControlProfile* prof);
  94. void setControlArrowProfile(GuiControlProfile* prof);
  95. void setConstantThumbHeight(bool isConstant) { mUseConstantHeightThumb = isConstant; }
  96. void setShowArrowButtons(bool show) { mShowArrowButtons = show; }
  97. void setScrollBarThickness(S32 thickness) { mScrollBarThickness = thickness; }
  98. inline GuiListBoxCtrl* getList() { return mListBox; }
  99. DECLARE_CONOBJECT(GuiDropDownCtrl);
  100. };
  101. #endif