diff options
author | frosch <frosch@openttd.org> | 2010-08-05 19:23:19 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-08-05 19:23:19 +0000 |
commit | 01833039bdcbc9f8e79de7e69f2942b3c1cca7d1 (patch) | |
tree | 6ace02975bba3b223e6e5db7b4feb9e7604eb037 /src | |
parent | b2181365b0ec791abcbc0687cf557c6efc326cfb (diff) | |
download | openttd-01833039bdcbc9f8e79de7e69f2942b3c1cca7d1.tar.xz |
(svn r20384) -Fix: Update cursor dimensions when reloading grfs resp. changing base graphics, so the cursor does not glitch if it becomes bigger.
Diffstat (limited to 'src')
-rw-r--r-- | src/gfx.cpp | 40 | ||||
-rw-r--r-- | src/gfx_func.h | 1 | ||||
-rw-r--r-- | src/gfxinit.cpp | 2 |
3 files changed, 36 insertions, 7 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp index 5d2bc2bbf..1487efe06 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1775,22 +1775,37 @@ bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int heigh return true; } -static void SetCursorSprite(CursorID cursor, PaletteID pal) +/** + * Update cursor dimension. + * Called when changing cursor sprite resp. reloading grfs. + */ +void UpdateCursorSize() { CursorVars *cv = &_cursor; - const Sprite *p; + const Sprite *p = GetSprite(GB(cv->sprite, 0, SPRITE_WIDTH), ST_NORMAL); - if (cv->sprite == cursor) return; - - p = GetSprite(GB(cursor, 0, SPRITE_WIDTH), ST_NORMAL); - cv->sprite = cursor; - cv->pal = pal; cv->size.y = p->height; cv->size.x = p->width; cv->offs.x = p->x_offs; cv->offs.y = p->y_offs; cv->dirty = true; +} + +/** + * Switch cursor to different sprite. + * @param cursor Sprite to draw for the cursor. + * @param pal Palette to use for recolouring. + */ +static void SetCursorSprite(CursorID cursor, PaletteID pal) +{ + CursorVars *cv = &_cursor; + if (cv->sprite == cursor) return; + + cv->sprite = cursor; + cv->pal = pal; + UpdateCursorSize(); + cv->short_vehicle_offset = 0; } @@ -1813,6 +1828,12 @@ void CursorTick() } } +/** + * Assign a single non-animated sprite to the cursor. + * @param sprite Sprite to draw for the cursor. + * @param pal Palette to use for recolouring. + * @see SetAnimatedMouseCursor + */ void SetMouseCursor(CursorID sprite, PaletteID pal) { /* Turn off animation */ @@ -1821,6 +1842,11 @@ void SetMouseCursor(CursorID sprite, PaletteID pal) SetCursorSprite(sprite, pal); } +/** + * Assign an animation to the cursor. + * @param table Array of animation states. + * @see SetMouseCursor + */ void SetAnimatedMouseCursor(const AnimCursor *table) { _cursor.animate_list = table; diff --git a/src/gfx_func.h b/src/gfx_func.h index 07c7c8130..41d623f94 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -159,6 +159,7 @@ void DrawOverlappedWindowForAll(int left, int top, int right, int bottom); void SetMouseCursor(CursorID cursor, PaletteID pal); void SetAnimatedMouseCursor(const AnimCursor *table); void CursorTick(); +void UpdateCursorSize(); bool ChangeResInGame(int w, int h); void SortResolutions(int count); bool ToggleFullScreen(bool fs); diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 269ee8ade..7cfb6eddf 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -207,6 +207,8 @@ void GfxLoadSprites() GfxInitSpriteMem(); LoadSpriteTables(); GfxInitPalettes(); + + UpdateCursorSize(); } bool GraphicsSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename) |