Skip to content

Commit

Permalink
Merge pull request #44 from moezb/master
Browse files Browse the repository at this point in the history
Upgrade to > Qt5.15 -6 and ImGUI > v1.87 + fixes keyboard and mouse handling & widget samples
  • Loading branch information
seanchas116 committed Apr 14, 2023
2 parents 52dd94b + f65a0b2 commit 3ce55a3
Show file tree
Hide file tree
Showing 15 changed files with 693 additions and 240 deletions.
52 changes: 27 additions & 25 deletions examples/multiple/demo-widgets.cpp
Expand Up @@ -20,12 +20,9 @@ class DemoWindow
{
initializeOpenGLFunctions();
ref = QtImGui::initialize(this, false);

// Update at 60 fps
auto* timer = new QTimer(this);
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(16);

// Update at 60 fps
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
timer.start(16);
// create plot context
ctx = ImPlot::CreateContext();
}
Expand All @@ -47,26 +44,28 @@ class DemoWindow
ImGui::SetNextWindowSize(use_work_area ? viewport->WorkSize : viewport->Size);

if (ImGui::Begin("Example: Fullscreen window", nullptr, flags)) {
ImGui::BulletText("Click and drag the horizontal and vertical lines.");

ImGui::Checkbox("Show Labels##1", &show_labels);
if (ImPlot::BeginPlot("##guides", 0, 0, ImVec2(-1, -1), ImPlotFlags_YAxis2)) {
ImPlot::DragLineX("x1", &x1, show_labels);
ImPlot::DragLineX("x2", &x2, show_labels);
ImPlot::DragLineY("y1", &y1, show_labels);
ImPlot::DragLineY("y2", &y2, show_labels);
double xs[1000], ys[1000];
for (int i = 0; i < 1000; ++i) {
xs[i] = (x2 + x1) / 2 + abs(x2 - x1) * (i / 1000.0f - 0.5f);
ys[i] = (y1 + y2) / 2 + abs(y2 - y1) / 2 * sin(f * i / 10);
ImGui::InputTextWithHint("input text (w/ hint)", "enter text here", input_text, IM_ARRAYSIZE(input_text));
ImGui::BulletText("Click and drag the horizontal and vertical lines.");
ImGui::CheckboxFlags("NoCursors", (unsigned int*)&drag_flags, ImPlotDragToolFlags_NoCursors); ImGui::SameLine();
ImGui::CheckboxFlags("NoFit", (unsigned int*)&drag_flags, ImPlotDragToolFlags_NoFit); ImGui::SameLine();
ImGui::CheckboxFlags("NoInput", (unsigned int*)&drag_flags, ImPlotDragToolFlags_NoInputs);
if (ImPlot::BeginPlot("##lines",ImVec2(-1,0))) {
ImPlot::SetupAxesLimits(0,1,0,1);
ImPlot::DragLineX(0,&x1,ImVec4(1,1,1,1),1,drag_flags);
ImPlot::DragLineX(1,&x2,ImVec4(1,1,1,1),1,drag_flags);
ImPlot::DragLineY(2,&y1,ImVec4(1,1,1,1),1,drag_flags);
ImPlot::DragLineY(3,&y2,ImVec4(1,1,1,1),1,drag_flags);
double xs[1000], ys[1000];
for (int i = 0; i < 1000; ++i) {
xs[i] = (x2+x1)/2+fabs(x2-x1)*(i/1000.0f - 0.5f);
ys[i] = (y1+y2)/2+fabs(y2-y1)/2*sin(f*i/10);
}
ImPlot::PlotLine("Interactive Data", xs, ys, 1000);
ImPlot::DragLineY(120482,&f,ImVec4(1,0.5f,1,1),1,drag_flags);
ImPlot::EndPlot();
}
ImPlot::PlotLine("Interactive Data", xs, ys, 1000);
ImPlot::SetPlotYAxis(ImPlotYAxis_2);
ImPlot::DragLineY("f", &f, show_labels, ImVec4(1, 0.5f, 1, 1));
ImPlot::EndPlot();
}
}
ImGui::End();
ImGui::End();
}

