OpenTTD Source 20241224-master-gf74b0cf984
gfx.cpp File Reference

Handling of drawing text and other gfx related stuff. More...

#include "stdafx.h"
#include "gfx_layout.h"
#include "progress.h"
#include "zoom_func.h"
#include "blitter/factory.hpp"
#include "video/video_driver.hpp"
#include "strings_func.h"
#include "settings_type.h"
#include "network/network.h"
#include "network/network_func.h"
#include "window_gui.h"
#include "window_func.h"
#include "newgrf_debug.h"
#include "core/backup_type.hpp"
#include "core/container_func.hpp"
#include "core/geometry_func.hpp"
#include "viewport_func.h"
#include "table/string_colours.h"
#include "table/sprites.h"
#include "table/control_codes.h"
#include "safeguards.h"

Go to the source code of this file.

Typedefs

typedef std::pair< Point, PointLineSegment
 

Functions

static void GfxMainBlitterViewport (const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub=nullptr, SpriteID sprite_id=SPR_CURSOR_MOUSE)
 
static void GfxMainBlitter (const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub=nullptr, SpriteID sprite_id=SPR_CURSOR_MOUSE, ZoomLevel zoom=ZOOM_LVL_MIN)
 
void GfxScroll (int left, int top, int width, int height, int xo, int yo)
 
void GfxFillRect (int left, int top, int right, int bottom, int colour, FillRectMode mode)
 Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
 
static std::vector< LineSegment > MakePolygonSegments (const std::vector< Point > &shape, Point offset)
 Make line segments from a polygon defined by points, translated by an offset.
 
void GfxFillPolygon (const std::vector< Point > &shape, int colour, FillRectMode mode)
 Fill a polygon with colour.
 
static void GfxDoDrawLine (void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash=0)
 Check line clipping by using a linear equation and draw the visible part of the line given by x/y and x2/y2.
 
static bool GfxPreprocessLine (DrawPixelInfo *dpi, int &x, int &y, int &x2, int &y2, int width)
 Align parameters of a line to the given DPI and check simple clipping.
 
void GfxDrawLine (int x, int y, int x2, int y2, int colour, int width, int dash)
 
void GfxDrawLineUnscaled (int x, int y, int x2, int y2, int colour)
 
