diff --git a/ssheven-console.c b/ssheven-console.c index 8e9ff10..7a38fe0 100644 --- a/ssheven-console.c +++ b/ssheven-console.c @@ -763,6 +763,35 @@ const VTermScreenCallbacks vtscrcb = .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) { // don't clobber font settings diff --git a/ssheven-console.h b/ssheven-console.h index fd42933..a2dccee 100644 --- a/ssheven-console.h +++ b/ssheven-console.h @@ -24,3 +24,5 @@ void update_console_colors(void); size_t get_selection(char** selection); void clear_selection(void); + +void font_size_change(void); diff --git a/ssheven-constants.r b/ssheven-constants.r index 7f0262f..fac8b68 100644 --- a/ssheven-constants.r +++ b/ssheven-constants.r @@ -96,6 +96,7 @@ #define CNTL_PREF_FG_COLOR 128 #define CNTL_PREF_BG_COLOR 129 #define CNTL_PREF_TERM_TYPE 130 +#define CNTL_PREF_FONT_SIZE 131 /* menus */ #define MBAR_SSHEVEN 128 @@ -105,5 +106,6 @@ #define MENU_EDIT 130 #define MENU_COLOR 131 #define MENU_TERM_TYPE 132 +#define MENU_FONT_SIZE 133 #endif diff --git a/ssheven.c b/ssheven.c index 3b37c9e..6a4f9d0 100644 --- a/ssheven.c +++ b/ssheven.c @@ -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) { // modal dialog setup @@ -382,12 +412,17 @@ void preferences_window(void) fg_color_menu = (ControlHandle)itemH; 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 // stop on ok or cancel short item; do { ModalDialog(NULL, &item); - } while(item != 1 && item != 9); + } while(item != 1 && item != 11); // save if OK'd if (item == 1) @@ -401,6 +436,14 @@ void preferences_window(void) prefs.bg_color = menu_item_to_qd_color(GetControlValue(bg_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(); diff --git a/ssheven.r b/ssheven.r index 024770e..19888dd 100644 --- a/ssheven.r +++ b/ssheven.r @@ -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) { - { 50, 100, 195, 420 }, + { 50, 100, 205, 420 }, dBoxProc, visible, noGoAway, @@ -516,7 +531,7 @@ resource 'DLOG' (DLOG_PREFERENCES) { resource 'DITL' (DITL_PREFERENCES) { { - { 115, 230, 135, 310 }, + { 125, 230, 145, 310 }, Button { enabled, "OK" }; { 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 }, 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" }; /* @@ -582,3 +603,14 @@ resource 'CNTL' (CNTL_PREF_TERM_TYPE) { 0, "" }; + +resource 'CNTL' (CNTL_PREF_FONT_SIZE) { + { 0, 0, 19, 150 }, + popupTitleLeftJust, + visible, + 0, + MENU_FONT_SIZE, + popupMenuProc, + 0, + "" +};