2023-01-09 04:10:49 +01:00
|
|
|
/* UTF8-aware load_from_file functions for SFML objects,
|
|
|
|
uses nowide under the hood */
|
|
|
|
#pragma once
|
|
|
|
|
2023-01-09 16:17:46 +01:00
|
|
|
#include <SFML/System/FileInputStream.hpp>
|
2023-01-09 04:10:49 +01:00
|
|
|
#include <filesystem>
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
#include <nowide/fstream.hpp>
|
|
|
|
#include <SFML/Audio/Music.hpp>
|
|
|
|
#include <SFML/Graphics/Texture.hpp>
|
2023-01-09 16:17:46 +01:00
|
|
|
#include <SFML/System/FileInputStream.hpp>
|
|
|
|
|
|
|
|
#include "utf8_file_input_stream.hpp"
|
2023-01-09 04:10:49 +01:00
|
|
|
|
|
|
|
namespace feis {
|
2023-03-11 12:13:37 +01:00
|
|
|
/* UTF8-aware wrapper around SFML resource classes that "load" files, i.e.
|
|
|
|
resource classes that read the whole file at once when calling
|
|
|
|
load_from_file() and thus don't need the file stream to remain available
|
|
|
|
after the call to load_from_file() */
|
2023-01-09 16:17:46 +01:00
|
|
|
template<class T>
|
|
|
|
class LoadFromPathMixin : public T {
|
2023-01-09 04:10:49 +01:00
|
|
|
public:
|
2023-01-09 16:17:46 +01:00
|
|
|
bool load_from_path(const std::filesystem::path& file) {
|
|
|
|
UTF8FileInputStream f;
|
|
|
|
if (not f.open(file)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this->loadFromStream(f);
|
|
|
|
}
|
2023-01-09 04:10:49 +01:00
|
|
|
};
|
|
|
|
|
2023-03-11 12:13:37 +01:00
|
|
|
/* UTF8-aware wrapper around SFML resource classes that "open" files, i.e.
|
|
|
|
resource classes that just store the file stream when open_from_path() is
|
|
|
|
called and stream the file contents on demand and hence require the file
|
|
|
|
stream to remain available for the whole lifetime of the resource */
|
2023-01-09 04:10:49 +01:00
|
|
|
template<class T>
|
2023-01-09 16:17:46 +01:00
|
|
|
class HoldFileStreamMixin : public T {
|
2023-01-09 04:10:49 +01:00
|
|
|
public:
|
2023-01-09 16:17:46 +01:00
|
|
|
bool open_from_path(const std::filesystem::path& file) {
|
|
|
|
if (not file_stream.open(file)) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
return this->openFromStream(file_stream);
|
|
|
|
}
|
2023-01-09 04:10:49 +01:00
|
|
|
protected:
|
2023-01-09 16:17:46 +01:00
|
|
|
UTF8FileInputStream file_stream;
|
2023-01-09 04:10:49 +01:00
|
|
|
};
|
|
|
|
}
|