field.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUI_INSPECTOR_FIELD_H_
  23. #define _GUI_INSPECTOR_FIELD_H_
  24. #include "gui/core/guiCanvas.h"
  25. #include "gui/shiny/guiTickCtrl.h"
  26. #include "gui/controls/guiTextEditCtrl.h"
  27. #include "gui/buttons/guiBitmapButtonCtrl.h"
  28. #include "gui/controls/guiPopUpCtrl.h"
  29. #include "gui/containers/guiRolloutCtrl.h"
  30. class GuiInspectorGroup;
  31. class GuiInspector;
  32. /// The GuiInspectorField control is a representation of a single abstract
  33. /// field for a given ConsoleObject derived object. It handles creation
  34. /// getting and setting of it's fields data and editing control.
  35. ///
  36. /// Creation of custom edit controls is done through this class and is
  37. /// dependent upon the dynamic console type, which may be defined to be
  38. /// custom for different types.
  39. ///
  40. /// @note GuiInspectorField controls must have a GuiInspectorGroup as their
  41. /// parent.
  42. class GuiInspectorField : public GuiControl
  43. {
  44. public:
  45. typedef GuiControl Parent;
  46. friend class GuiInspectorGroup;
  47. protected:
  48. /// The text to display as the field name.
  49. StringTableEntry mCaption;
  50. /// The group to which this field belongs.
  51. GuiInspectorGroup* mParent;
  52. /// The GuiInspector that the group is in to which this field belongs.
  53. GuiInspector* mInspector;
  54. ///
  55. AbstractClassRep::Field* mField;
  56. ///
  57. StringTableEntry mFieldArrayIndex;
  58. ///
  59. String mFieldDocs;
  60. ///
  61. GuiControl* mEdit;
  62. ///
  63. RectI mCaptionRect;
  64. ///
  65. RectI mEditCtrlRect;
  66. ///
  67. bool mHighlighted;
  68. //These are so we can special-case our height for additional room on certain field-types
  69. bool mUseHeightOverride;
  70. U32 mHeightOverride;
  71. //An override that lets us bypass inspector-dependent logic for setting/getting variables/fields
  72. bool mSpecialEditField;
  73. //An override to make sure this field is associated to an object that isn't expressly
  74. //the one the inspector is inspecting. Such as an entity's component.
  75. SimObject* mTargetObject;
  76. //Special edit field, variable name - the variable or field name targeted
  77. StringTableEntry mVariableName;
  78. //Special edit field, callback name - if defined, we'll do a callback to the function listed here when editing the field
  79. StringTableEntry mCallbackName;
  80. virtual void _registerEditControl( GuiControl *ctrl );
  81. virtual void _executeSelectedCallback();
  82. void _setFieldDocs( StringTableEntry docs );
  83. public:
  84. explicit GuiInspectorField();
  85. ///
  86. GuiInspectorField( GuiInspector *inspector, GuiInspectorGroup* parent, AbstractClassRep::Field* field );
  87. virtual ~GuiInspectorField();
  88. ///
  89. virtual void init( GuiInspector *inspector, GuiInspectorGroup *group );
  90. ///
  91. virtual void setInspectorField( AbstractClassRep::Field *field,
  92. StringTableEntry caption = NULL,
  93. const char *arrayIndex = NULL );
  94. ///
  95. virtual GuiControl* constructEditControl();
  96. /// Chooses and sets the GuiControlProfile.
  97. virtual void setInspectorProfile();
  98. /// Sets this control's caption text, usually set within setInspectorField,
  99. /// this is exposed in case someone wants to override the normal caption.
  100. virtual void setCaption( StringTableEntry caption ) { mCaption = caption; }
  101. void setEditControl(GuiControl* editCtrl);
  102. void setHeightOverride(bool useOverride, U32 heightOverride);
  103. virtual void setDocs(String docs) { mFieldDocs = docs; }
  104. /// Returns pointer to this InspectorField's edit ctrl.
  105. virtual GuiControl* getEditCtrl() { return mEdit; }
  106. /// Sets the value of this GuiInspectorField (not the actual field)
  107. /// This means the EditCtrl unless overridden.
  108. virtual void setValue( const char* newValue );
  109. /// Get the currently value of this control (not the actual field)
  110. virtual const char* getValue() { return NULL; }
  111. /// Update this controls value to reflect that of the inspected field.
  112. virtual void updateValue();
  113. /// Return the name of the field being edited.
  114. virtual StringTableEntry getFieldName();
  115. /// Return the name of the console type that this field uses.
  116. virtual StringTableEntry getFieldType();
  117. /// Return the name without the array index that may potentially be present.
  118. virtual StringTableEntry getRawFieldName();
  119. ///
  120. StringTableEntry getArrayIndex() const { return mFieldArrayIndex; }
  121. /// Called from within setData to allow child classes
  122. /// to perform their own verification.
  123. virtual bool verifyData( StringTableEntry data ) { return true; }
  124. /// Set value of the field we are inspecting
  125. virtual void setData( const char* data, bool callbacks = true );
  126. /// Reset the field value to its default value based on default-constructed objects.
  127. ///
  128. /// @note If multiple objects are inspected, this will take the default value from
  129. /// the first object and set all fields to this value.
  130. virtual void resetData();
  131. /// Get value of the field we are inspecting.
  132. ///
  133. /// @note The string returned by this method may be a transient string allocated
  134. /// internally by the console. For any non-transient needs, this string has
  135. /// to be copied to locally owned memory.
  136. /// @note This method always returns the value of the field in the first
  137. /// inspected object.
  138. virtual const char* getData( U32 inspectObjectIndex = 0 );
  139. /// Update the inspected field to match the value of this control.
  140. virtual void updateData() {};
  141. ///
  142. virtual bool updateRects();
  143. ///
  144. virtual void setHLEnabled( bool enabled );
  145. /// Return true if all inspected objects have the same value for this
  146. /// field.
  147. bool hasSameValueInAllObjects();
  148. /// Return the inspector object that this field belongs to.
  149. GuiInspector* getInspector() const { return mInspector; }
  150. // GuiControl.
  151. virtual bool onAdd();
  152. virtual bool resize(const Point2I &newPosition, const Point2I &newExtent);
  153. virtual void onRender(Point2I offset, const RectI &updateRect);
  154. virtual void setFirstResponder( GuiControl *firstResponder );
  155. virtual void onMouseDown( const GuiEvent &event );
  156. virtual void onRightMouseUp( const GuiEvent &event );
  157. void setTargetObject(SimObject* obj) { mTargetObject = obj; }
  158. SimObject* getTargetObject() { return mTargetObject; }
  159. void setSpecialEditField(bool isSpecialEditField) { mSpecialEditField = isSpecialEditField; }
  160. void setSpecialEditVariableName(String varName) { mVariableName = StringTable->insert(varName); }
  161. void setSpecialEditCallbackName(String callName) { mCallbackName = StringTable->insert(callName); }
  162. DECLARE_CONOBJECT( GuiInspectorField );
  163. DECLARE_CATEGORY( "Gui Editor" );
  164. };
  165. #endif // _GUI_INSPECTOR_FIELD_H_