void DrawBox (int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
 Draws the projection of a parallelepiped.
 
void DrawRectOutline (const Rect &r, int colour, int width, int dash)
 Draw the outline of a Rect.
 
static void SetColourRemap (TextColour colour)
 Set the colour remap to be for the given colour.
 
static int DrawLayoutLine (const ParagraphLayouter::Line &line, int y, int left, int right, StringAlignment align, bool underline, bool truncation, TextColour default_colour)
 Drawing routine for drawing a laid out line of text.
 
int DrawString (int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
 Draw string, possibly truncated to make it fit in its allocated space.
 
int DrawString (int left, int right, int top, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
 Draw string, possibly truncated to make it fit in its allocated space.
 
int GetStringHeight (std::string_view str, int maxw, FontSize fontsize)
 Calculates height of string (in pixels).
 
int GetStringHeight (StringID str, int maxw)
 Calculates height of string (in pixels).
 
int GetStringLineCount (StringID str, int maxw)
 Calculates number of lines of string.
 
Dimension GetStringMultiLineBoundingBox (StringID str, const Dimension &suggestion)
 Calculate string bounding box for multi-line strings.
 
Dimension GetStringMultiLineBoundingBox (std::string_view str, const Dimension &suggestion)
 Calculate string bounding box for multi-line strings.
 
int DrawStringMultiLine (int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
 Draw string, possibly over multiple lines.
 
int DrawStringMultiLine (int left, int right, int top, int bottom, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
 Draw string, possibly over multiple lines.
 
Dimension GetStringBoundingBox (std::string_view str, FontSize start_fontsize)
 Return the string dimension in pixels.
 
Dimension GetStringBoundingBox (StringID strid, FontSize start_fontsize)
 Get bounding box of a string.
 
uint GetStringListWidth (std::span< const StringID > list, FontSize fontsize)
 Get maximum width of a list of strings.
 
Dimension GetStringListBoundingBox (std::span< const StringID > list, FontSize fontsize)
 Get maximum dimension of a list of strings.
 
void DrawCharCentered (char32_t c, const Rect &r, TextColour colour)
 Draw single character horizontally centered around (x,y)
 
Dimension GetSpriteSize (SpriteID sprid, Point *offset, ZoomLevel zoom)
 Get the size of a sprite.
 
static BlitterMode GetBlitterMode (PaletteID pal)
 Helper function to get the blitter mode for different types of palettes.
 
void DrawSpriteViewport (SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
 Draw a sprite in a viewport.
 
void DrawSprite (SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
 Draw a sprite, not in a viewport.
 
template<int ZOOM_BASE, bool SCALED_XY>
static void GfxBlitter (const Sprite *const sprite, int x, int y, BlitterMode mode, const SubSprite *const sub, SpriteID sprite_id, ZoomLevel zoom, const DrawPixelInfo *dst=nullptr)
 The code for setting up the blitter mode and sprite information before finally drawing the sprite.
 
std::unique_ptr< uint32_t[]> DrawSpriteToRgbaBuffer (SpriteID spriteId, ZoomLevel zoom)
 Draws a sprite to a new RGBA buffer (see Colour union) instead of drawing to the screen.
 
void LoadStringWidthTable (bool monospace)
 Initialize _stringwidth_table cache.
 
uint8_t GetCharacterWidth (FontSize size, char32_t key)
 Return width of character glyph.
 
uint8_t GetDigitWidth (FontSize size)
 Return the maximum width of single digit.
 
void GetBroadestDigit (uint *front, uint *next, FontSize size)
 Determine the broadest digits for guessing the maximum width of a n-digit number.
 
void ScreenSizeChanged ()
 
void UndrawMouseCursor ()
 
void DrawMouseCursor ()
 
void RedrawScreenRect (int left, int top, int right, int bottom)
 Repaints a specific rectangle of the screen.
 
void DrawDirtyBlocks ()
 Repaints the rectangle blocks which are marked as 'dirty'.
 
void AddDirtyBlock (int left, int top, int right, int bottom)
 Extend the internal _invalid_rect rectangle to contain the rectangle defined by the given parameters.
 
void MarkWholeScreenDirty ()
 This function mark the whole screen as dirty.
 
bool FillDrawPixelInfo (DrawPixelInfo *n, int left, int top, int width, int height)
 Set up a clipping area for only drawing into a certain area.
 
void UpdateCursorSize ()
 Update cursor dimension.
 
static void SetCursorSprite (CursorID cursor, PaletteID pal)
 Switch cursor to different sprite.
 
static void SwitchAnimatedCursor ()
 
void CursorTick ()
 
void SetMouseCursorBusy (bool busy)
 Set or unset the ZZZ cursor.
 
void SetMouseCursor (CursorID sprite, PaletteID pal)
 Assign a single non-animated sprite to the cursor.
 
void SetAnimatedMouseCursor (const AnimCursor *table)
 Assign an animation to the cursor.
 
bool ChangeResInGame (int width, int height)
 
bool ToggleFullScreen (bool fs)
 
void SortResolutions ()
 
void UpdateGUIZoom ()
 Resolve GUI zoom level, if auto-suggestion is requested.
 
bool AdjustGUIZoom (bool automatic)
 Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested.
 
void ChangeGameSpeed (bool enable_fast_forward)
 

Variables

uint8_t _dirkeys
 1 = left, 2 = up, 4 = right, 8 = down
 
bool _fullscreen
 
uint8_t _support8bpp
 
CursorVars _cursor
 
bool _ctrl_pressed
 Is Ctrl pressed?
 
bool _shift_pressed
 Is Shift pressed?
 
uint16_t _game_speed = 100
 Current game-speed; 100 is 1x, 0 is infinite.
 
bool _left_button_down
 Is left mouse button pressed?
 
bool _left_button_clicked
 Is left mouse button clicked?
 
bool _right_button_down
 Is right mouse button pressed?
 
bool _right_button_clicked
 Is right mouse button clicked?
 
DrawPixelInfo _screen
 
bool _screen_disable_anim = false
 Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
 
std::atomic< bool > _exit_game
 
GameMode _game_mode
 
SwitchMode _switch_mode
 The next mainloop command.
 
PauseMode _pause_mode
 The current pause mode.
 
GameSessionStats _game_session_stats
 Statistics about the current session.
 
static uint8_t _stringwidth_table [FS_END][224]
 Cache containing width of often used characters.
 
DrawPixelInfo_cur_dpi
 
static ReusableBuffer< uint8_t > _cursor_backup
 
ZoomLevel _gui_zoom = ZOOM_LVL_NORMAL
 GUI Zoom level.
 
ZoomLevel _font_zoom = _gui_zoom
 Sprite font Zoom level (not clamped)
 
int _gui_scale = MIN_INTERFACE_SCALE
 GUI scale, 100 is 100%.
 
int _gui_scale_cfg
 GUI scale in config.
 
static Rect _invalid_rect
 The rect for repaint.
 
static const uint8_t * _colour_remap_ptr
 
static uint8_t _string_colourremap [3]
 Recoloursprite for stringdrawing. The grf loader ensures that SpriteType::Font sprites only use colours 0 to 2.
 
static const uint DIRTY_BLOCK_HEIGHT = 8
 
static const uint DIRTY_BLOCK_WIDTH = 64
 
static uint _dirty_bytes_per_line = 0
 
static uint8_t * _dirty_blocks = nullptr
 
uint _dirty_block_colour
 

Detailed Description

Handling of drawing text and other gfx related stuff.

Definition in file gfx.cpp.

Typedef Documentation

◆ LineSegment

typedef std::pair<Point, Point> LineSegment

Definition at line 161 of file gfx.cpp.

Function Documentation

◆ AdjustGUIZoom()

bool AdjustGUIZoom ( bool  automatic)

Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested.

Parameters
automaticSet if the change is occuring due to OS DPI scaling being changed.
Returns
true when the zoom level has changed, caller must call ReInitAllWindows(true) after resizing the application's window/buffer.

Definition at line 1793 of file gfx.cpp.

References _font_zoom, _gui_scale, _gui_zoom, _settings_client, Clamp(), VideoDriver::ClearSystemSprites(), VideoDriver::GetInstance(), GfxClearFontSpriteCache(), ClientSettings::gui, LoadStringWidthTable(), SetupWidgetDimensions(), UpdateAllVirtCoords(), UpdateCursorSize(), UpdateGUIZoom(), GUISettings::zoom_max, and GUISettings::zoom_min.

Referenced by GameOptionsWindow::OnClick(), and GameOptionsWindow::OnMouseLoop().

◆ ChangeGameSpeed()

void ChangeGameSpeed ( bool  enable_fast_forward)

Definition at line 1831 of file gfx.cpp.

◆ ChangeResInGame()

bool ChangeResInGame ( int  width,
int  height 
)

Definition at line 1744 of file gfx.cpp.

◆ CursorTick()

void CursorTick ( )

Definition at line 1659 of file gfx.cpp.

◆ DrawBox()

void DrawBox ( int  x,
int  y,
int  dx1,
int  dy1,
int  dx2,
int  dy2,
int  dx3,
int  dy3 
)

Draws the projection of a parallelepiped.

This can be used to draw boxes in world coordinates.

Parameters
xScreen X-coordinate of top front corner.
yScreen Y-coordinate of top front corner.
dx1Screen X-length of first edge.
dy1Screen Y-length of first edge.
dx2Screen X-length of second edge.
dy2Screen Y-length of second edge.
dx3Screen X-length of third edge.
dy3Screen Y-length of third edge.

Definition at line 418 of file gfx.cpp.

References PC_WHITE.

Referenced by ViewportDrawBoundingBoxes().

◆ DrawCharCentered()

void DrawCharCentered ( char32_t  c,
const Rect r,
TextColour  colour 
)

Draw single character horizontally centered around (x,y)

Parameters
cCharacter (glyph) to draw
rRectangle to draw character within
colourColour to use, for details see _string_colourmap in table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h

Definition at line 905 of file gfx.cpp.

References BM_COLOUR_REMAP, CenterBounds(), FS_NORMAL, GetCharacterHeight(), GetCharacterWidth(), GetGlyph(), and SetColourRemap().

Referenced by OskWindow::DrawWidget().

◆ DrawLayoutLine()

static int DrawLayoutLine ( const ParagraphLayouter::Line line,
int  y,
int  left,
int  right,
StringAlignment  align,
bool  underline,
bool  truncation,
TextColour  default_colour 
)
static

Drawing routine for drawing a laid out line of text.

Parameters
lineString to draw.
yThe top most position to draw on.
leftThe left most position to draw on.
rightThe right most position to draw on.
alignThe alignment of the string when drawing left-to-right. In the case a right-to-left language is chosen this is inverted so it will be drawn in the right direction.
underlineWhether to underline what has been drawn or not.
truncationWhether to perform string truncation or not.
default_colourColour of text if not specified within string.
Returns
In case of left or center alignment the right most pixel we have drawn to. In case of right alignment the left most pixel we have drawn to.

Definition at line 499 of file gfx.cpp.

References _current_text_dir, _string_colourremap, BM_COLOUR_REMAP, Font::colour, Font::fc, FontCache::GetDrawGlyphShadow(), FontCache::GetGlyph(), FontCache::GetGlyphWidth(), GfxFillRect(), HasFlag(), FontCache::MapCharToGlyph(), RoundDivSU(), SA_FORCE, SA_HOR_CENTER, SA_HOR_MASK, SA_LEFT, SA_RIGHT, WidgetDimensions::scaled, ScaleGUITrad(), SetColourRemap(), TC_FORCED, TC_NO_SHADE, TD_RTL, Sprite::width, and Sprite::x_offs.

Referenced by DrawString(), and DrawStringMultiLine().

◆ DrawMouseCursor()

void DrawMouseCursor ( )

Definition at line 1297 of file gfx.cpp.

◆ DrawRectOutline()

void DrawRectOutline ( const Rect r,
int  colour,
int  width,
int  dash 
)

Draw the outline of a Rect.

Parameters
rRect to draw.
colourColour of the outline.
widthWidth of the outline.
dashLength of dashes for dashed lines. 0 means solid lines.

Definition at line 456 of file gfx.cpp.

Referenced by CargoesField::Draw(), and SpriteAlignerWindow::DrawWidget().

◆ DrawSprite()

void DrawSprite ( SpriteID  img,
PaletteID  pal,
int  x,
int  y,
const SubSprite sub,
ZoomLevel  zoom 
)

Draw a sprite, not in a viewport.

Parameters
imgImage number to draw
palPalette to use.
xLeft coordinate of image in pixels
yTop coordinate of image in pixels
subIf available, draw only specified part of the sprite
zoomZoom level of sprite

Definition at line 988 of file gfx.cpp.

References BM_NORMAL, BM_TRANSPARENT, BM_TRANSPARENT_REMAP, GB(), GetBlitterMode(), HasBit(), Normal, PALETTE_MODIFIER_TRANSPARENT, PALETTE_TEXT_RECOLOUR, PALETTE_TO_TRANSPARENT, PALETTE_WIDTH, Recolour, SetColourRemap(), and SPRITE_WIDTH.

Referenced by VehicleSpriteSeq::Draw(), StoryBookWindow::DrawActionElement(), NetworkClientListWindow::DrawButtons(), DrawCargoIconOverlay(), DrawCargoIcons(), DrawCloseBox(), DrawCommonTileSeqInGUI(), NetworkClientListWindow::DrawCompany(), DrawCompanyIcon(), DrawCompanyManagerFace(), DrawEngineList(), VehicleGroupWindow::DrawGroupInfo(), DrawHouseInGUI(), DrawNewHouseTileInGUI(), DrawNewObjectTileInGUI(), DrawOrderString(), TownAuthorityWindow::DrawRatings(), DrawRoadDepotSprite(), DrawRoadStopTile(), SettingsPage::DrawSetting(), BuildSignalWindow::DrawSignalSprite(), DrawStationTile(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehicleProfitButton(), DrawVehicleRefitWindow(), BuildAirportWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), CompanyWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), NewGRFWindow::DrawWidget(), PickerWindow::DrawWidget(), StatusBarWindow::DrawWidget(), ScenarioEditorLandscapeGenerationWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), TransparenciesWindow::DrawWidget(), BuildTreesWindow::DrawWidget(), and MainWindow::OnPaint().

◆ DrawSpriteToRgbaBuffer()

std::unique_ptr< uint32_t[]> DrawSpriteToRgbaBuffer ( SpriteID  spriteId,
ZoomLevel  zoom 
)

Draws a sprite to a new RGBA buffer (see Colour union) instead of drawing to the screen.

Parameters
spriteIdThe sprite to draw.
zoomThe zoom level at which to draw the sprites.
Returns
Pixel buffer, or nullptr if an 8bpp blitter is being used.

Definition at line 1144 of file gfx.cpp.

References _cur_palette, _screen_disable_anim, _settings_client, BM_NORMAL, Colour::data, GB(), BlitterFactory::GetCurrentBlitter(), Blitter::GetScreenDepth(), GetSpriteSize(), ClientSettings::gui, Normal, Palette::palette, Backup< T >::Restore(), SPRITE_WIDTH, and GUISettings::zoom_max.

◆ DrawSpriteViewport()

void DrawSpriteViewport ( SpriteID  img,
PaletteID  pal,
int  x,
int  y,
const SubSprite sub 
)

Draw a sprite in a viewport.

Parameters
imgImage number to draw
palPalette to use.
xLeft coordinate of image in viewport, scaled by zoom
yTop coordinate of image in viewport, scaled by zoom
subIf available, draw only specified part of the sprite

Definition at line 960 of file gfx.cpp.

References BM_NORMAL, BM_TRANSPARENT, BM_TRANSPARENT_REMAP, GB(), GetBlitterMode(), HasBit(), Normal, PALETTE_MODIFIER_TRANSPARENT, PALETTE_TEXT_RECOLOUR, PALETTE_TO_TRANSPARENT, PALETTE_WIDTH, Recolour, SetColourRemap(), and SPRITE_WIDTH.

◆ DrawString() [1/2]

int DrawString ( int  left,
int  right,
int  top,
std::string_view  str,
TextColour  colour,
StringAlignment  align,
bool  underline,
FontSize  fontsize 
)

Draw string, possibly truncated to make it fit in its allocated space.

Parameters
leftThe left most position to draw on.
rightThe right most position to draw on.
topThe top most position to draw on.
strString to draw.
colourColour used for drawing the string, for details see _string_colourmap in table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
alignThe alignment of the string when drawing left-to-right. In the case a right-to-left language is chosen this is inverted so it will be drawn in the right direction.
underlineWhether to underline what has been drawn or not.
fontsizeThe size of the initial characters.
Returns
In case of left or center alignment the right most pixel we have drawn to. In case of right alignment the left most pixel we have drawn to.

Definition at line 657 of file gfx.cpp.

References DrawLayoutLine(), FS_LARGE, FS_MONO, FS_NORMAL, FS_SMALL, and GetCharacterHeight().

Referenced by CargoesField::Draw(), StoryBookWindow::DrawActionElement(), TownAuthorityWindow::DrawActions(), DrawAircraftDetails(), DrawAircraftPurchaseInfo(), TimetableWindow::DrawArrivalDeparturePanel(), DrawButtonDropdown(), DrawCaption(), StationViewWindow::DrawCargoRatings(), DrawCategories(), DrawCategory(), NetworkClientListWindow::DrawCompany(), CompanyInfrastructureWindow::DrawCountLine(), NetworkContentListWindow::DrawDetails(), FramerateWindow::DrawElementTimesColumn(), DrawEngineList(), StationViewWindow::DrawEntries(), DrawFrame(), BaseGraphWindow::DrawGraph(), VehicleGroupWindow::DrawGroupInfo(), SmallMapWindow::DrawIndustryNames(), IndustryViewWindow::DrawInfo(), DrawInset(), DrawLabel(), GoalListWindow::DrawListColumn(), NetworkContentListWindow::DrawMatrix(), DrawNewsString(), DrawOrderString(), DrawPrice(), TownAuthorityWindow::DrawRatings(), DrawRoadVehDetails(), NetworkGameWindow::DrawServerLine(), SettingEntry::DrawSetting(), SettingsPage::DrawSetting(), DrawShipDetails(), DrawSliderWidget(), DrawSmallOrderList(), DrawString(), TimetableWindow::DrawSummaryPanel(), DrawText(), TimetableWindow::DrawTimetablePanel(), SmallMapWindow::DrawTowns(), DrawTrainDetails(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehiclePurchaseInfo(), DrawVehicleRefitWindow(), AIConfigWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), CheatWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), FramerateWindow::DrawWidget(), FrametimeGraphWindow::DrawWidget(), GSConfigWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), BaseGraphWindow::DrawWidget(), PaymentRatesGraphWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), IndustryProductionGraphWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), PerformanceLeagueWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), LinkGraphLegendWindow::DrawWidget(), LandInfoWindow::DrawWidget(), AboutWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), MusicWindow::DrawWidget(), BaseNetworkContentDownloadStatusWindow::DrawWidget(), NetworkStartServerWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SavePresetWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), OrdersWindow::DrawWidget(), PickerWindow::DrawWidget(), ScriptListWindow::DrawWidget(), ScriptSettingsWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), SignListWindow::DrawWidget(), SmallMapWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), StatusBarWindow::DrawWidget(), StoryBookWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TextfileWindow::DrawWidget(), ScenarioEditorToolbarWindow::DrawWidget(), TownViewWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), VehicleViewWindow::DrawWidget(), ScriptDebugWindow::DrawWidgetLog(), DrawYearColumn(), BuildAirportWindow::OnPaint(), IConsoleWindow::OnPaint(), HighScoreWindow::OnPaint(), StationsWndShowStationRating(), TrainDetailsCapacityTab(), TrainDetailsCargoTab(), and TrainDetailsInfoTab().

◆ DrawString() [2/2]

int DrawString ( int  left,
int  right,
int  top,
StringID  str,
TextColour  colour,
StringAlignment  align,
bool  underline,
FontSize  fontsize 
)

Draw string, possibly truncated to make it fit in its allocated space.

Parameters
leftThe left most position to draw on.
rightThe right most position to draw on.
topThe top most position to draw on.
strString to draw.
colourColour used for drawing the string, for details see _string_colourmap in table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
alignThe alignment of the string when drawing left-to-right. In the case a right-to-left language is chosen this is inverted so it will be drawn in the right direction.
underlineWhether to underline what has been drawn or not.
fontsizeThe size of the initial characters.
Returns
In case of left or center alignment the right most pixel we have drawn to. In case of right alignment the left most pixel we have drawn to.

Definition at line 693 of file gfx.cpp.

References DrawString(), and GetString().

◆ DrawStringMultiLine() [1/2]

int DrawStringMultiLine ( int  left,
int  right,
int  top,
int  bottom,
std::string_view  str,
TextColour  colour,
StringAlignment  align,
bool  underline,
FontSize  fontsize 
)

Draw string, possibly over multiple lines.

Parameters
leftThe left most position to draw on.
rightThe right most position to draw on.
topThe top most position to draw on.
bottomThe bottom most position to draw on.
strString to draw.
colourColour used for drawing the string, for details see _string_colourmap in table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
alignThe horizontal and vertical alignment of the string.
underlineWhether to underline all strings
fontsizeThe size of the initial characters.
Returns
If align is SA_BOTTOM, the top to where we have written, else the bottom to where we have written.

