This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.hpp
67 lines (63 loc) · 1.97 KB
/
ui.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
#pragma once
#include "game.hpp"
#include "render.hpp"
namespace Win32GameEngine {
class UI : public Renderer {
protected:
set<ScreenEntity *> elements;
virtual Vec2F screen_texture(Texture const *texture, Vec2F screenp) const override {
ScreenTransform &tt = ((ScreenEntity *)texture->entity)->transform;
Vec3F aug = screenp;
aug[2] = 1;
return tt.world.inverse()(aug);
}
virtual Vec2F texture_screen(Texture const *texture, Vec2F texturep) const {
ScreenTransform &tt = ((ScreenEntity *)texture->entity)->transform;
Vec3F aug = texturep;
aug[2] = 1;
return tt.world(aug);
}
virtual Vec2F buffer_screen(Vec2I screenp) const { return screenp; }
virtual Vec2I screen_buffer(Vec2F bufferp) const { return bufferp; }
virtual bool validate(Entity const *entity) override {
if(!entity->isactive())
return false;
if(elements.find((ScreenEntity *)entity) == elements.end())
return false;
Texture *const texture = entity->getcomponent<Texture>();
if(!texture || !texture->isactive())
return false;
return true;
}
virtual bool compare(Entity const *a, Entity const *b) override {
return ((ScreenEntity *)a)->transform.z.value < ((ScreenEntity *)b)->transform.z.value;
}
virtual void sample() override {
for(Entity *const entity : queue) {
ScreenEntity *se = (ScreenEntity *)entity;
Texture *const texture = entity->getcomponent<Texture>();
Bound bound = texture->bound.transform([&](Vec2F v) {
Vec3F a = v;
a[2] = 1;
return se->transform.world(a);
});
texture->put(buffer, bound);
GetBitmapBits(buffer.gethandle(), buffer.size * sizeof(Color), buffer.data.get());
}
}
public:
UI(Entity *entity) : Renderer(entity) {}
ScreenEntity *makeelement() {
ScreenEntity *el = new ScreenEntity(entity->scene);
elements.insert(el);
return el;
}
};
class UIBase : public ScreenEntity {
public:
UI &ui;
UIBase(Scene *scene) : ScreenEntity(scene),
ui(*makecomponent<UI>()) {
}
};
}