commit f9841ef7c4809ce49e5649f96b0fc9b83b54d0e9
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sun Jan 15 16:11:17 2023 -0700
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sun Jan 15 16:11:17 2023 -0700
WIP- only one off chars not quite right
---
source/graphics.cpp | 71 +++++++++++++++++++++++++-------------------------
source/printHelper.cpp | 7 ++---
2 files changed, 40 insertions(+), 38 deletions(-)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index 848a68c..3dd26b9 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -1312,36 +1312,33 @@ int Graphics::drawCharacter(
int extraCharWidth = 0;
if ((printMode & PRINT_MODE_ON) == PRINT_MODE_ON){
- int scrW = 4;
- int scrH = 5;
- bool evenPxOnly = false;
- 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
- evenPxOnly = true;
- }
- //TODO: other print modes
+ if (ch > 0x0f) {
+ uint8_t charWidth =
+ ch < 0x80
+ ? forceCharWidth > -1 && forceCharWidth < 4 ? forceCharWidth : 4
+ : forceCharWidth > -1 && forceCharWidth < 4 ? (forceCharWidth + 4) : 8;
- 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, evenPxOnly);
- } 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, evenPxOnly);
+ uint8_t charHeight = forceCharHeight > -1 && forceCharHeight < 5 ? forceCharHeight : 5;
+
+ drawCharacterFromBytes(
+ &(defaultFontBinaryData[ch*8]),
+ x,
+ y,
+ fgColor,
+ bgColor,
+ printMode,
+ charWidth,
+ charHeight
+ );
}
+
}
else if ((printMode & PRINT_MODE_CUSTOM_FONT) == PRINT_MODE_CUSTOM_FONT) {
uint8_t charWidth =
ch < 0x80
? forceCharWidth > -1 && forceCharWidth < 4 ? forceCharWidth : _memory->data[0x5600]
- : forceCharWidth > -1 && forceCharWidth < 4 ? forceCharWidth : _memory->data[0x5601];
+ : forceCharWidth > -1 && forceCharWidth < 4 ? (forceCharWidth + 4) : _memory->data[0x5601];
uint8_t charHeight = forceCharHeight > -1 && forceCharHeight < 5 ? forceCharHeight : _memory->data[0x5602];
@@ -1374,7 +1371,7 @@ int Graphics::drawCharacter(
//need to pass in w/h to crop
drawCharacterFromBytes(
- &(defaultFontBinaryData[ch*8]),//get bytes from memory (0x5600)
+ &(defaultFontBinaryData[ch*8]),
x,
y,
fgColor,
@@ -1390,7 +1387,7 @@ int Graphics::drawCharacter(
uint8_t charHeight = forceCharHeight > -1 && forceCharHeight < 5 ? forceCharHeight : 5;
drawCharacterFromBytes(
- &(defaultFontBinaryData[ch*8]),//get bytes from memory (0x5600)
+ &(defaultFontBinaryData[ch*8]),
x,
y,
fgColor,
@@ -1431,11 +1428,11 @@ std::tuple<int, int> Graphics::drawCharacterFromBytes(
if ((printMode & PRINT_MODE_ON) == PRINT_MODE_ON){
if ((printMode & PRINT_MODE_WIDE) == PRINT_MODE_WIDE) {
wFactor = 2;
- extraCharWidth = 8;
+ extraCharWidth = charWidth;
}
if((printMode & PRINT_MODE_TALL) == PRINT_MODE_TALL) {
hFactor = 2;
- extraCharHeight = 8;
+ extraCharHeight = charHeight;
}
if((printMode & PRINT_MODE_STRIPEY) == PRINT_MODE_STRIPEY) {
//draw every other pixel-- also kinda broken on pico 8 0.2.4
@@ -1445,20 +1442,24 @@ std::tuple<int, int> Graphics::drawCharacterFromBytes(
}
if (bgColor != 0) {
+ //possible todo: check perf if this is better than doing it in the other loop (m)
uint8_t prevPenColor = _memory->drawState.color;
rectfill(x-1, y-1, x + charWidth*wFactor - 1, y + charHeight*hFactor - 1, bgColor);
_memory->drawState.color = prevPenColor;
}
- for (size_t i = 0; i < charHeight * hFactor; i++) {
- for(uint8_t bitn = 0; bitn < charWidth * wFactor; bitn++) {
- bool on = BITMASK(bitn / wFactor) & chBytes[i / hFactor];
- on &= wFactor == 1 || !evenPxOnly || (i % 2 == 0);
- on &= wFactor == 1 || !evenPxOnly || (bitn % 2 == 0);
- const int pixX = x + bitn;
- const int pixY = y + i;
- if (on && isWithinClip(pixX, pixY)) {
- setPixelNibble(pixX, pixY, fgColor, screenBuffer);
+ for (int relDestY = 0; relDestY < charHeight * hFactor; relDestY++) {
+ for(int relDestX = 0; relDestX < charWidth * wFactor; relDestX++) {
+
+ bool on = BITMASK(relDestX / wFactor) & chBytes[relDestY / hFactor];
+ on &= hFactor == 1 || !evenPxOnly || (relDestY % 2 == 0);
+ on &= wFactor == 1 || !evenPxOnly || (relDestX % 2 == 0);
+
+ int absDestX = x + relDestX;
+ int absDestY = y + relDestY;
+
+ if (on && isWithinClip(absDestX, absDestY)) {
+ setPixelNibble(absDestX, absDestY, fgColor, screenBuffer);
}
}
}
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 4d19b66..b147ab7 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -86,7 +86,7 @@ int print(std::string str, int x, int y) {
}
int print(std::string str, int x, int y, uint8_t c) {
- if (y == 83) {
+ if (y == 83) { //wat?
y +=0;
}
_ph_graphics->color(c);
@@ -273,6 +273,7 @@ int print(std::string str, int x, int y, uint8_t c) {
printMode |= PRINT_MODE_SOLID_BG;
}
else if (commandChar == ':' || commandChar == '.'){
+ charWidth = forceCharWidth > 0 ? forceCharWidth : 8;
charHeight = forceCharHeight > 0 ? forceCharHeight : 8;
if (commandChar == ':') {
std::string hexStr = str.substr(n+1, 16);
@@ -295,10 +296,10 @@ int print(std::string str, int x, int y, uint8_t c) {
prevDrawPal[fgColor & 0x0f],
bgColor,
printMode,
- 8,
+ charWidth,
charHeight);
- x += 8 + get<0>(values);
+ x += charWidth + get<0>(values);
charHeight = charHeight + get<1>(values);
lineHeight = charHeight > lineHeight ? charHeight : lineHeight;
}