Definition at line 774 of file gfx.cpp.

References DrawLayoutLine(), Layouter::GetBounds(), RoundDivSU(), SA_BOTTOM, SA_TOP, SA_VERT_CENTER, and SA_VERT_MASK.

Referenced by StationViewWindow::DrawAcceptedCargo(), StationViewWindow::DrawCargoRatings(), NetworkContentListWindow::DrawDetails(), BaseGraphWindow::DrawGraph(), IndustryViewWindow::DrawInfo(), DrawStationCoverageAreaText(), DrawStringMultiLine(), BuildAirportWindow::DrawWidget(), BootstrapErrorWindow::DrawWidget(), BootstrapAskForDownloadWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), CompanyWindow::DrawWidget(), BuyCompanyWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), GoalQuestionWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), SelectGameWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), LandInfoWindow::DrawWidget(), TooltipsWindow::DrawWidget(), QueryWindow::DrawWidget(), BaseNetworkContentDownloadStatusWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), NetworkAskRelayWindow::DrawWidget(), NetworkAskSurveyWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), NewsWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), ScriptListWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), StoryBookWindow::DrawWidget(), TextfileWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), TownViewWindow::DrawWidget(), BuildHouseWindow::DrawWidget(), RefitWindow::DrawWidget(), NetworkDrawChatMessage(), IConsoleWindow::OnPaint(), EndGameWindow::OnPaint(), HighScoreWindow::OnPaint(), GameSettingsWindow::OnPaint(), ShowAdditionalText(), and ShowRefitOptionsList().

◆ DrawStringMultiLine() [2/2]

int DrawStringMultiLine ( int  left,
int  right,
int  top,
int  bottom,
StringID  str,
TextColour  colour,
StringAlignment  align,
bool  underline,
FontSize  fontsize 
)

Draw string, possibly over multiple lines.

Parameters
leftThe left most position to draw on.
rightThe right most position to draw on.
topThe top most position to draw on.
bottomThe bottom most position to draw on.
strString to draw.
colourColour used for drawing the string, for details see _string_colourmap in table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
alignThe horizontal and vertical alignment of the string.
underlineWhether to underline all strings
fontsizeThe size of the initial characters.
Returns
If align is SA_BOTTOM, the top to where we have written, else the bottom to where we have written.

Definition at line 836 of file gfx.cpp.

References DrawStringMultiLine(), and GetString().

◆ FillDrawPixelInfo()

bool FillDrawPixelInfo ( DrawPixelInfo n,
int  left,
int  top,
int  width,
int  height 
)

Set up a clipping area for only drawing into a certain area.

To do this, Fill a DrawPixelInfo object with the supplied relative rectangle, backup the original (calling) _cur_dpi and assign the just returned DrawPixelInfo _cur_dpi. When you are done, give restore _cur_dpi's original value

Parameters
*nthe DrawPixelInfo that will be the clipping rectangle box allowed for drawing
left,top,width,heightthe relative coordinates of the clipping rectangle relative to the current _cur_dpi. This will most likely be the offset from the calling window coordinates
Returns
return false if the requested rectangle is not possible with the current dpi pointer. Only continue of the return value is true, or you'll get some nasty results

Definition at line 1548 of file gfx.cpp.

References BlitterFactory::GetCurrentBlitter(), Blitter::MoveTo(), and ZOOM_LVL_MIN.

Referenced by NWidgetMatrix::Draw(), NWidgetLeaf::Draw(), DrawRoadVehImage(), DrawTrainImage(), BuildDocksDepotWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), IndustryCargoesWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), PickerWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), BuildRailDepotWindow::DrawWidget(), BuildRoadDepotWindow::DrawWidget(), BuildRoadStationWindow::DrawWidget(), SmallMapWindow::DrawWidget(), StoryBookWindow::DrawWidget(), TextfileWindow::DrawWidget(), and ScriptDebugWindow::DrawWidgetLog().

◆ GetBlitterMode()

static BlitterMode GetBlitterMode ( PaletteID  pal)
static

Helper function to get the blitter mode for different types of palettes.

Parameters
palThe palette to get the blitter mode for.
Returns
The blitter mode associated with the palette.

Definition at line 942 of file gfx.cpp.

References BM_BLACK_REMAP, BM_COLOUR_REMAP, BM_CRASH_REMAP, BM_NORMAL, PALETTE_ALL_BLACK, and PALETTE_CRASH.

Referenced by DrawSprite(), and DrawSpriteViewport().

◆ GetBroadestDigit()

void GetBroadestDigit ( uint *  front,
uint *  next,
FontSize  size 
)

Determine the broadest digits for guessing the maximum width of a n-digit number.

Parameters
[out]frontBroadest digit, which is not 0. (Use this digit as first digit for numbers with more than one digit.)
[out]nextBroadest digit, including 0. (Use this digit for all digits, except the first one; or for numbers with only one digit.)
sizeFont of the digit

Definition at line 1255 of file gfx.cpp.

References GetCharacterWidth().

Referenced by SetDParamMaxDigits().

◆ GetCharacterWidth()

uint8_t GetCharacterWidth ( FontSize  size,
char32_t  key 
)

Return width of character glyph.

Parameters
sizeFont of the character
keyCharacter code glyph
Returns
Width of the character glyph

Definition at line 1227 of file gfx.cpp.

References _stringwidth_table, and GetGlyphWidth().

Referenced by DrawCharCentered(), GetBroadestDigit(), GetDigitWidth(), FallbackParagraphLayout::NextLine(), and IConsoleWindow::OnInit().

◆ GetDigitWidth()

uint8_t GetDigitWidth ( FontSize  size)

Return the maximum width of single digit.

Parameters
sizeFont of the digit
Returns
Width of the digit.

Definition at line 1240 of file gfx.cpp.

References GetCharacterWidth().

Referenced by BuildSignalWindow::UpdateWidgetSize().

◆ GetSpriteSize()

Dimension GetSpriteSize ( SpriteID  sprid,
Point offset,
ZoomLevel  zoom 
)

Get the size of a sprite.

Parameters
spridSprite to examine.
[out]offsetOptionally returns the sprite position offset.
zoomThe zoom level applicable to the sprite.
Returns
Sprite size in pixels.
Note
The size assumes (0, 0) as top-left coordinate and ignores any part of the sprite drawn at the left or above that position.

Definition at line 922 of file gfx.cpp.

