diff --git a/src/elrail.cpp b/src/elrail.cpp index 9121c60615..fb4de52fcc 100644 --- a/src/elrail.cpp +++ b/src/elrail.cpp @@ -587,10 +587,11 @@ static void DrawRailCatenaryRailway(const TileInfo *ti) /* * The "wire"-sprite position is inside the tile, i.e. 0 <= sss->?_offset < TILE_SIZE. * Therefore it is safe to use GetSlopePixelZ() for the elevation. - * Also note that the result of GetSlopePixelZ() is very special for bridge-ramps. + * Also note that the result of GetSlopePixelZ() is very special for bridge-ramps, so we round the result up or + * down to the nearest full height change. */ AddSortableSpriteToDraw(wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset, - sss->x_size, sss->y_size, sss->z_size, GetSlopePixelZ(ti->x + sss->x_offset, ti->y + sss->y_offset) + sss->z_offset, + sss->x_size, sss->y_size, sss->z_size, (GetSlopePixelZ(ti->x + sss->x_offset, ti->y + sss->y_offset) + 4) / 8 * 8 + sss->z_offset, IsTransparencySet(TO_CATENARY)); } } diff --git a/src/fontcache.h b/src/fontcache.h index 8d9be6df4a..3818517af0 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -33,12 +33,12 @@ protected: int descender; ///< The descender value of the font. int units_per_em; ///< The units per EM value of the font. - static int GetDefaultFontHeight(FontSize fs); - public: FontCache(FontSize fs); virtual ~FontCache(); + static int GetDefaultFontHeight(FontSize fs); + /** * Get the FontSize of the font. * @return The FontSize. diff --git a/src/fontcache/freetypefontcache.cpp b/src/fontcache/freetypefontcache.cpp index 70acdad68e..275daefd35 100644 --- a/src/fontcache/freetypefontcache.cpp +++ b/src/fontcache/freetypefontcache.cpp @@ -65,14 +65,14 @@ void FreeTypeFontCache::SetFontSize(FontSize fs, FT_Face face, int pixels) { if (pixels == 0) { /* Try to determine a good height based on the minimal height recommended by the font. */ - int scaled_height = ScaleGUITrad(this->GetDefaultFontHeight(this->fs)); + int scaled_height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs)); pixels = scaled_height; TT_Header *head = (TT_Header *)FT_Get_Sfnt_Table(this->face, ft_sfnt_head); if (head != nullptr) { /* Font height is minimum height plus the difference between the default * height for this font size and the small size. */ - int diff = scaled_height - ScaleGUITrad(this->GetDefaultFontHeight(FS_SMALL)); + int diff = scaled_height - ScaleGUITrad(FontCache::GetDefaultFontHeight(FS_SMALL)); /* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */ pixels = std::min(std::max(std::min(head->Lowest_Rec_PPEM, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE); } diff --git a/src/fontcache/spritefontcache.cpp b/src/fontcache/spritefontcache.cpp index 32a09539cd..f7641cd169 100644 --- a/src/fontcache/spritefontcache.cpp +++ b/src/fontcache/spritefontcache.cpp @@ -28,8 +28,8 @@ static const int ASCII_LETTERSTART = 32; ///< First printable ASCII letter. SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs), glyph_to_spriteid_map(nullptr) { this->InitializeUnicodeGlyphMap(); - this->height = ScaleGUITrad(this->GetDefaultFontHeight(this->fs)); - this->ascender = (this->height - ScaleSpriteTrad(this->GetDefaultFontHeight(this->fs))) / 2; + this->height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs)); + this->ascender = (this->height - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(this->fs))) / 2; } /** @@ -106,8 +106,8 @@ void SpriteFontCache::ClearGlyphToSpriteMap() void SpriteFontCache::ClearFontCache() { Layouter::ResetFontCache(this->fs); - this->height = ScaleGUITrad(this->GetDefaultFontHeight(this->fs)); - this->ascender = (this->height - ScaleSpriteTrad(this->GetDefaultFontHeight(this->fs))) / 2; + this->height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs)); + this->ascender = (this->height - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(this->fs))) / 2; } const Sprite *SpriteFontCache::GetGlyph(GlyphID key) diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp index e4e64f88e4..bf8a17d984 100644 --- a/src/gfx_layout.cpp +++ b/src/gfx_layout.cpp @@ -11,6 +11,7 @@ #include "gfx_layout.h" #include "string_func.h" #include "strings_func.h" +#include "zoom_func.h" #include "debug.h" #include "table/control_codes.h" @@ -345,11 +346,11 @@ FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(Font *font, const for (int i = 0; i < this->glyph_count; i++) { this->glyphs[i] = font->fc->MapCharToGlyph(chars[i]); if (isbuiltin) { - this->positions[2 * i + 1] = font->fc->GetAscender(); // Apply sprite font's ascender. + this->positions[2 * i + 1] = font->fc->GetAscender(); // Apply sprite font's ascender. } else if (chars[i] >= SCC_SPRITE_START && chars[i] <= SCC_SPRITE_END) { - this->positions[2 * i + 1] = font->fc->GetAscender() - font->fc->GetGlyph(this->glyphs[i])->height - 1; // Align sprite glyphs to font baseline. + this->positions[2 * i + 1] = (font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(font->fc->GetSize()))) / 2; // Align sprite font to centre } else { - this->positions[2 * i + 1] = 0; // No ascender adjustment. + this->positions[2 * i + 1] = 0; // No ascender adjustment. } this->positions[2 * i + 2] = this->positions[2 * i] + font->fc->GetGlyphWidth(this->glyphs[i]); this->glyph_to_char[i] = i; diff --git a/src/lang/english_AU.txt b/src/lang/english_AU.txt index 8424315fd0..f0f81701b5 100644 --- a/src/lang/english_AU.txt +++ b/src/lang/english_AU.txt @@ -3370,7 +3370,10 @@ STR_SPRITE_ALIGNER_SPRITE_TOOLTIP :{BLACK}Represen STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Move the sprite around, changing the X and Y offsets ###length 2 +STR_SPRITE_ALIGNER_CENTRE_OFFSET :{BLACK}Offset centred +STR_SPRITE_ALIGNER_CENTRE_SPRITE :{BLACK}Sprite centred +STR_SPRITE_ALIGNER_CROSSHAIR :{BLACK}Crosshair STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Reset relative STR_SPRITE_ALIGNER_RESET_TOOLTIP :{BLACK}Reset the current relative offsets diff --git a/src/lang/english_US.txt b/src/lang/english_US.txt index e2cd93ef7e..3aa42a1952 100644 --- a/src/lang/english_US.txt +++ b/src/lang/english_US.txt @@ -3371,7 +3371,10 @@ STR_SPRITE_ALIGNER_SPRITE_TOOLTIP :{BLACK}Represen STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Move the sprite around, changing the X and Y offsets. Ctrl+Click to move the sprite eight units at a time ###length 2 +STR_SPRITE_ALIGNER_CENTRE_OFFSET :{BLACK}Offset centered +STR_SPRITE_ALIGNER_CENTRE_SPRITE :{BLACK}Sprite centered +STR_SPRITE_ALIGNER_CROSSHAIR :{BLACK}Crosshair STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Reset relative STR_SPRITE_ALIGNER_RESET_TOOLTIP :{BLACK}Reset the current relative offsets diff --git a/src/lang/finnish.txt b/src/lang/finnish.txt index 06a75bdde2..1abaf940c9 100644 --- a/src/lang/finnish.txt +++ b/src/lang/finnish.txt @@ -3343,7 +3343,10 @@ STR_SPRITE_ALIGNER_SPRITE_TOOLTIP :{BLACK}Valitun STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Liikuta spriteä ympäriinsä, muuttaen X- ja Y-sijainteja. Ctrl+napsautus siirtää spriteä kahdeksan yksikköä kerralla. ###length 2 +STR_SPRITE_ALIGNER_CENTRE_OFFSET :{BLACK}Siirros keskitetty +STR_SPRITE_ALIGNER_CENTRE_SPRITE :{BLACK}Sprite keskitetty +STR_SPRITE_ALIGNER_CROSSHAIR :{BLACK}Hiusristikko STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Nollaa suhteelliset STR_SPRITE_ALIGNER_RESET_TOOLTIP :{BLACK}Nollaa suhteelliset erotukset diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp index 7580f2ae8b..d8186f8228 100644 --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -173,7 +173,7 @@ void CoreTextFontCache::SetFontSize(int pixels) { if (pixels == 0) { /* Try to determine a good height based on the height recommended by the font. */ - int scaled_height = ScaleGUITrad(this->GetDefaultFontHeight(this->fs)); + int scaled_height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs)); pixels = scaled_height; CFAutoRelease font(CTFontCreateWithFontDescriptor(this->font_desc.get(), 0.0f, nullptr)); @@ -197,7 +197,7 @@ void CoreTextFontCache::SetFontSize(int pixels) /* Font height is minimum height plus the difference between the default * height for this font size and the small size. */ - int diff = scaled_height - ScaleGUITrad(this->GetDefaultFontHeight(FS_SMALL)); + int diff = scaled_height - ScaleGUITrad(FontCache::GetDefaultFontHeight(FS_SMALL)); /* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */ pixels = std::min(std::max(std::min(min_size, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE); } diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index be01e1479d..c34a7b6208 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -13,6 +13,7 @@ #include "../../strings_func.h" #include "../../table/control_codes.h" #include "../../fontcache.h" +#include "../../zoom_func.h" #include "../../scope.h" #include "macos.h" @@ -246,7 +247,7 @@ CoreTextParagraphLayout::CoreTextVisualRun::CoreTextVisualRun(CTRunRef run, Font if (buff[this->glyph_to_char[i]] >= SCC_SPRITE_START && buff[this->glyph_to_char[i]] <= SCC_SPRITE_END) { this->glyphs[i] = font->fc->MapCharToGlyph(buff[this->glyph_to_char[i]]); this->positions[i * 2 + 0] = pts[i].x; - this->positions[i * 2 + 1] = font->fc->GetAscender() - font->fc->GetGlyph(this->glyphs[i])->height - 1; // Align sprite glyphs to font baseline. + this->positions[i * 2 + 1] = (font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(font->fc->GetSize()))) / 2; // Align sprite font to centre } else { this->glyphs[i] = gl[i]; this->positions[i * 2 + 0] = pts[i].x; diff --git a/src/os/windows/font_win32.cpp b/src/os/windows/font_win32.cpp index 467d426b59..cbad3ce69d 100644 --- a/src/os/windows/font_win32.cpp +++ b/src/os/windows/font_win32.cpp @@ -392,7 +392,7 @@ void Win32FontCache::SetFontSize(FontSize fs, int pixels) { if (pixels == 0) { /* Try to determine a good height based on the minimal height recommended by the font. */ - int scaled_height = ScaleGUITrad(this->GetDefaultFontHeight(this->fs)); + int scaled_height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs)); pixels = scaled_height; HFONT temp = CreateFontIndirect(&this->logfont); @@ -405,7 +405,7 @@ void Win32FontCache::SetFontSize(FontSize fs, int pixels) /* Font height is minimum height plus the difference between the default * height for this font size and the small size. */ - int diff = scaled_height - ScaleGUITrad(this->GetDefaultFontHeight(FS_SMALL)); + int diff = scaled_height - ScaleGUITrad(FontCache::GetDefaultFontHeight(FS_SMALL)); /* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */ pixels = std::min(std::max(std::min(otm->otmusMinimumPPEM, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE); diff --git a/src/os/windows/string_uniscribe.cpp b/src/os/windows/string_uniscribe.cpp index 883ee2949b..8374d2b7ce 100644 --- a/src/os/windows/string_uniscribe.cpp +++ b/src/os/windows/string_uniscribe.cpp @@ -14,6 +14,7 @@ #include "../../strings_func.h" #include "../../string_func.h" #include "../../table/control_codes.h" +#include "../../zoom_func.h" #include "win32.h" #include @@ -195,7 +196,7 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b if (buff[range.pos + i] >= SCC_SPRITE_START && buff[range.pos + i] <= SCC_SPRITE_END) { auto pos = range.char_to_glyph[i]; range.ft_glyphs[pos] = range.font->fc->MapCharToGlyph(buff[range.pos + i]); - range.offsets[pos].dv = range.font->fc->GetAscender() - range.font->fc->GetGlyph(range.ft_glyphs[pos])->height - 1; // Align sprite glyphs to font baseline. + range.offsets[pos].dv = (range.font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(range.font->fc->GetSize()))) / 2; // Align sprite font to centre range.advances[pos] = range.font->fc->GetGlyphWidth(range.ft_glyphs[pos]); } } diff --git a/src/table/elrail_data.h b/src/table/elrail_data.h index 12132848b8..5e1b9e792f 100644 --- a/src/table/elrail_data.h +++ b/src/table/elrail_data.h @@ -327,7 +327,9 @@ struct SortableSpriteStruct { /** Distance between wire and rail */ static const uint ELRAIL_ELEVATION = 10; /** Wires that a draw one level higher than the north corner. */ -static const uint ELRAIL_ELEVRAISE = ELRAIL_ELEVATION + TILE_HEIGHT; +static const uint ELRAIL_ELEVRAISE = ELRAIL_ELEVATION + TILE_HEIGHT + 1; +/** Wires that a draw one level lower than the north corner. */ +static const uint ELRAIL_ELEVLOWER = ELRAIL_ELEVATION - 1; static const SortableSpriteStruct RailCatenarySpriteData[] = { /* X direction @@ -345,9 +347,9 @@ static const SortableSpriteStruct RailCatenarySpriteData[] = { /* "down" tiles * Wires */ - { WSO_X_SW_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVATION }, //! 6: Wire in X pitch down, pylon on the SW end - { WSO_X_NE_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVATION }, //! 7: Wire in X pitch down, pylon on the NE end - { WSO_X_SHORT_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVATION }, //! 8: Wire in X pitch down, pylon on both ends + { WSO_X_SW_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVLOWER }, //! 6: Wire in X pitch down, pylon on the SW end + { WSO_X_NE_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVLOWER }, //! 7: Wire in X pitch down, pylon on the NE end + { WSO_X_SHORT_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVLOWER }, //! 8: Wire in X pitch down, pylon on both ends /* Y direction @@ -365,9 +367,9 @@ static const SortableSpriteStruct RailCatenarySpriteData[] = { /* "down" tiles * Wires */ - { WSO_Y_SE_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVATION }, //!15: Wire in Y pitch down, pylon on the SE end - { WSO_Y_NW_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVATION }, //!16: Wire in Y pitch down, pylon on the NW end - { WSO_Y_SHORT_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVATION }, //!17: Wire in Y pitch down, pylon on both ends + { WSO_Y_SE_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVLOWER }, //!15: Wire in Y pitch down, pylon on the SE end + { WSO_Y_NW_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVLOWER }, //!16: Wire in Y pitch down, pylon on the NW end + { WSO_Y_SHORT_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVLOWER }, //!17: Wire in Y pitch down, pylon on both ends /* NS Direction */ { WSO_NS_SHORT, 8, 0, 8, 8, 1, ELRAIL_ELEVATION }, //!18: LEFT trackbit wire, pylon on both ends diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index a37acd990f..5802ff3c8d 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -3176,10 +3176,10 @@ struct VehicleDetailsWindow : Window { /* Articulated road vehicles use a complete line. */ if (v->type == VEH_ROAD && v->HasArticulatedPart()) { - DrawVehicleImage(v, tr, INVALID_VEHICLE, EIT_IN_DETAILS, 0); + DrawVehicleImage(v, tr.WithHeight(ScaleGUITrad(GetVehicleHeight(v->type)), false), INVALID_VEHICLE, EIT_IN_DETAILS, 0); } else { Rect sr = tr.WithWidth(sprite_width, rtl); - DrawVehicleImage(v, sr, INVALID_VEHICLE, EIT_IN_DETAILS, 0); + DrawVehicleImage(v, sr.WithHeight(ScaleGUITrad(GetVehicleHeight(v->type)), false), INVALID_VEHICLE, EIT_IN_DETAILS, 0); } DrawVehicleDetails(v, tr.Indent(sprite_width, rtl), 0, 0, this->tab); diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 44497356d7..512e8f15be 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -413,12 +413,12 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button bool above = false; /* Available height below (or above, if the dropdown is placed above the widget). */ - uint available_height = std::max(GetMainViewBottom() - top - WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0U); + uint available_height = std::max(GetMainViewBottom() - top - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0); /* If the dropdown doesn't fully fit below the widget... */ if (height > available_height) { - uint available_height_above = std::max(w->top + wi_rect.top - GetMainViewTop() - WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0U); + uint available_height_above = std::max(w->top + wi_rect.top - GetMainViewTop() - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0); /* Put the dropdown above if there is more available space. */ if (available_height_above > available_height) {