Mercurial > malikania
annotate 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 |
rev | line source |
---|---|
182 | 1 /* |
2 * main.cpp -- test Window (JavaScript binding) | |
3 * | |
4 * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <chrono> | |
20 #include <iostream> | |
21 #include <thread> | |
22 | |
189
f28cb6d04731
Misc: extreme refactoring
David Demelier <markand@malikania.fr>
parents:
188
diff
changeset
|
23 #include <malikania/client/js/window_js_api.hpp> |
208
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
24 #include <malikania/client/js/painter_js_api.hpp> |
182 | 25 |
26 using namespace std::chrono_literals; | |
27 | |
28 using namespace mlk; | |
189
f28cb6d04731
Misc: extreme refactoring
David Demelier <markand@malikania.fr>
parents:
188
diff
changeset
|
29 using namespace mlk::client::js; |
182 | 30 using namespace mlk::client; |
189
f28cb6d04731
Misc: extreme refactoring
David Demelier <markand@malikania.fr>
parents:
188
diff
changeset
|
31 using namespace mlk::js::duk; |
182 | 32 |
188
0cecdadfb5c4
Misc: rework javascript bindings, closes #916
David Demelier <markand@malikania.fr>
parents:
182
diff
changeset
|
33 void basic(duk_context* ctx) |
182 | 34 { |
188
0cecdadfb5c4
Misc: rework javascript bindings, closes #916
David Demelier <markand@malikania.fr>
parents:
182
diff
changeset
|
35 const auto ret = duk_peval_string(ctx, |
182 | 36 "w = new Malikania.Window();" |
208
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
37 "p = new Malikania.Painter(w);" |
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
38 "p.setDrawingColor('lightskyblue');" |
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
39 "p.clear();" |
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
40 "p.present();" |
182 | 41 ); |
42 | |
188
0cecdadfb5c4
Misc: rework javascript bindings, closes #916
David Demelier <markand@malikania.fr>
parents:
182
diff
changeset
|
43 if (ret != 0) |
0cecdadfb5c4
Misc: rework javascript bindings, closes #916
David Demelier <markand@malikania.fr>
parents:
182
diff
changeset
|
44 throw get_stack(ctx, -1); |
182 | 45 |
46 std::this_thread::sleep_for(3s); | |
47 } | |
48 | |
188
0cecdadfb5c4
Misc: rework javascript bindings, closes #916
David Demelier <markand@malikania.fr>
parents:
182
diff
changeset
|
49 void rect(duk_context* ctx) |
182 | 50 { |
188
0cecdadfb5c4
Misc: rework javascript bindings, closes #916
David Demelier <markand@malikania.fr>
parents:
182
diff
changeset
|
51 const auto ret = duk_peval_string(ctx, |
182 | 52 "w = new Malikania.Window();" |
208
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
53 "p = new Malikania.Painter(w);" |
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
54 "p.setDrawingColor('lightskyblue');" |
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
55 "p.clear();" |
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
56 "p.setDrawingColor('white');" |
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
57 "p.drawRectangle({ x: 10, y: 10, width: 10, height: 10 });" |
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
58 "p.present();" |
182 | 59 ); |
60 | |
188
0cecdadfb5c4
Misc: rework javascript bindings, closes #916
David Demelier <markand@malikania.fr>
parents:
182
diff
changeset
|
61 if (ret != 0) |
0cecdadfb5c4
Misc: rework javascript bindings, closes #916
David Demelier <markand@malikania.fr>
parents:
182
diff
changeset
|
62 throw get_stack(ctx, -1); |
182 | 63 |
64 std::this_thread::sleep_for(3s); | |
65 } | |
66 | |
67 int main() | |
68 { | |
69 try { | |
188
0cecdadfb5c4
Misc: rework javascript bindings, closes #916
David Demelier <markand@malikania.fr>
parents:
182
diff
changeset
|
70 context ctx; |
182 | 71 |
72 duk_push_object(ctx); | |
73 duk_put_global_string(ctx, "Malikania"); | |
74 | |
188
0cecdadfb5c4
Misc: rework javascript bindings, closes #916
David Demelier <markand@malikania.fr>
parents:
182
diff
changeset
|
75 load_window_api(ctx); |
208
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
76 load_painter_api(ctx); |
263122adef77
client: add texture and painter
David Demelier <markand@malikania.fr>
parents:
189
diff
changeset
|
77 |
182 | 78 basic(ctx); |
79 rect(ctx); | |
80 } catch (const std::exception& ex) { | |
81 std::cerr << ex.what() << std::endl; | |
82 return 1; | |
83 } | |
84 } |