MeshLib Documentation
Loading...
Searching...
No Matches
MRSceneObjectsListDrawer.h
Go to the documentation of this file.
1#pragma once
2
3#include "exports.h"
4#include "SceneReorder.h"
5#include <memory>
6#include <string>
7#include <unordered_map>
8
9namespace MR
10{
11
12class Object;
13
15class MRVIEWER_CLASS SceneObjectsListDrawer
16{
17public:
18 virtual ~SceneObjectsListDrawer() = default;
19
22 MRVIEWER_API virtual void draw( float height, float scaling );
23
25 void setShowNewSelectedObjects( bool show ) { showNewSelectedObjects_ = show; };
27 bool getShowNewSelectedObjects() { return showNewSelectedObjects_; };
28
30 void setDeselectNewHiddenObjects( bool deselect ) { deselectNewHiddenObjects_ = deselect; }
32 bool getDeselectNewHiddenObjects() { return deselectNewHiddenObjects_; }
33
37 MRVIEWER_API void changeSelection( bool isDown, bool isShift );
40 MRVIEWER_API void changeVisible( bool isDown );
41
42 // select all selectable objects
43 MRVIEWER_API void selectAllObjects();
44
45 // stt visible flag all selectable objects
46 MRVIEWER_API void setLeavesVisibility( bool visible );
47
49 MRVIEWER_API void setObjectTreeState( const Object* obj, bool open );
50
52 MRVIEWER_API void allowSceneReorder( bool allow );
53
55 MRVIEWER_API void setNextFrameFixScroll() { nextFrameFixScroll_ = true; }
56protected:
60 MRVIEWER_API virtual void drawCustomObjectPrefixInScene_( const Object&, bool )
61 {}
64 MRVIEWER_API virtual void drawSceneContextMenu_( const std::vector<std::shared_ptr<Object>>& /*selected*/, const std::string& /*uniqueStr*/ )
65 {}
66
70 MRVIEWER_API virtual float drawCustomTreeObjectProperties_( Object& obj, bool onlyCalcHeight );
71
72 typedef int ImGuiTreeNodeFlags;
74 MRVIEWER_API virtual bool collapsingHeader_( const std::string& uniqueName, ImGuiTreeNodeFlags flags );
75
76 MRVIEWER_API virtual std::string objectLineStrId_( const Object& object, const std::string& uniqueStr );
77
79 MRVIEWER_API virtual bool drawObject_( Object& object, const std::string& uniqueStr, int depth );
81 MRVIEWER_API virtual bool drawSkippedObject_( Object& object, const std::string& uniqueStr, int depth );
82
84 MRVIEWER_API bool drawObjectCollapsingHeader_( Object& object, const std::string& uniqueStr, bool hasRealChildren );
85
87 MRVIEWER_API void processItemClick_( Object& object, const std::vector<std::shared_ptr<Object>>& selected );
88
90 MRVIEWER_API void makeDragDropSource_( const std::vector<std::shared_ptr<Object>>& payload );
91
93 MRVIEWER_API bool needDragDropTarget_();
94
98 MRVIEWER_API void makeDragDropTarget_( Object& target, bool before, bool betweenLine, const std::string& uniqueStr );
99
100 // draw visibility checkbox and call ImGui::SameLine at the end
101 MRVIEWER_API void drawObjectVisibilityCheckbox_( Object& object, const std::string& uniqueStr );
102
103 bool showNewSelectedObjects_ = true;
104 bool deselectNewHiddenObjects_ = false;
105private:
106 void drawObjectsList_();
107
108 float getDrawDropTargetHeight_() const { return 4.f * menuScaling_; }
109 void reorderSceneIfNeeded_();
110
112 MRVIEWER_API virtual void updateSceneWindowScrollIfNeeded_();
113
114 std::vector<Object*> getPreSelection_( Object* meshclicked,
115 bool isShift, bool isCtrl,
116 const std::vector<std::shared_ptr<Object>>& selected,
117 const std::vector<std::shared_ptr<Object>>& all );
118 void updateSelection_( Object* objPtr, const std::vector<std::shared_ptr<Object>>& selected, const std::vector<std::shared_ptr<Object>>& all );
119
120 bool dragTrigger_ = false;
121 bool clickTrigger_ = false;
122 bool allowSceneReorder_ = true;
123
124 // struct to auto-scroll after move (arrow up / down)
125 struct MoveAndScrollData
126 {
127 int index = -1; // index of new selected object in list of all
128 float posY = -1.f; // scroll position of new selected object in list of all
129 bool needScroll = false; // flag to using auto-scroll
130 };
131 MoveAndScrollData upFirstSelected_;
132 MoveAndScrollData downLastSelected_;
133 MoveAndScrollData nextVisible_;
134
135 SceneReorder sceneReorderCommand_;
136 // Drag objects servant data
137 // struct to handle changed scene window size scroll
138 struct ScrollPositionPreservation
139 {
140 float relativeMousePos{ 0.0f };
141 float absLinePosRatio{ 0.0f };
142 } prevScrollInfo_;
143 // true to fix scroll position in next frame
144 bool nextFrameFixScroll_{ false };
145 // flag to know if we are dragging objects now or not
146 bool dragObjectsMode_{ false };
147
148protected:
149 float menuScaling_ = 1.f;
150 std::unordered_map<const Object*, bool> sceneOpenCommands_;
151};
152
153}
named object in the data model
Definition MRObject.h:60
class for drawing a list of scene objects (and handling interaction with it)
Definition MRSceneObjectsListDrawer.h:16
MRVIEWER_API void selectAllObjects()
virtual MRVIEWER_API float drawCustomTreeObjectProperties_(Object &obj, bool onlyCalcHeight)
MRVIEWER_API void allowSceneReorder(bool allow)
set possibility change object order
virtual MRVIEWER_API void drawSceneContextMenu_(const std::vector< std::shared_ptr< Object > > &, const std::string &)
Definition MRSceneObjectsListDrawer.h:64
std::unordered_map< const Object *, bool > sceneOpenCommands_
Definition MRSceneObjectsListDrawer.h:150
MRVIEWER_API void setObjectTreeState(const Object *obj, bool open)
set object collapse state (hiding children)
virtual MRVIEWER_API std::string objectLineStrId_(const Object &object, const std::string &uniqueStr)
MRVIEWER_API void setLeavesVisibility(bool visible)
MRVIEWER_API void setNextFrameFixScroll()
helper method for fix scroll position after change available height
Definition MRSceneObjectsListDrawer.h:55
MRVIEWER_API void makeDragDropSource_(const std::vector< std::shared_ptr< Object > > &payload)
payload object will be moved
virtual MRVIEWER_API bool drawSkippedObject_(Object &object, const std::string &uniqueStr, int depth)
draw dummy container for skipped object
void setShowNewSelectedObjects(bool show)
set flag of the object visibility activation after selection
Definition MRSceneObjectsListDrawer.h:25
bool getDeselectNewHiddenObjects()
get flag of deselect object after hidden
Definition MRSceneObjectsListDrawer.h:32
MRVIEWER_API void processItemClick_(Object &object, const std::vector< std::shared_ptr< Object > > &selected)
function that do click logic on object line (select/deselect/rename/open context)
MRVIEWER_API void changeSelection(bool isDown, bool isShift)
virtual MRVIEWER_API bool collapsingHeader_(const std::string &uniqueName, ImGuiTreeNodeFlags flags)
override this to customize CollapsingHeader draw
virtual MRVIEWER_API void draw(float height, float scaling)
MRVIEWER_API bool needDragDropTarget_()
checking the need to draw a target
bool getShowNewSelectedObjects()
get flag of the object visibility activation after selection
Definition MRSceneObjectsListDrawer.h:27
MRVIEWER_API void makeDragDropTarget_(Object &target, bool before, bool betweenLine, const std::string &uniqueStr)
void setDeselectNewHiddenObjects(bool deselect)
set flag of deselect object after hidden
Definition MRSceneObjectsListDrawer.h:30
MRVIEWER_API bool drawObjectCollapsingHeader_(Object &object, const std::string &uniqueStr, bool hasRealChildren)
function that draws collapsing header and process click on it
int ImGuiTreeNodeFlags
Definition MRSceneObjectsListDrawer.h:72
MRVIEWER_API void drawObjectVisibilityCheckbox_(Object &object, const std::string &uniqueStr)
virtual MRVIEWER_API void drawCustomObjectPrefixInScene_(const Object &, bool)
Definition MRSceneObjectsListDrawer.h:60
MRVIEWER_API void changeVisible(bool isDown)
virtual MRVIEWER_API bool drawObject_(Object &object, const std::string &uniqueStr, int depth)
override this to customize whole object line
virtual ~SceneObjectsListDrawer()=default
Definition MRCameraOrientationPlugin.h:8