Scale font height rather than oversampling

This commit is contained in:
Kristian Bolino 2022-03-16 16:47:36 -04:00
parent 779c420d06
commit 04eac1db2a

View File

@ -76,10 +76,7 @@ main(int argc, char *argv[])
SDL_Renderer *renderer; SDL_Renderer *renderer;
int running = 1; int running = 1;
int flags = 0; int flags = 0;
float font_scale = 1;
/* Nuklear settings */
unsigned char oversample_h = 1;
unsigned char oversample_v = 1;
/* GUI */ /* GUI */
struct nk_context *ctx; struct nk_context *ctx;
@ -126,12 +123,7 @@ main(int argc, char *argv[])
scale_x = (float)(render_w) / (float)(window_w); scale_x = (float)(render_w) / (float)(window_w);
scale_y = (float)(render_h) / (float)(window_h); scale_y = (float)(render_h) / (float)(window_h);
SDL_RenderSetScale(renderer, scale_x, scale_y); SDL_RenderSetScale(renderer, scale_x, scale_y);
if (scale_x > 1) { font_scale = scale_y;
oversample_h = 3 * nk_iceilf(scale_x);
}
if (scale_y > 1) {
oversample_v = nk_iceilf(scale_y);
}
} }
/* GUI */ /* GUI */
@ -141,28 +133,25 @@ main(int argc, char *argv[])
{ {
struct nk_font_atlas *atlas; struct nk_font_atlas *atlas;
struct nk_font_config config = nk_font_config(0); struct nk_font_config config = nk_font_config(0);
struct nk_font *default_font, *droid, *roboto, *future, *clean, *tiny, *cousine; struct nk_font *font;
/* oversample the fonts for high-DPI displays */ /* set up the font atlas and add desired font; note that font sizes are
if (oversample_h > config.oversample_h) { * multiplied by font_scale to produce better results at higher DPIs */
config.oversample_h = oversample_h;
}
if (oversample_v > config.oversample_v) {
config.oversample_v = oversample_v;
}
/* set up the font atlas and add desired fonts */
nk_sdl_font_stash_begin(&atlas); nk_sdl_font_stash_begin(&atlas);
default_font = nk_font_atlas_add_default(atlas, 13, &config); font = nk_font_atlas_add_default(atlas, 13 * font_scale, &config);
/*droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, &config);*/ /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14 * font_scale, &config);*/
/*roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, &config);*/ /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16 * font_scale, &config);*/
/*future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, &config);*/ /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13 * font_scale, &config);*/
/*clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, &config);*/ /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12 * font_scale, &config);*/
/*tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, &config);*/ /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10 * font_scale, &config);*/
/*cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, &config);*/ /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13 * font_scale, &config);*/
nk_sdl_font_stash_end(); nk_sdl_font_stash_end();
/* this hack makes the font appear to be scaled down to the desired
* size and is only necessary when font_scale > 1 */
font->handle.height /= font_scale;
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/ /*nk_style_load_all_cursors(ctx, atlas->cursors);*/
nk_style_set_font(ctx, &default_font->handle); nk_style_set_font(ctx, &font->handle);
} }
#ifdef INCLUDE_STYLE #ifdef INCLUDE_STYLE