imgui: Input fixes
This commit is contained in:
parent
5de52b7da4
commit
1045b43d4f
3 changed files with 24 additions and 13 deletions
|
@ -5230,10 +5230,8 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
|
||||||
#if ENABLE_IMGUI
|
#if ENABLE_IMGUI
|
||||||
auto imgui = wxGetApp().imgui();
|
auto imgui = wxGetApp().imgui();
|
||||||
if (imgui->update_key_data(evt)) {
|
if (imgui->update_key_data(evt)) {
|
||||||
|
return;
|
||||||
render();
|
render();
|
||||||
if (imgui->want_any_input()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif // ENABLE_IMGUI
|
#endif // ENABLE_IMGUI
|
||||||
|
|
||||||
|
@ -5385,9 +5383,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||||
auto imgui = wxGetApp().imgui();
|
auto imgui = wxGetApp().imgui();
|
||||||
if (imgui->update_mouse_data(evt)) {
|
if (imgui->update_mouse_data(evt)) {
|
||||||
render();
|
render();
|
||||||
if (imgui->want_any_input()) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif // ENABLE_IMGUI
|
#endif // ENABLE_IMGUI
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ ImGuiWrapper::ImGuiWrapper()
|
||||||
, m_style_scaling(1.0)
|
, m_style_scaling(1.0)
|
||||||
, m_mouse_buttons(0)
|
, m_mouse_buttons(0)
|
||||||
, m_disabled(false)
|
, m_disabled(false)
|
||||||
|
, m_new_frame_open(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,9 +107,10 @@ bool ImGuiWrapper::update_mouse_data(wxMouseEvent& evt)
|
||||||
io.MouseDown[2] = evt.MiddleDown();
|
io.MouseDown[2] = evt.MiddleDown();
|
||||||
|
|
||||||
unsigned buttons = (evt.LeftDown() ? 1 : 0) | (evt.RightDown() ? 2 : 0) | (evt.MiddleDown() ? 4 : 0);
|
unsigned buttons = (evt.LeftDown() ? 1 : 0) | (evt.RightDown() ? 2 : 0) | (evt.MiddleDown() ? 4 : 0);
|
||||||
bool res = buttons != m_mouse_buttons;
|
|
||||||
m_mouse_buttons = buttons;
|
m_mouse_buttons = buttons;
|
||||||
return res;
|
|
||||||
|
new_frame();
|
||||||
|
return want_mouse();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGuiWrapper::update_key_data(wxKeyEvent &evt)
|
bool ImGuiWrapper::update_key_data(wxKeyEvent &evt)
|
||||||
|
@ -117,7 +119,10 @@ bool ImGuiWrapper::update_key_data(wxKeyEvent &evt)
|
||||||
|
|
||||||
if (evt.GetEventType() == wxEVT_CHAR) {
|
if (evt.GetEventType() == wxEVT_CHAR) {
|
||||||
// Char event
|
// Char event
|
||||||
io.AddInputCharacter(evt.GetUnicodeKey());
|
const auto key = evt.GetUnicodeKey();
|
||||||
|
if (key != 0) {
|
||||||
|
io.AddInputCharacter(key);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Key up/down event
|
// Key up/down event
|
||||||
int key = evt.GetKeyCode();
|
int key = evt.GetKeyCode();
|
||||||
|
@ -130,21 +135,31 @@ bool ImGuiWrapper::update_key_data(wxKeyEvent &evt)
|
||||||
io.KeySuper = evt.MetaDown();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiWrapper::new_frame()
|
void ImGuiWrapper::new_frame()
|
||||||
{
|
{
|
||||||
|
if (m_new_frame_open) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_font_texture == 0)
|
if (m_font_texture == 0)
|
||||||
create_device_objects();
|
create_device_objects();
|
||||||
|
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
m_new_frame_open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiWrapper::render()
|
void ImGuiWrapper::render()
|
||||||
{
|
{
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
render_draw_data(ImGui::GetDrawData());
|
render_draw_data(ImGui::GetDrawData());
|
||||||
|
m_new_frame_open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiWrapper::set_next_window_pos(float x, float y, int flag)
|
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);
|
wxTheClipboard->GetData(data);
|
||||||
|
|
||||||
if (data.GetTextLength() > 0) {
|
if (data.GetTextLength() > 0) {
|
||||||
self->clipboard_text = into_u8(data.GetText());
|
self->m_clipboard_text = into_u8(data.GetText());
|
||||||
res = self->clipboard_text.c_str();
|
res = self->m_clipboard_text.c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ class ImGuiWrapper
|
||||||
float m_style_scaling;
|
float m_style_scaling;
|
||||||
unsigned m_mouse_buttons;
|
unsigned m_mouse_buttons;
|
||||||
bool m_disabled;
|
bool m_disabled;
|
||||||
|
bool m_new_frame_open;
|
||||||
|
std::string m_clipboard_text;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ImGuiWrapper();
|
ImGuiWrapper();
|
||||||
|
@ -67,8 +69,6 @@ public:
|
||||||
bool want_any_input() const;
|
bool want_any_input() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string clipboard_text;
|
|
||||||
|
|
||||||
void init_default_font(float scaling);
|
void init_default_font(float scaling);
|
||||||
void create_device_objects();
|
void create_device_objects();
|
||||||
void create_fonts_texture();
|
void create_fonts_texture();
|
||||||
|
|
Loading…
Add table
Reference in a new issue