commit 10972fbbd35042e8650ee1212d1b9d1279c649b3
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Mar 12 11:20:54 2022 -0700
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Mar 12 11:20:54 2022 -0700
Add control codes for wide and tall characters
---
source/graphics.cpp | 44 ++++++++++++++++++++++++++++++++++++--------
source/graphics.h | 2 +-
source/hostVmShared.h | 12 ++++++++++++
source/printHelper.cpp | 36 ++++++++++++++++++++++++++++++++++--
test/printHelperTests.cpp | 34 ++++++++++++++++++++++++++++++++++
5 files changed, 117 insertions(+), 11 deletions(-)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index 4effd17..baf9d79 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -1248,15 +1248,43 @@ fix32 Graphics::fillp(fix32 pat) {
}
-int Graphics::drawCharacter(uint8_t ch, int x, int y) {
+int Graphics::drawCharacter(uint8_t ch, int x, int y, uint8_t printMode) {
int extraCharWidth = 0;
- if (ch >= 0x10 && ch < 0x80) {
- int index = ch - 0x10;
- copySpriteToScreen(fontSpriteData, x, y, (index % 16) * 8, (index / 16) * 8, 4, 5, false, false);
- } else if (ch >= 0x80) {
- int index = ch - 0x80;
- copySpriteToScreen(fontSpriteData, x, y, (index % 16) * 8, (index / 16) * 8 + 56, 8, 5, false, false);
- extraCharWidth = 4;
+ if ((printMode & PRINT_MODE_ON) == PRINT_MODE_ON){
+ int scrW = 4;
+ int scrH = 5;
+
+ if ((printMode & PRINT_MODE_WIDE) == PRINT_MODE_WIDE) {
+ scrW *= 2;
+ }
+ if((printMode & PRINT_MODE_TALL) == PRINT_MODE_TALL) {
+ scrH *= 2;
+ }
+ if((printMode & PRINT_MODE_STRIPEY) == PRINT_MODE_STRIPEY) {
+ //draw every other pixel-- also kinda broken on pico 8 0.2.4
+ }
+ //TODO: other print modes
+
+ if (ch >= 0x10 && ch < 0x80) {
+ int index = ch - 0x10;
+ copyStretchSpriteToScreen(fontSpriteData, (index % 16) * 8, (index / 16) * 8, 4, 5, x, y, scrW, scrH, false, false);
+ } else if (ch >= 0x80) {
+ int index = ch - 0x80;
+ extraCharWidth = 4;
+ copyStretchSpriteToScreen(fontSpriteData, (index % 16) * 8, (index / 16) * 8 + 56, 8, 5, x, y, (scrW + extraCharWidth), scrH, false, false);
+
+ }
+
+ }
+ else{
+ if (ch >= 0x10 && ch < 0x80) {
+ int index = ch - 0x10;
+ copySpriteToScreen(fontSpriteData, x, y, (index % 16) * 8, (index / 16) * 8, 4, 5, false, false);
+ } else if (ch >= 0x80) {
+ int index = ch - 0x80;
+ copySpriteToScreen(fontSpriteData, x, y, (index % 16) * 8, (index / 16) * 8 + 56, 8, 5, false, false);
+ extraCharWidth = 4;
+ }
}
return extraCharWidth;
diff --git a/source/graphics.h b/source/graphics.h
index 85d9eb7..ce3a0e2 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -108,7 +108,7 @@ class Graphics {
fix32 fillp(fix32 pat);
- int drawCharacter(uint8_t ch, int x, int y);
+ int drawCharacter(uint8_t ch, int x, int y, uint8_t printMode = 0);
void spr(
int n,
diff --git a/source/hostVmShared.h b/source/hostVmShared.h
index 83bf561..00aee38 100644
--- a/source/hostVmShared.h
+++ b/source/hostVmShared.h
@@ -73,3 +73,15 @@ struct InputState_t {
int16_t mouseY;
uint8_t mouseBtnState;
};
+
+enum PrintMode_t
+{
+ PRINT_MODE_ON = 0x1,
+ PRINT_MODE_PADDING = 0x2,
+ PRINT_MODE_WIDE = 0x4,
+ PRINT_MODE_TALL = 0x8,
+ PRINT_MODE_SOLID_BG = 0x10,
+ PRINT_MODE_INVERTED = 0x20,
+ PRINT_MODE_STRIPEY = 0x40,
+ PRINT_MODE_CUSTOM_FONT = 0x80
+};
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index ff9121b..525eb0f 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -84,6 +84,7 @@ int print(std::string str, int x, int y, uint8_t c) {
int tabStopWidth = 4;
int charWidth = 4;
int charHeight = 6;
+ uint8_t printMode = 0;
uint8_t effectiveC = _ph_graphics->getDrawPalMappedColor(c);
@@ -112,7 +113,7 @@ int print(std::string str, int x, int y, uint8_t c) {
ch = str[++n];
for(int i = 0; i < times; i++) {
- x += charWidth + _ph_graphics->drawCharacter(ch, x, y);
+ x += charWidth + _ph_graphics->drawCharacter(ch, x, y, printMode);
}
}
else if (ch == 2) { // "\#{p0}" draw text on a solid background color
@@ -200,6 +201,37 @@ int print(std::string str, int x, int y, uint8_t c) {
uint8_t charHeightChar = str[++n];
charHeight = p0CharToNum(charHeightChar);
}
+ else if (commandChar == 'w'){
+ printMode |= PRINT_MODE_ON;
+ printMode |= PRINT_MODE_WIDE;
+
+ }
+ else if (commandChar == 't'){
+ printMode |= PRINT_MODE_ON;
+ printMode |= PRINT_MODE_TALL;
+ }
+ else if (commandChar == '.'){
+ printMode |= PRINT_MODE_ON;
+ printMode |= PRINT_MODE_STRIPEY;
+ }
+ else if (commandChar == 'p'){
+ printMode |= PRINT_MODE_ON;
+ printMode |= PRINT_MODE_WIDE;
+ printMode |= PRINT_MODE_TALL;
+ printMode |= PRINT_MODE_STRIPEY;
+ }
+ else if (commandChar == 'i'){
+ printMode |= PRINT_MODE_ON;
+ printMode |= PRINT_MODE_INVERTED;
+ }
+ else if (commandChar == 'b'){
+ printMode |= PRINT_MODE_ON;
+ printMode |= PRINT_MODE_PADDING;
+ }
+ else if (commandChar == '#'){
+ printMode |= PRINT_MODE_ON;
+ printMode |= PRINT_MODE_SOLID_BG;
+ }
}
else if (ch == 12) { //"\f{p0}" draw text with this foreground color
@@ -224,7 +256,7 @@ int print(std::string str, int x, int y, uint8_t c) {
x = _ph_mem->drawState.text_x;
}
else if (ch >= 0x10) {
- x += charWidth + _ph_graphics->drawCharacter(ch, x, y);
+ x += charWidth + _ph_graphics->drawCharacter(ch, x, y, printMode);
while (framesToPause > 0){
_ph_vm->vm_flip();
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index 414b2a2..68bc893 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -401,6 +401,40 @@ TEST_CASE("Print helper functions") {
checkPoints(graphics, expectedPoints);
}
+ SUBCASE("p8scii special control code for wide character(\\^w) ") {
+ graphics->cls();
+
+ print("\x06""w:", 0, 0);
+
+ std::vector<coloredPoint> expectedPoints = {
+ {2, 0, 0}, {3, 0, 0},
+ {2, 1, 6}, {3, 1, 6},
+ {2, 2, 0}, {3, 2, 0},
+ {2, 3, 6}, {3, 3, 6},
+ {2, 4, 0}, {3, 4, 0}
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
+ SUBCASE("p8scii special control code for char height(\\^t) ") {
+ graphics->cls();
+
+ print("\x06""t:", 0, 0);
+
+ std::vector<coloredPoint> expectedPoints = {
+ {1, 0, 0},
+ {1, 1, 0},
+ {1, 2, 6},
+ {1, 3, 6},
+ {1, 4, 0},
+ {1, 5, 0},
+ {1, 6, 6},
+ {1, 7, 6},
+ {1, 8, 0}
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
delete stubHost;