Switched to using events for shortcuts

This commit is contained in:
Stepland 2019-01-16 22:10:20 +01:00
parent 5e057aad4b
commit 6ee1e9271c
5 changed files with 32 additions and 38 deletions

View File

@ -11,7 +11,7 @@
#include "tinyfiledialogs.h"
#include "Toolbox.h"
EditorState::EditorState(Fumen &fumen) : fumen(fumen), markerEndingState(MISS) {
EditorState::EditorState(Fumen &fumen) : fumen(fumen) {
reloadFromFumen();
}
@ -304,7 +304,7 @@ std::vector<Note> EditorState::getVisibleNotes() {
std::vector<Note> visibleNotes;
float minPos;
if (this->markerEndingState == MISS) {
if (this->playfield.markerEndingState == MISS) {
minPos = playbackPosition.asSeconds() - 8.f/30.f;
} else {
minPos = playbackPosition.asSeconds() - 16.f/30.f;

View File

@ -16,11 +16,13 @@ class EditorState {
public:
Fumen fumen;
Widgets::Playfield playfield;
MarkerEndingState markerEndingState;
std::optional<sf::Music> music;
std::optional<sf::Texture> jacket;
std::optional<Chart> selectedChart; // Ok this was a pretty terrible design choice, be EXTRA careful about this still being in sync with what's actually in the std::map of fumen
Widgets::Playfield playfield;
std::optional<sf::Music> music;
float musicVolume = 100.f; // 0 -> 100
std::optional<sf::Texture> jacket;
sf::Time playbackPosition;
sf::Time chartRuntime; // Timing at which the playback stops

View File

@ -10,20 +10,6 @@
#include <c++/8.2.1/fstream>
#include "Toolbox.h"
bool Toolbox::isShortcutPressed(std::initializer_list<sf::Keyboard::Key> anyOf, std::initializer_list<sf::Keyboard::Key> allOf) {
for (auto key : allOf) {
if (not sf::Keyboard::isKeyPressed(key)) {
return false;
}
}
for (auto key : anyOf) {
if (sf::Keyboard::isKeyPressed(key)) {
return true;
}
}
return false;
}
void Toolbox::pushNewRecentFile(std::filesystem::path path) {
std::ifstream readFile(std::filesystem::path("settings/recent files.txt"));
std::list<std::string> recent;
@ -108,4 +94,3 @@ bool Toolbox::InputTextColored(bool isValid, const std::string& hoverHelpText, c
}
return return_value;
}

View File

@ -8,7 +8,9 @@
#define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B))
#include <SFML/Window.hpp>
#include <functional>
#include <filesystem>
#include "EditorState.h"
namespace Toolbox {
@ -20,7 +22,6 @@ namespace Toolbox {
ImColor FrameBgHovered_Red = {0.980f, 0.261f, 0.261f, 0.400f};
ImColor FrameBgActive_Red = {0.980f, 0.261f, 0.261f, 0.671f};
};
bool isShortcutPressed(std::initializer_list<sf::Keyboard::Key> anyOf, std::initializer_list<sf::Keyboard::Key> allOf);
void pushNewRecentFile(std::filesystem::path path);
std::vector<std::string> getRecentFiles();

View File

@ -18,6 +18,9 @@ int main(int argc, char** argv) {
// TODO : Edition des notes à la souris (mode suppression / mode ajout)
// TODO : Bruit différent si clap simple ou chord
// TODO : Density graph sur la timeline
// TODO : Système de notifs
// TODO : Undo / Redo
// TODO : set pitch
// Création de la fenêtre
sf::RenderWindow window(sf::VideoMode(800, 600), "FEIS");
@ -87,8 +90,27 @@ int main(int argc, char** argv) {
}
}
break;
case sf::Keyboard::O:
if (event.key.control) {
ESHelper::open(editorState);
}
break;
case sf::Keyboard::P:
if (event.key.shift) {
editorState->showProperties = true;
}
break;
case sf::Keyboard::S:
if (event.key.control) {
ESHelper::save(*editorState);
}
break;
default:
break;
}
break;
default:
break;
}
}
@ -177,22 +199,6 @@ int main(int argc, char** argv) {
bg.render(window);
}
// TODO : Use events instead
// Gestion des Raccourcis Clavier
// Ctrl+S
if (editorState and Toolbox::isShortcutPressed({sf::Keyboard::LControl,sf::Keyboard::RControl},{sf::Keyboard::S})) {
ESHelper::save(*editorState);
// Ctrl+O
} else if (Toolbox::isShortcutPressed({sf::Keyboard::LControl,sf::Keyboard::RControl},{sf::Keyboard::O})) {
ESHelper::open(editorState);
// Shift+P
} else if (editorState and Toolbox::isShortcutPressed({sf::Keyboard::LShift,sf::Keyboard::RShift},{sf::Keyboard::P})) {
editorState->showProperties = true;
}
// Dessin de l'interface
ImGui::BeginMainMenuBar();
{