Back to index

extremetuxracer  0.5beta
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
VideoConfig Class Reference

#include <videoconfig.h>

Inheritance diagram for VideoConfig:
Inheritance graph
[legend]
Collaboration diagram for VideoConfig:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 VideoConfig ()
 ~VideoConfig ()
void setWidgetPositions ()
void apply ()
void loop (float timeStep)
void drawTextandWidgets ()
bool keyPressEvent (SDLKey key)
void cancel ()
virtual void customLoop (float timeStep)
virtual bool keyboardEvent (SDLKey key, bool release)
virtual bool keyReleaseEvent (SDLKey key)
virtual bool mouseButtonEvent (int button, int x, int y, bool pressed)
virtual bool mouseButtonPressEvent (int button, int x, int y)
virtual bool mouseButtonReleaseEvent (int button, int x, int y)

Static Public Attributes

static GameModecurrentMode = NULL
static game_mode_t mode
static game_mode_t prevmode

Protected Member Functions

void setTitle (const char *title)
void drawSnow (float timeStep, bool windy=false)
 custom function for drawing snow in the ui

Protected Attributes

pp::Buttonmp_cancelBtn
pp::Buttonmp_applyBtn
pp::Labelmp_titleLbl
std::string m_title

Private Member Functions

void initVideoModes ()
 fills m_resolutionList with modes by trying to autodetect the available modes.

Private Attributes

pp::Listbox< resolution_t > * mp_resolutionListbox
pp::Listbox< bpp_t > * mp_bppListbox
pp::Listbox< multisample_t > * mp_multisampleListbox
std::list< resolution_tm_resolutionList
std::list< bpp_tm_bppList
std::list< multisample_tm_multisampleList
pp::CheckBoxmp_fullscreenBox
pp::CheckBoxmp_stencilBox
pp::CheckBoxmp_fsaaBox

Detailed Description

Definition at line 40 of file videoconfig.h.


Constructor & Destructor Documentation

Definition at line 58 of file videoconfig.cpp.

{
       setTitle(_("Video Configuration"));       
       
       pp::Vec2d pos(0,0);
       
       // resolution listbox 
       
       bool found=false;
       #ifdef _WIN32
              //Skip the resolutionbox
       #else
       
       std::list<resolution_t>::iterator resit;

       
       initVideoModes();
       
       // check for the current resolution
       for (resit = m_resolutionList.begin();
               resit != m_resolutionList.end();
               resit++)
       {
              if ( (*resit).x==getparam_x_resolution() && (*resit).y==getparam_y_resolution())
                     break;                
       }

       if (resit == m_resolutionList.end()){
              // current resolution not in list
              // therefore we simply add this
              char buff[16];
              resolution_t resolution;
              sprintf(buff,"%d x %d",getparam_x_resolution(), getparam_y_resolution());
              resolution.name = buff;
              resolution.x=getparam_x_resolution();
              resolution.y=getparam_y_resolution();
              m_resolutionList.insert(m_resolutionList.begin(),resolution);
              resit = m_resolutionList.begin();
       }
       

       mp_resolutionListbox = new pp::Listbox<resolution_t>( pos,
                               pp::Vec2d(190, 32),
                               "listbox_item",
                               m_resolutionList);
     mp_resolutionListbox->setCurrentItem( resit );
       
       //bpp listbox
       std::list<bpp_t>::iterator bppit;
       for (unsigned int i=0; i < sizeof(bpps)/sizeof(bpp_t) ; i++) {
              m_bppList.push_back(bpps[i]);
              if(bpps[i].data==getparam_bpp_mode()){
                     bppit = --m_bppList.end();
              }
    }
    mp_bppListbox = new pp::Listbox<bpp_t>( pos,
                                   pp::Vec2d(190, 32),
                                   "listbox_item",
                                   m_bppList);
    mp_bppListbox->setCurrentItem( bppit );
       
       mp_fullscreenBox = new pp::CheckBox(pos, pp::Vec2d(32, 32) );
       mp_fullscreenBox->setState( getparam_fullscreen() );
#endif
       
       mp_stencilBox = new pp::CheckBox(pos, pp::Vec2d(32, 32) );
       mp_stencilBox->setState( getparam_stencil_buffer() );
       
       //multisample listbox
       found=false;
       std::list<multisample_t>::iterator multiit;
       for (unsigned int i=0; i < sizeof(multisamples)/sizeof(multisample_t) ; i++) {
              m_multisampleList.push_back(multisamples[i]);
              if(multisamples[i].data==getparam_multisamples()){
                     multiit = --m_multisampleList.end();
                     found=true;
              }
    }
       if(!found) multiit = m_multisampleList.begin();
    mp_multisampleListbox = new pp::Listbox<multisample_t>( pos,
                                   pp::Vec2d(150, 32),
                                   "listbox_item",
                                   m_multisampleList);
    mp_multisampleListbox->setCurrentItem( multiit );
       
       mp_fsaaBox = new pp::CheckBox(pos, pp::Vec2d(32, 32) );
       mp_fsaaBox->setState( getparam_enable_fsaa());
}

