guiInspector.h

Engine/source/gui/editor/guiInspector.h

More...

Classes:

class

A control that allows to edit the properties of one or more SimObjects.

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
 24#ifndef _GUI_INSPECTOR_H_
 25#define _GUI_INSPECTOR_H_
 26
 27#ifndef _GUISTACKCTRL_H_
 28   #include "gui/containers/guiStackCtrl.h"
 29#endif
 30
 31
 32class GuiInspectorGroup;
 33class GuiInspectorField;
 34class GuiInspectorDatablockField;
 35
 36
 37/// A control that allows to edit the properties of one or more SimObjects.
 38class GuiInspector : public GuiStackControl
 39{
 40   typedef GuiStackControl Parent;
 41
 42public:
 43
 44   GuiInspector();
 45   virtual ~GuiInspector();
 46
 47   DECLARE_CONOBJECT(GuiInspector);
 48   DECLARE_CATEGORY( "Gui Editor" );
 49   DECLARE_DESCRIPTION( "A control that allows to edit the properties of one or more SimObjects." );
 50
 51   // Console Object
 52   static void initPersistFields();
 53
 54   // SimObject
 55   virtual void onRemove();
 56   virtual void onDeleteNotify( SimObject *object );
 57
 58   // GuiControl
 59   virtual void parentResized( const RectI &oldParentRect, const RectI &newParentRect );
 60   virtual bool resize( const Point2I &newPosition, const Point2I &newExtent );
 61   virtual GuiControl* findHitControl( const Point2I &pt, S32 initialLayer );   
 62   virtual void getCursor( GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent );
 63   virtual void onMouseMove( const GuiEvent &event );
 64   virtual void onMouseDown( const GuiEvent &event );
 65   virtual void onMouseUp( const GuiEvent &event );
 66   virtual void onMouseDragged( const GuiEvent &event );
 67
 68   // GuiInspector
 69   
 70   /// Return true if "object" is in the inspection set of this inspector.
 71   bool isInspectingObject( SimObject* object );
 72
 73   /// Set the currently inspected object.
 74   virtual void inspectObject( SimObject *object );
 75   
 76   /// Add another object to the set of currently inspected objects.
 77   virtual void addInspectObject( SimObject* object, bool autoSync = true );
 78   
 79   /// Remove the given object from the set of inspected objects.
 80   virtual void removeInspectObject( SimObject* object );
 81   
 82   /// Remove all objects from the inspection set.
 83   virtual void clearInspectObjects();
 84
 85   /// Get the currently inspected object
 86   SimObject* getInspectObject(U32 index = 0)
 87   {
 88      if (!mTargets.empty())
 89         return mTargets[index];
 90      else
 91         return nullptr;
 92   }
 93
 94   S32 getComponentGroupTargetId() { return mComponentGroupTargetId; }
 95   void setComponentGroupTargetId(S32 compId) { mComponentGroupTargetId = compId; }
 96   
 97   /// Return the number of objects being inspected by this GuiInspector.
 98   U32 getNumInspectObjects() const { return mTargets.size(); }
 99   
100   /// Call inspectPreApply on all inspected objects.
101   void sendInspectPreApply();
102   
103   /// Call inspectPostApply on all inspected objects.
104   void sendInspectPostApply();
105
106   /// Set the currently inspected object name
107   /// @note Only valid in single-object mode.
108   void setName( StringTableEntry newName );
109
110   void addInspectorGroup(GuiInspectorGroup* group)
111   {
112      mGroups.push_back(group);
113   }
114
115   /// <summary>
116   /// Inserts a group into group list at a specific position
117   /// </summary>
118   /// <param name="insertIndex"></param>
119   /// <param name="group"></param>
120   void insertInspectorGroup(U32 insertIndex, GuiInspectorGroup* group)
121   {
122      mGroups.insert(insertIndex, group);
123   }
124
125   /// Deletes all GuiInspectorGroups
126   void clearGroups();   
127
128   /// Returns true if the named group exists
129   /// Helper for inspectObject
130   GuiInspectorGroup* findExistentGroup( StringTableEntry groupName );
131
132   /// <summary>
133   /// Looks through the group list by name to find it's index
134   /// </summary>
135   /// <param name="groupName"></param>
136   /// <returns>Returns the index position of the group in the group list as S32. -1 if groupName not found.</returns>
137   S32 findExistentGroupIndex(StringTableEntry groupName);
138
139   /// Should there be a GuiInspectorField associated with this fieldName,
140   /// update it to reflect actual/current value of that field in the inspected object.
141   /// Added to support UndoActions
142   void updateFieldValue( StringTableEntry fieldName, const char* arrayIdx );
143
144   /// Divider position is interpreted as an offset 
145   /// from the right edge of the field control.
146   /// Divider margin is an offset on both left and right
147   /// sides of the divider in which it can be selected
148   /// with the mouse.
149   void getDivider( S32 &pos, S32 &margin );   
150
151   void updateDivider();
152
153   bool collideDivider( const Point2I &localPnt );
154
155   void setHighlightField( GuiInspectorField *field );
156
157   // If returns true that group will not be inspected.
158   bool isGroupFiltered( const char *groupName ) const;
159
160   // Returns true only if the group name follows a minus symbol in the filters.
161   bool isGroupExplicitlyFiltered( const char *groupName ) const;
162
163   void setObjectField( const char *fieldName, const char *data );
164
165   static GuiInspector* findByObject( SimObject *obj );   
166
167protected:
168      
169   typedef Vector< SimObjectPtr< SimObject> > TargetVector;
170
171   Vector<GuiInspectorGroup*> mGroups;
172
173   /// Objects being inspected by this GuiInspector.
174   TargetVector mTargets;
175
176   S32 mComponentGroupTargetId;
177   
178   F32 mDividerPos;   
179   S32 mDividerMargin;
180   bool mOverDivider;
181   bool mMovingDivider;
182   SimObjectPtr<GuiInspectorField> mHLField;
183   String mGroupFilters;   
184   bool mShowCustomFields;
185   
186   void refresh();
187};
188
189#endif
190