Skip to content

Commit

Permalink
Reset scaling factor to 1 if display too small
Browse files Browse the repository at this point in the history
  • Loading branch information
ifreund committed Feb 23, 2019
1 parent d99ef5c commit f78d798
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 26 deletions.
18 changes: 2 additions & 16 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2528,8 +2528,8 @@ std::string options_manager::show( bool ingame, const bool world_options_only )
int scaling_factor = get_scaling_factor();
int TERMX = ::get_option<int>( "TERMINAL_X" );
int TERMY = ::get_option<int>( "TERMINAL_Y" );
TERMX += TERMX % scaling_factor;
TERMY += TERMY % scaling_factor;
TERMX -= TERMX % scaling_factor;
TERMY -= TERMY % scaling_factor;
get_option( "TERMINAL_X" ).setValue( std::max( 80 * scaling_factor, TERMX ) );
get_option( "TERMINAL_Y" ).setValue( std::max( 24 * scaling_factor, TERMY ) );
save();
Expand Down Expand Up @@ -2643,20 +2643,6 @@ void options_manager::load()
}
}

int scaling_factor = 1;
if( ::get_option<std::string>( "SCALING_FACTOR" ) == "4" ) {
scaling_factor = 4;
} else if( ::get_option<std::string>( "SCALING_FACTOR" ) == "2" ) {
scaling_factor = 2;
}
int TERMX = ::get_option<int>( "TERMINAL_X" );
int TERMY = ::get_option<int>( "TERMINAL_Y" );
TERMX += TERMX % scaling_factor;
TERMY += TERMY % scaling_factor;
get_option( "TERMINAL_X" ).setValue( std::max( 80 * scaling_factor, TERMX ) );
get_option( "TERMINAL_Y" ).setValue( std::max( 24 * scaling_factor, TERMY ) );
save();

// cache to global due to heavy usage.
trigdist = ::get_option<bool>( "CIRCLEDIST" );
use_tiles = ::get_option<bool>( "USE_TILES" );
Expand Down
74 changes: 64 additions & 10 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2963,9 +2963,72 @@ int projected_window_height()
return get_option<int>( "TERMINAL_Y" ) * fontheight;
}

void init_term_size_and_scaling_factor()
{
SDL_DisplayMode current;
int display_width, display_height;
if( SDL_GetDesktopDisplayMode( get_option<int>( "DISPLAY" ), &current ) == 0 ) {
display_width = current.w;
display_height = current.h;
} else {
dbg( D_WARNING ) << "Failed to get current Display Mode, assuming infinite display size.";
std::cout << "Failed to get current Display Mode, assuming infinite display size.";
display_width = INT_MAX;
display_height = INT_MAX;
}
std::cout << "w: " << display_width << " h: " << display_height << std::endl;

if( get_option<std::string>( "SCALING_FACTOR" ) == "4" ) {
scaling_factor = 4;
} else if( get_option<std::string>( "SCALING_FACTOR" ) == "2" ) {
scaling_factor = 2;
} else {
scaling_factor = 1;
}

int TERMX = get_option<int>( "TERMINAL_X" );
int TERMY = get_option<int>( "TERMINAL_Y" );

if( TERMX * fontwidth > display_width || 80 * fontwidth * scaling_factor > display_width ) {
std::cout << "HI" << std::endl;
if( 80 * fontwidth * scaling_factor > display_width ) {
dbg( D_INFO ) << "SCALING_FACTOR set too high for display size, resetting to 1";
scaling_factor = 1;
get_options().get_option( "SCALING_FACTOR" ).setValue( "1" );
} else {
TERMX = display_width / fontwidth;
}
}

if( TERMY * fontheight > display_height || 24 * fontheight * scaling_factor > display_height ) {
if( 24 * fontheight * scaling_factor > display_height ) {
dbg( D_INFO ) << "SCALING_FACTOR set too high for display size, resetting to 1";
scaling_factor = 1;
get_options().get_option( "SCALING_FACTOR" ).setValue( "1" );
} else {
TERMY = display_height / fontheight;
}
}

TERMX -= TERMX % scaling_factor;
TERMY -= TERMY % scaling_factor;

TERMX = std::max( 80 * scaling_factor, TERMX );
TERMY = std::max( 24 * scaling_factor, TERMY );

get_options().get_option( "TERMINAL_X" ).setValue( std::max( 80 * scaling_factor, TERMX ) );
get_options().get_option( "TERMINAL_Y" ).setValue( std::max( 24 * scaling_factor, TERMY ) );

get_options().save();

TERMINAL_WIDTH = TERMX / scaling_factor;
TERMINAL_HEIGHT = TERMY / scaling_factor;
}

//Basic Init, create the font, backbuffer, etc
void catacurses::init_interface()
{
std::cout << "init_interface" << std::endl;
last_input = input_event();
inputdelay = -1;

Expand All @@ -2978,16 +3041,7 @@ void catacurses::init_interface()

find_videodisplays();

if( get_option<std::string>( "SCALING_FACTOR" ) == "4" ) {
scaling_factor = 4;
} else if( get_option<std::string>( "SCALING_FACTOR" ) == "2" ) {
scaling_factor = 2;
} else {
scaling_factor = 1;
}

TERMINAL_WIDTH = get_option<int>( "TERMINAL_X" ) / scaling_factor;
TERMINAL_HEIGHT = get_option<int>( "TERMINAL_Y" ) / scaling_factor;
init_term_size_and_scaling_factor();

WinCreate();

Expand Down

0 comments on commit f78d798

Please sign in to comment.