commit e1af5e785e27a4055bcd52c44fb1dce79113d0de
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Tue Jan 3 19:24:34 2023 -0600
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Tue Jan 3 19:24:34 2023 -0600
Add basic char decoration p8scii support
---
source/printHelper.cpp | 14 ++++++++++++++
test/printHelperTests.cpp | 15 +++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index b8c23b9..7fcb8d5 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -96,6 +96,8 @@ int print(std::string str, int x, int y, uint8_t c) {
int length = str.length();
int homeX = x;
int homeY = y;
+ int prevX = x;
+ int prevY = y;
int tabStopWidth = 4;
int charWidth = 4;
int charHeight = 6;
@@ -333,6 +335,16 @@ int print(std::string str, int x, int y, uint8_t c) {
}
//todo: generate audio stuff and play
}
+ else if (ch == 11) { // "\v" decorate previous character
+ uint8_t offsetChar = str[++n];
+ uint8_t toPrint = str[++n];
+ int offset = p0CharToNum(offsetChar);
+
+ int xOffset = (offset%4)-2;
+ int yOffset = (offset/4)-8;
+
+ _ph_graphics->drawCharacter(toPrint, prevX + xOffset, prevY + yOffset, printMode, forceCharWidth, forceCharHeight);
+ }
else if (ch == 12) { //"\f{p0}" draw text with this foreground color
uint8_t fgColChar = str[++n];
fgColor = p0CharToNum(fgColChar);
@@ -364,6 +376,8 @@ int print(std::string str, int x, int y, uint8_t c) {
_ph_graphics->rectfill(x-1, y-1, x + charWidth-1, y + lineHeight-1, bgColor);
_ph_mem->drawState.color = prevPenColor;
}
+ prevX = x;
+ prevY = y;
x += charWidth + _ph_graphics->drawCharacter(ch, x, y, printMode, forceCharWidth, forceCharHeight);
while (framesToPause > 0){
_ph_vm->vm_flip();
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index f37fdd6..a574da6 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -752,6 +752,21 @@ TEST_CASE("Print helper functions") {
checkPoints(graphics, expectedPoints);
}
+ SUBCASE("p8scii audio control code for decorating prev char (\\v)") {
+ graphics->cls();
+
+ print("\n:\x0b""b:", 0, 0);
+
+ std::vector<coloredPoint> expectedPoints = {
+ {2, 0, 0},
+ {2, 1, 6},
+ {2, 2, 0},
+ {2, 3, 6},
+ {2, 4, 0},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
delete stubHost;