Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
ConfigDisplay Class Reference

#include <config_display.hpp>

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

List of all members.

Public Member Functions

 ConfigDisplay ()
 ~ConfigDisplay ()
void select ()
virtual void update (float dt)
virtual void handle (GameAction, int)
virtual void inputKeyboard (SDLKey, int)
virtual void countdown ()
void inputPointer (int x, int y)
void lockInput ()
void unlockInput ()
void TimeToString (const double time, char *s)

Protected Attributes

bool m_locked
int m_menu_id

Private Member Functions

void changeResolution (int width, int height)
void getScreenModes ()
 This gets the available screen resolutions available on the hardware and populates a vector with them.
void changeApplyButton ()
bool isBlacklisted (int width, int height)
void showBlacklistButtons ()
void loadDefaultModes ()
 loadDefaultModes() populates our list of resolutios manually, sorted from smallest to biggest, first on the width, then the height.

Private Attributes

std::vector< std::pair< int,
int > > 
m_sizes
int m_curr_res
int m_curr_width
int m_curr_height

Detailed Description

Definition at line 29 of file config_display.hpp.


Constructor & Destructor Documentation

Definition at line 47 of file config_display.cpp.

{
    getScreenModes(); //Fill the vector m_sizes with possible resolutions

    m_curr_width = m_sizes[m_curr_res].first;
    m_curr_height = m_sizes[m_curr_res].second;

    widget_manager->switchOrder();
    widget_manager->addTitleWgt( WTOK_TITLE, 60, 7, _("Display Settings"));

    if( isBlacklisted( m_curr_width, m_curr_height ))
    {
        widget_manager->addEmptyWgt( WTOK_FULLSCREEN, 1, 7);

        if (user_config->m_fullscreen)
        {
            std::cerr << "Warning: current screen mode is blacklisted.\n";
        }
    }
    else
    {
        if(user_config->m_fullscreen)
        {
            widget_manager->addTextButtonWgt( WTOK_FULLSCREEN, 60, 7,
                _("Window mode"));
        }
        else
        {
            widget_manager->addTextButtonWgt( WTOK_FULLSCREEN, 60, 7,
                _("Fullscreen mode"));
        }
    }

    widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 60, 2 );

    char msg [MAX_MESSAGE_LENGTH];
    snprintf( msg, MAX_MESSAGE_LENGTH, _("Current: %dx%d"), m_curr_width, m_curr_height );
    widget_manager->addTextWgt( WTOK_CURRENT_RES, 60, 7, msg);

    widget_manager->addTextButtonWgt( WTOK_INCR_RES, 60, 7,
        _("Increase Resolution"));
    widget_manager->addTextButtonWgt( WTOK_DECR_RES, 60, 7,
        _("Decrease Resolution"));

    widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 1, 2 );
    widget_manager->addTextButtonWgt( WTOK_APPLY_RES, 60, 7, _("Apply "));
    widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 1, 2 );

    widget_manager->addEmptyWgt( WTOK_CLEAR_BLACKLIST, 60, 7);
    widget_manager->setWgtText( WTOK_CLEAR_BLACKLIST,
        _("Clear from Blacklist") );

    widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 1, 2 );

    widget_manager->addTextButtonWgt( WTOK_QUIT, 60, 7, _("Press <ESC> to go back"));
    widget_manager->setWgtTextSize( WTOK_QUIT, WGT_FNT_SML );

    widget_manager->layout( WGT_AREA_ALL );
}

Here is the call graph for this function:

Definition at line 108 of file config_display.cpp.

Here is the call graph for this function:


Member Function Documentation

Definition at line 347 of file config_display.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void ConfigDisplay::changeResolution ( int  width,
int  height 
) [private]

reverse &&

reverse &&

Definition at line 240 of file config_display.cpp.

