My Project
SelectionManager.h
1 #pragma once
2 #include <vector>
3 #include <list>
4 #include "IRefObject.h"
5 
6 namespace ParaEngine
7 {
8  using namespace std;
9  class CBaseObject;
10  class CGUIBase;
11 
15  struct SelectedItem
16  {
17  IAttributeFields::WeakPtr_type m_pObjectRef;
18  enum ObjectBaseType{
19  TYPE_CBASEOBJECT,
20  TYPE_CGUIBASE,
21  TYPE_UNKNOWN,
22  }m_nItemType;
23 
24  bool m_bSelected;
25 
26  public:
27  SelectedItem() :m_bSelected(false), m_nItemType(TYPE_UNKNOWN){};
28  SelectedItem(CBaseObject* pObj) :m_pObjectRef((IAttributeFields*)pObj), m_bSelected(false), m_nItemType(TYPE_CBASEOBJECT){};
29  SelectedItem(CGUIBase* pObj) :m_pObjectRef((IAttributeFields*)pObj), m_bSelected(false), m_nItemType(TYPE_CGUIBASE){};
30 
31  inline IAttributeFields* GetObject(){
32  return m_pObjectRef.get();
33  };
34 
35  CBaseObject* GetAs3DObject(){
36  return Is3DObject() ? (CBaseObject*)m_pObjectRef.get() : NULL;
37  };
38 
39  CGUIBase* GetAs2DObject(){
40  return (Is2DObject()) ? (CGUIBase*)m_pObjectRef.get() : NULL;
41  };
42 
44  operator bool() const
45  {
46  return m_pObjectRef;
47  }
48 
49  inline bool Is3DObject(){ return m_nItemType == TYPE_CBASEOBJECT && m_pObjectRef; };
50  inline bool Is2DObject(){ return m_nItemType == TYPE_CGUIBASE && m_pObjectRef; };
51  };
52 
58  {
59  public:
60  CSelectionGroup() : m_bSelected(false), m_nMaxItemNumber(1), m_bRemoveFromBack(false), m_bExclusiveSelect(true) {};
61  virtual ~CSelectionGroup(){};
62 
63  ATTRIBUTE_DEFINE_CLASS(CSelectionGroup);
64 
66  virtual int GetChildAttributeObjectCount(int nColumnIndex = 0);
67  virtual IAttributeFields* GetChildAttributeObject(int nRowIndex, int nColumnIndex = 0);
68 
69  public:
71  int GetItemCount() { return (int)(m_items.size()); }
72 
74  SelectedItem& GetItem(int nIndex) { return m_items[nIndex]; }
75 
77  bool IsExclusive(){ return m_bExclusiveSelect; }
78  public:
80  vector<SelectedItem> m_items;
81 
84 
87 
91 
94  };
95 
103  {
104  public:
105  CSelectionManager(void);
106  virtual ~CSelectionManager(void);
107  ATTRIBUTE_DEFINE_CLASS(CSelectionManager);
108 
110  virtual int GetChildAttributeObjectCount(int nColumnIndex = 0);
111  virtual IAttributeFields* GetChildAttributeObject(int nRowIndex, int nColumnIndex = 0);
112 
117  static CSelectionManager* GetSingleton();
118  public:
125  virtual void OnRefDeleted(IRefObject* rm);
126 
131  void RemoveObject(CBaseObject* pObject);
132  void RemoveObject(CGUIBase* pObject);
133 
136  int GetObjectCount(CBaseObject* pObject);
137 
144  void AddObject(CBaseObject* pObject, int nGroupID = 0);
145  void AddObject(CGUIBase* pObject, int nGroupID = 0);
146 
154  bool GetObject(int nGroupID, int nItemIndex, SelectedItem* pOut);
155 
162  int GetItemNumInGroup(int nGroupID);
163 
169  void SelectGroup(int nGroupID, bool bSelect);
174  void ClearGroup(int nGroupID);
175 
182  void SetMaxItemNumberInGroup(int nGroupID, int nMaxItemsNumber);
183 
189  int GetMaxItemNumberInGroup(int nGroupID);
190 
196  CSelectionGroup* GetGroup(int nGroupID);
197 
203  CSelectionGroup* CreateGroup(int nGroupID);
204 
206  int GetGroupCount(){ return (int)(m_groups.size()); }
207 
208  protected:
209 
214  void UpdateGroup(int nGroupID);
215 
216  public:
217  vector< ref_ptr<CSelectionGroup> > m_groups;
218  };
219 
220 }
int GetGroupCount()
get the group count.
Definition: SelectionManager.h:206
Definition: combase.h:159
vector< SelectedItem > m_items
all items in the selection group.
Definition: SelectionManager.h:80
different physics engine has different winding order.
Definition: EventBinding.h:32
SelectedItem & GetItem(int nIndex)
get item at give index.
Definition: SelectionManager.h:74
int m_nMaxItemNumber
maximum number of objects in the group.
Definition: SelectionManager.h:86
base object for all 2D GUI objects (1) 2D GUI object are not tested against view frustum, instead it is controlled by visibility tag automatically or through user input.
Definition: GUIBase.h:54
bool IsExclusive()
default to true.
Definition: SelectionManager.h:77
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
bool m_bExclusiveSelect
default to true.
Definition: SelectionManager.h:93
int GetItemCount()
get item count.
Definition: SelectionManager.h:71
bool m_bRemoveFromBack
if true, objects exceeding the max item number will be removed from the back of the item list...
Definition: SelectionManager.h:90
Defines the base class of all scene elements:CBaseObject for Parallel World Engine.
Definition: BaseObject.h:230
bool m_bSelected
whether the entire group is selected.default value is false
Definition: SelectionManager.h:83
A pool of currently selected objects.
Definition: SelectionManager.h:102
a group of selected object
Definition: SelectionManager.h:57
anything that makes references to other objects.
Definition: IRefObject.h:65
currently selected item.
Definition: SelectionManager.h:15