Auto-resize all buttons and fonts, when screen resoluition changes
This commit is contained in:
@@ -757,12 +757,12 @@ struct AIConfigWindow : public Window {
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_AIC_GAMELIST:
|
||||
this->line_height = GetMinSizing(NWST_STEP, _settings_client.gui.min_step + WD_MATRIX_TOP + WD_MATRIX_BOTTOM);
|
||||
this->line_height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM);
|
||||
size->height = this->line_height;
|
||||
break;
|
||||
|
||||
case WID_AIC_LIST:
|
||||
this->line_height = GetMinSizing(NWST_STEP, _settings_client.gui.min_step + WD_MATRIX_TOP + WD_MATRIX_BOTTOM);
|
||||
this->line_height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM);
|
||||
size->height = 8 * this->line_height;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ static void LoadFreeTypeFont(FontSize fs)
|
||||
return;
|
||||
|
||||
found_face:
|
||||
new FreeTypeFontCache(fs, face, settings->size);
|
||||
new FreeTypeFontCache(fs, face, RescaleFrom854x480(settings->size));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "gfx_type.h"
|
||||
#include "strings_type.h"
|
||||
#include "string_type.h"
|
||||
#include "core/math_func.hpp"
|
||||
|
||||
void GameLoop();
|
||||
|
||||
@@ -196,6 +197,16 @@ static inline int Center(int top, int height, uint size = FONT_HEIGHT_NORMAL)
|
||||
return top + (height - size) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns fint/button size, rescaled to current screen resolution from the base Android resolution, which is 854x480
|
||||
* @param value The value to rescale
|
||||
* @return Rescaled value, using lesser of the curret screen coordinates
|
||||
*/
|
||||
static inline int RescaleFrom854x480(int value)
|
||||
{
|
||||
return min(value * _cur_resolution.width / 854, value * _cur_resolution.height / 480);
|
||||
}
|
||||
|
||||
extern DrawPixelInfo *_cur_dpi;
|
||||
|
||||
TextColour GetContrastColour(uint8 background);
|
||||
|
||||
@@ -525,7 +525,7 @@ public:
|
||||
}
|
||||
|
||||
case WID_NCL_MATRIX:
|
||||
resize->height = GetMinSizing(NWST_STEP, _settings_client.gui.min_step + WD_MATRIX_TOP + WD_MATRIX_BOTTOM);
|
||||
resize->height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM);
|
||||
size->height = 6 * resize->height;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ struct NewGRFParametersWindow : public Window {
|
||||
}
|
||||
|
||||
case WID_NP_BACKGROUND:
|
||||
this->line_height = _settings_client.gui.min_step + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
||||
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
||||
|
||||
resize->width = 1;
|
||||
resize->height = this->line_height;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "textfile_gui.h"
|
||||
#include "stringfilter_type.h"
|
||||
#include "querystring_gui.h"
|
||||
#include "fontcache.h"
|
||||
|
||||
|
||||
static const StringID _driveside_dropdown[] = {
|
||||
@@ -506,6 +507,29 @@ struct GameOptionsWindow : Window {
|
||||
|
||||
case WID_GO_RESOLUTION_DROPDOWN: // Change resolution
|
||||
if (index < _num_resolutions && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
|
||||
// Reinit all GUI elements and fonts, so they will rescale
|
||||
InitFreeType(true);
|
||||
CheckForMissingGlyphs();
|
||||
|
||||
DeleteAllNonVitalWindows();
|
||||
|
||||
switch (_game_mode) {
|
||||
case GM_MENU:
|
||||
DeleteWindowById(WC_SELECT_GAME, 0);
|
||||
extern void ShowSelectGameWindow();
|
||||
ShowSelectGameWindow();
|
||||
break;
|
||||
|
||||
case GM_NORMAL:
|
||||
case GM_EDITOR:
|
||||
HideVitalWindows();
|
||||
ShowVitalWindows();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
this->SetDirty();
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -784,6 +784,7 @@ void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
|
||||
break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
min_size = RescaleFrom854x480(min_size);
|
||||
|
||||
this->min_x = max(min_x, min_size);
|
||||
this->min_y = max(min_y, min_size);
|
||||
@@ -2942,6 +2943,7 @@ uint GetMinSizing(NWidSizingType type, uint min_1)
|
||||
break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
min_sizing = RescaleFrom854x480(min_sizing);
|
||||
|
||||
return max(min_sizing, min_1);
|
||||
}
|
||||
|
||||
@@ -1822,7 +1822,7 @@ void CheckWindowMinSizings()
|
||||
SETTING_BUTTON_WIDTH = 2 * SETTING_BUTTON_HEIGHT;
|
||||
|
||||
extern uint _tooltip_width;
|
||||
_tooltip_width = max<uint>(194, 10 * _settings_client.gui.min_button);
|
||||
_tooltip_width = max<uint>(194, 10 * RescaleFrom854x480(_settings_client.gui.min_button));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user