Video Class Reference

#include <video.h>

Collaboration diagram for Video:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void SetWindowCaption (std::string caption)
void SetMaxFps (uint max_fps)
uint GetMaxFps ()
uint GetSleepMaxFps ()
 Video ()
 ~Video ()
bool IsFullScreen () const
std::list< Point2i > & GetAvailableConfigs ()
bool SetConfig (int width, int height, bool fullscreen)
void ToggleFullscreen ()
void InitWindow (void)
void Flip (void)

Public Attributes

Surface window

Private Member Functions

void ComputeAvailableConfigs ()
void SetWindowIcon (std::string icon)
void InitSDL (void)

Private Attributes

uint m_max_fps
uint m_sleep_max_fps
bool SDLReady
bool fullscreen
std::list< Point2iavailable_configs

Detailed Description

Definition at line 29 of file video.h.


Constructor & Destructor Documentation

Video::Video (  ) 

Definition at line 32 of file video.cpp.

00032             {
00033   SetMaxFps (50);
00034   fullscreen = false;
00035   SDLReady = false;
00036 }

Here is the call graph for this function:

Video::~Video (  ) 

Definition at line 38 of file video.cpp.

00038              {
00039   if( SDLReady )
00040     SDL_Quit();
00041 }


Member Function Documentation

void Video::ComputeAvailableConfigs (  )  [private]

Definition at line 68 of file video.cpp.

