diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index f60fead3dc..f82dc262fa 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -1509,9 +1509,7 @@ bool GLCanvas3D::WarningTexture::generate(const std::string& msg) //############################################################################################################################################ int pow_of_two_size = next_highest_power_of_2((int)std::max(w, h)); -//############################################################################################################################################ -//############################################################################################################################################ m_original_width = (int)w; m_original_height = (int)h; m_width = pow_of_two_size; @@ -1573,7 +1571,7 @@ bool GLCanvas3D::WarningTexture::generate(const std::string& msg) //############################################################################################################################################ void GLCanvas3D::WarningTexture::render(const GLCanvas3D& canvas) const { - if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0)) + if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0)) { ::glDisable(GL_DEPTH_TEST); ::glPushMatrix(); @@ -1610,6 +1608,25 @@ const unsigned char GLCanvas3D::LegendTexture::Squares_Border_Color[3] = { 64, 6 const unsigned char GLCanvas3D::LegendTexture::Background_Color[3] = { 9, 91, 134 }; const unsigned char GLCanvas3D::LegendTexture::Opacity = 255; +//############################################################################################################################################ +GLCanvas3D::LegendTexture::LegendTexture() + : GUI::GLTexture() + , m_original_width(0) + , m_original_height(0) +{ +} + +int GLCanvas3D::LegendTexture::get_original_width() const +{ + return m_original_width; +} + +int GLCanvas3D::LegendTexture::get_original_height() const +{ + return m_original_height; +} +//############################################################################################################################################ + bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector& tool_colors) { reset(); @@ -1642,10 +1659,22 @@ bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, c max_text_height = std::max(max_text_height, (int)h); } - m_width = std::max(2 * Px_Border + title_width, 2 * (Px_Border + Px_Square_Contour) + Px_Square + Px_Text_Offset + max_text_width); - m_height = 2 * (Px_Border + Px_Square_Contour) + title_height + Px_Title_Offset + items_count * Px_Square; +//############################################################################################################################################ + m_original_width = std::max(2 * Px_Border + title_width, 2 * (Px_Border + Px_Square_Contour) + Px_Square + Px_Text_Offset + max_text_width); + m_original_height = 2 * (Px_Border + Px_Square_Contour) + title_height + Px_Title_Offset + items_count * Px_Square; if (items_count > 1) - m_height += (items_count - 1) * Px_Square_Contour; + m_original_height += (items_count - 1) * Px_Square_Contour; + + int pow_of_two_size = next_highest_power_of_2(std::max(m_original_width, m_original_height)); + + m_width = pow_of_two_size; + m_height = pow_of_two_size; + +// m_width = std::max(2 * Px_Border + title_width, 2 * (Px_Border + Px_Square_Contour) + Px_Square + Px_Text_Offset + max_text_width); +// m_height = 2 * (Px_Border + Px_Square_Contour) + title_height + Px_Title_Offset + items_count * Px_Square; +// if (items_count > 1) +// m_height += (items_count - 1) * Px_Square_Contour; +//############################################################################################################################################ // generates bitmap wxBitmap bitmap(m_width, m_height); @@ -1754,6 +1783,42 @@ bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, c return true; } +//############################################################################################################################################ +void GLCanvas3D::LegendTexture::render(const GLCanvas3D& canvas) const +{ + if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0)) + { + ::glDisable(GL_DEPTH_TEST); + ::glPushMatrix(); + ::glLoadIdentity(); + + const Size& cnv_size = canvas.get_canvas_size(); + float zoom = canvas.get_camera_zoom(); + float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; + float left = (-0.5f * (float)cnv_size.get_width()) * inv_zoom; + float top = (0.5f * (float)cnv_size.get_height()) * inv_zoom; + float right = left + (float)m_original_width * inv_zoom; + float bottom = top - (float)m_original_height * inv_zoom; + + float uv_left = 0.0f; + float uv_top = 0.0f; + float uv_right = (float)m_original_width / (float)m_width; + float uv_bottom = (float)m_original_height / (float)m_height; + + GLTexture::Quad_UVs uvs; + uvs.left_top = { uv_left, uv_top }; + uvs.left_bottom = { uv_left, uv_bottom }; + uvs.right_bottom = { uv_right, uv_bottom }; + uvs.right_top = { uv_right, uv_top }; + + GLTexture::render_sub_texture(m_id, left, right, bottom, top, uvs); + + ::glPopMatrix(); + ::glEnable(GL_DEPTH_TEST); + } +} +//############################################################################################################################################ + GLGizmoBase* GLCanvas3D::Gizmos::_get_current() const { GizmosMap::const_iterator it = m_gizmos.find(m_current); @@ -3988,32 +4053,36 @@ void GLCanvas3D::_render_legend_texture() const if (!m_legend_texture_enabled) return; - // If the legend texture has not been loaded into the GPU, do it now. - unsigned int tex_id = m_legend_texture.get_id(); - if (tex_id > 0) - { - int w = m_legend_texture.get_width(); - int h = m_legend_texture.get_height(); - if ((w > 0) && (h > 0)) - { - ::glDisable(GL_DEPTH_TEST); - ::glPushMatrix(); - ::glLoadIdentity(); +//############################################################################################################################################ + m_legend_texture.render(*this); - const Size& cnv_size = get_canvas_size(); - float zoom = get_camera_zoom(); - float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; - float l = (-0.5f * (float)cnv_size.get_width()) * inv_zoom; - 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); - - ::glPopMatrix(); - ::glEnable(GL_DEPTH_TEST); - } - } +// // If the legend texture has not been loaded into the GPU, do it now. +// unsigned int tex_id = m_legend_texture.get_id(); +// if (tex_id > 0) +// { +// int w = m_legend_texture.get_width(); +// int h = m_legend_texture.get_height(); +// if ((w > 0) && (h > 0)) +// { +// ::glDisable(GL_DEPTH_TEST); +// ::glPushMatrix(); +// ::glLoadIdentity(); +// +// const Size& cnv_size = get_canvas_size(); +// float zoom = get_camera_zoom(); +// float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; +// float l = (-0.5f * (float)cnv_size.get_width()) * inv_zoom; +// 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); +// +// ::glPopMatrix(); +// ::glEnable(GL_DEPTH_TEST); +// } +// } +//############################################################################################################################################ } void GLCanvas3D::_render_layer_editing_overlay() const diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 51aaca1071..97b44ca929 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -433,8 +433,24 @@ public: static const unsigned char Background_Color[3]; static const unsigned char Opacity; +//############################################################################################################################################ + int m_original_width; + int m_original_height; +//############################################################################################################################################ + public: +//############################################################################################################################################ + LegendTexture(); + + int get_original_width() const; + int get_original_height() const; +//############################################################################################################################################ + bool generate(const GCodePreviewData& preview_data, const std::vector& tool_colors); + +//############################################################################################################################################ + void render(const GLCanvas3D& canvas) const; +//############################################################################################################################################ }; private: