Make more stuff react to screen resize
This commit is contained in:
parent
b994459f74
commit
3317b5bf71
@ -2,17 +2,12 @@
|
||||
|
||||
namespace MusicSelect {
|
||||
ButtonHighlight::ButtonHighlight(SharedResources& resources) :
|
||||
m_resources(resources),
|
||||
HoldsSharedResources(resources),
|
||||
m_highlight(),
|
||||
m_time_to_alpha(0.f, 0.25f, 255.f, 0.f)
|
||||
{
|
||||
m_highlight.setSize({
|
||||
(m_resources.preferences.layout.panel_size-3.f/768.f)*m_resources.preferences.screen.width,
|
||||
(m_resources.preferences.layout.panel_size-3.f/768.f)*m_resources.preferences.screen.width,
|
||||
});
|
||||
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 ButtonHighlight::button_pressed(Button button) {
|
||||
@ -21,8 +16,11 @@ namespace MusicSelect {
|
||||
|
||||
void ButtonHighlight::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
states.transform *= getTransform();
|
||||
auto panel_step = m_resources.preferences.layout.panel_step()*m_resources.preferences.screen.width;
|
||||
auto panel_size = m_resources.preferences.layout.panel_size*m_resources.preferences.screen.width;
|
||||
m_highlight.setSize({
|
||||
get_panel_size()-(3.f/768.f)*get_screen_width(),
|
||||
get_panel_size()-(3.f/768.f)*get_screen_width(),
|
||||
});
|
||||
m_highlight.setOrigin(m_highlight.getSize().x / 2.f, m_highlight.getSize().y / 2.f);
|
||||
auto it = m_button_presses_history.begin();
|
||||
while (it != m_button_presses_history.end()) {
|
||||
auto elapsed = it->second.getElapsedTime();
|
||||
@ -33,8 +31,8 @@ namespace MusicSelect {
|
||||
auto alpha = m_time_to_alpha.transform(elapsed.asSeconds());
|
||||
m_highlight.setOutlineColor(sf::Color(255,255,0,static_cast<std::size_t>(alpha)));
|
||||
m_highlight.setPosition({
|
||||
static_cast<float>(coords.x * panel_step) + panel_size/2.f,
|
||||
static_cast<float>(coords.y * panel_step) + panel_size/2.f
|
||||
static_cast<float>(coords.x * get_panel_step()) + get_panel_size()/2.f,
|
||||
static_cast<float>(coords.y * get_panel_step()) + get_panel_size()/2.f
|
||||
});
|
||||
target.draw(m_highlight, states);
|
||||
++it;
|
||||
|
@ -11,13 +11,12 @@
|
||||
#include "SharedResources.hpp"
|
||||
|
||||
namespace MusicSelect {
|
||||
class ButtonHighlight : public sf::Drawable, public sf::Transformable {
|
||||
class ButtonHighlight : public sf::Drawable, public sf::Transformable, public HoldsSharedResources {
|
||||
public:
|
||||
ButtonHighlight(SharedResources& resources);
|
||||
void button_pressed(Button button);
|
||||
private:
|
||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
||||
SharedResources& m_resources;
|
||||
mutable sf::RectangleShape m_highlight;
|
||||
mutable std::map<Button, sf::Clock> m_button_presses_history;
|
||||
Toolkit::AffineTransform<float> m_time_to_alpha;
|
||||
|
@ -47,6 +47,12 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
|
||||
case sf::Event::Closed:
|
||||
window.close();
|
||||
break;
|
||||
case sf::Event::Resized:
|
||||
// update the view to the new size of the window
|
||||
window.setView(sf::View({0, 0, event.size.width, event.size.height}));
|
||||
resources.preferences.screen.height = event.size.height;
|
||||
resources.preferences.screen.width = event.size.width;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ namespace MusicSelect {
|
||||
BigCover::BigCover(SharedResources& resources) :
|
||||
HoldsSharedResources(resources)
|
||||
{
|
||||
m_cover_fallback.setSize({get_size(), get_size()});
|
||||
m_cover_fallback.setFillColor(sf::Color::Transparent);
|
||||
m_cover_fallback.setOutlineThickness(1.f);
|
||||
m_cover_fallback.setOutlineColor(sf::Color::White);
|
||||
@ -18,6 +17,7 @@ namespace MusicSelect {
|
||||
|
||||
void BigCover::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
states.transform *= getTransform();
|
||||
m_cover_fallback.setSize({get_size(), get_size()});
|
||||
target.draw(m_cover_fallback, states);
|
||||
auto selected_panel = m_resources.selected_panel;
|
||||
if (not selected_panel.has_value()) {
|
||||
@ -47,22 +47,14 @@ namespace MusicSelect {
|
||||
target.draw(cover, states);
|
||||
}
|
||||
|
||||
SongInfo::SongInfo(SharedResources& resources) :
|
||||
HoldsSharedResources(resources),
|
||||
m_big_cover(resources)
|
||||
{
|
||||
m_big_cover.setOrigin(
|
||||
m_big_cover.get_size()*0.5f,
|
||||
0.f
|
||||
);
|
||||
m_big_cover.setPosition(
|
||||
get_big_cover_x(),
|
||||
get_big_cover_y()
|
||||
);
|
||||
SongInfo::SongInfo(SharedResources& resources) : HoldsSharedResources(resources), m_big_cover(resources) {
|
||||
|
||||
}
|
||||
|
||||
void SongInfo::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
states.transform *= getTransform();
|
||||
m_big_cover.setOrigin(m_big_cover.get_size()*0.5f, 0.f);
|
||||
m_big_cover.setPosition(get_big_cover_x(), get_big_cover_y());
|
||||
target.draw(m_big_cover, states);
|
||||
draw_song_title(target);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace MusicSelect {
|
||||
float get_size() const {return m_resources.preferences.layout.big_cover_size*get_screen_width();};
|
||||
private:
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
sf::RectangleShape m_cover_fallback;
|
||||
mutable sf::RectangleShape m_cover_fallback;
|
||||
const Toolkit::AffineTransform<float> m_seconds_to_alpha{0.0f, 0.3f, 0.f, 255.f};
|
||||
};
|
||||
|
||||
@ -26,6 +26,6 @@ namespace MusicSelect {
|
||||
private:
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
void draw_song_title(sf::RenderTarget& target) const;
|
||||
BigCover m_big_cover;
|
||||
mutable BigCover m_big_cover;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user