#include "ui/Frame.hpp" #include "graphics/colors.hpp" ui::Frame::Frame(int x, int y, int width, int height) : m_x(x) , m_y(y) , m_width(width) , m_height(height) { Frame::initialize_static_members(); } void ui::Frame::render(sdl::SharedTexture &target, bool hasFocus) { // This is the size of one of the "tiles" of the frame. static constexpr int TILE = 16; const int midWidth = m_width - (TILE * 2); const int midHeight = m_height - (TILE * 2); const int rightEdge = (m_x + m_width) - TILE; const int bottomEdge = (m_y + m_height) - TILE; const int textureCorner = TILE * 2; // Top. sm_frameCorners->render_part(target, m_x, m_y, 0, 0, TILE, TILE); sm_frameCorners->render_part_stretched(target, TILE, 0, TILE, TILE, m_x + TILE, m_y, midWidth, TILE); sm_frameCorners->render_part(target, rightEdge, m_y, 32, 0, TILE, TILE); // Middle sm_frameCorners->render_part_stretched(target, 0, TILE, TILE, TILE, m_x, m_y + TILE, TILE, midHeight); sdl::render_rect_fill(target, m_x + TILE, m_y + TILE, midWidth, midHeight, colors::SLIDE_PANEL_CLEAR); sm_frameCorners->render_part_stretched(target, textureCorner, TILE, TILE, TILE, rightEdge, m_y + TILE, TILE, midHeight); // Bottom sm_frameCorners->render_part(target, m_x, bottomEdge, 0, textureCorner, TILE, TILE); sm_frameCorners->render_part_stretched(target, TILE, textureCorner, TILE, TILE, m_x + TILE, bottomEdge, midWidth, TILE); sm_frameCorners->render_part(target, rightEdge, bottomEdge, textureCorner, textureCorner, TILE, TILE); } void ui::Frame::set_x(int x) { m_x = x; } void ui::Frame::set_y(int y) { m_y = y; } void ui::Frame::set_width(int width) { m_width = width; } void ui::Frame::set_height(int height) { m_height = height; } void ui::Frame::initialize_static_members() { static constexpr std::string_view FRAME_NAME = "FrameCorners"; static constexpr const char *FRAME_PATH = "romfs:/Textures/Frame.png"; if (sm_frameCorners) { return; } sm_frameCorners = sdl::TextureManager::load(FRAME_NAME, FRAME_PATH); }