7 |
class Window { |
class Window { |
8 |
public: |
public: |
9 |
Window() {} |
Window() {} |
10 |
Window (const ScreenArea &area) : m_area(area) |
Window (const ScreenArea &area) : m_area(area) |
11 |
{} |
{} |
12 |
|
|
13 |
const ScreenArea &get_area() const { return m_area; } |
const ScreenArea &get_area() const { return m_area; } |
40 |
px::Font &font; |
px::Font &font; |
41 |
double time, maxtime; |
double time, maxtime; |
42 |
}; |
}; |
43 |
|
|
44 |
class StatusBarImpl : public StatusBar, public Window { |
class StatusBarImpl : public StatusBar, public Window { |
45 |
public: |
public: |
46 |
StatusBarImpl (const ScreenArea &area); |
StatusBarImpl (const ScreenArea &area); |
57 |
void set_inventory (Inventory *inv); |
void set_inventory (Inventory *inv); |
58 |
void update_inventory (Inventory *inv); |
void update_inventory (Inventory *inv); |
59 |
|
|
60 |
void show_text (const std::string &str, |
void show_text (const std::string &str, |
61 |
TextMode m=TEXT_SCROLLING); |
TextMode m=TEXT_SCROLLING); |
62 |
void hide_text() { m_textview.deactivate(); } |
void hide_text() { m_textview.deactivate(); } |
63 |
private: |
private: |
73 |
}; |
}; |
74 |
} |
} |
75 |
|
|
76 |
StatusBarImpl::StatusBarImpl (const ScreenArea &area) |
StatusBarImpl::StatusBarImpl (const ScreenArea &area) |
77 |
: Window(area), |
: Window(area), |
78 |
m_itemarea (area.x+142, area.y+area.h-64+5, area.w-147, 64-10), |
m_itemarea (area.x+142, area.y+area.h-64+5, area.w-147, 64-10), |
79 |
m_textarea (area.x+147, area.y+area.h-64+20, area.w-157, 32), |
m_textarea (area.x+147, area.y+area.h-64+20, area.w-157, 32), |
80 |
m_models(), |
m_models(), |
88 |
StatusBarImpl::~StatusBarImpl() |
StatusBarImpl::~StatusBarImpl() |
89 |
{} |
{} |
90 |
|
|
91 |
void |
void |
92 |
StatusBarImpl::redraw (px::GC &gc, const ScreenArea &r) |
StatusBarImpl::redraw (px::GC &gc, const ScreenArea &r) |
93 |
{ |
{ |
94 |
ScreenArea a = get_area(); |
ScreenArea a = get_area(); |
115 |
if (m_textview.is_active()) { |
if (m_textview.is_active()) { |
116 |
m_textview.draw (gc, r); |
m_textview.draw (gc, r); |
117 |
} |
} |
118 |
else |
else |
119 |
{ |
{ |
120 |
for (unsigned i=0; i<m_models.size(); ++i) |
for (unsigned i=0; i<m_models.size(); ++i) |
121 |
{ |
{ |
126 |
m_changedp = false; |
m_changedp = false; |
127 |
} |
} |
128 |
|
|
129 |
void |
void |
130 |
StatusBarImpl::set_inventory (Inventory *inv) |
StatusBarImpl::set_inventory (Inventory *inv) |
131 |
{ |
{ |
132 |
m_inventory = inv; |
m_inventory = inv; |
133 |
update_inventory (inv); |
update_inventory (inv); |
134 |
} |
} |
135 |
|
|
136 |
void |
void |
137 |
StatusBarImpl::update_inventory (Inventory *inv) |
StatusBarImpl::update_inventory (Inventory *inv) |
138 |
{ |
{ |
139 |
if (inv && inv == m_inventory) |
if (inv && inv == m_inventory) |
148 |
m_changedp = true; |
m_changedp = true; |
149 |
} |
} |
150 |
} |
} |
151 |
|
|
152 |
void |
void |
153 |
StatusBarImpl::show_text (const std::string &str, TextMode m) |
StatusBarImpl::show_text (const std::string &str, TextMode m) |
154 |
{ |
{ |
155 |
m_textview.set_text (str, m); |
m_textview.set_text (str, m); |
156 |
} |
} |
157 |
|
|
158 |
void |
void |
159 |
StatusBarImpl::tick (double dtime) |
StatusBarImpl::tick (double dtime) |
160 |
{ |
{ |
161 |
// Update text display |
// Update text display |
162 |
if (m_textview.is_active()) |
if (m_textview.is_active()) |
163 |
{ |
{ |
164 |
m_textview.tick (dtime); |
m_textview.tick (dtime); |
165 |
m_changedp = m_textview.has_changed(); |
m_changedp = m_textview.has_changed(); |
171 |
m_changedp = true; // update clock |
m_changedp = true; // update clock |
172 |
} |
} |
173 |
|
|
174 |
void |
void |
175 |
StatusBarImpl::new_world() |
StatusBarImpl::new_world() |
176 |
{ |
{ |
177 |
m_leveltime = 0; |
m_leveltime = 0; |
178 |
|
|
186 |
//---------------------------------------- |
//---------------------------------------- |
187 |
// TextDisplay |
// TextDisplay |
188 |
//---------------------------------------- |
//---------------------------------------- |
189 |
TextDisplay::TextDisplay(ScreenArea a, Font &f) |
TextDisplay::TextDisplay(ScreenArea a, Font &f) |
190 |
: text(), active(false), changedp(false), |
: text(), active(false), changedp(false), |
191 |
mode(TEXT_SCROLLING), |
mode(TEXT_SCROLLING), |
192 |
area(a), xoff(0), scrollspeed(200), |
area(a), xoff(0), scrollspeed(200), |
193 |
textsurface(0), font(f) |
textsurface(0), font(f) |
195 |
time = maxtime = 0; |
time = maxtime = 0; |
196 |
} |
} |
197 |
|
|
198 |
void |
void |
199 |
TextDisplay::set_text(const string &t, TextMode m) |
TextDisplay::set_text(const string &t, TextMode m) |
200 |
{ |
{ |
201 |
text = t; |
text = t; |
202 |
mode = m; |
mode = m; |
203 |
textsurface.reset(font.render(text.c_str())); |
textsurface.reset(font.render(text.c_str())); |
204 |
|
|
205 |
time = 0; |
time = 0; |
206 |
maxtime = 1e20; // this should be close to ``indefinitely'' |
|
207 |
switch (mode) { |
switch (mode) { |
208 |
case TEXT_SCROLLING: |
case TEXT_2SECONDS: maxtime = 2.0; break; |
209 |
|
case TEXT_5SECONDS: maxtime = 5.0; break; |
210 |
|
default : maxtime = 1e20; break; // this should be close to ``indefinitely'' |
211 |
|
} |
212 |
|
|
213 |
|
if (mode == TEXT_SCROLLING) { |
214 |
xoff = -area.w; |
xoff = -area.w; |
215 |
break; |
} |
216 |
case TEXT_2SECONDS: |
else { // all other modes are centered |
|
maxtime = 2.0; // 2 seconds |
|
|
// fall through |
|
|
case TEXT_STATIC: |
|
217 |
xoff = -(area.w - textsurface->width())/2; |
xoff = -(area.w - textsurface->width())/2; |
|
break; |
|
218 |
} |
} |
219 |
|
|
220 |
|
// switch (m) { |
221 |
|
|
222 |
|
// } |
223 |
|
|
224 |
|
// switch (mode) { |
225 |
|
// case TEXT_SCROLLING: |
226 |
|
// xoff = -area.w; |
227 |
|
// break; |
228 |
|
// case TEXT_2SECONDS: |
229 |
|
// maxtime = 2.0; // 2 seconds |
230 |
|
// // fall through |
231 |
|
// case TEXT_STATIC: |
232 |
|
// xoff = -(area.w - textsurface->width())/2; |
233 |
|
// break; |
234 |
|
// } |
235 |
changedp = active = true; |
changedp = active = true; |
236 |
} |
} |
237 |
|
|
238 |
void |
void |
239 |
TextDisplay::tick(double dtime) |
TextDisplay::tick(double dtime) |
240 |
{ |
{ |
241 |
time += dtime; |
time += dtime; |
242 |
if (time > maxtime) { |
if (time > maxtime) { |
243 |
active = false; |
active = false; |
244 |
changedp = true; |
changedp = true; |
245 |
} |
} |
246 |
else { |
else { |
247 |
int oldxoff = int(xoff); |
int oldxoff = int(xoff); |
248 |
if (mode == TEXT_SCROLLING) { |
if (mode == TEXT_SCROLLING) { |
256 |
} |
} |
257 |
} |
} |
258 |
|
|
259 |
void |
void |
260 |
TextDisplay::draw(px::GC &gc, const ScreenArea &r) |
TextDisplay::draw(px::GC &gc, const ScreenArea &r) |
261 |
{ |
{ |
262 |
if (active) { |
if (active) { |
263 |
clip(gc, intersect(area, r)); |
clip(gc, intersect(area, r)); |