main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. #define _GNU_SOURCE // for O_TMPFILE
  2. #define NK_INCLUDE_FIXED_TYPES
  3. #define NK_INCLUDE_STANDARD_IO
  4. #define NK_INCLUDE_STANDARD_VARARGS
  5. #define NK_INCLUDE_DEFAULT_ALLOCATOR
  6. #define NK_IMPLEMENTATION
  7. #define NK_RAWFB_IMPLEMENTATION
  8. #define NK_INCLUDE_FONT_BAKING
  9. #define NK_INCLUDE_DEFAULT_FONT
  10. #define NK_INCLUDE_SOFTWARE_FONT
  11. #include <wayland-client.h>
  12. #include <stdlib.h>
  13. #include <fcntl.h>
  14. #include <sys/mman.h>
  15. #include <unistd.h>
  16. #include <string.h>
  17. #include <stdio.h>
  18. #include <math.h>
  19. #include <time.h>
  20. #include <sys/time.h>
  21. #include "../../../nuklear.h"
  22. #include "xdg-shell.h"
  23. #include "../nuklear_rawfb.h"
  24. struct nk_wayland {
  25. /*wayland vars*/
  26. struct wl_display *display;
  27. struct wl_compositor *compositor;
  28. struct xdg_wm_base *xdg_wm_base;
  29. struct wl_shm *wl_shm;
  30. struct wl_seat* seat;
  31. struct wl_callback *frame_callback;
  32. struct wl_surface *surface;
  33. struct xdg_surface *xdg_surface;
  34. struct xdg_toplevel *xdg_toplevel;
  35. struct wl_buffer *front_buffer;
  36. int32_t *data;
  37. int mouse_pointer_x;
  38. int mouse_pointer_y;
  39. uint8_t tex_scratch[512 * 512];
  40. struct rawfb_context *rawfb;
  41. };
  42. #define WIDTH 800
  43. #define HEIGHT 600
  44. #define DTIME 20
  45. /* ===============================================================
  46. *
  47. * EXAMPLE
  48. *
  49. * ===============================================================*/
  50. /* This are some code examples to provide a small overview of what can be
  51. * done with this library. To try out an example uncomment the defines */
  52. /*#define INCLUDE_ALL */
  53. /*#define INCLUDE_STYLE */
  54. /*#define INCLUDE_CALCULATOR */
  55. /*#define INCLUDE_CANVAS */
  56. #define INCLUDE_OVERVIEW
  57. /*#define INCLUDE_CONFIGURATOR */
  58. /*#define INCLUDE_NODE_EDITOR */
  59. #ifdef INCLUDE_ALL
  60. #define INCLUDE_STYLE
  61. #define INCLUDE_CALCULATOR
  62. #define INCLUDE_CANVAS
  63. #define INCLUDE_OVERVIEW
  64. #define INCLUDE_CONFIGURATOR
  65. #define INCLUDE_NODE_EDITOR
  66. #endif
  67. #ifdef INCLUDE_STYLE
  68. #include "../../common/style.c"
  69. #endif
  70. #ifdef INCLUDE_CALCULATOR
  71. #include "../../common/calculator.c"
  72. #endif
  73. #ifdef INCLUDE_CANVAS
  74. #include "../../common/canvas.c"
  75. #endif
  76. #ifdef INCLUDE_OVERVIEW
  77. #include "../../common/overview.c"
  78. #endif
  79. #ifdef INCLUDE_CONFIGURATOR
  80. #include "../../common/style_configurator.c"
  81. #endif
  82. #ifdef INCLUDE_NODE_EDITOR
  83. #include "../../common/node_editor.c"
  84. #endif
  85. //WAYLAND OUTPUT INTERFACE
  86. static void nk_wayland_output_cb_geometry(void *data, struct wl_output *wl_output, int x, int y, int w, int h, int subpixel, const char *make, const char *model, int transform)
  87. {
  88. NK_UNUSED(data);
  89. NK_UNUSED(wl_output);
  90. NK_UNUSED(subpixel);
  91. NK_UNUSED(make);
  92. NK_UNUSED(model);
  93. NK_UNUSED(transform);
  94. printf("wl_output geometry x=%d, y=%d, w=%d, h=%d make=%s, model=%s \n", x,y,w,h, make, model);
  95. }
  96. static void nk_wayland_output_cb_mode(void *data, struct wl_output *wl_output, unsigned int flags, int w, int h, int refresh)
  97. {
  98. NK_UNUSED(data);
  99. NK_UNUSED(wl_output);
  100. NK_UNUSED(flags);
  101. NK_UNUSED(w);
  102. NK_UNUSED(h);
  103. NK_UNUSED(refresh);
  104. }
  105. static void nk_wayland_output_cb_done(void *data, struct wl_output *output)
  106. {
  107. NK_UNUSED(data);
  108. NK_UNUSED(output);
  109. }
  110. static void nk_wayland_output_cb_scale(void *data, struct wl_output *output, int scale)
  111. {
  112. NK_UNUSED(data);
  113. NK_UNUSED(output);
  114. NK_UNUSED(scale);
  115. }
  116. static const struct wl_output_listener nk_wayland_output_listener =
  117. {
  118. &nk_wayland_output_cb_geometry,
  119. &nk_wayland_output_cb_mode,
  120. &nk_wayland_output_cb_done,
  121. &nk_wayland_output_cb_scale
  122. };
  123. //-------------------------------------------------------------------- endof WAYLAND OUTPUT INTERFACE
  124. //WAYLAND POINTER INTERFACE (mouse/touchpad)
  125. static void nk_wayland_pointer_enter (void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y)
  126. {
  127. NK_UNUSED(data);
  128. NK_UNUSED(pointer);
  129. NK_UNUSED(serial);
  130. NK_UNUSED(surface);
  131. NK_UNUSED(surface_x);
  132. NK_UNUSED(surface_y);
  133. }
  134. static void nk_wayland_pointer_leave (void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface)
  135. {
  136. NK_UNUSED(data);
  137. NK_UNUSED(pointer);
  138. NK_UNUSED(serial);
  139. NK_UNUSED(surface);
  140. }
  141. static void nk_wayland_pointer_motion (void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y)
  142. {
  143. struct nk_wayland* win = (struct nk_wayland*)data;
  144. NK_UNUSED(pointer);
  145. NK_UNUSED(time);
  146. win->mouse_pointer_x = wl_fixed_to_int(x);
  147. win->mouse_pointer_y = wl_fixed_to_int(y);
  148. nk_input_motion(&(win->rawfb->ctx), win->mouse_pointer_x, win->mouse_pointer_y);
  149. }
  150. static void nk_wayland_pointer_button (void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
  151. {
  152. struct nk_wayland* win = (struct nk_wayland*)data;
  153. NK_UNUSED(pointer);
  154. NK_UNUSED(serial);
  155. NK_UNUSED(time);
  156. if (button == 272){ //left mouse button
  157. if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
  158. // printf("nk_input_button x=%d, y=%d press: 1 \n", win->mouse_pointer_x, win->mouse_pointer_y);
  159. nk_input_button(&(win->rawfb->ctx), NK_BUTTON_LEFT, win->mouse_pointer_x, win->mouse_pointer_y, 1);
  160. } else if (state == WL_POINTER_BUTTON_STATE_RELEASED) {
  161. nk_input_button(&(win->rawfb->ctx), NK_BUTTON_LEFT, win->mouse_pointer_x, win->mouse_pointer_y, 0);
  162. }
  163. }
  164. }
  165. static void nk_wayland_pointer_axis (void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
  166. {
  167. NK_UNUSED(data);
  168. NK_UNUSED(pointer);
  169. NK_UNUSED(time);
  170. NK_UNUSED(axis);
  171. NK_UNUSED(value);
  172. }
  173. static struct wl_pointer_listener nk_wayland_pointer_listener =
  174. {
  175. &nk_wayland_pointer_enter,
  176. &nk_wayland_pointer_leave,
  177. &nk_wayland_pointer_motion,
  178. &nk_wayland_pointer_button,
  179. &nk_wayland_pointer_axis,
  180. NULL,
  181. NULL,
  182. NULL,
  183. NULL
  184. };
  185. //-------------------------------------------------------------------- endof WAYLAND POINTER INTERFACE
  186. //WAYLAND KEYBOARD INTERFACE
  187. static void nk_wayland_keyboard_keymap (void *data, struct wl_keyboard *keyboard, uint32_t format, int32_t fd, uint32_t size)
  188. {
  189. NK_UNUSED(data);
  190. NK_UNUSED(keyboard);
  191. NK_UNUSED(format);
  192. NK_UNUSED(fd);
  193. NK_UNUSED(size);
  194. }
  195. static void nk_wayland_keyboard_enter (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys)
  196. {
  197. NK_UNUSED(data);
  198. NK_UNUSED(keyboard);
  199. NK_UNUSED(serial);
  200. NK_UNUSED(surface);
  201. NK_UNUSED(keys);
  202. }
  203. static void nk_wayland_keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface)
  204. {
  205. NK_UNUSED(data);
  206. NK_UNUSED(keyboard);
  207. NK_UNUSED(serial);
  208. NK_UNUSED(surface);
  209. }
  210. static void nk_wayland_keyboard_key (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
  211. {
  212. NK_UNUSED(data);
  213. NK_UNUSED(keyboard);
  214. NK_UNUSED(serial);
  215. NK_UNUSED(time);
  216. NK_UNUSED(state);
  217. printf("key: %d \n", key);
  218. }
  219. static void nk_wayland_keyboard_modifiers (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
  220. {
  221. NK_UNUSED(data);
  222. NK_UNUSED(keyboard);
  223. NK_UNUSED(serial);
  224. NK_UNUSED(mods_depressed);
  225. NK_UNUSED(mods_latched);
  226. NK_UNUSED(mods_locked);
  227. NK_UNUSED(group);
  228. }
  229. static struct wl_keyboard_listener nk_wayland_keyboard_listener =
  230. {
  231. &nk_wayland_keyboard_keymap,
  232. &nk_wayland_keyboard_enter,
  233. &nk_wayland_keyboard_leave,
  234. &nk_wayland_keyboard_key,
  235. &nk_wayland_keyboard_modifiers,
  236. NULL
  237. };
  238. //-------------------------------------------------------------------- endof WAYLAND KEYBOARD INTERFACE
  239. //WAYLAND SEAT INTERFACE
  240. static void seat_capabilities (void *data, struct wl_seat *seat, uint32_t capabilities)
  241. {
  242. struct nk_wayland* win = (struct nk_wayland*)data;
  243. if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
  244. struct wl_pointer *pointer = wl_seat_get_pointer (seat);
  245. wl_pointer_add_listener (pointer, &nk_wayland_pointer_listener, win);
  246. }
  247. if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) {
  248. struct wl_keyboard *keyboard = wl_seat_get_keyboard (seat);
  249. wl_keyboard_add_listener (keyboard, &nk_wayland_keyboard_listener, win);
  250. }
  251. }
  252. static struct wl_seat_listener seat_listener =
  253. {
  254. &seat_capabilities,
  255. NULL
  256. };
  257. //-------------------------------------------------------------------- endof WAYLAND SEAT INTERFACE
  258. // WAYLAND SHELL INTERFACE
  259. static void nk_wayland_xdg_wm_base_ping (void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial)
  260. {
  261. NK_UNUSED(data);
  262. xdg_wm_base_pong (xdg_wm_base, serial);
  263. }
  264. static struct xdg_wm_base_listener nk_wayland_xdg_wm_base_listener =
  265. {
  266. &nk_wayland_xdg_wm_base_ping
  267. };
  268. static void nk_wayland_xdg_surface_configure (void *data, struct xdg_surface *xdg_surface, uint32_t serial)
  269. {
  270. NK_UNUSED(data);
  271. xdg_surface_ack_configure(xdg_surface, serial);
  272. }
  273. static struct xdg_surface_listener nk_wayland_xdg_surface_listener =
  274. {
  275. &nk_wayland_xdg_surface_configure,
  276. };
  277. static void nk_wayland_xdg_toplevel_configure (void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states)
  278. {
  279. NK_UNUSED(data);
  280. NK_UNUSED(xdg_toplevel);
  281. NK_UNUSED(width);
  282. NK_UNUSED(height);
  283. NK_UNUSED(states);
  284. }
  285. static void nk_wayland_xdg_toplevel_close (void *data, struct xdg_toplevel *xdg_toplevel)
  286. {
  287. NK_UNUSED(data);
  288. NK_UNUSED(xdg_toplevel);
  289. }
  290. static struct xdg_toplevel_listener nk_wayland_xdg_toplevel_listener =
  291. {
  292. &nk_wayland_xdg_toplevel_configure,
  293. &nk_wayland_xdg_toplevel_close
  294. };
  295. //--------------------------------------------------------------------- endof WAYLAND SHELL INTERFACE
  296. // WAYLAND REGISTRY INTERFACE
  297. static void nk_wayland_registry_add_object (void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
  298. {
  299. struct nk_wayland* win = (struct nk_wayland*)data;
  300. NK_UNUSED(version);
  301. //printf("looking for %s interface \n", interface);
  302. if (!strcmp(interface,"wl_compositor")) {
  303. win->compositor = wl_registry_bind (registry, name, &wl_compositor_interface, 1);
  304. } else if (!strcmp(interface,"xdg_wm_base")) {
  305. win->xdg_wm_base = wl_registry_bind (registry, name, &xdg_wm_base_interface, 1);
  306. xdg_wm_base_add_listener (win->xdg_wm_base, &nk_wayland_xdg_wm_base_listener, win);
  307. } else if (!strcmp(interface,"wl_shm")) {
  308. win->wl_shm = wl_registry_bind (registry, name, &wl_shm_interface, 1);
  309. } else if (!strcmp(interface,"wl_seat")) {
  310. win->seat = wl_registry_bind (registry, name, &wl_seat_interface, 1);
  311. wl_seat_add_listener (win->seat, &seat_listener, win);
  312. } else if (!strcmp(interface, "wl_output")) {
  313. struct wl_output *wl_output = wl_registry_bind(registry, name, &wl_output_interface, 1);
  314. wl_output_add_listener(wl_output, &nk_wayland_output_listener, NULL);
  315. }
  316. }
  317. static void nk_wayland_registry_remove_object (void *data, struct wl_registry *registry, uint32_t name)
  318. {
  319. NK_UNUSED(data);
  320. NK_UNUSED(registry);
  321. NK_UNUSED(name);
  322. }
  323. static struct wl_registry_listener nk_wayland_registry_listener =
  324. {
  325. &nk_wayland_registry_add_object,
  326. &nk_wayland_registry_remove_object
  327. };
  328. //------------------------------------------------------------------------------------------------ endof WAYLAND REGISTRY INTERFACE
  329. static void nk_wayland_deinit(struct nk_wayland *win)
  330. {
  331. xdg_toplevel_destroy (win->xdg_toplevel);
  332. xdg_surface_destroy (win->xdg_surface);
  333. xdg_wm_base_destroy (win->xdg_wm_base);
  334. wl_surface_destroy (win->surface);
  335. }
  336. static long timestamp(void)
  337. {
  338. struct timeval tv;
  339. if (gettimeofday(&tv, NULL) < 0) return 0;
  340. return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
  341. }
  342. static void sleep_for(long t)
  343. {
  344. struct timespec req;
  345. const time_t sec = (int)(t/1000);
  346. const long ms = t - (sec * 1000);
  347. req.tv_sec = sec;
  348. req.tv_nsec = ms * 1000000L;
  349. while(-1 == nanosleep(&req, &req));
  350. }
  351. static void nk_wayland_surf_clear(struct nk_wayland* win)
  352. {
  353. int x, y;
  354. int pix_idx;
  355. for (y = 0; y < HEIGHT; y++){
  356. for (x = 0; x < WIDTH; x++){
  357. pix_idx = y * WIDTH + x;
  358. win->data[pix_idx] = 0xFF000000;
  359. }
  360. }
  361. }
  362. //This causes the screen to refresh
  363. static const struct wl_callback_listener frame_listener;
  364. static void redraw(void *data, struct wl_callback *callback, uint32_t time)
  365. {
  366. // printf("redrawing.. 1\n");
  367. struct nk_wayland* win = (struct nk_wayland*)data;
  368. NK_UNUSED(callback);
  369. NK_UNUSED(time);
  370. wl_callback_destroy(win->frame_callback);
  371. wl_surface_damage(win->surface, 0, 0, WIDTH, HEIGHT);
  372. win->frame_callback = wl_surface_frame(win->surface);
  373. wl_surface_attach(win->surface, win->front_buffer, 0, 0);
  374. wl_callback_add_listener(win->frame_callback, &frame_listener, win);
  375. wl_surface_commit(win->surface);
  376. }
  377. static const struct wl_callback_listener frame_listener = {
  378. redraw
  379. };
  380. int main ()
  381. {
  382. long dt;
  383. long started;
  384. struct nk_wayland nk_wayland_ctx;
  385. struct wl_registry *registry;
  386. int running = 1;
  387. struct rawfb_pl pl;
  388. #ifdef INCLUDE_CONFIGURATOR
  389. static struct nk_color color_table[NK_COLOR_COUNT];
  390. memcpy(color_table, nk_default_color_style, sizeof(color_table));
  391. #endif
  392. //1. Initialize display
  393. nk_wayland_ctx.display = wl_display_connect (NULL);
  394. if (nk_wayland_ctx.display == NULL) {
  395. printf("no wayland display found. do you have wayland composer running? \n");
  396. return -1;
  397. }
  398. registry = wl_display_get_registry (nk_wayland_ctx.display);
  399. wl_registry_add_listener (registry, &nk_wayland_registry_listener, &nk_wayland_ctx);
  400. wl_display_roundtrip (nk_wayland_ctx.display);
  401. //2. Create Window
  402. nk_wayland_ctx.surface = wl_compositor_create_surface (nk_wayland_ctx.compositor);
  403. nk_wayland_ctx.xdg_surface = xdg_wm_base_get_xdg_surface(nk_wayland_ctx.xdg_wm_base, nk_wayland_ctx.surface);
  404. xdg_surface_add_listener (nk_wayland_ctx.xdg_surface, &nk_wayland_xdg_surface_listener, &nk_wayland_ctx);
  405. nk_wayland_ctx.xdg_toplevel = xdg_surface_get_toplevel(nk_wayland_ctx.xdg_surface);
  406. xdg_toplevel_add_listener (nk_wayland_ctx.xdg_toplevel, &nk_wayland_xdg_toplevel_listener, &nk_wayland_ctx);
  407. nk_wayland_ctx.frame_callback = wl_surface_frame(nk_wayland_ctx.surface);
  408. wl_callback_add_listener(nk_wayland_ctx.frame_callback, &frame_listener, &nk_wayland_ctx);
  409. wl_surface_commit (nk_wayland_ctx.surface);
  410. size_t size = WIDTH * HEIGHT * 4;
  411. char *xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
  412. int fd = open (xdg_runtime_dir, O_TMPFILE|O_RDWR|O_EXCL, 0600);
  413. ftruncate (fd, size);
  414. nk_wayland_ctx.data = mmap (NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
  415. struct wl_shm_pool *pool = wl_shm_create_pool (nk_wayland_ctx.wl_shm, fd, size);
  416. nk_wayland_ctx.front_buffer = wl_shm_pool_create_buffer (pool, 0, WIDTH, HEIGHT, WIDTH*4, WL_SHM_FORMAT_XRGB8888);
  417. wl_shm_pool_destroy (pool);
  418. close (fd);
  419. wl_display_roundtrip (nk_wayland_ctx.display);
  420. //3. Clear window and start rendering loop
  421. nk_wayland_surf_clear(&nk_wayland_ctx);
  422. wl_surface_attach (nk_wayland_ctx.surface, nk_wayland_ctx.front_buffer, 0, 0);
  423. wl_surface_commit (nk_wayland_ctx.surface);
  424. pl.bytesPerPixel = 4;
  425. pl.ashift = 24;
  426. pl.rshift = 16;
  427. pl.gshift = 8;
  428. pl.bshift = 0;
  429. pl.aloss = 0;
  430. pl.rloss = 0;
  431. pl.gloss = 0;
  432. pl.bloss = 0;
  433. nk_wayland_ctx.rawfb = nk_rawfb_init(nk_wayland_ctx.data, nk_wayland_ctx.tex_scratch, WIDTH, HEIGHT, WIDTH*4, pl);
  434. //4. rendering UI
  435. while (running) {
  436. started = timestamp();
  437. // GUI
  438. if (nk_begin(&(nk_wayland_ctx.rawfb->ctx), "Demo", nk_rect(50, 50, 200, 200),
  439. NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|
  440. NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) {
  441. enum {EASY, HARD};
  442. static int op = EASY;
  443. static int property = 20;
  444. nk_layout_row_static(&(nk_wayland_ctx.rawfb->ctx), 30, 80, 1);
  445. if (nk_button_label(&(nk_wayland_ctx.rawfb->ctx), "button")){
  446. printf("button pressed\n");
  447. }
  448. nk_layout_row_dynamic(&(nk_wayland_ctx.rawfb->ctx), 30, 2);
  449. if (nk_option_label(&(nk_wayland_ctx.rawfb->ctx), "easy", op == EASY)) op = EASY;
  450. if (nk_option_label(&(nk_wayland_ctx.rawfb->ctx), "hard", op == HARD)) op = HARD;
  451. nk_layout_row_dynamic(&(nk_wayland_ctx.rawfb->ctx), 25, 1);
  452. nk_property_int(&(nk_wayland_ctx.rawfb->ctx), "Compression:", 0, &property, 100, 10, 1);
  453. }
  454. nk_end(&(nk_wayland_ctx.rawfb->ctx));
  455. if (nk_window_is_closed(&(nk_wayland_ctx.rawfb->ctx), "Demo")) break;
  456. /* -------------- EXAMPLES ---------------- */
  457. #ifdef INCLUDE_CALCULATOR
  458. calculator(&(nk_wayland_ctx.rawfb->ctx));
  459. #endif
  460. #ifdef INCLUDE_CANVAS
  461. canvas(&(nk_wayland_ctx.rawfb->ctx));
  462. #endif
  463. #ifdef INCLUDE_OVERVIEW
  464. overview(&(nk_wayland_ctx.rawfb->ctx));
  465. #endif
  466. #ifdef INCLUDE_CONFIGURATOR
  467. style_configurator(&(nk_wayland_ctx.rawfb->ctx), color_table);
  468. #endif
  469. #ifdef INCLUDE_NODE_EDITOR
  470. node_editor(&(nk_wayland_ctx.rawfb->ctx));
  471. #endif
  472. /* ----------------------------------------- */
  473. // Draw framebuffer
  474. nk_rawfb_render(nk_wayland_ctx.rawfb, nk_rgb(30,30,30), 1);
  475. //handle wayland stuff (send display to FB & get inputs)
  476. nk_input_begin(&(nk_wayland_ctx.rawfb->ctx));
  477. wl_display_dispatch(nk_wayland_ctx.display);
  478. nk_input_end(&(nk_wayland_ctx.rawfb->ctx));
  479. // Timing
  480. dt = timestamp() - started;
  481. if (dt < DTIME)
  482. sleep_for(DTIME - dt);
  483. }
  484. nk_wayland_deinit (&nk_wayland_ctx);
  485. wl_display_disconnect (nk_wayland_ctx.display);
  486. return 0;
  487. }