Generate gizmos' tooltip on demand
This commit is contained in:
parent
ffe404fc5b
commit
a0ed240af1
@ -262,12 +262,6 @@ void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GLGizmoBase::set_tooltip(const std::string& tooltip) const
|
||||
{
|
||||
m_tooltip = tooltip;
|
||||
}
|
||||
|
||||
std::string GLGizmoBase::format(float value, unsigned int decimals) const
|
||||
{
|
||||
return Slic3r::string_printf("%.*f", decimals, value);
|
||||
|
@ -100,7 +100,6 @@ protected:
|
||||
mutable std::vector<Grabber> m_grabbers;
|
||||
ImGuiWrapper* m_imgui;
|
||||
bool m_first_input_window_render;
|
||||
mutable std::string m_tooltip;
|
||||
|
||||
public:
|
||||
GLGizmoBase(GLCanvas3D& parent,
|
||||
@ -146,11 +145,11 @@ public:
|
||||
|
||||
void update(const UpdateData& data);
|
||||
|
||||
void render() const { m_tooltip.clear(); on_render(); }
|
||||
void render() const { on_render(); }
|
||||
void render_for_picking() const { on_render_for_picking(); }
|
||||
void render_input_window(float x, float y, float bottom_limit);
|
||||
|
||||
virtual const std::string& get_tooltip() const { return m_tooltip; }
|
||||
virtual std::string get_tooltip() const { return ""; }
|
||||
|
||||
protected:
|
||||
virtual bool on_init() = 0;
|
||||
@ -177,7 +176,6 @@ protected:
|
||||
void render_grabbers(float size) const;
|
||||
void render_grabbers_for_picking(const BoundingBoxf3& box) const;
|
||||
|
||||
void set_tooltip(const std::string& tooltip) const;
|
||||
std::string format(float value, unsigned int decimals) const;
|
||||
};
|
||||
|
||||
|
@ -30,6 +30,11 @@ GLGizmoCut::GLGizmoCut(GLCanvas3D& parent, const std::string& icon_filename, uns
|
||||
, m_rotate_lower(false)
|
||||
{}
|
||||
|
||||
std::string GLGizmoCut::get_tooltip() const
|
||||
{
|
||||
return (m_hover_id == 0 || m_grabbers[0].dragging) ? "Z: " + format(m_cut_z, 2) : "";
|
||||
}
|
||||
|
||||
bool GLGizmoCut::on_init()
|
||||
{
|
||||
m_grabbers.emplace_back();
|
||||
@ -79,9 +84,6 @@ void GLGizmoCut::on_update(const UpdateData& data)
|
||||
|
||||
void GLGizmoCut::on_render() const
|
||||
{
|
||||
if (m_hover_id == 0 || m_grabbers[0].dragging)
|
||||
set_tooltip("Z: " + format(m_cut_z, 2));
|
||||
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
|
||||
update_max_z(selection);
|
||||
|
@ -28,6 +28,8 @@ public:
|
||||
double get_cut_z() const { return m_cut_z; }
|
||||
void set_cut_z(double cut_z) const;
|
||||
|
||||
virtual std::string get_tooltip() const;
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual void on_load(cereal::BinaryInputArchive& ar) { ar(m_cut_z, m_keep_upper, m_keep_lower, m_rotate_lower); }
|
||||
|
@ -31,6 +31,22 @@ GLGizmoMove3D::~GLGizmoMove3D()
|
||||
::gluDeleteQuadric(m_quadric);
|
||||
}
|
||||
|
||||
std::string GLGizmoMove3D::get_tooltip() const
|
||||
{
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
bool show_position = selection.is_single_full_instance();
|
||||
const Vec3d& position = selection.get_bounding_box().center();
|
||||
|
||||
if (m_hover_id == 0 || m_grabbers[0].dragging)
|
||||
return "X: " + format(show_position ? position(0) : m_displacement(0), 2);
|
||||
else if (m_hover_id == 1 || m_grabbers[1].dragging)
|
||||
return "Y: " + format(show_position ? position(1) : m_displacement(1), 2);
|
||||
else if (m_hover_id == 2 || m_grabbers[2].dragging)
|
||||
return "Z: " + format(show_position ? position(2) : m_displacement(2), 2);
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
bool GLGizmoMove3D::on_init()
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
@ -85,22 +101,6 @@ void GLGizmoMove3D::on_render() const
|
||||
{
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
|
||||
bool show_position = selection.is_single_full_instance();
|
||||
const Vec3d& position = selection.get_bounding_box().center();
|
||||
|
||||
if ((show_position && (m_hover_id == 0)) || m_grabbers[0].dragging)
|
||||
set_tooltip("X: " + format(show_position ? position(0) : m_displacement(0), 2));
|
||||
else if (!m_grabbers[0].dragging && (m_hover_id == 0))
|
||||
set_tooltip("X");
|
||||
else if ((show_position && (m_hover_id == 1)) || m_grabbers[1].dragging)
|
||||
set_tooltip("Y: " + format(show_position ? position(1) : m_displacement(1), 2));
|
||||
else if (!m_grabbers[1].dragging && (m_hover_id == 1))
|
||||
set_tooltip("Y");
|
||||
else if ((show_position && (m_hover_id == 2)) || m_grabbers[2].dragging)
|
||||
set_tooltip("Z: " + format(show_position ? position(2) : m_displacement(2), 2));
|
||||
else if (!m_grabbers[2].dragging && (m_hover_id == 2))
|
||||
set_tooltip("Z");
|
||||
|
||||
glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
|
||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||
|
||||
|
@ -30,6 +30,8 @@ public:
|
||||
|
||||
const Vec3d& get_displacement() const { return m_displacement; }
|
||||
|
||||
virtual std::string get_tooltip() const;
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual std::string on_get_name() const;
|
||||
|
@ -67,6 +67,18 @@ void GLGizmoRotate::set_angle(double angle)
|
||||
m_angle = angle;
|
||||
}
|
||||
|
||||
std::string GLGizmoRotate::get_tooltip() const
|
||||
{
|
||||
std::string axis;
|
||||
switch (m_axis)
|
||||
{
|
||||
case X: { axis = "X"; break; }
|
||||
case Y: { axis = "Y"; break; }
|
||||
case Z: { axis = "Z"; break; }
|
||||
}
|
||||
return (m_hover_id == 0 || m_grabbers[0].dragging) ? axis + ": " + format((float)Geometry::rad2deg(m_angle), 4) : "";
|
||||
}
|
||||
|
||||
bool GLGizmoRotate::on_init()
|
||||
{
|
||||
m_grabbers.push_back(Grabber());
|
||||
@ -127,17 +139,7 @@ void GLGizmoRotate::on_render() const
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
const BoundingBoxf3& box = selection.get_bounding_box();
|
||||
|
||||
std::string axis;
|
||||
switch (m_axis)
|
||||
{
|
||||
case X: { axis = "X"; break; }
|
||||
case Y: { axis = "Y"; break; }
|
||||
case Z: { axis = "Z"; break; }
|
||||
}
|
||||
|
||||
if (m_hover_id == 0 || m_grabbers[0].dragging)
|
||||
set_tooltip(axis + ": " + format((float)Geometry::rad2deg(m_angle), 4));
|
||||
else
|
||||
if (m_hover_id != 0 && !m_grabbers[0].dragging)
|
||||
{
|
||||
m_center = box.center();
|
||||
m_radius = Offset + box.radius();
|
||||
|
@ -49,6 +49,8 @@ public:
|
||||
double get_angle() const { return m_angle; }
|
||||
void set_angle(double angle);
|
||||
|
||||
virtual std::string get_tooltip() const;
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual std::string on_get_name() const { return ""; }
|
||||
@ -81,14 +83,14 @@ public:
|
||||
Vec3d get_rotation() const { return Vec3d(m_gizmos[X].get_angle(), m_gizmos[Y].get_angle(), m_gizmos[Z].get_angle()); }
|
||||
void set_rotation(const Vec3d& rotation) { m_gizmos[X].set_angle(rotation(0)); m_gizmos[Y].set_angle(rotation(1)); m_gizmos[Z].set_angle(rotation(2)); }
|
||||
|
||||
virtual const std::string& get_tooltip() const
|
||||
virtual std::string get_tooltip() const
|
||||
{
|
||||
m_tooltip = m_gizmos[X].get_tooltip();
|
||||
if (m_tooltip.empty())
|
||||
m_tooltip = m_gizmos[Y].get_tooltip();
|
||||
if (m_tooltip.empty())
|
||||
m_tooltip = m_gizmos[Z].get_tooltip();
|
||||
return m_tooltip;
|
||||
std::string tooltip = m_gizmos[X].get_tooltip();
|
||||
if (tooltip.empty())
|
||||
tooltip = m_gizmos[Y].get_tooltip();
|
||||
if (tooltip.empty())
|
||||
tooltip = m_gizmos[Z].get_tooltip();
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -20,6 +20,38 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filen
|
||||
{
|
||||
}
|
||||
|
||||
std::string GLGizmoScale3D::get_tooltip() const
|
||||
{
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
|
||||
bool single_instance = selection.is_single_full_instance();
|
||||
bool single_volume = selection.is_single_modifier() || selection.is_single_volume();
|
||||
bool single_selection = single_instance || single_volume;
|
||||
|
||||
Vec3f scale = 100.0f * Vec3f::Ones();
|
||||
if (single_instance)
|
||||
scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_scaling_factor().cast<float>();
|
||||
else if (single_volume)
|
||||
scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_volume_scaling_factor().cast<float>();
|
||||
|
||||
if (m_hover_id == 0 || m_hover_id == 1 || m_grabbers[0].dragging || m_grabbers[1].dragging)
|
||||
return "X: " + format(scale(0), 4) + "%";
|
||||
else if (m_hover_id == 2 || m_hover_id == 3 || m_grabbers[2].dragging || m_grabbers[3].dragging)
|
||||
return "Y: " + format(scale(1), 4) + "%";
|
||||
else if (m_hover_id == 4 || m_hover_id == 5 || m_grabbers[4].dragging || m_grabbers[5].dragging)
|
||||
return "Z: " + format(scale(2), 4) + "%";
|
||||
else if (m_hover_id == 6 || m_hover_id == 7 || m_hover_id == 8 || m_hover_id == 9 ||
|
||||
m_grabbers[6].dragging || m_grabbers[7].dragging || m_grabbers[8].dragging || m_grabbers[9].dragging)
|
||||
{
|
||||
std::string tooltip = "X: " + format(scale(0), 4) + "%\n";
|
||||
tooltip += "Y: " + format(scale(1), 4) + "%\n";
|
||||
tooltip += "Z: " + format(scale(2), 4) + "%";
|
||||
return tooltip;
|
||||
}
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
bool GLGizmoScale3D::on_init()
|
||||
{
|
||||
for (int i = 0; i < 10; ++i)
|
||||
@ -89,37 +121,6 @@ void GLGizmoScale3D::on_render() const
|
||||
|
||||
bool single_instance = selection.is_single_full_instance();
|
||||
bool single_volume = selection.is_single_modifier() || selection.is_single_volume();
|
||||
bool single_selection = single_instance || single_volume;
|
||||
|
||||
Vec3f scale = 100.0f * Vec3f::Ones();
|
||||
if (single_instance)
|
||||
scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_scaling_factor().cast<float>();
|
||||
else if (single_volume)
|
||||
scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_volume_scaling_factor().cast<float>();
|
||||
|
||||
if ((single_selection && ((m_hover_id == 0) || (m_hover_id == 1))) || m_grabbers[0].dragging || m_grabbers[1].dragging)
|
||||
set_tooltip("X: " + format(scale(0), 4) + "%");
|
||||
else if (!m_grabbers[0].dragging && !m_grabbers[1].dragging && ((m_hover_id == 0) || (m_hover_id == 1)))
|
||||
set_tooltip("X");
|
||||
else if ((single_selection && ((m_hover_id == 2) || (m_hover_id == 3))) || m_grabbers[2].dragging || m_grabbers[3].dragging)
|
||||
set_tooltip("Y: " + format(scale(1), 4) + "%");
|
||||
else if (!m_grabbers[2].dragging && !m_grabbers[3].dragging && ((m_hover_id == 2) || (m_hover_id == 3)))
|
||||
set_tooltip("Y");
|
||||
else if ((single_selection && ((m_hover_id == 4) || (m_hover_id == 5))) || m_grabbers[4].dragging || m_grabbers[5].dragging)
|
||||
set_tooltip("Z: " + format(scale(2), 4) + "%");
|
||||
else if (!m_grabbers[4].dragging && !m_grabbers[5].dragging && ((m_hover_id == 4) || (m_hover_id == 5)))
|
||||
set_tooltip("Z");
|
||||
else if ((single_selection && ((m_hover_id == 6) || (m_hover_id == 7) || (m_hover_id == 8) || (m_hover_id == 9)))
|
||||
|| m_grabbers[6].dragging || m_grabbers[7].dragging || m_grabbers[8].dragging || m_grabbers[9].dragging)
|
||||
{
|
||||
std::string tooltip = "X: " + format(scale(0), 4) + "%\n";
|
||||
tooltip += "Y: " + format(scale(1), 4) + "%\n";
|
||||
tooltip += "Z: " + format(scale(2), 4) + "%";
|
||||
set_tooltip(tooltip);
|
||||
}
|
||||
else if (!m_grabbers[6].dragging && !m_grabbers[7].dragging && !m_grabbers[8].dragging && !m_grabbers[9].dragging &&
|
||||
((m_hover_id == 6) || (m_hover_id == 7) || (m_hover_id == 8) || (m_hover_id == 9)))
|
||||
set_tooltip("X/Y/Z");
|
||||
|
||||
glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
|
||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||
|
@ -42,6 +42,8 @@ public:
|
||||
|
||||
const Vec3d& get_offset() const { return m_offset; }
|
||||
|
||||
virtual std::string get_tooltip() const;
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual std::string on_get_name() const;
|
||||
|
Loading…
Reference in New Issue
Block a user