Moved everything around to let meson build the libraries, but I suspect I have too much SFML support gear for it to be useable.

This commit is contained in:
Zed A. Shaw 2025-05-07 12:21:34 -04:00
parent 560f506733
commit 838f54a4f4
22 changed files with 36 additions and 26 deletions

15
include/sfml/color.hpp Normal file
View file

@ -0,0 +1,15 @@
#pragma once
#include <SFML/Graphics/Color.hpp>
namespace ColorValue {
constexpr const sf::Color BLACK{0, 0, 0};
constexpr const sf::Color DARK_DARK{10, 10, 10};
constexpr const sf::Color DARK_MID{30, 30, 30};
constexpr const sf::Color DARK_LIGHT{60, 60, 60};
constexpr const sf::Color MID{100, 100, 100};
constexpr const sf::Color LIGHT_DARK{150, 150, 150};
constexpr const sf::Color LIGHT_MID{200, 200, 200};
constexpr const sf::Color LIGHT_LIGHT{230, 230, 230};
constexpr const sf::Color WHITE{255, 255, 255};
constexpr const sf::Color TRANSPARENT = sf::Color::Transparent;
}

120
include/sfml/components.hpp Normal file
View file

@ -0,0 +1,120 @@
#pragma once
#include "dbc.hpp"
#include "sfml/color.hpp"
#include "lel.hpp"
#include <string>
#include <memory>
#include <SFML/Graphics.hpp>
#include <functional>
#include <any>
namespace guecs {
using std::shared_ptr, std::wstring, std::string;
constexpr const int PADDING = 3;
constexpr const int BORDER_PX = 1;
constexpr const int TEXT_SIZE = 30;
constexpr const int LABEL_SIZE = 20;
constexpr const sf::Color FILL_COLOR = ColorValue::DARK_MID;
constexpr const sf::Color TEXT_COLOR = ColorValue::LIGHT_LIGHT;
constexpr const sf::Color BG_COLOR = ColorValue::MID;
constexpr const sf::Color BORDER_COLOR = ColorValue::MID;
constexpr const char *FONT_FILE_NAME="assets/text.otf";
struct Textual {
std::wstring content;
unsigned int size = TEXT_SIZE;
sf::Color color = TEXT_COLOR;
int padding = PADDING;
bool centered = false;
shared_ptr<sf::Font> font = nullptr;
shared_ptr<sf::Text> text = nullptr;
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr);
void update(const std::wstring& new_content);
};
struct Label : public Textual {
template<typename... Args>
Label(Args... args) : Textual(args...)
{
centered = true;
size = LABEL_SIZE;
}
Label() {
centered = true;
};
};
struct Sprite {
string name;
int padding = PADDING;
std::shared_ptr<sf::Sprite> sprite = nullptr;
void init(lel::Cell &cell);
void update(const string& new_name);
};
struct Rectangle {
int padding = PADDING;
sf::Color color = FILL_COLOR;
sf::Color border_color = BORDER_COLOR;
int border_px = BORDER_PX;
shared_ptr<sf::RectangleShape> shape = nullptr;
void init(lel::Cell& cell);
};
struct Meter {
float percent = 1.0f;
sf::Color color = ColorValue::BLACK;
Rectangle bar;
void init(lel::Cell& cell);
void render(lel::Cell& cell);
};
struct Effect {
float duration = 0.1f;
string name{"ui_shader"};
float $u_time_end = 0.0;
bool $active = false;
std::shared_ptr<sf::Clock> $clock = nullptr;
std::shared_ptr<sf::Shader> $shader = nullptr;
int $shader_version = 0;
void init(lel::Cell &cell);
void run();
void stop();
void step();
shared_ptr<sf::Shader> checkout_ptr();
};
struct Sound {
string on_click{"ui_click"};
void play(bool hover);
void stop(bool hover);
};
struct Background {
float x = 0.0f;
float y = 0.0f;
float w = 0.0f;
float h = 0.0f;
sf::Color color = BG_COLOR;
shared_ptr<sf::RectangleShape> shape = nullptr;
Background(lel::Parser& parser, sf::Color bg_color=BG_COLOR) :
x(parser.grid_x),
y(parser.grid_y),
w(parser.grid_w),
h(parser.grid_h),
color(bg_color)
{}
Background() {}
void init();
};
}

27
include/sfml/shaders.hpp Normal file
View file

@ -0,0 +1,27 @@
#pragma once
#include <cstdint>
#include <vector>
#include <string>
#include <SFML/Graphics.hpp>
#include <unordered_map>
#include <memory>
#include <nlohmann/json.hpp>
namespace shaders {
struct Record {
std::string name;
std::string file_name;
std::shared_ptr<sf::Shader> ptr = nullptr;
};
struct ShaderManager {
std::unordered_map<std::string, Record> shaders;
};
std::shared_ptr<sf::Shader> get(const std::string& name);
void init();
bool load_shader(std::string& name, nlohmann::json& settings);
bool updated(int my_version);
int reload();
int version();
}

26
include/sfml/sound.hpp Normal file
View file

@ -0,0 +1,26 @@
#pragma once
#include <string>
#include <filesystem>
#include <memory>
#include <unordered_map>
#include <SFML/Audio.hpp>
namespace sound {
struct SoundPair {
std::shared_ptr<sf::SoundBuffer> buffer;
std::shared_ptr<sf::Sound> sound;
};
struct SoundManager {
std::unordered_map<std::string, SoundPair> sounds;
};
void init();
void load(const std::string& name, const std::string& path);
void play(const std::string& name, bool loop=false);
void play_at(const std::string& name, float x, float y, float z);
void stop(const std::string& name);
void mute(bool setting);
bool playing(const std::string& name);
SoundPair& get_sound_pair(const std::string& name);
}

27
include/sfml/textures.hpp Normal file
View file

@ -0,0 +1,27 @@
#pragma once
#include <cstdint>
#include <vector>
#include <string>
#include <SFML/Graphics.hpp>
#include <unordered_map>
#include <memory>
namespace textures {
struct SpriteTexture {
std::shared_ptr<sf::Sprite> sprite = nullptr;
std::shared_ptr<sf::Texture> texture = nullptr;
};
struct TextureManager {
std::vector<sf::Image> surfaces;
std::unordered_map<std::string, SpriteTexture> sprite_textures;
std::unordered_map<wchar_t, int> char_to_texture;
};
void init();
SpriteTexture get(const std::string& name);
sf::Image load_image(const std::string& filename);
}