From 04fc4595cfd330abb58dca13992d28636526d32b Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 13 Nov 2013 21:53:40 +0000 Subject: [PATCH] (svn r25987) [1.3] -Backport from trunk: - Fix: When clearing font cache, also clear layout cache [FS#5737] (r25860) - Fix: Goto button in order window was not always lowered when it should [FS#5783] (r25858, 25857) - Fix: Searching for a suitable font failed, if one of the fonts had no '?' glyph, and no baseset is installed [FS#5704] (r25822, r25820) - Fix: Sprite 0 was considered available, even if no baseset was loaded (r25821) --- src/blitter/32bpp_optimized.cpp | 2 +- src/blitter/32bpp_optimized.hpp | 2 +- src/blitter/32bpp_simple.cpp | 2 +- src/blitter/32bpp_simple.hpp | 2 +- src/blitter/8bpp_optimized.cpp | 2 +- src/blitter/8bpp_optimized.hpp | 2 +- src/blitter/8bpp_simple.cpp | 2 +- src/blitter/8bpp_simple.hpp | 2 +- src/blitter/base.hpp | 2 +- src/blitter/null.cpp | 2 +- src/blitter/null.hpp | 2 +- src/fontcache.cpp | 40 +++++++++++++++++++++++++++++---- src/fontcache.h | 3 ++- src/order_gui.cpp | 13 ++++++----- src/spritecache.cpp | 3 ++- 15 files changed, 59 insertions(+), 22 deletions(-) diff --git a/src/blitter/32bpp_optimized.cpp b/src/blitter/32bpp_optimized.cpp index 1c1ac816d6..4911e83140 100644 --- a/src/blitter/32bpp_optimized.cpp +++ b/src/blitter/32bpp_optimized.cpp @@ -207,7 +207,7 @@ void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, } } -Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator) +Sprite *Blitter_32bppOptimized::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) { /* streams of pixels (a, r, g, b channels) * diff --git a/src/blitter/32bpp_optimized.hpp b/src/blitter/32bpp_optimized.hpp index c8cfd91cf9..ea55d8d9fc 100644 --- a/src/blitter/32bpp_optimized.hpp +++ b/src/blitter/32bpp_optimized.hpp @@ -24,7 +24,7 @@ public: }; /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); - /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator); + /* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator); /* virtual */ const char *GetName() { return "32bpp-optimized"; } diff --git a/src/blitter/32bpp_simple.cpp b/src/blitter/32bpp_simple.cpp index 73487e54cd..539d26ff02 100644 --- a/src/blitter/32bpp_simple.cpp +++ b/src/blitter/32bpp_simple.cpp @@ -92,7 +92,7 @@ void Blitter_32bppSimple::DrawColourMappingRect(void *dst, int width, int height DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('%d')", pal); } -Sprite *Blitter_32bppSimple::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator) +Sprite *Blitter_32bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) { Blitter_32bppSimple::Pixel *dst; Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width * sizeof(*dst)); diff --git a/src/blitter/32bpp_simple.hpp b/src/blitter/32bpp_simple.hpp index f09920d0e9..59ea50c283 100644 --- a/src/blitter/32bpp_simple.hpp +++ b/src/blitter/32bpp_simple.hpp @@ -28,7 +28,7 @@ class Blitter_32bppSimple : public Blitter_32bppBase { public: /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); /* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal); - /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator); + /* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator); /* virtual */ const char *GetName() { return "32bpp-simple"; } }; diff --git a/src/blitter/8bpp_optimized.cpp b/src/blitter/8bpp_optimized.cpp index 77fc36576e..c84e7aea77 100644 --- a/src/blitter/8bpp_optimized.cpp +++ b/src/blitter/8bpp_optimized.cpp @@ -112,7 +112,7 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z } } -Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator) +Sprite *Blitter_8bppOptimized::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) { /* Make memory for all zoom-levels */ uint memory = sizeof(SpriteData); diff --git a/src/blitter/8bpp_optimized.hpp b/src/blitter/8bpp_optimized.hpp index 66fbe4091f..2be2214956 100644 --- a/src/blitter/8bpp_optimized.hpp +++ b/src/blitter/8bpp_optimized.hpp @@ -25,7 +25,7 @@ public: }; /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); - /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator); + /* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator); /* virtual */ const char *GetName() { return "8bpp-optimized"; } }; diff --git a/src/blitter/8bpp_simple.cpp b/src/blitter/8bpp_simple.cpp index f8a808186c..1d405e0eea 100644 --- a/src/blitter/8bpp_simple.cpp +++ b/src/blitter/8bpp_simple.cpp @@ -55,7 +55,7 @@ void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoom } } -Sprite *Blitter_8bppSimple::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator) +Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) { Sprite *dest_sprite; dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width); diff --git a/src/blitter/8bpp_simple.hpp b/src/blitter/8bpp_simple.hpp index 28102fcab0..1ea438639c 100644 --- a/src/blitter/8bpp_simple.hpp +++ b/src/blitter/8bpp_simple.hpp @@ -19,7 +19,7 @@ class Blitter_8bppSimple FINAL : public Blitter_8bppBase { public: /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); - /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator); + /* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator); /* virtual */ const char *GetName() { return "8bpp-simple"; } }; diff --git a/src/blitter/base.hpp b/src/blitter/base.hpp index 45aa19b7d9..91ff68c3b2 100644 --- a/src/blitter/base.hpp +++ b/src/blitter/base.hpp @@ -77,7 +77,7 @@ public: /** * Convert a sprite from the loader to our own format. */ - virtual Sprite *Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator) = 0; + virtual Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) = 0; /** * Move the destination pointer the requested amount x and y, keeping in mind diff --git a/src/blitter/null.cpp b/src/blitter/null.cpp index 470b88354f..1c2b379d1b 100644 --- a/src/blitter/null.cpp +++ b/src/blitter/null.cpp @@ -15,7 +15,7 @@ /** Instantiation of the null blitter factory. */ static FBlitter_Null iFBlitter_Null; -Sprite *Blitter_Null::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator) +Sprite *Blitter_Null::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) { Sprite *dest_sprite; dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite)); diff --git a/src/blitter/null.hpp b/src/blitter/null.hpp index 4ec5ff4763..821e01be65 100644 --- a/src/blitter/null.hpp +++ b/src/blitter/null.hpp @@ -20,7 +20,7 @@ public: /* virtual */ uint8 GetScreenDepth() { return 0; } /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) {}; /* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) {}; - /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator); + /* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator); /* virtual */ void *MoveTo(void *video, int x, int y) { return NULL; }; /* virtual */ void SetPixel(void *video, int x, int y, uint8 colour) {}; /* virtual */ void DrawRect(void *video, int width, int height, uint8 colour) {}; diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 9e0fd1e166..9e95fee642 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -75,7 +75,7 @@ public: virtual SpriteID GetUnicodeGlyph(WChar key); virtual void SetUnicodeGlyph(WChar key, SpriteID sprite); virtual void InitializeUnicodeGlyphMap(); - virtual void ClearFontCache() {} + virtual void ClearFontCache(); virtual const Sprite *GetGlyph(GlyphID key); virtual uint GetGlyphWidth(GlyphID key); virtual bool GetDrawGlyphShadow(); @@ -162,6 +162,11 @@ void SpriteFontCache::ClearGlyphToSpriteMap() this->glyph_to_spriteid_map = NULL; } +void SpriteFontCache::ClearFontCache() +{ + Layouter::ResetFontCache(this->fs); +} + const Sprite *SpriteFontCache::GetGlyph(GlyphID key) { SpriteID sprite = this->GetUnicodeGlyph(key); @@ -392,6 +397,8 @@ void FreeTypeFontCache::ClearFontCache() free(this->glyph_to_sprite); this->glyph_to_sprite = NULL; + + Layouter::ResetFontCache(this->fs); } FreeTypeFontCache::GlyphEntry *FreeTypeFontCache::GetGlyphPtr(GlyphID key) @@ -458,9 +465,34 @@ const Sprite *FreeTypeFontCache::GetGlyph(GlyphID key) if (key == 0) { GlyphID question_glyph = this->MapCharToGlyph('?'); if (question_glyph == 0) { - /* The font misses the '?' character. Use sprite font. */ - SpriteID sprite = this->GetUnicodeGlyph(key); - Sprite *spr = (Sprite*)GetRawSprite(sprite, ST_FONT, AllocateFont); + /* The font misses the '?' character. Use built-in sprite. + * Note: We cannot use the baseset as this also has to work in the bootstrap GUI. */ +#define CPSET { 0, 0, 0, 0, 1 } +#define CP___ { 0, 0, 0, 0, 0 } + static SpriteLoader::CommonPixel builtin_questionmark_data[10 * 8] = { + CP___, CP___, CPSET, CPSET, CPSET, CPSET, CP___, CP___, + CP___, CPSET, CPSET, CP___, CP___, CPSET, CPSET, CP___, + CP___, CP___, CP___, CP___, CP___, CPSET, CPSET, CP___, + CP___, CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, + CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, + CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, + CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, + CP___, CP___, CP___, CP___, CP___, CP___, CP___, CP___, + CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, + CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, + }; +#undef CPSET +#undef CP___ + static const SpriteLoader::Sprite builtin_questionmark = { + 10, // height + 8, // width + 0, // x_offs + 0, // y_offs + ST_FONT, + builtin_questionmark_data + }; + + Sprite *spr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&builtin_questionmark, AllocateFont); assert(spr != NULL); new_glyph.sprite = spr; new_glyph.width = spr->width + (this->fs != FS_NORMAL); diff --git a/src/fontcache.h b/src/fontcache.h index 1f52ddcdc4..646adff1aa 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -159,7 +159,8 @@ static inline void InitializeUnicodeGlyphMap() } } -static inline void ClearFontCache() { +static inline void ClearFontCache() +{ for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) { FontCache::Get(fs)->ClearFontCache(); } diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 845c0c3e57..71f80163bf 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -481,6 +481,7 @@ struct OrdersWindow : public Window { private: /** Under what reason are we using the PlaceObject functionality? */ enum OrderPlaceObjectState { + OPOS_NONE, OPOS_GOTO, OPOS_CONDITIONAL, OPOS_SHARE, @@ -631,7 +632,6 @@ private: */ void OrderClick_Conditional(int i) { - this->LowerWidget(WID_O_GOTO); this->SetWidgetDirty(WID_O_GOTO); SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_NONE, this); this->goto_type = OPOS_CONDITIONAL; @@ -643,7 +643,6 @@ private: */ void OrderClick_Share(int i) { - this->LowerWidget(WID_O_GOTO); this->SetWidgetDirty(WID_O_GOTO); SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_VEHICLE, this); this->goto_type = OPOS_SHARE; @@ -810,6 +809,7 @@ public: this->selected_order = -1; this->order_over = INVALID_VEH_ORDER_ID; + this->goto_type = OPOS_NONE; this->owner = v->owner; this->UpdateAutoRefitState(); @@ -1101,7 +1101,11 @@ public: virtual void OnPaint() { - if (this->vehicle->owner != _local_company) this->selected_order = -1; // Disable selection any selected row at a competitor order window. + if (this->vehicle->owner != _local_company) { + this->selected_order = -1; // Disable selection any selected row at a competitor order window. + } else { + this->SetWidgetLoweredState(WID_O_GOTO, this->goto_type != OPOS_NONE); + } this->DrawWidgets(); } @@ -1189,7 +1193,6 @@ public: switch (widget) { case WID_O_ORDER_LIST: { if (this->goto_type == OPOS_CONDITIONAL) { - this->goto_type = OPOS_GOTO; VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top); if (order_id != INVALID_VEH_ORDER_ID) { Order order; @@ -1477,7 +1480,7 @@ public: virtual void OnPlaceObjectAbort() { - this->RaiseWidget(WID_O_GOTO); + this->goto_type = OPOS_NONE; this->SetWidgetDirty(WID_O_GOTO); /* Remove drag highlighting if it exists. */ diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 767282d1eb..9cd2a6ab15 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -118,9 +118,10 @@ bool SkipSpriteData(byte type, uint16 num) /* Check if the given Sprite ID exists */ bool SpriteExists(SpriteID id) { + if (id >= _spritecache_items) return false; + /* Special case for Sprite ID zero -- its position is also 0... */ if (id == 0) return true; - if (id >= _spritecache_items) return false; return !(GetSpriteCache(id)->file_pos == 0 && GetSpriteCache(id)->file_slot == 0); }