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

@ -7,10 +7,13 @@
static void InitLogging()
{
// set log flags
// g_pLog->SetConsoleOutputParams(true);
g_pLog->SetConsoleOutputParams(true, nullptr, LOGLEVEL_PROFILE);
g_pLog->SetFilterLevel(LOGLEVEL_PROFILE);
// g_pLog->SetDebugOutputParams(true);
#ifdef Y_BUILD_CONFIG_DEBUG
g_pLog->SetConsoleOutputParams(true, nullptr, LOGLEVEL_DEBUG);
g_pLog->SetFilterLevel(LOGLEVEL_DEBUG);
#else
g_pLog->SetConsoleOutputParams(true, nullptr, LOGLEVEL_INFO);
g_pLog->SetFilterLevel(LOGLEVEL_INFO);
#endif
}
int main(int argc, char* argv[])

View File

@ -371,6 +371,7 @@ bool OpenGLDisplayWindow::createImGuiContext()
return false;
ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame();
return true;
}
@ -464,13 +465,13 @@ void OpenGLDisplayWindow::Render()
renderDisplay();
ImDrawData* draw_data = ImGui::GetDrawData();
if (draw_data)
ImGui_ImplOpenGL3_RenderDrawData(draw_data);
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
m_gl_context->makeCurrent(this);
m_gl_context->swapBuffers(this);
ImGui::NewFrame();
ImGui_ImplOpenGL3_NewFrame();
GL::Program::ResetLastProgram();

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());
}

View File

@ -2,6 +2,7 @@
#include <QtGui/QWindow>
class QKeyEvent;
class QResizeEvent;
class HostDisplay;
@ -23,14 +24,21 @@ public:
virtual void Render();
// this comes back on the emu thread
virtual void onWindowResized(int width, int height);
Q_SIGNALS:
void windowResizedEvent(int width, int height);
protected:
virtual bool createImGuiContext();
virtual void destroyImGuiContext();
virtual bool createDeviceResources();
virtual void destroyDeviceResources();
void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
virtual void keyPressEvent(QKeyEvent* event) override;
virtual void keyReleaseEvent(QKeyEvent* event) override;
virtual void resizeEvent(QResizeEvent* event) override;
QtHostInterface* m_host_interface;
};

View File

@ -130,6 +130,8 @@ void QtHostInterface::refreshGameList(bool invalidate_cache /*= false*/)
QWidget* QtHostInterface::createDisplayWidget(QWidget* parent)
{
m_display_window = new OpenGLDisplayWindow(this, nullptr);
connect(m_display_window, &QtDisplayWindow::windowResizedEvent, this, &QtHostInterface::onDisplayWindowResized);
m_display.release();
m_display = std::unique_ptr<HostDisplay>(m_display_window->getHostDisplayInterface());
return QWidget::createWindowContainer(m_display_window, parent);
@ -176,6 +178,11 @@ void QtHostInterface::doHandleKeyEvent(int key, bool pressed)
iter->second(pressed);
}
void QtHostInterface::onDisplayWindowResized(int width, int height)
{
m_display_window->onWindowResized(width, height);
}
void QtHostInterface::updateInputMap()
{
if (!isOnWorkerThread())
@ -352,16 +359,17 @@ void QtHostInterface::threadEntryPoint()
// rendering
{
// DrawImGui();
if (m_system)
{
DrawDebugWindows();
m_system->GetGPU()->ResetGraphicsAPIState();
}
DrawFPSWindow();
DrawOSDMessages();
// ImGui::Render();
m_display->Render();
// ImGui::NewFrame();
if (m_system)
{
m_system->GetGPU()->RestoreGraphicsAPIState();

View File

@ -67,6 +67,7 @@ private Q_SLOTS:
void doBootSystem(QString initial_filename, QString initial_save_state_filename);
void doUpdateInputMap();
void doHandleKeyEvent(int key, bool pressed);
void onDisplayWindowResized(int width, int height);
private:
class Thread : public QThread