diff options
author | Clifford Wolf <clifford@clifford.at> | 2018-11-09 12:57:14 +0100 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2018-11-09 12:57:14 +0100 |
commit | 66dd17664c08aca17b53d2853558121aa9e702e4 (patch) | |
tree | b6bc5dd919e5f525ec7328861b81f616673a1ea6 /3rdparty/qtimgui/demo-widget/demo-widget.cpp | |
parent | e91241f10d68fcaaf0a81fa77e9a91666120ccee (diff) | |
parent | 15d9b3d3cc05656e58d01ba2f97ec92b6daaee1c (diff) | |
download | nextpnr-66dd17664c08aca17b53d2853558121aa9e702e4.tar.gz nextpnr-66dd17664c08aca17b53d2853558121aa9e702e4.tar.bz2 nextpnr-66dd17664c08aca17b53d2853558121aa9e702e4.zip |
Merge branch 'master' of github.com:YosysHQ/nextpnr into router_improve
Diffstat (limited to '3rdparty/qtimgui/demo-widget/demo-widget.cpp')
-rw-r--r-- | 3rdparty/qtimgui/demo-widget/demo-widget.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/3rdparty/qtimgui/demo-widget/demo-widget.cpp b/3rdparty/qtimgui/demo-widget/demo-widget.cpp new file mode 100644 index 00000000..f0c44bef --- /dev/null +++ b/3rdparty/qtimgui/demo-widget/demo-widget.cpp @@ -0,0 +1,85 @@ +#include <QtImGui.h> +#include <imgui.h> +#include <QApplication> +#include <QTimer> +#include <QSurfaceFormat> +#include <QOpenGLWidget> +#include <QOpenGLExtraFunctions> + +class DemoWindow : public QOpenGLWidget, private QOpenGLExtraFunctions +{ +protected: + void initializeGL() override + { + initializeOpenGLFunctions(); + QtImGui::initialize(this); + } + void paintGL() override + { + QtImGui::newFrame(); + + // 1. Show a simple window + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" + { + static float f = 0.0f; + ImGui::Text("Hello, world!"); + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); + ImGui::ColorEdit3("clear color", (float*)&clear_color); + if (ImGui::Button("Test Window")) show_test_window ^= 1; + if (ImGui::Button("Another Window")) show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + } + + // 2. Show another simple window, this time using an explicit Begin/End pair + if (show_another_window) + { + ImGui::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver); + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello"); + ImGui::End(); + } + + // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() + if (show_test_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver); + ImGui::ShowTestWindow(); + } + + // Do render before ImGui UI is rendered + glViewport(0, 0, width(), height()); + glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); + glClear(GL_COLOR_BUFFER_BIT); + + ImGui::Render(); + } + +private: + bool show_test_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImColor(114, 144, 154); +}; + +int main(int argc, char *argv[]) +{ + // Use OpenGL 3 Core Profile + QSurfaceFormat glFormat; + glFormat.setVersion(3, 3); + glFormat.setProfile(QSurfaceFormat::CoreProfile); + QSurfaceFormat::setDefaultFormat(glFormat); + + QApplication a(argc, argv); + + // Show window + DemoWindow w; + w.setWindowTitle("QtImGui widget example"); + w.resize(1280, 720); + w.show(); + + // Update at 60 fps + QTimer timer; + QObject::connect(&timer, SIGNAL(timeout()), &w, SLOT(update())); + timer.start(16); + + return a.exec(); +} |