guiInspector.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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_H_
  23. #define _GUI_INSPECTOR_H_
  24. #ifndef _GUISTACKCTRL_H_
  25. #include "gui/containers/guiStackCtrl.h"
  26. #endif
  27. class GuiInspectorGroup;
  28. class GuiInspectorField;
  29. class GuiInspectorDatablockField;
  30. /// A control that allows to edit the properties of one or more SimObjects.
  31. class GuiInspector : public GuiStackControl
  32. {
  33. typedef GuiStackControl Parent;
  34. public:
  35. GuiInspector();
  36. virtual ~GuiInspector();
  37. DECLARE_CONOBJECT(GuiInspector);
  38. DECLARE_CATEGORY( "Gui Editor" );
  39. DECLARE_DESCRIPTION( "A control that allows to edit the properties of one or more SimObjects." );
  40. // Console Object
  41. static void initPersistFields();
  42. // SimObject
  43. virtual void onRemove();
  44. virtual void onDeleteNotify( SimObject *object );
  45. // GuiControl
  46. virtual void parentResized( const RectI &oldParentRect, const RectI &newParentRect );
  47. virtual bool resize( const Point2I &newPosition, const Point2I &newExtent );
  48. virtual GuiControl* findHitControl( const Point2I &pt, S32 initialLayer );
  49. virtual void getCursor( GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent );
  50. virtual void onMouseMove( const GuiEvent &event );
  51. virtual void onMouseDown( const GuiEvent &event );
  52. virtual void onMouseUp( const GuiEvent &event );
  53. virtual void onMouseDragged( const GuiEvent &event );
  54. // GuiInspector
  55. /// Return true if "object" is in the inspection set of this inspector.
  56. bool isInspectingObject( SimObject* object );
  57. /// Set the currently inspected object.
  58. virtual void inspectObject( SimObject *object );
  59. /// Add another object to the set of currently inspected objects.
  60. virtual void addInspectObject( SimObject* object, bool autoSync = true );
  61. /// Remove the given object from the set of inspected objects.
  62. virtual void removeInspectObject( SimObject* object );
  63. /// Remove all objects from the inspection set.
  64. virtual void clearInspectObjects();
  65. /// Get the currently inspected object
  66. SimObject* getInspectObject(U32 index = 0)
  67. {
  68. if (!mTargets.empty())
  69. return mTargets[index];
  70. else
  71. return nullptr;
  72. }
  73. S32 getComponentGroupTargetId() { return mComponentGroupTargetId; }
  74. void setComponentGroupTargetId(S32 compId) { mComponentGroupTargetId = compId; }
  75. /// Return the number of objects being inspected by this GuiInspector.
  76. U32 getNumInspectObjects() const { return mTargets.size(); }
  77. /// Call inspectPreApply on all inspected objects.
  78. void sendInspectPreApply();
  79. /// Call inspectPostApply on all inspected objects.
  80. void sendInspectPostApply();
  81. /// Set the currently inspected object name
  82. /// @note Only valid in single-object mode.
  83. void setName( StringTableEntry newName );
  84. void addInspectorGroup(GuiInspectorGroup* group)
  85. {
  86. mGroups.push_back(group);
  87. }
  88. /// <summary>
  89. /// Inserts a group into group list at a specific position
  90. /// </summary>
  91. /// <param name="insertIndex"></param>
  92. /// <param name="group"></param>
  93. void insertInspectorGroup(U32 insertIndex, GuiInspectorGroup* group)
  94. {
  95. mGroups.insert(insertIndex, group);
  96. }
  97. /// Deletes all GuiInspectorGroups
  98. void clearGroups();
  99. /// Returns true if the named group exists
  100. /// Helper for inspectObject
  101. GuiInspectorGroup* findExistentGroup( StringTableEntry groupName );
  102. /// <summary>
  103. /// Looks through the group list by name to find it's index
  104. /// </summary>
  105. /// <param name="groupName"></param>
  106. /// <returns>Returns the index position of the group in the group list as S32. -1 if groupName not found.</returns>
  107. S32 findExistentGroupIndex(StringTableEntry groupName);
  108. /// Should there be a GuiInspectorField associated with this fieldName,
  109. /// update it to reflect actual/current value of that field in the inspected object.
  110. /// Added to support UndoActions
  111. void updateFieldValue( StringTableEntry fieldName, const char* arrayIdx );
  112. /// Divider position is interpreted as an offset
  113. /// from the right edge of the field control.
  114. /// Divider margin is an offset on both left and right
  115. /// sides of the divider in which it can be selected
  116. /// with the mouse.
  117. void getDivider( S32 &pos, S32 &margin );
  118. void updateDivider();
  119. bool collideDivider( const Point2I &localPnt );
  120. void setHighlightField( GuiInspectorField *field );
  121. // If returns true that group will not be inspected.
  122. bool isGroupFiltered( const char *groupName ) const;
  123. // Returns true only if the group name follows a minus symbol in the filters.
  124. bool isGroupExplicitlyFiltered( const char *groupName ) const;
  125. void setObjectField( const char *fieldName, const char *data );
  126. static GuiInspector* findByObject( SimObject *obj );
  127. void refresh();
  128. protected:
  129. typedef Vector< SimObjectPtr< SimObject > > TargetVector;
  130. Vector<GuiInspectorGroup*> mGroups;
  131. /// Objects being inspected by this GuiInspector.
  132. TargetVector mTargets;
  133. S32 mComponentGroupTargetId;
  134. F32 mDividerPos;
  135. S32 mDividerMargin;
  136. bool mOverDivider;
  137. bool mMovingDivider;
  138. SimObjectPtr<GuiInspectorField> mHLField;
  139. String mGroupFilters;
  140. bool mShowCustomFields;
  141. };
  142. #endif