Configurable OSD font

This commit is contained in:
Toni Wilen 2024-01-13 12:35:13 +02:00
parent 44eece8228
commit 89b857cc59
6 changed files with 88 additions and 42 deletions

View File

@ -645,6 +645,7 @@
#define IDC_GUI_DEFAULT 1289
#define IDC_INFO1 1289
#define IDC_INFO2 1290
#define IDC_OSD_FONT 1290
#define IDC_INFO3 1291
#define IDC_GUI_LVDEFAULT 1291
#define IDC_PORT0_JOYSC 1302

View File

@ -646,6 +646,7 @@ BEGIN
COMBOBOX IDC_KBLED3,184,295,64,65,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "USB mode",IDC_KBLED_USB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,264,296,64,11
CONTROL "Dark mode",IDC_GUI_DARKMODE,"Button",BS_AUTO3STATE | WS_TABSTOP,273,224,114,11
PUSHBUTTON "OSD Font...",IDC_OSD_FONT,333,146,54,14
END
IDD_HARDFILE DIALOGEX 0, 0, 397, 292
@ -1188,7 +1189,7 @@ BEGIN
END
IDD_STRINGBOX DIALOGEX 0, 0, 396, 209
STYLE DS_LOCALEDIT | DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
STYLE DS_LOCALEDIT | DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Enter text..."
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN

View File

