Improved resolution switching.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1500 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
751ed6d748
commit
57af89dae6
@ -35,58 +35,50 @@ enum WidgetTokens
|
||||
WTOK_TITLE,
|
||||
|
||||
WTOK_FULLSCREEN,
|
||||
|
||||
WTOK_INCR_RES,
|
||||
|
||||
WTOK_DECR_RES,
|
||||
|
||||
WTOK_CURRENT_RES,
|
||||
|
||||
WTOK_APPLY_RES,
|
||||
WTOK_CLEAR_BLACKLIST,
|
||||
|
||||
WTOK_EMPTY,
|
||||
|
||||
WTOK_EMPTY1,
|
||||
|
||||
WTOK_EMPTY2,
|
||||
|
||||
WTOK_EMPTY3,
|
||||
|
||||
WTOK_QUIT,
|
||||
|
||||
WTOK_CLEAR_BLACKLIST
|
||||
WTOK_QUIT
|
||||
};
|
||||
|
||||
ConfigDisplay::ConfigDisplay()
|
||||
{
|
||||
// The following code comes before the widget code because it may change
|
||||
// the fullscreen status, which is used in displaying the WTOK_FULLSCREEN
|
||||
{
|
||||
//This is commented because there is no point in checking the resolution
|
||||
//when we enter the display configuration every time; this should be done
|
||||
//at the start of the program and after the resolution confirm screen.
|
||||
#if 0
|
||||
// The following code comes before the widget code because it may change
|
||||
// the fullscreen status, which is used in displaying the WTOK_FULLSCREEN
|
||||
// text.
|
||||
|
||||
// if prev resolution different to current res then a resolution change
|
||||
// has been rejected
|
||||
if (user_config->m_width != user_config->m_prev_width
|
||||
&& user_config->m_height != user_config->m_prev_height)
|
||||
{
|
||||
changeResolution(user_config->m_prev_width,
|
||||
user_config->m_prev_height,true);
|
||||
}
|
||||
|
||||
// if m_prev_windowed is true and m_fullscreen is true then a change to
|
||||
// fullscreen has been rejected
|
||||
else if (user_config->m_prev_windowed && user_config->m_fullscreen)
|
||||
|
||||
if( user_config->m_width != user_config->m_prev_width &&
|
||||
user_config->m_height != user_config->m_prev_height )
|
||||
{
|
||||
drv_toggleFullscreen();
|
||||
user_config->m_prev_windowed = false; //reset flags
|
||||
user_config->m_crashed = false;
|
||||
user_config->saveConfig();
|
||||
changeResolution( user_config->m_prev_width, user_config->m_prev_height, true );
|
||||
}
|
||||
else
|
||||
else if( user_config->m_prev_windowed && user_config->m_fullscreen )
|
||||
{
|
||||
user_config->m_crashed = false; //if we are here we didn't crash
|
||||
user_config->saveConfig();
|
||||
drv_toggleFullscreen();
|
||||
user_config->m_prev_windowed = false;
|
||||
user_config->m_crashed = false;
|
||||
user_config->saveConfig();
|
||||
}
|
||||
|
||||
else //no problems detected
|
||||
{
|
||||
user_config->m_crashed = false;
|
||||
user_config->saveConfig();
|
||||
}
|
||||
#endif
|
||||
getScreenModes(); //Fill the vector m_sizes with possible resolutions
|
||||
|
||||
const bool SHOW_RECT = true;
|
||||
const bool SHOW_TEXT = true;
|
||||
widget_manager->setInitialRectState(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
|
||||
@ -99,92 +91,96 @@ ConfigDisplay::ConfigDisplay()
|
||||
|
||||
widget_manager->setInitialActivationState(true);
|
||||
widget_manager->addWgt( WTOK_FULLSCREEN, 40, 7);
|
||||
if(user_config->m_fullscreen)
|
||||
if( isBlacklisted( m_curr_width, m_curr_height ))
|
||||
{
|
||||
widget_manager->setWgtText( WTOK_FULLSCREEN, _("Window mode"));
|
||||
if (!(user_config->m_fullscreen))
|
||||
{
|
||||
// widget_manager->setWgtText(WTOK_FULLSCREEN, _("Fullscreen Unavailable"));
|
||||
widget_manager->hideWgtText(WTOK_FULLSCREEN);
|
||||
widget_manager->hideWgtRect(WTOK_FULLSCREEN);
|
||||
widget_manager->deactivateWgt(WTOK_FULLSCREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Warning: current screen mode is blacklisted.\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
widget_manager->setWgtText( WTOK_FULLSCREEN, _("Fullscreen mode"));
|
||||
if(user_config->m_fullscreen)
|
||||
{
|
||||
widget_manager->setWgtText( WTOK_FULLSCREEN, _("Window mode"));
|
||||
}
|
||||
else
|
||||
{
|
||||
widget_manager->setWgtText( WTOK_FULLSCREEN, _("Fullscreen mode"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_EMPTY, 40, 2);
|
||||
widget_manager->deactivateWgt( WTOK_EMPTY );
|
||||
widget_manager->hideWgtRect( WTOK_EMPTY );
|
||||
widget_manager->hideWgtText( WTOK_EMPTY );
|
||||
|
||||
|
||||
|
||||
m_curr_width = m_sizes[m_curr_res].first;
|
||||
m_curr_height = m_sizes[m_curr_res].second;
|
||||
|
||||
widget_manager->addWgt( WTOK_CURRENT_RES, 40, 7);
|
||||
widget_manager->setWgtText( WTOK_CURRENT_RES, _("Current: ****x****"));
|
||||
|
||||
char msg [MAX_MESSAGE_LENGTH];
|
||||
snprintf( msg, MAX_MESSAGE_LENGTH, _("Current: %dx%d"), m_curr_width, m_curr_height );
|
||||
widget_manager->setWgtText( WTOK_CURRENT_RES, msg );
|
||||
|
||||
widget_manager->addWgt( WTOK_INCR_RES, 40, 7);
|
||||
widget_manager->setWgtText( WTOK_INCR_RES, _("Increase Resolution"));
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_DECR_RES, 40, 7);
|
||||
widget_manager->setWgtText( WTOK_DECR_RES, _("Decrease Resolution"));
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_EMPTY2, 40, 2);
|
||||
widget_manager->deactivateWgt( WTOK_EMPTY2 );
|
||||
widget_manager->hideWgtRect( WTOK_EMPTY2 );
|
||||
widget_manager->hideWgtText( WTOK_EMPTY2 );
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_APPLY_RES, 40, 7);
|
||||
widget_manager->setWgtText( WTOK_APPLY_RES, _("Apply "));
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_EMPTY3, 40, 2);
|
||||
widget_manager->deactivateWgt( WTOK_EMPTY3 );
|
||||
widget_manager->hideWgtRect( WTOK_EMPTY3 );
|
||||
widget_manager->hideWgtText( WTOK_EMPTY3 );
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_CLEAR_BLACKLIST, 40, 7);
|
||||
widget_manager->setWgtText( WTOK_CLEAR_BLACKLIST, _("Clear from Blacklist"));
|
||||
widget_manager->deactivateWgt( WTOK_CLEAR_BLACKLIST);
|
||||
widget_manager->hideWgtRect( WTOK_CLEAR_BLACKLIST);
|
||||
widget_manager->hideWgtText( WTOK_CLEAR_BLACKLIST);
|
||||
|
||||
|
||||
widget_manager->deactivateWgt( WTOK_CLEAR_BLACKLIST);
|
||||
widget_manager->hideWgtRect( WTOK_CLEAR_BLACKLIST);
|
||||
widget_manager->hideWgtText( WTOK_CLEAR_BLACKLIST);
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_EMPTY1, 40, 7);
|
||||
widget_manager->deactivateWgt( WTOK_EMPTY1 );
|
||||
widget_manager->hideWgtRect( WTOK_EMPTY1 );
|
||||
widget_manager->hideWgtText( WTOK_EMPTY1 );
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_QUIT, 40, 7);
|
||||
widget_manager->setWgtText( WTOK_QUIT, _("Press <ESC> to go back"));
|
||||
widget_manager->setWgtTextSize( WTOK_QUIT, WGT_FNT_SML );
|
||||
|
||||
|
||||
widget_manager->layout( WGT_AREA_ALL );
|
||||
|
||||
//get current resolution and set wgt txt
|
||||
getScreenModes(); //Populate a list with possible resolutions
|
||||
if (m_sizes_index == -1) //A custom res has been set previously that is not in list
|
||||
{
|
||||
|
||||
//Custom resolutions are disabled because, SDL *should* give the all the
|
||||
//the available resolutions (i.e. there is no point in using a custom
|
||||
//res), and there is the risk of users changing the configuration to a
|
||||
//setting that causes a crash.
|
||||
#if 0
|
||||
if (m_curr_res == -1) //A custom res has been set previously that is not in list
|
||||
{
|
||||
snprintf (m_resolution, MAX_MESSAGE_LENGTH, _("Current: %dx%d"), user_config->m_width, user_config->m_height);
|
||||
widget_manager->setWgtText(WTOK_CURRENT_RES, m_resolution);
|
||||
}
|
||||
else // Find the current res from those in the list
|
||||
{
|
||||
m_curr_width = m_sizes[m_sizes_index].first;
|
||||
m_curr_height = m_sizes[m_sizes_index].second;
|
||||
snprintf(m_resolution, MAX_MESSAGE_LENGTH, _("Current: %dx%d"),m_curr_width,m_curr_height);
|
||||
widget_manager->setWgtText(WTOK_CURRENT_RES, m_resolution);
|
||||
}
|
||||
|
||||
m_blacklist_res_size = 0;
|
||||
if (!user_config->m_blacklist_res.empty())
|
||||
{
|
||||
m_blacklist_res_size = (int)user_config->m_blacklist_res.size();
|
||||
if (onBlacklist(m_curr_width,m_curr_height) >= 0) // check current res against blacklist
|
||||
{
|
||||
// if in windowed mode make fullscreen unavailable
|
||||
if (!user_config->m_fullscreen)
|
||||
{
|
||||
widget_manager->setWgtText(WTOK_FULLSCREEN, _("Fullscreen Unavailable"));
|
||||
widget_manager->deactivateWgt(WTOK_FULLSCREEN);
|
||||
}
|
||||
else
|
||||
showBlacklistButtons(); // change widgets to blacklisted mode
|
||||
}
|
||||
}
|
||||
|
||||
{}
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -196,208 +192,265 @@ ConfigDisplay::~ConfigDisplay()
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConfigDisplay::select()
|
||||
{
|
||||
switch ( widget_manager->getSelectedWgt())
|
||||
switch ( widget_manager->getSelectedWgt() )
|
||||
{
|
||||
case WTOK_FULLSCREEN:
|
||||
drv_toggleFullscreen();
|
||||
if (user_config->m_fullscreen)
|
||||
{
|
||||
user_config->m_prev_windowed = true;
|
||||
menu_manager->pushMenu(MENUID_DISPLAY_RES_CONFIRM);
|
||||
}
|
||||
else
|
||||
widget_manager->setWgtText(WTOK_FULLSCREEN, _("Fullscreen mode"));
|
||||
changeApplyButton();
|
||||
break;
|
||||
case WTOK_INCR_RES:
|
||||
m_sizes_index = std::min(m_sizes_size-1,m_sizes_index+1);
|
||||
//if there is a blacklist and we are fullscreen, inform user about blacklisted res
|
||||
if (!user_config->m_blacklist_res.empty() && user_config->m_fullscreen)
|
||||
drv_toggleFullscreen();
|
||||
if( user_config->m_fullscreen )
|
||||
{
|
||||
if (onBlacklist() >= 0) // check new res against blacklist
|
||||
{
|
||||
showBlacklistButtons(); // change widgets to blacklisted mode
|
||||
}
|
||||
else
|
||||
changeApplyButton();
|
||||
menu_manager->pushMenu( MENUID_RESOLUTION_CONFIRM_WIN );
|
||||
}
|
||||
else
|
||||
changeApplyButton(); // change text on Apply button
|
||||
{
|
||||
//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 = 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_sizes_index = std::max(0,m_sizes_index-1);
|
||||
//if there is a blacklist and we are fullscreen, inform user about blacklisted res
|
||||
if (!user_config->m_blacklist_res.empty() && user_config->m_fullscreen)
|
||||
{
|
||||
if (onBlacklist() >= 0) // check new res against blacklist
|
||||
{
|
||||
showBlacklistButtons(); // change widgets to blacklisted mode
|
||||
}
|
||||
else
|
||||
changeApplyButton();
|
||||
}
|
||||
else
|
||||
changeApplyButton(); // change text on Apply button
|
||||
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_sizes_index].first
|
||||
|| m_curr_height != m_sizes[m_sizes_index].second) //Only allow Apply if a new res has been selected
|
||||
{
|
||||
changeResolution(m_sizes[m_sizes_index].first,m_sizes[m_sizes_index].second);
|
||||
|
||||
if (user_config->m_fullscreen) // if in fullscreen seek confirmation
|
||||
menu_manager->pushMenu(MENUID_DISPLAY_RES_CONFIRM);
|
||||
else
|
||||
{
|
||||
snprintf (m_resolution, MAX_MESSAGE_LENGTH, "Current: %dx%d",
|
||||
user_config->m_width, user_config->m_height);
|
||||
widget_manager->setWgtText(WTOK_CURRENT_RES, m_resolution);
|
||||
// Check new res against blacklist to determine if fullscreen is an option
|
||||
if (!user_config->m_blacklist_res.empty())
|
||||
{
|
||||
if (onBlacklist(user_config->m_width, user_config->m_height) >= 0)
|
||||
{
|
||||
widget_manager->setWgtText(WTOK_FULLSCREEN, _("Fullscreen Unavailable"));
|
||||
widget_manager->deactivateWgt(WTOK_FULLSCREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
widget_manager->setWgtText(WTOK_FULLSCREEN, _("Fullscreen mode"));
|
||||
widget_manager->activateWgt(WTOK_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
widget_manager->layout();
|
||||
// set prev_width and height values to current
|
||||
user_config->m_prev_width = m_curr_width = user_config->m_width;
|
||||
user_config->m_prev_height = m_curr_height = user_config->m_height;
|
||||
|
||||
}
|
||||
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->setWgtText(WTOK_FULLSCREEN, _("Fullscreen Unavailable"));
|
||||
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->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:
|
||||
user_config->m_blacklist_res.erase(user_config->m_blacklist_res.begin()
|
||||
+ onBlacklist());
|
||||
|
||||
if (!user_config->m_blacklist_res.empty())
|
||||
m_blacklist_res_size = (int)user_config->m_blacklist_res.size();
|
||||
else
|
||||
m_blacklist_res_size = 0;
|
||||
|
||||
changeApplyButton();
|
||||
widget_manager->layout();
|
||||
break;
|
||||
{
|
||||
const int NUM_BLACKLISTED = 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;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConfigDisplay::changeResolution(int width, int height, bool reverse)
|
||||
void ConfigDisplay::changeResolution(int width, int height/*, bool reverse*/)
|
||||
{
|
||||
if (!reverse && user_config->m_fullscreen) // don't store previous res if returning to it
|
||||
// or if not in fullscreen mode
|
||||
if (/*!reverse && */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;
|
||||
//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();
|
||||
user_config->m_crashed = false;
|
||||
user_config->saveConfig();
|
||||
}
|
||||
|
||||
if (!reverse && user_config->m_fullscreen)
|
||||
#endif
|
||||
|
||||
if (/*!reverse && */user_config->m_fullscreen )
|
||||
{
|
||||
// Store settings in user config file in case new video mode
|
||||
// causes a crash
|
||||
user_config->m_crashed = true; //set flag.
|
||||
user_config->saveConfig();
|
||||
// Store settings in user config file in case new video mode
|
||||
// causes a crash
|
||||
user_config->m_crashed = true;
|
||||
user_config->saveConfig();
|
||||
}
|
||||
|
||||
|
||||
//FIXME: setVideoMode() should be put inside a namespace or something
|
||||
setVideoMode();
|
||||
|
||||
glViewport(0,0,user_config->m_width, user_config->m_height);
|
||||
glScissor(0,0,user_config->m_width, user_config->m_height);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//This gets the available screen resolutions available on the hardware and
|
||||
//populates a vector with them.
|
||||
/**This gets the available screen resolutions available on the hardware and
|
||||
* populates a vector with them.
|
||||
*/
|
||||
void ConfigDisplay::getScreenModes()
|
||||
{
|
||||
SDL_Rect **modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN | SDL_HWSURFACE );
|
||||
|
||||
//Check if any modes are available
|
||||
if (!modes)
|
||||
SDL_Rect **modes = SDL_ListModes( NULL, SDL_OPENGL | SDL_FULLSCREEN | SDL_HWSURFACE );
|
||||
|
||||
if (modes == NULL)
|
||||
{
|
||||
std::cerr << "No Screen Modes available" <<std::endl;
|
||||
}
|
||||
else if (modes == (SDL_Rect **)-1)
|
||||
{
|
||||
//This means all modes are available..Shouldn't happen.
|
||||
std::cerr << "All modes available" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; modes[i]; ++i)
|
||||
m_sizes.push_back (std::pair <int, int> (modes[i]->w, modes[i]->h));
|
||||
|
||||
//Sort the entries
|
||||
sort (m_sizes.begin(), m_sizes.end());
|
||||
|
||||
//Prevent use of very small resolutions
|
||||
const int minRes = 640;
|
||||
m_sizes_size = (int)m_sizes.size();
|
||||
|
||||
for (int i = m_sizes_size-1; i >= 0; --i)
|
||||
std::cerr << "No fullscreen modes available.\n";
|
||||
|
||||
loadDefaultModes();
|
||||
|
||||
//FIXME: blacklist all resolutions
|
||||
|
||||
#if 0
|
||||
//This isn't enabled because SDL_VideoInfo must be called before the
|
||||
//first SDL_SetVideoMode() call to get the desktop resolution.
|
||||
|
||||
//Erase any resolutions from the list that are bigger than the
|
||||
//current desktop resolution
|
||||
const SDL_VideoInfo *VIDEO_INFO = SDL_GetVideoInfo();
|
||||
|
||||
const int NUM_RES = m_sizes.size();
|
||||
for (int i = 0; i < NUM_RES; ++i)
|
||||
{
|
||||
if (m_sizes[i].first < minRes) //find largest width less than minRes
|
||||
if (m_sizes[i].first > VIDEO_INFO->current_w &&
|
||||
m_sizes[i].second > VIDEO_INFO->current_h)
|
||||
{
|
||||
m_sizes.erase(m_sizes.begin(),m_sizes.begin()+i+1); //remove all resolutions prior
|
||||
m_sizes.erase( m_sizes.begin() + i, m_sizes.end() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//reassess m_sizes_size
|
||||
m_sizes_size = (int)m_sizes.size();
|
||||
|
||||
// search m_sizes for the current resolution
|
||||
m_sizes_index = -1;
|
||||
m_sizes_size = (int)m_sizes.size();
|
||||
for (int i = 0; i < m_sizes_size; i++)
|
||||
#endif
|
||||
}
|
||||
else if (modes == (SDL_Rect **)-1) //Any screen size can be used
|
||||
{
|
||||
if (m_sizes[i].first == user_config->m_width
|
||||
&& m_sizes[i].second == user_config->m_height)
|
||||
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_index = i;
|
||||
break;
|
||||
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 = 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 = 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConfigDisplay::changeApplyButton()
|
||||
{
|
||||
// change Apply button text
|
||||
snprintf(m_resolution, MAX_MESSAGE_LENGTH, _("Apply %dx%d"),
|
||||
m_sizes[m_sizes_index].first,m_sizes[m_sizes_index].second);
|
||||
widget_manager->setWgtText(WTOK_APPLY_RES, m_resolution);
|
||||
widget_manager->activateWgt(WTOK_APPLY_RES);
|
||||
|
||||
// change Apply button text
|
||||
char msg [MAX_MESSAGE_LENGTH];
|
||||
snprintf(msg, MAX_MESSAGE_LENGTH, _("Apply %dx%d"),
|
||||
m_sizes[m_curr_res].first,m_sizes[m_curr_res].second);
|
||||
widget_manager->setWgtText(WTOK_APPLY_RES, msg);
|
||||
widget_manager->activateWgt(WTOK_APPLY_RES);
|
||||
|
||||
// hide Remove from blacklist button
|
||||
widget_manager->hideWgtRect(WTOK_CLEAR_BLACKLIST);
|
||||
widget_manager->hideWgtText(WTOK_CLEAR_BLACKLIST);
|
||||
@ -405,49 +458,77 @@ void ConfigDisplay::changeApplyButton()
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int ConfigDisplay::onBlacklist()
|
||||
#if 0
|
||||
int ConfigDisplay::isBlacklisted()
|
||||
{
|
||||
int black_width, black_height = 0;
|
||||
int black_width, black_height = 0;
|
||||
for (int i = 0; i < m_blacklist_res_size; i++)
|
||||
{
|
||||
sscanf(user_config->m_blacklist_res[i].c_str(),
|
||||
"%dx%d",& black_width, & black_height);
|
||||
|
||||
if (m_sizes[m_sizes_index].first == black_width
|
||||
&& m_sizes[m_sizes_index].second == black_height)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
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)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int ConfigDisplay::onBlacklist(int width, int height)
|
||||
bool ConfigDisplay::isBlacklisted(int width, int height)
|
||||
{
|
||||
int black_width, black_height = 0;
|
||||
for (int i = 0; i < m_blacklist_res_size; i++)
|
||||
int black_width, black_height;
|
||||
const int NUM_BLACKLISTED = 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 i;
|
||||
}
|
||||
return -1;
|
||||
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 i;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConfigDisplay::showBlacklistButtons()
|
||||
{
|
||||
//change Apply button to Blacklisted button
|
||||
snprintf(m_resolution, MAX_MESSAGE_LENGTH, _("%dx%d Blacklisted"),
|
||||
m_sizes[m_sizes_index].first,m_sizes[m_sizes_index].second);
|
||||
widget_manager->setWgtText(WTOK_APPLY_RES, m_resolution);
|
||||
//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);
|
||||
|
||||
}
|
||||
|
||||
/** 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
|
||||
*/
|
||||
void ConfigDisplay::loadDefaultModes()
|
||||
{
|
||||
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) );
|
||||
};
|
||||
|
||||
|
@ -35,23 +35,27 @@ public:
|
||||
void select();
|
||||
|
||||
private:
|
||||
std::vector<std::pair<int,int> > m_sizes;
|
||||
int m_sizes_index;
|
||||
int m_sizes_size;
|
||||
char m_resolution[MAX_MESSAGE_LENGTH];
|
||||
std::vector< std::pair<int,int> > m_sizes;
|
||||
int m_curr_res;
|
||||
|
||||
int m_curr_width;
|
||||
int m_curr_height;
|
||||
int m_blacklist_res_size;
|
||||
|
||||
// changeResolution reverse param is set true when changing to a previous resolution
|
||||
void changeResolution(int width, int height, bool reverse=false);
|
||||
|
||||
// changeResolution() reverse param is set true when changing to a previous resolution,
|
||||
// thought it is disabled for now.
|
||||
void changeResolution(int width, int height/*, bool reverse*/);
|
||||
void getScreenModes();
|
||||
void changeApplyButton();
|
||||
// onBlacklist returns the index of the resolution in the blacklist
|
||||
|
||||
#if 0
|
||||
// isBlacklisted() returns the index of the resolution in the blacklist
|
||||
// or -1 if not in the blacklist
|
||||
int onBlacklist();
|
||||
int onBlacklist(int width, int height);
|
||||
int isBlacklisted();
|
||||
#endif
|
||||
bool isBlacklisted(int width, int height);
|
||||
void showBlacklistButtons();
|
||||
|
||||
void loadDefaultModes();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "widget_manager.hpp"
|
||||
#include "translation.hpp"
|
||||
#include "user_config.hpp"
|
||||
#include "sdldrv.hpp"
|
||||
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
@ -34,20 +35,20 @@
|
||||
enum WidgetTokens
|
||||
{
|
||||
WTOK_TITLE,
|
||||
|
||||
WTOK_APPLY_RES,
|
||||
|
||||
|
||||
WTOK_EMPTY,
|
||||
|
||||
WTOK_EMPTY1,
|
||||
|
||||
WTOK_QUIT
|
||||
};
|
||||
|
||||
DisplayResConfirm::DisplayResConfirm()
|
||||
{
|
||||
m_counter = 5; // Number of seconds in which to confirm
|
||||
|
||||
//FIXME: at the moment, FROM_WINDOW is not used.
|
||||
DisplayResConfirm::DisplayResConfirm( const bool FROM_WINDOW_ ) :
|
||||
FROM_WINDOW (FROM_WINDOW_)
|
||||
{
|
||||
m_counter = 5; // Number of seconds in which to confirm
|
||||
|
||||
const bool SHOW_RECT = true;
|
||||
const bool SHOW_TEXT = true;
|
||||
widget_manager->setInitialRectState(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
|
||||
@ -59,32 +60,34 @@ DisplayResConfirm::DisplayResConfirm()
|
||||
widget_manager->setWgtText( WTOK_TITLE, _("Confirm Resolution Within 5 Seconds"));
|
||||
|
||||
widget_manager->setInitialActivationState(true);
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_EMPTY, 40, 2);
|
||||
widget_manager->deactivateWgt( WTOK_EMPTY );
|
||||
widget_manager->hideWgtRect( WTOK_EMPTY );
|
||||
widget_manager->hideWgtText( WTOK_EMPTY );
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_APPLY_RES, 40, 7);
|
||||
widget_manager->setWgtText( WTOK_APPLY_RES, _("Confirm Resolution"));
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_EMPTY1, 40, 2);
|
||||
widget_manager->deactivateWgt( WTOK_EMPTY1 );
|
||||
widget_manager->hideWgtRect( WTOK_EMPTY1 );
|
||||
widget_manager->hideWgtText( WTOK_EMPTY1 );
|
||||
|
||||
|
||||
widget_manager->addWgt( WTOK_QUIT, 40, 7);
|
||||
widget_manager->setWgtText( WTOK_QUIT, _("Press <ESC> to Cancel"));
|
||||
widget_manager->setWgtTextSize( WTOK_QUIT, WGT_FNT_SML );
|
||||
|
||||
widget_manager->layout( WGT_AREA_ALL );
|
||||
|
||||
|
||||
m_timer = SDL_AddTimer(1000,timeout,NULL);
|
||||
if (m_timer == NULL)
|
||||
std::cerr << "Warning: Timer could not be initialised!" << std::endl;
|
||||
|
||||
{
|
||||
std::cerr << "Warning: Timer could not be initialised!\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
DisplayResConfirm::~DisplayResConfirm()
|
||||
{
|
||||
@ -96,22 +99,16 @@ void DisplayResConfirm::select()
|
||||
{
|
||||
switch ( widget_manager->getSelectedWgt())
|
||||
{
|
||||
case WTOK_APPLY_RES:
|
||||
//set prev resolution to current values to confirm change
|
||||
user_config->m_prev_width = user_config->m_width;
|
||||
user_config->m_prev_height = user_config->m_height;
|
||||
|
||||
// if changing to fullscreen then it has now been confirmed
|
||||
// so we need to change m_prev_windowed to confirm the change
|
||||
if (user_config->m_fullscreen && user_config->m_prev_windowed)
|
||||
user_config->m_prev_windowed = false;
|
||||
|
||||
SDL_RemoveTimer(m_timer);
|
||||
case WTOK_APPLY_RES:
|
||||
user_config->m_prev_width = user_config->m_width;
|
||||
user_config->m_prev_height = user_config->m_height;
|
||||
|
||||
SDL_RemoveTimer(m_timer);
|
||||
menu_manager->popMenu();
|
||||
break;
|
||||
case WTOK_QUIT:
|
||||
SDL_RemoveTimer(m_timer);
|
||||
menu_manager->popMenu();
|
||||
SDL_RemoveTimer(m_timer);
|
||||
menu_manager->popMenu();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
@ -120,29 +117,38 @@ void DisplayResConfirm::select()
|
||||
//-----------------------------------------------------------------------------
|
||||
void DisplayResConfirm::countdown()
|
||||
{
|
||||
if (m_counter > 1)
|
||||
{
|
||||
m_counter--;
|
||||
snprintf(m_count, MAX_MESSAGE_LENGTH, _("Confirm Resolution Within %d Seconds"), m_counter);
|
||||
widget_manager->setWgtText(WTOK_TITLE, m_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_RemoveTimer(m_timer);
|
||||
|
||||
// blacklist the resolution
|
||||
std::ostringstream o;
|
||||
o << user_config->m_width << "x" << user_config->m_height;
|
||||
user_config->m_blacklist_res.push_back (o.str());
|
||||
|
||||
menu_manager->popMenu();
|
||||
}
|
||||
if (m_counter > 1)
|
||||
{
|
||||
m_counter--;
|
||||
snprintf(m_count, MAX_MESSAGE_LENGTH, _("Confirm Resolution Within %d Seconds"), m_counter);
|
||||
widget_manager->setWgtText(WTOK_TITLE, m_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_RemoveTimer(m_timer);
|
||||
|
||||
// blacklist the resolution
|
||||
std::ostringstream o;
|
||||
o << user_config->m_width << "x" << user_config->m_height;
|
||||
user_config->m_blacklist_res.push_back (o.str());
|
||||
|
||||
if( FROM_WINDOW )
|
||||
{
|
||||
drv_toggleFullscreen();
|
||||
user_config->m_prev_windowed = false;
|
||||
user_config->m_crashed = false;
|
||||
user_config->saveConfig();
|
||||
}
|
||||
|
||||
|
||||
menu_manager->popMenu();
|
||||
}
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
Uint32 timeout(Uint32 interval, void *param)
|
||||
{
|
||||
SDL_Event event;
|
||||
SDL_Event event;
|
||||
SDL_UserEvent userevent;
|
||||
|
||||
userevent.type = SDL_USEREVENT;
|
||||
@ -154,7 +160,7 @@ Uint32 timeout(Uint32 interval, void *param)
|
||||
event.user = userevent;
|
||||
|
||||
SDL_PushEvent(&event);
|
||||
|
||||
return (interval);
|
||||
|
||||
return (interval);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
class DisplayResConfirm: public BaseGUI
|
||||
{
|
||||
public:
|
||||
DisplayResConfirm();
|
||||
DisplayResConfirm( const bool FROM_WINDOW_ );
|
||||
~DisplayResConfirm();
|
||||
|
||||
void select();
|
||||
@ -36,7 +36,8 @@ public:
|
||||
private:
|
||||
char m_count[60];
|
||||
int m_counter;
|
||||
|
||||
const bool FROM_WINDOW;
|
||||
|
||||
SDL_TimerID m_timer;
|
||||
};
|
||||
|
||||
|
@ -200,9 +200,18 @@ void MenuManager::update()
|
||||
case MENUID_CONFIG_DISPLAY:
|
||||
m_current_menu= new ConfigDisplay();
|
||||
break;
|
||||
case MENUID_DISPLAY_RES_CONFIRM:
|
||||
m_current_menu= new DisplayResConfirm();
|
||||
break;
|
||||
case MENUID_RESOLUTION_CONFIRM_FS:
|
||||
{
|
||||
const bool FROM_FULLSCREEN = false;
|
||||
m_current_menu= new DisplayResConfirm( FROM_FULLSCREEN );
|
||||
}
|
||||
break;
|
||||
case MENUID_RESOLUTION_CONFIRM_WIN:
|
||||
{
|
||||
const bool FROM_WINDOW = true;
|
||||
m_current_menu= new DisplayResConfirm( FROM_WINDOW );
|
||||
}
|
||||
break;
|
||||
case MENUID_CONFIG_SOUND:
|
||||
m_current_menu= new ConfigSound();
|
||||
break;
|
||||
|
@ -46,7 +46,8 @@ enum MenuManagerIDs
|
||||
|
||||
// menu configuration
|
||||
MENUID_CONFIG_DISPLAY,
|
||||
MENUID_DISPLAY_RES_CONFIRM,
|
||||
MENUID_RESOLUTION_CONFIRM_FS,
|
||||
MENUID_RESOLUTION_CONFIRM_WIN,
|
||||
MENUID_CONFIG_SOUND,
|
||||
MENUID_CONFIG_CONTROLS,
|
||||
MENUID_CONFIG_P1,
|
||||
|
Loading…
Reference in New Issue
Block a user