{
    if (user_config->m_fullscreen )
    {
        //store previous width and height
        user_config->m_prev_width = user_config->m_width;
        user_config->m_prev_height = user_config->m_height;
    }

    //change to new height and width
    user_config->m_width = width;
    user_config->m_height = height;

#if 0
    // if returning to prev res, change m_crashed to false as we didn't crash and save config
    if (reverse && user_config->m_fullscreen)
    {
        user_config->m_crashed = false;
        user_config->saveConfig();
    }
#endif

    if (user_config->m_fullscreen )
    {
        // Store settings in user config file in case new video mode
        // causes a crash
        user_config->m_crashed = true;
        user_config->saveConfig();
    }

    inputDriver->setVideoMode();
    glViewport(0,0,user_config->m_width, user_config->m_height);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void BaseGUI::countdown ( ) [virtual, inherited]

Reimplemented in DisplayResConfirm.

Definition at line 147 of file base_gui.cpp.

{
}
void ConfigDisplay::getScreenModes ( ) [private]

This gets the available screen resolutions available on the hardware and populates a vector with them.

Definition at line 277 of file config_display.cpp.

{
    SDL_Rect **modes = SDL_ListModes( NULL, SDL_OPENGL | SDL_FULLSCREEN | SDL_HWSURFACE );

    if (modes == NULL)
    {
        std::cerr << "No fullscreen modes available.\n";

        loadDefaultModes();

        //FIXME: blacklist all resolutions

    }
    else if (modes == (SDL_Rect **)-1) //Any screen size can be used
    {
        loadDefaultModes();
    }
    else
    {
        //modes[i] is used as the breaking condition because that's how SDL's
        //docs use it in their examples.
        for (int i = 0; modes[i]; ++i)
        {
            m_sizes.push_back (std::pair <int, int> (modes[i]->w,
                modes[i]->h));
        }

        std::sort (m_sizes.begin(), m_sizes.end());

        //Prevent use of very small resolutions
        const int MIN_WIDTH = 640;
        const int MIN_HEIGHT = 480;
        const int NUM_RES = (int)m_sizes.size();

        for (int i = NUM_RES - 1; i >= 0; --i)
        {
            if ( m_sizes[i].first < MIN_WIDTH )
            {
                //Remove the resolutions with a width smaller than MIN_WIDTH
                m_sizes.erase( m_sizes.begin(), m_sizes.begin() + i + 1 );
                break;
            }
            else if ( m_sizes[i].first == MIN_WIDTH &&
                m_sizes[i].second < MIN_HEIGHT )
            {
                m_sizes.erase( m_sizes.begin(), m_sizes.begin() + i + 1 );
                break;
            }
        }
    }

    //Set the same resolution as the one in the config file; if it's not
    //found, set it to the lowest resolution available as a sane default.
    m_curr_res = -1;
    const int NUM_RES = (int)m_sizes.size();

    for (int i = 0; i < NUM_RES; ++i)
    {
        if (m_sizes[i].first == user_config->m_width
         && m_sizes[i].second == user_config->m_height)
        {
            m_curr_res = i;
            return;
        }
    }

    m_curr_res = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void BaseGUI::handle ( GameAction  action,
int  value 
) [virtual, inherited]

Reimplemented in RaceGUI, LeaderResult, PlayerControls, RaceResultsGUI, DisplayResConfirm, MainMenu, Options, and RaceMenu.

Definition at line 43 of file base_gui.cpp.

{
    if( m_locked ) return;

    // Skip on keypress, act on keyrelease only.
    if (value) return;

       int previous = widget_manager->getSelectedWgt();

    switch ( action )
    {
    case GA_CURSOR_LEFT:
              animateWidget(previous,
                                     widget_manager->handleLeft());

              break;
    case GA_CURSOR_RIGHT:
              animateWidget(previous,
                                     widget_manager->handleRight());
              break;
    case GA_CURSOR_UP:
              animateWidget(previous,
                                     widget_manager->handleUp());
              break;
    case GA_CURSOR_DOWN:
              animateWidget(previous,
                                     widget_manager->handleDown());
              break;
       case GA_INC_SCROLL_SPEED:
              widget_manager->increaseScrollSpeed();
              break;
       case GA_INC_SCROLL_SPEED_FAST:
              widget_manager->increaseScrollSpeed(true);
              break;
       case GA_DEC_SCROLL_SPEED:
              widget_manager->decreaseScrollSpeed();
              break;
       case GA_DEC_SCROLL_SPEED_FAST:
              widget_manager->decreaseScrollSpeed(true);
              break;
    case GA_ENTER:
        select();
        break;
    case GA_LEAVE:
        if (menu_manager->getMenuStackSize() > 1)
        {
           if(menu_manager->isCurrentMenu(MENUID_RACEMENU))
             world->unpause();

           menu_manager->popMenu();
        }
        break;

    default:
        break;
    }   // switch
}   // handle

Here is the call graph for this function:

Here is the caller graph for this function:

void BaseGUI::inputKeyboard ( SDLKey  ,
int   
) [virtual, inherited]

Reimplemented in PlayerControls.

Definition at line 139 of file base_gui.cpp.

{
       // This method is not supposed to be called since BaseGUI does not
       // handle low-level keyboard input.
       assert(false);
}

Here is the caller graph for this function:

void BaseGUI::inputPointer ( int  x,
int  y 
) [inherited]

Definition at line 102 of file base_gui.cpp.

{
    if( m_locked ) return;

    const int PREV_SELECTED_WGT = widget_manager->getSelectedWgt();
    const int SELECTED_WGT = widget_manager->handlePointer( x, y );

    if( SELECTED_WGT != WidgetManager::WGT_NONE )
    {
        if( PREV_SELECTED_WGT != WidgetManager::WGT_NONE )
        {
            widget_manager->darkenWgtColor( PREV_SELECTED_WGT );
        }

        widget_manager->lightenWgtColor( SELECTED_WGT );
        widget_manager->pulseWgt( SELECTED_WGT );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool ConfigDisplay::isBlacklisted ( int  width,
int  height 
) [private]

Definition at line 363 of file config_display.cpp.

{
    int black_width, black_height;
    const int NUM_BLACKLISTED = (int)user_config->m_blacklist_res.size();

    for (int i = 0; i < NUM_BLACKLISTED; ++i)
    {
        sscanf(user_config->m_blacklist_res[i].c_str(),
        "%dx%d", &black_width, &black_height );

        if (width == black_width && height == black_height) return true;
    }

    return false;

}

Here is the caller graph for this function:

void ConfigDisplay::loadDefaultModes ( ) [private]

loadDefaultModes() populates our list of resolutios manually, sorted from smallest to biggest, first on the width, then the height.

Useful when no fullscreen resolutions are available or when any resolution is available. The list of resolutions is taken from http://www.tamingthebeast.net/blog/web-development/screen-resolution-statistics-0907.htm

Definition at line 402 of file config_display.cpp.

{
    m_sizes.clear();

    m_sizes.push_back( std::pair <int, int> (800, 600) );
    m_sizes.push_back( std::pair <int, int> (1024, 768) );
    m_sizes.push_back( std::pair <int, int> (1152, 864) );
    m_sizes.push_back( std::pair <int, int> (1280, 768) );
    m_sizes.push_back( std::pair <int, int> (1280, 800) );
    m_sizes.push_back( std::pair <int, int> (1280, 960) );
    m_sizes.push_back( std::pair <int, int> (1280, 1024) );
    m_sizes.push_back( std::pair <int, int> (1440, 900) );
    m_sizes.push_back( std::pair <int, int> (1680, 1050) );
    m_sizes.push_back( std::pair <int, int> (1920, 1200) );
};

Here is the caller graph for this function:

void BaseGUI::lockInput ( ) [inline, inherited]

Definition at line 49 of file base_gui.hpp.

{ m_locked = true; }
void ConfigDisplay::select ( ) [virtual]

Implements BaseGUI.

Definition at line 114 of file config_display.cpp.

{
    switch ( widget_manager->getSelectedWgt() )
    {
    case WTOK_FULLSCREEN:
        inputDriver->toggleFullscreen();
        if( user_config->m_fullscreen )
        {
            menu_manager->pushMenu( MENUID_RESOLUTION_CONFIRM_WIN );
        }
        else
        {
            //FIXME: maybe instead of 'Fullscreen mode' something like
            //'Switch to fullscreen mode' would be more user friendly?
            widget_manager->setWgtText(WTOK_FULLSCREEN, _("Fullscreen mode"));
        }
        changeApplyButton();
        break;

    case WTOK_INCR_RES:
        {
            const int NUM_RES = (int)m_sizes.size();
            m_curr_res = std::min(NUM_RES - 1, m_curr_res + 1);

            if ( user_config->m_fullscreen &&
                isBlacklisted( m_curr_width, m_curr_height ))
            {
                showBlacklistButtons();
            }
            else changeApplyButton();
        }
        break;

    case WTOK_DECR_RES:
        m_curr_res = std::max(0,m_curr_res-1);
        if ( user_config->m_fullscreen &&
            isBlacklisted( m_curr_width, m_curr_height ))
        {
            showBlacklistButtons();
        }
        else changeApplyButton();
        break;

    case WTOK_APPLY_RES:
        if (m_curr_width != m_sizes[m_curr_res].first ||
            m_curr_height != m_sizes[m_curr_res].second)
        {
            changeResolution(m_sizes[m_curr_res].first,m_sizes[m_curr_res].second/*, false*/);

            if (user_config->m_fullscreen)
            {
                menu_manager->pushMenu(MENUID_RESOLUTION_CONFIRM_FS);
            }
            else
            {
                char msg [MAX_MESSAGE_LENGTH];
                snprintf (msg, MAX_MESSAGE_LENGTH, "Current: %dx%d",
                user_config->m_width, user_config->m_height);
                widget_manager->setWgtText(WTOK_CURRENT_RES, msg);

                if ( isBlacklisted( user_config->m_width,
                    user_config->m_height ))
                {
                    widget_manager->hideWgtText(WTOK_FULLSCREEN);
                    widget_manager->hideWgtRect(WTOK_FULLSCREEN);
                    widget_manager->deactivateWgt(WTOK_FULLSCREEN);
                }
                else
                {
                    widget_manager->setWgtText(WTOK_FULLSCREEN, _("Fullscreen mode"));
                    widget_manager->showWgtText(WTOK_FULLSCREEN);
                    widget_manager->showWgtRect(WTOK_FULLSCREEN);
                    widget_manager->activateWgt(WTOK_FULLSCREEN);
                }
                widget_manager->layout();

                user_config->m_prev_width = m_curr_width = user_config->m_width;
                user_config->m_prev_height = m_curr_height = user_config->m_height;
            }
        }
        break;

    case WTOK_CLEAR_BLACKLIST:
        {
            const int NUM_BLACKLISTED = (int)user_config->m_blacklist_res.size();
            int black_width, black_height = 0;
            int id = -1;

            for ( int i = 0; i < NUM_BLACKLISTED; ++i )
            {
                sscanf(user_config->m_blacklist_res[i].c_str(),
                       "%dx%d",& black_width, & black_height);

                if ( m_sizes[m_curr_res].first == black_width &&
                     m_sizes[m_curr_res].second == black_height )
                {
                    id = i;
                    break;
                }
            }

            if( id != -1 )
            {
                user_config->m_blacklist_res.erase(
                    user_config->m_blacklist_res.begin() + id );
            }
            else
            {
                std::cerr << "Warning: tried to erase a resolution that " <<
                    "is not blacklisted.\n";
            }
        }

        changeApplyButton();
        widget_manager->layout();
        break;

    case WTOK_QUIT:
        menu_manager->popMenu();
        break;

    default: break;
    }
}

Here is the call graph for this function:

Definition at line 381 of file config_display.cpp.

{
    //change Apply button to Blacklisted button
    char msg [MAX_MESSAGE_LENGTH];
    snprintf(msg, MAX_MESSAGE_LENGTH, _("%dx%d Blacklisted"),
      m_sizes[m_curr_res].first,m_sizes[m_curr_res].second);
    widget_manager->setWgtText(WTOK_APPLY_RES, msg);
    widget_manager->deactivateWgt(WTOK_APPLY_RES);

    //show Remove from blacklist button
    widget_manager->showWgtRect( WTOK_CLEAR_BLACKLIST);
    widget_manager->showWgtText( WTOK_CLEAR_BLACKLIST);
    widget_manager->activateWgt( WTOK_CLEAR_BLACKLIST);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void BaseGUI::TimeToString ( const double  time,
char *  s 
) [inherited]

Definition at line 130 of file base_gui.cpp.

{
    int min     = (int) floor ( TIME / 60.0 ) ;
    int sec     = (int) floor ( TIME - (double) ( 60 * min ) ) ;
    int tenths  = (int) floor ( 10.0f * (TIME - (double)(sec + 60* min)));
    sprintf ( s, "%d:%02d:%d", min,  sec,  tenths ) ;
}   // TimeToString

Here is the caller graph for this function:

void BaseGUI::unlockInput ( ) [inline, inherited]

Definition at line 50 of file base_gui.hpp.

{ m_locked = false; }
void BaseGUI::update ( float  dt) [virtual, inherited]

Reimplemented in RaceGUI, CharSel, HelpPageOne, GrandPrixEnd, LeaderResult, GrandPrixSelect, ChallengesMenu, StartRaceFeedback, and TrackSel.

Definition at line 123 of file base_gui.cpp.

{
    widget_manager->update(dt);
}   // update

Here is the call graph for this function:


Member Data Documentation

Definition at line 42 of file config_display.hpp.

Definition at line 39 of file config_display.hpp.

Definition at line 41 of file config_display.hpp.

bool BaseGUI::m_locked [protected, inherited]

Definition at line 55 of file base_gui.hpp.

int BaseGUI::m_menu_id [protected, inherited]

Definition at line 56 of file base_gui.hpp.

std::vector< std::pair<int,int> > ConfigDisplay::m_sizes [private]

Definition at line 38 of file config_display.hpp.


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