InfoBox Class Reference

This class is displaying a box with information text inside the game. More...

#include <info_box.hpp>

List of all members.

Public Member Functions

 InfoBox (const std::string &text)
 ~InfoBox ()
void draw (DrawingContext &context)
void scrolldown ()
void scrollup ()
void pagedown ()
void pageup ()

Private Member Functions

 InfoBox (const InfoBox &)
InfoBoxoperator= (const InfoBox &)

Private Attributes

size_t firstline
std::vector< InfoBoxLine * > lines
std::map< std::string, Surface * > images
SurfacePtr arrow_scrollup
SurfacePtr arrow_scrolldown


Detailed Description

This class is displaying a box with information text inside the game.

Definition at line 31 of file info_box.hpp.


Constructor & Destructor Documentation

InfoBox::InfoBox ( const std::string &  text  ) 

Definition at line 25 of file info_box.cpp.

References arrow_scrolldown, arrow_scrollup, Surface::create(), lines, log_warning, and InfoBoxLine::split().

00025                                       :
00026   firstline(0),
00027   lines(),
00028   images(),
00029   arrow_scrollup(),
00030   arrow_scrolldown()
00031 {
00032   // Split text string lines into a vector
00033   lines = InfoBoxLine::split(text, 400);
00034 
00035   try
00036   {
00037     // get the arrow sprites
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 }

InfoBox::~InfoBox (  ) 

Definition at line 49 of file info_box.cpp.

References lines.

00050 {
00051   for(std::vector<InfoBoxLine*>::iterator i = lines.begin();
00052       i != lines.end(); i++)
00053     delete *i;
00054 }

InfoBox::InfoBox ( const InfoBox  )  [private]


Member Function Documentation

void InfoBox::draw ( DrawingContext context  ) 

Definition at line 57 of file info_box.cpp.

References arrow_scrolldown, arrow_scrollup, DrawingContext::draw_filled_rect(), DrawingContext::draw_surface(), firstline, LAYER_GUI, lines, SCREEN_HEIGHT, and SCREEN_WIDTH.

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     // draw the scrolling arrows
00081     if (arrow_scrollup.get() && firstline > 0)
00082       context.draw_surface(arrow_scrollup,
00083                            Vector( x1 + width  - arrow_scrollup->get_width(),  // top-right corner of box
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(),  // bottom-light corner of box
00089                                    y1 + height - arrow_scrolldown->get_height()),
00090                            LAYER_GUI);
00091   }
00092 }

void InfoBox::scrolldown (  ) 

Definition at line 102 of file info_box.cpp.

References firstline, and lines.

00103 {
00104   if(firstline < lines.size()-1)
00105     firstline++;
00106 }

void InfoBox::scrollup (  ) 

Definition at line 95 of file info_box.cpp.

References firstline.

00096 {
00097   if(firstline > 0)
00098     firstline--;
00099 }

void InfoBox::pagedown (  ) 

Definition at line 114 of file info_box.cpp.

00115 {
00116 }

void InfoBox::pageup (  ) 

Definition at line 109 of file info_box.cpp.

00110 {
00111 }

InfoBox& InfoBox::operator= ( const InfoBox  )  [private]


Member Data Documentation

size_t InfoBox::firstline [private]

Definition at line 44 of file info_box.hpp.

Referenced by draw(), scrolldown(), and scrollup().

std::vector<InfoBoxLine*> InfoBox::lines [private]

Definition at line 45 of file info_box.hpp.

Referenced by draw(), InfoBox(), scrolldown(), and ~InfoBox().

std::map<std::string, Surface*> InfoBox::images [private]

Definition at line 46 of file info_box.hpp.

SurfacePtr InfoBox::arrow_scrollup [private]

Definition at line 47 of file info_box.hpp.

Referenced by draw(), and InfoBox().

SurfacePtr InfoBox::arrow_scrolldown [private]

Definition at line 48 of file info_box.hpp.

Referenced by draw(), and InfoBox().


The documentation for this class was generated from the following files:
Generated on Mon Apr 14 03:38:36 2014 for SuperTux by  doxygen 1.5.1