Fix crash when launching game with non-default GUI scale in config
See: #459
This commit is contained in:
@@ -2361,7 +2361,7 @@ void UpdateGUIZoom()
|
|||||||
* @returns true when the zoom level has changed, caller must call ReInitAllWindows(true)
|
* @returns true when the zoom level has changed, caller must call ReInitAllWindows(true)
|
||||||
* after resizing the application's window/buffer.
|
* after resizing the application's window/buffer.
|
||||||
*/
|
*/
|
||||||
bool AdjustGUIZoom(bool automatic)
|
bool AdjustGUIZoom(AdjustGUIZoomMode mode)
|
||||||
{
|
{
|
||||||
ZoomLevel old_zoom = _gui_zoom;
|
ZoomLevel old_zoom = _gui_zoom;
|
||||||
int old_scale = _gui_scale;
|
int old_scale = _gui_scale;
|
||||||
@@ -2373,14 +2373,14 @@ bool AdjustGUIZoom(bool automatic)
|
|||||||
GfxClearSpriteCache();
|
GfxClearSpriteCache();
|
||||||
VideoDriver::GetInstance()->ClearSystemSprites();
|
VideoDriver::GetInstance()->ClearSystemSprites();
|
||||||
UpdateCursorSize();
|
UpdateCursorSize();
|
||||||
UpdateRouteStepSpriteSize();
|
if (mode != AGZM_STARTUP) UpdateRouteStepSpriteSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClearFontCache();
|
ClearFontCache();
|
||||||
UpdateFontHeightCache();
|
UpdateFontHeightCache();
|
||||||
LoadStringWidthTable();
|
LoadStringWidthTable();
|
||||||
UpdateAllVirtCoords();
|
UpdateAllVirtCoords();
|
||||||
FixTitleGameZoom();
|
if (mode != AGZM_STARTUP) FixTitleGameZoom();
|
||||||
|
|
||||||
extern void FlushDeparturesWindowTextCaches();
|
extern void FlushDeparturesWindowTextCaches();
|
||||||
FlushDeparturesWindowTextCaches();
|
FlushDeparturesWindowTextCaches();
|
||||||
@@ -2389,7 +2389,7 @@ bool AdjustGUIZoom(bool automatic)
|
|||||||
to move around when the application is moved to a screen with different DPI. */
|
to move around when the application is moved to a screen with different DPI. */
|
||||||
auto zoom_shift = old_zoom - _gui_zoom;
|
auto zoom_shift = old_zoom - _gui_zoom;
|
||||||
for (Window *w : Window::IterateFromBack()) {
|
for (Window *w : Window::IterateFromBack()) {
|
||||||
if (automatic) {
|
if (mode == AGZM_AUTOMATIC) {
|
||||||
w->left = (w->left * _gui_scale) / old_scale;
|
w->left = (w->left * _gui_scale) / old_scale;
|
||||||
w->top = (w->top * _gui_scale) / old_scale;
|
w->top = (w->top * _gui_scale) / old_scale;
|
||||||
w->width = (w->width * _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 DrawMouseCursor();
|
||||||
void ScreenSizeChanged();
|
void ScreenSizeChanged();
|
||||||
void GameSizeChanged();
|
void GameSizeChanged();
|
||||||
bool AdjustGUIZoom(bool automatic);
|
|
||||||
void UndrawMouseCursor();
|
void UndrawMouseCursor();
|
||||||
|
|
||||||
|
enum AdjustGUIZoomMode {
|
||||||
|
AGZM_MANUAL,
|
||||||
|
AGZM_AUTOMATIC,
|
||||||
|
AGZM_STARTUP,
|
||||||
|
};
|
||||||
|
bool AdjustGUIZoom(AdjustGUIZoomMode mode);
|
||||||
|
|
||||||
/** Size of the buffer used for drawing strings. */
|
/** Size of the buffer used for drawing strings. */
|
||||||
static const int DRAW_STRING_BUFFER = 2048;
|
static const int DRAW_STRING_BUFFER = 2048;
|
||||||
|
|
||||||
|
@@ -941,7 +941,7 @@ int openttd_main(int argc, char *argv[])
|
|||||||
_screen.zoom = ZOOM_LVL_NORMAL;
|
_screen.zoom = ZOOM_LVL_NORMAL;
|
||||||
|
|
||||||
/* The video driver is now selected, now initialise GUI zoom */
|
/* The video driver is now selected, now initialise GUI zoom */
|
||||||
AdjustGUIZoom(false);
|
AdjustGUIZoom(AGZM_STARTUP);
|
||||||
|
|
||||||
NetworkStartUp(); // initialize network-core
|
NetworkStartUp(); // initialize network-core
|
||||||
|
|
||||||
|
@@ -520,7 +520,7 @@ struct GameOptionsWindow : Window {
|
|||||||
} else {
|
} else {
|
||||||
_gui_scale_cfg = -1;
|
_gui_scale_cfg = -1;
|
||||||
this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, true);
|
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->gui_scale = _gui_scale;
|
||||||
}
|
}
|
||||||
this->SetWidgetDirty(widget);
|
this->SetWidgetDirty(widget);
|
||||||
@@ -564,7 +564,7 @@ struct GameOptionsWindow : Window {
|
|||||||
|
|
||||||
_gui_scale_cfg = this->gui_scale;
|
_gui_scale_cfg = this->gui_scale;
|
||||||
|
|
||||||
if (AdjustGUIZoom(false)) {
|
if (AdjustGUIZoom(AGZM_MANUAL)) {
|
||||||
ReInitAllWindows(true);
|
ReInitAllWindows(true);
|
||||||
this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, false);
|
this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, false);
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
|
@@ -1271,7 +1271,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
|||||||
/** Screen the window is on changed. */
|
/** Screen the window is on changed. */
|
||||||
- (void)windowDidChangeBackingProperties:(NSNotification *)notification
|
- (void)windowDidChangeBackingProperties:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
bool did_adjust = AdjustGUIZoom(true);
|
bool did_adjust = AdjustGUIZoom(AGZM_AUTOMATIC);
|
||||||
|
|
||||||
/* Reallocate screen buffer if necessary. */
|
/* Reallocate screen buffer if necessary. */
|
||||||
driver->AllocateBackingStore();
|
driver->AllocateBackingStore();
|
||||||
|
@@ -677,7 +677,7 @@ LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case WM_DPICHANGED: {
|
case WM_DPICHANGED: {
|
||||||
auto did_adjust = AdjustGUIZoom(true);
|
auto did_adjust = AdjustGUIZoom(AGZM_AUTOMATIC);
|
||||||
|
|
||||||
/* Resize the window to match the new DPI setting. */
|
/* Resize the window to match the new DPI setting. */
|
||||||
RECT *prcNewWindow = (RECT *)lParam;
|
RECT *prcNewWindow = (RECT *)lParam;
|
||||||
|
Reference in New Issue
Block a user