Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions workspace/all/common/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ static SDL_Rect asset_rects[ASSET_COUNT];
static uint32_t asset_rgbs[ASSET_COLORS];
static SDL_Rect input_rects[INPUT_COUNT];
GFX_Fonts font;
static int system_font_face_style = TTF_STYLE_NORMAL;

///////////////////////////////

Expand Down Expand Up @@ -324,6 +325,9 @@ int GFX_loadSystemFont(const char *fontPath)
font.tiny = TTF_OpenFont(fontPath, SCALE1(FONT_TINY));
font.micro = TTF_OpenFont(fontPath, SCALE1(FONT_MICRO));

// This value is only intrinsic before the configured style is applied.
system_font_face_style = font.large ? TTF_GetFontStyle(font.large) : TTF_STYLE_NORMAL;

TTF_SetFontStyle(font.large, CFG_getFontStyle());
TTF_SetFontStyle(font.medium, CFG_getFontStyle());
TTF_SetFontStyle(font.small, CFG_getFontStyle());
Expand All @@ -333,6 +337,11 @@ int GFX_loadSystemFont(const char *fontPath)
return 0;
}

int GFX_getSystemFontFaceStyle(void)
{
return system_font_face_style;
}

int GFX_updateColors(void)
{
// We are currently micro managing all of these screen-mapped colors,
Expand Down
3 changes: 3 additions & 0 deletions workspace/all/common/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ enum {
};

SDL_Surface* GFX_init(int mode);
// Style reported by SDL_ttf immediately after opening the current font face,
// before NextUI applies its configured synthetic style.
int GFX_getSystemFontFaceStyle(void);
#define GFX_resize PLAT_resizeVideo // (int w, int h, int pitch);
#define GFX_setSharpness PLAT_setSharpness // (int sharpness)
#define GFX_setEffectColor PLAT_setEffectColor // (int color)
Expand Down
4 changes: 3 additions & 1 deletion workspace/all/common/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,9 @@ int CFG_getFontStyle(void)

void CFG_setFontStyle(int style)
{
settings.fontStyle = clamp(style, 0x00, 0x01);
// SDL_ttf defines TTF_STYLE_NORMAL as 0x00 and TTF_STYLE_BOLD as 0x01.
// Use the values directly to keep config.c free of SDL dependencies.
settings.fontStyle = (style & 0x01) ? 0x01 : 0x00;
CFG_sync();
// reload the font to apply the new style (if the font supports it)
CFG_setFontFile(CFG_getFontFile());
Expand Down
25 changes: 21 additions & 4 deletions workspace/all/settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,31 @@ int main(int argc, char *argv[])
font_values.push_back(f.filename);
font_labels.push_back(f.label);
}

MenuItem *fontStyleItem = nullptr;
auto resetFontStyleToFaceDefault = [&fontStyleItem]() {
const int faceStyle = GFX_getSystemFontFaceStyle();
const int style = (faceStyle & TTF_STYLE_BOLD)
? TTF_STYLE_BOLD
: TTF_STYLE_NORMAL;
CFG_setFontStyle(style);
if (fontStyleItem)
fontStyleItem->reselect();
};
auto selectFont = [&resetFontStyleToFaceDefault](const char *filename) {
CFG_setFontFile(filename);
resetFontStyleToFaceDefault();
};

appearanceItems.push_back(new MenuItem{ListItemType::Generic, "Font", "The font to render all UI text.", font_values, font_labels,
[]() -> std::any { return std::string(CFG_getFontFile()); },
[](const std::any &value) { CFG_setFontFile(std::any_cast<std::string>(value).c_str()); },
[]() { CFG_setFontFile(CFG_DEFAULT_FONT_FILE); }});
appearanceItems.push_back(new MenuItem{ListItemType::Generic, "Font style", "The style to render the UI font (e.g. bold)", std::vector<std::any>{0, 1}, std::vector<std::string>{"Normal", "Bold"},
[&selectFont](const std::any &value) { selectFont(std::any_cast<std::string>(value).c_str()); },
[&selectFont]() { selectFont(CFG_DEFAULT_FONT_FILE); }});
fontStyleItem = new MenuItem{ListItemType::Generic, "Font style", "The style to render the UI font (e.g. bold)", std::vector<std::any>{TTF_STYLE_NORMAL, TTF_STYLE_BOLD}, std::vector<std::string>{"Normal", "Bold"},
[]() -> std::any { return CFG_getFontStyle(); },
[](const std::any &value) { CFG_setFontStyle(std::any_cast<int>(value)); },
[]() { CFG_setFontStyle(CFG_DEFAULT_FONT_STYLE); }});
[&resetFontStyleToFaceDefault]() { resetFontStyleToFaceDefault(); }};
appearanceItems.push_back(fontStyleItem);
appearanceItems.push_back(buildPaletteMenuItem());
for (auto *item : colorMenuItems)
appearanceItems.push_back(item);
Expand Down
Loading