diff --git a/src/Screens/MusicSelect/ButtonHighlight.cpp b/src/Screens/MusicSelect/ButtonHighlight.cpp index 62a159a..0a177b7 100644 --- a/src/Screens/MusicSelect/ButtonHighlight.cpp +++ b/src/Screens/MusicSelect/ButtonHighlight.cpp @@ -1,35 +1,39 @@ #include "ButtonHighlight.hpp" -MusicSelect::ButtonHighlight::ButtonHighlight(std::size_t t_panel_size) : - panel_size(t_panel_size), - highlight({static_cast(t_panel_size-3), static_cast(t_panel_size-3)}), - time_to_alpha(0.f, 0.25f, 255.f, 0.f) -{ - highlight.setFillColor(sf::Color::Transparent); - highlight.setOutlineThickness(1.f); - highlight.setOrigin(highlight.getSize().x / 2.f, highlight.getSize().y / 2.f); -} +namespace MusicSelect { + ButtonHighlight::ButtonHighlight(const float& panel_size, const float& panel_spacing) : + m_panel_size(panel_size), + m_panel_spacing(panel_spacing), + m_highlight({static_cast(panel_size-3), static_cast(panel_size-3)}), + m_time_to_alpha(0.f, 0.25f, 255.f, 0.f) + { + m_highlight.setFillColor(sf::Color::Transparent); + m_highlight.setOutlineThickness(1.f); + m_highlight.setOrigin(m_highlight.getSize().x / 2.f, m_highlight.getSize().y / 2.f); + } -void MusicSelect::ButtonHighlight::button_pressed(Button button) { - button_presses_history[button].restart(); -} + void ButtonHighlight::button_pressed(Button button) { + m_button_presses_history[button].restart(); + } -void MusicSelect::ButtonHighlight::draw(sf::RenderTarget& target, sf::RenderStates states) const { - auto it = button_presses_history.begin(); - while (it != button_presses_history.end()) { - auto elapsed = it->second.getElapsedTime(); - auto coords = toCoords(it->first); - if (elapsed > sf::milliseconds(250)) { - it = button_presses_history.erase(it); - } else { - auto alpha = time_to_alpha.transform(elapsed.asSeconds()); - highlight.setOutlineColor(sf::Color(255,255,0,static_cast(alpha))); - highlight.setPosition({ - static_cast(coords.x * panel_size) + panel_size/2.f, - static_cast(coords.y * panel_size) + panel_size/2.f - }); - target.draw(highlight, states); - ++it; - } - } + void ButtonHighlight::draw(sf::RenderTarget& target, sf::RenderStates states) const { + states.transform *= getTransform(); + auto it = m_button_presses_history.begin(); + while (it != m_button_presses_history.end()) { + auto elapsed = it->second.getElapsedTime(); + auto coords = toCoords(it->first); + if (elapsed > sf::milliseconds(250)) { + it = m_button_presses_history.erase(it); + } else { + auto alpha = m_time_to_alpha.transform(elapsed.asSeconds()); + m_highlight.setOutlineColor(sf::Color(255,255,0,static_cast(alpha))); + m_highlight.setPosition({ + static_cast(coords.x * (m_panel_size+m_panel_spacing)) + m_panel_size/2.f, + static_cast(coords.y * (m_panel_size+m_panel_spacing)) + m_panel_size/2.f + }); + target.draw(m_highlight, states); + ++it; + } + } + } } diff --git a/src/Screens/MusicSelect/ButtonHighlight.hpp b/src/Screens/MusicSelect/ButtonHighlight.hpp index 7c51427..8d06785 100644 --- a/src/Screens/MusicSelect/ButtonHighlight.hpp +++ b/src/Screens/MusicSelect/ButtonHighlight.hpp @@ -9,15 +9,16 @@ #include "../../Toolkit/AffineTransform.hpp" namespace MusicSelect { - class ButtonHighlight : public sf::Drawable { + class ButtonHighlight : public sf::Drawable, public sf::Transformable { public: - explicit ButtonHighlight(std::size_t t_panel_size); + ButtonHighlight(const float& panel_size, const float& panel_spacing); void button_pressed(Button button); private: virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; - std::size_t panel_size; - mutable sf::RectangleShape highlight; - mutable std::map button_presses_history; - Toolkit::AffineTransform time_to_alpha; + const float& m_panel_size; + const float& m_panel_spacing; + mutable sf::RectangleShape m_highlight; + mutable std::map m_button_presses_history; + Toolkit::AffineTransform m_time_to_alpha; }; }