guiInspector.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 ) { return mTargets[ index ]; }
  67. /// Return the number of objects being inspected by this GuiInspector.
  68. U32 getNumInspectObjects() const { return mTargets.size(); }
  69. /// Call inspectPreApply on all inspected objects.
  70. void sendInspectPreApply();
  71. /// Call inspectPostApply on all inspected objects.
  72. void sendInspectPostApply();
  73. /// Set the currently inspected object name
  74. /// @note Only valid in single-object mode.
  75. void setName( StringTableEntry newName );
  76. /// Deletes all GuiInspectorGroups
  77. void clearGroups();
  78. /// Returns true if the named group exists
  79. /// Helper for inspectObject
  80. GuiInspectorGroup* findExistentGroup( StringTableEntry groupName );
  81. /// Should there be a GuiInspectorField associated with this fieldName,
  82. /// update it to reflect actual/current value of that field in the inspected object.
  83. /// Added to support UndoActions
  84. void updateFieldValue( StringTableEntry fieldName, const char* arrayIdx );
  85. /// Divider position is interpreted as an offset
  86. /// from the right edge of the field control.
  87. /// Divider margin is an offset on both left and right
  88. /// sides of the divider in which it can be selected
  89. /// with the mouse.
  90. void getDivider( S32 &pos, S32 &margin );
  91. void updateDivider();
  92. bool collideDivider( const Point2I &localPnt );
  93. void setHighlightField( GuiInspectorField *field );
  94. // If returns true that group will not be inspected.
  95. bool isGroupFiltered( const char *groupName ) const;
  96. // Returns true only if the group name follows a minus symbol in the filters.
  97. bool isGroupExplicitlyFiltered( const char *groupName ) const;
  98. void setObjectField( const char *fieldName, const char *data );
  99. static GuiInspector* findByObject( SimObject *obj );
  100. protected:
  101. typedef Vector< SimObjectPtr< SimObject > > TargetVector;
  102. Vector<GuiInspectorGroup*> mGroups;
  103. /// Objects being inspected by this GuiInspector.
  104. TargetVector mTargets;
  105. F32 mDividerPos;
  106. S32 mDividerMargin;
  107. bool mOverDivider;
  108. bool mMovingDivider;
  109. SimObjectPtr<GuiInspectorField> mHLField;
  110. String mGroupFilters;
  111. bool mShowCustomFields;
  112. void refresh();
  113. };
  114. #endif