-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatter.cpp
More file actions
207 lines (163 loc) · 5.32 KB
/
matter.cpp
File metadata and controls
207 lines (163 loc) · 5.32 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
203
204
205
206
207
#include "matter.hpp"
#include "plane.hpp"
#include "datum/box.hpp"
#include "graphics/image.hpp"
#include "physics/algebra/vector.hpp"
#include <typeinfo>
using namespace Plteen;
/**************************************************************************************************/
Plteen::IMatter::~IMatter() {
if (this->info != nullptr) {
delete this->info;
this->info = nullptr;
}
if (this->_metatdata != nullptr) {
delete this->_metatdata;
this->_metatdata = nullptr;
}
}
IPlane* Plteen::IMatter::master() const {
IPlane* plane = nullptr;
if (this->info != nullptr) {
plane = this->info->master;
}
return plane;
}
dc_t* Plteen::IMatter::drawing_context() const {
IPlane* master = this->master();
dc_t* device = nullptr;
if (master != nullptr) {
device = master->drawing_context();
}
return device;
}
void Plteen::IMatter::attach_metadata(IMatterMetadata* metadata) {
if (this->_metatdata != nullptr) {
delete this->_metatdata;
}
this->_metatdata = metadata;
}
bool Plteen::IMatter::is_colliding(const Dot& local_pt) {
Box box = this->get_bounding_box();
Margin margin = this->get_margin();
return margin.is_point_inside(local_pt.x, local_pt.y, box.width(), box.height());
}
void Plteen::IMatter::scale(float x_ratio, float y_ratio, const Port& port) {
if (this->can_resize) {
if ((x_ratio != 1.0F) || (y_ratio != 1.0F)) {
Box box = this->get_bounding_box();
this->moor(port);
this->on_resize(box.width() * x_ratio, box.height() * y_ratio, box.width(), box.height());
this->notify_updated();
}
}
}
void Plteen::IMatter::scale_to(float x_ratio, float y_ratio, const Port& port) {
if (this->can_resize) {
float nwidth, nheight;
Box cbox = this->get_bounding_box();
Box obox = this->get_original_bounding_box();
nwidth = obox.width() * x_ratio;
nheight = obox.height() * y_ratio;
if ((nwidth != cbox.width()) || (nheight != cbox.height())) {
this->moor(port);
this->on_resize(nwidth, nheight, cbox.width(), cbox.height());
this->notify_updated();
}
}
}
void Plteen::IMatter::scale_by_size(float size, bool given_width, const Port& port) {
if (this->can_resize) {
float nwidth, nheight;
Box box = this->get_bounding_box();
if (given_width) {
nwidth = size;
nheight = box.height() * (size / box.width());
} else {
nheight = size;
nwidth = box.width() * (size / box.height());
}
if ((nwidth != box.width()) || (nheight != box.height())) {
this->moor(port);
this->on_resize(nwidth, nheight, box.width(), box.height());
this->notify_updated();
}
}
}
void Plteen::IMatter::resize(float nwidth, float nheight, const Port& port) {
if (this->can_resize) {
Box box = this->get_bounding_box();
if (nwidth == 0.0F) {
nwidth = box.width();
}
if (nheight == 0.0F) {
nheight = box.height();
}
if ((box.width() != nwidth) || (box.height() != nheight)) {
this->moor(port);
this->on_resize(nwidth, nheight, box.width(), box.height());
this->notify_updated();
}
}
}
void Plteen::IMatter::notify_updated() {
if (this->info != nullptr) {
if (!this->port.is_zero()) {
Dot dot = this->info->master->get_matter_location(this, this->port);
/** NOTE
* Gliding dramatically increasing the complexity of moving as glidings might be queued,
* the anchored moving here therefore uses relative target position,
* and do the moving immediately.
**/
if (dot != this->port_dot) {
this->info->master->move(this, this->port_dot - dot, true);
}
this->clear_moor();
}
this->info->master->notify_updated(this);
}
}
void Plteen::IMatter::notify_timeline_restart(uint32_t count0, int duration) {
if (this->info != nullptr) {
this->info->master->notify_matter_timeline_restart(this, count0, duration);
}
}
void Plteen::IMatter::moor(const Port& port) {
if (this->port != port) {
if (this->info != nullptr) {
this->port = port;
this->port_dot = this->info->master->get_matter_location(this, port);
}
}
}
void Plteen::IMatter::clear_moor() {
this->port.reset();
}
bool Plteen::IMatter::has_caret() {
bool careted = false;
if (this->info != nullptr) {
careted = (this->info->master->get_focused_matter() == this);
}
return careted;
}
void Plteen::IMatter::show(bool yes_no) {
if (this->invisible == yes_no) {
this->invisible = !yes_no;
this->notify_updated();
}
}
Dot Plteen::IMatter::get_location(const Port& p) {
Dot dot(flnan_f, flnan_f);
if (this->info != nullptr) {
dot = this->info->master->get_matter_location(this, p);
}
return dot;
}
void Plteen::IMatter::log_message(Log level, const std::string& msg) {
if (this->info != nullptr) {
this->info->master->log_message(level, msg);
}
}
const char* Plteen::IMatter::name() {
return typeid(this).name();
}