Here is the call graph for this function:

Definition at line 147 of file videoconfig.cpp.

{
       #ifdef _WIN32
       #else
              delete mp_resolutionListbox;
              delete mp_bppListbox;
              delete mp_fullscreenBox;
       #endif
       
       delete mp_multisampleListbox;
       delete mp_stencilBox;
       delete mp_fsaaBox;
}

Member Function Documentation

void VideoConfig::apply ( ) [virtual]

Implements ConfigMode.

Definition at line 206 of file videoconfig.cpp.

{
       bool updatevideo = false;
       
       std::list<multisample_t>::iterator multiit = mp_multisampleListbox->getCurrentItem();
       
       #ifdef _WIN32
              //Skip the resolutionbox
       #else
              std::list<resolution_t>::iterator resit = mp_resolutionListbox->getCurrentItem();
              std::list<bpp_t>::iterator bppit = mp_bppListbox->getCurrentItem();
       

              if ( (*resit).x != getparam_x_resolution() ){
                     setparam_x_resolution((*resit).x);
                     setparam_y_resolution((*resit).y);
                     updatevideo=true;    
              }
       
       
              if ( (*bppit).data != getparam_bpp_mode() ){
                     setparam_bpp_mode((*bppit).data);
                     updatevideo=true;    
              }
              
              if (mp_fullscreenBox->getState() != getparam_fullscreen() ){
                     setparam_fullscreen(bool( mp_fullscreenBox->getState() ));
                     updatevideo=true;
              }
       #endif
       
       if (mp_stencilBox->getState() != getparam_stencil_buffer() ){
              setparam_stencil_buffer(bool( mp_stencilBox->getState() ));
              updatevideo=true;
       }
       
       if (mp_fsaaBox->getState() != getparam_enable_fsaa() ){
              setparam_enable_fsaa(bool( mp_fsaaBox->getState() ));
              updatevideo=true;
       }
       
       if ( (*multiit).data != getparam_multisamples() ){
              setparam_multisamples((*multiit).data);
              updatevideo=true;    
       }
       
       #ifdef _WIN32
              //Skip video update
       #else
       if (updatevideo==true){
              printf("Set new videomode:%dx%d bpp:%d \n", (*resit).x, (*resit).y,(*bppit).data);
              setup_sdl_video_mode();
       }
       #endif
       
       write_config_file();
       
       set_game_mode( GameMode::prevmode );
    UIMgr.setDirty();       
}

Here is the call graph for this function:

void ConfigMode::cancel ( ) [inherited]

Definition at line 112 of file configmode.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void ConfigMode::customLoop ( float  timeStep) [inline, virtual, inherited]

Definition at line 53 of file configmode.h.

