Fix crash when launching game with non-default GUI scale in config

See: #459
pull/461/head
Jonathan G Rennison 2 years ago
parent e647075870
commit 351090ae7f

@ -2361,7 +2361,7 @@ void UpdateGUIZoom()
* @returns true when the zoom level has changed, caller must call ReInitAllWindows(true)
* after resizing the application's window/buffer.
*/
bool AdjustGUIZoom(bool automatic)
bool AdjustGUIZoom(AdjustGUIZoomMode mode)
{
ZoomLevel old_zoom = _gui_zoom;
int old_scale = _gui_scale;
@ -2373,14 +2373,14 @@ bool AdjustGUIZoom(bool automatic)
GfxClearSpriteCache();
VideoDriver::GetInstance()->ClearSystemSprites();
UpdateCursorSize();
UpdateRouteStepSpriteSize();
if (mode != AGZM_STARTUP) UpdateRouteStepSpriteSize();
}
ClearFontCache();
UpdateFontHeightCache();
LoadStringWidthTable();
UpdateAllVirtCoords();
FixTitleGameZoom();
if (mode != AGZM_STARTUP) FixTitleGameZoom();
extern void FlushDeparturesWindowTextCaches();
FlushDeparturesWindowTextCaches();
@ -2389,7 +2389,7 @@ bool AdjustGUIZoom(bool automatic)
to move around when the application is moved to a screen with different DPI. */
auto zoom_shift = old_zoom - _gui_zoom;
for (Window *w : Window::IterateFromBack()) {
if (automatic) {
if (mode == AGZM_AUTOMATIC) {
w->left = (w->left * _gui_scale) / old_scale;
w->top = (w->top * _gui_scale) / old_scale;
w->width = (w->width * _gui_scale) / old_scale;

@ -83,9 +83,15 @@ void ChangeGameSpeed(bool enable_fast_forward);
void DrawMouseCursor();
void ScreenSizeChanged();
void GameSizeChanged();
bool AdjustGUIZoom(bool automatic);
void UndrawMouseCursor();
enum AdjustGUIZoomMode {
AGZM_MANUAL,
AGZM_AUTOMATIC,
AGZM_STARTUP,
};
bool AdjustGUIZoom(AdjustGUIZoomMode mode);
/** Size of the buffer used for drawing strings. */
static const int DRAW_STRING_BUFFER = 2048;

@ -941,7 +941,7 @@ int openttd_main(int argc, char *argv[])
_screen.zoom = ZOOM_LVL_NORMAL;
/* The video driver is now selected, now initialise GUI zoom */
AdjustGUIZoom(false);
AdjustGUIZoom(AGZM_STARTUP);
NetworkStartUp(); // initialize network-core

@ -520,7 +520,7 @@ struct GameOptionsWindow : Window {
} else {
_gui_scale_cfg = -1;
this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, true);
if (AdjustGUIZoom(false)) ReInitAllWindows(true);
if (AdjustGUIZoom(AGZM_MANUAL)) ReInitAllWindows(true);
this->gui_scale = _gui_scale;
}
this->SetWidgetDirty(widget);
@ -564,7 +564,7 @@ struct GameOptionsWindow : Window {
_gui_scale_cfg = this->gui_scale;
if (AdjustGUIZoom(false)) {
if (AdjustGUIZoom(AGZM_MANUAL)) {
ReInitAllWindows(true);
this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, false);
this->SetDirty();

@ -1271,7 +1271,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
/** Screen the window is on changed. */
- (void)windowDidChangeBackingProperties:(NSNotification *)notification
{
bool did_adjust = AdjustGUIZoom(true);
bool did_adjust = AdjustGUIZoom(AGZM_AUTOMATIC);
/* Reallocate screen buffer if necessary. */
driver->AllocateBackingStore();

@ -677,7 +677,7 @@ LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
case WM_DPICHANGED: {
auto did_adjust = AdjustGUIZoom(true);
auto did_adjust = AdjustGUIZoom(AGZM_AUTOMATIC);
/* Resize the window to match the new DPI setting. */
RECT *prcNewWindow = (RECT *)lParam;

Loading…
Cancel
Save