foxygit / fake-08-xbox360 Log in
commit 1c27a6ca86e3f02e9f75755f83ad927c7485897b
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Mon Jan 16 19:04:08 2023 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Mon Jan 16 19:04:08 2023 -0700

    add invert colors print mode support
---
 source/graphics.cpp       | 12 ++++++++++++
 source/printHelper.cpp    |  3 ---
 test/printHelperTests.cpp | 15 +++++++++++++++
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index 3dd26b9..b032c2b 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -1424,6 +1424,8 @@ std::tuple<int, int> Graphics::drawCharacterFromBytes(
 	int hFactor = 1;
 	//TODO: character modes
 	bool evenPxOnly = false;
+	bool invertColors = false;
+	//bool solidBg = false;

 	if ((printMode & PRINT_MODE_ON) == PRINT_MODE_ON){
 		if ((printMode & PRINT_MODE_WIDE) == PRINT_MODE_WIDE) {
@@ -1438,6 +1440,12 @@ std::tuple<int, int> Graphics::drawCharacterFromBytes(
 			//draw every other pixel-- also kinda broken on pico 8 0.2.4
 			evenPxOnly = true;
 		}
+		if((printMode & PRINT_MODE_INVERTED) == PRINT_MODE_INVERTED) {
+			invertColors = true;
+		}
+		//if((printMode & PRINT_MODE_SOLID_BG) == PRINT_MODE_SOLID_BG) {
+		//	solidBg = true;
+		//}
 		//TODO: other print modes
 	}

@@ -1457,6 +1465,10 @@ std::tuple<int, int> Graphics::drawCharacterFromBytes(

 			int absDestX = x + relDestX;
 			int absDestY = y + relDestY;
+
+			if (invertColors) {
+				on = !on;
+			}

 			if (on && isWithinClip(absDestX, absDestY)) {
 				setPixelNibble(absDestX, absDestY, fgColor, screenBuffer);
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 2ea38b8..7d6ffe4 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -86,9 +86,6 @@ int print(std::string str, int x, int y) {
 }

 int print(std::string str, int x, int y, uint8_t c) {
-    if (y == 83) { //wat?
-        y +=0;
-    }
 	_ph_graphics->color(c);

 	_ph_mem->drawState.text_x = x;
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index f2e20a8..e9d8944 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -803,6 +803,21 @@ TEST_CASE("Print helper functions") {

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


     delete stubHost;