summaryrefslogtreecommitdiff
path: root/ted.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-07-20 20:11:16 -0700
committerpommicket <pommicket@gmail.com>2023-07-20 20:16:12 -0700
commit02dd1005fee63a66bd8ed9afa647f373ec554a34 (patch)
treefc34f611ef33f1f34280e38bc960c3b6ad9f0589 /ted.c
parent6148ea652c3e396a12e739a7d84c1a2e46255485 (diff)
make ted DPI aware on windows
Diffstat (limited to 'ted.c')
-rw-r--r--ted.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/ted.c b/ted.c
index 56df17d..5585685 100644
--- a/ted.c
+++ b/ted.c
@@ -1,6 +1,9 @@
// various core ted functions (opening files, displaying errors, etc.)
#include "ted.h"
+#if _WIN32
+ #include <SDL_syswm.h>
+#endif
void die(const char *fmt, ...) {
char buf[256] = {0};
@@ -336,7 +339,32 @@ static Font *ted_load_multifont(Ted *ted, const char *filenames) {
return first_font;
}
+static float ted_get_ui_scaling(Ted *ted) {
+#if _WIN32
+ SDL_SysWMinfo wm_info;
+ SDL_VERSION(&wm_info.version);
+ if (!SDL_GetWindowWMInfo(ted->window, &wm_info))
+ return 1;
+ HWND hwnd = wm_info.info.win.window;
+ UINT dpi = GetDpiForWindow(hwnd);
+ if (!dpi)
+ return 1;
+ return (float)dpi / 96.0f;
+#else
+ return 1;
+#endif
+}
+
void ted_load_fonts(Ted *ted) {
+ {
+ // compute text size
+ float scaling = ted_get_ui_scaling(ted);
+ arr_foreach_ptr(ted->all_settings, Settings, set) {
+ u16 size = (u16)roundf(scaling * (float)set->text_size_no_dpi);
+ set->text_size = clamp_u16(size, TEXT_SIZE_MIN, TEXT_SIZE_MAX);
+ }
+ }
+
ted_free_fonts(ted);
Settings *settings = ted_active_settings(ted);
ted->font = ted_load_multifont(ted, settings->font);
@@ -794,3 +822,4 @@ void ted_color_settings_for_message_type(MessageType type, ColorSetting *bg_colo
break;
}
}
+