diff --git a/resources/icons/sla_view_original.svg b/resources/icons/sla_view_original.svg new file mode 100644 index 000000000..4691721c8 --- /dev/null +++ b/resources/icons/sla_view_original.svg @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + diff --git a/resources/icons/sla_view_processed.svg b/resources/icons/sla_view_processed.svg new file mode 100644 index 000000000..a26a0db2f --- /dev/null +++ b/resources/icons/sla_view_processed.svg @@ -0,0 +1,56 @@ + + + + + + + + + + + diff --git a/src/imgui/imconfig.h b/src/imgui/imconfig.h index dff8aea9f..5aed97842 100644 --- a/src/imgui/imconfig.h +++ b/src/imgui/imconfig.h @@ -166,6 +166,8 @@ namespace ImGui const wchar_t PauseHoverButton = 0x261B; const wchar_t OpenButton = 0x261C; const wchar_t OpenHoverButton = 0x261D; + const wchar_t SlaViewOriginal = 0x261E; + const wchar_t SlaViewProcessed = 0x261F; const wchar_t LegendTravel = 0x2701; const wchar_t LegendWipe = 0x2702; diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 62d4314db..20ba4a216 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -4049,69 +4049,58 @@ void GCodeViewer::render_legend(float& legend_height) } }; - auto image_icon = [&imgui](ImGuiWindow& window, const ImVec2& pos, float size, const wchar_t& icon_id) { - ImGuiIO& io = ImGui::GetIO(); - const ImTextureID tex_id = io.Fonts->TexID; - const float tex_w = static_cast(io.Fonts->TexWidth); - const float tex_h = static_cast(io.Fonts->TexHeight); - const ImFontAtlas::CustomRect* const rect = imgui.GetTextureCustomRect(icon_id); - const ImVec2 uv0 = { static_cast(rect->X) / tex_w, static_cast(rect->Y) / tex_h }; - const ImVec2 uv1 = { static_cast(rect->X + rect->Width) / tex_w, static_cast(rect->Y + rect->Height) / tex_h }; - window.DrawList->AddImage(tex_id, pos, { pos.x + size, pos.y + size }, uv0, uv1, ImGuiWrapper::to_ImU32({ 1.0f, 1.0f, 1.0f, 1.0f })); - }; - ImGui::Spacing(); ImGui::Separator(); ImGui::Spacing(); ImGui::Spacing(); - toggle_button(Preview::OptionType::Travel, _u8L("Travel"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendTravel); + toggle_button(Preview::OptionType::Travel, _u8L("Travel"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendTravel); }); ImGui::SameLine(); - toggle_button(Preview::OptionType::Wipe, _u8L("Wipe"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendWipe); + toggle_button(Preview::OptionType::Wipe, _u8L("Wipe"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendWipe); }); ImGui::SameLine(); - toggle_button(Preview::OptionType::Retractions, _u8L("Retractions"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendRetract); + toggle_button(Preview::OptionType::Retractions, _u8L("Retractions"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendRetract); }); ImGui::SameLine(); - toggle_button(Preview::OptionType::Unretractions, _u8L("Deretractions"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendDeretract); + toggle_button(Preview::OptionType::Unretractions, _u8L("Deretractions"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendDeretract); }); ImGui::SameLine(); - toggle_button(Preview::OptionType::Seams, _u8L("Seams"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendSeams); + toggle_button(Preview::OptionType::Seams, _u8L("Seams"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendSeams); }); ImGui::SameLine(); - toggle_button(Preview::OptionType::ToolChanges, _u8L("Tool changes"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendToolChanges); + toggle_button(Preview::OptionType::ToolChanges, _u8L("Tool changes"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendToolChanges); }); ImGui::SameLine(); - toggle_button(Preview::OptionType::ColorChanges, _u8L("Color changes"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendColorChanges); + toggle_button(Preview::OptionType::ColorChanges, _u8L("Color changes"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendColorChanges); }); ImGui::SameLine(); - toggle_button(Preview::OptionType::PausePrints, _u8L("Print pauses"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendPausePrints); + toggle_button(Preview::OptionType::PausePrints, _u8L("Print pauses"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendPausePrints); }); ImGui::SameLine(); - toggle_button(Preview::OptionType::CustomGCodes, _u8L("Custom G-codes"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendCustomGCodes); + toggle_button(Preview::OptionType::CustomGCodes, _u8L("Custom G-codes"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendCustomGCodes); }); ImGui::SameLine(); - toggle_button(Preview::OptionType::CenterOfGravity, _u8L("Center of gravity"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendCOG); + toggle_button(Preview::OptionType::CenterOfGravity, _u8L("Center of gravity"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendCOG); }); ImGui::SameLine(); if (!wxGetApp().is_gcode_viewer()) { - toggle_button(Preview::OptionType::Shells, _u8L("Shells"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendShells); + toggle_button(Preview::OptionType::Shells, _u8L("Shells"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendShells); }); ImGui::SameLine(); } - toggle_button(Preview::OptionType::ToolMarker, _u8L("Tool marker"), [image_icon](ImGuiWindow& window, const ImVec2& pos, float size) { - image_icon(window, pos, size, ImGui::LegendToolMarker); + toggle_button(Preview::OptionType::ToolMarker, _u8L("Tool marker"), [&imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + imgui.draw_icon(window, pos, size, ImGui::LegendToolMarker); }); bool size_dirty = !ImGui::GetCurrentWindow()->ScrollbarY && ImGui::CalcWindowNextAutoFitSize(ImGui::GetCurrentWindow()).x != ImGui::GetWindowWidth(); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 4decbdab9..fe0a7b724 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1146,15 +1146,41 @@ void GLCanvas3D::SLAView::render_switch_button() ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.0f, 0.0f, 0.0f, 0.0f)); ImGui::SetNextWindowPos(ImVec2((float)ss_box.max.x(), (float)ss_box.center().y()), ImGuiCond_Always, ImVec2(0.0, 0.5)); imgui.begin(std::string("SLAViewSwitch"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration); - const wxString btn_text = (m_type == ESLAViewType::Original) ? _L("Processed") : _L("Original"); - if (imgui.button(btn_text)) { + const float icon_size = 1.5 * ImGui::GetTextLineHeight(); + if (imgui.draw_radio_button(_u8L("SLA view"), 1.5f * icon_size, true, [this, &imgui](ImGuiWindow& window, const ImVec2& pos, float size) { + wchar_t icon_id; + switch (m_type) + { + case ESLAViewType::Original: { icon_id = ImGui::SlaViewProcessed; break; } + case ESLAViewType::Processed: { icon_id = ImGui::SlaViewOriginal; break; } + default: { assert(false); break; } + } + imgui.draw_icon(window, pos, size, icon_id); + + })) { switch (m_type) { case ESLAViewType::Original: { m_parent.set_sla_view_type(ESLAViewType::Processed); break; } case ESLAViewType::Processed: { m_parent.set_sla_view_type(ESLAViewType::Original); break; } - default: { assert(false); break; } + default: { assert(false); break; } } } + + if (ImGui::IsItemHovered()) { + ImGui::PushStyleColor(ImGuiCol_PopupBg, ImGuiWrapper::COL_WINDOW_BACKGROUND); + ImGui::BeginTooltip(); + wxString tooltip; + switch (m_type) + { + case ESLAViewType::Original: { tooltip = _L("Show as processed"); break; } + case ESLAViewType::Processed: { tooltip = _L("Show as original"); break; } + default: { assert(false); break; } + } + + imgui.text(tooltip); + ImGui::EndTooltip(); + ImGui::PopStyleColor(); + } imgui.end(); ImGui::PopStyleColor(2); } diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 55bf57602..3d2b92610 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -104,6 +104,8 @@ static const std::map font_icons_large = { {ImGui::PauseHoverButton , "notification_pause_hover" }, {ImGui::OpenButton , "notification_open" }, {ImGui::OpenHoverButton , "notification_open_hover" }, + {ImGui::SlaViewOriginal , "sla_view_original" }, + {ImGui::SlaViewProcessed , "sla_view_processed" }, }; static const std::map font_icons_extra_large = { @@ -490,6 +492,18 @@ bool ImGuiWrapper::radio_button(const wxString &label, bool active) return ImGui::RadioButton(label_utf8.c_str(), active); } +void ImGuiWrapper::draw_icon(ImGuiWindow& window, const ImVec2& pos, float size, wchar_t icon_id) +{ + ImGuiIO& io = ImGui::GetIO(); + const ImTextureID tex_id = io.Fonts->TexID; + const float tex_w = static_cast(io.Fonts->TexWidth); + const float tex_h = static_cast(io.Fonts->TexHeight); + const ImFontAtlas::CustomRect* const rect = GetTextureCustomRect(icon_id); + const ImVec2 uv0 = { static_cast(rect->X) / tex_w, static_cast(rect->Y) / tex_h }; + const ImVec2 uv1 = { static_cast(rect->X + rect->Width) / tex_w, static_cast(rect->Y + rect->Height) / tex_h }; + window.DrawList->AddImage(tex_id, pos, { pos.x + size, pos.y + size }, uv0, uv1, ImGuiWrapper::to_ImU32({ 1.0f, 1.0f, 1.0f, 1.0f })); +} + bool ImGuiWrapper::draw_radio_button(const std::string& name, float size, bool active, std::function draw_callback) { diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index 077bf568d..d95b934f1 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -92,9 +92,10 @@ public: void end(); bool button(const wxString &label, const wxString& tooltip = {}); - bool button(const wxString& label, float width, float height); + bool button(const wxString& label, float width, float height); bool button(const wxString& label, const ImVec2 &size, bool enable); // default size = ImVec2(0.f, 0.f) bool radio_button(const wxString &label, bool active); + void draw_icon(ImGuiWindow& window, const ImVec2& pos, float size, wchar_t icon_id); bool draw_radio_button(const std::string& name, float size, bool active, std::function draw_callback); bool checkbox(const wxString &label, bool &value); static void text(const char *label);