MeshLib C++ Docs
Loading...
Searching...
No Matches
MRAncillaryLabels.h
Go to the documentation of this file.
1#pragma once
2#ifndef MRMESH_NO_LABEL
3
4#include "exports.h"
5#include "MRMesh/MRMeshFwd.h"
6#include "MRMesh/MRVector2.h"
10#include <memory>
11#include <optional>
12
13namespace MR
14{
15class Object;
16class ObjectLabel;
17struct PositionedText;
18
20struct MRVIEWER_CLASS AncillaryLabel
21{
22 std::shared_ptr<ObjectLabel> obj;
23
24 AncillaryLabel() = default;
25
27 AncillaryLabel( AncillaryLabel && b ) noexcept = default;
28 AncillaryLabel & operator =( AncillaryLabel && b ) { reset(); obj = std::move( b.obj ); return *this; }
29
31 explicit AncillaryLabel( Object& parent, const PositionedText& text, bool depthTest = false )
32 { make( parent, text, depthTest ); }
33
35 MRVIEWER_API void make( Object& parent, const PositionedText& text, bool depthTest = false );
36
38 static MRVIEWER_API std::shared_ptr<ObjectLabel> makeDetached(
39 const PositionedText& text, bool depthTest = false );
40
42 MRVIEWER_API void reset();
43
45 ~AncillaryLabel() { reset(); }
46
48 MRVIEWER_API void setText( const PositionedText& text );
49
51 MRVIEWER_API void resetText();
52
54 MRVIEWER_API void setDepthTest( bool depthTest );
55
57 MRVIEWER_API void setPosition( const Vector3f& pos );
58};
59
61class MRVIEWER_CLASS AncillaryImGuiLabel : public PreDrawListener
62{
63public:
65
67 MRVIEWER_API void make( Object &parent, const PositionedText& text );
68
71 MRVIEWER_API void make( std::shared_ptr<Object> parent, const PositionedText& text );
72
74 MRVIEWER_API void make( const PositionedText& text );
75
77 MRVIEWER_API void reset();
78
82 Vector2f getPivot() const { return pivot_; }
83 void setPivot( Vector2f pivot ) { pivot_ = pivot; }
84
86 MRVIEWER_API void overrideParams( const ImGuiMeasurementIndicators::Params& params );
87
89 MRVIEWER_API void resetOverrideParams();
90private:
91 MRVIEWER_API virtual void preDraw_() override;
92
93 std::weak_ptr<Object> parent_;
94 Vector2f pivot_ = { 0.5f, 0.5f };
95 Vector3f localPos_;
96 PositionedText labelData_;
97 std::optional<ImGuiMeasurementIndicators::Params> overrideParams_;
98 boost::signals2::scoped_connection parentXfConnection_;
99};
100
101
102} //namespace MR
103
104#endif
Helper class that draws ImGui label.
Definition MRAncillaryLabels.h:62
MRVIEWER_API void make(Object &parent, const PositionedText &text)
Make label in parent space coordinates, follows parent worldXf.
void setPivot(Vector2f pivot)
Definition MRAncillaryLabels.h:83
Vector2f getPivot() const
Definition MRAncillaryLabels.h:82
MRVIEWER_API void make(std::shared_ptr< Object > parent, const PositionedText &text)
MRVIEWER_API void reset()
clears this instance
MRVIEWER_API void resetOverrideParams()
use default parameters instead of overridden ones
MRVIEWER_API void make(const PositionedText &text)
Make label in world space coordinates.
MRVIEWER_API void overrideParams(const ImGuiMeasurementIndicators::Params &params)
Optionally override rendering params for this label.
named object in the data model
Definition MRObject.h:62
Definition MRCameraOrientationPlugin.h:8
Helper class to manage ancillary labels used by plugins.
Definition MRAncillaryLabels.h:21
MRVIEWER_API void reset()
detach owned object from parent, stops owning it
AncillaryLabel(AncillaryLabel &&b) noexcept=default
since this uniquely owns an ancillary object, we provide only move operations, not copy
std::shared_ptr< ObjectLabel > obj
Definition MRAncillaryLabels.h:22
MRVIEWER_API void make(Object &parent, const PositionedText &text, bool depthTest=false)
Make not-pickable ancillary object, link it to parent object, and set label text.
MRVIEWER_API void setDepthTest(bool depthTest)
Set depth test.
AncillaryLabel()=default
MRVIEWER_API void setPosition(const Vector3f &pos)
Set text position.
MRVIEWER_API void setText(const PositionedText &text)
Set label text.
static MRVIEWER_API std::shared_ptr< ObjectLabel > makeDetached(const PositionedText &text, bool depthTest=false)
Make not-pickable ancillary object without parent object, and set label text.
~AncillaryLabel()
detach owned object from parent, stops owning it
Definition MRAncillaryLabels.h:45
MRVIEWER_API void resetText()
Reset label text.
AncillaryLabel(Object &parent, const PositionedText &text, bool depthTest=false)
Make not-pickable ancillary object, link it to parent object, and set label text.
Definition MRAncillaryLabels.h:31
Definition MRImGuiMeasurementIndicators.h:39
Definition MRPositionedText.h:10
Definition MRViewerEventsListener.h:168