--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Graphics/MessageView.cc Wed Jan 21 03:33:35 2009 +0200
@@ -0,0 +1,59 @@
+
+#include "Graphics.hh"
+#include "MessageView.hh"
+
+namespace graphics
+{
+
+MessageView::MessageView (const PixelArea &area) :
+ View(area), messages()
+{
+
+}
+
+void MessageView::add_message (CL_Color color, std::string message) {
+ Message msg (color, message);
+
+ messages.push_back(msg);
+}
+
+void MessageView::draw (Display *display) {
+ // get font
+ CL_Font &font = graphics->fonts.getSimpleFont();
+
+ // remember color
+ CL_Color font_color = font.get_color();
+
+ // maximum width
+ CL_Size max_size = CL_Size(area.right - area.left, 0);
+
+ // starting point for drawing
+ PixelDimension offset_prev = area.bottom;
+
+ // render messages, bottom up
+ for (std::vector<Message>::reverse_iterator it = messages.rbegin(); it != messages.rend(); it++) {
+ // set message color
+ font.set_color(it->color);
+
+ // calculate height
+ PixelDimension height = font.get_height(it->message, max_size) + MESSAGE_VIEW_LINE_OFFSET;
+
+ // new draw_point
+ PixelDimension offset_this = offset_prev - height;
+
+ // break if it doesn't fit anymore
+ if (offset_this < area.top)
+ break;
+
+ // draw text
+ font.draw(CL_Rect(area.left, offset_this, area.right, offset_prev), it->message, g->get_gc());
+
+ // advance offset
+ offset_prev = offset_this;
+ }
+
+ // restore font color
+ font.set_color(font_color);
+}
+
+}