From c657654c02a0490734c43dbb682c098652b2e3ac Mon Sep 17 00:00:00 2001 From: Enrico Turri <enricoturri@seznam.cz> Date: Wed, 13 Jun 2018 10:49:59 +0200 Subject: [PATCH] Hovering on gizmo overlay --- xs/src/slic3r/GUI/3DScene.cpp | 2 - xs/src/slic3r/GUI/3DScene.hpp | 2 - xs/src/slic3r/GUI/GLCanvas3D.cpp | 227 +++++------------------- xs/src/slic3r/GUI/GLCanvas3D.hpp | 55 +----- xs/src/slic3r/GUI/GLCanvas3DManager.cpp | 4 +- xs/src/slic3r/GUI/GLCanvas3DManager.hpp | 2 - xs/src/slic3r/GUI/GLGizmo.cpp | 12 +- xs/src/slic3r/GUI/GLGizmo.hpp | 6 +- 8 files changed, 61 insertions(+), 249 deletions(-) diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 3770ad0e6..34d066730 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1903,12 +1903,10 @@ void _3DScene::enable_moving(wxGLCanvas* canvas, bool enable) s_canvas_mgr.enable_moving(canvas, enable); } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void _3DScene::enable_gizmos(wxGLCanvas* canvas, bool enable) { s_canvas_mgr.enable_gizmos(canvas, enable); } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void _3DScene::enable_shader(wxGLCanvas* canvas, bool enable) { diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index ad2b8d5c5..26b9911e0 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -557,9 +557,7 @@ public: static void enable_legend_texture(wxGLCanvas* canvas, bool enable); static void enable_picking(wxGLCanvas* canvas, bool enable); static void enable_moving(wxGLCanvas* canvas, bool enable); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ static void enable_gizmos(wxGLCanvas* canvas, bool enable); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ static void enable_shader(wxGLCanvas* canvas, bool enable); static void enable_force_zoom_to_bed(wxGLCanvas* canvas, bool enable); static void allow_multisample(wxGLCanvas* canvas, bool allow); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index e4420cf0c..9ad7afeb8 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -4,9 +4,7 @@ #include "../../slic3r/GUI/GLShader.hpp" #include "../../slic3r/GUI/GUI.hpp" #include "../../slic3r/GUI/PresetBundle.hpp" -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #include "../../slic3r/GUI/GLGizmo.hpp" -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #include "../../libslic3r/ClipperUtils.hpp" #include "../../libslic3r/PrintConfig.hpp" #include "../../libslic3r/Print.hpp" @@ -15,9 +13,6 @@ #include <GL/glew.h> #include <wx/glcanvas.h> -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -//#include <wx/image.h> -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #include <wx/timer.h> #include <tbb/parallel_for.h> @@ -28,9 +23,7 @@ #include <iostream> #include <float.h> -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #include <algorithm> -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ static const float TRACKBALLSIZE = 0.8f; static const float GIMBALL_LOCK_THETA_MAX = 180.0f; @@ -245,108 +238,6 @@ void Rect::set_bottom(float bottom) m_bottom = bottom; } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -//GLCanvas3D::GLTextureData::GLTextureData() -// : m_id(0) -// , m_width(0) -// , m_height(0) -// , m_source("") -//{ -//} -// -//GLCanvas3D::GLTextureData::~GLTextureData() -//{ -// reset(); -//} -// -//bool GLCanvas3D::GLTextureData::load_from_file(const std::string& filename) -//{ -// reset(); -// -// // Load a PNG with an alpha channel. -// wxImage image; -// if (!image.LoadFile(filename, wxBITMAP_TYPE_PNG)) -// { -// reset(); -// return false; -// } -// -// m_width = image.GetWidth(); -// m_height = image.GetHeight(); -// int n_pixels = m_width * m_height; -// -// if (n_pixels <= 0) -// { -// reset(); -// return false; -// } -// -// // Get RGB & alpha raw data from wxImage, pack them into an array. -// unsigned char* img_rgb = image.GetData(); -// if (img_rgb == nullptr) -// { -// reset(); -// return false; -// } -// -// unsigned char* img_alpha = image.GetAlpha(); -// -// std::vector<unsigned char> data(n_pixels * 4, 0); -// for (int i = 0; i < n_pixels; ++i) -// { -// int data_id = i * 4; -// int img_id = i * 3; -// data[data_id + 0] = img_rgb[img_id + 0]; -// data[data_id + 1] = img_rgb[img_id + 1]; -// data[data_id + 2] = img_rgb[img_id + 2]; -// data[data_id + 3] = (img_alpha != nullptr) ? img_alpha[i] : 255; -// } -// -// // sends data to gpu -// ::glGenTextures(1, &m_id); -// ::glBindTexture(GL_TEXTURE_2D, m_id); -// ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); -// ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); -// ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); -// ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()); -// ::glBindTexture(GL_TEXTURE_2D, 0); -// -// m_source = filename; -// return true; -//} -// -//void GLCanvas3D::GLTextureData::reset() -//{ -// if (m_id != 0) -// ::glDeleteTextures(1, &m_id); -// -// m_id = 0; -// m_width = 0; -// m_height = 0; -// m_source = ""; -//} -// -//unsigned int GLCanvas3D::GLTextureData::get_id() const -//{ -// return m_id; -//} -// -//int GLCanvas3D::GLTextureData::get_width() const -//{ -// return m_width; -//} -// -//int GLCanvas3D::GLTextureData::get_height() const -//{ -// return m_height; -//} -// -//const std::string& GLCanvas3D::GLTextureData::get_source() const -//{ -// return m_source; -//} -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - GLCanvas3D::Camera::Camera() : type(Ortho) , zoom(1.0f) @@ -918,10 +809,7 @@ void GLCanvas3D::LayersEditing::render(const GLCanvas3D& canvas, const PrintObje ::glLoadIdentity(); _render_tooltip_texture(canvas, bar_rect, reset_rect); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ _render_reset_texture(reset_rect); -// _render_reset_texture(canvas, reset_rect); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ _render_active_object_annotations(canvas, volume, print_object, bar_rect); _render_profile(print_object, bar_rect); @@ -1049,16 +937,10 @@ void GLCanvas3D::LayersEditing::_render_tooltip_texture(const GLCanvas3D& canvas float t = reset_bottom + (float)m_tooltip_texture.get_height() * inv_zoom + gap; float b = reset_bottom + gap; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GLTexture::render_texture(m_tooltip_texture.get_id(), l, r, b, t); -// canvas.render_texture(m_tooltip_texture.get_id(), l, r, b, t); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void GLCanvas3D::LayersEditing::_render_reset_texture(const Rect& reset_rect) const -//void GLCanvas3D::LayersEditing::_render_reset_texture(const GLCanvas3D& canvas, const Rect& reset_rect) const -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ { if (m_reset_texture.get_id() == 0) { @@ -1067,10 +949,7 @@ void GLCanvas3D::LayersEditing::_render_reset_texture(const Rect& reset_rect) co return; } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GLTexture::render_texture(m_reset_texture.get_id(), reset_rect.get_left(), reset_rect.get_right(), reset_rect.get_bottom(), reset_rect.get_top()); -// canvas.render_texture(m_reset_texture.get_id(), reset_rect.get_left(), reset_rect.get_right(), reset_rect.get_bottom(), reset_rect.get_top()); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ } void GLCanvas3D::LayersEditing::_render_active_object_annotations(const GLCanvas3D& canvas, const GLVolume& volume, const PrintObject& print_object, const Rect& bar_rect) const @@ -1203,7 +1082,6 @@ bool GLCanvas3D::Mouse::is_start_position_3D_defined() const return (drag.start_position_3D != Drag::Invalid_3D_Point); } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ const float GLCanvas3D::Gizmos::OverlayOffsetX = 10.0f; const float GLCanvas3D::Gizmos::OverlayGapY = 10.0f; @@ -1268,6 +1146,29 @@ void GLCanvas3D::Gizmos::reset_selection() m_current = Undefined; } +void GLCanvas3D::Gizmos::update_hover_state(const GLCanvas3D& canvas, const Pointf& mouse_pos) +{ + if (!m_enabled) + return; + + float cnv_h = (float)canvas.get_canvas_size().get_height(); + float height = _get_total_overlay_height(); + float top_y = 0.5f * (cnv_h - height); + for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) + { + if ((it->second == nullptr) || (it->second->get_state() == GLGizmoBase::On)) + continue; + + float tex_size = (float)it->second->get_textures_size(); + float half_tex_size = 0.5f * tex_size; + + // we currently use circular icons for gizmo, so we check the radius + bool inside = length(Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size).vector_to(mouse_pos)) < half_tex_size; + it->second->set_state(inside ? GLGizmoBase::Hover : GLGizmoBase::Off); + top_y += (tex_size + OverlayGapY); + } +} + void GLCanvas3D::Gizmos::render(const GLCanvas3D& canvas) const { if (!m_enabled) @@ -1300,30 +1201,19 @@ void GLCanvas3D::Gizmos::_render_overlay(const GLCanvas3D& canvas) const if (m_gizmos.empty()) return; - const Size& cnv_size = canvas.get_canvas_size(); - - float cnv_w = (float)cnv_size.get_width(); - + float cnv_w = (float)canvas.get_canvas_size().get_width(); float zoom = canvas.get_camera_zoom(); float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; - float total_h = 0.0f; - for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) - { - total_h += (float)it->second->get_textures_height(); - if (std::distance(it, m_gizmos.end()) > 1) - total_h += OverlayGapY; - } - + float height = _get_total_overlay_height(); float top_x = (OverlayOffsetX - 0.5f * cnv_w) * inv_zoom; - float top_y = 0.5f * total_h * inv_zoom; + float top_y = 0.5f * height * inv_zoom; float scaled_gap_y = OverlayGapY * inv_zoom; for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) { - float tex_w = (float)it->second->get_textures_width() * inv_zoom; - float tex_h = (float)it->second->get_textures_height() * inv_zoom; - GLTexture::render_texture(it->second->get_textures_id(), top_x, top_x + tex_w, top_y - tex_h, top_y); - top_y -= (tex_h + scaled_gap_y); + float tex_size = (float)it->second->get_textures_size() * inv_zoom; + GLTexture::render_texture(it->second->get_textures_id(), top_x, top_x + tex_size, top_y - tex_size, top_y); + top_y -= (tex_size + scaled_gap_y); } } @@ -1335,7 +1225,19 @@ void GLCanvas3D::Gizmos::_render_current_gizmo() const it->second->render(); } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + +float GLCanvas3D::Gizmos::_get_total_overlay_height() const +{ + float height = 0.0f; + for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) + { + height += (float)it->second->get_textures_size(); + if (std::distance(it, m_gizmos.end()) > 1) + height += OverlayGapY; + } + + return height; +} GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context) : m_canvas(canvas) @@ -1441,10 +1343,8 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl) if (!m_volumes.empty()) m_volumes.finalize_geometry(m_use_VBOs); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ if (m_gizmos.is_enabled() && !m_gizmos.init()) return false; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ m_initialized = true; @@ -1687,12 +1587,10 @@ void GLCanvas3D::enable_moving(bool enable) m_moving_enabled = enable; } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void GLCanvas3D::enable_gizmos(bool enable) { m_gizmos.set_enabled(enable); } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void GLCanvas3D::enable_shader(bool enable) { @@ -1811,40 +1709,11 @@ void GLCanvas3D::render() _render_warning_texture(); _render_legend_texture(); _render_layer_editing_overlay(); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ _render_gizmo(); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ m_canvas->SwapBuffers(); } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -//void GLCanvas3D::render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const -//{ -// ::glColor4f(1.0f, 1.0f, 1.0f, 1.0f); -// -// ::glDisable(GL_LIGHTING); -// ::glEnable(GL_BLEND); -// ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -// ::glEnable(GL_TEXTURE_2D); -// -// ::glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id); -// -// ::glBegin(GL_QUADS); -// ::glTexCoord2d(0.0f, 1.0f); ::glVertex3f(left, bottom, 0.0f); -// ::glTexCoord2d(1.0f, 1.0f); ::glVertex3f(right, bottom, 0.0f); -// ::glTexCoord2d(1.0f, 0.0f); ::glVertex3f(right, top, 0.0f); -// ::glTexCoord2d(0.0f, 0.0f); ::glVertex3f(left, top, 0.0f); -// ::glEnd(); -// -// ::glBindTexture(GL_TEXTURE_2D, 0); -// -// ::glDisable(GL_TEXTURE_2D); -// ::glDisable(GL_BLEND); -// ::glEnable(GL_LIGHTING); -//} -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - std::vector<double> GLCanvas3D::get_current_print_zs(bool active_only) const { return m_volumes.get_current_print_zs(active_only); @@ -3179,6 +3048,10 @@ void GLCanvas3D::_picking_pass() const } } } + + // updates gizmos overlay + if (!m_volumes.empty()) + m_gizmos.update_hover_state(*this, pos); } } @@ -3301,10 +3174,7 @@ void GLCanvas3D::_render_warning_texture() const float r = l + (float)w * inv_zoom; float b = t - (float)h * inv_zoom; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GLTexture::render_texture(tex_id, l, r, b, t); -// render_texture(tex_id, l, r, b, t); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ::glPopMatrix(); ::glEnable(GL_DEPTH_TEST); @@ -3336,10 +3206,7 @@ void GLCanvas3D::_render_legend_texture() const float t = (0.5f * (float)cnv_size.get_height()) * inv_zoom; float r = l + (float)w * inv_zoom; float b = t - (float)h * inv_zoom; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GLTexture::render_texture(tex_id, l, r, b, t); -// render_texture(tex_id, l, r, b, t); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ::glPopMatrix(); ::glEnable(GL_DEPTH_TEST); @@ -3425,12 +3292,10 @@ void GLCanvas3D::_render_volumes(bool fake_colors) const ::glEnable(GL_CULL_FACE); } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void GLCanvas3D::_render_gizmo() const { m_gizmos.render(*this); } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ float GLCanvas3D::_get_layers_editing_cursor_z_relative() const { diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 74c95ca74..2852d82d1 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -2,9 +2,7 @@ #define slic3r_GLCanvas3D_hpp_ #include "../../slic3r/GUI/3DScene.hpp" -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #include "../../slic3r/GUI/GLTexture.hpp" -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ class wxTimer; class wxSizeEvent; @@ -21,9 +19,7 @@ class ExPolygon; namespace GUI { -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ class GLGizmoBase; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ class GeometryBuffer { @@ -109,29 +105,6 @@ class GLCanvas3D void reset() { first_volumes.clear(); } }; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -// struct GLTextureData -// { -// private: -// unsigned int m_id; -// int m_width; -// int m_height; -// std::string m_source; -// -// public: -// GLTextureData(); -// ~GLTextureData(); -// -// bool load_from_file(const std::string& filename); -// void reset(); -// -// unsigned int get_id() const; -// int get_width() const; -// int get_height() const; -// const std::string& get_source() const; -// }; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - public: struct Camera { @@ -179,12 +152,8 @@ public: Polygon m_polygon; GeometryBuffer m_triangles; GeometryBuffer m_gridlines; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ mutable GLTexture m_top_texture; mutable GLTexture m_bottom_texture; -// mutable GLTextureData m_top_texture; -// mutable GLTextureData m_bottom_texture; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ public: Bed(); @@ -279,12 +248,8 @@ public: bool m_enabled; Shader m_shader; unsigned int m_z_texture_id; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ mutable GLTexture m_tooltip_texture; mutable GLTexture m_reset_texture; -// mutable GLTextureData m_tooltip_texture; -// mutable GLTextureData m_reset_texture; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ public: EState state; @@ -323,10 +288,7 @@ public: private: bool _is_initialized() const; void _render_tooltip_texture(const GLCanvas3D& canvas, const Rect& bar_rect, const Rect& reset_rect) const; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void _render_reset_texture(const Rect& reset_rect) const; -// void _render_reset_texture(const GLCanvas3D& canvas, const Rect& reset_rect) const; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void _render_active_object_annotations(const GLCanvas3D& canvas, const GLVolume& volume, const PrintObject& print_object, const Rect& bar_rect) const; void _render_profile(const PrintObject& print_object, const Rect& bar_rect) const; }; @@ -360,7 +322,6 @@ public: bool is_start_position_3D_defined() const; }; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ class Gizmos { static const float OverlayOffsetX; @@ -393,6 +354,8 @@ public: void select(EType type); void reset_selection(); + void update_hover_state(const GLCanvas3D& canvas, const Pointf& mouse_pos); + void render(const GLCanvas3D& canvas) const; private: @@ -400,8 +363,9 @@ public: void _render_overlay(const GLCanvas3D& canvas) const; void _render_current_gizmo() const; + + float _get_total_overlay_height() const; }; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ private: wxGLCanvas* m_canvas; @@ -414,9 +378,7 @@ private: LayersEditing m_layers_editing; Shader m_shader; Mouse m_mouse; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - Gizmos m_gizmos; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + mutable Gizmos m_gizmos; mutable GLVolumeCollection m_volumes; DynamicPrintConfig* m_config; @@ -521,9 +483,7 @@ public: void enable_legend_texture(bool enable); void enable_picking(bool enable); void enable_moving(bool enable); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void enable_gizmos(bool enable); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void enable_shader(bool enable); void enable_force_zoom_to_bed(bool enable); void allow_multisample(bool allow); @@ -536,9 +496,6 @@ public: void update_volumes_colors_by_extruder(); void render(); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -// void render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ std::vector<double> get_current_print_zs(bool active_only) const; void set_toolpaths_range(double low, double high); @@ -617,9 +574,7 @@ private: void _render_legend_texture() const; void _render_layer_editing_overlay() const; void _render_volumes(bool fake_colors) const; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void _render_gizmo() const; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ float _get_layers_editing_cursor_z_relative() const; int _get_layers_editing_first_selected_object_id(unsigned int objects_count) const; diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index 8a84d4cb5..97af89fb7 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -107,7 +107,7 @@ std::string GLCanvas3DManager::GLInfo::to_string(bool format_as_html, bool exten GLint num_extensions; ::glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions); - for (unsigned int i = 0; i < num_extensions; ++i) + for (GLint i = 0; i < num_extensions; ++i) { const char* e = (const char*)::glGetStringi(GL_EXTENSIONS, i); extensions_list.push_back(e); @@ -427,14 +427,12 @@ void GLCanvas3DManager::enable_moving(wxGLCanvas* canvas, bool enable) it->second->enable_moving(enable); } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void GLCanvas3DManager::enable_gizmos(wxGLCanvas* canvas, bool enable) { CanvasesMap::iterator it = _get_canvas(canvas); if (it != m_canvases.end()) it->second->enable_gizmos(enable); } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void GLCanvas3DManager::enable_shader(wxGLCanvas* canvas, bool enable) { diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp index 9ec645c1a..95bd2af80 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -110,9 +110,7 @@ public: void enable_legend_texture(wxGLCanvas* canvas, bool enable); void enable_picking(wxGLCanvas* canvas, bool enable); void enable_moving(wxGLCanvas* canvas, bool enable); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void enable_gizmos(wxGLCanvas* canvas, bool enable); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void enable_shader(wxGLCanvas* canvas, bool enable); void enable_force_zoom_to_bed(wxGLCanvas* canvas, bool enable); void allow_multisample(wxGLCanvas* canvas, bool allow); diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index 172720390..b4237e162 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -21,17 +21,17 @@ GLGizmoBase::EState GLGizmoBase::get_state() const return m_state; } +void GLGizmoBase::set_state(GLGizmoBase::EState state) +{ + m_state = state; +} + unsigned int GLGizmoBase::get_textures_id() const { return m_textures[m_state].get_id(); } -int GLGizmoBase::get_textures_height() const -{ - return m_textures[Off].get_height(); -} - -int GLGizmoBase::get_textures_width() const +int GLGizmoBase::get_textures_size() const { return m_textures[Off].get_width(); } diff --git a/xs/src/slic3r/GUI/GLGizmo.hpp b/xs/src/slic3r/GUI/GLGizmo.hpp index 1da216ba9..3ca8e3213 100644 --- a/xs/src/slic3r/GUI/GLGizmo.hpp +++ b/xs/src/slic3r/GUI/GLGizmo.hpp @@ -19,7 +19,7 @@ public: protected: EState m_state; - // textures are assumed to be all the same size in pixels + // textures are assumed to be square and all with the same size in pixels // no internal check is done GLTexture m_textures[Num_States]; @@ -30,10 +30,10 @@ public: bool init(); EState get_state() const; + void set_state(EState state); unsigned int get_textures_id() const; - int get_textures_height() const; - int get_textures_width() const; + int get_textures_size() const; virtual void render() const = 0;