field.h 6.9 KB

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