Save window size

This commit is contained in:
Stepland 2023-07-20 15:38:48 +02:00
parent fa16d34e5c
commit 8f0e7f6041
6 changed files with 52 additions and 15 deletions

View File

@ -1,5 +1,4 @@
# v2.0.0
*(+ 2.0.0-rc.1)*
## 🥝🍇🍓🍊🍏 New Stuff 🍏🍊🍓🍇🥝
- BPM Autodetect
- Waveform mode for the Linear View
@ -40,6 +39,7 @@
- Support for the jujube marker format
- Sound parameters are saved
- Markers and Marker previews are loaded in the background, which should avoid long boot up times + UI freezes
- The window size is saved and restored when restarting F.E.I.S.
## 🚧 Changes 🚧
- Force using the asset folder next to the executable
@ -61,6 +61,7 @@
- cutting/pasting/deleting notes with the keyboard shortcuts or the menu item
- the audio file changes or is unloaded (because of an invalid path for example) (or more generally when the end point of the chart changes without the notes changing)
- BPMs are inserted
- Fix background logo disappearing if the window is smaller than the logo
# v1.1.0
## 🍓 New Stuff 🍓

View File

@ -140,6 +140,7 @@ void config::Windows::load_from_v1_0_0_table(const toml::table& tbl) {
return;
}
const auto windows_table = tbl["windows"].ref<toml::table>();
load_vector2(windows_table["main_window_size"], main_window_size);
if (auto val = windows_table["show_playfield"].value<bool>()) {
show_playfield = *val;
}
@ -188,7 +189,8 @@ void config::Windows::load_from_v1_0_0_table(const toml::table& tbl) {
}
void config::Windows::dump_as_v1_0_0(toml::table& tbl) {
tbl.insert_or_assign("windows", toml::table{
auto window_table = toml::table{
{"main_window_size", dump_vector2(main_window_size)},
{"show_playfield", show_playfield},
{"show_playfield_settings", show_playfield_settings},
{"show_file_properties", show_file_properties},
@ -204,7 +206,8 @@ void config::Windows::dump_as_v1_0_0(toml::table& tbl) {
{"show_chart_properties", show_chart_properties},
{"show_sync_menu", show_sync_menu},
{"show_bpm_change_menu", show_bpm_change_menu}
});
};
tbl.insert_or_assign("windows", window_table);
}

View File

@ -1,7 +1,9 @@
#pragma once
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Time.hpp>
#include <SFML/System/Vector2.hpp>
#include <filesystem>
#include <toml++/toml.h>
@ -58,6 +60,7 @@ namespace config {
};
struct Windows {
sf::Vector2u main_window_size = {800, 600};
bool show_playfield = true;
bool show_playfield_settings = false;
bool show_file_properties = false;
@ -78,6 +81,33 @@ namespace config {
void dump_as_v1_0_0(toml::table& tbl);
};
template<class T, class toml_node>
std::optional<sf::Vector2<T>> parse_vector2(const toml_node& node) {
const auto array = node.as_array();
if (array == nullptr or array->size() != 2) {
return {};
}
const auto a = array->at(0).template value<T>();
const auto b = array->at(1).template value<T>();
if (not (a and b)) {
return {};
}
return sf::Vector2<T>{*a, *b};
}
template<class T>
toml::array dump_vector2(const sf::Vector2<T>& vec) {
return toml::array{vec.x, vec.y};
}
template<class T, class toml_node>
void load_vector2(const toml_node& node, sf::Vector2<T>& vec) {
const auto parsed = parse_vector2<T>(node);
if (parsed) {
vec = *parsed;
}
}
struct Playfield {
bool show_free_buttons = false;
bool color_chords = false;

View File

@ -3,7 +3,10 @@
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/System/Time.hpp>
#include <SFML/Window/ContextSettings.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <SFML/Window/VideoMode.hpp>
#include <algorithm>
#include <chrono>
#include <exception>
@ -47,11 +50,12 @@ int main() {
const auto markers_folder = assets_folder / "textures" / "markers";
config::Config config{settings_folder};
sf::RenderWindow window(sf::VideoMode(800, 600), "FEIS");
const auto video_mode = sf::VideoMode{config.windows.main_window_size.x, config.windows.main_window_size.y};
sf::RenderWindow window;
window.setVerticalSyncEnabled(true);
window.setFramerateLimit(60);
window.setKeyRepeatEnabled(false);
window.create(video_mode, "F.E.I.S");
ImGui::SFML::Init(window, false);
@ -114,6 +118,7 @@ int main() {
case sf::Event::Resized:
window.setView(sf::View(
sf::FloatRect(0, 0, event.size.width, event.size.height)));
config.windows.main_window_size = window.getSize();
break;
case sf::Event::MouseButtonPressed:
switch (event.mouseButton.button) {

View File

@ -1,25 +1,23 @@
#include "blank_screen.hpp"
#include <SFML/System/Vector2.hpp>
#include <string>
#include "toolbox.hpp"
#include "utf8_strings.hpp"
BlankScreen::BlankScreen(std::filesystem::path assets) : gris_de_fond(sf::Color(38, 38, 38)) {
BlankScreen::BlankScreen(std::filesystem::path assets) : background_grey(sf::Color(38, 38, 38)) {
if (!tex_FEIS_logo.load_from_path(assets / "textures" / "FEIS_logo.png")) {
throw std::string("Unable to load assets/textures/FEIS_logo.png");
}
tex_FEIS_logo.setSmooth(true);
FEIS_logo.setTexture(tex_FEIS_logo);
FEIS_logo.setColor(sf::Color(255, 255, 255, 32)); // un huitième opaque
FEIS_logo.setColor(sf::Color(255, 255, 255, 32));
}
void BlankScreen::render(sf::RenderWindow& window) {
// effacement de la fenêtre en noir
window.clear(gris_de_fond);
// c'est ici qu'on dessine tout
FEIS_logo.setPosition(sf::Vector2f(
static_cast<float>((window.getSize().x - tex_FEIS_logo.getSize().x) / 2),
static_cast<float>((window.getSize().y - tex_FEIS_logo.getSize().y) / 2)));
window.clear(background_grey);
Toolbox::center(FEIS_logo);
FEIS_logo.setPosition(sf::Vector2f{window.getSize()} / 2.0f);
window.draw(FEIS_logo);
}

View File

@ -11,7 +11,7 @@ public:
void render(sf::RenderWindow& window);
private:
sf::Color gris_de_fond;
sf::Color background_grey;
feis::Texture tex_FEIS_logo;
sf::Sprite FEIS_logo;
};