mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 01:07:57 -06:00
1st installment of gizmos refactoring
1) GLCanvas3D::Gizmos moved into a standalone class GLGizmosManager 2) GLGizmosManager handles mouse events by calling its on_mouse method (wip)
This commit is contained in:
commit
3818bfa19a
28 changed files with 1346 additions and 522 deletions
|
@ -23,6 +23,9 @@ GLGizmosManager::GLGizmosManager()
|
|||
, m_overlay_scale(1.0f)
|
||||
, m_overlay_border(5.0f)
|
||||
, m_overlay_gap_y(5.0f)
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
, m_tooltip("")
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
{
|
||||
}
|
||||
#else
|
||||
|
@ -186,51 +189,53 @@ void GLGizmosManager::set_overlay_scale(float scale)
|
|||
#endif // ENABLE_SVG_ICONS
|
||||
}
|
||||
|
||||
std::string GLGizmosManager::update_hover_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos, const Selection& selection)
|
||||
{
|
||||
std::string name = "";
|
||||
|
||||
if (!m_enabled)
|
||||
return name;
|
||||
|
||||
float cnv_h = (float)canvas.get_canvas_size().get_height();
|
||||
float height = get_total_overlay_height();
|
||||
#if ENABLE_SVG_ICONS
|
||||
float scaled_icons_size = m_overlay_icons_size * m_overlay_scale;
|
||||
float scaled_border = m_overlay_border * m_overlay_scale;
|
||||
float scaled_gap_y = m_overlay_gap_y * m_overlay_scale;
|
||||
float scaled_stride_y = scaled_icons_size + scaled_gap_y;
|
||||
float top_y = 0.5f * (cnv_h - height) + scaled_border;
|
||||
#else
|
||||
float top_y = 0.5f * (cnv_h - height) + m_overlay_border;
|
||||
float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * m_overlay_icons_scale;
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
|
||||
for (GizmosMap::iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
|
||||
{
|
||||
if ((it->second == nullptr) || !it->second->is_selectable())
|
||||
continue;
|
||||
|
||||
#if ENABLE_SVG_ICONS
|
||||
bool inside = (scaled_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size);
|
||||
#else
|
||||
bool inside = (m_overlay_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= m_overlay_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size);
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
if (inside)
|
||||
name = it->second->get_name();
|
||||
|
||||
if (it->second->is_activable(selection) && (it->second->get_state() != GLGizmoBase::On))
|
||||
it->second->set_state(inside ? GLGizmoBase::Hover : GLGizmoBase::Off);
|
||||
|
||||
#if ENABLE_SVG_ICONS
|
||||
top_y += scaled_stride_y;
|
||||
#else
|
||||
top_y += (scaled_icons_size + m_overlay_gap_y);
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
//std::string GLGizmosManager::update_hover_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos, const Selection& selection)
|
||||
//{
|
||||
// std::string name = "";
|
||||
//
|
||||
// if (!m_enabled)
|
||||
// return name;
|
||||
//
|
||||
// float cnv_h = (float)canvas.get_canvas_size().get_height();
|
||||
// float height = get_total_overlay_height();
|
||||
//#if ENABLE_SVG_ICONS
|
||||
// float scaled_icons_size = m_overlay_icons_size * m_overlay_scale;
|
||||
// float scaled_border = m_overlay_border * m_overlay_scale;
|
||||
// float scaled_gap_y = m_overlay_gap_y * m_overlay_scale;
|
||||
// float scaled_stride_y = scaled_icons_size + scaled_gap_y;
|
||||
// float top_y = 0.5f * (cnv_h - height) + scaled_border;
|
||||
//#else
|
||||
// float top_y = 0.5f * (cnv_h - height) + m_overlay_border;
|
||||
// float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * m_overlay_icons_scale;
|
||||
//#endif // ENABLE_SVG_ICONS
|
||||
//
|
||||
// for (GizmosMap::iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
|
||||
// {
|
||||
// if ((it->second == nullptr) || !it->second->is_selectable())
|
||||
// continue;
|
||||
//
|
||||
//#if ENABLE_SVG_ICONS
|
||||
// bool inside = (scaled_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size);
|
||||
//#else
|
||||
// bool inside = (m_overlay_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= m_overlay_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size);
|
||||
//#endif // ENABLE_SVG_ICONS
|
||||
// if (inside)
|
||||
// name = it->second->get_name();
|
||||
//
|
||||
// if (it->second->is_activable(selection) && (it->second->get_state() != GLGizmoBase::On))
|
||||
// it->second->set_state(inside ? GLGizmoBase::Hover : GLGizmoBase::Off);
|
||||
//
|
||||
//#if ENABLE_SVG_ICONS
|
||||
// top_y += scaled_stride_y;
|
||||
//#else
|
||||
// top_y += (scaled_icons_size + m_overlay_gap_y);
|
||||
//#endif // ENABLE_SVG_ICONS
|
||||
// }
|
||||
//
|
||||
// return name;
|
||||
//}
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
void GLGizmosManager::update_on_off_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos, const Selection& selection)
|
||||
{
|
||||
|
@ -346,46 +351,48 @@ void GLGizmosManager::enable_grabber(EType type, unsigned int id, bool enable)
|
|||
}
|
||||
}
|
||||
|
||||
bool GLGizmosManager::overlay_contains_mouse(const GLCanvas3D& canvas, const Vec2d& mouse_pos) const
|
||||
{
|
||||
if (!m_enabled)
|
||||
return false;
|
||||
|
||||
float cnv_h = (float)canvas.get_canvas_size().get_height();
|
||||
float height = get_total_overlay_height();
|
||||
|
||||
#if ENABLE_SVG_ICONS
|
||||
float scaled_icons_size = m_overlay_icons_size * m_overlay_scale;
|
||||
float scaled_border = m_overlay_border * m_overlay_scale;
|
||||
float scaled_gap_y = m_overlay_gap_y * m_overlay_scale;
|
||||
float scaled_stride_y = scaled_icons_size + scaled_gap_y;
|
||||
float top_y = 0.5f * (cnv_h - height) + scaled_border;
|
||||
#else
|
||||
float top_y = 0.5f * (cnv_h - height) + m_overlay_border;
|
||||
float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * m_overlay_icons_scale;
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
|
||||
for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
|
||||
{
|
||||
if ((it->second == nullptr) || !it->second->is_selectable())
|
||||
continue;
|
||||
|
||||
#if ENABLE_SVG_ICONS
|
||||
if ((scaled_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size))
|
||||
#else
|
||||
if ((m_overlay_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= m_overlay_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size))
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
return true;
|
||||
|
||||
#if ENABLE_SVG_ICONS
|
||||
top_y += scaled_stride_y;
|
||||
#else
|
||||
top_y += (scaled_icons_size + m_overlay_gap_y);
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
//bool GLGizmosManager::overlay_contains_mouse(const GLCanvas3D& canvas, const Vec2d& mouse_pos) const
|
||||
//{
|
||||
// if (!m_enabled)
|
||||
// return false;
|
||||
//
|
||||
// float cnv_h = (float)canvas.get_canvas_size().get_height();
|
||||
// float height = get_total_overlay_height();
|
||||
//
|
||||
//#if ENABLE_SVG_ICONS
|
||||
// float scaled_icons_size = m_overlay_icons_size * m_overlay_scale;
|
||||
// float scaled_border = m_overlay_border * m_overlay_scale;
|
||||
// float scaled_gap_y = m_overlay_gap_y * m_overlay_scale;
|
||||
// float scaled_stride_y = scaled_icons_size + scaled_gap_y;
|
||||
// float top_y = 0.5f * (cnv_h - height) + scaled_border;
|
||||
//#else
|
||||
// float top_y = 0.5f * (cnv_h - height) + m_overlay_border;
|
||||
// float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * m_overlay_icons_scale;
|
||||
//#endif // ENABLE_SVG_ICONS
|
||||
//
|
||||
// for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
|
||||
// {
|
||||
// if ((it->second == nullptr) || !it->second->is_selectable())
|
||||
// continue;
|
||||
//
|
||||
//#if ENABLE_SVG_ICONS
|
||||
// if ((scaled_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size))
|
||||
//#else
|
||||
// if ((m_overlay_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= m_overlay_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size))
|
||||
//#endif // ENABLE_SVG_ICONS
|
||||
// return true;
|
||||
//
|
||||
//#if ENABLE_SVG_ICONS
|
||||
// top_y += scaled_stride_y;
|
||||
//#else
|
||||
// top_y += (scaled_icons_size + m_overlay_gap_y);
|
||||
//#endif // ENABLE_SVG_ICONS
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
//}
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
bool GLGizmosManager::grabber_contains_mouse() const
|
||||
{
|
||||
|
@ -614,6 +621,78 @@ void GLGizmosManager::render_overlay(const GLCanvas3D& canvas, const Selection&
|
|||
glsafe(::glPopMatrix());
|
||||
}
|
||||
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
bool GLGizmosManager::on_mouse(wxMouseEvent& evt, GLCanvas3D& canvas)
|
||||
{
|
||||
Vec2d mouse_pos((double)evt.GetX(), (double)evt.GetY());
|
||||
|
||||
std::cout << to_string(mouse_pos) << std::endl;
|
||||
|
||||
|
||||
const Selection& selection = canvas.get_selection();
|
||||
bool processed = false;
|
||||
|
||||
// mouse anywhere
|
||||
if (!evt.Dragging() && !evt.Leaving() && !evt.Entering() && (m_mouse_capture.parent != nullptr))
|
||||
{
|
||||
if (m_mouse_capture.any() && (evt.LeftUp() || evt.MiddleUp() || evt.RightUp()))
|
||||
// prevents loosing selection into the scene if mouse down was done inside the toolbar and mouse up was down outside it
|
||||
processed = true;
|
||||
|
||||
m_mouse_capture.reset();
|
||||
}
|
||||
|
||||
// mouse anywhere
|
||||
if (evt.Moving())
|
||||
m_tooltip = update_hover_state(canvas, mouse_pos);
|
||||
else if (evt.LeftUp())
|
||||
m_mouse_capture.left = false;
|
||||
else if (evt.MiddleUp())
|
||||
m_mouse_capture.middle = false;
|
||||
else if (evt.RightUp())
|
||||
m_mouse_capture.right = false;
|
||||
else if (evt.Dragging() && m_mouse_capture.any())
|
||||
// if the button down was done on this toolbar, prevent from dragging into the scene
|
||||
processed = true;
|
||||
|
||||
if (!overlay_contains_mouse(canvas, mouse_pos))
|
||||
{
|
||||
// mouse is outside the toolbar
|
||||
m_tooltip = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
// mouse inside toolbar
|
||||
if (evt.LeftDown() || evt.LeftDClick())
|
||||
{
|
||||
m_mouse_capture.left = true;
|
||||
m_mouse_capture.parent = &canvas;
|
||||
processed = true;
|
||||
if (!selection.is_empty())
|
||||
{
|
||||
update_on_off_state(canvas, mouse_pos, selection);
|
||||
canvas.update_gizmos_data();
|
||||
canvas.set_as_dirty();
|
||||
}
|
||||
}
|
||||
else if (evt.MiddleDown())
|
||||
{
|
||||
m_mouse_capture.middle = true;
|
||||
m_mouse_capture.parent = &canvas;
|
||||
}
|
||||
else if (evt.RightDown())
|
||||
{
|
||||
m_mouse_capture.right = true;
|
||||
m_mouse_capture.parent = &canvas;
|
||||
}
|
||||
else if (evt.LeftUp())
|
||||
processed = true;
|
||||
}
|
||||
|
||||
return processed;
|
||||
}
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
void GLGizmosManager::reset()
|
||||
{
|
||||
for (GizmosMap::value_type& gizmo : m_gizmos)
|
||||
|
@ -861,5 +940,96 @@ bool GLGizmosManager::generate_icons_texture() const
|
|||
}
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
std::string GLGizmosManager::update_hover_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos)
|
||||
{
|
||||
std::string name = "";
|
||||
|
||||
if (!m_enabled)
|
||||
return name;
|
||||
|
||||
const Selection& selection = canvas.get_selection();
|
||||
|
||||
float cnv_h = (float)canvas.get_canvas_size().get_height();
|
||||
float height = get_total_overlay_height();
|
||||
#if ENABLE_SVG_ICONS
|
||||
float scaled_icons_size = m_overlay_icons_size * m_overlay_scale;
|
||||
float scaled_border = m_overlay_border * m_overlay_scale;
|
||||
float scaled_gap_y = m_overlay_gap_y * m_overlay_scale;
|
||||
float scaled_stride_y = scaled_icons_size + scaled_gap_y;
|
||||
float top_y = 0.5f * (cnv_h - height) + scaled_border;
|
||||
#else
|
||||
float top_y = 0.5f * (cnv_h - height) + m_overlay_border;
|
||||
float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * m_overlay_icons_scale;
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
|
||||
for (GizmosMap::iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
|
||||
{
|
||||
if ((it->second == nullptr) || !it->second->is_selectable())
|
||||
continue;
|
||||
|
||||
#if ENABLE_SVG_ICONS
|
||||
bool inside = (scaled_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size);
|
||||
#else
|
||||
bool inside = (m_overlay_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= m_overlay_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size);
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
if (inside)
|
||||
name = it->second->get_name();
|
||||
|
||||
if (it->second->is_activable(selection) && (it->second->get_state() != GLGizmoBase::On))
|
||||
it->second->set_state(inside ? GLGizmoBase::Hover : GLGizmoBase::Off);
|
||||
|
||||
#if ENABLE_SVG_ICONS
|
||||
top_y += scaled_stride_y;
|
||||
#else
|
||||
top_y += (scaled_icons_size + m_overlay_gap_y);
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
bool GLGizmosManager::overlay_contains_mouse(const GLCanvas3D& canvas, const Vec2d& mouse_pos) const
|
||||
{
|
||||
if (!m_enabled)
|
||||
return false;
|
||||
|
||||
float cnv_h = (float)canvas.get_canvas_size().get_height();
|
||||
float height = get_total_overlay_height();
|
||||
|
||||
#if ENABLE_SVG_ICONS
|
||||
float scaled_icons_size = m_overlay_icons_size * m_overlay_scale;
|
||||
float scaled_border = m_overlay_border * m_overlay_scale;
|
||||
float scaled_gap_y = m_overlay_gap_y * m_overlay_scale;
|
||||
float scaled_stride_y = scaled_icons_size + scaled_gap_y;
|
||||
float top_y = 0.5f * (cnv_h - height) + scaled_border;
|
||||
#else
|
||||
float top_y = 0.5f * (cnv_h - height) + m_overlay_border;
|
||||
float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * m_overlay_icons_scale;
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
|
||||
for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
|
||||
{
|
||||
if ((it->second == nullptr) || !it->second->is_selectable())
|
||||
continue;
|
||||
|
||||
#if ENABLE_SVG_ICONS
|
||||
if ((scaled_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size))
|
||||
#else
|
||||
if ((m_overlay_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= m_overlay_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size))
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
return true;
|
||||
|
||||
#if ENABLE_SVG_ICONS
|
||||
top_y += scaled_stride_y;
|
||||
#else
|
||||
top_y += (scaled_icons_size + m_overlay_gap_y);
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue