diff --git a/Packaging/resources/assets/ui_art/button.png b/Packaging/resources/assets/ui_art/button.png index adf57168d..0aa4441fb 100644 Binary files a/Packaging/resources/assets/ui_art/button.png and b/Packaging/resources/assets/ui_art/button.png differ diff --git a/Source/controls/touch/renderers.cpp b/Source/controls/touch/renderers.cpp index 4e7294bdc..9842ee8e9 100644 --- a/Source/controls/touch/renderers.cpp +++ b/Source/controls/touch/renderers.cpp @@ -90,11 +90,13 @@ VirtualGamepadButtonType GetStandButtonType(bool isPressed) void LoadButtonArt(ButtonTexture *buttonArt, SDL_Renderer *renderer) { - constexpr unsigned Frames = 26; + constexpr unsigned Sprites = 13; + constexpr unsigned Frames = 2; buttonArt->surface.reset(LoadPNG("ui_art\\button.png")); if (buttonArt->surface == nullptr) return; + buttonArt->numSprites = Sprites; buttonArt->numFrames = Frames; if (renderer != nullptr) { @@ -181,6 +183,7 @@ Size ButtonTexture::size() const } else { SDL_QueryTexture(texture.get(), /*format=*/nullptr, /*access=*/nullptr, &w, &h); } + w /= numSprites; h /= numFrames; return Size { w, h }; } @@ -324,8 +327,9 @@ void VirtualPadButtonRenderer::Render(RenderFunction renderFunction, const Butto VirtualGamepadButtonType buttonType = GetButtonType(); Size size = buttonArt.size(); - int frame = buttonType; - int offset = size.height * frame; + const auto index = static_cast(buttonType); + const int xOffset = size.width * (index / buttonArt.numFrames); + const int yOffset = size.height * (index % buttonArt.numFrames); auto center = virtualPadButton->area.position; auto radius = virtualPadButton->area.radius; @@ -336,7 +340,7 @@ void VirtualPadButtonRenderer::Render(RenderFunction renderFunction, const Butto int width = diameter; int height = diameter; - SDL_Rect src = MakeSdlRect(0, offset, size.width, size.height); + SDL_Rect src = MakeSdlRect(xOffset, yOffset, size.width, size.height); SDL_Rect dst = MakeSdlRect(x, y, width, height); renderFunction(buttonArt, &src, &dst); } diff --git a/Source/controls/touch/renderers.h b/Source/controls/touch/renderers.h index 68e664cbf..fe8e1c6c9 100644 --- a/Source/controls/touch/renderers.h +++ b/Source/controls/touch/renderers.h @@ -53,6 +53,7 @@ enum VirtualGamepadPotionType : uint8_t { struct ButtonTexture { SDLSurfaceUniquePtr surface; SDLTextureUniquePtr texture; + unsigned numSprites = 1; unsigned numFrames = 1; Size size() const;