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 ) { return mTargets[ index ]; }
 87   
 88   /// Return the number of objects being inspected by this GuiInspector.
 89   U32 getNumInspectObjects() const { return mTargets.size(); }
 90   
 91   /// Call inspectPreApply on all inspected objects.
 92   void sendInspectPreApply();
 93   
 94   /// Call inspectPostApply on all inspected objects.
 95   void sendInspectPostApply();
 96
 97   /// Set the currently inspected object name
 98   /// @note Only valid in single-object mode.
 99   void setName( StringTableEntry newName );
100
101   /// Deletes all GuiInspectorGroups
102   void clearGroups();   
103
104   /// Returns true if the named group exists
105   /// Helper for inspectObject
106   GuiInspectorGroup* findExistentGroup( StringTableEntry groupName );
107
108   /// Should there be a GuiInspectorField associated with this fieldName,
109   /// update it to reflect actual/current value of that field in the inspected object.
110   /// Added to support UndoActions
111   void updateFieldValue( StringTableEntry fieldName, const char* arrayIdx );
112
113   /// Divider position is interpreted as an offset 
114   /// from the right edge of the field control.
115   /// Divider margin is an offset on both left and right
116   /// sides of the divider in which it can be selected
117   /// with the mouse.
118   void getDivider( S32 &pos, S32 &margin );   
119
120   void updateDivider();
121
122   bool collideDivider( const Point2I &localPnt );
123
124   void setHighlightField( GuiInspectorField *field );
125
126   // If returns true that group will not be inspected.
127   bool isGroupFiltered( const char *groupName ) const;
128
129   // Returns true only if the group name follows a minus symbol in the filters.
130   bool isGroupExplicitlyFiltered( const char *groupName ) const;
131
132   void setObjectField( const char *fieldName, const char *data );
133
134   static GuiInspector* findByObject( SimObject *obj );   
135
136protected:
137      
138   typedef Vector< SimObjectPtr< SimObject> > TargetVector;
139
140   Vector<GuiInspectorGroup*> mGroups;
141
142   /// Objects being inspected by this GuiInspector.
143   TargetVector mTargets;
144   
145   F32 mDividerPos;   
146   S32 mDividerMargin;
147   bool mOverDivider;
148   bool mMovingDivider;
149   SimObjectPtr<GuiInspectorField> mHLField;
150   String mGroupFilters;   
151   bool mShowCustomFields;
152   
153   void refresh();
154};
155
156#endif
157