Mercurial > malikania
comparison examples/js-window/main.cpp @ 215:268b66d72ec0 default tip @
misc: remove Javascript bindings, closes #2402
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 10 Oct 2019 13:52:57 +0200 |
parents | e2574aa8301d |
children |
comparison
equal
deleted
inserted
replaced
214:e2574aa8301d | 215:268b66d72ec0 |
---|---|
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 | |
23 #include <malikania/client/js/window_js_api.hpp> | |
24 #include <malikania/client/js/painter_js_api.hpp> | |
25 | |
26 using namespace std::chrono_literals; | |
27 | |
28 using namespace mlk; | |
29 using namespace mlk::client::js; | |
30 using namespace mlk::client; | |
31 using namespace mlk::js::duk; | |
32 | |
33 void basic(duk_context* ctx) | |
34 { | |
35 const auto ret = duk_peval_string(ctx, | |
36 "w = new Malikania.Window();" | |
37 "p = new Malikania.Painter(w);" | |
38 "p.setDrawingColor('lightskyblue');" | |
39 "p.clear();" | |
40 "p.present();" | |
41 ); | |
42 | |
43 if (ret != 0) | |
44 throw get_stack(ctx, -1); | |
45 | |
46 std::this_thread::sleep_for(3s); | |
47 } | |
48 | |
49 void rect(duk_context* ctx) | |
50 { | |
51 const auto ret = duk_peval_string(ctx, | |
52 "w = new Malikania.Window();" | |
53 "p = new Malikania.Painter(w);" | |
54 "p.setDrawingColor('lightskyblue');" | |
55 "p.clear();" | |
56 "p.setDrawingColor('white');" | |
57 "p.drawRectangle({ x: 10, y: 10, width: 10, height: 10 });" | |
58 "p.present();" | |
59 ); | |
60 | |
61 if (ret != 0) | |
62 throw get_stack(ctx, -1); | |
63 | |
64 std::this_thread::sleep_for(3s); | |
65 } | |
66 | |
67 int main() | |
68 { | |
69 try { | |
70 context ctx; | |
71 | |
72 duk_push_object(ctx); | |
73 duk_put_global_string(ctx, "Malikania"); | |
74 | |
75 load_window_api(ctx); | |
76 load_painter_api(ctx); | |
77 | |
78 basic(ctx); | |
79 rect(ctx); | |
80 } catch (const std::exception& ex) { | |
81 std::cerr << ex.what() << std::endl; | |
82 return 1; | |
83 } | |
84 } |