References Sprite::height, Normal, UnScaleByZoom(), Sprite::width, Sprite::x_offs, and Sprite::y_offs.

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), StoryBookWindow::DrawActionElement(), DrawCargoIconOverlay(), DrawCloseBox(), NetworkClientListWindow::DrawCompany(), DrawCompanyManagerFace(), DrawEngineList(), DrawOrderString(), BuildSignalWindow::DrawSignalSprite(), DrawSpriteToRgbaBuffer(), TimetableWindow::DrawTimetablePanel(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehicleRefitWindow(), BuildAirportWindow::DrawWidget(), CompanyWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), LinkGraphLegendWindow::DrawWidget(), NewGRFWindow::DrawWidget(), OrdersWindow::DrawWidget(), PickerWindow::DrawWidget(), SignListWindow::DrawWidget(), StatusBarWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), ScriptDebugWindow::DrawWidgetCompanyButton(), GetLargestCargoIconSize(), GetMaxTreeSpriteSize(), StoryBookWindow::GetPageElementHeight(), GetRailTypeDropDownList(), GetScaledSpriteSize(), MakeCompanyButtonRows(), MakeNWidgetCompanyLines(), CheatWindow::OnInit(), SelectCompanyManagerFaceWindow::OnInit(), BuildSignalWindow::OnInit(), GameSettingsWindow::OnInit(), TownAuthorityWindow::OnInit(), MainWindow::OnPaint(), NetworkClientListWindow::OnTooltip(), BuildAirportWindow::UpdateWidgetSize(), SelectCompanyLiveryWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), PerformanceLeagueWindow::UpdateWidgetSize(), ScriptLeagueWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), SignListWindow::UpdateWidgetSize(), and TownDirectoryWindow::UpdateWidgetSize().

◆ GetStringBoundingBox() [1/2]

Dimension GetStringBoundingBox ( std::string_view  str,
FontSize  start_fontsize 
)

Return the string dimension in pixels.

The height and width are returned in a single Dimension value. TINYFONT, BIGFONT modifiers are only supported as the first character of the string. The returned dimensions are therefore a rough estimation correct for all the current strings but not every possible combination

Parameters
strstring to calculate pixel-width
start_fontsizeFontsize to start the text with
Returns
string width and height in pixels

Definition at line 851 of file gfx.cpp.

References Layouter::GetBounds().

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), DrawCaption(), DrawEngineList(), SmallMapWindow::DrawIndustryNames(), DrawLabel(), DrawSliderWidget(), DrawText(), TimetableWindow::DrawTimetablePanel(), CheatWindow::DrawWidget(), OrdersWindow::DrawWidget(), BaseVehicleListWindow::GetActionDropdownSize(), IndustryDirectoryWindow::GetIndustryListWidth(), ExpensesList::GetListWidth(), GetMaxCategoriesWidth(), StoryBookWindow::GetPageElementFloatWidth(), StoryBookWindow::GetPageElementHeight(), GetStringBoundingBox(), GetStringListBoundingBox(), GetStringListWidth(), GetUnitNumberWidth(), NWidgetSocialPlugins::GetWidestPlugin(), BaseGraphWindow::GetYLabelWidth(), TextfileWindow::LoadText(), SelectCompanyManagerFaceWindow::OnInit(), IConsoleWindow::OnInit(), IndustryCargoesWindow::OnInit(), SmallMapWindow::OnInit(), BaseVehicleListWindow::OnInit(), ScriptDebugWindow::OnInvalidateData(), RefitWindow::OnInvalidateData(), GoalListWindow::OnPaint(), NWidgetBackground::SetupSmallestSize(), NWidgetLeaf::SetupSmallestSize(), NWidgetResizeBase::UpdateMultilineWidgetSize(), ViewportSign::UpdatePosition(), BuildAirportWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), BootstrapErrorWindow::UpdateWidgetSize(), BootstrapAskForDownloadWindow::UpdateWidgetSize(), BuildBridgeWindow::UpdateWidgetSize(), BuildVehicleWindow::UpdateWidgetSize(), CheatWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), SelectCompanyLiveryWindow::UpdateWidgetSize(), SelectCompanyManagerFaceWindow::UpdateWidgetSize(), CompanyInfrastructureWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), SetDateWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), SaveLoadWindow::UpdateWidgetSize(), FramerateWindow::UpdateWidgetSize(), FrametimeGraphWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), GoalListWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), PaymentRatesGraphWindow::UpdateWidgetSize(), PerformanceRatingDetailWindow::UpdateWidgetSize(), IndustryProductionGraphWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), IndustryDirectoryWindow::UpdateWidgetSize(), PerformanceLeagueWindow::UpdateWidgetSize(), ScriptLeagueWindow::UpdateWidgetSize(), LinkGraphLegendWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), AboutWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), MusicTrackSelectionWindow::UpdateWidgetSize(), MusicWindow::UpdateWidgetSize(), NetworkContentListWindow::UpdateWidgetSize(), BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), NetworkStartServerWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), NetworkJoinStatusWindow::UpdateWidgetSize(), NetworkAskRelayWindow::UpdateWidgetSize(), NetworkAskSurveyWindow::UpdateWidgetSize(), SpriteAlignerWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), NewGRFWindow::UpdateWidgetSize(), SavePresetWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), NewsWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), GameSettingsWindow::UpdateWidgetSize(), CustomCurrencyWindow::UpdateWidgetSize(), SignListWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), StationViewWindow::UpdateWidgetSize(), SelectStationWindow< T >::UpdateWidgetSize(), StatusBarWindow::UpdateWidgetSize(), StoryBookWindow::UpdateWidgetSize(), SubsidyListWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), ScenarioEditorToolbarWindow::UpdateWidgetSize(), TownAuthorityWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), VehicleListWindow::UpdateWidgetSize(), VehicleDetailsWindow::UpdateWidgetSize(), and Textbuf::UpdateWidth().

◆ GetStringBoundingBox() [2/2]

Dimension GetStringBoundingBox ( StringID  strid,
FontSize  start_fontsize 
)

Get bounding box of a string.

Uses parameters set by SetDParam if needed. Has the same restrictions as GetStringBoundingBox(std::string_view str, FontSize start_fontsize).

Parameters
stridString to examine.
Returns
Width and height of the bounding box for the string in pixels.

Definition at line 863 of file gfx.cpp.

References GetString(), and GetStringBoundingBox().

◆ GetStringHeight() [1/2]

◆ GetStringHeight() [2/2]

int GetStringHeight ( StringID  str,
int  maxw 
)

Calculates height of string (in pixels).

The string is changed to a multiline string if needed.

Parameters
strstring to check
maxwmaximum string width
Returns
height of pixels of string when it is drawn

Definition at line 717 of file gfx.cpp.

References GetString(), and GetStringHeight().

◆ GetStringLineCount()

int GetStringLineCount ( StringID  str,
int  maxw 
)

Calculates number of lines of string.

The string is changed to a multiline string if needed.

Parameters
strstring to check
maxwmaximum string width
Returns
number of lines of string when it is drawn

Definition at line 728 of file gfx.cpp.

References GetString().

Referenced by NetworkDrawChatMessage(), and GameSettingsWindow::OnPaint().

◆ GetStringListBoundingBox()

Dimension GetStringListBoundingBox ( std::span< const StringID list,
FontSize  fontsize 
)

Get maximum dimension of a list of strings.

Parameters
listList of strings, terminated by INVALID_STRING_ID.
fontsizeFont size to use.
Returns
Dimension of highest and longest string within the list.

Definition at line 889 of file gfx.cpp.

References GetStringBoundingBox(), and maxdim().

