mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-04-13 20:36:12 -05:00
92 lines
2.2 KiB
C++
92 lines
2.2 KiB
C++
#include "ui/SlideOutPanel.hpp"
|
|
#include "colors.hpp"
|
|
#include "config.hpp"
|
|
#include <cmath>
|
|
|
|
ui::SlideOutPanel::SlideOutPanel(int width, Side side) : m_x(side == Side::Left ? -width : 1280), m_width(width), m_side(side)
|
|
{
|
|
static int slidePanelTargetID = 0;
|
|
std::string panelTargetName = "PanelTarget_" + std::to_string(slidePanelTargetID++);
|
|
m_renderTarget = sdl::TextureManager::createLoadTexture(panelTargetName, width, 720, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET);
|
|
}
|
|
|
|
void ui::SlideOutPanel::update(bool hasFocus)
|
|
{
|
|
double scaling = config::getAnimationScaling();
|
|
|
|
if (!m_isOpen && m_side == Side::Left && m_x < 0)
|
|
{
|
|
m_x -= std::ceil(m_x / scaling);
|
|
}
|
|
else if (!m_isOpen && m_side == Side::Right && m_x > 1280 - m_width)
|
|
{
|
|
m_x += std::ceil((1280.0f - (static_cast<double>(m_width)) - m_x) / scaling);
|
|
}
|
|
else if (m_closePanel && m_side == Side::Left && m_x > -(m_width))
|
|
{
|
|
m_x -= std::ceil((m_width - m_x) / scaling);
|
|
}
|
|
else if (m_closePanel && m_side == Side::Right && m_x < 1280)
|
|
{
|
|
m_x += std::ceil((1280.0f - m_x) / scaling);
|
|
}
|
|
else
|
|
{
|
|
m_isOpen = true;
|
|
}
|
|
|
|
if (hasFocus && m_isOpen)
|
|
{
|
|
for (auto ¤tElement : m_elements)
|
|
{
|
|
currentElement->update(hasFocus);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ui::SlideOutPanel::render(SDL_Texture *Target, bool hasFocus)
|
|
{
|
|
for (auto ¤tElement : m_elements)
|
|
{
|
|
currentElement->render(m_renderTarget->get(), hasFocus);
|
|
}
|
|
m_renderTarget->render(NULL, m_x, 0);
|
|
}
|
|
|
|
void ui::SlideOutPanel::clearTarget(void)
|
|
{
|
|
m_renderTarget->clear(colors::SLIDE_PANEL_CLEAR);
|
|
}
|
|
|
|
void ui::SlideOutPanel::reset(void)
|
|
{
|
|
m_x = m_side == Side::Left ? -(m_width) : 1280.0f;
|
|
m_isOpen = false;
|
|
m_closePanel = false;
|
|
}
|
|
|
|
void ui::SlideOutPanel::close(void)
|
|
{
|
|
m_closePanel = true;
|
|
}
|
|
|
|
bool ui::SlideOutPanel::isOpen(void) const
|
|
{
|
|
return m_isOpen;
|
|
}
|
|
|
|
bool ui::SlideOutPanel::isClosed(void) const
|
|
{
|
|
return m_closePanel && (m_side == Side::Left ? m_x > -(m_width) : m_x < 1280);
|
|
}
|
|
|
|
void ui::SlideOutPanel::pushNewElement(std::shared_ptr<ui::Element> newElement)
|
|
{
|
|
m_elements.push_back(newElement);
|
|
}
|
|
|
|
SDL_Texture *ui::SlideOutPanel::get(void)
|
|
{
|
|
return m_renderTarget->get();
|
|
}
|