Qt: ImGui support

This commit is contained in:
Connor McLaughlin
2020-01-02 19:14:16 +10:00
parent 9de0bf0aaf
commit bea15c97cd
6 changed files with 57 additions and 14 deletions

View File

@ -37,6 +37,11 @@ void QtDisplayWindow::destroyDeviceContext()
bool QtDisplayWindow::createImGuiContext()
{
ImGui::CreateContext();
auto& io = ImGui::GetIO();
io.DisplaySize.x = static_cast<float>(width());
io.DisplaySize.y = static_cast<float>(height());
return true;
}
@ -54,6 +59,17 @@ void QtDisplayWindow::destroyDeviceResources() {}
void QtDisplayWindow::Render() {}
void QtDisplayWindow::onWindowResized(int width, int height)
{
// imgui may not have been initialized yet
if (!ImGui::GetCurrentContext())
return;
auto& io = ImGui::GetIO();
io.DisplaySize.x = static_cast<float>(width);
io.DisplaySize.y = static_cast<float>(height);
}
void QtDisplayWindow::keyPressEvent(QKeyEvent* event)
{
m_host_interface->handleKeyEvent(event->key(), true);
@ -63,3 +79,9 @@ void QtDisplayWindow::keyReleaseEvent(QKeyEvent* event)
{
m_host_interface->handleKeyEvent(event->key(), false);
}
void QtDisplayWindow::resizeEvent(QResizeEvent* event)
{
QWindow::resizeEvent(event);
emit windowResizedEvent(event->size().width(), event->size().height());
}