forked from NaiJi/project-kyoku
Implement selection manager
parent
4ec11560f1
commit
6768aeabdf
@ -1,9 +1,8 @@
|
||||
#include "classicnote.h"
|
||||
#include "classicmode/classicnote.h"
|
||||
|
||||
ClassicNote::ClassicNote(NoteInitializer &&init) :
|
||||
Note(init.perfect_offset),
|
||||
_state(State::NONE),
|
||||
_context(init.context)
|
||||
_state(State::NONE)
|
||||
{}
|
||||
|
||||
void ClassicNote::setState(ClassicNote::State state) noexcept
|
@ -0,0 +1,53 @@
|
||||
#include "selectionmanager.h"
|
||||
#include "classicmocknote.h"
|
||||
#include "mockelement.h"
|
||||
#include "graphics/classicselection.h"
|
||||
#include <algorithm>
|
||||
|
||||
SelectionManager::SelectionManager() :
|
||||
_multiselection_enabled(false)
|
||||
{}
|
||||
|
||||
void SelectionManager::discard()
|
||||
{
|
||||
for (const auto& note : _selected_notes)
|
||||
for (auto& element : note->getElements())
|
||||
element.selected = false;
|
||||
|
||||
_selected_notes.clear();
|
||||
}
|
||||
|
||||
void SelectionManager::fetch(ClassicMockNote * const note)
|
||||
{
|
||||
bool already_there = std::any_of(_selected_notes.begin(), _selected_notes.end(),
|
||||
[¬e](const auto& selected_note)
|
||||
{
|
||||
return note == selected_note;
|
||||
});
|
||||
|
||||
if (!already_there)
|
||||
_selected_notes.emplace_back(note);
|
||||
}
|
||||
|
||||
void SelectionManager::remove(ClassicMockNote * const note)
|
||||
{
|
||||
for (std::size_t i = 0; i < _selected_notes.size(); ++i)
|
||||
{
|
||||
if (note == _selected_notes.at(i))
|
||||
{
|
||||
_selected_notes[i] = std::move(_selected_notes.back());
|
||||
_selected_notes.pop_back();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SelectionManager::enableMultiselection(bool enable)
|
||||
{
|
||||
_multiselection_enabled = enable;
|
||||
}
|
||||
|
||||
bool SelectionManager::isMultiselectionEnabled() const
|
||||
{
|
||||
return _multiselection_enabled;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "classicmocknote.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class SelectionManager
|
||||
{
|
||||
public:
|
||||
explicit SelectionManager();
|
||||
|
||||
// Remove whole selection completely
|
||||
void discard();
|
||||
|
||||
void fetch(ClassicMockNote * const note);
|
||||
void remove(ClassicMockNote * const note);
|
||||
|
||||
void enableMultiselection(bool enable = true);
|
||||
bool isMultiselectionEnabled() const;
|
||||
|
||||
private:
|
||||
std::vector<ClassicMockNote*> _selected_notes;
|
||||
bool _multiselection_enabled;
|
||||
};
|
@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class HoldManager;
|
||||
|
||||
struct Context
|
||||
{
|
||||
std::shared_ptr<HoldManager> hold_manager;
|
||||
};
|
Loading…
Reference in New Issue