// Do render before ImGui UI is rendered
glViewport(0, 0, width(), height());
Expand All @@ -86,8 +85,11 @@ class DemoWindow
double y1 = 0.25;
double y2 = 0.75;
double f = 0.1;
ImPlotDragToolFlags drag_flags = ImPlotDragToolFlags_None;
bool show_labels = true;
ImPlotContext* ctx = nullptr;
QTimer timer;
char input_text[128] = "";
};

int main(int argc, char* argv[])
Expand Down
43 changes: 29 additions & 14 deletions examples/widget/demo-widget.cpp
@@ -1,3 +1,4 @@
#include <QGridLayout>
#include <QtImGui.h>
#include <imgui.h>
#include <QApplication>
Expand All @@ -7,17 +8,26 @@
#include <QOpenGLExtraFunctions>
#include <implot.h>

class DemoWindow : public QOpenGLWidget, private QOpenGLExtraFunctions
class DemoWidget : public QOpenGLWidget, private QOpenGLExtraFunctions
{

protected:
void initializeGL() override
{
initializeOpenGLFunctions();
QtImGui::initialize(this);
ref = QtImGui::initialize(this,false);
// Update at 60 fps
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
timer.start(16);
im_context = ImPlot::CreateContext();
}


void paintGL() override
{
QtImGui::newFrame();
QtImGui::newFrame(ref);
//ImGui::GetIO().BackendFlags = ImGui::GetIO().BackendFlags | ImGuiBackendFlags_RendererHasVtxOffset;
//auto test =(ImGui::GetIO().BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset);

// 1. Show a simple window
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
Expand All @@ -42,9 +52,8 @@ class DemoWindow : public QOpenGLWidget, private QOpenGLExtraFunctions
if (show_implot_demo_window)
{
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver);
ImPlot::CreateContext();
ImPlot::SetCurrentContext(im_context);
ImPlot::ShowDemoWindow(&show_implot_demo_window);
ImPlot::DestroyContext();
}

// Do render before ImGui UI is rendered
Expand All @@ -53,13 +62,17 @@ class DemoWindow : public QOpenGLWidget, private QOpenGLExtraFunctions
glClear(GL_COLOR_BUFFER_BIT);

ImGui::Render();
QtImGui::render();
QtImGui::render(ref);
}

private:
bool show_imgui_demo_window = true;
bool show_implot_demo_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);
ImPlotContext * im_context;
QtImGui::RenderRef ref = nullptr;
QTimer timer{this};

};

int main(int argc, char *argv[])
Expand All @@ -68,22 +81,24 @@ int main(int argc, char *argv[])

// Use OpenGL 3 Core Profile, when available
QSurfaceFormat glFormat;
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL)
{
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
glFormat.setVersion(3, 3);
glFormat.setProfile(QSurfaceFormat::CoreProfile);
}
QSurfaceFormat::setDefaultFormat(glFormat);

// Show window
DemoWindow w;
w.setWindowTitle("QtImGui widget example");
w.resize(1280, 720);
w.show();

DemoWidget *widget=new DemoWidget();
widget->setWindowTitle("QtImGui widget example");
QWidget* window=new QWidget();
auto* l = new QGridLayout();
window->setLayout(l);
l->addWidget(widget, 0, 0);
window->resize(1280, 720);
window->show();
// Update at 60 fps
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), &w, SLOT(update()));
QObject::connect(&timer, SIGNAL(timeout()), widget, SLOT(update()));
timer.start(16);

return a.exec();
Expand Down
1 change: 1 addition & 0 deletions examples/window/CMakeLists.txt
Expand Up @@ -4,6 +4,7 @@ else()
add_executable(qt_imgui_demo_window demo-window.cpp)
endif()
target_link_libraries(qt_imgui_demo_window PRIVATE qt_imgui_quick)
target_link_libraries(qt_imgui_demo_window PRIVATE implot)

if(ANDROID)
include(${CMAKE_CURRENT_LIST_DIR}/../../tools/qt-android-cmake/AddQtAndroidApk.cmake)
Expand Down
10 changes: 5 additions & 5 deletions examples/window/demo-window.cpp
Expand Up @@ -5,6 +5,7 @@
#include <QSurfaceFormat>
#include <QOpenGLWindow>
#include <QOpenGLExtraFunctions>
#include <implot.h>

