boot_credits.cpp

Go to the documentation of this file.
00001 
00002 //            Copyright (C) 2004-2007 by The Allacrost Project
00003 //                         All Rights Reserved
00004 //
00005 // This code is licensed under the GNU GPL version 2. It is free software 
00006 // and you may modify it and/or redistribute it under the terms of this license.
00007 // See http://www.gnu.org/copyleft/gpl.html for details.
00009 
00016 #include "video.h"
00017 #include "script.h"
00018 
00019 #include "boot_credits.h"
00020 
00021 using namespace std;
00022 
00023 using namespace hoa_utils;
00024 using namespace hoa_video;
00025 using namespace hoa_script;
00026 
00027 namespace hoa_boot {
00028 
00029 CreditsScreen::CreditsScreen() :
00030   _visible(false),
00031   _text_offset_y(0.0f),
00032   _credits_rendered(NULL)
00033 {
00034   // Init the background window
00035   _window.Create(1024.0f, 600.0f);
00036   _window.SetPosition(0.0f, 630.0f);
00037   _window.SetDisplayMode(VIDEO_MENU_EXPAND_FROM_CENTER);
00038   _window.Hide();
00039 
00040   // Load the credits from the Lua file
00041   ReadScriptDescriptor credits_file;
00042   if (credits_file.OpenFile("dat/credits.lua") == false) {
00043     cerr << "BOOT ERROR: failed to open the credits file" << endl;
00044     exit(1);
00045   }
00046   _credits_text = credits_file.ReadString("credits_text");
00047   credits_file.CloseFile();
00048 }
00049 
00050 
00051 CreditsScreen::~CreditsScreen()
00052 {
00053   _window.Destroy();
00054   if (_credits_rendered != NULL) {
00055     delete(_credits_rendered);
00056     _credits_rendered = NULL;
00057   }
00058 }
00059 
00060 
00061 // Draws the credits window on the screen if it is set visible
00062 void CreditsScreen::Draw()
00063 {
00064   // Draw the background window
00065   _window.Draw();
00066   if (_window.GetState() != VIDEO_MENU_STATE_SHOWN) // Don't draw any text until the window is ready for drawing
00067     return;
00068 
00069   // Set clip region for the text and draw the visible part of it
00070   VideoManager->Move(512.0f, 450 + _text_offset_y);
00071   VideoManager->SetScissorRect(_window.GetScissorRect());
00072   VideoManager->EnableScissoring(true);
00073   if (_credits_rendered)
00074   {
00075     // Fade in the text by setting new color with alpha value below 1.0f
00076     float color_alpha = _text_offset_y * 0.025f;
00077     if (color_alpha > 1.0f)
00078       color_alpha = 1.0f;
00079     GLfloat modulation[] = {1.0f, 1.0f, 1.0f, color_alpha};
00080     glColor4fv(modulation);
00081     _credits_rendered->Draw();
00082   }
00083   VideoManager->EnableScissoring(false);
00084 }
00085 
00086 
00087 // Updates the credits window
00088 void CreditsScreen::UpdateWindow(int32 frameTime)
00089 {
00090   _window.Update(frameTime);
00091   float delta = static_cast<float>(frameTime) * 0.02f;
00092   _text_offset_y += delta; // Update text offset
00093 }
00094 
00095 
00096 // Shows the credits window
00097 void CreditsScreen::Show()
00098 {
00099   _window.Show();
00100   _visible = true;
00101   _text_offset_y = 0.0f; // Reset the text offset
00102   VideoManager->SetFont("default"); // Reset font
00103   VideoManager->SetTextColor(Color::white); // Reset text color
00104 
00105   if (!_credits_rendered) {
00106     _credits_rendered = VideoManager->RenderText(MakeUnicodeString(_credits_text));
00107     if (!_credits_rendered) {
00108       cerr << "BOOT ERROR: failed to render the credits string.\n" << endl;
00109       exit(1);
00110     }
00111   }
00112 }
00113 
00114 
00115 // Hides the credits window
00116 void CreditsScreen::Hide()
00117 {
00118   _window.Hide();
00119   _visible = false;
00120   glColor4fv(&Color::white[0]);
00121   if (_credits_rendered) {
00122     delete(_credits_rendered);
00123     _credits_rendered = NULL;
00124   }
00125 }
00126 
00127 
00128 // Returns true if the credits window is set visible at the moment
00129 bool CreditsScreen::IsVisible()
00130 {
00131   return _visible;
00132 }
00133 
00134 
00135 } // end hoa_boot

Generated on Fri Jul 6 23:11:11 2007 for Hero of Allacrost by  doxygen 1.5.1