diff --git a/src/gfx.cpp b/src/gfx.cpp index 2cae30cf0e..bec290e9f2 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -25,6 +25,7 @@ #include "core/geometry_func.hpp" #include "viewport_func.h" +#include "table/animcursors.h" #include "table/string_colours.h" #include "table/sprites.h" #include "table/control_codes.h" @@ -1725,6 +1726,20 @@ void SetAnimatedMouseCursor(std::span table) SwitchAnimatedCursor(); } +/** + * Assign an animation or a non-animated sprite to the cursor. + * @param icon New shape of the mouse cursor. + * @param pal Palette to use. + */ +void SetCursor(CursorID icon, PaletteID pal) +{ + if ((icon & ANIMCURSOR_FLAG) != 0) { + SetAnimatedMouseCursor(_animcursors[icon & ~ANIMCURSOR_FLAG]); + } else { + SetMouseCursor(icon, pal); + } +} + /** * Update cursor position based on a relative change. * diff --git a/src/gfx_func.h b/src/gfx_func.h index 9f03080678..80a4559f80 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -170,6 +170,7 @@ void DrawOverlappedWindowForAll(int left, int top, int right, int bottom); void SetMouseCursorBusy(bool busy); void SetMouseCursor(CursorID cursor, PaletteID pal); void SetAnimatedMouseCursor(std::span table); +void SetCursor(CursorID cursor, PaletteID pal); void CursorTick(); void UpdateCursorSize(); bool ChangeResInGame(int w, int h); diff --git a/src/viewport.cpp b/src/viewport.cpp index 7a5d7a20a5..0609db4b7c 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -3567,12 +3567,7 @@ void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowC VpStartPreSizing(); } - if ((icon & ANIMCURSOR_FLAG) != 0) { - SetAnimatedMouseCursor(_animcursors[icon & ~ANIMCURSOR_FLAG]); - } else { - SetMouseCursor(icon, pal); - } - + SetCursor(icon, pal); } /** Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows). */