class DemoWindow : public QOpenGLWindow, private QOpenGLExtraFunctions
{
Expand All @@ -13,6 +14,9 @@ class DemoWindow : public QOpenGLWindow, private QOpenGLExtraFunctions
{
initializeOpenGLFunctions();
QtImGui::initialize(this);
// Update at 60 fps
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
timer.start(16);
}
void paintGL() override
{
Expand Down Expand Up @@ -59,6 +63,7 @@ class DemoWindow : public QOpenGLWindow, private QOpenGLExtraFunctions
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);
QTimer timer;
};

int main(int argc, char *argv[])
Expand All @@ -80,10 +85,5 @@ int main(int argc, char *argv[])
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();
}
2 changes: 1 addition & 1 deletion modules/imgui
Submodule imgui updated 92 files
+1 −1 .github/issue_template.md
+1 −1 .github/pull_request_template.md
+27 −15 .github/workflows/build.yml
+1 −1 LICENSE.txt
+149 −45 backends/imgui_impl_allegro5.cpp
+2 −1 backends/imgui_impl_allegro5.h
+140 −51 backends/imgui_impl_android.cpp
+3 −2 backends/imgui_impl_android.h
+5 −4 backends/imgui_impl_dx10.cpp
+5 −4 backends/imgui_impl_dx11.cpp
+4 −3 backends/imgui_impl_dx12.cpp
+1 −2 backends/imgui_impl_dx12.h
+2 −2 backends/imgui_impl_dx9.cpp
+341 −134 backends/imgui_impl_glfw.cpp
+12 −7 backends/imgui_impl_glfw.h
+151 −71 backends/imgui_impl_glut.cpp
+3 −1 backends/imgui_impl_glut.h
+39 −1 backends/imgui_impl_metal.h
+283 −273 backends/imgui_impl_metal.mm
+2 −1 backends/imgui_impl_opengl2.cpp
+94 −16 backends/imgui_impl_opengl3.cpp
+1 −1 backends/imgui_impl_opengl3.h
+138 −109 backends/imgui_impl_opengl3_loader.h
+3 −3 backends/imgui_impl_osx.h
+380 −178 backends/imgui_impl_osx.mm
+256 −141 backends/imgui_impl_sdl.cpp
+4 −3 backends/imgui_impl_sdl.h
+4 −2 backends/imgui_impl_sdlrenderer.cpp
+66 −33 backends/imgui_impl_vulkan.cpp
+20 −14 backends/imgui_impl_vulkan.h
+3 −2 backends/imgui_impl_wgpu.cpp
+271 −109 backends/imgui_impl_win32.cpp
+5 −3 backends/imgui_impl_win32.h
+3 −3 docs/BACKENDS.md
+325 −44 docs/CHANGELOG.txt
+77 −0 docs/CONTRIBUTING.md
+50 −46 docs/EXAMPLES.md
+8 −8 docs/FAQ.md
+8 −4 docs/FONTS.md
+36 −42 docs/README.md
+35 −69 docs/TODO.txt
+2 −2 examples/example_allegro5/main.cpp
+17 −42 examples/example_apple_metal/main.mm
+0 −29 examples/example_apple_opengl2/main.mm
+2 −2 examples/example_emscripten_opengl3/main.cpp
+2 −2 examples/example_emscripten_wgpu/main.cpp
+1 −1 examples/example_glfw_metal/Makefile
+2 −2 examples/example_glfw_metal/main.mm
+1 −1 examples/example_glfw_opengl2/Makefile
+2 −2 examples/example_glfw_opengl2/main.cpp
+1 −1 examples/example_glfw_opengl3/Makefile
+2 −2 examples/example_glfw_opengl3/main.cpp
+1 −0 examples/example_glfw_vulkan/CMakeLists.txt
+2 −2 examples/example_glfw_vulkan/build_win32.bat
+2 −2 examples/example_glfw_vulkan/build_win64.bat
+4 −0 examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj
+5 −3 examples/example_glfw_vulkan/main.cpp
+1 −1 examples/example_glut_opengl2/Makefile
+3 −2 examples/example_glut_opengl2/main.cpp
+2 −2 examples/example_null/Makefile
+2 −2 examples/example_sdl_directx11/main.cpp
+1 −1 examples/example_sdl_metal/Makefile
+2 −2 examples/example_sdl_metal/main.mm
+1 −1 examples/example_sdl_opengl2/Makefile
+2 −2 examples/example_sdl_opengl2/main.cpp
+1 −1 examples/example_sdl_opengl3/Makefile
+2 −2 examples/example_sdl_opengl3/main.cpp
+1 −1 examples/example_sdl_sdlrenderer/Makefile
+5 −5 examples/example_sdl_sdlrenderer/main.cpp
+1 −1 examples/example_sdl_vulkan/build_win32.bat
+4 −0 examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj
+5 −3 examples/example_sdl_vulkan/main.cpp
+5 −4 examples/example_win32_directx10/main.cpp
+5 −4 examples/example_win32_directx11/main.cpp
+5 −4 examples/example_win32_directx12/main.cpp
+5 −4 examples/example_win32_directx9/main.cpp
+13 −11 imconfig.h
+1,539 −722 imgui.cpp
+370 −221 imgui.h
+184 −75 imgui_demo.cpp
+46 −68 imgui_draw.cpp
+244 −126 imgui_internal.h
+49 −30 imgui_tables.cpp
+442 −353 imgui_widgets.cpp
+15 −27 imstb_rectpack.h
+6 −8 imstb_textedit.h
+502 −320 imstb_truetype.h
+0 −4 misc/cpp/imgui_stdlib.cpp
+0 −4 misc/cpp/imgui_stdlib.h
+26 −23 misc/fonts/binary_to_compressed_c.cpp
+3 −3 misc/freetype/README.md
+1 −1 misc/freetype/imgui_freetype.cpp
2 changes: 1 addition & 1 deletion modules/implot
26 changes: 21 additions & 5 deletions src/CMakeLists.txt
Expand Up @@ -4,13 +4,23 @@ project(qtimgui)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5 COMPONENTS Core Quick Gui Widgets REQUIRED)

