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
|
#include <SDL.h>
#include <Input.h>
#include "font.h"
#include "widgets.h"
#include "engine.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gettext.h"
mogltk::widget * mogltk::widget::focused = 0;
mogltk::widget::widget(widget * _father, int _x, int _y, int _sx, int _sy, int _type, String _name, mogltk::shape * _sh) :
x(_x), y(_y), sx(_sx), sy(_sy), father(_father), type(_type), name(_name), sh(_sh) {
if (!father) {
root = this;
father = this;
next = 0;
x = 0;
y = 0;
sx = engine::base_o->GetWidth();
sy = engine::base_o->GetHeight();
} else {
next = father->child;
if (next)
next->prev = this;
father->child = this;
root = father->root;
}
prev = 0;
child = 0;
computeabs();
}
mogltk::widget::~widget() {
while(child)
delete child;
if (prev)
prev->next = next;
else
father->child = next;
if (next)
next->prev = prev;
}
void mogltk::widget::computeabs() {
if (father != this) {
ax = father->ax + x;
ay = father->ay + y;
} else {
ax = x;
ay = y;
}
ax2 = ax + sx;
ay2 = ay + sy;
}
void mogltk::widget::move(int nx, int ny) {
x = nx;
y = ny;
computeabs();
}
void mogltk::widget::resize(int nsx, int nsy) {
sx = nsx;
sy = nsy;
ax2 = ax + sx;
ay2 = ay + sy;
}
int mogltk::widget::GetX() {
return x;
}
int mogltk::widget::GetY() {
return y;
}
int mogltk::widget::GetH() {
return sx;
}
int mogltk::widget::GetW() {
return sy;
}
int mogltk::widget::GetAX() {
return ax;
}
int mogltk::widget::GetAY() {
return ay;
}
int mogltk::widget::GetAX2() {
return ax2;
}
int mogltk::widget::GetAY2() {
return ay2;
}
mogltk::shape * mogltk::widget::Shaper() {
return sh;
}
void mogltk::widget::fulldraw() {
bool was2D;
if (!(was2D = mogltk::engine::glbase_o->is2D()))
mogltk::engine::glbase_o->Enter2DMode();
texture::Unbind();
mogltk::ColorP::Max = WHITE;
mogltk::ColorP::Min = BLACK;
mogltk::ColorP::Min.A = 0;
root->idraw();
if (!was2D)
mogltk::engine::glbase_o->Leave2DMode();
}
void mogltk::widget::idraw() {
int x1, y1, x2, y2;
if (next)
next->idraw();
x1 = MAX(GetAX(), father->GetAX());
y1 = MAX(GetAY(), father->GetAY());
x2 = MIN(GetAX2(), father->GetAX2());
y2 = MIN(GetAY2(), father->GetAY2());
engine::base_o->changeviewport(x1, y1, x2 - x1, y2 - y1);
draw();
if (child)
child->idraw();
}
/*
* Predefined widgets.
*/
/* Here is Root */
mogltk::Root::Root(mogltk::shape * sh, mogltk::drawer * _dr) : widget(0, 0, 0, 0, 0, 0, "Root", sh), dr(_dr) {
if (engine::root)
delete engine::root;
engine::root = this;
}
void mogltk::Root::draw() {
if (dr)
dr->draw(this);
else
Shaper()->box(GetAX(), GetAY(), GetAX2(), GetAY2());
}
void mogltk::Root::setdrawer(drawer * _dr) {
dr = _dr;
}
|