pause.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 "utils.h"
00017 #include <iostream>
00018 #include "pause.h"
00019 #include "audio.h"
00020 #include "video.h"
00021 #include "input.h"
00022 #include "system.h"
00023 
00024 using namespace std;
00025 using namespace hoa_audio;
00026 using namespace hoa_video;
00027 using namespace hoa_mode_manager;
00028 using namespace hoa_input;
00029 using namespace hoa_system;
00030 
00031 namespace hoa_pause {
00032 
00033 bool PAUSE_DEBUG = false;
00034 
00035 // Constructor changes audio, saves currently rendered screen, and draws "Paused" text
00036 PauseMode::PauseMode() {
00037   if (PAUSE_DEBUG) cout << "PAUSE: PauseMode constructor invoked" << endl;
00038 
00039   mode_type = MODE_MANAGER_PAUSE_MODE;
00040   // Adjust the volume while in paused mode acordingly
00041 //  switch (SystemManager->GetPauseVolumeAction()) {
00042 //    case SETTINGS_PAUSE_AUDIO:
00043 //      AudioManager->PauseAudio();
00044 //      break;
00045 //    case SETTINGS_ZERO_VOLUME:
00046 //      AudioManager->SetMusicVolume(0);
00047 //      AudioManager->SetSoundVolume(0);
00048 //      break;
00049 //    case SETTINGS_HALF_VOLUME:
00050 // //       AudioManager->SetMusicVolume(static_cast<int32>(SystemManager->music_vol * 0.5));
00051 // //       AudioManager->SetSoundVolume(static_cast<int32>(SystemManager->sound_vol * 0.5));
00052 //      break;
00053 //    // Don't need to do anything for the case SETTINGS_SAME_VOLUME
00054 //  }
00055 
00056   // Save a copy of the current screen to use as a backdrop
00057   if (!VideoManager->CaptureScreen(_saved_screen)) 
00058     if (PAUSE_DEBUG) cerr << "PAUSE: ERROR: Couldn't save the screen!" << endl;
00059 }
00060 
00061 
00062 
00063 // The destructor might possibly have to free the "Paused" image...
00064 PauseMode::~PauseMode() {
00065   if (PAUSE_DEBUG) cout << "PAUSE: PauseMode destructor invoked" << endl;
00066 
00067 //  // Restore the game audio/volume levels appropriately
00068 //  switch (SystemManager->GetPauseVolumeAction()) {
00069 //    case SETTINGS_PAUSE_AUDIO:
00070 //      AudioManager->ResumeAudio();
00071 //      break;
00072 //    case SETTINGS_ZERO_VOLUME:
00073 //    case SETTINGS_HALF_VOLUME:
00074 // //       AudioManager->SetMusicVolume(SystemManager->music_vol);
00075 // //       AudioManager->SetSoundVolume(SystemManager->sound_vol);
00076 //      break;
00077 //    default: // Don't need to do anything for case SETTINGS_SAME_VOLUME
00078 //      break;
00079 //    
00080 //  }
00081 
00082   // Release the saved screen frame.
00083   VideoManager->DeleteImage(_saved_screen);
00084 }
00085 
00086 
00087 // Called whenever PauseMode is put on top of the stack
00088 void PauseMode::Reset() {
00089   // Setup video engine constructs.
00090   VideoManager->SetCoordSys(0, 1024, 0, 768);
00091   if(!VideoManager->SetFont("default")) 
00092     cerr << "MAP: ERROR > Couldn't set map font!" << endl;
00093   VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, 0);
00094 }
00095 
00096 
00097 // The true logic is all handled in GameSystem::KeyEventHandler() instead of this function.
00098 void PauseMode::Update() { 
00099   // Don't eat up 100% of the CPU time when we're in pause mode
00100   SDL_Delay(50);
00101 }
00102 
00103 
00104 
00105 // Nothing to draw since the screen never changes in pause mode (maybe we should call SDL_Delay here?)
00106 void PauseMode::Draw() {
00107   // Draw the background image
00108   // For that, set the system coordinates to the size of the window (same with the save-screen)
00109   int32 width = VideoManager->GetWidth();
00110   int32 height = VideoManager->GetHeight();
00111   VideoManager->SetCoordSys (0.0f, static_cast<float>(width), 0.0f, static_cast<float>(height));
00112 
00113   Color grayed(0.35f, 0.35f, 0.35f, 1.0f);
00114   VideoManager->SetDrawFlags(VIDEO_X_LEFT, 0);
00115   VideoManager->Move(0,0);
00116   VideoManager->DrawImage(_saved_screen, grayed);
00117   
00118   // Render the "Paused" text to appear on the center of the screen
00119   // Restore the Coordinate system (that one is quit mode coodinate system)
00120   VideoManager->SetCoordSys (0.0f, 1024.0f, 0.0f, 768.0f);
00121 
00122   VideoManager->SetDrawFlags(VIDEO_X_CENTER, 0);
00123   VideoManager->Move(512, 384);
00124   VideoManager->DrawText("Paused");
00125 }
00126 
00127 } // namespace hoa_pause

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