foxygit / fake-08-xbox360 Log in
commit 0eabc19df0701928ea2889b24b6d0894b75f6cbf
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Mar 12 09:31:48 2022 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Mar 12 09:31:48 2022 -0700

    add rhs text wrap control code
---
 source/printHelper.cpp    | 11 +++++++++++
 test/printHelperTests.cpp | 17 +++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 04da465..475001d 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -98,6 +98,7 @@ int print(std::string str, int x, int y, uint8_t c) {

     int framesBetweenChars = 0;
     int framesToPause = 0;
+    int rhsWrap = -1;


 	for (size_t n = 0; n < str.length(); n++) {
@@ -179,6 +180,10 @@ int print(std::string str, int x, int y, uint8_t c) {
                 x = p0CharToNum(xChar) * 4;
                 y = p0CharToNum(yChar) * 4;
             }
+            else if (commandChar == 'r'){
+                uint8_t rhsWrapChar = str[++n];
+                rhsWrap = p0CharToNum(rhsWrapChar) * 4;
+            }
             else if (commandChar == 's'){
                 uint8_t tswChar = str[++n];
                 tabStopWidth = p0CharToNum(tswChar);
@@ -214,6 +219,12 @@ int print(std::string str, int x, int y, uint8_t c) {
                 framesToPause--;
             }
 		}
+
+        //soft wrap if enabled
+        if (rhsWrap > 0 && x >= rhsWrap) {
+            x = _ph_mem->drawState.text_x;
+			y += 6;
+        }
 	}

 	for(int i = 0; i < 16; i++) {
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index dfb4722..aa521af 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -369,6 +369,23 @@ TEST_CASE("Print helper functions") {

         checkPoints(graphics, expectedPoints);
     }
+    SUBCASE("p8scii special control code for rhs wrap(\\^r) ") {
+        graphics->cls();
+
+        print("\x06""rsthis is a long string that should wrap somewhere", 0, 0);
+
+        //the "h" in "should" is the first character to wrap
+        std::vector<coloredPoint> expectedPoints = {
+            {0, 6, 6},
+            {0, 7, 6},
+            {0, 8, 6},
+            {0, 9, 6},
+            {0, 10, 6},
+            {0, 11, 0}
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }


     delete stubHost;