Calculator started and the SFML components are off in their own thing.

This commit is contained in:
Zed A. Shaw 2025-05-05 13:50:57 -04:00
parent 942300f0bb
commit 74f5652842
4 changed files with 13 additions and 243 deletions

112
guecs.hpp
View file

@ -1,27 +1,16 @@
#pragma once
#include "dbc.hpp"
#include "sfml/color.hpp"
#include "lel.hpp"
#include <string>
#include <memory>
#include <SFML/Graphics.hpp>
#include <functional>
#include <any>
#include <queue>
#include <typeindex>
#include <unordered_map>
#include "sfml/components.hpp"
namespace guecs {
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";
using std::shared_ptr, std::wstring, std::string;
using Entity = unsigned long;
@ -34,32 +23,6 @@ namespace guecs {
std::queue<size_t> free_indices;
};
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 Clickable {
/* This is actually called by UI::mouse and passed the entity ID of the
* button pressed so you can interact with it in the event handler.
@ -67,34 +30,6 @@ namespace guecs {
std::function<void(Entity ent, std::any data)> action;
};
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 ActionData {
std::any data;
};
@ -103,50 +38,6 @@ namespace guecs {
string name;
};
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();
};
class UI {
public:
Entity MAIN = 0;
@ -306,7 +197,6 @@ namespace guecs {
return get<lel::Cell>(ent);
}
// BUG: close could just be remove with overload
template <typename Comp>
void close(string region) {