diff --git a/resources/icons/toolbar_background.png b/resources/icons/toolbar_background.png new file mode 100644 index 000000000..2b5ea013b Binary files /dev/null and b/resources/icons/toolbar_background.png differ diff --git a/resources/icons/view_toolbar.png b/resources/icons/view_toolbar.png index 26202a2a4..dd1f5aca4 100644 Binary files a/resources/icons/view_toolbar.png and b/resources/icons/view_toolbar.png differ diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index e0c35d55c..d604896ad 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -38,6 +38,8 @@ #define ENABLE_CONSTRAINED_CAMERA_TARGET (1 && ENABLE_1_42_0) // Use wxDataViewRender instead of wxDataViewCustomRenderer #define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING (0 && ENABLE_1_42_0) +// Adds background texture to toolbars +#define ENABLE_TOOLBAR_BACKGROUND_TEXTURE (1 && ENABLE_1_42_0) #endif // _technologies_h_ diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 352ea2f49..8b1d636e5 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3434,7 +3434,11 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas) : m_canvas(canvas) , m_context(nullptr) , m_in_render(false) +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + , m_toolbar(GLToolbar::Normal) +#else , m_toolbar(*this) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #if ENABLE_REMOVE_TABS_FROM_PLATER , m_view_toolbar(nullptr) #endif // ENABLE_REMOVE_TABS_FROM_PLATER @@ -4675,7 +4679,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) int layer_editing_object_idx = is_layers_editing_enabled() ? selected_object_idx : -1; m_layers_editing.last_object_id = layer_editing_object_idx; bool gizmos_overlay_contains_mouse = m_gizmos.overlay_contains_mouse(*this, m_mouse.position); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + int toolbar_contains_mouse = m_toolbar.contains_mouse(m_mouse.position, *this); +#else int toolbar_contains_mouse = m_toolbar.contains_mouse(m_mouse.position); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #if ENABLE_REMOVE_TABS_FROM_PLATER int view_toolbar_contains_mouse = (m_view_toolbar != nullptr) ? m_view_toolbar->contains_mouse(m_mouse.position, *this) : -1; #endif // ENABLE_REMOVE_TABS_FROM_PLATER @@ -4699,7 +4707,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) else if (evt.LeftDClick() && (toolbar_contains_mouse != -1)) { m_toolbar_action_running = true; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + m_toolbar.do_action((unsigned int)toolbar_contains_mouse, *this); +#else m_toolbar.do_action((unsigned int)toolbar_contains_mouse); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } else if (evt.LeftDClick() && (m_gizmos.get_current_type() != Gizmos::Undefined)) { @@ -4778,7 +4790,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) else if (toolbar_contains_mouse != -1) { m_toolbar_action_running = true; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + m_toolbar.do_action((unsigned int)toolbar_contains_mouse, *this); +#else m_toolbar.do_action((unsigned int)toolbar_contains_mouse); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE m_mouse.left_down = false; } else @@ -5061,7 +5077,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // updates toolbar overlay if (tooltip.empty()) +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + tooltip = m_toolbar.update_hover_state(m_mouse.position, *this); +#else tooltip = m_toolbar.update_hover_state(m_mouse.position); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE // updates view toolbar overlay if (tooltip.empty() && (m_view_toolbar != nullptr)) @@ -5429,7 +5449,24 @@ bool GLCanvas3D::_init_toolbar() if (!m_toolbar.is_enabled()) return true; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + ItemsIconsTexture::Metadata icons_data; + icons_data.filename = "toolbar.png"; + icons_data.icon_size = 36; + icons_data.icon_border_size = 1; + icons_data.icon_gap_size = 1; + + BackgroundTexture::Metadata background_data; + background_data.filename = "toolbar_background.png"; + background_data.left = 16; + background_data.top = 16; + background_data.right = 16; + background_data.bottom = 16; + + if (!m_toolbar.init(icons_data, background_data)) +#else if (!m_toolbar.init("toolbar.png", 36, 1, 1)) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { // unable to init the toolbar texture, disable it m_toolbar.set_enabled(false); @@ -5438,6 +5475,10 @@ bool GLCanvas3D::_init_toolbar() // m_toolbar.set_layout_type(GLToolbar::Layout::Vertical); m_toolbar.set_layout_type(GLToolbar::Layout::Horizontal); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + m_toolbar.set_layout_orientation(GLToolbar::Layout::Top); + m_toolbar.set_border(5.0f); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE m_toolbar.set_separator_size(5); m_toolbar.set_gap_size(2); @@ -5524,9 +5565,6 @@ bool GLCanvas3D::_init_toolbar() if (!m_toolbar.add_item(item)) return false; - if (!m_toolbar.add_separator()) - return false; - enable_toolbar_item("add", true); return true; @@ -6063,7 +6101,11 @@ void GLCanvas3D::_render_toolbar() const #if !ENABLE_REMOVE_TABS_FROM_PLATER _resize_toolbar(); #endif // !ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + m_toolbar.render(*this); +#else m_toolbar.render(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } #if ENABLE_REMOVE_TABS_FROM_PLATER @@ -7721,25 +7763,54 @@ void GLCanvas3D::_resize_toolbar() const float zoom = get_camera_zoom(); float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + GLToolbar::Layout::EOrientation orientation = m_toolbar.get_layout_orientation(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + switch (m_toolbar.get_layout_type()) { default: case GLToolbar::Layout::Horizontal: { // centers the toolbar on the top edge of the 3d scene - unsigned int toolbar_width = m_toolbar.get_width(); - float top = (0.5f * (float)cnv_size.get_height() - 2.0f) * inv_zoom; - float left = -0.5f * (float)toolbar_width * inv_zoom; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float top, left; + if (orientation == GLToolbar::Layout::Top) + { + top = 0.5f * (float)cnv_size.get_height() * inv_zoom; + left = -0.5f * m_toolbar.get_width() * inv_zoom; + } + else + { + top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar->get_height()) * inv_zoom; + left = -0.5f * m_toolbar.get_width() * inv_zoom; + } +#else + float top = 0.5f * (float)cnv_size.get_height() * inv_zoom; + float left = -0.5f * m_toolbar.get_width() * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE m_toolbar.set_position(top, left); break; } case GLToolbar::Layout::Vertical: { // centers the toolbar on the right edge of the 3d scene - unsigned int toolbar_width = m_toolbar.get_width(); - unsigned int toolbar_height = m_toolbar.get_height(); - float top = 0.5f * (float)toolbar_height * inv_zoom; - float left = (0.5f * (float)cnv_size.get_width() - toolbar_width - 2.0f) * inv_zoom; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float top, left; + if (orientation == GLToolbar::Layout::Left) + { + top = 0.5f * m_toolbar.get_height() * inv_zoom; + left = (-0.5f * (float)cnv_size.get_width()) * inv_zoom; + } + else + { + top = 0.5f * m_toolbar.get_height() * inv_zoom; + left = (0.5f * (float)cnv_size.get_width() - m_toolbar.get_width()) * inv_zoom; + } +#else + float top = 0.5f * m_toolbar.get_height() * inv_zoom; + float left = (0.5f * (float)cnv_size.get_width() - m_toolbar.get_width()) * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE m_toolbar.set_position(top, left); break; } @@ -7748,6 +7819,7 @@ void GLCanvas3D::_resize_toolbar() const #if ENABLE_REMOVE_TABS_FROM_PLATER if (m_view_toolbar != nullptr) { + // places the toolbar on the bottom-left corner of the 3d scene float top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar->get_height()) * inv_zoom; float left = -0.5f * (float)cnv_size.get_width() * inv_zoom; m_view_toolbar->set_position(top, left); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 12a83eebd..ebc2929d9 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -769,7 +769,11 @@ private: mutable Gizmos m_gizmos; mutable GLToolbar m_toolbar; #if ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + GLToolbar* m_view_toolbar; +#else GLRadioToolbar* m_view_toolbar; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #endif // ENABLE_REMOVE_TABS_FROM_PLATER ClippingPlane m_clipping_planes[2]; bool m_use_clipping_planes; @@ -824,7 +828,11 @@ public: wxGLCanvas* get_wxglcanvas() { return m_canvas; } #if ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + void set_view_toolbar(GLToolbar* toolbar) { m_view_toolbar = toolbar; } +#else void set_view_toolbar(GLRadioToolbar* toolbar) { m_view_toolbar = toolbar; } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #endif // ENABLE_REMOVE_TABS_FROM_PLATER bool init(bool useVBOs, bool use_legacy_opengl); diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index 92b3e96af..a7f623b8d 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -75,6 +75,13 @@ bool GLToolbarItem::is_enabled() const return m_state != Disabled; } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +bool GLToolbarItem::is_disabled() const +{ + return m_state == Disabled; +} +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + bool GLToolbarItem::is_hovered() const { return (m_state == Hover) || (m_state == HoverPressed); @@ -124,24 +131,63 @@ GLTexture::Quad_UVs GLToolbarItem::get_uvs(unsigned int texture_size, unsigned i return uvs; } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +ItemsIconsTexture::Metadata::Metadata() + : filename("") + , icon_size(0) + , icon_border_size(0) + , icon_gap_size(0) +{ +} +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + +#if !ENABLE_TOOLBAR_BACKGROUND_TEXTURE ItemsIconsTexture::ItemsIconsTexture() : items_icon_size(0) , items_icon_border_size(0) , items_icon_gap_size(0) { } +#endif // !ENABLE_TOOLBAR_BACKGROUND_TEXTURE + +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +BackgroundTexture::Metadata::Metadata() + : filename("") + , left(0) + , right(0) + , top(0) + , bottom(0) +{ +} +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE GLToolbar::Layout::Layout() : type(Horizontal) +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + , orientation(Center) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE , top(0.0f) , left(0.0f) +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + , border(0.0f) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE , separator_size(0.0f) , gap_size(0.0f) +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + , width(0.0f) + , height(0.0f) + , dirty(true) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +GLToolbar::GLToolbar(GLToolbar::EType type) + : m_type(type) +#else GLToolbar::GLToolbar(GLCanvas3D& parent) : m_parent(parent) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE , m_enabled(false) { } @@ -154,6 +200,26 @@ GLToolbar::~GLToolbar() } } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +bool GLToolbar::init(const ItemsIconsTexture::Metadata& icons_texture, const BackgroundTexture::Metadata& background_texture) +{ + if (m_icons_texture.texture.get_id() != 0) + return true; + + std::string path = resources_dir() + "/icons/"; + bool res = !icons_texture.filename.empty() && m_icons_texture.texture.load_from_file(path + icons_texture.filename, false); + if (res) + m_icons_texture.metadata = icons_texture; + + if (!background_texture.filename.empty()) + res = m_background_texture.texture.load_from_file(path + background_texture.filename, false); + + if (res) + m_background_texture.metadata = background_texture; + + return res; +} +#else bool GLToolbar::init(const std::string& icons_texture_filename, unsigned int items_icon_size, unsigned int items_icon_border_size, unsigned int items_icon_gap_size) { std::string path = resources_dir() + "/icons/"; @@ -167,31 +233,61 @@ bool GLToolbar::init(const std::string& icons_texture_filename, unsigned int ite return res; } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE -GLToolbar::Layout::Type GLToolbar::get_layout_type() const +GLToolbar::Layout::EType GLToolbar::get_layout_type() const { return m_layout.type; } -void GLToolbar::set_layout_type(GLToolbar::Layout::Type type) +void GLToolbar::set_layout_type(GLToolbar::Layout::EType type) { m_layout.type = type; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + m_layout.dirty = true; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +GLToolbar::Layout::EOrientation GLToolbar::get_layout_orientation() const +{ + return m_layout.orientation; +} + +void GLToolbar::set_layout_orientation(GLToolbar::Layout::EOrientation orientation) +{ + m_layout.orientation = orientation; +} +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + void GLToolbar::set_position(float top, float left) { m_layout.top = top; m_layout.left = left; } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void GLToolbar::set_border(float border) +{ + m_layout.border = border; + m_layout.dirty = true; +} +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + void GLToolbar::set_separator_size(float size) { m_layout.separator_size = size; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + m_layout.dirty = true; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } void GLToolbar::set_gap_size(float size) { m_layout.gap_size = size; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + m_layout.dirty = true; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } bool GLToolbar::is_enabled() const @@ -211,6 +307,9 @@ bool GLToolbar::add_item(const GLToolbarItem::Data& data) return false; m_items.push_back(item); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + m_layout.dirty = true; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE return true; } @@ -222,11 +321,20 @@ bool GLToolbar::add_separator() return false; m_items.push_back(item); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + m_layout.dirty = true; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE return true; } float GLToolbar::get_width() const { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + if (m_layout.dirty) + calc_layout(); + + return m_layout.width; +#else switch (m_layout.type) { default: @@ -239,10 +347,17 @@ float GLToolbar::get_width() const return get_width_vertical(); } } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } float GLToolbar::get_height() const { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + if (m_layout.dirty) + calc_layout(); + + return m_layout.height; +#else switch (m_layout.type) { default: @@ -255,6 +370,7 @@ float GLToolbar::get_height() const return get_height_vertical(); } } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } void GLToolbar::enable_item(const std::string& name) @@ -281,6 +397,23 @@ void GLToolbar::disable_item(const std::string& name) } } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void GLToolbar::select_item(const std::string& name) +{ + if (is_item_disabled(name)) + return; + + for (GLToolbarItem* item : m_items) + { + if (!item->is_disabled()) + { + bool hover = item->is_hovered(); + item->set_state((item->get_name() == name) ? (hover ? GLToolbarItem::HoverPressed : GLToolbarItem::Pressed) : (hover ? GLToolbarItem::Hover : GLToolbarItem::Normal)); + } + } +} +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + bool GLToolbar::is_item_pressed(const std::string& name) const { for (GLToolbarItem* item : m_items) @@ -292,10 +425,31 @@ bool GLToolbar::is_item_pressed(const std::string& name) const return false; } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +bool GLToolbar::is_item_disabled(const std::string& name) const +{ + for (GLToolbarItem* item : m_items) + { + if (item->get_name() == name) + return item->is_disabled(); + } + + return false; +} +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + #if ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +std::string GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent) +#else std::string GLToolbar::update_hover_state(const Vec2d& mouse_pos) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE +#else +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent) #else void GLToolbar::update_hover_state(const Vec2d& mouse_pos) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #endif // ENABLE_REMOVE_TABS_FROM_PLATER { #if ENABLE_REMOVE_TABS_FROM_PLATER @@ -310,24 +464,30 @@ void GLToolbar::update_hover_state(const Vec2d& mouse_pos) { default: #if ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + case Layout::Horizontal: { return update_hover_state_horizontal(mouse_pos, parent); } + case Layout::Vertical: { return update_hover_state_vertical(mouse_pos, parent); } +#else case Layout::Horizontal: { return update_hover_state_horizontal(mouse_pos); } case Layout::Vertical: { return update_hover_state_vertical(mouse_pos); } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #else - case Layout::Horizontal: - { - update_hover_state_horizontal(mouse_pos); - break; - } - case Layout::Vertical: - { - update_hover_state_vertical(mouse_pos); - break; - } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + case Layout::Horizontal: { update_hover_state_horizontal(mouse_pos, parent); break; } + case Layout::Vertical: { update_hover_state_vertical(mouse_pos, parent); break; } +#else + case Layout::Horizontal: { update_hover_state_horizontal(mouse_pos); break; } + case Layout::Vertical: { update_hover_state_vertical(mouse_pos); break; } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #endif // ENABLE_REMOVE_TABS_FROM_PLATER } } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +int GLToolbar::contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) const +#else int GLToolbar::contains_mouse(const Vec2d& mouse_pos) const +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { if (!m_enabled) return -1; @@ -335,18 +495,21 @@ int GLToolbar::contains_mouse(const Vec2d& mouse_pos) const switch (m_layout.type) { default: - case Layout::Horizontal: - { - return contains_mouse_horizontal(mouse_pos); - } - case Layout::Vertical: - { - return contains_mouse_vertical(mouse_pos); - } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + case Layout::Horizontal: { return contains_mouse_horizontal(mouse_pos, parent); } + case Layout::Vertical: { return contains_mouse_vertical(mouse_pos, parent); } +#else + case Layout::Horizontal: { return contains_mouse_horizontal(mouse_pos); } + case Layout::Vertical: { return contains_mouse_vertical(mouse_pos); } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void GLToolbar::do_action(unsigned int item_id, GLCanvas3D& parent) +#else void GLToolbar::do_action(unsigned int item_id) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { if (item_id < (unsigned int)m_items.size()) { @@ -361,26 +524,51 @@ void GLToolbar::do_action(unsigned int item_id) else if (state == GLToolbarItem::HoverPressed) item->set_state(GLToolbarItem::Hover); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + parent.render(); + item->do_action(parent.get_wxglcanvas()); +#else m_parent.render(); item->do_action(m_parent.get_wxglcanvas()); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } else { - item->set_state(GLToolbarItem::HoverPressed); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + if (m_type == Radio) + select_item(item->get_name()); + else +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + item->set_state(GLToolbarItem::HoverPressed); + +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + parent.render(); + item->do_action(parent.get_wxglcanvas()); + if ((m_type == Normal) && (item->get_state() != GLToolbarItem::Disabled)) +#else m_parent.render(); item->do_action(m_parent.get_wxglcanvas()); if (item->get_state() != GLToolbarItem::Disabled) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { // the item may get disabled during the action, if not, set it back to hover state item->set_state(GLToolbarItem::Hover); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + parent.render(); +#else m_parent.render(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } } } } } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void GLToolbar::render(const GLCanvas3D& parent) const +#else void GLToolbar::render() const +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { if (!m_enabled || m_items.empty()) return; @@ -393,21 +581,42 @@ void GLToolbar::render() const switch (m_layout.type) { default: - case Layout::Horizontal: - { - render_horizontal(); - break; - } - case Layout::Vertical: - { - render_vertical(); - break; - } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + case Layout::Horizontal: { render_horizontal(parent); break; } + case Layout::Vertical: { render_vertical(parent); break; } +#else + case Layout::Horizontal: { render_horizontal(); break; } + case Layout::Vertical: { render_vertical(); break; } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } ::glPopMatrix(); } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void GLToolbar::calc_layout() const +{ + switch (m_layout.type) + { + default: + case Layout::Horizontal: + { + m_layout.width = get_width_horizontal(); + m_layout.height = get_height_horizontal(); + break; + } + case Layout::Vertical: + { + m_layout.width = get_width_vertical(); + m_layout.height = get_height_vertical(); + break; + } + } + + m_layout.dirty = false; +} +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float GLToolbar::get_width_horizontal() const { return get_main_size(); @@ -415,12 +624,20 @@ float GLToolbar::get_width_horizontal() const float GLToolbar::get_width_vertical() const { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + return 2.0f * m_layout.border + m_icons_texture.metadata.icon_size; +#else return m_icons_texture.items_icon_size; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } float GLToolbar::get_height_horizontal() const { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + return 2.0f * m_layout.border + m_icons_texture.metadata.icon_size; +#else return m_icons_texture.items_icon_size; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } float GLToolbar::get_height_vertical() const @@ -430,13 +647,21 @@ float GLToolbar::get_height_vertical() const float GLToolbar::get_main_size() const { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float size = 2.0f * m_layout.border; +#else float size = 0.0f; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE for (unsigned int i = 0; i < (unsigned int)m_items.size(); ++i) { if (m_items[i]->is_separator()) size += m_layout.separator_size; else +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + size += (float)m_icons_texture.metadata.icon_size; +#else size += (float)m_icons_texture.items_icon_size; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } if (m_items.size() > 1) @@ -446,26 +671,54 @@ float GLToolbar::get_main_size() const } #if ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent) +#else std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE +#else +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent) #else void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #endif // ENABLE_REMOVE_TABS_FROM_PLATER { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float zoom = parent.get_camera_zoom(); +#else float zoom = m_parent.get_camera_zoom(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + Size cnv_size = parent.get_canvas_size(); +#else Size cnv_size = m_parent.get_canvas_size(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * inv_zoom; +#else float scaled_icons_size = (float)m_icons_texture.items_icon_size * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float scaled_separator_size = m_layout.separator_size * inv_zoom; float scaled_gap_size = m_layout.gap_size * inv_zoom; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_border = m_layout.border * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float separator_stride = scaled_separator_size + scaled_gap_size; float icon_stride = scaled_icons_size + scaled_gap_size; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float left = m_layout.left + scaled_border; + float top = m_layout.top - scaled_border; +#else float left = m_layout.left; float top = m_layout.top; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE std::string tooltip = ""; @@ -486,7 +739,14 @@ void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos) case GLToolbarItem::Normal: { if (inside) +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + { +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE item->set_state(GLToolbarItem::Hover); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + parent.set_as_dirty(); + } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE break; } @@ -495,15 +755,29 @@ void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos) if (inside) tooltip = item->get_tooltip(); else +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + { +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE item->set_state(GLToolbarItem::Normal); - +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + parent.set_as_dirty(); + } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + break; } case GLToolbarItem::Pressed: { if (inside) +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + { +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE item->set_state(GLToolbarItem::HoverPressed); - +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + parent.set_as_dirty(); + } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + break; } case GLToolbarItem::HoverPressed: @@ -511,8 +785,15 @@ void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos) if (inside) tooltip = item->get_tooltip(); else +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + { +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE item->set_state(GLToolbarItem::Pressed); - +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + parent.set_as_dirty(); + } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + break; } default: @@ -535,26 +816,54 @@ void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos) } #if ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent) +#else std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE +#else +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent) #else void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #endif // ENABLE_REMOVE_TABS_FROM_PLATER { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float zoom = parent.get_camera_zoom(); +#else float zoom = m_parent.get_camera_zoom(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + Size cnv_size = parent.get_canvas_size(); +#else Size cnv_size = m_parent.get_canvas_size(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * inv_zoom; +#else float scaled_icons_size = (float)m_icons_texture.items_icon_size * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float scaled_separator_size = m_layout.separator_size * inv_zoom; float scaled_gap_size = m_layout.gap_size * inv_zoom; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_border = m_layout.border * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float separator_stride = scaled_separator_size + scaled_gap_size; float icon_stride = scaled_icons_size + scaled_gap_size; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float left = m_layout.left + scaled_border; + float top = m_layout.top - scaled_border; +#else float left = m_layout.left; float top = m_layout.top; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE std::string tooltip = ""; @@ -575,7 +884,14 @@ void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos) case GLToolbarItem::Normal: { if (inside) +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + { +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE item->set_state(GLToolbarItem::Hover); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + parent.set_as_dirty(); + } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE break; } @@ -584,14 +900,28 @@ void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos) if (inside) tooltip = item->get_tooltip(); else +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + { +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE item->set_state(GLToolbarItem::Normal); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + parent.set_as_dirty(); + } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE break; } case GLToolbarItem::Pressed: { if (inside) +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + { +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE item->set_state(GLToolbarItem::HoverPressed); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + parent.set_as_dirty(); + } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE break; } @@ -600,7 +930,14 @@ void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos) if (inside) tooltip = item->get_tooltip(); else +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + { +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE item->set_state(GLToolbarItem::Pressed); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + parent.set_as_dirty(); + } +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE break; } @@ -622,23 +959,47 @@ void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos) #endif // ENABLE_REMOVE_TABS_FROM_PLATER } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const +#else int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos) const +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float zoom = parent.get_camera_zoom(); +#else float zoom = m_parent.get_camera_zoom(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + Size cnv_size = parent.get_canvas_size(); +#else Size cnv_size = m_parent.get_canvas_size(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * inv_zoom; +#else float scaled_icons_size = (float)m_icons_texture.items_icon_size * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float scaled_separator_size = m_layout.separator_size * inv_zoom; float scaled_gap_size = m_layout.gap_size * inv_zoom; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_border = m_layout.border * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float separator_stride = scaled_separator_size + scaled_gap_size; float icon_stride = scaled_icons_size + scaled_gap_size; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float left = m_layout.left + scaled_border; + float top = m_layout.top - scaled_border; +#else float left = m_layout.left; float top = m_layout.top; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE int id = -1; @@ -663,23 +1024,47 @@ int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos) const return -1; } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& parent) const +#else int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos) const +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float zoom = parent.get_camera_zoom(); +#else float zoom = m_parent.get_camera_zoom(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + Size cnv_size = parent.get_canvas_size(); +#else Size cnv_size = m_parent.get_canvas_size(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * inv_zoom; +#else float scaled_icons_size = (float)m_icons_texture.items_icon_size * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float scaled_separator_size = m_layout.separator_size * inv_zoom; float scaled_gap_size = m_layout.gap_size * inv_zoom; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_border = m_layout.border * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float separator_stride = scaled_separator_size + scaled_gap_size; float icon_stride = scaled_icons_size + scaled_gap_size; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float left = m_layout.left + scaled_border; + float top = m_layout.top - scaled_border; +#else float left = m_layout.left; float top = m_layout.top; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE int id = -1; @@ -704,7 +1089,11 @@ int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos) const return -1; } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void GLToolbar::render_horizontal(const GLCanvas3D& parent) const +#else void GLToolbar::render_horizontal() const +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { unsigned int tex_id = m_icons_texture.texture.get_id(); int tex_size = m_icons_texture.texture.get_width(); @@ -712,18 +1101,124 @@ void GLToolbar::render_horizontal() const if ((tex_id == 0) || (tex_size <= 0)) return; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float zoom = parent.get_camera_zoom(); +#else float zoom = m_parent.get_camera_zoom(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * inv_zoom; +#else float scaled_icons_size = (float)m_icons_texture.items_icon_size * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float scaled_separator_size = m_layout.separator_size * inv_zoom; float scaled_gap_size = m_layout.gap_size * inv_zoom; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_border = m_layout.border * inv_zoom; + float scaled_width = get_width() * inv_zoom; + float scaled_height = get_height() * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float separator_stride = scaled_separator_size + scaled_gap_size; float icon_stride = scaled_icons_size + scaled_gap_size; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE float left = m_layout.left; float top = m_layout.top; + float right = left + scaled_width; + float bottom = top - scaled_height; + + // renders background + unsigned int bg_tex_id = m_background_texture.texture.get_id(); + float bg_tex_width = (float)m_background_texture.texture.get_width(); + float bg_tex_height = (float)m_background_texture.texture.get_height(); + if ((bg_tex_id != 0) && (bg_tex_width > 0) && (bg_tex_height > 0)) + { + float inv_bg_tex_width = (bg_tex_width != 0.0f) ? 1.0f / bg_tex_width : 0.0f; + float inv_bg_tex_height = (bg_tex_height != 0.0f) ? 1.0f / bg_tex_height : 0.0f; + + float bg_uv_left = 0.0f; + float bg_uv_right = 1.0f; + float bg_uv_top = 1.0f; + float bg_uv_bottom = 0.0f; + + float bg_left = left; + float bg_right = right; + float bg_top = top; + float bg_bottom = bottom; + float bg_width = right - left; + float bg_height = top - bottom; + float bg_min_size = std::min(bg_width, bg_height); + + float bg_uv_i_left = (float)m_background_texture.metadata.left * inv_bg_tex_width; + float bg_uv_i_right = 1.0f - (float)m_background_texture.metadata.right * inv_bg_tex_width; + float bg_uv_i_top = 1.0f - (float)m_background_texture.metadata.top * inv_bg_tex_height; + float bg_uv_i_bottom = (float)m_background_texture.metadata.bottom * inv_bg_tex_height; + + float bg_i_left = bg_left + scaled_border; + float bg_i_right = bg_right - scaled_border; + float bg_i_top = bg_top - scaled_border; + float bg_i_bottom = bg_bottom + scaled_border; + + switch (m_layout.orientation) + { + case Layout::Top: + { + bg_uv_top = bg_uv_i_top; + bg_i_top = bg_top; + break; + } + case Layout::Bottom: + { + bg_uv_bottom = bg_uv_i_bottom; + bg_i_bottom = bg_bottom; + break; + } + case Layout::Center: + { + break; + } + }; + + if ((m_layout.border > 0) && (bg_uv_top != bg_uv_i_top)) + { + if (bg_uv_left != bg_uv_i_left) + GLTexture::render_sub_texture(bg_tex_id, bg_left, bg_i_left, bg_i_top, bg_top, { { bg_uv_left, bg_uv_i_top }, { bg_uv_i_left, bg_uv_i_top }, { bg_uv_i_left, bg_uv_top }, { bg_uv_left, bg_uv_top } }); + + GLTexture::render_sub_texture(bg_tex_id, bg_i_left, bg_i_right, bg_i_top, bg_top, { { bg_uv_i_left, bg_uv_i_top }, { bg_uv_i_right, bg_uv_i_top }, { bg_uv_i_right, bg_uv_top }, { bg_uv_i_left, bg_uv_top } }); + + if (bg_uv_right != bg_uv_i_right) + GLTexture::render_sub_texture(bg_tex_id, bg_i_right, bg_right, bg_i_top, bg_top, { { bg_uv_i_right, bg_uv_i_top }, { bg_uv_right, bg_uv_i_top }, { bg_uv_right, bg_uv_top }, { bg_uv_i_right, bg_uv_top } }); + } + + if ((m_layout.border > 0) && (bg_uv_left != bg_uv_i_left)) + GLTexture::render_sub_texture(bg_tex_id, bg_left, bg_i_left, bg_i_bottom, bg_i_top, { { bg_uv_left, bg_uv_i_bottom }, { bg_uv_i_left, bg_uv_i_bottom }, { bg_uv_i_left, bg_uv_i_top }, { bg_uv_left, bg_uv_i_top } }); + + GLTexture::render_sub_texture(bg_tex_id, bg_i_left, bg_i_right, bg_i_bottom, bg_i_top, { { bg_uv_i_left, bg_uv_i_bottom }, { bg_uv_i_right, bg_uv_i_bottom }, { bg_uv_i_right, bg_uv_i_top }, { bg_uv_i_left, bg_uv_i_top } }); + + if ((m_layout.border > 0) && (bg_uv_right != bg_uv_i_right)) + GLTexture::render_sub_texture(bg_tex_id, bg_i_right, bg_right, bg_i_bottom, bg_i_top, { { bg_uv_i_right, bg_uv_i_bottom }, { bg_uv_right, bg_uv_i_bottom }, { bg_uv_right, bg_uv_i_top }, { bg_uv_i_right, bg_uv_i_top } }); + + if ((m_layout.border > 0) && (bg_uv_bottom != bg_uv_i_bottom)) + { + if (bg_uv_left != bg_uv_i_left) + GLTexture::render_sub_texture(bg_tex_id, bg_left, bg_i_left, bg_bottom, bg_i_bottom, { { bg_uv_left, bg_uv_bottom }, { bg_uv_i_left, bg_uv_bottom }, { bg_uv_i_left, bg_uv_i_bottom }, { bg_uv_left, bg_uv_i_bottom } }); + + GLTexture::render_sub_texture(bg_tex_id, bg_i_left, bg_i_right, bg_bottom, bg_i_bottom, { { bg_uv_i_left, bg_uv_bottom }, { bg_uv_i_right, bg_uv_bottom }, { bg_uv_i_right, bg_uv_i_bottom }, { bg_uv_i_left, bg_uv_i_bottom } }); + + if (bg_uv_right != bg_uv_i_right) + GLTexture::render_sub_texture(bg_tex_id, bg_i_right, bg_right, bg_bottom, bg_i_bottom, { { bg_uv_i_right, bg_uv_bottom }, { bg_uv_right, bg_uv_bottom }, { bg_uv_right, bg_uv_i_bottom }, { bg_uv_i_right, bg_uv_i_bottom } }); + } + } + + left += scaled_border; + top -= scaled_border; +#else + float left = m_layout.left; + float top = m_layout.top; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE // renders icons for (const GLToolbarItem* item : m_items) @@ -732,13 +1227,21 @@ void GLToolbar::render_horizontal() const left += separator_stride; else { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_size, m_icons_texture.metadata.icon_border_size, m_icons_texture.metadata.icon_size, m_icons_texture.metadata.icon_gap_size); +#else item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_size, m_icons_texture.items_icon_border_size, m_icons_texture.items_icon_size, m_icons_texture.items_icon_gap_size); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE left += icon_stride; } } } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void GLToolbar::render_vertical(const GLCanvas3D& parent) const +#else void GLToolbar::render_vertical() const +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { unsigned int tex_id = m_icons_texture.texture.get_id(); int tex_size = m_icons_texture.texture.get_width(); @@ -746,18 +1249,124 @@ void GLToolbar::render_vertical() const if ((tex_id == 0) || (tex_size <= 0)) return; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float zoom = parent.get_camera_zoom(); +#else float zoom = m_parent.get_camera_zoom(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * inv_zoom; +#else float scaled_icons_size = (float)m_icons_texture.items_icon_size * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float scaled_separator_size = m_layout.separator_size * inv_zoom; float scaled_gap_size = m_layout.gap_size * inv_zoom; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float scaled_border = m_layout.border * inv_zoom; + float scaled_width = get_width() * inv_zoom; + float scaled_height = get_height() * inv_zoom; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float separator_stride = scaled_separator_size + scaled_gap_size; float icon_stride = scaled_icons_size + scaled_gap_size; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE float left = m_layout.left; float top = m_layout.top; + float right = left + scaled_width; + float bottom = top - scaled_height; + + // renders background + unsigned int bg_tex_id = m_background_texture.texture.get_id(); + float bg_tex_width = (float)m_background_texture.texture.get_width(); + float bg_tex_height = (float)m_background_texture.texture.get_height(); + if ((bg_tex_id != 0) && (bg_tex_width > 0) && (bg_tex_height > 0)) + { + float inv_bg_tex_width = (bg_tex_width != 0.0f) ? 1.0f / bg_tex_width : 0.0f; + float inv_bg_tex_height = (bg_tex_height != 0.0f) ? 1.0f / bg_tex_height : 0.0f; + + float bg_uv_left = 0.0f; + float bg_uv_right = 1.0f; + float bg_uv_top = 1.0f; + float bg_uv_bottom = 0.0f; + + float bg_left = left; + float bg_right = right; + float bg_top = top; + float bg_bottom = bottom; + float bg_width = right - left; + float bg_height = top - bottom; + float bg_min_size = std::min(bg_width, bg_height); + + float bg_uv_i_left = (float)m_background_texture.metadata.left * inv_bg_tex_width; + float bg_uv_i_right = 1.0f - (float)m_background_texture.metadata.right * inv_bg_tex_width; + float bg_uv_i_top = 1.0f - (float)m_background_texture.metadata.top * inv_bg_tex_height; + float bg_uv_i_bottom = (float)m_background_texture.metadata.bottom * inv_bg_tex_height; + + float bg_i_left = bg_left + scaled_border; + float bg_i_right = bg_right - scaled_border; + float bg_i_top = bg_top - scaled_border; + float bg_i_bottom = bg_bottom + scaled_border; + + switch (m_layout.orientation) + { + case Layout::Left: + { + bg_uv_left = bg_uv_i_left; + bg_i_left = bg_left; + break; + } + case Layout::Right: + { + bg_uv_right = bg_uv_i_right; + bg_i_right = bg_right; + break; + } + case Layout::Center: + { + break; + } + }; + + if ((m_layout.border > 0) && (bg_uv_top != bg_uv_i_top)) + { + if (bg_uv_left != bg_uv_i_left) + GLTexture::render_sub_texture(bg_tex_id, bg_left, bg_i_left, bg_i_top, bg_top, { { bg_uv_left, bg_uv_i_top }, { bg_uv_i_left, bg_uv_i_top }, { bg_uv_i_left, bg_uv_top }, { bg_uv_left, bg_uv_top } }); + + GLTexture::render_sub_texture(bg_tex_id, bg_i_left, bg_i_right, bg_i_top, bg_top, { { bg_uv_i_left, bg_uv_i_top }, { bg_uv_i_right, bg_uv_i_top }, { bg_uv_i_right, bg_uv_top }, { bg_uv_i_left, bg_uv_top } }); + + if (bg_uv_right != bg_uv_i_right) + GLTexture::render_sub_texture(bg_tex_id, bg_i_right, bg_right, bg_i_top, bg_top, { { bg_uv_i_right, bg_uv_i_top }, { bg_uv_right, bg_uv_i_top }, { bg_uv_right, bg_uv_top }, { bg_uv_i_right, bg_uv_top } }); + } + + if ((m_layout.border > 0) && (bg_uv_left != bg_uv_i_left)) + GLTexture::render_sub_texture(bg_tex_id, bg_left, bg_i_left, bg_i_bottom, bg_i_top, { { bg_uv_left, bg_uv_i_bottom }, { bg_uv_i_left, bg_uv_i_bottom }, { bg_uv_i_left, bg_uv_i_top }, { bg_uv_left, bg_uv_i_top } }); + + GLTexture::render_sub_texture(bg_tex_id, bg_i_left, bg_i_right, bg_i_bottom, bg_i_top, { { bg_uv_i_left, bg_uv_i_bottom }, { bg_uv_i_right, bg_uv_i_bottom }, { bg_uv_i_right, bg_uv_i_top }, { bg_uv_i_left, bg_uv_i_top } }); + + if ((m_layout.border > 0) && (bg_uv_right != bg_uv_i_right)) + GLTexture::render_sub_texture(bg_tex_id, bg_i_right, bg_right, bg_i_bottom, bg_i_top, { { bg_uv_i_right, bg_uv_i_bottom }, { bg_uv_right, bg_uv_i_bottom }, { bg_uv_right, bg_uv_i_top }, { bg_uv_i_right, bg_uv_i_top } }); + + if ((m_layout.border > 0) && (bg_uv_bottom != bg_uv_i_bottom)) + { + if (bg_uv_left != bg_uv_i_left) + GLTexture::render_sub_texture(bg_tex_id, bg_left, bg_i_left, bg_bottom, bg_i_bottom, { { bg_uv_left, bg_uv_bottom }, { bg_uv_i_left, bg_uv_bottom }, { bg_uv_i_left, bg_uv_i_bottom }, { bg_uv_left, bg_uv_i_bottom } }); + + GLTexture::render_sub_texture(bg_tex_id, bg_i_left, bg_i_right, bg_bottom, bg_i_bottom, { { bg_uv_i_left, bg_uv_bottom }, { bg_uv_i_right, bg_uv_bottom }, { bg_uv_i_right, bg_uv_i_bottom }, { bg_uv_i_left, bg_uv_i_bottom } }); + + if (bg_uv_right != bg_uv_i_right) + GLTexture::render_sub_texture(bg_tex_id, bg_i_right, bg_right, bg_bottom, bg_i_bottom, { { bg_uv_i_right, bg_uv_bottom }, { bg_uv_right, bg_uv_bottom }, { bg_uv_right, bg_uv_i_bottom }, { bg_uv_i_right, bg_uv_i_bottom } }); + } + } + + left += scaled_border; + top -= scaled_border; +#else + float left = m_layout.left; + float top = m_layout.top; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE // renders icons for (const GLToolbarItem* item : m_items) @@ -766,12 +1375,17 @@ void GLToolbar::render_vertical() const top -= separator_stride; else { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_size, m_icons_texture.metadata.icon_border_size, m_icons_texture.metadata.icon_size, m_icons_texture.metadata.icon_gap_size); +#else item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_size, m_icons_texture.items_icon_border_size, m_icons_texture.items_icon_size, m_icons_texture.items_icon_gap_size); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE top -= icon_stride; } } } +#if !ENABLE_TOOLBAR_BACKGROUND_TEXTURE GLRadioToolbarItem::Data::Data() : name("") , tooltip("") @@ -1075,6 +1689,7 @@ void GLRadioToolbar::render(const GLCanvas3D& parent) const ::glPopMatrix(); } +#endif // !ENABLE_TOOLBAR_BACKGROUND_TEXTURE } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index 7eab518f7..4e15edd17 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -77,6 +77,9 @@ public: void do_action(wxEvtHandler *target); bool is_enabled() const; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + bool is_disabled() const; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE bool is_hovered() const; bool is_pressed() const; @@ -94,7 +97,25 @@ private: // from left to right struct ItemsIconsTexture { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + struct Metadata + { + // path of the file containing the icons' texture + std::string filename; + // size of the square icons, in pixels + unsigned int icon_size; + // size of the border, in pixels + unsigned int icon_border_size; + // distance between two adjacent icons (to avoid filtering artifacts), in pixels + unsigned int icon_gap_size; + + Metadata(); + }; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE GLTexture texture; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + Metadata metadata; +#else // size of the square icons, in pixels unsigned int items_icon_size; // distance from the border, in pixels @@ -103,49 +124,129 @@ struct ItemsIconsTexture unsigned int items_icon_gap_size; ItemsIconsTexture(); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE }; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +struct BackgroundTexture +{ + struct Metadata + { + // path of the file containing the background texture + std::string filename; + // size of the left edge, in pixels + unsigned int left; + // size of the right edge, in pixels + unsigned int right; + // size of the top edge, in pixels + unsigned int top; + // size of the bottom edge, in pixels + unsigned int bottom; + + Metadata(); + }; + + GLTexture texture; + Metadata metadata; +}; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + class GLToolbar { public: +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + enum EType : unsigned char + { + Normal, + Radio, + Num_Types + }; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + struct Layout { - enum Type : unsigned char + enum EType : unsigned char { Horizontal, Vertical, Num_Types }; - Type type; + enum EOrientation : unsigned int + { + Top, + Bottom, + Left, + Right, + Center, + Num_Locations + }; + + EType type; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + EOrientation orientation; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float top; float left; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float border; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float separator_size; float gap_size; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + float width; + float height; + bool dirty; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + Layout(); }; private: typedef std::vector ItemsList; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + EType m_type; +#else GLCanvas3D& m_parent; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE bool m_enabled; ItemsIconsTexture m_icons_texture; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + BackgroundTexture m_background_texture; + mutable Layout m_layout; +#else Layout m_layout; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE ItemsList m_items; public: +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + explicit GLToolbar(EType type); +#else explicit GLToolbar(GLCanvas3D& parent); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE ~GLToolbar(); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + bool init(const ItemsIconsTexture::Metadata& icons_texture, const BackgroundTexture::Metadata& background_texture); +#else bool init(const std::string& icons_texture_filename, unsigned int items_icon_size, unsigned int items_icon_border_size, unsigned int items_icon_gap_size); - - Layout::Type get_layout_type() const; - void set_layout_type(Layout::Type type); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE + + Layout::EType get_layout_type() const; + void set_layout_type(Layout::EType type); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + Layout::EOrientation get_layout_orientation() const; + void set_layout_orientation(Layout::EOrientation orientation); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE void set_position(float top, float left); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + void set_border(float border); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE void set_separator_size(float size); void set_gap_size(float size); @@ -160,42 +261,89 @@ public: void enable_item(const std::string& name); void disable_item(const std::string& name); +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + void select_item(const std::string& name); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE bool is_item_pressed(const std::string& name) const; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + bool is_item_disabled(const std::string& name) const; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #if ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + std::string update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent); +#else std::string update_hover_state(const Vec2d& mouse_pos); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE +#else +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + void update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent); #else void update_hover_state(const Vec2d& mouse_pos); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #endif // ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + // returns the id of the item under the given mouse position or -1 if none + int contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) const; + + void do_action(unsigned int item_id, GLCanvas3D& parent); +#else // returns the id of the item under the given mouse position or -1 if none int contains_mouse(const Vec2d& mouse_pos) const; void do_action(unsigned int item_id); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + void render(const GLCanvas3D& parent) const; +#else void render() const; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE private: +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + void calc_layout() const; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE float get_width_horizontal() const; float get_width_vertical() const; float get_height_horizontal() const; float get_height_vertical() const; float get_main_size() const; #if ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + std::string update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent); + std::string update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent); +#else std::string update_hover_state_horizontal(const Vec2d& mouse_pos); std::string update_hover_state_vertical(const Vec2d& mouse_pos); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE +#else +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + void update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent); + void update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent); #else void update_hover_state_horizontal(const Vec2d& mouse_pos); void update_hover_state_vertical(const Vec2d& mouse_pos); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #endif // ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + int contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const; + int contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& parent) const; + + void render_horizontal(const GLCanvas3D& parent) const; + void render_vertical(const GLCanvas3D& parent) const; +#else int contains_mouse_horizontal(const Vec2d& mouse_pos) const; int contains_mouse_vertical(const Vec2d& mouse_pos) const; void render_horizontal() const; void render_vertical() const; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE }; +#if !ENABLE_TOOLBAR_BACKGROUND_TEXTURE class GLRadioToolbarItem { public: @@ -274,6 +422,7 @@ public: void render(const GLCanvas3D& parent) const; }; +#endif // !ENABLE_TOOLBAR_BACKGROUND_TEXTURE } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 724815076..4e14aefe8 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -92,7 +92,11 @@ bool View3D::init(wxWindow* parent, Model* model, DynamicPrintConfig* config, Ba return true; } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void View3D::set_view_toolbar(GLToolbar* toolbar) +#else void View3D::set_view_toolbar(GLRadioToolbar* toolbar) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { if (m_canvas != nullptr) m_canvas->set_view_toolbar(toolbar); @@ -365,7 +369,11 @@ Preview::~Preview() } #if ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +void Preview::set_view_toolbar(GLToolbar* toolbar) +#else void Preview::set_view_toolbar(GLRadioToolbar* toolbar) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { if (m_canvas != nullptr) m_canvas->set_view_toolbar(toolbar); diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index 2aebdccd5..23e6a682f 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -28,9 +28,15 @@ class Model; namespace GUI { class GLCanvas3D; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE +#if ENABLE_REMOVE_TABS_FROM_PLATER +class GLToolbar; +#endif // ENABLE_REMOVE_TABS_FROM_PLATER +#else #if ENABLE_REMOVE_TABS_FROM_PLATER class GLRadioToolbar; #endif // ENABLE_REMOVE_TABS_FROM_PLATER +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #if ENABLE_REMOVE_TABS_FROM_PLATER class View3D : public wxPanel @@ -53,7 +59,11 @@ public: wxGLCanvas* get_wxglcanvas() { return m_canvas_widget; } GLCanvas3D* get_canvas3d() { return m_canvas; } +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + void set_view_toolbar(GLToolbar* toolbar); +#else void set_view_toolbar(GLRadioToolbar* toolbar); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE void set_as_dirty(); void set_bed_shape(const Pointfs& shape); @@ -122,7 +132,11 @@ public: wxGLCanvas* get_wxglcanvas() { return m_canvas_widget; } #if ENABLE_REMOVE_TABS_FROM_PLATER +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + void set_view_toolbar(GLToolbar* toolbar); +#else void set_view_toolbar(GLRadioToolbar* toolbar); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #endif // ENABLE_REMOVE_TABS_FROM_PLATER void set_number_extruders(unsigned int number_extruders); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 381a9e864..8db804c12 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -913,7 +913,11 @@ struct Plater::priv Sidebar *sidebar; #if ENABLE_REMOVE_TABS_FROM_PLATER View3D* view3D; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + GLToolbar view_toolbar; +#else GLRadioToolbar view_toolbar; +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE #else #if !ENABLE_IMGUI wxPanel *panel3d; @@ -1068,6 +1072,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) #endif // !ENABLE_REMOVE_TABS_FROM_PLATER , delayed_scene_refresh(false) , project_filename(wxEmptyString) +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + , view_toolbar(GLToolbar::Radio) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE { arranging.store(false); rotoptimizing.store(false); @@ -1286,7 +1293,9 @@ void Plater::priv::select_view_3D(const std::string& name) else if (name == "Preview") set_current_panel(preview); +#if !ENABLE_TOOLBAR_BACKGROUND_TEXTURE view_toolbar.set_selection(name); +#endif // !ENABLE_TOOLBAR_BACKGROUND_TEXTURE } #else void Plater::priv::select_view(const std::string& direction) @@ -2646,9 +2655,58 @@ bool Plater::priv::complit_init_part_menu() #if ENABLE_REMOVE_TABS_FROM_PLATER void Plater::priv::init_view_toolbar() { +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + ItemsIconsTexture::Metadata icons_data; + icons_data.filename = "view_toolbar.png"; + icons_data.icon_size = 64; + icons_data.icon_border_size = 0; + icons_data.icon_gap_size = 0; + + BackgroundTexture::Metadata background_data; + background_data.filename = "toolbar_background.png"; + background_data.left = 16; + background_data.top = 16; + background_data.right = 16; + background_data.bottom = 16; + + if (!view_toolbar.init(icons_data, background_data)) +#else if (!view_toolbar.init("view_toolbar.png", 64, 0, 0)) +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE return; +#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE + view_toolbar.set_layout_orientation(GLToolbar::Layout::Bottom); + view_toolbar.set_border(5.0f); + view_toolbar.set_gap_size(1.0f); + + GLToolbarItem::Data item; + + item.name = "3D"; + item.tooltip = GUI::L_str("3D editor view"); + item.sprite_id = 0; + item.action_event = EVT_GLVIEWTOOLBAR_3D; + item.is_toggable = false; + if (!view_toolbar.add_item(item)) + return; + + item.name = "Preview"; + item.tooltip = GUI::L_str("Preview"); + item.sprite_id = 1; + item.action_event = EVT_GLVIEWTOOLBAR_PREVIEW; + item.is_toggable = false; + if (!view_toolbar.add_item(item)) + return; + + view_toolbar.enable_item("3D"); + view_toolbar.enable_item("Preview"); + + view_toolbar.select_item("3D"); + view_toolbar.set_enabled(true); + + view3D->set_view_toolbar(&view_toolbar); + preview->set_view_toolbar(&view_toolbar); +#else GLRadioToolbarItem::Data item; item.name = "3D"; @@ -2669,6 +2727,7 @@ void Plater::priv::init_view_toolbar() preview->set_view_toolbar(&view_toolbar); view_toolbar.set_selection("3D"); +#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE } #endif // ENABLE_REMOVE_TABS_FROM_PLATER