From 7c165e6c5ba2c92bab5359344f0755fd43d1bb9e Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Wed, 3 Oct 2018 17:49:26 -0400 Subject: Changed and added some methods for generic gui elements. Changed getabsrect() to now return getAbsolutePosition() Added getabsclippingrect() to return what getabsrect used to return Added getrelrect() to return getRelativePosition() --- src/client/lua_api/gui/iguielement.cpp | 41 ++++++++++++++++++++++++++++++++++ src/client/lua_api/gui/iguielement.hpp | 4 ++++ 2 files changed, 45 insertions(+) (limited to 'src') diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp index 3567d80..81d339f 100644 --- a/src/client/lua_api/gui/iguielement.cpp +++ b/src/client/lua_api/gui/iguielement.cpp @@ -46,6 +46,27 @@ Find the rectangle that an element occupies */ //getabsrect({element})-> {{sx,sy},{ex,ey}} int getiguiclippingrect(lua_State* L){ + lua_getfield(L,-1,"guielement"); + IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1);//{element},ud_element + lua_pop(L,2); + core::rect rect = el->getAbsolutePosition(); + pushrecti( + L, + rect.UpperLeftCorner.X, + rect.UpperLeftCorner.Y, + rect.LowerRightCorner.X, + rect.LowerRightCorner.Y + ); + return 1; +} + +/*** +Find the rectangle that an element occupies that is visible to the user +@function guielement:getabsclippingrect() +@treturn rect The rectangle that this element occupies that is visible to the user +*/ +//getabsclippingrect({element}) :: {{sx,sy},{ex,ey}} +int getiguiabsclippingrect(lua_State *L){ lua_getfield(L,-1,"guielement"); IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1);//{element},ud_element lua_pop(L,2); @@ -60,6 +81,26 @@ int getiguiclippingrect(lua_State* L){ return 1; } +/*** +Find the relative rectangle that this element occupies +@function guielement:getrelrect() +@treturn rect The rectangle that this element occupies relative to it's parent +*/ +int getiguirelrect(lua_State *L){ + lua_getfield(L,-1,"guielement"); + IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1);//{element},ud_element + lua_pop(L,2); + core::rect rect = el->getRelativePosition(); + pushrecti( + L, + rect.UpperLeftCorner.X, + rect.UpperLeftCorner.Y, + rect.LowerRightCorner.X, + rect.LowerRightCorner.Y + ); + return 1; +} + /*** Sets the text of the element This function may do different things to different gui elements. diff --git a/src/client/lua_api/gui/iguielement.hpp b/src/client/lua_api/gui/iguielement.hpp index 0e08644..7969c65 100644 --- a/src/client/lua_api/gui/iguielement.hpp +++ b/src/client/lua_api/gui/iguielement.hpp @@ -10,6 +10,8 @@ extern "C" { int moveiguielement(lua_State* L); int getiguiclippingrect(lua_State* L); +int getiguiabsclippingrect(lua_State *L); +int getiguirelrect(lua_State *L); int setiguitext(lua_State* L); int getiguitext(lua_State* L); int removeiguielement(lua_State* L); @@ -23,6 +25,8 @@ static const luaL_reg iguielement_m[] = { {"move", moveiguielement}, {"setrect", setrelrect}, {"getabsrect", getiguiclippingrect}, + {"getabsclippingrect", getiguiabsclippingrect}, + {"getrelrect", getiguirelrect}, {"settext", setiguitext}, {"gettext", getiguitext}, {"remove", removeiguielement}, -- cgit v1.2.3-70-g09d2