aboutsummaryrefslogtreecommitdiff
path: root/subprojects/nk_pugl/example
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2020-04-08 12:19:11 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2020-04-08 12:19:11 +0200
commite7bc0b065ecb7144574af333b6e2e89b63924524 (patch)
treeba4bdf3228cf87b6622c9fcbcc1e9d0f681f7cef /subprojects/nk_pugl/example
parent7b2c07a52345a0effb03d6839d0ce3c764b3a602 (diff)
parent338cfea726c71ec7a049490e1e21d2ff8f14075b (diff)
downloadmidi_matrix.lv2-e7bc0b065ecb7144574af333b6e2e89b63924524.tar.xz
Merge commit '338cfea726c71ec7a049490e1e21d2ff8f14075b' as 'subprojects/nk_pugl'
Diffstat (limited to 'subprojects/nk_pugl/example')
-rw-r--r--subprojects/nk_pugl/example/example.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/subprojects/nk_pugl/example/example.c b/subprojects/nk_pugl/example/example.c
new file mode 100644
index 0000000..8efb947
--- /dev/null
+++ b/subprojects/nk_pugl/example/example.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2016-2020 Hanspeter Portner (dev@open-music-kontrollers.ch)
+ *
+ * This is free software: you can redistribute it and/or modify
+ * it under the terms of the Artistic License 2.0 as published by
+ * The Perl Foundation.
+ *
+ * This source is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Artistic License 2.0 for more details.
+ *
+ * You should have received a copy of the Artistic License 2.0
+ * along the source as a COPYING file. If not, obtain it from
+ * http://www.perlfoundation.org/artistic_license_2_0.
+ */
+
+#include <unistd.h>
+#include <signal.h>
+#include <time.h>
+#include <limits.h>
+
+#define LEN NK_LEN
+#define MAX NK_MAX
+
+#define NK_PUGL_IMPLEMENTATION
+#include <nk_pugl/nk_pugl.h>
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#pragma GCC diagnostic ignored "-Wunused-variable"
+#include "nuklear/demo/overview.c"
+#pragma GCC diagnostic pop
+
+static volatile sig_atomic_t done = 0;
+
+static void
+_sigint(int signum __attribute__((unused)))
+{
+ done = 1;
+}
+
+static void
+_expose(struct nk_context *ctx, struct nk_rect wbounds __attribute__((unused)),
+ void *data __attribute__((unused)))
+{
+ overview(ctx);
+}
+
+int
+main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
+{
+ static nk_pugl_window_t win;
+ nk_pugl_config_t *cfg = &win.cfg;
+
+ cfg->width = 1280;
+ cfg->height = 720;
+ cfg->resizable = true;
+ cfg->parent = 0;
+ cfg->ignore = false;
+ cfg->class = "nk_pugl_example";
+ cfg->title = "Nk Pugl Example";
+ cfg->expose = _expose;
+ cfg->data = NULL;
+ cfg->font.face = "./Cousine-Regular.ttf";
+ cfg->font.size = 13;
+
+ signal(SIGTERM, _sigint);
+ signal(SIGINT, _sigint);
+#if !defined(_WIN32)
+ signal(SIGQUIT, _sigint);
+ signal(SIGKILL, _sigint);
+#endif
+
+ const intptr_t widget = nk_pugl_init(&win);
+ if(!widget)
+ {
+ return 1;
+ }
+
+ nk_pugl_show(&win);
+
+#if !defined(_WIN32) && !defined(__APPLE__)
+ struct timespec tm;
+ clock_gettime(CLOCK_MONOTONIC, &tm);
+#endif
+
+ while(!done)
+ {
+#if !defined(_WIN32) && !defined(__APPLE__)
+ if(clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &tm, NULL) != 0)
+ {
+ continue;
+ }
+
+#define NANOS 1000000000
+ tm.tv_nsec += NANOS / 25;
+ while(tm.tv_nsec >= NANOS)
+ {
+ tm.tv_sec += 1;
+ tm.tv_nsec -= NANOS;
+ }
+#undef NANOS
+#else
+ usleep(1000000 / 25);
+#endif
+
+ done = nk_pugl_process_events(&win);
+ }
+
+ nk_pugl_hide(&win);
+
+ nk_pugl_shutdown(&win);
+
+ return 0;
+}