Mercurial > malikania
comparison examples/js-window/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 | f28cb6d04731 |
children |
comparison
equal
deleted
inserted
replaced
207:10687519f46e | 208:263122adef77 |
---|---|
19 #include <chrono> | 19 #include <chrono> |
20 #include <iostream> | 20 #include <iostream> |
21 #include <thread> | 21 #include <thread> |
22 | 22 |
23 #include <malikania/client/js/window_js_api.hpp> | 23 #include <malikania/client/js/window_js_api.hpp> |
24 #include <malikania/client/js/painter_js_api.hpp> | |
24 | 25 |
25 using namespace std::chrono_literals; | 26 using namespace std::chrono_literals; |
26 | 27 |
27 using namespace mlk; | 28 using namespace mlk; |
28 using namespace mlk::client::js; | 29 using namespace mlk::client::js; |
31 | 32 |
32 void basic(duk_context* ctx) | 33 void basic(duk_context* ctx) |
33 { | 34 { |
34 const auto ret = duk_peval_string(ctx, | 35 const auto ret = duk_peval_string(ctx, |
35 "w = new Malikania.Window();" | 36 "w = new Malikania.Window();" |
36 "w.setDrawingColor('lightskyblue');" | 37 "p = new Malikania.Painter(w);" |
37 "w.clear();" | 38 "p.setDrawingColor('lightskyblue');" |
38 "w.present();" | 39 "p.clear();" |
40 "p.present();" | |
39 ); | 41 ); |
40 | 42 |
41 if (ret != 0) | 43 if (ret != 0) |
42 throw get_stack(ctx, -1); | 44 throw get_stack(ctx, -1); |
43 | 45 |
46 | 48 |
47 void rect(duk_context* ctx) | 49 void rect(duk_context* ctx) |
48 { | 50 { |
49 const auto ret = duk_peval_string(ctx, | 51 const auto ret = duk_peval_string(ctx, |
50 "w = new Malikania.Window();" | 52 "w = new Malikania.Window();" |
51 "w.setDrawingColor('lightskyblue');" | 53 "p = new Malikania.Painter(w);" |
52 "w.clear();" | 54 "p.setDrawingColor('lightskyblue');" |
53 "w.setDrawingColor('white');" | 55 "p.clear();" |
54 "w.drawRectangle({ x: 10, y: 10, width: 10, height: 10 });" | 56 "p.setDrawingColor('white');" |
55 "w.present();" | 57 "p.drawRectangle({ x: 10, y: 10, width: 10, height: 10 });" |
58 "p.present();" | |
56 ); | 59 ); |
57 | 60 |
58 if (ret != 0) | 61 if (ret != 0) |
59 throw get_stack(ctx, -1); | 62 throw get_stack(ctx, -1); |
60 | 63 |
68 | 71 |
69 duk_push_object(ctx); | 72 duk_push_object(ctx); |
70 duk_put_global_string(ctx, "Malikania"); | 73 duk_put_global_string(ctx, "Malikania"); |
71 | 74 |
72 load_window_api(ctx); | 75 load_window_api(ctx); |
76 load_painter_api(ctx); | |
77 | |
73 basic(ctx); | 78 basic(ctx); |
74 rect(ctx); | 79 rect(ctx); |
75 } catch (const std::exception& ex) { | 80 } catch (const std::exception& ex) { |
76 std::cerr << ex.what() << std::endl; | 81 std::cerr << ex.what() << std::endl; |
77 return 1; | 82 return 1; |