field.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. //An override that lets us bypass inspector-dependent logic for setting/getting variables/fields
  69. bool mSpecialEditField;
  70. //An override to make sure this field is associated to an object that isn't expressly
  71. //the one the inspector is inspecting. Such as an entity's component.
  72. SimObject* mTargetObject;
  73. //Special edit field, variable name - the variable or field name targeted
  74. StringTableEntry mVariableName;
  75. //Special edit field, callback name - if defined, we'll do a callback to the function listed here when editing the field
  76. StringTableEntry mCallbackName;
  77. virtual void _registerEditControl( GuiControl *ctrl );
  78. virtual void _executeSelectedCallback();
  79. void _setFieldDocs( StringTableEntry docs );
  80. public:
  81. explicit GuiInspectorField();
  82. ///
  83. GuiInspectorField( GuiInspector *inspector, GuiInspectorGroup* parent, AbstractClassRep::Field* field );
  84. virtual ~GuiInspectorField();
  85. ///
  86. virtual void init( GuiInspector *inspector, GuiInspectorGroup *group );
  87. ///
  88. virtual void setInspectorField( AbstractClassRep::Field *field,
  89. StringTableEntry caption = NULL,
  90. const char *arrayIndex = NULL );
  91. ///
  92. virtual GuiControl* constructEditControl();
  93. /// Chooses and sets the GuiControlProfile.
  94. virtual void setInspectorProfile();
  95. /// Sets this control's caption text, usually set within setInspectorField,
  96. /// this is exposed in case someone wants to override the normal caption.
  97. virtual void setCaption( StringTableEntry caption ) { mCaption = caption; }
  98. void setEditControl(GuiControl* editCtrl);
  99. virtual void setDocs(String docs) { mFieldDocs = docs; }
  100. /// Returns pointer to this InspectorField's edit ctrl.
  101. virtual GuiControl* getEditCtrl() { return mEdit; }
  102. /// Sets the value of this GuiInspectorField (not the actual field)
  103. /// This means the EditCtrl unless overridden.
  104. virtual void setValue( const char* newValue );
  105. /// Get the currently value of this control (not the actual field)
  106. virtual const char* getValue() { return NULL; }
  107. /// Update this controls value to reflect that of the inspected field.
  108. virtual void updateValue();
  109. /// Return the name of the field being edited.
  110. virtual StringTableEntry getFieldName();
  111. /// Return the name of the console type that this field uses.
  112. virtual StringTableEntry getFieldType();
  113. /// Return the name without the array index that may potentially be present.
  114. virtual StringTableEntry getRawFieldName();
  115. ///
  116. StringTableEntry getArrayIndex() const { return mFieldArrayIndex; }
  117. /// Called from within setData to allow child classes
  118. /// to perform their own verification.
  119. virtual bool verifyData( StringTableEntry data ) { return true; }
  120. /// Set value of the field we are inspecting
  121. virtual void setData( const char* data, bool callbacks = true );
  122. /// Reset the field value to its default value based on default-constructed objects.
  123. ///
  124. /// @note If multiple objects are inspected, this will take the default value from
  125. /// the first object and set all fields to this value.
  126. virtual void resetData();
  127. /// Get value of the field we are inspecting.
  128. ///
  129. /// @note The string returned by this method may be a transient string allocated
  130. /// internally by the console. For any non-transient needs, this string has
  131. /// to be copied to locally owned memory.
  132. /// @note This method always returns the value of the field in the first
  133. /// inspected object.
  134. virtual const char* getData( U32 inspectObjectIndex = 0 );
  135. /// Update the inspected field to match the value of this control.
  136. virtual void updateData() {};
  137. ///
  138. virtual bool updateRects();
  139. ///
  140. virtual void setHLEnabled( bool enabled );
  141. /// Return true if all inspected objects have the same value for this
  142. /// field.
  143. bool hasSameValueInAllObjects();
  144. /// Return the inspector object that this field belongs to.
  145. GuiInspector* getInspector() const { return mInspector; }
  146. // GuiControl.
  147. virtual bool onAdd();
  148. virtual bool resize(const Point2I &newPosition, const Point2I &newExtent);
  149. virtual void onRender(Point2I offset, const RectI &updateRect);
  150. virtual void setFirstResponder( GuiControl *firstResponder );
  151. virtual void onMouseDown( const GuiEvent &event );
  152. virtual void onRightMouseUp( const GuiEvent &event );
  153. void setTargetObject(SimObject* obj) { mTargetObject = obj; }
  154. SimObject* getTargetObject() { return mTargetObject; }
  155. void setSpecialEditField(bool isSpecialEditField) { mSpecialEditField = isSpecialEditField; }
  156. void setSpecialEditVariableName(String varName) { mVariableName = StringTable->insert(varName); }
  157. void setSpecialEditCallbackName(String callName) { mCallbackName = StringTable->insert(callName); }
  158. DECLARE_CONOBJECT( GuiInspectorField );
  159. DECLARE_CATEGORY( "Gui Editor" );
  160. };
  161. #endif // _GUI_INSPECTOR_FIELD_H_