# We're using qt versionless targets so our minimal Qt version is 5.15, we support Qt6 as well
# See https://www.qt.io/blog/versionless-cmake-targets-qt-5.15
find_package(Qt6 COMPONENTS COMPONENTS Core Quick Gui Widgets OpenGLWidgets )
if (NOT Qt6_FOUND)
find_package(Qt5 5.15 REQUIRED COMPONENTS Core Quick Gui Widgets)
if (NOT Qt5_FOUND)
message(FATAL_ERROR "We only support only Qt 5.15 and higher.")
endif()
endif()

message(STATUS Qt ${QT_DEFAULT_MAJOR_VERSION})

set(
qt_imgui_sources
ImGuiRenderer.h
key_mappings.h
ImGuiRenderer.cpp
QtImGui.h
QtImGui.cpp
)

Expand All @@ -21,7 +31,10 @@ target_link_libraries(
qt_imgui_quick
PUBLIC
imgui
Qt5::Gui
Qt::Gui
# We use the new Qt Rendering Hardware Interface (RHI) when buzilding with Qt and thgus we need openglwidgets qt module
# see https://www.qt.io/blog/qt-5.15-released
$<$<BOOL:${Qt6_FOUND}>:Qt::OpenGLWidgets>
)
if (ANDROID)
target_link_libraries(qt_imgui_quick PUBLIC log dl GLESv2 z)
Expand All @@ -34,7 +47,10 @@ target_link_libraries(
qt_imgui_widgets
PUBLIC
imgui
Qt5::Widgets
Qt::Widgets
# We use the new Qt Rendering Hardware Interface (RHI) when buzilding with Qt and thgus we need openglwidgets qt module
# see https://www.qt.io/blog/qt-5.15-released
$<$<BOOL:${Qt6_FOUND}>:Qt::OpenGLWidgets>
)
if (ANDROID)
target_link_libraries(qt_imgui_widgets PUBLIC log dl GLESv2 z)
Expand Down

0 comments on commit 3ce55a3

Please sign in to comment.