{};

Here is the caller graph for this function:

void GameMode::drawSnow ( float  timeStep,
bool  windy = false 
) [protected, inherited]

custom function for drawing snow in the ui

Definition at line 203 of file loop.cpp.

{
       // check wether ui snow is 
       if(getparam_ui_snow()){
              // update and draw snow
              update_ui_snow( timeStep, windy );
              draw_ui_snow();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ConfigMode::drawTextandWidgets ( ) [inherited]

Definition at line 86 of file configmode.cpp.

{
       int w = getparam_x_resolution();
    int h = getparam_y_resolution();

       mp_cancelBtn->setPosition(pp::Vec2d(w/2-300,h/2-240));
       mp_applyBtn->setPosition(pp::Vec2d(w/2,h/2-240));
       mp_titleLbl->setPosition(pp::Vec2d(w/2,h/2+200));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void VideoConfig::initVideoModes ( ) [private]

fills m_resolutionList with modes by trying to autodetect the available modes.

If the autodetection fails, standard modes are used.

Definition at line 268 of file videoconfig.cpp.

{
       SDL_Rect **modes;
       int i;

       // get available fullscreen OpenGL modes
       if(!getparam_disable_videomode_autodetection()){ 
              modes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL);
       }else{
              modes=(SDL_Rect **)-1;
       }
       // check if we cannot receive the modes
       if(    modes == (SDL_Rect **)-1 ||
              modes == (SDL_Rect **)0 )
       {
              // unable to find modes... fall back to standard modes
              for (unsigned int i=0; i<sizeof(resolutions)/sizeof(resolution_t); i++) {
                     m_resolutionList.push_back(resolutions[i]);
              }      
       }else{
              char buff[16];
              resolution_t resolution;
              
              // fill list with modes
              for(i=0; modes[i]; ++i){
                     sprintf(buff,"%d x %d", modes[i]->w, modes[i]->h);
                     resolution.name = buff;
                     resolution.x=modes[i]->w;
                     resolution.y=modes[i]->h;
                     m_resolutionList.push_back(resolution);   
              }      
       }
}

Here is the caller graph for this function:

virtual bool GameMode::keyboardEvent ( SDLKey  key,
bool  release 
) [inline, virtual, inherited]

Reimplemented in Racing.

Definition at line 90 of file loop.h.

{return false;};
bool ConfigMode::keyPressEvent ( SDLKey  key) [virtual, inherited]

Reimplemented from GameMode.

Definition at line 97 of file configmode.cpp.

{
       switch (key){
              case SDLK_ESCAPE:
                     cancel();
              return true;
              case SDLK_RETURN:
                     apply();
              return true;
              default:
                     return false;
       }
}

Here is the call graph for this function:

virtual bool GameMode::keyReleaseEvent ( SDLKey  key) [inline, virtual, inherited]

Reimplemented in HighscoreShow, and SplashScreen.

Definition at line 92 of file loop.h.

{return false;};
void ConfigMode::loop ( float  timeStep) [virtual, inherited]

Implements GameMode.

Definition at line 56 of file configmode.cpp.

{
       update_audio();
    set_gl_options( GUI );
    clear_rendering_context();
    UIMgr.setupDisplay();
       
       drawTextandWidgets();
       
       // forces the config mode to update it's widget positions
       // perhaps we should call this only when the screen size changes
       setWidgetPositions();
       
       // calls the custom loop of the derived class (if it exists)
       customLoop( timeStep );
       
       // draw snow if enabled
       drawSnow( timeStep );
       
       theme.drawMenuDecorations();
       
       // draw ui widgets
    UIMgr.draw();
       
       
    reshape( getparam_x_resolution(), getparam_y_resolution() );
    winsys_swap_buffers();
}

Here is the call graph for this function:

virtual bool GameMode::mouseButtonEvent ( int  button,
int  x,
int  y,
bool  pressed 
) [inline, virtual, inherited]

Reimplemented in GameOver.

Definition at line 94 of file loop.h.

{return false;};
virtual bool GameMode::mouseButtonPressEvent ( int  button,
int  x,
int  y 
) [inline, virtual, inherited]

Definition at line 95 of file loop.h.

{return false;};
virtual bool GameMode::mouseButtonReleaseEvent ( int  button,
int  x,
int  y 
) [inline, virtual, inherited]

Reimplemented in CreditsTrans, and SplashScreen.

Definition at line 96 of file loop.h.

{return false;};
void ConfigMode::setTitle ( const char *  title) [protected, inherited]

Definition at line 119 of file configmode.cpp.

{
       mp_titleLbl->setText(title);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void VideoConfig::setWidgetPositions ( ) [virtual]

Implements ConfigMode.

Definition at line 162 of file videoconfig.cpp.

{
       int width = 550;
       int height = 240;
       
       pp::Vec2d pos(getparam_x_resolution()/2 - width/2,
                              getparam_y_resolution()/2 + height/2);
       
       pp::Font *font = pp::Font::get("button_label");
       
       #ifdef _WIN32
              font->draw(_("To change the resolution, or switch into fullscreen mode"),pos);
              pos.y-=30;
              font->draw(_("use options.txt, located in the config folder."),pos);
       #else
              font->draw(_("Resolution:"),pos);
              mp_resolutionListbox->setPosition(pp::Vec2d(pos.x+width-190,pos.y));  
       
              pos.y-=40;
              font->draw(_("Bits Per Pixel:"),pos);
              mp_bppListbox->setPosition(pp::Vec2d(pos.x+width-190,pos.y));
              
              pos.y-=40;
              font->draw(_("Fullscreen:"),pos);
              mp_fullscreenBox->setPosition(pp::Vec2d(pos.x+width-32,pos.y));
       #endif
       pos.y-=80;
       font->draw(_("Experimental (needs restart)"),pos);
       
       pos.y-=40;
       font->draw(_("Stencil Buffer:"),pos);
       mp_stencilBox->setPosition(pp::Vec2d(pos.x+width-32,pos.y));
       
       pos.y-=40;
       font->draw(_("Enable FSAA:"),pos);
       mp_fsaaBox->setPosition(pp::Vec2d(pos.x+width-32,pos.y));
       
       pos.y-=40;
       font->draw(_("FSAA Multisamples:"),pos);
       mp_multisampleListbox->setPosition(pp::Vec2d(pos.x+width-150,pos.y));

}

Here is the call graph for this function:


Member Data Documentation

GameMode * GameMode::currentMode = NULL [static, inherited]

Definition at line 96 of file loop.h.

std::list<bpp_t> VideoConfig::m_bppList [private]

Definition at line 47 of file videoconfig.h.

Definition at line 48 of file videoconfig.h.

Definition at line 46 of file videoconfig.h.

std::string ConfigMode::m_title [protected, inherited]

Definition at line 38 of file configmode.h.

game_mode_t GameMode::mode [static, inherited]

Definition at line 99 of file loop.h.

pp::Button* ConfigMode::mp_applyBtn [protected, inherited]

Definition at line 35 of file configmode.h.

Definition at line 43 of file videoconfig.h.

pp::Button* ConfigMode::mp_cancelBtn [protected, inherited]

Definition at line 34 of file configmode.h.

Definition at line 52 of file videoconfig.h.

Definition at line 50 of file videoconfig.h.

Definition at line 44 of file videoconfig.h.

Definition at line 42 of file videoconfig.h.

Definition at line 51 of file videoconfig.h.

pp::Label* ConfigMode::mp_titleLbl [protected, inherited]

Definition at line 36 of file configmode.h.

game_mode_t GameMode::prevmode [static, inherited]

Definition at line 100 of file loop.h.


The documentation for this class was generated from the following files: