A GUI library for games that's so small you won't even know its there.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
lel-guecs/include/guecs/sfml/components.hpp

116 lines
2.7 KiB

#pragma once
#include <SFML/Graphics.hpp>
#include "guecs/dbc.hpp"
#include "guecs/lel.hpp"
#include <string>
#include <memory>
#include <functional>
#include <any>
#include "guecs/theme.hpp"
namespace guecs {
using std::shared_ptr, std::wstring, std::string;
struct Textual {
std::wstring content;
unsigned int size = THEME.TEXT_SIZE;
sf::Color color = THEME.TEXT_COLOR;
int padding = THEME.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 = THEME.LABEL_SIZE;
}
Label() {
centered = true;
};
};
struct Sprite {
// either you set a filename here,
// or some kind of config,
// or a callback that does the loading,
// or a virtual function and you subclass
// or there's a static config function you call once,
// that's passed an object with all the necessary gear
string name;
int padding = THEME.PADDING;
std::shared_ptr<sf::Sprite> sprite = nullptr;
void init(lel::Cell &cell);
void update(const string& new_name);
};
struct Rectangle {
int padding = THEME.PADDING;
sf::Color color = THEME.FILL_COLOR;
sf::Color border_color = THEME.BORDER_COLOR;
int border_px = THEME.BORDER_PX;
shared_ptr<sf::RectangleShape> shape = nullptr;
void init(lel::Cell& cell);
};
struct Meter {
float percent = 1.0f;
sf::Color color = THEME.BG_COLOR_DARK;
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 = THEME.BG_COLOR;
shared_ptr<sf::RectangleShape> shape = nullptr;
Background(lel::Parser& parser, sf::Color bg_color=THEME.BG_COLOR) :
x(parser.grid_x),
y(parser.grid_y),
w(parser.grid_w),
h(parser.grid_h),
color(bg_color)
{}
Background() {}
void init();
};
}