add font size preference change UI and support for live changing

This commit is contained in:
cy384 2021-06-05 11:10:06 -04:00
parent 887237e0c7
commit 13a85e4e70
5 changed files with 112 additions and 4 deletions

View File

@ -763,6 +763,35 @@ const VTermScreenCallbacks vtscrcb =
.sb_popline = NULL .sb_popline = NULL
}; };
void font_size_change()
{
clear_selection();
// don't clobber font settings
short save_font = qd.thePort->txFont;
short save_font_size = qd.thePort->txSize;
short save_font_face = qd.thePort->txFace;
TextFont(kFontIDMonaco);
TextSize(prefs.font_size);
TextFace(normal);
FontInfo fi = {0};
GetFontInfo(&fi);
con.cell_height = fi.ascent + fi.descent + fi.leading + 1;
font_offset = fi.descent;
con.cell_width = fi.widMax;
TextFont(save_font);
TextSize(save_font_size);
TextFace(save_font_face);
SizeWindow(con.win, con.cell_width * con.size_x + 4, con.cell_height * con.size_y + 4, true);
EraseRect(&(con.win->portRect));
InvalRect(&(con.win->portRect));
}
void console_setup(void) void console_setup(void)
{ {
// don't clobber font settings // don't clobber font settings

View File

@ -24,3 +24,5 @@ void update_console_colors(void);
size_t get_selection(char** selection); size_t get_selection(char** selection);
void clear_selection(void); void clear_selection(void);
void font_size_change(void);

View File

@ -96,6 +96,7 @@
#define CNTL_PREF_FG_COLOR 128 #define CNTL_PREF_FG_COLOR 128
#define CNTL_PREF_BG_COLOR 129 #define CNTL_PREF_BG_COLOR 129
#define CNTL_PREF_TERM_TYPE 130 #define CNTL_PREF_TERM_TYPE 130
#define CNTL_PREF_FONT_SIZE 131
/* menus */ /* menus */
#define MBAR_SSHEVEN 128 #define MBAR_SSHEVEN 128
@ -105,5 +106,6 @@
#define MENU_EDIT 130 #define MENU_EDIT 130
#define MENU_COLOR 131 #define MENU_COLOR 131
#define MENU_TERM_TYPE 132 #define MENU_TERM_TYPE 132
#define MENU_FONT_SIZE 133
#endif #endif

View File

@ -347,6 +347,36 @@ int menu_item_to_qd_color(int menu_item)
} }
} }
int font_size_to_menu_item(int font_size)
{
switch (font_size)
{
case 9: return 1;
case 10: return 2;
case 12: return 3;
case 14: return 4;
case 18: return 5;
case 24: return 6;
case 36: return 7;
default: return 1;
}
}
int menu_item_to_font_size(int menu_item)
{
switch (menu_item)
{
case 1: return 9;
case 2: return 10;
case 3: return 12;
case 4: return 14;
case 5: return 18;
case 6: return 24;
case 7: return 36;
default: return 9;
}
}
void preferences_window(void) void preferences_window(void)
{ {
// modal dialog setup // modal dialog setup
@ -382,12 +412,17 @@ void preferences_window(void)
fg_color_menu = (ControlHandle)itemH; fg_color_menu = (ControlHandle)itemH;
SetControlValue(fg_color_menu, qd_color_to_menu_item(prefs.fg_color)); SetControlValue(fg_color_menu, qd_color_to_menu_item(prefs.fg_color));
ControlHandle font_size_menu;
GetDialogItem(dlg, 10, &type, &itemH, &box);
font_size_menu = (ControlHandle)itemH;
SetControlValue(font_size_menu, font_size_to_menu_item(prefs.font_size));
// let the modalmanager do everything // let the modalmanager do everything
// stop on ok or cancel // stop on ok or cancel
short item; short item;
do { do {
ModalDialog(NULL, &item); ModalDialog(NULL, &item);
} while(item != 1 && item != 9); } while(item != 1 && item != 11);
// save if OK'd // save if OK'd
if (item == 1) if (item == 1)
@ -401,6 +436,14 @@ void preferences_window(void)
prefs.bg_color = menu_item_to_qd_color(GetControlValue(bg_color_menu)); prefs.bg_color = menu_item_to_qd_color(GetControlValue(bg_color_menu));
prefs.fg_color = menu_item_to_qd_color(GetControlValue(fg_color_menu)); prefs.fg_color = menu_item_to_qd_color(GetControlValue(fg_color_menu));
int new_font_size = menu_item_to_font_size(GetControlValue(font_size_menu));
// resize window if font size changed
if (new_font_size != prefs.font_size)
{
prefs.font_size = new_font_size;
font_size_change();
}
save_prefs(); save_prefs();

View File

@ -503,8 +503,23 @@ resource 'MENU' (MENU_TERM_TYPE) {
} }
}; };
resource 'MENU' (MENU_FONT_SIZE) {
MENU_FONT_SIZE, textMenuProc;
allEnabled, enabled;
"Size";
{
"9", noIcon, noKey, noMark, plain;
"10", noIcon, noKey, noMark, plain;
"12", noIcon, noKey, noMark, plain;
"14", noIcon, noKey, noMark, plain;
"18", noIcon, noKey, noMark, plain;
"24", noIcon, noKey, noMark, plain;
"36", noIcon, noKey, noMark, plain;
}
};
resource 'DLOG' (DLOG_PREFERENCES) { resource 'DLOG' (DLOG_PREFERENCES) {
{ 50, 100, 195, 420 }, { 50, 100, 205, 420 },
dBoxProc, dBoxProc,
visible, visible,
noGoAway, noGoAway,
@ -516,7 +531,7 @@ resource 'DLOG' (DLOG_PREFERENCES) {
resource 'DITL' (DITL_PREFERENCES) { resource 'DITL' (DITL_PREFERENCES) {
{ {
{ 115, 230, 135, 310 }, { 125, 230, 145, 310 },
Button { enabled, "OK" }; Button { enabled, "OK" };
{ 190-10-20-5, 320-10-80-5, 190-10+5, 320-10+5 }, /* box for border */ { 190-10-20-5, 320-10-80-5, 190-10+5, 320-10+5 }, /* box for border */
@ -540,7 +555,13 @@ resource 'DITL' (DITL_PREFERENCES) {
{ 70, 150, 89, 300 }, { 70, 150, 89, 300 },
Control { enabled, CNTL_PREF_FG_COLOR }; Control { enabled, CNTL_PREF_FG_COLOR };
{ 115, 10, 135, 90 }, { 100, 66, 118, 132 },
StaticText { enabled, "Font Size: " };
{ 100, 150, 119, 300 },
Control { enabled, CNTL_PREF_FONT_SIZE };
{ 125, 10, 145, 90 },
Button { enabled, "Cancel" }; Button { enabled, "Cancel" };
/* /*
@ -582,3 +603,14 @@ resource 'CNTL' (CNTL_PREF_TERM_TYPE) {
0, 0,
"" ""
}; };
resource 'CNTL' (CNTL_PREF_FONT_SIZE) {
{ 0, 0, 19, 150 },
popupTitleLeftJust,
visible,
0,
MENU_FONT_SIZE,
popupMenuProc,
0,
""
};