From aa2fa9ed8c78b66e8dbe3611499ec283122f3584 Mon Sep 17 00:00:00 2001 From: mniip Date: Wed, 12 Apr 2023 19:24:25 +0200 Subject: [PATCH] Remove Graphics::SetClipRect --- src/graphics/Graphics.cpp | 10 ---------- src/graphics/Graphics.h | 2 -- src/graphics/Pixel.h | 2 -- src/gui/game/GameView.cpp | 12 +++--------- src/gui/game/ToolButton.cpp | 19 +++++++------------ src/gui/game/ToolButton.h | 5 +---- src/lua/LuaScriptInterface.cpp | 11 ++++++----- 7 files changed, 17 insertions(+), 44 deletions(-) diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index c4313dad3..d4edf61e1 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -459,16 +459,6 @@ void Graphics::SwapClipRect(Rect &rect) clipRect &= video.Size().OriginRect(); } -void Graphics::SetClipRect(int &x, int &y, int &w, int &h) -{ - Rect rect = RectSized(Vec2(x, y), Vec2(w, h)); - SwapClipRect(rect); - x = rect.TopLeft.X; - y = rect.TopLeft.Y; - w = rect.Size().X; - h = rect.Size().Y; -} - bool Graphics::GradientStop::operator <(const GradientStop &other) const { return point < other.point; diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h index 257097bc7..726b0b6fd 100644 --- a/src/graphics/Graphics.h +++ b/src/graphics/Graphics.h @@ -104,6 +104,4 @@ public: Graphics(); void SwapClipRect(Rect &); - [[deprecated("Use SwapClipRect")]] - void SetClipRect(int &x, int &y, int &w, int &h); }; diff --git a/src/graphics/Pixel.h b/src/graphics/Pixel.h index 35282d7ba..8ce888141 100644 --- a/src/graphics/Pixel.h +++ b/src/graphics/Pixel.h @@ -11,8 +11,6 @@ typedef uint32_t pixel; constexpr int PIXELCHANNELS = 3; -[[deprecated("Avoid manipulating pixel* as char*")]] -constexpr int PIXELSIZE = 4; // Least significant byte is blue, then green, then red, then alpha. // Use sparingly, e.g. when passing packed data to a third party library. diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 845e9de86..bc1977620 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -573,10 +573,7 @@ void GameView::NotifyToolListChanged(GameModel * sender) else tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), tool->Name, tool->Identifier, tool->Description); - tempButton->clipRectX = 1; - tempButton->clipRectY = YRES + 1; - tempButton->clipRectW = XRES - 1; - tempButton->clipRectH = 18; + tempButton->ClipRect = RectSized(Vec2(1, RES.Y + 1), Vec2(RES.X - 1, 18)); //currentY -= 17; currentX -= 31; @@ -1848,11 +1845,8 @@ void GameView::DoDraw() c->Tick(); { - int x = 0; - int y = 0; - int w = WINDOWW; - int h = WINDOWH; - g->SetClipRect(x, y, w, h); // reset any nonsense cliprect Lua left configured + auto rect = g->Size().OriginRect(); + g->SwapClipRect(rect); // reset any nonsense cliprect Lua left configured } } diff --git a/src/gui/game/ToolButton.cpp b/src/gui/game/ToolButton.cpp index f7d12ea9c..3354e0011 100644 --- a/src/gui/game/ToolButton.cpp +++ b/src/gui/game/ToolButton.cpp @@ -45,14 +45,10 @@ void ToolButton::OnMouseUp(int x, int y, unsigned int button) void ToolButton::Draw(const ui::Point& screenPos) { Graphics * g = GetGraphics(); - int x = clipRectX; - int y = clipRectY; - int w = clipRectW; - int h = clipRectH; - if (clipRectW && clipRectH) - { - g->SetClipRect(x, y, w, h); // old cliprect is now in x, y, w, h - } + auto rect = ClipRect; + if (ClipRect.Size().X && ClipRect.Size().Y) + g->SwapClipRect(rect); // old cliprect is now in rect + int totalColour = Appearance.BackgroundInactive.Blue + (3*Appearance.BackgroundInactive.Green) + (2*Appearance.BackgroundInactive.Red); if (Appearance.GetTexture()) @@ -85,10 +81,9 @@ void ToolButton::Draw(const ui::Point& screenPos) { g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, buttonDisplayText, 0, 0, 0, 255); } - if (clipRectW && clipRectH) - { - g->SetClipRect(x, y, w, h); // apply old clip rect - } + + if (ClipRect.Size().X && ClipRect.Size().Y) + g->SwapClipRect(rect); // apply old clip rect } void ToolButton::SetSelectionState(int state) diff --git a/src/gui/game/ToolButton.h b/src/gui/game/ToolButton.h index 84e1fa277..18687a93e 100644 --- a/src/gui/game/ToolButton.h +++ b/src/gui/game/ToolButton.h @@ -16,8 +16,5 @@ public: void SetSelectionState(int state); int GetSelectionState(); Tool *tool; - int clipRectX = 0; - int clipRectY = 0; - int clipRectW = 0; - int clipRectH = 0; + Rect ClipRect = RectSized(Vec2::Zero, Vec2::Zero); }; diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 3d2814699..8d0b365c5 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -3901,11 +3901,12 @@ int LuaScriptInterface::graphics_setClipRect(lua_State * l) int y = luaL_optinteger(l, 2, 0); int w = luaL_optinteger(l, 3, WINDOWW); int h = luaL_optinteger(l, 4, WINDOWH); - luacon_g->SetClipRect(x, y, w, h); - lua_pushinteger(l, x); - lua_pushinteger(l, y); - lua_pushinteger(l, w); - lua_pushinteger(l, h); + auto rect = RectSized(Vec2(x, y), Vec2(w, h)); + luacon_g->SwapClipRect(rect); + lua_pushinteger(l, rect.TopLeft.X); + lua_pushinteger(l, rect.TopLeft.Y); + lua_pushinteger(l, rect.Size().X); + lua_pushinteger(l, rect.Size().Y); return 4; }