diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 9fc1d1e3a..c7c18bb8a 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3146,7 +3146,10 @@ void GLCanvas3D::Gizmos::do_render_overlay(const GLCanvas3D& canvas, const GLCan float scaled_icons_size = m_overlay_icons_size * m_overlay_scale * inv_zoom; float scaled_stride_y = scaled_icons_size + scaled_gap_y; unsigned int icons_texture_id = m_icons_texture.get_id(); - unsigned int texture_size = m_icons_texture.get_width(); + unsigned int tex_width = m_icons_texture.get_width(); + unsigned int tex_height = m_icons_texture.get_height(); + float inv_tex_width = (tex_width != 0) ? 1.0f / (float)tex_width : 0.0f; + float inv_tex_height = (tex_height != 0) ? 1.0f / (float)tex_height : 0.0f; #else top_x += m_overlay_border * inv_zoom; top_y -= m_overlay_border * inv_zoom; @@ -3155,11 +3158,11 @@ void GLCanvas3D::Gizmos::do_render_overlay(const GLCanvas3D& canvas, const GLCan float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * m_overlay_icons_scale * inv_zoom; unsigned int icons_texture_id = m_icons_texture.texture.get_id(); unsigned int texture_size = m_icons_texture.texture.get_width(); -#endif // ENABLE_SVG_ICONS float inv_texture_size = (texture_size != 0) ? 1.0f / (float)texture_size : 0.0f; +#endif // ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS - if ((icons_texture_id == 0) || (texture_size <= 0)) + if ((icons_texture_id == 0) || (tex_width <= 0) || (tex_height <= 0)) return; #endif // ENABLE_SVG_ICONS @@ -3172,14 +3175,19 @@ void GLCanvas3D::Gizmos::do_render_overlay(const GLCanvas3D& canvas, const GLCan GLGizmoBase::EState state = it->second->get_state(); #if ENABLE_SVG_ICONS - float uv_icon_size = m_overlay_icons_size * inv_texture_size; + float u_icon_size = m_overlay_icons_size * inv_tex_width; + float v_icon_size = m_overlay_icons_size * inv_tex_height; + float top = sprite_id * v_icon_size; + float left = state * u_icon_size; + float bottom = top + v_icon_size; + float right = left + u_icon_size; #else float uv_icon_size = (float)m_icons_texture.metadata.icon_size * inv_texture_size; -#endif // ENABLE_SVG_ICONS float top = sprite_id * uv_icon_size; float left = state * uv_icon_size; float bottom = top + uv_icon_size; float right = left + uv_icon_size; +#endif // ENABLE_SVG_ICONS GLTexture::render_sub_texture(icons_texture_id, top_x, top_x + scaled_icons_size, top_y - scaled_icons_size, top_y, { { left, bottom }, { right, bottom }, { right, top }, { left, top } }); #if ENABLE_IMGUI @@ -3262,9 +3270,9 @@ bool GLCanvas3D::Gizmos::generate_icons_texture() const { if (it->second != nullptr) { - const std::string& svg_file = it->second->get_svg_file(); - if (!svg_file.empty()) - filenames.push_back(path + svg_file); + const std::string& icon_filename = it->second->get_icon_filename(); + if (!icon_filename.empty()) + filenames.push_back(path + icon_filename); } } @@ -5901,7 +5909,7 @@ bool GLCanvas3D::_init_toolbar() item.name = "add"; #if ENABLE_SVG_ICONS - item.svg_file = "add.svg"; + item.icon_filename = "add.svg"; #endif // ENABLE_SVG_ICONS item.tooltip = GUI::L_str("Add...") + " [" + GUI::shortkey_ctrl_prefix() + "I]"; item.sprite_id = 0; @@ -5911,7 +5919,7 @@ bool GLCanvas3D::_init_toolbar() item.name = "delete"; #if ENABLE_SVG_ICONS - item.svg_file = "remove.svg"; + item.icon_filename = "remove.svg"; #endif // ENABLE_SVG_ICONS item.tooltip = GUI::L_str("Delete") + " [Del]"; item.sprite_id = 1; @@ -5921,7 +5929,7 @@ bool GLCanvas3D::_init_toolbar() item.name = "deleteall"; #if ENABLE_SVG_ICONS - item.svg_file = "delete_all.svg"; + item.icon_filename = "delete_all.svg"; #endif // ENABLE_SVG_ICONS item.tooltip = GUI::L_str("Delete all") + " [" + GUI::shortkey_ctrl_prefix() + "Del]"; item.sprite_id = 2; @@ -5931,7 +5939,7 @@ bool GLCanvas3D::_init_toolbar() item.name = "arrange"; #if ENABLE_SVG_ICONS - item.svg_file = "arrange.svg"; + item.icon_filename = "arrange.svg"; #endif // ENABLE_SVG_ICONS item.tooltip = GUI::L_str("Arrange [A]"); item.sprite_id = 3; @@ -5944,7 +5952,7 @@ bool GLCanvas3D::_init_toolbar() item.name = "more"; #if ENABLE_SVG_ICONS - item.svg_file = "instance_add.svg"; + item.icon_filename = "instance_add.svg"; #endif // ENABLE_SVG_ICONS item.tooltip = GUI::L_str("Add instance [+]"); item.sprite_id = 4; @@ -5954,7 +5962,7 @@ bool GLCanvas3D::_init_toolbar() item.name = "fewer"; #if ENABLE_SVG_ICONS - item.svg_file = "instance_remove.svg"; + item.icon_filename = "instance_remove.svg"; #endif // ENABLE_SVG_ICONS item.tooltip = GUI::L_str("Remove instance [-]"); item.sprite_id = 5; @@ -5967,7 +5975,7 @@ bool GLCanvas3D::_init_toolbar() item.name = "splitobjects"; #if ENABLE_SVG_ICONS - item.svg_file = "split_objects.svg"; + item.icon_filename = "split_objects.svg"; #endif // ENABLE_SVG_ICONS item.tooltip = GUI::L_str("Split to objects"); item.sprite_id = 6; @@ -5977,7 +5985,7 @@ bool GLCanvas3D::_init_toolbar() item.name = "splitvolumes"; #if ENABLE_SVG_ICONS - item.svg_file = "split_parts.svg"; + item.icon_filename = "split_parts.svg"; #endif // ENABLE_SVG_ICONS item.tooltip = GUI::L_str("Split to parts"); item.sprite_id = 8; @@ -5990,7 +5998,7 @@ bool GLCanvas3D::_init_toolbar() item.name = "layersediting"; #if ENABLE_SVG_ICONS - item.svg_file = "layers.svg"; + item.icon_filename = "layers.svg"; #endif // ENABLE_SVG_ICONS item.tooltip = GUI::L_str("Layers editing"); item.sprite_id = 7; diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index b7573410b..b9018d0a1 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -158,7 +158,7 @@ void GLGizmoBase::Grabber::render_face(float half_size) const } #if ENABLE_SVG_ICONS -GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id) +GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) #else GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, unsigned int sprite_id) #endif // ENABLE_SVG_ICONS @@ -167,7 +167,7 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, unsigned int sprite_id) , m_state(Off) , m_shortcut_key(0) #if ENABLE_SVG_ICONS - , m_svg_file(svg_file) + , m_icon_filename(icon_filename) #endif // ENABLE_SVG_ICONS , m_sprite_id(sprite_id) , m_hover_id(-1) @@ -334,7 +334,7 @@ GLGizmoRotate::GLGizmoRotate(GLCanvas3D& parent, GLGizmoRotate::Axis axis) GLGizmoRotate::GLGizmoRotate(const GLGizmoRotate& other) #if ENABLE_SVG_ICONS - : GLGizmoBase(other.m_parent, other.m_svg_file, other.m_sprite_id) + : GLGizmoBase(other.m_parent, other.m_icon_filename, other.m_sprite_id) #else : GLGizmoBase(other.m_parent, other.m_sprite_id) #endif // ENABLE_SVG_ICONS @@ -710,8 +710,8 @@ Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, cons } #if ENABLE_SVG_ICONS -GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id) - : GLGizmoBase(parent, svg_file, sprite_id) +GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) + : GLGizmoBase(parent, icon_filename, sprite_id) #else GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent, unsigned int sprite_id) : GLGizmoBase(parent, sprite_id) @@ -795,8 +795,8 @@ void GLGizmoRotate3D::on_render_input_window(float x, float y, const GLCanvas3D: const float GLGizmoScale3D::Offset = 5.0f; #if ENABLE_SVG_ICONS -GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id) - : GLGizmoBase(parent, svg_file, sprite_id) +GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) + : GLGizmoBase(parent, icon_filename, sprite_id) #else GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, unsigned int sprite_id) : GLGizmoBase(parent, sprite_id) @@ -1146,8 +1146,8 @@ double GLGizmoScale3D::calc_ratio(const UpdateData& data) const const double GLGizmoMove3D::Offset = 10.0; #if ENABLE_SVG_ICONS -GLGizmoMove3D::GLGizmoMove3D(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id) - : GLGizmoBase(parent, svg_file, sprite_id) +GLGizmoMove3D::GLGizmoMove3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) + : GLGizmoBase(parent, icon_filename, sprite_id) #else GLGizmoMove3D::GLGizmoMove3D(GLCanvas3D& parent, unsigned int sprite_id) : GLGizmoBase(parent, sprite_id) @@ -1388,8 +1388,8 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box } #if ENABLE_SVG_ICONS -GLGizmoFlatten::GLGizmoFlatten(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id) - : GLGizmoBase(parent, svg_file, sprite_id) +GLGizmoFlatten::GLGizmoFlatten(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) + : GLGizmoBase(parent, icon_filename, sprite_id) #else GLGizmoFlatten::GLGizmoFlatten(GLCanvas3D& parent, unsigned int sprite_id) : GLGizmoBase(parent, sprite_id) @@ -1732,8 +1732,8 @@ Vec3d GLGizmoFlatten::get_flattening_normal() const } #if ENABLE_SVG_ICONS -GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id) - : GLGizmoBase(parent, svg_file, sprite_id) +GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) + : GLGizmoBase(parent, icon_filename, sprite_id) #else GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent, unsigned int sprite_id) : GLGizmoBase(parent, sprite_id) @@ -2550,8 +2550,8 @@ const double GLGizmoCut::Margin = 20.0; const std::array GLGizmoCut::GrabberColor = { 1.0, 0.5, 0.0 }; #if ENABLE_SVG_ICONS -GLGizmoCut::GLGizmoCut(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id) - : GLGizmoBase(parent, svg_file, sprite_id) +GLGizmoCut::GLGizmoCut(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) + : GLGizmoBase(parent, icon_filename, sprite_id) #else GLGizmoCut::GLGizmoCut(GLCanvas3D& parent, unsigned int sprite_id) : GLGizmoBase(parent, sprite_id) diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index dc632fe80..e524c2381 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -88,7 +88,7 @@ protected: EState m_state; int m_shortcut_key; #if ENABLE_SVG_ICONS - std::string m_svg_file; + std::string m_icon_filename; #endif // ENABLE_SVG_ICONS unsigned int m_sprite_id; int m_hover_id; @@ -103,7 +103,7 @@ protected: public: #if ENABLE_SVG_ICONS - GLGizmoBase(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id); + GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); #else GLGizmoBase(GLCanvas3D& parent, unsigned int sprite_id); #endif // ENABLE_SVG_ICONS @@ -123,7 +123,7 @@ public: void set_shortcut_key(int key) { m_shortcut_key = key; } #if ENABLE_SVG_ICONS - const std::string& get_svg_file() const { return m_svg_file; } + const std::string& get_icon_filename() const { return m_icon_filename; } #endif // ENABLE_SVG_ICONS bool is_activable(const GLCanvas3D::Selection& selection) const { return on_is_activable(selection); } @@ -254,7 +254,7 @@ class GLGizmoRotate3D : public GLGizmoBase public: #if ENABLE_SVG_ICONS - GLGizmoRotate3D(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id); + GLGizmoRotate3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); #else GLGizmoRotate3D(GLCanvas3D& parent, unsigned int sprite_id); #endif // ENABLE_SVG_ICONS @@ -329,7 +329,7 @@ class GLGizmoScale3D : public GLGizmoBase public: #if ENABLE_SVG_ICONS - GLGizmoScale3D(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id); + GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); #else GLGizmoScale3D(GLCanvas3D& parent, unsigned int sprite_id); #endif // ENABLE_SVG_ICONS @@ -380,7 +380,7 @@ class GLGizmoMove3D : public GLGizmoBase public: #if ENABLE_SVG_ICONS - GLGizmoMove3D(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id); + GLGizmoMove3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); #else GLGizmoMove3D(GLCanvas3D& parent, unsigned int sprite_id); #endif // ENABLE_SVG_ICONS @@ -439,7 +439,7 @@ private: public: #if ENABLE_SVG_ICONS - GLGizmoFlatten(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id); + GLGizmoFlatten(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); #else GLGizmoFlatten(GLCanvas3D& parent, unsigned int sprite_id); #endif // ENABLE_SVG_ICONS @@ -491,7 +491,7 @@ private: public: #if ENABLE_SVG_ICONS - GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id); + GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); #else GLGizmoSlaSupports(GLCanvas3D& parent, unsigned int sprite_id); #endif // ENABLE_SVG_ICONS @@ -588,7 +588,7 @@ class GLGizmoCut : public GLGizmoBase public: #if ENABLE_SVG_ICONS - GLGizmoCut(GLCanvas3D& parent, const std::string& svg_file, unsigned int sprite_id); + GLGizmoCut(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); #else GLGizmoCut(GLCanvas3D& parent, unsigned int sprite_id); #endif // ENABLE_SVG_ICONS diff --git a/src/slic3r/GUI/GLTexture.cpp b/src/slic3r/GUI/GLTexture.cpp index 9679680d0..7e822a4c1 100644 --- a/src/slic3r/GUI/GLTexture.cpp +++ b/src/slic3r/GUI/GLTexture.cpp @@ -148,8 +148,8 @@ bool GLTexture::load_from_svg_files_as_sprites_array(const std::vectorrender(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_size, (unsigned int)m_layout.icons_size); + item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale)); #else item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_size, m_icons_texture.metadata.icon_size); #endif // ENABLE_SVG_ICONS @@ -1062,14 +1065,17 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) const { #if ENABLE_SVG_ICONS unsigned int tex_id = m_icons_texture.get_id(); - int tex_size = m_icons_texture.get_width(); + int tex_width = m_icons_texture.get_width(); + int tex_height = m_icons_texture.get_height(); #else unsigned int tex_id = m_icons_texture.texture.get_id(); int tex_size = m_icons_texture.texture.get_width(); #endif // ENABLE_SVG_ICONS +#if !ENABLE_SVG_ICONS if ((tex_id == 0) || (tex_size <= 0)) return; +#endif // !ENABLE_SVG_ICONS float zoom = parent.get_camera_zoom(); float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; @@ -1184,6 +1190,11 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) const left += scaled_border; top -= scaled_border; +#if ENABLE_SVG_ICONS + if ((tex_id == 0) || (tex_width <= 0) || (tex_height <= 0)) + return; +#endif // ENABLE_SVG_ICONS + // renders icons for (const GLToolbarItem* item : m_items) { @@ -1197,7 +1208,7 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) const else { #if ENABLE_SVG_ICONS - item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_size, (unsigned int)(m_layout.icons_size * m_layout.scale)); + item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale)); #else item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_size, m_icons_texture.metadata.icon_size); #endif // ENABLE_SVG_ICONS @@ -1213,9 +1224,9 @@ bool GLToolbar::generate_icons_texture() const std::vector filenames; for (GLToolbarItem* item : m_items) { - const std::string& svg_file = item->get_svg_file(); - if (!svg_file.empty()) - filenames.push_back(path + svg_file); + const std::string& icon_filename = item->get_icon_filename(); + if (!icon_filename.empty()) + filenames.push_back(path + icon_filename); } bool res = m_icons_texture.load_from_svg_files_as_sprites_array(filenames, GLToolbarItem::Num_States, (unsigned int)(m_layout.icons_size * m_layout.scale)); diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index b12b2693e..30a9ff04d 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -52,7 +52,7 @@ public: { std::string name; #if ENABLE_SVG_ICONS - std::string svg_file; + std::string icon_filename; #endif // ENABLE_SVG_ICONS std::string tooltip; unsigned int sprite_id; @@ -78,7 +78,7 @@ public: const std::string& get_name() const { return m_data.name; } #if ENABLE_SVG_ICONS - const std::string& get_svg_file() const { return m_data.svg_file; } + const std::string& get_icon_filename() const { return m_data.icon_filename; } #endif // ENABLE_SVG_ICONS const std::string& get_tooltip() const { return m_data.tooltip; } @@ -96,10 +96,10 @@ public: #endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS bool is_separator() const { return m_type == Separator; } - void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int texture_size, unsigned int icon_size) const; + void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const; private: - GLTexture::Quad_UVs get_uvs(unsigned int texture_size, unsigned int icon_size) const; + GLTexture::Quad_UVs get_uvs(unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const; }; #if !ENABLE_SVG_ICONS diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index d17cce97d..6c2c3a1ea 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2651,7 +2651,7 @@ void Plater::priv::init_view_toolbar() item.name = "3D"; #if ENABLE_SVG_ICONS - item.svg_file = "add.svg"; + item.icon_filename = "add.svg"; #endif // ENABLE_SVG_ICONS item.tooltip = GUI::L_str("3D editor view") + " [" + GUI::shortkey_ctrl_prefix() + "5]"; item.sprite_id = 0; @@ -2662,7 +2662,7 @@ void Plater::priv::init_view_toolbar() item.name = "Preview"; #if ENABLE_SVG_ICONS - item.svg_file = "remove.svg"; + item.icon_filename = "remove.svg"; #endif // ENABLE_SVG_ICONS item.tooltip = GUI::L_str("Preview") + " [" + GUI::shortkey_ctrl_prefix() + "6]"; item.sprite_id = 1;