1 /*
2 * Copyright (c) 2018-2019 Hanspeter Portner (dev@open-music-kontrollers.ch)
3 *
4 * This is free software: you can redistribute it and/or modify
5 * it under the terms of the Artistic License 2.0 as published by
6 * The Perl Foundation.
7 *
8 * This source is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * Artistic License 2.0 for more details.
12 *
13 * You should have received a copy of the Artistic License 2.0
14 * along the source as a COPYING file. If not, obtain it from
15 * http://www.perlfoundation.org/artistic_license_2_0.
16 */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <inttypes.h>
21 #include <unistd.h>
22 #include <signal.h>
23
24 #include <d2tk/frontend_pugl.h>
25 #include "example/example.h"
26
27 typedef struct _app_t app_t;
28
29 struct _app_t {
30 d2tk_frontend_t *dpugl;
31 };
32
33 static sig_atomic_t done = false;
34
35 static void
_sig(int signum)36 _sig(int signum __attribute__((unused)))
37 {
38 done = true;
39 }
40
41 static int
_expose(void * data,d2tk_coord_t w,d2tk_coord_t h)42 _expose(void *data, d2tk_coord_t w, d2tk_coord_t h)
43 {
44 app_t *app = data;
45 d2tk_frontend_t *dpugl = app->dpugl;
46 d2tk_base_t *base = d2tk_frontend_get_base(dpugl);
47
48 d2tk_example_run(dpugl, base, w, h);
49
50 return EXIT_SUCCESS;
51 }
52
53 int
main(int argc,char ** argv)54 main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
55 {
56 static app_t app;
57
58 const float scale = d2tk_frontend_get_scale();
59 d2tk_coord_t w = scale * 1280;
60 d2tk_coord_t h = scale * 720;
61
62 int c;
63 while( (c = getopt(argc, argv, "w:h:")) != -1)
64 {
65 switch(c)
66 {
67 case 'w':
68 {
69 w = atoi(optarg);
70 } break;
71 case 'h':
72 {
73 h = atoi(optarg);
74 } break;
75
76 default:
77 {
78 fprintf(stderr, "Usage: %s\n"
79 " -w width\n"
80 " -h height\n\n",
81 argv[0]);
82 } return EXIT_FAILURE;
83 }
84 }
85
86 const d2tk_pugl_config_t config = {
87 .parent = 0,
88 .bundle_path = "./",
89 .min_w = w/4,
90 .min_h = h/4,
91 .w = w,
92 .h = h,
93 .fixed_size = false,
94 .fixed_aspect = false,
95 .expose = _expose,
96 .data = &app
97 };
98
99 signal(SIGINT, _sig);
100 signal(SIGTERM, _sig);
101 #if !defined(_WIN32)
102 signal(SIGQUIT, _sig);
103 signal(SIGKILL, _sig);
104 #endif
105
106 app.dpugl = d2tk_pugl_new(&config, NULL);
107 if(app.dpugl)
108 {
109 d2tk_example_init();
110
111 d2tk_frontend_run(app.dpugl, &done);
112
113 d2tk_frontend_free(app.dpugl);
114
115 d2tk_example_deinit();
116
117 return EXIT_SUCCESS;
118 }
119
120 return EXIT_FAILURE;
121 }
122