comparison examples/image/main.cpp @ 208:263122adef77

client: add texture and painter closes #966 @2h closes #967 @2h
author David Demelier <markand@malikania.fr>
date Wed, 05 Dec 2018 22:24:44 +0100
parents 0a285d62ace7
children
comparison
equal deleted inserted replaced
207:10687519f46e 208:263122adef77
18 18
19 #include <chrono> 19 #include <chrono>
20 #include <iostream> 20 #include <iostream>
21 #include <thread> 21 #include <thread>
22 22
23 #include <malikania/client/image.hpp>
23 #include <malikania/client/loader.hpp> 24 #include <malikania/client/loader.hpp>
24 #include <malikania/client/image.hpp> 25 #include <malikania/client/painter.hpp>
25 #include <malikania/client/window.hpp> 26 #include <malikania/client/window.hpp>
26 #include <malikania/locator.hpp> 27 #include <malikania/locator.hpp>
27 28
28 using namespace std::chrono_literals; 29 using namespace std::chrono_literals;
29 30
30 void draw(mlk::client::window& window, mlk::client::loader& loader) 31 void draw(mlk::client::painter& painter, mlk::client::loader& loader)
31 { 32 {
32 try { 33 try {
33 auto image = loader.load_image("images/smiley.png"); 34 auto image = loader.load_image("images/smiley.png");
34 auto x = (400 / 2) - (image.get_size().width / 2); 35 auto x = (400 / 2) - (image.get_size().width / 2);
35 auto y = (400 / 2) - (image.get_size().height / 2); 36 auto y = (400 / 2) - (image.get_size().height / 2);
36 37
37 window.clear(); 38 painter.clear();
38 image.draw(window, { 39 image.draw(painter, {
39 static_cast<int>(x), 40 static_cast<int>(x),
40 static_cast<int>(y) 41 static_cast<int>(y)
41 }); 42 });
42 window.present(); 43 painter.present();
43 44
44 std::this_thread::sleep_for(3s); 45 std::this_thread::sleep_for(3s);
45 } catch (const std::exception &ex) { 46 } catch (const std::exception &ex) {
46 std::cerr << ex.what() << std::endl; 47 std::cerr << ex.what() << std::endl;
47 std::exit(1); 48 std::exit(1);
50 51
51 int main(int, char**) 52 int main(int, char**)
52 { 53 {
53 try { 54 try {
54 mlk::client::window window(400, 400); 55 mlk::client::window window(400, 400);
56 mlk::client::painter painter(window);
55 mlk::directory_locator locator(CMAKE_CURRENT_SOURCE_DIR "/resources"); 57 mlk::directory_locator locator(CMAKE_CURRENT_SOURCE_DIR "/resources");
56 mlk::client::loader loader(locator); 58 mlk::client::loader loader(locator);
57 59
58 draw(window, loader); 60 draw(painter, loader);
59 } catch (const std::exception& ex) { 61 } catch (const std::exception& ex) {
60 std::cerr << ex.what() << std::endl; 62 std::cerr << ex.what() << std::endl;
61 return 1; 63 return 1;
62 } 64 }
63 65