add example code

This commit is contained in:
SweetId 2022-08-09 21:41:28 +01:00
parent 94e5b8c03b
commit bf2c812867
5 changed files with 111 additions and 1 deletions

BIN
examples/Demo/LogoMini.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

94
examples/Demo/main.cpp Normal file
View File

@ -0,0 +1,94 @@
#include <Nazara/Core/Modules.hpp>
#include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraImgui/NazaraImgui.hpp>
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<Nz::Graphics, Nz::Imgui> 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;
}

7
examples/Demo/xmake.lua Normal file
View File

@ -0,0 +1,7 @@
target("NzImgui-demo")
set_group("Examples")
add_files("main.cpp")
add_packages("nazara")
add_deps("NazaraImgui")
set_rundir(".")

9
examples/xmake.lua Normal file
View File

@ -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

View File

@ -61,4 +61,4 @@ target("NazaraImgui")
add_headerfiles("src/NazaraImgui/**.inl", { prefixdir = "private", install = false })
add_files("src/NazaraImgui/**.cpp")
includes("examples/xmake.lua")