Mercurial > malikania
comparison examples/js-font/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 Font (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/locator.hpp> | |
24 | |
25 #include <malikania/client/loader.hpp> | |
26 | |
27 #include <malikania/client/js/font_js_api.hpp> | |
28 #include <malikania/client/js/loader_js_api.hpp> | |
29 #include <malikania/client/js/window_js_api.hpp> | |
30 #include <malikania/client/js/painter_js_api.hpp> | |
31 | |
32 using namespace std::chrono_literals; | |
33 | |
34 using namespace mlk; | |
35 using namespace mlk::client::js; | |
36 using namespace mlk::client; | |
37 using namespace mlk::js::duk; | |
38 | |
39 void basic(duk_context* ctx) | |
40 { | |
41 const auto ret = duk_peval_string(ctx, | |
42 "w = new Malikania.Window();" | |
43 "p = new Malikania.Painter(w);" | |
44 "f = new Malikania.Font('DejaVuSans.ttf', 10);" | |
45 "p.setDrawingColor('lightskyblue');" | |
46 "p.clear();" | |
47 "s = 'The world is Malikania.';" | |
48 "c = f.clip(s);" | |
49 "p.setDrawingColor('white');" | |
50 "f.draw(p, s, { x: 320 - (c.width / 2), y: 240 - (c.height / 2) });" | |
51 "p.present();" | |
52 ); | |
53 | |
54 if (ret != 0) | |
55 throw get_stack(ctx, -1); | |
56 | |
57 std::this_thread::sleep_for(3s); | |
58 } | |
59 | |
60 int main() | |
61 { | |
62 try { | |
63 directory_locator locator(CMAKE_CURRENT_SOURCE_DIR "/resources"); | |
64 client::loader loader(locator); | |
65 context ctx; | |
66 | |
67 duk_push_object(ctx); | |
68 duk_put_global_string(ctx, "Malikania"); | |
69 | |
70 load_font_api(ctx); | |
71 load_window_api(ctx); | |
72 load_painter_api(ctx); | |
73 | |
74 put(ctx, loader); | |
75 basic(ctx); | |
76 } catch (const std::exception& ex) { | |
77 std::cerr << ex.what() << std::endl; | |
78 return 1; | |
79 } | |
80 } |