-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathcursorfield.cc
More file actions
66 lines (53 loc) · 1.71 KB
/
Copy pathcursorfield.cc
File metadata and controls
66 lines (53 loc) · 1.71 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
#include "cursorfield.hh"
#include "ui.hh"
#include "world.hh"
cursorfield::cursorfield()
{
this->set_flag(ENTITY_HAS_CONFIG, true);
this->dialog_id = DIALOG_CURSORFIELD;
this->scaleselect = true;
this->scalemodifier = 6.5f;
this->set_num_properties(4);
this->properties[0].type = P_FLT;
this->properties[0].v.f = .5f;
this->properties[1].type = P_FLT;
this->properties[1].v.f = .5f;
this->properties[2].type = P_FLT;
this->properties[2].v.f = -.5f;
this->properties[3].type = P_FLT;
this->properties[3].v.f = -.5f;
}
void
cursorfield::init()
{
this->pressed = 0;
this->hover = 0;
this->dragged = 0;
if (this->get_body(0)) {
b2Body *b = this->get_body(0);
b2PolygonShape sh;
b2Vec2 vertices[4] = {
this->local_to_body(b2Vec2(this->properties[0].v.f, this->properties[1].v.f), 0),
this->local_to_body(b2Vec2(this->properties[2].v.f, this->properties[1].v.f), 0),
this->local_to_body(b2Vec2(this->properties[2].v.f, this->properties[3].v.f), 0),
this->local_to_body(b2Vec2(this->properties[0].v.f, this->properties[3].v.f), 0)
};
sh.Set(vertices, 4);
b2FixtureDef fd;
fd.isSensor = true;
fd.shape = &sh;
fd.density = 0.00000001f;
fd.friction = FLT_EPSILON;
fd.restitution = 0.f;
fd.filter = world::get_filter_for_layer(this->get_layer(), 15);
b->CreateFixture(&fd)->SetUserData(this);
}
}
edevice*
cursorfield::solve_electronics(void)
{
this->s_out[0].write(this->pressed >0 ? 1.f : 0.f);
this->s_out[1].write(this->dragged >0 ? 1.f : 0.f);
this->s_out[2].write(this->hover >0 ? 1.f : 0.f);
return 0;
}