field.h
Engine/source/gui/editor/inspector/field.h
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 virtual void _registerEditControl( GuiControl *ctrl ); 89 virtual void _executeSelectedCallback(); 90 91 void _setFieldDocs( StringTableEntry docs ); 92 93 public: 94 95 explicit GuiInspectorField(); 96 97 /// 98 GuiInspectorField( GuiInspector *inspector, GuiInspectorGroup* parent, AbstractClassRep::Field* field ); 99 100 virtual ~GuiInspectorField(); 101 102 /// 103 virtual void init( GuiInspector *inspector, GuiInspectorGroup *group ); 104 105 /// 106 virtual void setInspectorField( AbstractClassRep::Field *field, 107 StringTableEntry caption = NULL, 108 const char *arrayIndex = NULL ); 109 110 /// 111 virtual GuiControl* constructEditControl(); 112 113 /// Chooses and sets the GuiControlProfile. 114 virtual void setInspectorProfile(); 115 116 /// Sets this control's caption text, usually set within setInspectorField, 117 /// this is exposed in case someone wants to override the normal caption. 118 virtual void setCaption( StringTableEntry caption ) { mCaption = caption; } 119 120 /// Returns pointer to this InspectorField's edit ctrl. 121 virtual GuiControl* getEditCtrl() { return mEdit; } 122 123 /// Sets the value of this GuiInspectorField (not the actual field) 124 /// This means the EditCtrl unless overridden. 125 virtual void setValue( const char* newValue ); 126 127 /// Get the currently value of this control (not the actual field) 128 virtual const char* getValue() { return NULL; } 129 130 /// Update this controls value to reflect that of the inspected field. 131 virtual void updateValue(); 132 133 /// Return the name of the field being edited. 134 virtual StringTableEntry getFieldName(); 135 136 /// Return the name of the console type that this field uses. 137 virtual StringTableEntry getFieldType(); 138 139 /// Return the name without the array index that may potentially be present. 140 virtual StringTableEntry getRawFieldName(); 141 142 /// 143 StringTableEntry getArrayIndex() const { return mFieldArrayIndex; } 144 145 /// Called from within setData to allow child classes 146 /// to perform their own verification. 147 virtual bool verifyData( StringTableEntry data ) { return true; } 148 149 /// Set value of the field we are inspecting 150 virtual void setData( const char* data, bool callbacks = true ); 151 152 /// Reset the field value to its default value based on default-constructed objects. 153 /// 154 /// @note If multiple objects are inspected, this will take the default value from 155 /// the first object and set all fields to this value. 156 virtual void resetData(); 157 158 /// Get value of the field we are inspecting. 159 /// 160 /// @note The string returned by this method may be a transient string allocated 161 /// internally by the console. For any non-transient needs, this string has 162 /// to be copied to locally owned memory. 163 /// @note This method always returns the value of the field in the first 164 /// inspected object. 165 virtual const char* getData( U32 inspectObjectIndex = 0 ); 166 167 /// Update the inspected field to match the value of this control. 168 virtual void updateData() {}; 169 170 /// 171 virtual bool updateRects(); 172 173 /// 174 virtual void setHLEnabled( bool enabled ); 175 176 /// Return true if all inspected objects have the same value for this 177 /// field. 178 bool hasSameValueInAllObjects(); 179 180 /// Return the inspector object that this field belongs to. 181 GuiInspector* getInspector() const { return mInspector; } 182 183 // GuiControl. 184 virtual bool onAdd(); 185 virtual bool resize(const Point2I &newPosition, const Point2I &newExtent); 186 virtual void onRender(Point2I offset, const RectI &updateRect); 187 virtual void setFirstResponder( GuiControl *firstResponder ); 188 virtual void onMouseDown( const GuiEvent &event ); 189 virtual void onRightMouseUp( const GuiEvent &event ); 190 191 DECLARE_CONOBJECT( GuiInspectorField ); 192 DECLARE_CATEGORY( "Gui Editor" ); 193}; 194 195#endif // _GUI_INSPECTOR_FIELD_H_ 196
