guiListBoxCtrl.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 _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/core/guiControl.h"
  29. #endif
  30. #ifndef _DGL_H_
  31. #include "gfx/gfxDevice.h"
  32. #endif
  33. #ifndef _H_GUIDEFAULTCONTROLRENDER_
  34. #include "gui/core/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. DECLARE_CATEGORY( "Gui Lists" );
  48. DECLARE_DESCRIPTION( "Linear list of text items." );
  49. DECLARE_CALLBACK( void, onMouseDragged, ());
  50. DECLARE_CALLBACK( void, onClearSelection, ());
  51. DECLARE_CALLBACK( void, onUnSelect, ( S32 index, const char* itemText));
  52. DECLARE_CALLBACK( void, onSelect, ( S32 index , const char* itemText ));
  53. DECLARE_CALLBACK( void, onDoubleClick, ());
  54. DECLARE_CALLBACK( void, onMouseUp, ( S32 itemHit, S32 mouseClickCount ));
  55. DECLARE_CALLBACK( void, onDeleteKey, ());
  56. DECLARE_CALLBACK( bool, isObjectMirrored, ( const char* indexIdString ));
  57. struct LBItem
  58. {
  59. StringTableEntry itemText;
  60. String itemTooltip;
  61. bool isSelected;
  62. void* itemData;
  63. LinearColorF color;
  64. bool hasColor;
  65. };
  66. VectorPtr<LBItem*> mItems;
  67. VectorPtr<LBItem*> mSelectedItems;
  68. VectorPtr<LBItem*> mFilteredItems;
  69. bool mMultipleSelections;
  70. Point2I mItemSize;
  71. bool mFitParentWidth;
  72. bool mColorBullet;
  73. LBItem* mLastClickItem;
  74. // Persistence
  75. static void initPersistFields();
  76. // Item Accessors
  77. S32 getItemCount();
  78. S32 getSelCount();
  79. S32 getSelectedItem();
  80. void getSelectedItems( Vector<S32> &Items );
  81. S32 getItemIndex( LBItem *item );
  82. StringTableEntry getItemText( S32 index );
  83. SimObject* getItemObject( S32 index );
  84. void setCurSel( S32 index );
  85. void setCurSelRange( S32 start, S32 stop );
  86. void setItemText( S32 index, StringTableEntry text );
  87. S32 addItem( StringTableEntry text, void *itemData = NULL );
  88. S32 addItemWithColor( StringTableEntry text, LinearColorF color = LinearColorF(-1, -1, -1), void *itemData = NULL);
  89. S32 insertItem( S32 index, StringTableEntry text, void *itemData = NULL );
  90. S32 insertItemWithColor( S32 index, StringTableEntry text, LinearColorF color = LinearColorF(-1, -1, -1), void *itemData = NULL);
  91. S32 findItemText( StringTableEntry text, bool caseSensitive = false );
  92. void setItemColor(S32 index, const LinearColorF& color);
  93. void clearItemColor(S32 index);
  94. void deleteItem( S32 index );
  95. void clearItems();
  96. void clearSelection();
  97. void removeSelection( LBItem *item, S32 index );
  98. void removeSelection( S32 index );
  99. void addSelection( LBItem *item, S32 index );
  100. void addSelection( S32 index );
  101. inline void setMultipleSelection( bool allowMultipleSelect = true ) { mMultipleSelections = allowMultipleSelect; };
  102. bool hitTest( const Point2I& point, S32& outItem );
  103. // Sizing
  104. void updateSize();
  105. virtual void parentResized(const RectI& oldParentRect, const RectI& newParentRect);
  106. virtual bool onWake();
  107. // Rendering
  108. virtual void onRender( Point2I offset, const RectI &updateRect );
  109. virtual void onRenderItem(const RectI& itemRect, LBItem *item);
  110. void drawBox( const Point2I &box, S32 size, ColorI &outlineColor, ColorI &boxColor );
  111. bool renderTooltip( const Point2I &hoverPos, const Point2I& cursorPos, const char* tipText );
  112. void addFilteredItem( String item );
  113. void removeFilteredItem( String item );
  114. // Mouse/Key Events
  115. virtual void onMouseDown( const GuiEvent &event );
  116. virtual void onMouseDragged(const GuiEvent &event);
  117. virtual void onMouseUp( const GuiEvent& event );
  118. virtual bool onKeyDown( const GuiEvent &event );
  119. // String Utility
  120. static U32 getStringElementCount( const char *string );
  121. static const char* getStringElement( const char* inString, const U32 index );
  122. // SimSet Mirroring Stuff
  123. void setMirrorObject( SimSet *inObj );
  124. void _mirror();
  125. StringTableEntry _makeMirrorItemName( SimObject *inObj );
  126. String mMirrorSetName;
  127. String mMakeNameCallback;
  128. };
  129. #endif