88 lines
1.9 KiB
C++
88 lines
1.9 KiB
C++
#ifndef ELEMENTS_H
|
|
#define ELEMENTS_H
|
|
|
|
#include "bindings/ruby.h"
|
|
#include "localization/localization.h"
|
|
#include "utils.h"
|
|
#include "window/window.h"
|
|
|
|
enum Type { IMAGE,
|
|
TEXT,
|
|
RECT };
|
|
|
|
enum ClickMode { PASS,
|
|
BLOCK,
|
|
IGNORE };
|
|
|
|
namespace app {
|
|
struct Element {
|
|
Type type;
|
|
Vec2<float> position = {0, 0};
|
|
float rotation = 0;
|
|
Vec2<float> pivot = {0, 0};
|
|
Vec2<float> scale = {1, 1};
|
|
float alpha = 1.0f;
|
|
float z = 0;
|
|
ClickMode click_mode = ClickMode::BLOCK;
|
|
Ruby::Block on_click;
|
|
|
|
Element(Type type) : type(type) {}
|
|
virtual ~Element() = default;
|
|
virtual void render(uint64_t) = 0;
|
|
virtual Vec2<float> size() = 0;
|
|
|
|
void click();
|
|
};
|
|
|
|
struct EImage : Element {
|
|
uint64_t animation_id = UINT64_MAX;
|
|
|
|
EImage(uint64_t animation_id) : Element(Type::IMAGE), animation_id(animation_id) {}
|
|
|
|
~EImage();
|
|
|
|
Vec2<float> size() override;
|
|
|
|
void render(uint64_t) override;
|
|
};
|
|
|
|
struct EText : Element {
|
|
Localization::Key key;
|
|
uint64_t font_id = UINT64_MAX;
|
|
Color color = {255, 255, 255};
|
|
std::unordered_map<std::string, std::string> params;
|
|
|
|
~EText();
|
|
|
|
EText(Localization::Key key, uint64_t font_id, Color color, std::unordered_map<std::string, std::string> params)
|
|
: Element(Type::TEXT), key(key), font_id(font_id), color(color), params(params) {}
|
|
|
|
Vec2<float> size() override;
|
|
|
|
void reload_text();
|
|
|
|
void render(uint64_t) override;
|
|
|
|
private:
|
|
uint64_t text_id = UINT64_MAX;
|
|
Color last_color = color;
|
|
Localization::LanguageCode last_language = UINT32_MAX;
|
|
Localization::Key last_key = UINT16_MAX;
|
|
bool params_changed = true;
|
|
};
|
|
|
|
struct ERect : Element {
|
|
Color color = {255, 255, 255};
|
|
Vec2<float> shape = {0, 0};
|
|
|
|
Vec2<float> size() override;
|
|
|
|
ERect(Vec2<float> shape, Color color) : Element(Type::RECT), shape(shape), color(color) {}
|
|
|
|
void render(uint64_t) override;
|
|
};
|
|
|
|
inline Pool<Element> element_pool;
|
|
} // namespace app
|
|
|
|
#endif |