Mercurial > malikania
comparison mlk-client/main.cpp @ 206:12873699ad8b
client: create variant instead of dispatcher
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 29 Nov 2018 14:04:58 +0100 |
parents | c973501abe36 |
children | 263122adef77 |
comparison
equal
deleted
inserted
replaced
205:c973501abe36 | 206:12873699ad8b |
---|---|
26 #include <malikania/client/sprite.hpp> | 26 #include <malikania/client/sprite.hpp> |
27 #include <malikania/client/theme.hpp> | 27 #include <malikania/client/theme.hpp> |
28 | 28 |
29 #include <assets/ui.hpp> | 29 #include <assets/ui.hpp> |
30 | 30 |
31 class loop : public mlk::client::dispatcher { | 31 using namespace std::chrono_literals; |
32 }; | |
33 | 32 |
34 int main(int, char**) | 33 int main(int, char**) |
35 { | 34 { |
36 mlk::client::window win(1920/2, 1080/2, "Hello"); | 35 mlk::client::window win(1920/2, 1080/2, "Hello"); |
37 mlk::client::image image(std::string(ui, sizeof (ui))); | 36 mlk::client::image image(std::string(ui, sizeof (ui))); |
38 mlk::client::sprite sprite(std::move(image), {16, 16}); | 37 mlk::client::sprite sprite(std::move(image), {16, 16}); |
39 | 38 |
40 loop looper; | 39 for (;;) { |
40 while (auto ev = win.poll()) { | |
41 if (std::holds_alternative<mlk::client::quit_event>(ev)) | |
42 return 0; | |
43 } | |
41 | 44 |
42 while (win.is_open()) { | |
43 win.poll(looper); | |
44 win.clear(); | 45 win.clear(); |
45 win.set_drawing_color(mlk::client::color::from_hex(0xffffffff)); | 46 win.set_drawing_color(mlk::client::color::from_hex(0xffffffff)); |
46 | 47 |
47 const auto width = 200; | 48 const auto width = 200; |
48 const auto height = 150; | 49 const auto height = 150; |
69 sprite.draw(win, 35, mlk::point{10 + 8, 10 + 8 + 16}); | 70 sprite.draw(win, 35, mlk::point{10 + 8, 10 + 8 + 16}); |
70 sprite.draw(win, 36, mlk::rectangle{10 + 8 + 16, 10 + 8 + 16, width - 16, 16}); | 71 sprite.draw(win, 36, mlk::rectangle{10 + 8 + 16, 10 + 8 + 16, width - 16, 16}); |
71 sprite.draw(win, 37, mlk::point{10 + 8 + width, 10 + 8 + 16}); | 72 sprite.draw(win, 37, mlk::point{10 + 8 + width, 10 + 8 + 16}); |
72 | 73 |
73 win.present(); | 74 win.present(); |
75 std::this_thread::sleep_for(50ms); | |
74 } | 76 } |
75 | 77 |
76 return 0; | 78 return 0; |
77 } | 79 } |