-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_std.hpp
190 lines (131 loc) · 6.7 KB
/
plugin_std.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#ifndef PLUGIN_STD_HPP
#define PLUGIN_STD_HPP
#include <filesystem>
#include <string_view>
#include "lib_std/types_std.h"
#include "lib_std/widgets/collection.h"
#include "lib_std/extensioner_std.h"
namespace PUPPY {
constexpr uint32_t STD_VERSION = 0x00010000;
constexpr char EXT_STD[] = "std";
// this function is only defined in plugin. call it to get PluginInterface to interact with plugin
// make sure you wrap it into extern C section to avoid mangling
// const PluginInterface *get_plugin_interface();
struct PluginInterface;
constexpr char GET_INTERFACE_FUNC[] = "get_plugin_interface";
typedef PluginInterface* (*PluginGetInterfaceType)();
#ifdef _WIN32
#define PLUGIN_GETINTF_EXPORT __declspec(dllexport)
#else
#define PLUGIN_GETINTF_EXPORT
#endif
// ============================================================================
class RenderTarget {
public:
virtual ~RenderTarget() {}
virtual RenderTarget *get_copy() const = 0;
virtual Vec2s get_size() const = 0;
virtual RGBA get_pixel(size_t x, size_t y) const = 0;
virtual void set_pixel(size_t x, size_t y, const RGBA &color) = 0;
virtual RGBA *get_pixels() const = 0;
virtual void clear(const RGBA &color = 0) = 0; // fills the target with `color`
// render
virtual void render_circle(const Vec2f &position, float radius, const RGBA &color, const RenderMode &render_mode = {}) = 0;
virtual void render_line(const Vec2f &start, const Vec2f &end, const RGBA &color, const RenderMode &render_mode = {}) = 0;
virtual void render_triangle(const Vec2f &p1, const Vec2f &p2, const Vec2f &p3, const RGBA &color, const RenderMode &render_mode = {}) = 0;
virtual void render_rectangle(const Vec2f &p1, const Vec2f &p2, const RGBA &color, const RenderMode &render_mode = {}) = 0;
virtual void render_texture(const Vec2f &position, const RenderTarget *texture, const RenderMode &render_mode = {}) = 0;
virtual void render_pixels(const Vec2f &position, const Vec2s &size, const RGBA *data, const RenderMode &render_mode = {}) = 0;
virtual void apply_shader(const Shader *shader) = 0;
};
struct PluginInterface;
struct PluginInfo {
const uint32_t std_version;
void *reserved;
const PluginInterface *const interface;
const char *const name;
const char *const version;
const char *const author;
const char *const description;
const RenderTarget *icon;
const PluginType type;
};
struct AppInterface;
struct PluginInterface {
PluginInterface(uint32_t std_version = STD_VERSION, void* reserved = nullptr) :
std_version(std_version), reserved(reserved) {}
uint32_t std_version;
void *reserved;
// enables specified extension
virtual bool ext_enable(const char *name) const = 0;
// returns given function, if it is implemented in the specified (enabled) extension
virtual void *ext_get_func(const char *extension, const char *func) const = 0;
// returns given interface, if it is implemented in the specified (enabled) extension
virtual void *ext_get_interface(const char *extension, const char *name) const = 0;
virtual const PluginInfo *get_info() const = 0;
virtual Status init(const AppInterface*, const std::filesystem::path& path = std::filesystem::path("./")) = 0;
virtual Status deinit() = 0;
virtual void dump() const = 0;
virtual void on_tick(double dt) const = 0;
virtual void effect_apply() const = 0;
virtual void tool_on_press (const Vec2f &position) const = 0;
virtual void tool_on_release(const Vec2f &position) const = 0;
virtual void tool_on_move (const Vec2f &from, const Vec2f &to) const = 0;
virtual void show_settings() const = 0;
};
struct WidgetFactory {
virtual ~WidgetFactory() {}
virtual Button *button (const WBody &body, Widget *parent = nullptr) const = 0;
virtual Button *button (const PUPPY::Vec2f &pos, const char *caption, PUPPY::Widget *parent = nullptr) const = 0; // button fit to contain caption
virtual Slider *slider (Slider::Type type, const WBody &body, Widget *parent = nullptr) const = 0;
virtual TextField *text_field (const WBody &body, Widget *parent = nullptr) const = 0;
virtual Window *window (const char *name, const WBody &body, Widget *parent = nullptr) const = 0;
virtual ColorPicker *color_picker (const WBody &body, Widget *parent = nullptr) const = 0;
virtual Label *label (const PUPPY::Vec2f &pos, const char *text, Widget *parent = nullptr) const = 0;
virtual Widget *abstract (const WBody &body, Widget *parent = nullptr) const = 0;
};
struct ShaderFactory {
virtual ~ShaderFactory() {}
virtual Shader *compile (const char *code, ShaderType type, bool is_code = true) const = 0;
};
struct RenderTargetFactory {
virtual ~RenderTargetFactory() {}
virtual RenderTarget *spawn(const Vec2s &size, const RGBA &color = {0, 0, 0, 255}) const = 0; // color -> fill with it
virtual RenderTarget *from_pixels(const Vec2s &size, const RGBA *data) const = 0;
virtual RenderTarget *from_file(const char *path) const = 0;
};
struct AppInterface {
uint32_t std_version;
void *reserved;
int feature_level;
struct {
WidgetFactory *widget;
ShaderFactory *shader;
RenderTargetFactory *target;
} factory;
// extension
// enables specified extension
virtual bool ext_enable(const char *name) const = 0;
// returns given function, if it is implemented in the specified (enabled) extension
virtual void *ext_get_func(const char *extension, const char *func) const = 0;
// returns given interface, if it is implemented in the specified (enabled) extension
virtual void *ext_get_interface(const char *extension, const char *name) const = 0;
// registers plugin as the holder of functions and interfaces for an extension
virtual void ext_register_as(const char *extension) const = 0;
// general
virtual void log(const char *fmt, ...) const = 0;
virtual double get_absolute_time() const = 0;
virtual RGBA get_color() const = 0;
virtual float get_size() const = 0;
virtual void set_color(const PUPPY::RGBA &color) const = 0;
virtual void set_size(float size) const = 0;
virtual const std::vector<WBody> get_windows() const = 0;
virtual Widget *get_root_widget() const = 0;
// target
virtual RenderTarget *get_target() const = 0; // returns actual active layer, drawing in it changes app's layer
virtual RenderTarget *get_preview() const = 0; // returns actual preview layer, drawing in it changes app's layer
virtual void flush_preview() const = 0;
virtual ~AppInterface() {}
};
}
#endif