Skip to content

Commit

Permalink
Implemented GuiImage mirroring
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelio92 committed May 31, 2024
1 parent ed2bcc5 commit ada718b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions libGUI/include/guiimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class GuiImage : public GuiElement {
void setSize(int _width, int _height);
void draw();
void draw(bool onFocus);
void draw(bool onFocus, bool xMirror, bool yMirror);
void drawAlpha(int alpha);
void drawTextureAlphaTexCoords(int alpha, f32 textCoords[]);
Vector2 getDimensions() {return Vector2(width, height);};
Expand Down
Binary file modified libGUI/lib/libGUI.a
Binary file not shown.
17 changes: 12 additions & 5 deletions libGUI/source/guiimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,21 @@ void GuiImage::setSize(int _width, int _height) {
height = _height;
}

void GuiImage::draw() {
draw(false, false, false);
}

void GuiImage::draw(bool onFocus) {
if (tex.data != NULL) {
drawTextureResized(0, 0, width, height, tex);
}
draw(onFocus, false, false);
}

void GuiImage::draw() {
draw(false);
void GuiImage::draw(bool onFocus, bool xMirror, bool yMirror) {
int tempWidth = xMirror ? -width : width;
int tempHeight = yMirror ? -height : height;

if (tex.data != NULL) {
drawTextureResized(0, 0, tempWidth, tempHeight, tex);
}
}

void GuiImage::drawAlpha(int alpha) {
Expand Down
1 change: 1 addition & 0 deletions libs/libGUI/include/guiimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class GuiImage : public GuiElement {
void setSize(int _width, int _height);
void draw();
void draw(bool onFocus);
void draw(bool onFocus, bool xMirror, bool yMirror);
void drawAlpha(int alpha);
void drawTextureAlphaTexCoords(int alpha, f32 textCoords[]);
Vector2 getDimensions() {return Vector2(width, height);};
Expand Down
Binary file modified libs/libGUI/lib/libGUI.a
Binary file not shown.
11 changes: 9 additions & 2 deletions main/source/luasupport/luagfxlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ static int lua_Gfx_loadImage(lua_State* L) {
}

static int lua_Gfx_drawImage(lua_State* L) {
bool xMirror = false;
bool yMirror = false;
int argc = lua_gettop(L);
if (argc < 1) {
return luaL_error(L, "wrong number of arguments");
Expand All @@ -358,9 +360,14 @@ static int lua_Gfx_drawImage(lua_State* L) {
GuiImage* img = (GuiImage*)luaL_checkinteger(L, 1);
if (img) {
Gfx::pushMatrix();
if (argc == 3)
if (argc == 3 || argc == 5) {
Gfx::translate(luaL_checknumber(L, 2), luaL_checknumber(L, 3));
img->draw();
}
if (argc == 5) {
xMirror = lua_toboolean(L, 4);
yMirror = lua_toboolean(L, 5);
}
img->draw(false, xMirror, yMirror);
Gfx::popMatrix();
}

Expand Down

0 comments on commit ada718b

Please sign in to comment.