commit e41fe699642c4901d50e54772a52d7b60d3fdf9b
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Sat Mar 20 06:47:05 2021 -0600
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Sat Mar 20 06:47:05 2021 -0600
Update cursor() to return previous
---
source/graphics.cpp | 14 +++++++++-----
source/graphics.h | 6 +++---
source/picoluaapi.cpp | 18 +++++++++++-------
test/graphicstests.cpp | 10 ++++++++++
4 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index d639d79..0aaae79 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -1216,18 +1216,22 @@ void Graphics::palt(uint8_t c, bool t){
}
-void Graphics::cursor() {
- this->cursor(0, 0);
+std::tuple<uint8_t, uint8_t> Graphics::cursor() {
+ return this->cursor(0, 0);
}
-void Graphics::cursor(int x, int y) {
+std::tuple<uint8_t, uint8_t> Graphics::cursor(int x, int y) {
+ std::tuple<uint8_t, uint8_t> prev (_memory->drawState.text_x, _memory->drawState.text_y);
+
_memory->drawState.text_x = x;
_memory->drawState.text_y = y;
+
+ return prev;
}
-void Graphics::cursor(int x, int y, uint8_t col) {
+std::tuple<uint8_t, uint8_t> Graphics::cursor(int x, int y, uint8_t col) {
color(col);
- this->cursor(x, y);
+ return this->cursor(x, y);
}
diff --git a/source/graphics.h b/source/graphics.h
index 152448e..fcb4d3f 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -195,9 +195,9 @@ class Graphics {
void palt();
void palt(uint8_t c0, bool t);
- void cursor();
- void cursor(int x, int y);
- void cursor(int x, int y, uint8_t col);
+ std::tuple<uint8_t, uint8_t> cursor();
+ std::tuple<uint8_t, uint8_t> cursor(int x, int y);
+ std::tuple<uint8_t, uint8_t> cursor(int x, int y, uint8_t col);
};
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 55d05bc..a6ec960 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -584,17 +584,21 @@ int cursor(lua_State *L) {
int x = lua_tonumber(L,1);
int y = lua_tonumber(L,2);
- if (lua_gettop(L) <= 2) {
- _graphicsForLuaApi->cursor(x, y);
- return 0;
- }
+ std::tuple<uint8_t, uint8_t> prev;
- uint8_t c = lua_tonumber(L,3);
+ if (lua_gettop(L) < 3) {
+ prev = _graphicsForLuaApi->cursor(x, y);
+ }
+ else{
+ uint8_t c = lua_tonumber(L,3);
- _graphicsForLuaApi->cursor(x, y, c);
+ prev =_graphicsForLuaApi->cursor(x, y, c);
+ }
- return 0;
+ lua_pushnumber(L, get<0>(prev));
+ lua_pushnumber(L, get<1>(prev));
+ return 2;
}
int fillp(lua_State *L) {
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index 0b019a7..c043c7e 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -1758,6 +1758,16 @@ TEST_CASE("graphics class behaves as expected") {
CHECK_EQ(picoRam.drawState.text_y, 0);
CHECK_EQ(picoRam.drawState.color, 3);
}
+ SUBCASE("cursor() returns previous values")
+ {
+ uint8_t x = 33;
+ uint8_t y = 120;
+ graphics->cursor(x, y);
+ auto prev = graphics->cursor(11, 31);
+
+ CHECK_EQ(std::get<0>(prev), x);
+ CHECK_EQ(std::get<1>(prev), y);
+ }
SUBCASE("tline draws sprites from map"){
for(int i = 0; i < 128; i++) {
for (int j = 0; j < 32; j++)