Referenced by ReplaceVehicleWindow::UpdateWidgetSize(), BuildBridgeWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), IndustryDirectoryWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), and VehicleDetailsWindow::UpdateWidgetSize().

◆ GetStringListWidth()

uint GetStringListWidth ( std::span< const StringID list,
FontSize  fontsize 
)

Get maximum width of a list of strings.

Parameters
listList of strings.
fontsizeFont size to use.
Returns
Width of longest string within the list.

Definition at line 874 of file gfx.cpp.

References GetStringBoundingBox().

Referenced by VehicleGroupWindow::UpdateWidgetSize(), and VehicleListWindow::UpdateWidgetSize().

◆ GetStringMultiLineBoundingBox() [1/2]

Dimension GetStringMultiLineBoundingBox ( std::string_view  str,
const Dimension suggestion 
)

Calculate string bounding box for multi-line strings.

Parameters
strString to check.
suggestionSuggested bounding box.
Returns
Bounding box for the multi-line string, may be bigger than suggestion.

Definition at line 752 of file gfx.cpp.

References GetStringHeight().

◆ GetStringMultiLineBoundingBox() [2/2]

Dimension GetStringMultiLineBoundingBox ( StringID  str,
const Dimension suggestion 
)

Calculate string bounding box for multi-line strings.

Parameters
strString to check.
suggestionSuggested bounding box.
Returns
Bounding box for the multi-line string, may be bigger than suggestion.

Definition at line 740 of file gfx.cpp.

References GetStringHeight().

Referenced by BuildAirportWindow::UpdateWidgetSize(), QueryWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), NewsWindow::UpdateWidgetSize(), and TownAuthorityWindow::UpdateWidgetSize().

◆ GfxBlitter()

template<int ZOOM_BASE, bool SCALED_XY>
static void GfxBlitter ( const Sprite *const  sprite,
int  x,
int  y,
BlitterMode  mode,
const SubSprite *const  sub,
SpriteID  sprite_id,
ZoomLevel  zoom,
const DrawPixelInfo dst = nullptr 
)
static

The code for setting up the blitter mode and sprite information before finally drawing the sprite.

Parameters
spriteThe sprite to draw.
xThe X location to draw.
yThe Y location to draw.
modeThe settings for the blitter to pass.
subWhether to only draw a sub set of the sprite.
zoomThe zoom level at which to draw the sprites.
dstOptional parameter for a different blitting destination.
Template Parameters
ZOOM_BASEThe factor required to get the sub sprite information into the right size.
SCALED_XYWhether the X and Y are scaled or unscaled.

Definition at line 1020 of file gfx.cpp.

References _newgrf_debug_sprite_picker, NewGrfDebugSpritePicker::clicked_pixel, Sprite::data, Blitter::Draw(), Blitter::BlitterParams::dst, BlitterFactory::GetCurrentBlitter(), Blitter::GetScreenDepth(), Blitter::BlitterParams::height, Sprite::height, include(), Blitter::BlitterParams::left, NewGrfDebugSpritePicker::mode, Blitter::MoveTo(), Blitter::BlitterParams::pitch, Blitter::BlitterParams::remap, ScaleByZoom(), Blitter::BlitterParams::skip_left, Blitter::BlitterParams::skip_top, SPR_CURSOR_MOUSE, Blitter::BlitterParams::sprite, Blitter::BlitterParams::sprite_height, Blitter::BlitterParams::sprite_width, NewGrfDebugSpritePicker::sprites, Blitter::BlitterParams::top, UnScaleByZoom(), UnScaleByZoomLower(), Blitter::BlitterParams::width, Sprite::width, Sprite::x_offs, and Sprite::y_offs.

◆ GfxDoDrawLine()

static void GfxDoDrawLine ( void *  video,
int  x,
int  y,
int  x2,
int  y2,
int  screen_width,
int  screen_height,
uint8_t  colour,
int  width,
int  dash = 0 
)
inlinestatic

Check line clipping by using a linear equation and draw the visible part of the line given by x/y and x2/y2.

Parameters
videoDestination pointer to draw into.
xX coordinate of first point.
yY coordinate of first point.
x2X coordinate of second point.
y2Y coordinate of second point.
screen_widthWith of the screen to check clipping against.
screen_heightHeight of the screen to check clipping against.
colourColour of the line.
widthWidth of the line.
dashLength of dashes for dashed lines. 0 means solid line.

Definition at line 313 of file gfx.cpp.

References abs(), CeilDiv(), Blitter::DrawLine(), and BlitterFactory::GetCurrentBlitter().

◆ GfxDrawLine()

void GfxDrawLine ( int  x,
int  y,
int  x2,
int  y2,
int  colour,
int  width,
int  dash 
)

Definition at line 386 of file gfx.cpp.

◆ GfxDrawLineUnscaled()

void GfxDrawLineUnscaled ( int  x,
int  y,
int  x2,
int  y2,
int  colour 
)

Definition at line 394 of file gfx.cpp.

◆ GfxFillPolygon()

void GfxFillPolygon ( const std::vector< Point > &  shape,
int  colour,
FillRectMode  mode 
)

Fill a polygon with colour.

The odd-even winding rule is used, i.e. self-intersecting polygons will have holes in them. Left and top edges are inclusive, right and bottom edges are exclusive.

Note
For rectangles the GfxFillRect function will be faster.
Precondition
dpi->zoom == ZOOM_LVL_MIN
Parameters
shapeList of points on the polygon.
colourAn 8 bit palette index (FILLRECT_OPAQUE and FILLRECT_CHECKER) or a recolour spritenumber (FILLRECT_RECOLOUR).
modeFILLRECT_OPAQUE: Fill the polygon with the specified colour. FILLRECT_CHECKER: Fill every other pixel with the specified colour, in a checkerboard pattern. FILLRECT_RECOLOUR: Apply a recolour sprite to every pixel in the polygon.

Definition at line 210 of file gfx.cpp.

References Blitter::DrawColourMappingRect(), Blitter::DrawRect(), FILLRECT_CHECKER, FILLRECT_RECOLOUR, GB(), BlitterFactory::GetCurrentBlitter(), MakePolygonSegments(), Blitter::MoveTo(), PALETTE_WIDTH, Blitter::SetPixel(), and ZOOM_LVL_MIN.

Referenced by DrawSliderWidget().

◆ GfxFillRect()

void GfxFillRect ( int  left,
int  top,
int  right,
int  bottom,
int  colour,
FillRectMode  mode 
)

Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.

Precondition
dpi->zoom == ZOOM_LVL_MIN, right >= left, bottom >= top
Parameters
leftMinimum X (inclusive)
topMinimum Y (inclusive)
rightMaximum X (inclusive)
bottomMaximum Y (inclusive)
colourA 8 bit palette index (FILLRECT_OPAQUE and FILLRECT_CHECKER) or a recolour spritenumber (FILLRECT_RECOLOUR)
modeFILLRECT_OPAQUE: Fill the rectangle with the specified colour FILLRECT_CHECKER: Like FILLRECT_OPAQUE, but only draw every second pixel (used to grey out things) FILLRECT_RECOLOUR: Apply a recolour sprite to every pixel in the rectangle currently on screen

Definition at line 114 of file gfx.cpp.

References Blitter::DrawColourMappingRect(), Blitter::DrawRect(), FILLRECT_CHECKER, FILLRECT_RECOLOUR, GB(), BlitterFactory::GetCurrentBlitter(), Blitter::MoveTo(), PALETTE_WIDTH, Blitter::SetPixel(), and ZOOM_LVL_MIN.

