00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "supertux/info_box.hpp"
00018
00019 #include "supertux/globals.hpp"
00020 #include "supertux/info_box_line.hpp"
00021 #include "util/log.hpp"
00022 #include "video/drawing_context.hpp"
00023 #include "video/surface.hpp"
00024
00025 InfoBox::InfoBox(const std::string& text) :
00026 firstline(0),
00027 lines(),
00028 images(),
00029 arrow_scrollup(),
00030 arrow_scrolldown()
00031 {
00032
00033 lines = InfoBoxLine::split(text, 400);
00034
00035 try
00036 {
00037
00038 arrow_scrollup = Surface::create("images/engine/menu/scroll-up.png");
00039 arrow_scrolldown = Surface::create("images/engine/menu/scroll-down.png");
00040 }
00041 catch (std::exception& e)
00042 {
00043 log_warning << "Could not load scrolling images: " << e.what() << std::endl;
00044 arrow_scrollup.reset();
00045 arrow_scrolldown.reset();
00046 }
00047 }
00048
00049 InfoBox::~InfoBox()
00050 {
00051 for(std::vector<InfoBoxLine*>::iterator i = lines.begin();
00052 i != lines.end(); i++)
00053 delete *i;
00054 }
00055
00056 void
00057 InfoBox::draw(DrawingContext& context)
00058 {
00059 float x1 = SCREEN_WIDTH/2-200;
00060 float y1 = SCREEN_HEIGHT/2-200;
00061 float width = 400;
00062 float height = 200;
00063
00064 context.draw_filled_rect(Vector(x1, y1), Vector(width, height),
00065 Color(0.6f, 0.7f, 0.8f, 0.5f), LAYER_GUI-1);
00066
00067 float y = y1;
00068 bool linesLeft = false;
00069 for(size_t i = firstline; i < lines.size(); ++i) {
00070 if(y >= y1 + height) {
00071 linesLeft = true;
00072 break;
00073 }
00074
00075 lines[i]->draw(context, Rectf(x1, y, x1+width, y), LAYER_GUI);
00076 y += lines[i]->get_height();
00077 }
00078
00079 {
00080
00081 if (arrow_scrollup.get() && firstline > 0)
00082 context.draw_surface(arrow_scrollup,
00083 Vector( x1 + width - arrow_scrollup->get_width(),
00084 y1), LAYER_GUI);
00085
00086 if (arrow_scrolldown.get() && linesLeft && firstline < lines.size()-1)
00087 context.draw_surface(arrow_scrolldown,
00088 Vector( x1 + width - arrow_scrolldown->get_width(),
00089 y1 + height - arrow_scrolldown->get_height()),
00090 LAYER_GUI);
00091 }
00092 }
00093
00094 void
00095 InfoBox::scrollup()
00096 {
00097 if(firstline > 0)
00098 firstline--;
00099 }
00100
00101 void
00102 InfoBox::scrolldown()
00103 {
00104 if(firstline < lines.size()-1)
00105 firstline++;
00106 }
00107
00108 void
00109 InfoBox::pageup()
00110 {
00111 }
00112
00113 void
00114 InfoBox::pagedown()
00115 {
00116 }
00117
00118