field.h

Engine/source/gui/editor/inspector/field.h

More...

Classes:

class

The GuiInspectorField control is a representation of a single abstract field for a given ConsoleObject derived object.

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_FIELD_H_
 25#define _GUI_INSPECTOR_FIELD_H_
 26
 27#include "gui/core/guiCanvas.h"
 28#include "gui/shiny/guiTickCtrl.h"
 29#include "gui/controls/guiTextEditCtrl.h"
 30#include "gui/buttons/guiBitmapButtonCtrl.h"
 31#include "gui/controls/guiPopUpCtrl.h"
 32
 33#include "gui/containers/guiRolloutCtrl.h"
 34
 35class GuiInspectorGroup;
 36class GuiInspector;
 37
 38
 39/// The GuiInspectorField control is a representation of a single abstract
 40/// field for a given ConsoleObject derived object.  It handles creation
 41/// getting and setting of it's fields data and editing control.  
 42///
 43/// Creation of custom edit controls is done through this class and is
 44/// dependent upon the dynamic console type, which may be defined to be
 45/// custom for different types.
 46///
 47/// @note GuiInspectorField controls must have a GuiInspectorGroup as their
 48///        parent.  
 49class GuiInspectorField : public GuiControl
 50{
 51   public:
 52
 53      typedef GuiControl Parent;
 54      friend class GuiInspectorGroup;
 55
 56   protected:
 57
 58      /// The text to display as the field name.
 59      StringTableEntry mCaption;
 60      
 61      /// The group to which this field belongs.
 62      GuiInspectorGroup* mParent;
 63      
 64      /// The GuiInspector that the group is in to which this field belongs.
 65      GuiInspector* mInspector;
 66      
 67      ///
 68      AbstractClassRep::Field* mField;
 69      
 70      ///
 71      StringTableEntry mFieldArrayIndex;
 72      
 73      ///
 74      String mFieldDocs;
 75      
 76      ///
 77      GuiControl* mEdit;
 78      
 79      ///
 80      RectI mCaptionRect;
 81      
 82      ///
 83      RectI mEditCtrlRect;
 84      
 85      ///
 86      bool mHighlighted;
 87
 88      //These are so we can special-case our height for additional room on certain field-types
 89      bool mUseHeightOverride;
 90      U32 mHeightOverride;
 91
 92      //An override that lets us bypass inspector-dependent logic for setting/getting variables/fields
 93      bool mSpecialEditField;
 94      //An override to make sure this field is associated to an object that isn't expressly
 95      //the one the inspector is inspecting. Such as an entity's component.
 96      SimObject* mTargetObject;
 97      //Special edit field, variable name - the variable or field name targeted
 98      StringTableEntry mVariableName;
 99      //Special edit field, callback name - if defined, we'll do a callback to the function listed here when editing the field
100      StringTableEntry mCallbackName;
101
102      virtual void _registerEditControl( GuiControl *ctrl );
103      virtual void _executeSelectedCallback();
104      
105      void _setFieldDocs( StringTableEntry docs );
106      
107   public:
108
109      explicit GuiInspectorField();
110
111      ///
112      GuiInspectorField( GuiInspector *inspector, GuiInspectorGroup* parent, AbstractClassRep::Field* field );
113      
114      virtual ~GuiInspectorField();
115
116      ///
117      virtual void init( GuiInspector *inspector, GuiInspectorGroup *group );      
118      
119      ///
120      virtual void setInspectorField( AbstractClassRep::Field *field, 
121                                      StringTableEntry caption = NULL, 
122                                      const char *arrayIndex = NULL );
123      
124      ///
125      virtual GuiControl* constructEditControl();
126
127      /// Chooses and sets the GuiControlProfile.
128      virtual void setInspectorProfile();
129
130      /// Sets this control's caption text, usually set within setInspectorField,
131      /// this is exposed in case someone wants to override the normal caption.
132      virtual void setCaption( StringTableEntry caption ) { mCaption = caption; }
133
134      void setEditControl(GuiControl* editCtrl);
135
136      void setHeightOverride(bool useOverride, U32 heightOverride);
137
138      virtual void setDocs(String docs) { mFieldDocs = docs; }
139
140      /// Returns pointer to this InspectorField's edit ctrl.
141      virtual GuiControl* getEditCtrl() { return mEdit; }
142
143      /// Sets the value of this GuiInspectorField (not the actual field)
144      /// This means the EditCtrl unless overridden.
145      virtual void setValue( const char* newValue );
146
147      /// Get the currently value of this control (not the actual field)
148      virtual const char* getValue() { return NULL; }
149
150      /// Update this controls value to reflect that of the inspected field.
151      virtual void updateValue();
152      
153      /// Return the name of the field being edited.
154      virtual StringTableEntry getFieldName();
155      
156      /// Return the name of the console type that this field uses.
157      virtual StringTableEntry getFieldType();
158      
159      /// Return the name without the array index that may potentially be present.
160      virtual StringTableEntry getRawFieldName();
161      
162      ///
163      StringTableEntry getArrayIndex() const { return mFieldArrayIndex; }
164
165      /// Called from within setData to allow child classes
166      /// to perform their own verification.
167      virtual bool verifyData( StringTableEntry data ) { return true; }
168
169      /// Set value of the field we are inspecting
170      virtual void setData( const char* data, bool callbacks = true );
171      
172      /// Reset the field value to its default value based on default-constructed objects.
173      ///
174      /// @note If multiple objects are inspected, this will take the default value from
175      ///   the first object and set all fields to this value.
176      virtual void resetData();
177
178      /// Get value of the field we are inspecting.
179      ///
180      /// @note The string returned by this method may be a transient string allocated
181      ///   internally by the console.  For any non-transient needs, this string has
182      ///   to be copied to locally owned memory.
183      /// @note This method always returns the value of the field in the first
184      ///   inspected object.
185      virtual const char* getData( U32 inspectObjectIndex = 0 );
186
187      /// Update the inspected field to match the value of this control.
188      virtual void updateData() {};
189
190      ///
191      virtual bool updateRects();   
192
193      ///
194      virtual void setHLEnabled( bool enabled );
195      
196      /// Return true if all inspected objects have the same value for this
197      /// field.
198      bool hasSameValueInAllObjects();
199      
200      /// Return the inspector object that this field belongs to.
201      GuiInspector* getInspector() const { return mInspector; }
202      
203      // GuiControl.
204      virtual bool onAdd();
205      virtual bool resize(const Point2I &newPosition, const Point2I &newExtent);
206      virtual void onRender(Point2I offset, const RectI &updateRect);
207      virtual void setFirstResponder( GuiControl *firstResponder );
208      virtual void onMouseDown( const GuiEvent &event );
209      virtual void onRightMouseUp( const GuiEvent &event );
210
211      void setTargetObject(SimObject* obj) { mTargetObject = obj; }
212      SimObject* getTargetObject() { return mTargetObject; }
213      void setSpecialEditField(bool isSpecialEditField) { mSpecialEditField = isSpecialEditField; }
214      void setSpecialEditVariableName(String varName) { mVariableName = StringTable->insert(varName); }
215      void setSpecialEditCallbackName(String callName) { mCallbackName = StringTable->insert(callName); }
216
217      DECLARE_CONOBJECT( GuiInspectorField );
218      DECLARE_CATEGORY( "Gui Editor" );
219};
220
221#endif // _GUI_INSPECTOR_FIELD_H_
222