Referenced by NWidgetToolbarContainer::Draw(), NWidgetMatrix::Draw(), NWidgetSpacer::Draw(), NWidgetBackground::Draw(), NWidgetViewport::Draw(), NWidgetScrollbar::Draw(), NWidgetLeaf::Draw(), CargoesField::Draw(), DrawArrowButtons(), NetworkClientListWindow::DrawButtons(), DrawCaption(), NetworkContentListWindow::DrawDetails(), DrawDropDownButton(), DrawFrame(), DrawFrameRect(), BaseGraphWindow::DrawGraph(), VehicleGroupWindow::DrawGroupInfo(), CargoesField::DrawHorConnection(), SmallMapWindow::DrawHorizMapIndicator(), DrawHorizontalScrollbar(), DrawLayoutLine(), NetworkContentListWindow::DrawMatrix(), DrawMatrix(), DrawResizeBox(), NetworkGameWindow::DrawServerLine(), SmallMapWindow::DrawSmallMap(), DrawTrainDetails(), LinkGraphOverlay::DrawVertex(), DrawVerticalScrollbar(), SmallMapWindow::DrawVertMapIndicator(), BuildAirportWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), DropdownWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), FrametimeGraphWindow::DrawWidget(), PaymentRatesGraphWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), IndustryProductionGraphWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), LinkGraphLegendWindow::DrawWidget(), TooltipsWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), MusicWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SavePresetWindow::DrawWidget(), NewsWindow::DrawWidget(), OrdersWindow::DrawWidget(), PickerWindow::DrawWidget(), SmallMapWindow::DrawWidget(), BootstrapBackground::DrawWidget(), ScriptDebugWindow::DrawWidgetLog(), Window::DrawWidgets(), DrawYearCategory(), DrawYearColumn(), HighlightDragPosition(), NetworkDrawChatMessage(), IConsoleWindow::OnPaint(), and StationsWndShowStationRating().

◆ GfxMainBlitter()

static void GfxMainBlitter ( const Sprite sprite,
int  x,
int  y,
BlitterMode  mode,
const SubSprite sub = nullptr,
SpriteID  sprite_id = SPR_CURSOR_MOUSE,
ZoomLevel  zoom = ZOOM_LVL_MIN 
)
static

Definition at line 1201 of file gfx.cpp.

◆ GfxMainBlitterViewport()

static void GfxMainBlitterViewport ( const Sprite sprite,
int  x,
int  y,
BlitterMode  mode,
const SubSprite sub = nullptr,
SpriteID  sprite_id = SPR_CURSOR_MOUSE 
)
static

Definition at line 1196 of file gfx.cpp.

◆ GfxPreprocessLine()

static bool GfxPreprocessLine ( DrawPixelInfo dpi,
int &  x,
int &  y,
int &  x2,
int &  y2,
int  width 
)
inlinestatic

Align parameters of a line to the given DPI and check simple clipping.

Parameters
dpiScreen parameters to align with.
xX coordinate of first point.
yY coordinate of first point.
x2X coordinate of second point.
y2Y coordinate of second point.
widthWidth of the line.
Returns
True if the line is likely to be visible, false if it's certainly invisible.

Definition at line 371 of file gfx.cpp.

◆ GfxScroll()

void GfxScroll ( int  left,
int  top,
int  width,
int  height,
int  xo,
int  yo 
)

Definition at line 84 of file gfx.cpp.

◆ LoadStringWidthTable()

void LoadStringWidthTable ( bool  monospace)

Initialize _stringwidth_table cache.

Parameters
monospaceWhether to load the monospace cache or the normal fonts.

Definition at line 1210 of file gfx.cpp.

References _stringwidth_table, FS_BEGIN, FS_MONO, and GetGlyphWidth().

Referenced by AdjustGUIZoom(), AfterLoadGame(), CheckForMissingGlyphs(), GenerateWorld(), and ReloadNewGRFData().

◆ MakePolygonSegments()

static std::vector< LineSegment > MakePolygonSegments ( const std::vector< Point > &  shape,
Point  offset 
)
static

Make line segments from a polygon defined by points, translated by an offset.

Entirely horizontal lines (start and end at same Y coordinate) are skipped, as they are irrelevant to scanline conversion algorithms. Generated line segments always have the lowest Y coordinate point first, i.e. original direction is lost.

Parameters
shapeThe polygon to convert.
offsetOffset vector subtracted from all coordinates in the shape.
Returns
Vector of undirected line segments.

Definition at line 171 of file gfx.cpp.

Referenced by GfxFillPolygon().

◆ ScreenSizeChanged()

void ScreenSizeChanged ( )

Definition at line 1268 of file gfx.cpp.

◆ SetAnimatedMouseCursor()

void SetAnimatedMouseCursor ( const AnimCursor table)

Assign an animation to the cursor.

Parameters
tableArray of animation states.
See also
SetMouseCursor

Definition at line 1699 of file gfx.cpp.

References CursorVars::animate_cur, CursorVars::animate_list, and CursorVars::sprites.

Referenced by SetObjectToPlace().

◆ SetColourRemap()

static void SetColourRemap ( TextColour  colour)
static

Set the colour remap to be for the given colour.

Parameters
colourthe new colour of the remap.

Definition at line 468 of file gfx.cpp.

References _string_colourmap, _string_colourremap, TC_FORCED, TC_IS_PALETTE_COLOUR, and TC_NO_SHADE.

Referenced by DrawCharCentered(), DrawLayoutLine(), DrawSprite(), and DrawSpriteViewport().

◆ SetCursorSprite()

static void SetCursorSprite ( CursorID  cursor,
PaletteID  pal 
)
static

Switch cursor to different sprite.

Parameters
cursorSprite to draw for the cursor.
palPalette to use for recolouring.

Definition at line 1636 of file gfx.cpp.

References CursorVars::sprites, and UpdateCursorSize().

Referenced by SetMouseCursor().

◆ SetMouseCursor()

void SetMouseCursor ( CursorID  sprite,
PaletteID  pal 
)

Assign a single non-animated sprite to the cursor.

Parameters
spriteSprite to draw for the cursor.
palPalette to use for recolouring.
See also
SetAnimatedMouseCursor

Definition at line 1686 of file gfx.cpp.

References CursorVars::animate_timeout, and SetCursorSprite().

Referenced by SetMouseCursorBusy(), and SetObjectToPlace().

◆ SetMouseCursorBusy()

void SetMouseCursorBusy ( bool  busy)

Set or unset the ZZZ cursor.

Parameters
busyWhether to show the ZZZ cursor.

Definition at line 1670 of file gfx.cpp.

References SetMouseCursor(), SPR_CURSOR_MOUSE, and CursorVars::sprites.

Referenced by CleanupGeneration(), GenerateProgressWindow::OnClick(), SaveFileDone(), and SaveFileStart().

◆ SortResolutions()

void SortResolutions ( )

Definition at line 1758 of file gfx.cpp.

◆ SwitchAnimatedCursor()

static void SwitchAnimatedCursor ( )
static

Definition at line 1646 of file gfx.cpp.

◆ ToggleFullScreen()

bool ToggleFullScreen ( bool  fs)

Definition at line 1749 of file gfx.cpp.

◆ UndrawMouseCursor()

void UndrawMouseCursor ( )

Definition at line 1281 of file gfx.cpp.

◆ UpdateCursorSize()

void UpdateCursorSize ( )

Update cursor dimension.

Called when changing cursor sprite resp. reloading grfs.

Definition at line 1598 of file gfx.cpp.

