From 33574462787596e24c010ca185c30cfcf1fc1e32 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Wed, 9 Apr 2008 01:35:09 -0800 Subject: [PATCH] Simplify the text window in SolveSpace; better scrolling behaviour, and my concept is more like a web page than like a command line. [git-p4: depot-paths = "//depot/solvespace/": change = 1659] --- cmdline.cpp | 13 +++++-------- ui.h | 2 +- win32/w32main.cpp | 11 ++++++----- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cmdline.cpp b/cmdline.cpp index 026db5bb..3c0a3945 100644 --- a/cmdline.cpp +++ b/cmdline.cpp @@ -25,7 +25,6 @@ void TextWindow::ClearScreen(void) { meta[i][j].link = NOT_A_LINK; } } - row0 = 0; rows = 0; } @@ -33,14 +32,12 @@ void TextWindow::Printf(char *fmt, ...) { va_list vl; va_start(vl, fmt); + if(rows >= MAX_ROWS) return; + int r, c; - if(rows < MAX_ROWS) { - r = rows; - rows++; - } else { - r = row0; - row0++; - } + r = rows; + rows++; + for(c = 0; c < MAX_COLS; c++) { text[r][c] = ' '; meta[r][c].link = NOT_A_LINK; diff --git a/ui.h b/ui.h index 34e04901..596f5e60 100644 --- a/ui.h +++ b/ui.h @@ -42,7 +42,7 @@ public: LinkFunction *f; } meta[MAX_ROWS][MAX_COLS]; - int row0, rows; + int rows; void Init(void); void Printf(char *fmt, ...); diff --git a/win32/w32main.cpp b/win32/w32main.cpp index 627bd132..cacb450b 100644 --- a/win32/w32main.cpp +++ b/win32/w32main.cpp @@ -64,6 +64,9 @@ static void PaintTextWnd(HDC hdc) rows--; TextWndRows = rows; + TextWndScrollPos = min(TextWndScrollPos, SS.TW.rows - rows); + TextWndScrollPos = max(TextWndScrollPos, 0); + // Let's set up the scroll bar first SCROLLINFO si; memset(&si, 0, sizeof(si)); @@ -79,22 +82,20 @@ static void PaintTextWnd(HDC hdc) for(r = TextWndScrollPos; r < (TextWndScrollPos+rows); r++) { if(r < 0) continue; if(r >= SS.TW.MAX_ROWS) continue; - int rr = (r + SS.TW.row0); - while(rr >= SS.TW.MAX_ROWS) rr -= SS.TW.MAX_ROWS; for(c = 0; c < SS.TW.MAX_COLS; c++) { char v = '0' + (c % 10); - int color = SS.TW.meta[rr][c].color; + int color = SS.TW.meta[r][c].color; SetTextColor(backDc, SS.TW.colors[color].fg); SetBkColor(backDc, SS.TW.colors[color].bg); - if(SS.TW.meta[rr][c].link) { + if(SS.TW.meta[r][c].link) { SelectObject(backDc, LinkFont); } else { SelectObject(backDc, FixedFont); } TextOut(backDc, 4 + c*TEXT_WIDTH, (r-TextWndScrollPos)*TEXT_HEIGHT, - (char *)&(SS.TW.text[rr][c]), 1); + (char *)&(SS.TW.text[r][c]), 1); } }