AmendHub

Download:

jcs

/

subtext

/

amendments

/

11

console: Center window, fix line/column calculation in redraw


jcs made amendment 11 over 2 years ago
--- console.c Tue Nov 30 21:55:45 2021 +++ console.c Sun Dec 5 21:43:35 2021 @@ -24,7 +24,7 @@ /* for monaco 9 */ #define FONT_WIDTH 6 -#define FONT_HEIGHT 10 +#define FONT_HEIGHT 11 struct node_funcs console_node_funcs = { console_input, @@ -41,17 +41,23 @@ console_init(void) struct console *console; Rect bounds = { 0 }; Rect data_bounds = { 0, 0, 0, 1 }; /* tlbr */ - short padding = 20; + short width, height; console = xmalloczero(sizeof(struct console)); memset(console->chars, ' ', sizeof(console->chars)); + console->ncolumns = 80; + console->nlines = 24; + console->attrs[0] |= (ATTR_CURSOR | ATTR_DIRTY); + + width = FONT_WIDTH * (console->ncolumns + 2); + height = (FONT_HEIGHT * console->nlines) + (FONT_WIDTH * 2); + + bounds.left = (screenBits.bounds.right - width) / 2; + bounds.right = bounds.left + width; + bounds.top = ((screenBits.bounds.bottom - height) / 2) + + (GetMBarHeight()); + bounds.bottom = bounds.top + height; - bounds.left = (padding / 2); - bounds.top = screenBits.bounds.top + (GetMBarHeight() * 2) - 1 + - (padding / 2); - bounds.right = screenBits.bounds.right - 1 - (padding / 2); - bounds.bottom = screenBits.bounds.bottom - 1 - (padding / 2); - if (sprintf(title, "%s: console", PROGRAM_NAME) > sizeof(title)) err(1, "sprintf overflow!"); CtoPstr(title); @@ -73,9 +79,6 @@ console_init(void) console->session = session_create("console", &console_node_funcs); console->session->cookie = (void *)console; - console->ncolumns = 80; - console->nlines = 24; - console->attrs[0] |= (ATTR_CURSOR | ATTR_DIRTY); return console; } @@ -271,7 +274,7 @@ console_redraw(struct console *console, short nhints, cell = n; } - line = ((cell + 1) / console->ncolumns); + line = cell / console->ncolumns; column = cell - (line * console->ncolumns); cursor.left = FONT_WIDTH + ((console->win->portRect.left +