References CursorVars::dirty, GB(), GetMaxSpriteID(), Sprite::height, Normal, SPRITE_WIDTH, CursorVars::sprites, CursorVars::total_size, UnScaleGUI(), Sprite::width, Sprite::x_offs, and Sprite::y_offs.

Referenced by AdjustGUIZoom(), GfxLoadSprites(), SetCursorSprite(), and SetMouseCursorVehicle().

◆ UpdateGUIZoom()

Variable Documentation

◆ _colour_remap_ptr

const uint8_t* _colour_remap_ptr
static

Definition at line 74 of file gfx.cpp.

◆ _ctrl_pressed

bool _ctrl_pressed

Is Ctrl pressed?

Definition at line 38 of file gfx.cpp.

Referenced by CheckRedrawStationCoverage(), DepotWindow::DepotClick(), DispatchLeftClickEvent(), FindStationsAroundSelection(), GenerateDesertArea(), GenericPlaceSignals(), GetOrderCmdFromTile(), GUIPlaceProcDragXY(), HandleAutoSignalPlacement(), StationViewWindow::HandleCargoWaitingClick(), GoalListWindow::HandleClick(), HandleClickOnSign(), VideoDriver_SDL_Base::InputLoop(), VideoDriver_SDL::InputLoop(), VideoDriver_Win32Base::InputLoop(), TileHighlightData::IsDraggingDiagonal(), MenuClickHelp(), AIConfigWindow::OnClick(), ReplaceVehicleWindow::OnClick(), BuildVehicleWindow::OnClick(), CompanyFinancesWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), CompanyWindow::OnClick(), DepotWindow::OnClick(), GSConfigWindow::OnClick(), VehicleGroupWindow::OnClick(), IndustryViewWindow::OnClick(), IndustryDirectoryWindow::OnClick(), SelectGameWindow::OnClick(), LandInfoWindow::OnClick(), NetworkStartServerWindow::OnClick(), SpriteAlignerWindow::OnClick(), NewsWindow::OnClick(), OrdersWindow::OnClick(), PickerWindow::OnClick(), BuildRailToolbarWindow::OnClick(), BuildRoadToolbarWindow::OnClick(), ScriptDebugWindow::OnClick(), GameOptionsWindow::OnClick(), SignWindow::OnClick(), CompanyStationsWindow::OnClick(), StationViewWindow::OnClick(), TimetableWindow::OnClick(), TownViewWindow::OnClick(), TownDirectoryWindow::OnClick(), TransparenciesWindow::OnClick(), RefitWindow::OnClick(), VehicleListWindow::OnClick(), VehicleDetailsWindow::OnClick(), VehicleViewWindow::OnClick(), WaypointWindow::OnClick(), DepotWindow::OnCTRLStateChange(), DepotWindow::OnDragDrop(), CompanyStationsWindow::OnDropdownSelect(), SelectCompanyLiveryWindow::OnDropdownSelect(), StoryBookWindow::OnPageElementClick(), BuildDocksToolbarWindow::OnPlaceMouseUp(), BuildObjectWindow::OnPlaceMouseUp(), BuildRailToolbarWindow::OnPlaceMouseUp(), BuildRoadToolbarWindow::OnPlaceMouseUp(), TerraformToolbarWindow::OnPlaceMouseUp(), BuildTreesWindow::OnPlaceMouseUp(), BuildDocksToolbarWindow::OnPlaceObject(), DepotWindow::OnRightClick(), DepotWindow::OnVehicleSelect(), DepotWindow::OnVehicleSelect(), OrdersWindow::OnVehicleSelect(), OrdersWindow::OrderClick_Refit(), OrdersWindow::OrderClick_Skip(), OrdersWindow::OrderClick_StopSharing(), PlaceAirport(), PlaceRail_Station(), SmallMapWindow::SelectLegendItem(), ShowBuildBridgeWindow(), ShowCargoIconOverlay(), and StationJoinerNeeded().

◆ _cur_dpi

DrawPixelInfo* _cur_dpi

Definition at line 54 of file gfx.cpp.

◆ _cursor

CursorVars _cursor

Definition at line 37 of file gfx.cpp.

◆ _cursor_backup

ReusableBuffer<uint8_t> _cursor_backup
static

Definition at line 59 of file gfx.cpp.

◆ _dirkeys

uint8_t _dirkeys

1 = left, 2 = up, 4 = right, 8 = down

Definition at line 34 of file gfx.cpp.

Referenced by VideoDriver_SDL_Base::InputLoop(), VideoDriver_SDL::InputLoop(), and VideoDriver_Win32Base::InputLoop().

◆ _dirty_block_colour

uint _dirty_block_colour
extern

Definition at line 195 of file viewport.cpp.

◆ _dirty_blocks

uint8_t* _dirty_blocks = nullptr
static

Definition at line 81 of file gfx.cpp.

◆ _dirty_bytes_per_line

uint _dirty_bytes_per_line = 0
static

Definition at line 80 of file gfx.cpp.

◆ _exit_game

std::atomic<bool> _exit_game

Definition at line 47 of file gfx.cpp.

◆ _font_zoom

ZoomLevel _font_zoom = _gui_zoom

Sprite font Zoom level (not clamped)

Definition at line 62 of file gfx.cpp.

Referenced by AdjustGUIZoom(), ReadSprite(), ScaleFontTrad(), and UpdateGUIZoom().

◆ _fullscreen

bool _fullscreen

Definition at line 35 of file gfx.cpp.

◆ _game_mode

GameMode _game_mode

Definition at line 48 of file gfx.cpp.

◆ _game_session_stats

GameSessionStats _game_session_stats

◆ _game_speed

uint16_t _game_speed = 100

Current game-speed; 100 is 1x, 0 is infinite.

Definition at line 40 of file gfx.cpp.

Referenced by ToolbarFastForwardClick().

◆ _gui_scale

int _gui_scale = MIN_INTERFACE_SCALE

◆ _gui_scale_cfg

int _gui_scale_cfg

◆ _gui_zoom

GUI Zoom level.

Definition at line 61 of file gfx.cpp.

Referenced by AdjustGUIZoom(), and UpdateGUIZoom().

◆ _left_button_clicked

◆ _left_button_down

◆ _pause_mode

◆ _right_button_clicked

bool _right_button_clicked

Is right mouse button clicked?

Definition at line 44 of file gfx.cpp.

Referenced by HandleMouseEvents(), VideoDriver_SDL_Base::PollEvent(), and VideoDriver_SDL::PollEvent().

◆ _right_button_down

bool _right_button_down

◆ _screen

DrawPixelInfo _screen

Definition at line 45 of file gfx.cpp.

◆ _screen_disable_anim

◆ _shift_pressed

◆ _string_colourremap

uint8_t _string_colourremap[3]
static

Recoloursprite for stringdrawing. The grf loader ensures that SpriteType::Font sprites only use colours 0 to 2.

Definition at line 75 of file gfx.cpp.

Referenced by DrawLayoutLine(), and SetColourRemap().

◆ _stringwidth_table

uint8_t _stringwidth_table[FS_END][224]
static

Cache containing width of often used characters.

See also
GetCharacterWidth()

Definition at line 53 of file gfx.cpp.

Referenced by GetCharacterWidth(), and LoadStringWidthTable().

◆ _support8bpp

uint8_t _support8bpp

Definition at line 36 of file gfx.cpp.

◆ _switch_mode

◆ DIRTY_BLOCK_HEIGHT

const uint DIRTY_BLOCK_HEIGHT = 8
static

Definition at line 77 of file gfx.cpp.

◆ DIRTY_BLOCK_WIDTH

const uint DIRTY_BLOCK_WIDTH = 64
static

Definition at line 78 of file gfx.cpp.