foxygit / fake-08-xbox360 Log in
commit 1f2c3b5c6614f05dc2fd2c06380b441c1a9662bf
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Thu Apr 23 12:04:21 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Thu Apr 23 12:04:21 2020 -0600

    Add print overloads
---
 source/graphics.cpp   | 12 ++++++++++++
 source/graphics.h     |  3 +++
 source/picoluaapi.cpp | 24 ++++++++++++++++++++----
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index 1b5ed2e..83683a8 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -389,8 +389,18 @@ void Graphics::rectfill(short x1, short y1, short x2, short y2, uint8_t col) {
 	}
 }

+short Graphics::print(std::string str) {
+	return this->print(str, _gfxState_text_x, _gfxState_text_y);
+}
+
+short Graphics::print(std::string str, short x, short y) {
+	return this->print(str, x, y, _gfxState_color);
+}
+
 //based on tac08 impl
 short Graphics::print(std::string str, short x, short y, uint16_t c) {
+	color(c);
+
 	_gfxState_text_x = x;

 	for (size_t n = 0; n < str.length(); n++) {
@@ -412,6 +422,8 @@ short Graphics::print(std::string str, short x, short y, uint16_t c) {
 	_gfxState_text_x = 0;
 	_gfxState_text_y = y + 6;

+	//todo: auto scrolling
+
 	return x;
 }

diff --git a/source/graphics.h b/source/graphics.h
index b1cf92d..e9fb2e4 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -117,7 +117,10 @@ class Graphics {
 	void rectfill(short x1, short y1, short x2, short y2);
 	void rectfill(short x1, short y1, short x2, short y2, uint8_t col);

+	short print(std::string str);
+	short print(std::string str, short x, short y);
 	short print(std::string str, short x, short y, uint16_t c);
+
 	void spr(short n, short x, short y, short w, short h, bool flip_x, bool flip_y);

 	void sspr(
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index e6cde83..9761087 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -196,6 +196,10 @@ int rectfill(lua_State *L){
     return 0;
 }
 int print(lua_State *L){
+    if (lua_gettop(L) == 0){
+        return 0;
+    }
+
     const char * str = "";

     //todo: handle other cases, maybe move this somewhere else
@@ -213,11 +217,23 @@ int print(lua_State *L){
         str = lua_toboolean(L, 1) ? "true" : "false";
     }

-    double x = lua_tonumber(L,2);
-    double y = lua_tonumber(L,3);
-    double c = lua_tonumber(L,3);
+    if (lua_gettop(L) < 3) {
+        _graphicsForLuaApi->print(str);
+    }
+    else if (lua_gettop(L) == 3) {
+        short x = lua_tonumber(L,2);
+        short y = lua_tonumber(L,3);

-    _graphicsForLuaApi->print(str, x, y, c);
+        _graphicsForLuaApi->print(str, x, y);
+    }
+    else {
+        short x = lua_tonumber(L,2);
+        short y = lua_tonumber(L,3);
+
+        uint8_t c = lua_tonumber(L,4);
+
+        _graphicsForLuaApi->print(str, x, y, c);
+    }

     return 0;
 }