Torque3D Documentation / _generateds / guiListBoxCtrl.h

guiListBoxCtrl.h

Engine/source/gui/controls/guiListBoxCtrl.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23#ifndef _GUI_LISTBOXCTRL_H_
 24#define _GUI_LISTBOXCTRL_H_
 25
 26#ifndef _CONSOLETYPES_H_
 27#include "console/consoleTypes.h"
 28#endif
 29
 30#ifndef _GUICONTROL_H_
 31#include "gui/core/guiControl.h"
 32#endif
 33
 34#ifndef _DGL_H_
 35#include "gfx/gfxDevice.h"
 36#endif
 37
 38#ifndef _H_GUIDEFAULTCONTROLRENDER_
 39#include "gui/core/guiDefaultControlRender.h"
 40#endif
 41
 42#ifndef _GUISCROLLCTRL_H_
 43#include "gui/containers/guiScrollCtrl.h"
 44#endif
 45
 46
 47class GuiListBoxCtrl : public GuiControl
 48{
 49private:
 50   typedef GuiControl Parent;
 51public:
 52
 53   GuiListBoxCtrl();
 54   ~GuiListBoxCtrl();
 55   DECLARE_CONOBJECT(GuiListBoxCtrl);
 56   DECLARE_CATEGORY( "Gui Lists" );
 57   DECLARE_DESCRIPTION( "Linear list of text items." );
 58
 59   DECLARE_CALLBACK( void, onMouseDragged, ());
 60   DECLARE_CALLBACK( void, onClearSelection, ());
 61   DECLARE_CALLBACK( void, onUnSelect, ( S32 index, const char* itemText));
 62   DECLARE_CALLBACK( void, onSelect, ( S32 index , const char* itemText ));
 63   DECLARE_CALLBACK( void, onDoubleClick, ());
 64   DECLARE_CALLBACK( void, onMouseUp, ( S32 itemHit, S32 mouseClickCount ));
 65   DECLARE_CALLBACK( void, onDeleteKey, ());
 66   DECLARE_CALLBACK( bool, isObjectMirrored, ( const char* indexIdString ));
 67
 68   struct LBItem
 69   {
 70      StringTableEntry  itemText;
 71      String            itemTooltip;
 72      bool              isSelected;
 73      void*             itemData;
 74      LinearColorF            color;
 75      bool              hasColor;
 76   };
 77
 78   VectorPtr<LBItem*>   mItems;
 79   VectorPtr<LBItem*>   mSelectedItems;
 80
 81   VectorPtr<LBItem*>   mFilteredItems;
 82
 83   bool                 mMultipleSelections;
 84   Point2I              mItemSize;
 85   bool                 mFitParentWidth;
 86   bool                 mColorBullet;
 87   LBItem*              mLastClickItem;
 88
 89   // Persistence
 90   static void       initPersistFields();   
 91
 92   // Item Accessors
 93   S32               getItemCount();
 94   S32               getSelCount();
 95   S32               getSelectedItem();
 96   void              getSelectedItems( Vector<S32> &Items );
 97   S32               getItemIndex( LBItem *item );
 98   StringTableEntry  getItemText( S32 index );
 99   SimObject*        getItemObject( S32 index );
100   
101   void              setCurSel( S32 index );
102   void              setCurSelRange( S32 start, S32 stop );
103   void              setItemText( S32 index, StringTableEntry text );
104
105   S32               addItem( StringTableEntry text, void *itemData = NULL );
106   S32               addItemWithColor( StringTableEntry text, LinearColorF color = LinearColorF(-1, -1, -1), void *itemData = NULL);
107   S32               insertItem( S32 index, StringTableEntry text, void *itemData = NULL );
108   S32               insertItemWithColor( S32 index, StringTableEntry text, LinearColorF color = LinearColorF(-1, -1, -1), void *itemData = NULL);
109   S32               findItemText( StringTableEntry text, bool caseSensitive = false );
110
111   void              setItemColor(S32 index, const LinearColorF& color);
112   void              clearItemColor(S32 index);
113
114   void              deleteItem( S32 index );
115   void              clearItems();
116   void              clearSelection();
117   void              removeSelection( LBItem *item, S32 index );
118   void              removeSelection( S32 index );
119   void              addSelection( LBItem *item, S32 index );
120   void              addSelection( S32 index );
121   inline void       setMultipleSelection( bool allowMultipleSelect = true ) { mMultipleSelections = allowMultipleSelect; };
122   
123   bool              hitTest( const Point2I& point, S32& outItem );
124
125   // Sizing
126   void              updateSize();
127   virtual void      parentResized(const RectI& oldParentRect, const RectI& newParentRect);
128   virtual bool      onWake();
129
130   // Rendering
131   virtual void      onRender( Point2I offset, const RectI &updateRect );
132   virtual void      onRenderItem(const RectI& itemRect, LBItem *item);
133   void              drawBox( const Point2I &box, S32 size, ColorI &outlineColor, ColorI &boxColor );
134   bool              renderTooltip( const Point2I &hoverPos, const Point2I& cursorPos, const char* tipText );
135   void              addFilteredItem( String item );
136   void              removeFilteredItem( String item );
137   // Mouse/Key Events
138   virtual void      onMouseDown( const GuiEvent &event );
139   virtual void      onMouseDragged(const GuiEvent &event);
140   virtual void      onMouseUp( const GuiEvent& event );
141   virtual bool      onKeyDown( const GuiEvent &event );   
142
143   // String Utility
144   static U32        getStringElementCount( const char *string );
145   static const char* getStringElement( const char* inString, const U32 index );
146   
147   // SimSet Mirroring Stuff
148   void setMirrorObject( SimSet *inObj );
149   void _mirror();
150   StringTableEntry _makeMirrorItemName( SimObject *inObj );
151
152   String mMirrorSetName;
153   String mMakeNameCallback;
154};
155
156#endif
157