65 lines
1.5 KiB
C++
65 lines
1.5 KiB
C++
#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);
|
|
poll.resize(RESERVED_SIZE);
|
|
for (auto &sprite : poll)
|
|
{
|
|
sprite = createSprite(static_cast<Button>(i));
|
|
}
|
|
}
|
|
}
|
|
|
|
ClassicViewManager::~ClassicViewManager()
|
|
{}
|
|
|
|
std::shared_ptr<Sprite> ClassicViewManager::createSprite(Button kind_of_button) const
|
|
{
|
|
sf::RectangleShape sprite;
|
|
sprite.setSize({20.f, 20.f});
|
|
switch (kind_of_button)
|
|
{
|
|
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();
|
|
for (const auto& sprite : _sprite_dispatcher.at(static_cast<int>(type)))
|
|
{
|
|
if (!sprite->isAttached())
|
|
{
|
|
sprite->setCoordinates(note->position());
|
|
note->resetSprite(sprite);
|
|
return;
|
|
}
|
|
}
|
|
}
|