-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandalone-pyplug.cpp
More file actions
202 lines (156 loc) · 4.26 KB
/
standalone-pyplug.cpp
File metadata and controls
202 lines (156 loc) · 4.26 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
#include "tools.hpp"
#include <cstdint>
#include <sys/types.h>
#include <vector>
#define STANDALONE_MODE
/*
* Just for testing purpouses.
*/
#include "pyplug.cpp"
static std::vector<booba::Tool*> tools;
// ESL {{{
namespace booba {
void addTool(Tool *t)
{
std::cerr << "Tool " << (size_t)(t) << " was added\n";
tools.push_back(t);
}
void addFilter(Tool *t)
{
std::cerr << "Tool " << (size_t)(t) << " was added\n";
tools.push_back(t);
}
bool setToolBarSize(size_t w, size_t h)
{
std::cerr << "ToolBar was set to (w = " << w << ", h = " << h << ")\n";
return true;
}
size_t createButton(size_t x, size_t y, size_t w, size_t h, const char *text)
{
return x + y + w + h;
}
size_t createLabel(size_t x, size_t y, size_t w, size_t h, const char *text)
{
return x + y + w + h;
}
size_t createSlider(size_t x, size_t y, size_t w, size_t h, long min, long max, long start)
{
return min + max + start;
}
size_t createCanvas(size_t x, size_t y, size_t w, size_t h)
{
return x + y + w + h;
}
void setValueSlider(uint64_t sliderId, int64_t val)
{
//TODO
}
uint64_t createEditor(size_t x, size_t y, size_t w, size_t h)
{
return x * y + w * h;
}
void setTextEditor(uint64_t editorId, const char *text)
{
//TODO
}
char* getTextEditor(uint64_t editorId)
{
return (char*)editorId;
}
void putPixel(uint64_t canvas, size_t x, size_t y, booba::Color color)
{
//TODO
}
void putSprite(uint64_t canvas, size_t x, size_t y, size_t w, size_t h, const char *texture)
{
//TODO
}
void cleanCanvas(uint64_t canvasId, booba::Color color)
{
//TODO
}
void setTextLabel(uint64_t labelId, const char *text)
{
//TODO
}
char* getTextLabel(uint64_t labelId)
{
return "This is some label";
}
ApplicationContext *APPCONTEXT;
}
// ESL }}}
class TestingImage : public booba::Image {
public:
virtual size_t getH() override
{
return 10;
}
virtual size_t getW() override
{
return 20;
}
virtual booba::Color getPixel(size_t x, size_t y) override
{
return booba::Color(static_cast<uint32_t>(x + y));
}
virtual void setPixel(size_t x, size_t y, booba::Color color) override
{
assert(!"Not implemented yet!");
}
virtual booba::Picture getPicture(size_t x, size_t y, size_t w, size_t h) override
{
return booba::Picture(x, y, w, h, this);
}
virtual void setPicture(booba::Picture &&pic) override
{
std::cerr << "pic(2, 5) = " << pic(2, 5).toInteger() << "\n";
assert(pic(2, 5).toInteger() == 179);
}
virtual booba::Image* getHiddenLayer() override
{
return this;
}
virtual void clean(const booba::Color &c = booba::Color::WHITE) override
{
//TODO
}
};
int main()
{
py::scoped_interpreter guard{};
py::module_ sys = py::module_::import("sys");
sys.attr("path").attr("append")("../test/");
booba::APPCONTEXT = new booba::ApplicationContext;
std::cerr << "Started testing!\n";
py::module_ m = py::module_::import("test-plug");
py::object res = m.attr("init_module")();
for (auto tool : tools) {
std::cerr << "Testing tool " << (size_t)tool << "\n";
tool->buildSetupWidget();
TestingImage image;
booba::Event event;
event.type = booba::EventType::NoEvent;
tool->apply(&image, &event);
}
size_t ans = 0;
for (size_t i = 0; i < 10e6; ++i)
ans += i;
TestingImage image;
booba::Event event;
event.type = booba::EventType::MouseMoved;
std::cerr << "Texture: " << tools[0]->getTexture() << "\n";
tools[0]->apply(&image, &event);
for (size_t i = 0; i < 10e6; ++i)
ans += i;
tools[0]->apply(&image, &event);
for (size_t i = 0; i < 10e6; ++i)
ans += i;
tools[1]->apply(&image, &event);
for (size_t i = 0; i < 10e6; ++i)
ans += i;
tools[0]->apply(&image, &event);
event.type = booba::EventType::ButtonClicked;
tools[2]->apply(&image, &event);
std::cerr << "Finished testing!\n";
}