MeshLib C++ Docs
Loading...
Searching...
No Matches
MRSceneObjectsListDrawer.h
Go to the documentation of this file.
1#pragma once
2
3#include "exports.h"
4#include "MRSceneReorder.h"
5#include <memory>
6#include <string>
7#include <unordered_map>
8
9namespace MR
10{
13
14
15class Object;
16
18class MRVIEWER_CLASS SceneObjectsListDrawer
19{
20public:
21 virtual ~SceneObjectsListDrawer() = default;
22
25 MRVIEWER_API virtual void draw( float height );
26
31
33 void setDeselectNewHiddenObjects( bool deselect ) { deselectNewHiddenObjects_ = deselect; }
36
40 MRVIEWER_API void changeSelection( bool isDown, bool isShift );
43 MRVIEWER_API void changeVisible( bool isDown );
44
46 MRVIEWER_API void selectAllObjects();
47
49 MRVIEWER_API void setLeavesVisibility( bool visible );
50
52 MRVIEWER_API void setObjectTreeState( const Object* obj, bool open );
53
55 MRVIEWER_API void expandObjectTreeAndScroll( const Object* obj );
56
59 MRVIEWER_API void collapseSceneTree();
60
62 MRVIEWER_API void allowSceneReorder( bool allow );
63
65 MRVIEWER_API void setNextFrameFixScroll( int skipFrames = 1 );
66protected:
70 MRVIEWER_API virtual void drawCustomObjectPrefixInScene_( const Object&, bool )
71 {}
72
74 MRVIEWER_API virtual void drawSceneContextMenu_( const std::vector<std::shared_ptr<Object>>& , const std::string& )
75 {}
76
80 MRVIEWER_API virtual float drawCustomTreeObjectProperties_( Object& obj, bool onlyCalcHeight );
81
82 typedef int ImGuiTreeNodeFlags;
84 MRVIEWER_API virtual bool collapsingHeader_( const std::string& uniqueName, ImGuiTreeNodeFlags flags );
85
86 MRVIEWER_API virtual std::string objectLineStrId_( const Object& object, const std::string& uniqueStr );
87
89 MRVIEWER_API virtual bool drawObject_( Object& object, const std::string& uniqueStr, int depth );
91 MRVIEWER_API virtual bool drawSkippedObject_( Object& object, const std::string& uniqueStr, int depth );
92
94 MRVIEWER_API bool drawObjectCollapsingHeader_( Object& object, const std::string& uniqueStr, bool hasRealChildren );
95
97 MRVIEWER_API void processItemClick_( Object& object, const std::vector<std::shared_ptr<Object>>& selected );
98
100 MRVIEWER_API void makeDragDropSource_( const std::vector<std::shared_ptr<Object>>& payload );
101
103 MRVIEWER_API bool needDragDropTarget_();
104
108 MRVIEWER_API void makeDragDropTarget_( Object& target, bool before, bool betweenLine, const std::string& uniqueStr );
109
111 MRVIEWER_API void drawObjectVisibilityCheckbox_( Object& object, const std::string& uniqueStr );
112
115private:
116 void drawObjectsList_();
117
118 float getDrawDropTargetHeight_() const;
119 void reorderSceneIfNeeded_();
120
122 MRVIEWER_API virtual void updateSceneWindowScrollIfNeeded_();
123
124 std::vector<Object*> getPreSelection_( Object* meshclicked,
125 bool isShift, bool isCtrl,
126 const std::vector<std::shared_ptr<Object>>& selected,
127 const std::vector<std::shared_ptr<Object>>& all );
128 void updateSelection_( Object* objPtr, const std::vector<std::shared_ptr<Object>>& selected, const std::vector<std::shared_ptr<Object>>& all );
129
130 bool clickTrigger_ = false;
131 bool allowSceneReorder_ = true;
132
134 struct MoveAndScrollData
135 {
136 int index = -1;
137 float posY = -1.f;
138 bool needScroll = false;
139 };
140 MoveAndScrollData upFirstSelected_;
141 MoveAndScrollData downLastSelected_;
142 MoveAndScrollData nextVisible_;
143
144 SceneReorder sceneReorderCommand_;
147 struct ScrollPositionPreservation
148 {
149 float relativeMousePos{ 0.0f };
150 float absLinePosRatio{ 0.0f };
151 } prevScrollInfo_;
153 int framesTillFixScroll_ = 0;
155 bool dragObjectsMode_{ false };
157 bool dragModeTrigger_{ false };
158
160 void applyCollapseSceneTree_();
161
163 bool collapseSceneTreeRequested_ = false;
164
165protected:
166 std::unordered_map<const Object*, bool> sceneOpenCommands_;
167};
168
170constexpr inline int sDefaultGroupState = 1 << 5;
171
172}
named object in the data model
Definition MRObject.h:61
class for drawing a list of scene objects (and handling interaction with it)
Definition MRSceneObjectsListDrawer.h:19
auto height(const Box< V > &box)
returns size along y axis
Definition MRBox.h:361
auto depth(const Box< V > &box)
returns size along z axis
Definition MRBox.h:368
int index
Definition MRSceneObjectsListDrawer.h:136
void setObjectTreeState(const Object *obj, bool open)
set object collapse state (hiding children)
void setLeavesVisibility(bool visible)
set visible flag all selectable objects
void changeSelection(bool isDown, bool isShift)
void setNextFrameFixScroll(int skipFrames=1)
helper method for fix scroll position after change available height
std::unordered_map< const Object *, bool > sceneOpenCommands_
Definition MRSceneObjectsListDrawer.h:166
virtual void drawCustomObjectPrefixInScene_(const Object &, bool)
Definition MRSceneObjectsListDrawer.h:70
virtual void draw(float height)
void makeDragDropTarget_(Object &target, bool before, bool betweenLine, const std::string &uniqueStr)
bool needScroll
scroll position of new selected object in list of all
Definition MRSceneObjectsListDrawer.h:138
bool needDragDropTarget_()
checking the need to draw a target
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)
void drawObjectVisibilityCheckbox_(Object &object, const std::string &uniqueStr)
draw visibility checkbox and call ImGui::SameLine at the end
void allowSceneReorder(bool allow)
set possibility change object order
bool drawObjectCollapsingHeader_(Object &object, const std::string &uniqueStr, bool hasRealChildren)
function that draws collapsing header and process click on it
void setShowNewSelectedObjects(bool show)
set flag of the object visibility activation after selection
Definition MRSceneObjectsListDrawer.h:28
void makeDragDropSource_(const std::vector< std::shared_ptr< Object > > &payload)
payload object will be moved
bool getDeselectNewHiddenObjects()
get flag of deselect object after hidden
Definition MRSceneObjectsListDrawer.h:35
void selectAllObjects()
select all selectable objects
void expandObjectTreeAndScroll(const Object *obj)
expands all objs parents in tree and scroll scene tree window so selection becomes visible
void changeVisible(bool isDown)
virtual void drawSceneContextMenu_(const std::vector< std::shared_ptr< Object > > &, const std::string &)
Definition MRSceneObjectsListDrawer.h:74
bool getShowNewSelectedObjects()
get flag of the object visibility activation after selection
Definition MRSceneObjectsListDrawer.h:30
float relativeMousePos
Definition MRSceneObjectsListDrawer.h:149
void setDeselectNewHiddenObjects(bool deselect)
set flag of deselect object after hidden
Definition MRSceneObjectsListDrawer.h:33
virtual bool drawObject_(Object &object, const std::string &uniqueStr, int depth)
override this to customize whole object line
virtual bool drawSkippedObject_(Object &object, const std::string &uniqueStr, int depth)
draw dummy container for skipped object
bool showNewSelectedObjects_
Definition MRSceneObjectsListDrawer.h:113
constexpr int sDefaultGroupState
ImGuiTreeNodeFlags_DefaultOpen; the value is spelled out not to include imgui.h here,...
Definition MRSceneObjectsListDrawer.h:170
int ImGuiTreeNodeFlags
Definition MRSceneObjectsListDrawer.h:82
virtual std::string objectLineStrId_(const Object &object, const std::string &uniqueStr)
float absLinePosRatio
Definition MRSceneObjectsListDrawer.h:150
bool deselectNewHiddenObjects_
Definition MRSceneObjectsListDrawer.h:114
virtual bool collapsingHeader_(const std::string &uniqueName, ImGuiTreeNodeFlags flags)
override this to customize CollapsingHeader draw
float posY
index of new selected object in list of all
Definition MRSceneObjectsListDrawer.h:137
virtual float drawCustomTreeObjectProperties_(Object &obj, bool onlyCalcHeight)
virtual ~SceneObjectsListDrawer()=default
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRSceneReorder.h:13