From 4d1843a95e26a64ff3ff0b967d721794dbf0fe46 Mon Sep 17 00:00:00 2001 From: frosch Date: Mon, 15 Aug 2016 18:32:48 +0000 Subject: (svn r27627) -Codechange: Deduplicate some cursor magic into SetMouseCursorBusy. --- src/genworld.cpp | 2 +- src/genworld_gui.cpp | 2 +- src/gfx.cpp | 13 +++++++++++++ src/gfx_func.h | 1 + src/saveload/saveload.cpp | 4 ++-- 5 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/genworld.cpp b/src/genworld.cpp index 88e1b84a5..2b2dfb5fd 100644 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -77,7 +77,7 @@ static void CleanupGeneration() { _generating_world = false; - if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); + SetMouseCursorBusy(false); /* Show all vital windows again, because we have hidden them */ if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows(); SetModalProgress(false); diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index ad64ae802..741fd75d1 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -1190,7 +1190,7 @@ struct GenerateProgressWindow : public Window { { switch (widget) { case WID_GP_ABORT: - if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); + SetMouseCursorBusy(false); ShowQuery( STR_GENERATION_ABORT_CAPTION, STR_GENERATION_ABORT_MESSAGE, diff --git a/src/gfx.cpp b/src/gfx.cpp index f3a98461d..909f6729e 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1572,6 +1572,19 @@ void CursorTick() } } +/** + * Set or unset the ZZZ cursor. + * @param busy Whether to show the ZZZ cursor. + */ +void SetMouseCursorBusy(bool busy) +{ + if (busy) { + if (_cursor.sprite == SPR_CURSOR_MOUSE) SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE); + } else { + if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); + } +} + /** * Assign a single non-animated sprite to the cursor. * @param sprite Sprite to draw for the cursor. diff --git a/src/gfx_func.h b/src/gfx_func.h index 6576dee4f..973e15f2b 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -145,6 +145,7 @@ bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int heigh /* window.cpp */ void DrawOverlappedWindowForAll(int left, int top, int right, int bottom); +void SetMouseCursorBusy(bool busy); void SetMouseCursor(CursorID cursor, PaletteID pal); void SetAnimatedMouseCursor(const AnimCursor *table); void CursorTick(); diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 724bc649b..3d6f3c494 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -2460,7 +2460,7 @@ static void SaveFileStart() { _sl.ff_state = _fast_forward; _fast_forward = 0; - if (_cursor.sprite == SPR_CURSOR_MOUSE) SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE); + SetMouseCursorBusy(true); InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_START); _sl.saveinprogress = true; @@ -2470,7 +2470,7 @@ static void SaveFileStart() static void SaveFileDone() { if (_game_mode != GM_MENU) _fast_forward = _sl.ff_state; - if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); + SetMouseCursorBusy(false); InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_FINISH); _sl.saveinprogress = false; -- cgit v1.2.3-54-g00ecf