#include <textscroller.hpp>
Inherits Screen.
Public Member Functions | |
TextScroller (const std::string &file) | |
virtual | ~TextScroller () |
void | setup () |
gets called before this screen gets activated (which is at least once before the first draw or update call | |
void | draw (DrawingContext &context) |
gets called once per frame. | |
void | update (float elapsed_time) |
gets called for once (per logical) frame. | |
Static Public Attributes | |
static Color | small_color |
static Color | heading_color |
static Color | reference_color |
static Color | normal_color |
Private Member Functions | |
TextScroller (const TextScroller &) | |
TextScroller & | operator= (const TextScroller &) |
Private Attributes | |
float | defaultspeed |
float | speed |
std::string | music |
SurfacePtr | background |
std::vector< InfoBoxLine * > | lines |
float | scroll |
bool | fading |
Definition at line 34 of file textscroller.hpp.
TextScroller::TextScroller | ( | const std::string & | file | ) |
Definition at line 37 of file textscroller.cpp.
References background, Surface::create(), DEFAULT_SPEED, defaultspeed, fading, lisp::Lisp::get(), lisp::Lisp::get_lisp(), LEFT_BORDER, lines, music, lisp::Parser::parse(), SCREEN_WIDTH, scroll, speed, and InfoBoxLine::split().
00037 : 00038 defaultspeed(), 00039 speed(), 00040 music(), 00041 background(), 00042 lines(), 00043 scroll(), 00044 fading() 00045 { 00046 defaultspeed = DEFAULT_SPEED; 00047 speed = defaultspeed; 00048 00049 std::string text; 00050 std::string background_file; 00051 00052 lisp::Parser parser; 00053 try { 00054 const lisp::Lisp* root = parser.parse(filename); 00055 00056 const lisp::Lisp* text_lisp = root->get_lisp("supertux-text"); 00057 if(!text_lisp) 00058 throw std::runtime_error("File isn't a supertux-text file"); 00059 00060 if(!text_lisp->get("text", text)) 00061 throw std::runtime_error("file doesn't contain a text field"); 00062 if(!text_lisp->get("background", background_file)) 00063 throw std::runtime_error("file doesn't contain a background file"); 00064 text_lisp->get("speed", defaultspeed); 00065 text_lisp->get("music", music); 00066 } catch(std::exception& e) { 00067 std::ostringstream msg; 00068 msg << "Couldn't load file '" << filename << "': " << e.what() << std::endl; 00069 throw std::runtime_error(msg.str()); 00070 } 00071 00072 // Split text string lines into a vector 00073 lines = InfoBoxLine::split(text, SCREEN_WIDTH - 2*LEFT_BORDER); 00074 00075 // load background image 00076 background = Surface::create("images/background/" + background_file); 00077 00078 scroll = 0; 00079 fading = false; 00080 }
TextScroller::~TextScroller | ( | ) | [virtual] |
Definition at line 82 of file textscroller.cpp.
References lines.
00083 { 00084 for(std::vector<InfoBoxLine*>::iterator i = lines.begin(); i != lines.end(); i++) delete *i; 00085 }
TextScroller::TextScroller | ( | const TextScroller & | ) | [private] |
void TextScroller::setup | ( | ) | [virtual] |
gets called before this screen gets activated (which is at least once before the first draw or update call
Reimplemented from Screen.
Definition at line 88 of file textscroller.cpp.
References music, SoundManager::play_music(), and sound_manager.
00089 { 00090 sound_manager->play_music(music); 00091 }
void TextScroller::draw | ( | DrawingContext & | context | ) | [virtual] |
gets called once per frame.
The screen should draw itself in this function. State changes should not be done in this function, but rather in update
Implements Screen.
Definition at line 119 of file textscroller.cpp.
References background, DrawingContext::draw_filled_rect(), DrawingContext::draw_surface(), ScreenManager::exit_screen(), fading, g_screen_manager, LAYER_GUI, LEFT_BORDER, lines, SCREEN_HEIGHT, SCREEN_WIDTH, and scroll.
00120 { 00121 context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), 00122 Color(0.6f, 0.7f, 0.8f, 0.5f), 0); 00123 context.draw_surface(background, Vector(SCREEN_WIDTH/2 - background->get_width()/2 , SCREEN_HEIGHT/2 - background->get_height()/2), 0); 00124 00125 float y = SCREEN_HEIGHT - scroll; 00126 for(size_t i = 0; i < lines.size(); i++) { 00127 if (y + lines[i]->get_height() >= 0 && SCREEN_HEIGHT - y >= 0) { 00128 lines[i]->draw(context, Rectf(LEFT_BORDER, y, SCREEN_WIDTH - 2*LEFT_BORDER, y), LAYER_GUI); 00129 } 00130 00131 y += lines[i]->get_height(); 00132 } 00133 00134 if(y < 0 && !fading ) { 00135 fading = true; 00136 g_screen_manager->exit_screen(new FadeOut(0.5)); 00137 } 00138 }
void TextScroller::update | ( | float | elapsed_time | ) | [virtual] |
gets called for once (per logical) frame.
Screens should do their state updates and logic here
Implements Screen.
Definition at line 94 of file textscroller.cpp.
References Controller::ACTION, defaultspeed, Controller::DOWN, ScreenManager::exit_screen(), g_jk_controller, g_screen_manager, JoystickKeyboardController::get_main_controller(), Controller::hold(), Controller::JUMP, Controller::MENU_SELECT, Controller::PAUSE_MENU, Controller::pressed(), SCROLL, scroll, speed, and Controller::UP.
00095 { 00096 Controller *controller = g_jk_controller->get_main_controller(); 00097 if(controller->hold(Controller::UP)) { 00098 speed = -defaultspeed*5; 00099 } else if(controller->hold(Controller::DOWN)) { 00100 speed = defaultspeed*5; 00101 } else { 00102 speed = defaultspeed; 00103 } 00104 if(controller->pressed(Controller::JUMP) 00105 || controller->pressed(Controller::ACTION) 00106 || controller->pressed(Controller::MENU_SELECT)) 00107 scroll += SCROLL; 00108 if(controller->pressed(Controller::PAUSE_MENU)) { 00109 g_screen_manager->exit_screen(new FadeOut(0.5)); 00110 } 00111 00112 scroll += speed * elapsed_time; 00113 00114 if(scroll < 0) 00115 scroll = 0; 00116 }
TextScroller& TextScroller::operator= | ( | const TextScroller & | ) | [private] |
Color TextScroller::small_color [static] |
Color TextScroller::heading_color [static] |
Color TextScroller::reference_color [static] |
Color TextScroller::normal_color [static] |
float TextScroller::defaultspeed [private] |
float TextScroller::speed [private] |
std::string TextScroller::music [private] |
SurfacePtr TextScroller::background [private] |
std::vector<InfoBoxLine*> TextScroller::lines [private] |
Definition at line 54 of file textscroller.hpp.
Referenced by draw(), TextScroller(), and ~TextScroller().
float TextScroller::scroll [private] |
bool TextScroller::fading [private] |