diff --git a/examples/Demo/LogoMini.png b/examples/Demo/LogoMini.png new file mode 100644 index 0000000..18ea8c4 Binary files /dev/null and b/examples/Demo/LogoMini.png differ diff --git a/examples/Demo/main.cpp b/examples/Demo/main.cpp new file mode 100644 index 0000000..e497cbf --- /dev/null +++ b/examples/Demo/main.cpp @@ -0,0 +1,94 @@ + +#include +#include +#include + +#include + +struct MyImguiWindow + : private Nz::ImguiHandler +{ + MyImguiWindow() + { + Nz::Imgui::Instance()->AddHandler(this); + } + + ~MyImguiWindow() + { + Nz::Imgui::Instance()->RemoveHandler(this); + } + + void OnRenderImgui() override + { + ImGui::Begin("Handler Window"); + ImGui::InputFloat4("position", values); + ImGui::End(); + } + + float values[4] = { 0 }; +}; + +int WinMain(int argc, char* argv[]) +{ + NazaraUnused(argc); + NazaraUnused(argv); + + Nz::Modules nazara; + + // Load test texture + Nz::TextureParams texParams; + texParams.renderDevice = Nz::Graphics::Instance()->GetRenderDevice(); + texParams.loadFormat = Nz::PixelFormat::RGBA8; + auto logo = Nz::Texture::LoadFromFile("LogoMini.png", texParams); + + std::string windowTitle = "Nazara Imgui Demo"; + Nz::RenderWindow window; + if (!window.Create(Nz::Graphics::Instance()->GetRenderDevice(), Nz::VideoMode(1280, 720, 32), windowTitle)) + return false; + + // connect basic handler + window.GetEventHandler().OnQuit.Connect([&window](const auto* handler) { + NazaraUnused(handler); + window.Close(); + }); + + Nz::Imgui::Instance()->Init(window); + + MyImguiWindow mywindow; + float val = 0.f; + float color[4] = { 1,0,0,1 }; + + Nz::Clock updateClock; + + while (window.IsOpen()) + { + window.ProcessEvents(); + + Nz::RenderFrame frame = window.AcquireFrame(); + if (!frame) + { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + continue; + } + + float deltaTime = updateClock.GetSeconds(); + Nz::Imgui::Instance()->Update(window, deltaTime); + + ImGui::Begin("Loop Window"); + ImGui::Image(logo.get()); + ImGui::ImageButton(logo.get()); + ImGui::SliderFloat("test", &val, 0, 10); + ImGui::ColorPicker4("Color", color, ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_InputRGB); + + ImGui::InputFloat4("value from 2nd window", mywindow.values, "%.3f", ImGuiInputTextFlags_ReadOnly); + ImGui::End(); + + Nz::Imgui::Instance()->Render(window, frame); + + frame.Present(); + + updateClock.Restart(); + } + + return 0; +} \ No newline at end of file diff --git a/examples/Demo/xmake.lua b/examples/Demo/xmake.lua new file mode 100644 index 0000000..1167a0c --- /dev/null +++ b/examples/Demo/xmake.lua @@ -0,0 +1,7 @@ + +target("NzImgui-demo") + set_group("Examples") + add_files("main.cpp") + add_packages("nazara") + add_deps("NazaraImgui") + set_rundir(".") \ No newline at end of file diff --git a/examples/xmake.lua b/examples/xmake.lua new file mode 100644 index 0000000..1f37028 --- /dev/null +++ b/examples/xmake.lua @@ -0,0 +1,9 @@ +option("examples") + set_default(false) + set_showmenu(true) + set_description("Build examples") +option_end() + +if has_config("examples") then + includes("*/xmake.lua") +end \ No newline at end of file diff --git a/xmake.lua b/xmake.lua index 324e1b6..1edf61b 100644 --- a/xmake.lua +++ b/xmake.lua @@ -61,4 +61,4 @@ target("NazaraImgui") add_headerfiles("src/NazaraImgui/**.inl", { prefixdir = "private", install = false }) add_files("src/NazaraImgui/**.cpp") - +includes("examples/xmake.lua")