From 140670549158c3951dc7c7717a9187f7336c9cd3 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Thu, 2 Feb 2023 13:28:42 +0100 Subject: [PATCH] Update Tut02 --- examples/Tut02/main.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/Tut02/main.cpp b/examples/Tut02/main.cpp index f29a00821..ffd391a4a 100644 --- a/examples/Tut02/main.cpp +++ b/examples/Tut02/main.cpp @@ -1,4 +1,4 @@ -// Sources pour https://github.com/NazaraEngine/NazaraEngine/wiki/(FR)-Tutoriel:-%5B02%5D-Gestion-des-événements +// Sources pour https://github.com/NazaraEngine/NazaraEngine/wiki/(FR)-Tutoriel:-%5B02%5D-Signaux-et-gestion-des-%C3%A9v%C3%A9nements #include #include @@ -11,15 +11,18 @@ int main() { Nz::Application app; + // Création de la fenêtre auto& windowing = app.AddComponent(); - Nz::Window& mainWindow = windowing.CreateWindow(Nz::VideoMode(1280, 720), "Tut02 - Hello world"); + Nz::Window& mainWindow = windowing.CreateWindow(Nz::VideoMode(1280, 720), "Tut02 - Events"); + // Ajout d'un monde auto& ecs = app.AddComponent(); auto& world = ecs.AddWorld(); Nz::RenderSystem& renderSystem = world.AddSystem(); auto& windowSwapchain = renderSystem.CreateSwapchain(mainWindow); + // Création de l'entité caméra entt::handle cameraEntity = world.CreateEntity(); { cameraEntity.emplace(); @@ -28,6 +31,12 @@ int main() cameraComponent.UpdateClearColor(Nz::Color(0.46f, 0.48f, 0.84f, 1.f)); } + Nz::WindowEventHandler& eventHandler = mainWindow.GetEventHandler(); + eventHandler.OnQuit.Connect([&](const Nz::WindowEventHandler*) + { + app.Quit(); //< fermeture de l'application + }); + Nz::SimpleTextDrawer textDrawer; textDrawer.SetCharacterSize(72); textDrawer.SetOutlineThickness(4.f); @@ -47,7 +56,6 @@ int main() nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2); } - Nz::WindowEventHandler& eventHandler = mainWindow.GetEventHandler(); eventHandler.OnKeyPressed.Connect([&](const Nz::WindowEventHandler*, const Nz::WindowEvent::KeyEvent& e) { textDrawer.SetText("You pressed " + Nz::Keyboard::GetKeyName(e.virtualKey));