guiListBoxCtrl.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 _GUI_LISTBOXCTRL_H_
  23. #define _GUI_LISTBOXCTRL_H_
  24. #ifndef _CONSOLETYPES_H_
  25. #include "console/consoleTypes.h"
  26. #endif
  27. #ifndef _GUICONTROL_H_
  28. #include "gui/guiControl.h"
  29. #endif
  30. #ifndef _DGL_H_
  31. #include "graphics/dgl.h"
  32. #endif
  33. #ifndef _H_GUIDEFAULTCONTROLRENDER_
  34. #include "gui/guiDefaultControlRender.h"
  35. #endif
  36. #ifndef _GUISCROLLCTRL_H_
  37. #include "gui/containers/guiScrollCtrl.h"
  38. #endif
  39. class GuiListBoxCtrl : public GuiControl
  40. {
  41. private:
  42. typedef GuiControl Parent;
  43. public:
  44. GuiListBoxCtrl();
  45. ~GuiListBoxCtrl();
  46. DECLARE_CONOBJECT(GuiListBoxCtrl);
  47. struct LBItem
  48. {
  49. StringTableEntry itemText;
  50. bool isSelected;
  51. void* itemData;
  52. ColorF color;
  53. bool hasColor;
  54. };
  55. VectorPtr<LBItem*> mItems;
  56. VectorPtr<LBItem*> mSelectedItems;
  57. bool mMultipleSelections;
  58. Point2I mItemSize;
  59. bool mFitParentWidth;
  60. LBItem* mLastClickItem;
  61. // Persistence
  62. static void initPersistFields();
  63. // Item Accessors
  64. S32 getItemCount();
  65. S32 getSelCount();
  66. S32 getSelectedItem();
  67. void getSelectedItems( Vector<S32> &Items );
  68. S32 getItemIndex( LBItem *item );
  69. StringTableEntry getItemText( S32 index );
  70. void setCurSel( S32 index );
  71. void setCurSelRange( S32 start, S32 stop );
  72. void setItemText( S32 index, StringTableEntry text );
  73. S32 addItem( StringTableEntry text, void *itemData = NULL );
  74. S32 addItemWithColor( StringTableEntry text, ColorF color = ColorF(-1, -1, -1), void *itemData = NULL);
  75. S32 insertItem( S32 index, StringTableEntry text, void *itemData = NULL );
  76. S32 insertItemWithColor( S32 index, StringTableEntry text, ColorF color = ColorF(-1, -1, -1), void *itemData = NULL);
  77. S32 findItemText( StringTableEntry text, bool caseSensitive = false );
  78. void setItemColor(S32 index, ColorF color);
  79. void clearItemColor(S32 index);
  80. void clearAllColors();
  81. void deleteItem( S32 index );
  82. void clearItems();
  83. void clearSelection();
  84. void removeSelection( LBItem *item, S32 index );
  85. void removeSelection( S32 index );
  86. void addSelection( LBItem *item, S32 index );
  87. void addSelection( S32 index );
  88. inline void setMultipleSelection(bool allowMultipleSelect = true) { mMultipleSelections = allowMultipleSelect; };
  89. inline bool getMultipleSelection() { return mMultipleSelections; };
  90. // Sizing
  91. void updateSize();
  92. virtual void parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent);
  93. virtual bool onWake();
  94. virtual void addObject(SimObject *obj);
  95. // Rendering
  96. virtual void onRender( Point2I offset, const RectI &updateRect );
  97. virtual void onRenderItem( RectI &itemRect, LBItem *item );
  98. void drawBox( RectI &box, ColorI &boxColor );
  99. // Mouse Events
  100. virtual void onTouchDown( const GuiEvent &event );
  101. virtual void onTouchDragged(const GuiEvent &event);
  102. };
  103. #endif