foxygit / fake-08-xbox360 Log in
commit 4cbb98bb9a4804f40fb66752180b7fe5f5cbc035
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Mar 12 10:01:25 2022 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Mar 12 10:01:25 2022 -0700

    Add char widtch control character
---
 source/graphics.cpp       |  6 +++---
 source/printHelper.cpp    | 22 ++++++++++++++++------
 test/printHelperTests.cpp | 15 +++++++++++++++
 3 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index e4cc78d..4effd17 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -1249,17 +1249,17 @@ fix32 Graphics::fillp(fix32 pat) {


 int Graphics::drawCharacter(uint8_t ch, int x, int y) {
+	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);
-		x += 4;
 	} else if (ch >= 0x80) {
 		int index = ch - 0x80;
 		copySpriteToScreen(fontSpriteData, x, y, (index % 16) * 8, (index / 16) * 8 + 56, 8, 5, false, false);
-		x += 8;
+		extraCharWidth = 4;
 	}

-	return x;
+	return extraCharWidth;
 }

 void Graphics::spr(
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 475001d..26269c9 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -82,6 +82,8 @@ int print(std::string str, int x, int y, uint8_t c) {
     int homeX = x;
     int homeY = y;
     int tabStopWidth = 4;
+    int charWidth = 4;
+    int charHeight = 6;

 	uint8_t effectiveC = _ph_graphics->getDrawPalMappedColor(c);

@@ -110,7 +112,7 @@ int print(std::string str, int x, int y, uint8_t c) {

 			ch = str[++n];
 			for(int i = 0; i < times; i++) {
-				x = _ph_graphics->drawCharacter(ch, x, y);
+				x += charWidth +  _ph_graphics->drawCharacter(ch, x, y);
 			}
 		}
 		else if (ch == 2) { // "\#{p0}" draw text on a solid background color
@@ -188,6 +190,14 @@ int print(std::string str, int x, int y, uint8_t c) {
                 uint8_t tswChar = str[++n];
                 tabStopWidth = p0CharToNum(tswChar);
             }
+            else if (commandChar == 'x'){
+                uint8_t charWidthChar = str[++n];
+                charWidth = p0CharToNum(charWidthChar);
+            }
+            else if (commandChar == 'y'){
+                uint8_t charHeightChar = str[++n];
+                charHeight = p0CharToNum(charHeightChar);
+            }

 		}
 		else if (ch == 12) { //"\f{p0}" draw text with this foreground color
@@ -198,7 +208,7 @@ int print(std::string str, int x, int y, uint8_t c) {
 		}
 		else if (ch == '\n') {
 			x = _ph_mem->drawState.text_x;
-			y += 6;
+			y += charHeight;
 		}
 		else if (ch == '\t') {
 			while (x % (tabStopWidth*4) > 0) {
@@ -206,13 +216,13 @@ int print(std::string str, int x, int y, uint8_t c) {
 			}
 		}
 		else if (ch == '\b') {
-			x -= 4;
+			x -= charWidth;
 		}
 		else if (ch == '\r') {
 			x = _ph_mem->drawState.text_x;
 		}
 		else if (ch >= 0x10) {
-			x = _ph_graphics->drawCharacter(ch, x, y);
+			x += charWidth + _ph_graphics->drawCharacter(ch, x, y);
             while (framesToPause > 0){
                 _ph_vm->vm_flip();

@@ -223,7 +233,7 @@ int print(std::string str, int x, int y, uint8_t c) {
         //soft wrap if enabled
         if (rhsWrap > 0 && x >= rhsWrap) {
             x = _ph_mem->drawState.text_x;
-			y += 6;
+			y += charHeight;
         }
 	}

@@ -232,7 +242,7 @@ int print(std::string str, int x, int y, uint8_t c) {
 	}

 	//todo: auto scrolling
-	_ph_mem->drawState.text_y += 6;
+	_ph_mem->drawState.text_y += charHeight;

 	return x;
 }
\ No newline at end of file
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index aa521af..3080192 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -386,6 +386,21 @@ TEST_CASE("Print helper functions") {

         checkPoints(graphics, expectedPoints);
     }
+    SUBCASE("p8scii special control code for char width(\\^x) ") {
+        graphics->cls();
+
+        print("\x06""x7 :", 0, 0);
+
+        std::vector<coloredPoint> expectedPoints = {
+            {8, 0, 0},
+            {8, 1, 6},
+            {8, 2, 0},
+            {8, 3, 6},
+            {8, 4, 0}
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }ß


     delete stubHost;