aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2021-04-13 23:50:11 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2021-04-13 23:50:11 +0200
commitd25619d360ccd7d9c5ce6806238e3205a9b9271b (patch)
tree7049ebf41c36a16cb29d3ae48188e1a4c04bad3c
parent22368f0f07811c261044f8dda787efa59f3925b1 (diff)
parent3dc9383ec0c40b65424a0f34b3d38da5580e4b39 (diff)
downloadpatchmatrix-d25619d360ccd7d9c5ce6806238e3205a9b9271b.tar.xz
Merge commit '3dc9383ec0c40b65424a0f34b3d38da5580e4b39'
-rw-r--r--subprojects/nk_pugl/VERSION2
-rw-r--r--subprojects/nk_pugl/example/example.c8
-rw-r--r--subprojects/nk_pugl/nk_pugl/nk_pugl.h108
3 files changed, 54 insertions, 64 deletions
diff --git a/subprojects/nk_pugl/VERSION b/subprojects/nk_pugl/VERSION
index 8ca4b71..d3bfa59 100644
--- a/subprojects/nk_pugl/VERSION
+++ b/subprojects/nk_pugl/VERSION
@@ -1 +1 @@
-0.1.171
+0.1.173
diff --git a/subprojects/nk_pugl/example/example.c b/subprojects/nk_pugl/example/example.c
index 1c505da..c55a2ca 100644
--- a/subprojects/nk_pugl/example/example.c
+++ b/subprojects/nk_pugl/example/example.c
@@ -53,8 +53,10 @@ 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;
+ const float scale = nk_pugl_get_scale();
+
+ cfg->width = 1280 * scale;
+ cfg->height = 720 * scale;
cfg->resizable = true;
cfg->parent = 0;
cfg->threads = false;
@@ -64,7 +66,7 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
cfg->expose = _expose;
cfg->data = NULL;
cfg->font.face = "./Cousine-Regular.ttf";
- cfg->font.size = 13;
+ cfg->font.size = 13 * scale;
signal(SIGTERM, _sigint);
signal(SIGINT, _sigint);
diff --git a/subprojects/nk_pugl/nk_pugl/nk_pugl.h b/subprojects/nk_pugl/nk_pugl/nk_pugl.h
index 47d51b5..58fce93 100644
--- a/subprojects/nk_pugl/nk_pugl/nk_pugl.h
+++ b/subprojects/nk_pugl/nk_pugl/nk_pugl.h
@@ -107,7 +107,6 @@ struct _nk_pugl_config_t {
struct _nk_pugl_window_t {
nk_pugl_config_t cfg;
char urn [46];
- float scale;
PuglWorld *world;
PuglView *view;
@@ -183,7 +182,7 @@ NK_PUGL_API const char *
nk_pugl_paste_from_clipboard(nk_pugl_window_t *win, size_t *len);
NK_PUGL_API float
-nk_pugl_get_scale(nk_pugl_window_t *win);
+nk_pugl_get_scale();
#ifdef __cplusplus
}
@@ -450,7 +449,7 @@ _nk_pugl_font_init(nk_pugl_window_t *win)
{
nk_pugl_config_t *cfg = &win->cfg;
- const int font_size = cfg->font.size * win->scale;
+ const int font_size = cfg->font.size;
// init nuklear font
struct nk_font *ttf = NULL;
@@ -968,63 +967,8 @@ nk_pugl_init(nk_pugl_window_t *win)
nk_pugl_config_t *cfg = &win->cfg;
struct nk_convert_config *conv = &win->conv;
- const char *NK_SCALE = getenv("NK_SCALE");
- const float scale = NK_SCALE ? atof(NK_SCALE) : 1.f;
- const float dpi0 = 96.f; // reference DPI we're designing for
- float dpi1 = dpi0;
-
-#if defined(__APPLE__)
- // FIXME
-#elif defined(_WIN32)
- // GetDpiForSystem/Monitor/Window is Win10 only
- HDC screen = GetDC(NULL);
- dpi1 = GetDeviceCaps(screen, LOGPIXELSX);
- ReleaseDC(NULL, screen);
-#else
- win->async = (atomic_flag)ATOMIC_FLAG_INIT;
- Display *disp = XOpenDisplay(0);
- if(disp)
- {
- // modern X actually lies here, but proprietary nvidia
- dpi1 = XDisplayWidth(disp, 0) * 25.4f / XDisplayWidthMM(disp, 0);
-
- // read DPI from users's ~/.Xresources
- char *resource_string = XResourceManagerString(disp);
- XrmInitialize();
- if(resource_string)
- {
- XrmDatabase db = XrmGetStringDatabase(resource_string);
- if(db)
- {
- char *type = NULL;
- XrmValue value;
-
- XrmGetResource(db, "Xft.dpi", "String", &type, &value);
- if(value.addr)
- {
- dpi1 = atof(value.addr);
- }
-
- XrmDestroyDatabase(db);
- }
- }
-
- XCloseDisplay(disp);
- }
-#endif
-
- win->scale = scale * dpi1 / dpi0;
- if(win->scale < 0.5)
- {
- win->scale = 0.5;
- }
win->has_left = true;
- cfg->width *= win->scale;
- cfg->height *= win->scale;
- cfg->min_width *= win->scale;
- cfg->min_height *= win->scale;
-
// init pugl
win->world = puglNewWorld(cfg->parent ? PUGL_MODULE : PUGL_PROGRAM,
cfg->threads ? PUGL_WORLD_THREADS : 0);
@@ -1376,9 +1320,53 @@ nk_pugl_paste_from_clipboard(nk_pugl_window_t *win, size_t *len)
}
NK_PUGL_API float
-nk_pugl_get_scale(nk_pugl_window_t *win)
+nk_pugl_get_scale()
{
- return win->scale;
+ const char *NK_SCALE = getenv("NK_SCALE");
+ const float scale = NK_SCALE ? atof(NK_SCALE) : 1.f;
+ const float dpi0 = 96.f; // reference DPI we're designing for
+ float dpi1 = dpi0;
+
+#if defined(__APPLE__)
+ // FIXME
+#elif defined(_WIN32)
+ // GetDpiForSystem/Monitor/Window is Win10 only
+ HDC screen = GetDC(NULL);
+ dpi1 = GetDeviceCaps(screen, LOGPIXELSX);
+ ReleaseDC(NULL, screen);
+#else
+ Display *disp = XOpenDisplay(0);
+ if(disp)
+ {
+ // modern X actually lies here, but proprietary nvidia
+ dpi1 = XDisplayWidth(disp, 0) * 25.4f / XDisplayWidthMM(disp, 0);
+
+ // read DPI from users's ~/.Xresources
+ char *resource_string = XResourceManagerString(disp);
+ XrmInitialize();
+ if(resource_string)
+ {
+ XrmDatabase db = XrmGetStringDatabase(resource_string);
+ if(db)
+ {
+ char *type = NULL;
+ XrmValue value;
+
+ XrmGetResource(db, "Xft.dpi", "String", &type, &value);
+ if(value.addr)
+ {
+ dpi1 = atof(value.addr);
+ }
+
+ XrmDestroyDatabase(db);
+ }
+ }
+
+ XCloseDisplay(disp);
+ }
+#endif
+
+ return scale * dpi1 / dpi0;
}
#ifdef __cplusplus