Thu, 29 May 2025 11:34:34 +0200
add UI scaling
configure | file | annotate | diff | comparison | revisions | |
make/project.xml | file | annotate | diff | comparison | revisions | |
src/ascension/context.h | file | annotate | diff | comparison | revisions | |
src/ascension/ui.h | file | annotate | diff | comparison | revisions | |
src/context.c | file | annotate | diff | comparison | revisions | |
src/font.c | file | annotate | diff | comparison | revisions |
--- a/configure Thu May 29 11:20:49 2025 +0200 +++ b/configure Thu May 29 11:34:34 2025 +0200 @@ -430,6 +430,7 @@ break fi + TEMP_LDFLAGS="$TEMP_LDFLAGS -lm" cat >> "$TEMP_DIR/make.mk" << __EOF__ srcdir=$SRCDIR __EOF__
--- a/make/project.xml Thu May 29 11:20:49 2025 +0200 +++ b/make/project.xml Thu May 29 11:34:34 2025 +0200 @@ -6,6 +6,7 @@ <dependency> <lang>c</lang> <make>srcdir=$SRCDIR</make> + <ldflags>-lm</ldflags> </dependency> <dependency name="ucx">
--- a/src/ascension/context.h Thu May 29 11:20:49 2025 +0200 +++ b/src/ascension/context.h Thu May 29 11:34:34 2025 +0200 @@ -68,6 +68,7 @@ AscFont active_font; unsigned char active_window; asc_col4i ink; + float ui_scale; uint64_t frame_nanos; uint64_t total_nanos; } AscContext;
--- a/src/ascension/ui.h Thu May 29 11:20:49 2025 +0200 +++ b/src/ascension/ui.h Thu May 29 11:34:34 2025 +0200 @@ -30,5 +30,12 @@ #include "ui/text.h" +/** + * Sets the UI scaling factor. + * // TODO: think about whether this should be a context function which also triggers an update on all UI scenes + * @param factor the scaling factor + */ +#define asc_ui_scale(factor) asc_context.ui_scale = (factor) + #endif /* ASCENSION_UI_H */
--- a/src/context.c Thu May 29 11:20:49 2025 +0200 +++ b/src/context.c Thu May 29 11:34:34 2025 +0200 @@ -65,6 +65,9 @@ asc_context.active_font.style = ASC_FONT_REGULAR; asc_context.active_font.size = 14; + // default UI scale + asc_context.ui_scale = 1.0f; + // no window, yet asc_context.active_window = ASC_MAX_WINDOWS;
--- a/src/font.c Thu May 29 11:20:49 2025 +0200 +++ b/src/font.c Thu May 29 11:34:34 2025 +0200 @@ -31,6 +31,7 @@ #include "ascension/ui/font.h" #include <assert.h> +#include <math.h> #include <cx/array_list.h> void asc_font(enum AscFontStyle style, int size) { @@ -80,6 +81,11 @@ } TTF_Font *asc_font_load(AscFont font) { + // apply the UI scaling factor first to get the actual font size + if (asc_context.ui_scale != 1.f) { + font.size = (int) roundf((float) font.size * asc_context.ui_scale); + } + CxIterator iter = cxListIterator(asc_font_cache); cx_foreach(struct asc_font_cache_entry*, cache, iter) { if (cache->font.style == font.style && cache->font.size == font.size) {