diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 8aa6352f5..53a28ef24 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5230,10 +5230,8 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) #if ENABLE_IMGUI auto imgui = wxGetApp().imgui(); if (imgui->update_key_data(evt)) { + return; render(); - if (imgui->want_any_input()) { - return; - } } #endif // ENABLE_IMGUI @@ -5385,9 +5383,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) auto imgui = wxGetApp().imgui(); if (imgui->update_mouse_data(evt)) { render(); - if (imgui->want_any_input()) { - return; - } + return; } #endif // ENABLE_IMGUI diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 228d336c2..b94aa59d3 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -31,6 +31,7 @@ ImGuiWrapper::ImGuiWrapper() , m_style_scaling(1.0) , m_mouse_buttons(0) , m_disabled(false) + , m_new_frame_open(false) { } @@ -106,9 +107,10 @@ bool ImGuiWrapper::update_mouse_data(wxMouseEvent& evt) io.MouseDown[2] = evt.MiddleDown(); unsigned buttons = (evt.LeftDown() ? 1 : 0) | (evt.RightDown() ? 2 : 0) | (evt.MiddleDown() ? 4 : 0); - bool res = buttons != m_mouse_buttons; m_mouse_buttons = buttons; - return res; + + new_frame(); + return want_mouse(); } bool ImGuiWrapper::update_key_data(wxKeyEvent &evt) @@ -117,7 +119,10 @@ bool ImGuiWrapper::update_key_data(wxKeyEvent &evt) if (evt.GetEventType() == wxEVT_CHAR) { // Char event - io.AddInputCharacter(evt.GetUnicodeKey()); + const auto key = evt.GetUnicodeKey(); + if (key != 0) { + io.AddInputCharacter(key); + } } else { // Key up/down event int key = evt.GetKeyCode(); @@ -130,21 +135,31 @@ bool ImGuiWrapper::update_key_data(wxKeyEvent &evt) io.KeySuper = evt.MetaDown(); } + // XXX: Unfortunatelly this seems broken due to some interference with wxWidgets, + // we have to return true always (perform re-render). + // new_frame(); + // return want_keyboard() || want_text_input(); return true; } void ImGuiWrapper::new_frame() { + if (m_new_frame_open) { + return; + } + if (m_font_texture == 0) create_device_objects(); ImGui::NewFrame(); + m_new_frame_open = true; } void ImGuiWrapper::render() { ImGui::Render(); render_draw_data(ImGui::GetDrawData()); + m_new_frame_open = false; } void ImGuiWrapper::set_next_window_pos(float x, float y, int flag) @@ -492,8 +507,8 @@ const char* ImGuiWrapper::clipboard_get(void* user_data) wxTheClipboard->GetData(data); if (data.GetTextLength() > 0) { - self->clipboard_text = into_u8(data.GetText()); - res = self->clipboard_text.c_str(); + self->m_clipboard_text = into_u8(data.GetText()); + res = self->m_clipboard_text.c_str(); } } diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index b0b5cc858..ac77ab17f 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -26,6 +26,8 @@ class ImGuiWrapper float m_style_scaling; unsigned m_mouse_buttons; bool m_disabled; + bool m_new_frame_open; + std::string m_clipboard_text; public: ImGuiWrapper(); @@ -67,8 +69,6 @@ public: bool want_any_input() const; private: - std::string clipboard_text; - void init_default_font(float scaling); void create_device_objects(); void create_fonts_texture();