Update Tut02

This commit is contained in:
SirLynix 2023-02-02 13:28:42 +01:00
parent 35172f5028
commit 1406705491
1 changed files with 11 additions and 3 deletions

View File

@ -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 <Nazara/Core.hpp>
#include <Nazara/Graphics.hpp>
@ -11,15 +11,18 @@ int main()
{
Nz::Application<Nz::Graphics> app;
// Création de la fenêtre
auto& windowing = app.AddComponent<Nz::AppWindowingComponent>();
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<Nz::AppEntitySystemComponent>();
auto& world = ecs.AddWorld<Nz::EnttWorld>();
Nz::RenderSystem& renderSystem = world.AddSystem<Nz::RenderSystem>();
auto& windowSwapchain = renderSystem.CreateSwapchain(mainWindow);
// Création de l'entité caméra
entt::handle cameraEntity = world.CreateEntity();
{
cameraEntity.emplace<Nz::NodeComponent>();
@ -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));