MeshLib
 
Loading...
Searching...
No Matches
MRSceneObjectsListDrawer.h
Go to the documentation of this file.
1#pragma once
2#include "exports.h"
3#include <vector>
4#include <memory>
5#include <string>
6#include <unordered_map>
7
8namespace MR
9{
10
11class Object;
12
14class MRVIEWER_CLASS SceneObjectsListDrawer
15{
16public:
17 virtual ~SceneObjectsListDrawer() = default;
18
21 MRVIEWER_API virtual void draw( float height, float scaling );
22
24 void setShowNewSelectedObjects( bool show ) { showNewSelectedObjects_ = show; };
26 bool getShowNewSelectedObjects() { return showNewSelectedObjects_; };
27
29 void setDeselectNewHiddenObjects( bool deselect ) { deselectNewHiddenObjects_ = deselect; }
31 bool getDeselectNewHiddenObjects() { return deselectNewHiddenObjects_; }
32
36 MRVIEWER_API void changeSelection( bool isDown, bool isShift );
39 MRVIEWER_API void changeVisible( bool isDown );
40
41 // select all selectable objects
42 MRVIEWER_API void selectAllObjects();
43
44 // stt visible flag all selectable objects
45 MRVIEWER_API void setLeavesVisibility( bool visible );
46
48 MRVIEWER_API void setObjectTreeState( const Object* obj, bool open );
49
51 MRVIEWER_API void allowSceneReorder( bool allow );
52
54 MRVIEWER_API void setNextFrameFixScroll() { nextFrameFixScroll_ = true; }
55protected:
59 MRVIEWER_API virtual void drawCustomObjectPrefixInScene_( const Object&, bool )
60 {}
63 MRVIEWER_API virtual void drawSceneContextMenu_( const std::vector<std::shared_ptr<Object>>& /*selected*/, const std::string& /*uniqueStr*/ )
64 {}
65
69 MRVIEWER_API virtual float drawCustomTreeObjectProperties_( Object& obj, bool onlyCalcHeight );
70
71 typedef int ImGuiTreeNodeFlags;
73 MRVIEWER_API virtual bool collapsingHeader_( const std::string& uniqueName, ImGuiTreeNodeFlags flags );
74
75 MRVIEWER_API virtual std::string objectLineStrId_( const Object& object, const std::string& uniqueStr );
76
78 MRVIEWER_API virtual bool drawObject_( Object& object, const std::string& uniqueStr, int depth );
80 MRVIEWER_API virtual bool drawSkippedObject_( Object& object, const std::string& uniqueStr, int depth );
81
83 MRVIEWER_API bool drawObjectCollapsingHeader_( Object& object, const std::string& uniqueStr, bool hasRealChildren );
84
86 MRVIEWER_API void processItemClick_( Object& object, const std::vector<std::shared_ptr<Object>>& selected );
87
89 MRVIEWER_API void makeDragDropSource_( const std::vector<std::shared_ptr<Object>>& payload );
90
92 MRVIEWER_API bool needDragDropTarget_();
93
97 MRVIEWER_API void makeDragDropTarget_( Object& target, bool before, bool betweenLine, const std::string& uniqueStr );
98
99 // draw visibility checkbox and call ImGui::SameLine at the end
100 MRVIEWER_API void drawObjectVisibilityCheckbox_( Object& object, const std::string& uniqueStr );
101
102 bool showNewSelectedObjects_ = true;
103 bool deselectNewHiddenObjects_ = false;
104private:
105 void drawObjectsList_();
106
107 float getDrawDropTargetHeight_() const { return 4.f * menuScaling_; }
108 void reorderSceneIfNeeded_();
109
111 MRVIEWER_API virtual void updateSceneWindowScrollIfNeeded_();
112
113 std::vector<Object*> getPreSelection_( Object* meshclicked,
114 bool isShift, bool isCtrl,
115 const std::vector<std::shared_ptr<Object>>& selected,
116 const std::vector<std::shared_ptr<Object>>& all );
117 void updateSelection_( Object* objPtr, const std::vector<std::shared_ptr<Object>>& selected, const std::vector<std::shared_ptr<Object>>& all );
118
119 bool dragTrigger_ = false;
120 bool clickTrigger_ = false;
121 bool allowSceneReorder_ = true;
122
123 // struct to auto-scroll after move (arrow up / down)
124 struct MoveAndScrollData
125 {
126 int index = -1; // index of new selected object in list of all
127 float posY = -1.f; // scroll position of new selected object in list of all
128 bool needScroll = false; // flag to using auto-scroll
129 };
130 MoveAndScrollData upFirstSelected_;
131 MoveAndScrollData downLastSelected_;
132 MoveAndScrollData nextVisible_;
133
134 struct SceneReorder
135 {
136 std::vector<Object*> who; // object that will be moved
137 Object* to{ nullptr }; // address object
138 bool before{ false }; // if false "who" will be attached to "to" as last child, otherwise "who" will be attached to "to"'s parent as child before "to"
139 } sceneReorderCommand_;
140 // Drag objects servant data
141 // struct to handle changed scene window size scroll
142 struct ScrollPositionPreservation
143 {
144 float relativeMousePos{ 0.0f };
145 float absLinePosRatio{ 0.0f };
146 } prevScrollInfo_;
147 // true to fix scroll position in next frame
148 bool nextFrameFixScroll_{ false };
149 // flag to know if we are dragging objects now or not
150 bool dragObjectsMode_{ false };
151
152protected:
153 float menuScaling_ = 1.f;
154 std::unordered_map<const Object*, bool> sceneOpenCommands_;
155};
156
157}
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:15
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:63
std::unordered_map< const Object *, bool > sceneOpenCommands_
Definition MRSceneObjectsListDrawer.h:154
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:54
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:24
bool getDeselectNewHiddenObjects()
get flag of deselect object after hidden
Definition MRSceneObjectsListDrawer.h:31
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:26
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:29
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:71
MRVIEWER_API void drawObjectVisibilityCheckbox_(Object &object, const std::string &uniqueStr)
virtual MRVIEWER_API void drawCustomObjectPrefixInScene_(const Object &, bool)
Definition MRSceneObjectsListDrawer.h:59
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