@ -10,6 +10,8 @@
#include "win32.h"
#include "picasso96_win.h"
#include "win32gfx.h"
#include "registry.h"
#include "win32gui.h"
#include "statusline.h"
#include "gui.h"
#include "xwin.h"
@ -21,8 +23,10 @@ static int statusline_width;
static int statusline_height = TD_TOTAL_HEIGHT;
static HFONT statusline_font;
static HPALETTE statusline_palette;
static bool statusline_was_updated;
static char *td_new_numbers;
static int statusline_fontsize, statusline_fontstyle, statusline_fontweight;
static bool statusline_customfont;
static TCHAR statusline_fontname[256];
void deletestatusline(int monid)
{
@ -61,11 +65,16 @@ static void create_led_font(HWND parent, int monid)
xfree(td_new_numbers);
statusline_fontsize = 8;
_tcscpy(statusline_fontname, _T("Lucida Console"));
statusline_fontweight = FW_NORMAL;
statusline_customfont = regqueryfont(NULL, NULL, _T("OSDFont"), statusline_fontname, &statusline_fontsize, &statusline_fontstyle, &statusline_fontweight);
hdc = CreateCompatibleDC(NULL);
if (hdc) {
int y = getdpiforwindow(parent);
int fontsize = -MulDiv(6, y, 72);
fontsize = fontsize * statusline_get_multiplier(monid) / 100;
statusline_fontsize = -MulDiv(statusline_fontsize, y, 72);
statusline_fontsize = statusline_fontsize * statusline_get_multiplier(monid) / 100;
lp = (LOGPALETTE *)xcalloc(uae_u8, sizeof(LOGPALETTE) + 3 * sizeof(PALETTEENTRY));
if (lp) {
lp->palNumEntries = 4;
@ -94,10 +103,10 @@ static void create_led_font(HWND parent, int monid)
if (bitmap) {
SelectObject(hdc, bitmap);
RealizePalette(hdc);
HFONT font = CreateFont(fontsize, 0,
HFONT font = CreateFont(statusline_fontsize, 0,
0, 0,
FW_NORMAL,
FALSE,
statusline_fontweight,
(statusline_fontstyle & ITALIC_FONTTYPE) != 0,
FALSE,
FALSE,
DEFAULT_CHARSET,
@ -105,7 +114,7 @@ static void create_led_font(HWND parent, int monid)
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
FIXED_PITCH | FF_DONTCARE,
_T("Lucida Console"));
statusline_fontname);
if (font) {
SelectObject(hdc, font);
SetTextColor(hdc, PALETTEINDEX(2));
@ -188,10 +197,14 @@ bool createstatusline(HWND parentHwnd, int monid)
if (monid)
return false;
deletestatusline(mon->monitor_id);
statusline_hdc = CreateCompatibleDC(NULL);
if (!statusline_hdc)
return false;
create_led_font(parentHwnd, monid);
lp = (LOGPALETTE*)xcalloc(uae_u8, sizeof(LOGPALETTE) + 3 * sizeof(PALETTEENTRY));
if (!lp)
return false;
@ -204,6 +217,7 @@ bool createstatusline(HWND parentHwnd, int monid)
xfree(lp);
SelectPalette(statusline_hdc, statusline_palette, FALSE);
statusline_width = (WIN32GFX_GetWidth(mon) + 31) & ~31;
statusline_height = -statusline_fontsize;
bi = (BITMAPINFO*)xcalloc(uae_u8, sizeof(BITMAPINFOHEADER) + 4 * sizeof(RGBQUAD));
if (bi) {
bih = &bi->bmiHeader;
@ -228,12 +242,10 @@ bool createstatusline(HWND parentHwnd, int monid)
SelectObject(statusline_hdc, statusline_bitmap);
RealizePalette(statusline_hdc);
create_led_font(parentHwnd, monid);
statusline_font = CreateFont(-10, 0,
statusline_font = CreateFont(statusline_fontsize, 0,
0, 0,
FW_NORMAL,
FALSE,
statusline_fontweight,
(statusline_fontstyle & ITALIC_FONTTYPE) != 0,
FALSE,
FALSE,
DEFAULT_CHARSET,
@ -241,7 +253,7 @@ bool createstatusline(HWND parentHwnd, int monid)
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
VARIABLE_PITCH | FF_DONTCARE,
_T("Verdana"));
statusline_fontname);
SelectObject(statusline_hdc, statusline_font);
SetTextColor(statusline_hdc, PALETTEINDEX(2));
SetBkColor(statusline_hdc, PALETTEINDEX(1));
@ -255,7 +267,6 @@ void statusline_updated(int monid)
if (monid)
return;
struct AmigaMonitor *mon = &AMonitors[monid];
statusline_was_updated = true;
if (mon->hStatusWnd)
PostMessage(mon->hStatusWnd, SB_SETTEXT, (WPARAM)((window_led_msg_start) | SBT_OWNERDRAW), (LPARAM)_T(""));
}
@ -269,15 +280,16 @@ void statusline_render(int monid, uae_u8 *buf, int bpp, int pitch, int width, in
int y = -1, x = 10, textwidth = 0;
int bar_xstart;
if (monid)
if (monid || !statusline_hdc) {
return;
}
text = statusline_fetch();
//text = _T("Testing string 123!");
if (!text)
return;
BitBlt(statusline_hdc, 0, 0, statusline_width, statusline_height, NULL, 0, 0, BLACKNESS);
BitBlt(statusline_hdc, 0, 0, statusline_width, statusline_height, NULL, 0, 0, BLACKNESS);
SIZE size;
if (GetTextExtentPoint32(statusline_hdc, text, uaetcslen(text), &size)) {
textwidth = size.cx;

View File

@ -12868,10 +12868,17 @@ static void misc_setlang (int v)
exit_gui(0);
}
static void misc_gui_font (HWND hDlg, int fonttype)
static void misc_gui_font(HWND hDlg, int fonttype)
{
if (scaleresource_choosefont (hDlg, fonttype))
gui_size_changed = 10;
if (scaleresource_choosefont(hDlg, fonttype)) {
if (fonttype == 0) {
gui_size_changed = 10;
} else if (fonttype == 2) {
if (!full_property_sheet && AMonitors[0].hAmigaWnd) {
createstatusline(AMonitors[0].hAmigaWnd, 0);
}
}
}
}
static void values_to_miscdlg_dx(HWND hDlg)
@ -13252,7 +13259,10 @@ static INT_PTR MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
}
break;
case IDC_GUI_FONT:
misc_gui_font (hDlg, 0);
misc_gui_font(hDlg, 0);
break;
case IDC_OSD_FONT:
misc_gui_font(hDlg, 2);
break;
case IDC_GUI_RESIZE:
gui_resize_enabled = ischecked (hDlg, IDC_GUI_RESIZE);

View File

@ -172,5 +172,8 @@ void darkmode_initdialog(HWND hDlg);
void darkmode_themechanged(HWND hDlg);
INT_PTR darkmode_ctlcolor(WPARAM wParam, bool *handled);
void regsetfont(UAEREG *reg, const TCHAR *prefix, const TCHAR *name, const TCHAR *fontname, int fontsize, int fontstyle, int fontweight);
bool regqueryfont(UAEREG *reg, const TCHAR *prefix, const TCHAR *name, TCHAR *fontname, int *pfontsize, int *pfontstyle, int *pfontweight);
#endif

View File

@ -22,7 +22,7 @@
#include "darkmode.h"
#define MAX_GUI_FONTS 2
#define MAX_GUI_FONTS 3
#define DEFAULT_FONTSIZE_OLD 8
#define DEFAULT_FONTSIZE_NEW 9
@ -31,14 +31,17 @@ static int scaleresource_width, scaleresource_height;
static int scaleresource_reset;
static int dux, duy;
static TCHAR fontname_gui[32], fontname_list[32];
static TCHAR fontname_gui[32], fontname_list[32], fontname_osd[32];
static int fontsize_default = DEFAULT_FONTSIZE_OLD;
static int fontsize_gui = DEFAULT_FONTSIZE_OLD;
static int fontsize_list = DEFAULT_FONTSIZE_OLD;
static int fontsize_osd = 6;
static int fontstyle_gui = 0;
static int fontstyle_list = 0;
static int fontstyle_osd = 0;
static int fontweight_gui = FW_REGULAR;
static int fontweight_list = FW_REGULAR;
static int fontweight_osd = FW_REGULAR;
static TEXTMETRIC listview_tm;
static const TCHAR *fontprefix;
@ -1244,48 +1247,54 @@ static void setdeffont (void)
}
fontsize_default = fs;
_tcscpy (fontname_gui, wfont_vista);
_tcscpy(fontname_gui, wfont_vista);
fontsize_gui = fontsize_default;
fontstyle_gui = 0;
fontweight_gui = FW_REGULAR;
_tcscpy (fontname_list, wfont_vista);
_tcscpy(fontname_list, wfont_vista);
fontsize_list = fontsize_default;
fontstyle_list = 0;
fontweight_list = FW_REGULAR;
_tcscpy(fontname_osd, _T("Lucida Console"));
fontsize_osd = 8;
fontstyle_osd = 0;
fontweight_osd = FW_REGULAR;
}
static TCHAR *fontreg[2] = { _T("GUIFont"), _T("GUIListFont") };
static TCHAR *fontreg[3] = { _T("GUIFont"), _T("GUIListFont"), _T("OSDFont") };
static void regsetfont (UAEREG *reg, const TCHAR *prefix, const TCHAR *name, const TCHAR *fontname, int fontsize, int fontstyle, int fontweight)
void regsetfont(UAEREG *reg, const TCHAR *prefix, const TCHAR *name, const TCHAR *fontname, int fontsize, int fontstyle, int fontweight)
{
TCHAR tmp[256], tmp2[256];
_stprintf (tmp, _T("%s:%d:%d:%d"), fontname, fontsize, fontstyle, fontweight);
_stprintf (tmp2, _T("%s%s"), name, prefix);
regsetstr (reg, tmp2, tmp);
_stprintf(tmp, _T("%s:%d:%d:%d"), fontname, fontsize, fontstyle, fontweight);
_stprintf(tmp2, _T("%s%s"), name, prefix);
regsetstr(reg, tmp2, tmp);
}
static void regqueryfont (UAEREG *reg, const TCHAR *prefix, const TCHAR *name, TCHAR *fontname, int *pfontsize, int *pfontstyle, int *pfontweight)
bool regqueryfont(UAEREG *reg, const TCHAR *prefix, const TCHAR *name, TCHAR *fontname, int *pfontsize, int *pfontstyle, int *pfontweight)
{
TCHAR tmp2[256], tmp[256], *p1, *p2, *p3, *p4;
int size;
int fontsize, fontstyle, fontweight;
_tcscpy (tmp2, name);
_tcscat (tmp2, prefix);
if (prefix) {
_tcscat (tmp2, prefix);
}
size = sizeof tmp / sizeof (TCHAR);
if (!regquerystr (reg, tmp2, tmp, &size))
return;
return false;
p1 = _tcschr (tmp, ':');
if (!p1)
return;
return false;
*p1++ = 0;
p2 = _tcschr (p1, ':');
if (!p2)
return;
return false;
*p2++ = 0;
p3 = _tcschr (p2, ':');
if (!p3)
return;
return false;
*p3++ = 0;
p4 = _tcschr (p3, ':');
if (p4)
@ -1307,6 +1316,8 @@ static void regqueryfont (UAEREG *reg, const TCHAR *prefix, const TCHAR *name, T
*pfontstyle = fontstyle;
*pfontweight = fontweight;
return true;
}
void scaleresource_setdefaults(HWND hwnd)
@ -1330,30 +1341,38 @@ void scaleresource_init(const TCHAR *prefix, int fullscreen)
setdeffont();
if (fontprefix) {
regqueryfont (NULL, fontprefix, fontreg[0], fontname_gui, &fontsize_gui, &fontstyle_gui, &fontweight_gui);
regqueryfont (NULL, fontprefix, fontreg[1], fontname_list, &fontsize_list, &fontstyle_list, &fontweight_list);
regqueryfont(NULL, fontprefix, fontreg[0], fontname_gui, &fontsize_gui, &fontstyle_gui, &fontweight_gui);
regqueryfont(NULL, fontprefix, fontreg[1], fontname_list, &fontsize_list, &fontstyle_list, &fontweight_list);
}
//write_log (_T("GUI font %s:%d:%d:%d\n"), fontname_gui, fontsize_gui, fontstyle_gui, fontweight_gui);
//write_log (_T("List font %s:%d:%d:%d\n"), fontname_list, fontsize_list, fontstyle_list, fontweight_list);
}
int scaleresource_choosefont (HWND hDlg, int fonttype)
int scaleresource_choosefont(HWND hDlg, int fonttype)
{
CHOOSEFONT cf = { 0 };
LOGFONT lf = { 0 };
TCHAR *fontname[2];
int *fontsize[2], *fontstyle[2], *fontweight[2];
TCHAR *fontname[3];
int *fontsize[3], *fontstyle[3], *fontweight[3];
int lm = 72;
if (fonttype == 2) {
regqueryfont(NULL, NULL, fontreg[2], fontname_osd, &fontsize_osd, &fontstyle_osd, &fontweight_osd);
}
fontname[0] = fontname_gui;
fontname[1] = fontname_list;
fontname[2] = fontname_osd;
fontsize[0] = &fontsize_gui;
fontsize[1] = &fontsize_list;
fontsize[2] = &fontsize_osd;
fontstyle[0] = &fontstyle_gui;
fontstyle[1] = &fontstyle_list;
fontstyle[2] = &fontstyle_osd;
fontweight[0] = &fontweight_gui;
fontweight[1] = &fontweight_list;
fontweight[2] = &fontweight_osd;
cf.lStructSize = sizeof cf;
cf.hwndOwner = hDlg;
@ -1382,7 +1401,7 @@ int scaleresource_choosefont (HWND hDlg, int fonttype)
*fontweight[fonttype] = lf.lfWeight;
regsetfont (NULL, fontprefix, fontreg[fonttype], fontname[fonttype], *fontsize[fonttype], *fontstyle[fonttype], *fontweight[fonttype]);
regsetfont(NULL, fontprefix, fontreg[fonttype], fontname[fonttype], *fontsize[fonttype], *fontstyle[fonttype], *fontweight[fonttype]);
return 1;
}