From bcf635d5f94090a12bdd90ae5f241e028d34e764 Mon Sep 17 00:00:00 2001 From: DarwinNE Date: Thu, 9 Jan 2020 22:39:08 +0100 Subject: [PATCH] Used a single array for attributed chars to simplify code as well as condensed bold style for the font, so to have a regular grid. --- IConsole/retro/IConsole.cc | 120 +++++++++++-------------------------- IConsole/retro/IConsole.h | 11 +++- 2 files changed, 43 insertions(+), 88 deletions(-) diff --git a/IConsole/retro/IConsole.cc b/IConsole/retro/IConsole.cc index d5e4c85aa0..c9f99df9e0 100644 --- a/IConsole/retro/IConsole.cc +++ b/IConsole/retro/IConsole.cc @@ -80,6 +80,16 @@ inline bool operator!=(const Attributes& lhs, const Attributes& rhs) return !(lhs == rhs); } +inline bool operator==(const AttributedChar& lhs, const AttributedChar& rhs) +{ + return lhs.c==rhs.c && lhs.attrs==rhs.attrs; +} + +inline bool operator!=(const AttributedChar& lhs, const AttributedChar& rhs) +{ + return !(lhs == rhs); +} + namespace { class FontSetup @@ -143,8 +153,7 @@ void IConsole::Init(GrafPtr port, Rect r) rows = (bounds.bottom - bounds.top) / cellSizeY; cols = (bounds.right - bounds.left) / cellSizeX; - chars = std::vector(rows*cols, ' '); - attrs = std::vector(rows*cols); + chars = std::vector(rows*cols, AttributedChar(' ',currentAttr)); onscreen = chars; @@ -154,37 +163,13 @@ void IConsole::Init(GrafPtr port, Rect r) void IConsole::SetAttributes(Attributes aa) { - TextFace(aa.isBold()?bold:0 + aa.isUnderline()?underline:0 + aa.isItalic()?italic:0); -} - -short IConsole::CalcStartX(short x, short y) -{ - Attributes a=attrs[y * cols]; - SetAttributes(a); - short start=0; - short widthpx=0; - for(int i=0; i cursorX) @@ -252,20 +207,16 @@ void IConsole::DrawCells(short x1, short x2, short y, bool erase) EraseRect(&r); MoveTo(r.left, r.bottom - 2); - a=attrs[y * cols + x1]; + Attributes a=chars[y * cols + x1].attrs; SetAttributes(a); - start=x1; for(int i=x1; i= cols) PutCharNoUpdate('\n'); // This is to make sure the cursor width is calculated correctly - attrs[cursorY * cols + cursorX] = currentAttr; - + chars[cursorY * cols + cursorX].attrs = currentAttr; } } @@ -416,12 +364,12 @@ void IConsole::Update() bool needclear = false; for(short col = dirtyRect.left; col < dirtyRect.right; ++col) { - char old = onscreen[row * cols + col]; + AttributedChar old = onscreen[row * cols + col]; if(chars[row * cols + col] != old) { if(start == -1) start = col; - if(old != ' ') + if(old.c != ' ') needclear = true; onscreen[row * cols + col] = chars[row * cols + col]; } @@ -443,8 +391,8 @@ void IConsole::Update() Rect r = CellRect(cursorX, cursorY); if(cursorDrawn) DrawCell(cursorX, cursorY, true); - //else - // InvertRect(&r); + else + InvertRect(&r); cursorDrawn = !cursorDrawn; } @@ -555,11 +503,11 @@ void IConsole::Reshape(Rect newBounds) cursorY = newRows - 1; } - std::vector newChars(newRows*newCols, ' '); + std::vector newChars(newRows*newCols, AttributedChar(' ', currentAttr)); for(short row = 0; row < newRows && row + upshift < rows; row++) { - char *src = &chars[(row+upshift) * cols]; - char *dst = &newChars[row * newCols]; + AttributedChar *src = &chars[(row+upshift) * cols]; + AttributedChar *dst = &newChars[row * newCols]; std::copy(src, src + std::min(cols, newCols), dst); } chars.swap(newChars); diff --git a/IConsole/retro/IConsole.h b/IConsole/retro/IConsole.h index e71b3a4639..053a7a7357 100644 --- a/IConsole/retro/IConsole.h +++ b/IConsole/retro/IConsole.h @@ -46,6 +46,14 @@ namespace retro bool cUnderline; bool cItalic; }; + + class AttributedChar + { + public: + char c; + Attributes attrs; + AttributedChar(char cc, Attributes aa) {c=cc; attrs=aa;} + }; // inline bool operator==(const Attributes& lhs, const Attributes& rhs); // inline bool operator!=(const Attributes& lhs, const Attributes& rhs); @@ -79,8 +87,7 @@ namespace retro Rect bounds; Attributes currentAttr; - std::vector chars, onscreen; - std::vector attrs; + std::vector chars, onscreen; bool isProcessingEscSequence; int sequenceStep;