equal
deleted
inserted
replaced
|
1 |
|
2 #include "Graphics.hh" |
|
3 #include "MessageView.hh" |
|
4 |
|
5 namespace graphics |
|
6 { |
|
7 |
|
8 MessageView::MessageView (const PixelArea &area) : |
|
9 View(area), messages() |
|
10 { |
|
11 |
|
12 } |
|
13 |
|
14 void MessageView::add_message (CL_Color color, std::string message) { |
|
15 Message msg (color, message); |
|
16 |
|
17 messages.push_back(msg); |
|
18 } |
|
19 |
|
20 void MessageView::draw (Display *display) { |
|
21 // get font |
|
22 CL_Font &font = graphics->fonts.getSimpleFont(); |
|
23 |
|
24 // remember color |
|
25 CL_Color font_color = font.get_color(); |
|
26 |
|
27 // maximum width |
|
28 CL_Size max_size = CL_Size(area.right - area.left, 0); |
|
29 |
|
30 // starting point for drawing |
|
31 PixelDimension offset_prev = area.bottom; |
|
32 |
|
33 // render messages, bottom up |
|
34 for (std::vector<Message>::reverse_iterator it = messages.rbegin(); it != messages.rend(); it++) { |
|
35 // set message color |
|
36 font.set_color(it->color); |
|
37 |
|
38 // calculate height |
|
39 PixelDimension height = font.get_height(it->message, max_size) + MESSAGE_VIEW_LINE_OFFSET; |
|
40 |
|
41 // new draw_point |
|
42 PixelDimension offset_this = offset_prev - height; |
|
43 |
|
44 // break if it doesn't fit anymore |
|
45 if (offset_this < area.top) |
|
46 break; |
|
47 |
|
48 // draw text |
|
49 font.draw(CL_Rect(area.left, offset_this, area.right, offset_prev), it->message, g->get_gc()); |
|
50 |
|
51 // advance offset |
|
52 offset_prev = offset_this; |
|
53 } |
|
54 |
|
55 // restore font color |
|
56 font.set_color(font_color); |
|
57 } |
|
58 |
|
59 } |