project-kyoku/timelineviews/classicviewmanager.cpp

65 lines
1.5 KiB
C++
Raw Normal View History

2021-04-15 11:03:35 -04:00
#include "classicviewmanager.h"
#include "../note.h"
#include <SFML/Graphics/RectangleShape.hpp>
static constexpr std::size_t RESERVED_SIZE = 20;
ClassicViewManager::ClassicViewManager()
{
for (std::size_t i = ARROW_UP; i < AMOUNT_OF_KINDS; ++i)
{
SpritePoll &poll = _sprite_dispatcher.at(i);
2021-04-17 12:14:36 -04:00
poll.resize(RESERVED_SIZE);
2021-04-15 11:03:35 -04:00
for (auto &sprite : poll)
{
2021-04-17 12:14:36 -04:00
sprite = createSprite(static_cast<Button>(i));
2021-04-15 11:03:35 -04:00
}
}
}
2021-04-17 12:14:36 -04:00
ClassicViewManager::~ClassicViewManager()
{}
2021-04-15 11:03:35 -04:00
std::shared_ptr<Sprite> ClassicViewManager::createSprite(Button kind_of_button) const
{
2021-04-17 12:14:36 -04:00
sf::RectangleShape sprite;
sprite.setSize({20.f, 20.f});
2021-04-15 11:03:35 -04:00
switch (kind_of_button)
{
2021-04-17 12:14:36 -04:00
case ARROW_UP:
sprite.setFillColor(sf::Color(255, 0, 0));
break;
case ARROW_DOWN:
sprite.setFillColor(sf::Color(0, 255, 0));
break;
case ARROW_LEFT:
sprite.setFillColor(sf::Color(0, 0, 255));
break;
case ARROW_RIGHT:
sprite.setFillColor(sf::Color(255, 0, 255));
break;
default: // yellow
sprite.setFillColor(sf::Color(255, 239, 0));
}
return std::make_shared<Sprite>(sprite);
}
void ClassicViewManager::initNoteGraphics(Note *note)
{
const auto type = note->type();
2021-04-18 17:44:09 -04:00
for (const auto& sprite : _sprite_dispatcher.at(static_cast<int>(type)))
2021-04-17 12:14:36 -04:00
{
if (!sprite->isAttached())
{
sprite->setCoordinates(note->position());
note->resetSprite(sprite);
return;
}
2021-04-15 11:03:35 -04:00
}
}