00069 {
00070   // Add the current resolution
00071   available_configs.push_back(Point2i(AppWormux::GetInstance()->video.window.GetWidth(),
00072                                       AppWormux::GetInstance()->video.window.GetHeight()));
00073 
00074   //Generate video mode list
00075   SDL_Rect **modes;
00076 
00077   // Get available fullscreen/hardware modes
00078   modes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
00079 
00080   // Check is there are any modes available
00081   if(modes != NULL){
00082     // We also had the current window resolution if it is not already in the list!
00083     for(int i=0;modes[i];++i) {
00084       // We accept only modes that are bigger than 800x600
00085       if (modes[i]->w < 800 || modes[i]->h < 600) break;
00086       available_configs.push_back(Point2i(modes[i]->w, modes[i]->h));
00087     }
00088   }
00089 
00090   // Sort the list
00091   available_configs.sort(CompareConfigs);
00092 
00093   // If biggest resolution is big enough, we propose standard resolution such as
00094   // 800x600, 1024x768, 1280x1024, 1600x1200
00095   Point2i a(800, 600);
00096   if ( CompareConfigs((*available_configs.begin()), a))
00097     available_configs.push_back(a);
00098   Point2i b(1024, 768);
00099   if ( CompareConfigs((*available_configs.begin()), b))
00100     available_configs.push_back(b);
00101   Point2i c(1280, 1024);
00102   if ( CompareConfigs((*available_configs.begin()), c))
00103     available_configs.push_back(c);
00104   Point2i d(1600, 1200);
00105   if ( CompareConfigs((*available_configs.begin()), d))
00106     available_configs.push_back(d);
00107 
00108   // Sort the list again...
00109   available_configs.sort(CompareConfigs);
00110 
00111   // Remove double items
00112   std::list<Point2i>::iterator prev = available_configs.begin(),
00113     it = available_configs.begin() ,
00114     end = available_configs.end();
00115 
00116   for (++it; it != end ; ++it) {
00117     if ((*prev)==(*it)) // the two items are equals
00118       prev = available_configs.erase(prev);
00119     else
00120       prev++;
00121   }
00122 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Video::Flip ( void   ) 

Definition at line 203 of file video.cpp.

00203                 {
00204   window.Flip();
00205 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::list< Point2i > & Video::GetAvailableConfigs (  ) 

Definition at line 124 of file video.cpp.

00125 {
00126   return available_configs;
00127 }

Here is the caller graph for this function:

uint Video::GetMaxFps (  ) 

Definition at line 51 of file video.cpp.

00051                      {
00052   return m_max_fps;
00053 }

Here is the caller graph for this function:

uint Video::GetSleepMaxFps (  ) 

Definition at line 55 of file video.cpp.

00055                           {
00056   return m_sleep_max_fps;
00057 }

void Video::InitSDL ( void   )  [private]

Definition at line 192 of file video.cpp.

00192                    {
00193   if( SDLReady )
00194     return;
00195 
00196   if( SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) < 0 )
00197     Error( Format( _("Unable to initialize SDL library: %s"), SDL_GetError() ) );
00198 
00199   SDL_EnableUNICODE(1);
00200   SDLReady = true;
00201 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Video::InitWindow ( void   ) 

Definition at line 164 of file video.cpp.

00164                       {
00165   InitSDL();
00166 
00167   window.SetSurface( NULL , false );
00168   window.SetAutoFree( false );
00169 
00170   Config * config = Config::GetInstance();
00171   SetConfig(config->tmp.video.width,
00172             config->tmp.video.height,
00173             config->tmp.video.fullscreen);
00174 
00175   if( window.IsNull() )
00176     Error( "Unable to initialize SDL window.");
00177 
00178   SetWindowCaption( std::string("Wormux ") + Constants::VERSION );
00179   SetWindowIcon( config->GetDataDir() + PATH_SEPARATOR + "wormux-32.xpm" );
00180 
00181   ComputeAvailableConfigs();
00182 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Video::IsFullScreen (  )  const

Definition at line 59 of file video.cpp.

00059                               {
00060   return fullscreen;
00061 }

Here is the caller graph for this function:

bool Video::SetConfig ( int  width,
int  height,
bool  fullscreen 
)

Definition at line 129 of file video.cpp.

00129                                                             {
00130   // initialize the main window
00131   if( window.IsNull() ||
00132      (width != window.GetWidth() ||
00133       height != window.GetHeight() ) ){
00134 
00135     window.SetSurface( SDL_SetVideoMode(width, height, 32,
00136                        SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF ), false );
00137 
00138     if( window.IsNull() ) {
00139       window.SetSurface( SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE) );
00140       std::cerr << "WARNING: Video not using hardware acceleration!" << std::endl;
00141     }
00142 
00143     if( window.IsNull() )
00144       return false;
00145     fullscreen = false;
00146   }
00147 
00148   if(fullscreen != _fullscreen) {
00149     SDL_WM_ToggleFullScreen( window.GetSurface() );
00150     fullscreen = !fullscreen;
00151   }
00152 
00153   camera.SetSize(width, height);
00154 
00155   return true;
00156 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Video::SetMaxFps ( uint  max_fps  ) 

Definition at line 43 of file video.cpp.

00043                                  {
00044   m_max_fps = max_fps;
00045   if (0 < m_max_fps)
00046     m_sleep_max_fps = 1000/m_max_fps;
00047   else
00048     m_sleep_max_fps = 0;
00049 }

Here is the caller graph for this function:

void Video::SetWindowCaption ( std::string  caption  ) 

Definition at line 184 of file video.cpp.

00184                                              {
00185   SDL_WM_SetCaption( caption.c_str(), NULL );
00186 }

Here is the caller graph for this function:

void Video::SetWindowIcon ( std::string  icon  )  [private]

Definition at line 188 of file video.cpp.

00188                                            {
00189   SDL_WM_SetIcon( IMG_Load(filename.c_str()), NULL );
00190 }

Here is the caller graph for this function:

void Video::ToggleFullscreen (  ) 

Definition at line 158 of file video.cpp.

00159 {
00160   SDL_WM_ToggleFullScreen( window.GetSurface() );
00161   fullscreen = !fullscreen;
00162 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

std::list<Point2i> Video::available_configs [private]

Definition at line 36 of file video.h.

bool Video::fullscreen [private]

Definition at line 34 of file video.h.

uint Video::m_max_fps [private]

Definition at line 31 of file video.h.

uint Video::m_sleep_max_fps [private]

Definition at line 32 of file video.h.

bool Video::SDLReady [private]

Definition at line 33 of file video.h.

Surface Video::window

Definition at line 43 of file video.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 14:28:29 2007 for Wormux by  doxygen 1.4.7