OpenTTD Source: src/gfx_func.h File Reference

OpenTTD Source 14.0-beta1

Functions | Variables
gfx_func.h File Reference
`#include "gfx_type.h"`
`#include "strings_type.h"`
`#include "string_type.h"`

Go to the source code of this file.

## Functions
void | GameLoop ()
void | CreateConsole ()
void | HandleToolbarHotkey (int hotkey)
| Handle Toolbar hotkey events - can come from a source like the MacBook Touch Bar. More...
void | HandleKeypress (uint keycode, char32_t key)
| Handle keyboard input. More...
void | HandleTextInput (const char *str, bool marked=false, const char *caret=nullptr, const char *insert_location=nullptr, const char *replacement_end=nullptr)
| Handle text input. More...
void | HandleCtrlChanged ()
| State of CONTROL key has changed.
void | HandleMouseEvents ()
| Handle a mouse event from the video driver.
void | UpdateWindows ()
| Update the continuously changing contents of the windows, such as the viewports.
void | ChangeGameSpeed (bool enable_fast_forward)
void | DrawMouseCursor ()
void | ScreenSizeChanged ()
void | GameSizeChanged ()
| Size of the application screen changed. More...
bool | AdjustGUIZoom (bool automatic)
| Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested. More...
void | UndrawMouseCursor ()
void | RedrawScreenRect (int left, int top, int right, int bottom)
| Repaints a specific rectangle of the screen. More...
void | GfxScroll (int left, int top, int width, int height, int xo, int yo)
Dimension | GetSpriteSize (SpriteID sprid, Point *offset=nullptr, ZoomLevel zoom=ZOOM_LVL_GUI)
| Get the size of a sprite. More...
Dimension | GetScaledSpriteSize (SpriteID sprid)
| Scale sprite size for GUI. More...
void | DrawSpriteViewport (SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub=nullptr)
| Draw a sprite in a viewport. More...
void | DrawSprite (SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub=nullptr, ZoomLevel zoom=ZOOM_LVL_GUI)
| Draw a sprite, not in a viewport. More...
void | DrawSpriteIgnorePadding (SpriteID img, PaletteID pal, const Rect &r, StringAlignment align)
std::unique_ptr< uint32_t[]> | DrawSpriteToRgbaBuffer (SpriteID spriteId, ZoomLevel zoom=ZOOM_LVL_GUI)
| Draws a sprite to a new RGBA buffer (see Colour union) instead of drawing to the screen. More...
int | DrawString (int left, int right, int top, std::string_view str, TextColour colour=TC_FROMSTRING, StringAlignment align=SA_LEFT, bool underline=false, FontSize fontsize=FS_NORMAL)
| Draw string, possibly truncated to make it fit in its allocated space. More...
int | DrawString (int left, int right, int top, StringID str, TextColour colour=TC_FROMSTRING, StringAlignment align=SA_LEFT, bool underline=false, FontSize fontsize=FS_NORMAL)
| Draw string, possibly truncated to make it fit in its allocated space. More...
int | DrawStringMultiLine (int left, int right, int top, int bottom, std::string_view str, TextColour colour=TC_FROMSTRING, StringAlignment align=(SA_TOP|SA_LEFT), bool underline=false, FontSize fontsize=FS_NORMAL)
| Draw string, possibly over multiple lines. More...
int | DrawStringMultiLine (int left, int right, int top, int bottom, StringID str, TextColour colour=TC_FROMSTRING, StringAlignment align=(SA_TOP|SA_LEFT), bool underline=false, FontSize fontsize=FS_NORMAL)
| Draw string, possibly over multiple lines. More...
void | DrawCharCentered (char32_t c, const Rect &r, TextColour colour)
| Draw single character horizontally centered around (x,y) More...
void | GfxFillRect (int left, int top, int right, int bottom, int colour, FillRectMode mode=FILLRECT_OPAQUE)
| Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen. More...
void | GfxFillPolygon (const std::vector< Point > &shape, int colour, FillRectMode mode=FILLRECT_OPAQUE)
| Fill a polygon with colour. More...
void | GfxDrawLine (int left, int top, int right, int bottom, int colour, int width=1, int dash=0)
void | DrawBox (int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
| Draws the projection of a parallelepiped. More...
void | DrawRectOutline (const Rect &r, int colour, int width=1, int dash=0)
| Draw the outline of a Rect. More...
int | DrawString (const Rect &r, std::string_view str, TextColour colour=TC_FROMSTRING, StringAlignment align=SA_LEFT, bool underline=false, FontSize fontsize=FS_NORMAL)
int | DrawString (const Rect &r, StringID str, TextColour colour=TC_FROMSTRING, StringAlignment align=SA_LEFT, bool underline=false, FontSize fontsize=FS_NORMAL)
int | DrawStringMultiLine (const Rect &r, std::string_view str, TextColour colour=TC_FROMSTRING, StringAlignment align=(SA_TOP|SA_LEFT), bool underline=false, FontSize fontsize=FS_NORMAL)
int | DrawStringMultiLine (const Rect &r, StringID str, TextColour colour=TC_FROMSTRING, StringAlignment align=(SA_TOP|SA_LEFT), bool underline=false, FontSize fontsize=FS_NORMAL)
void | GfxFillRect (const Rect &r, int colour, FillRectMode mode=FILLRECT_OPAQUE)
Dimension | GetStringBoundingBox (std::string_view str, FontSize start_fontsize=FS_NORMAL)
| Return the string dimension in pixels. More...
Dimension | GetStringBoundingBox (StringID strid, FontSize start_fontsize=FS_NORMAL)
| Get bounding box of a string. More...
uint | GetStringListWidth (const StringID *list, FontSize fontsize=FS_NORMAL)
| Get maximum width of a list of strings. More...
int | GetStringHeight (std::string_view str, int maxw, FontSize fontsize=FS_NORMAL)
| Calculates height of string (in pixels). More...
int | GetStringHeight (StringID str, int maxw)
| Calculates height of string (in pixels). More...
int | GetStringLineCount (StringID str, int maxw)
| Calculates number of lines of string. More...
Dimension | GetStringMultiLineBoundingBox (StringID str, const Dimension &suggestion)
| Calculate string bounding box for multi-line strings. More...
Dimension | GetStringMultiLineBoundingBox (std::string_view str, const Dimension &suggestion)
| Calculate string bounding box for multi-line strings. More...
void | LoadStringWidthTable (bool monospace=false)
| Initialize _stringwidth_table cache. More...
Point | GetCharPosInString (std::string_view str, const char *ch, FontSize start_fontsize=FS_NORMAL)
| Get the leading corner of a character in a single-line string relative to the start of the string. More...
ptrdiff_t | GetCharAtPosition (std::string_view str, int x, FontSize start_fontsize=FS_NORMAL)
| Get the character from a string that is drawn at a specific position. More...
void | DrawDirtyBlocks ()
| Repaints the rectangle blocks which are marked as 'dirty'. More...
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. More...
void | MarkWholeScreenDirty ()
| This function mark the whole screen as dirty. More...
void | CheckBlitter ()
| Check whether we still use the right blitter, or use another (better) one.
bool | FillDrawPixelInfo (DrawPixelInfo *n, int left, int top, int width, int height)
| Set up a clipping area for only drawing into a certain area. More...
bool | FillDrawPixelInfo (DrawPixelInfo *n, const Rect &r)
int | CenterBounds (int min, int max, int size)
| Determine where to draw a centred object inside a widget. More...
void | DrawOverlappedWindowForAll (int left, int top, int right, int bottom)
| From a rectangle that needs redrawing, find the windows that intersect with the rectangle. More...
void | SetMouseCursorBusy (bool busy)
| Set or unset the ZZZ cursor. More...
void | SetMouseCursor (CursorID cursor, PaletteID pal)
| Assign a single non-animated sprite to the cursor. More...
void | SetAnimatedMouseCursor (const AnimCursor *table)
| Assign an animation to the cursor. More...
void | CursorTick ()
void | UpdateCursorSize ()
| Update cursor dimension. More...
bool | ChangeResInGame (int w, int h)
void | SortResolutions ()
bool | ToggleFullScreen (bool fs)
byte | GetCharacterWidth (FontSize size, char32_t key)
| Return width of character glyph. More...
byte | GetDigitWidth (FontSize size=FS_NORMAL)
| Return the maximum width of single digit. More...
void | GetBroadestDigit (uint *front, uint *next, FontSize size=FS_NORMAL)
| Determine the broadest digits for guessing the maximum width of a n-digit number. More...
int | GetCharacterHeight (FontSize size)
| Get height of a character for a given font size. More...

## Variables
byte | _dirkeys
| 1 = left, 2 = up, 4 = right, 8 = down
bool | _fullscreen
byte | _support8bpp
CursorVars | _cursor
bool | _ctrl_pressed
| Is Ctrl pressed?
bool | _shift_pressed
| Is Shift pressed?
uint16_t | _game_speed
| 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
| Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
std::vector< Dimension > | _resolutions
| List of resolutions.
Dimension | _cur_resolution
| The current resolution.
Palette | _cur_palette
| Current palette.
DrawPixelInfo * | _cur_dpi

## Detailed Description

Functions related to the gfx engine.

Definition in file gfx_func.h.

## Function Documentation

## ◆ AdjustGUIZoom()

bool AdjustGUIZoom | ( | bool | automatic | ) |

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

Parameters

  automatic | Set 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 1814 of file gfx.cpp.

References _font_zoom, _gui_scale, _gui_zoom, VideoDriver::ClearSystemSprites(), VideoDriver::GetInstance(), GfxClearFontSpriteCache(), UpdateCursorSize(), and UpdateGUIZoom().

Referenced by GameOptionsWindow::OnMouseLoop().

## ◆ CenterBounds()

int CenterBounds | ( | int | min,
|  | int | max,
|  | int | size
| ) |  |
| inline

Determine where to draw a centred object inside a widget.

Parameters

  min | The top or left coordinate.
  max | The bottom or right coordinate.
  size | The height or width of the object to draw.

Returns
  Offset of where to start drawing the object.

Definition at line 166 of file gfx_func.h.

Referenced by NetworkClientListWindow::DrawCompany(), and GetAlignedPosition().

## ◆ 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

  x | Screen X-coordinate of top front corner.
  y | Screen Y-coordinate of top front corner.
  dx1 | Screen X-length of first edge.
  dy1 | Screen Y-length of first edge.
  dx2 | Screen X-length of second edge.
  dy2 | Screen Y-length of second edge.
  dx3 | Screen X-length of third edge.
  dy3 | Screen Y-length of third edge.

Definition at line 417 of file gfx.cpp.

Referenced by ViewportDrawBoundingBoxes().

## ◆ DrawCharCentered()

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

Draw single character horizontally centered around (x,y)

Parameters

  c | Character (glyph) to draw
  r | Rectangle to draw character within
  colour | Colour 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 924 of file gfx.cpp.

References SetColourRemap().

## ◆ DrawOverlappedWindowForAll()

void DrawOverlappedWindowForAll | ( | int | left,
|  | int | top,
|  | int | right,
|  | int | bottom
| ) |  |

From a rectangle that needs redrawing, find the windows that intersect with the rectangle.

These windows should be re-painted.

Parameters

  left | Left edge of the rectangle that should be repainted
  top | Top edge of the rectangle that should be repainted
  right | Right edge of the rectangle that should be repainted
  bottom | Bottom edge of the rectangle that should be repainted

Definition at line 920 of file window.cpp.

## ◆ DrawRectOutline()

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

Draw the outline of a Rect.

Parameters

  r | Rect to draw.
  colour | Colour of the outline.
  width | Width of the outline.
  dash | Length of dashes for dashed lines. 0 means solid lines.

Definition at line 455 of file gfx.cpp.

## ◆ DrawSprite()

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

Draw a sprite, not in a viewport.

Parameters

  img | Image number to draw
  pal | Palette to use.
  x | Left coordinate of image in pixels
  y | Top coordinate of image in pixels
  sub | If available, draw only specified part of the sprite
  zoom | Zoom level of sprite

Definition at line 1007 of file gfx.cpp.

Referenced by StoryBookWindow::DrawActionElement().

## ◆ 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

  spriteId | The sprite to draw.
  zoom | The zoom level at which to draw the sprites.

Returns
  Pixel buffer, or nullptr if an 8bpp blitter is being used.

Definition at line 1163 of file gfx.cpp.

References _settings_client, GB(), BlitterFactory::GetCurrentBlitter(), Blitter::GetScreenDepth(), ClientSettings::gui, 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

  img | Image number to draw
  pal | Palette to use.
  x | Left coordinate of image in viewport, scaled by zoom
  y | Top coordinate of image in viewport, scaled by zoom
  sub | If available, draw only specified part of the sprite

Definition at line 979 of file gfx.cpp.

## ◆ 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

  left | The left most position to draw on.
  right | The right most position to draw on.
  top | The top most position to draw on.
  str | String to draw.
  colour | Colour 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
  align | The 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.
  underline | Whether to underline what has been drawn or not.
  fontsize | The 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 658 of file gfx.cpp.

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

Referenced by CargoesField::Draw(), TownAuthorityWindow::DrawActions(), DrawCaption(), StationViewWindow::DrawCargoRatings(), DrawCategory(), NetworkContentListWindow::DrawDetails(), DrawFrame(), IndustryViewWindow::DrawInfo(), DrawInset(), GoalListWindow::DrawListColumn(), DrawPrice(), TownAuthorityWindow::DrawRatings(), DrawString(), TimetableWindow::DrawSummaryPanel(), and DrawText().

## ◆ 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

  left | The left most position to draw on.
  right | The right most position to draw on.
  top | The top most position to draw on.
  str | String to draw.
  colour | Colour 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
  align | The 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.
  underline | Whether to underline what has been drawn or not.
  fontsize | The 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 694 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

  left | The left most position to draw on.
  right | The right most position to draw on.
  top | The top most position to draw on.
  bottom | The bottom most position to draw on.
  str | String to draw.
  colour | Colour 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
  align | The horizontal and vertical alignment of the string.
  underline | Whether to underline all strings
  fontsize | The 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 775 of file gfx.cpp.

References Layouter::GetBounds().

Referenced by StationViewWindow::DrawAcceptedCargo(), StationViewWindow::DrawCargoRatings(), DrawStringMultiLine(), IConsoleWindow::OnPaint(), and HighScoreWindow::OnPaint().

## ◆ 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

  left | The left most position to draw on.
  right | The right most position to draw on.
  top | The top most position to draw on.
  bottom | The bottom most position to draw on.
  str | String to draw.
  colour | Colour 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
  align | The horizontal and vertical alignment of the string.
  underline | Whether to underline all strings
  fontsize | The 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 837 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

  *n | the DrawPixelInfo that will be the clipping rectangle box allowed for drawing
  left,top,width,height | the 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 1571 of file gfx.cpp.

References BlitterFactory::GetCurrentBlitter().

Referenced by NWidgetMatrix::Draw(), NWidgetLeaf::Draw(), DrawRoadVehImage(), DrawTrainImage(), and ScriptDebugWindow::DrawWidgetLog().

## ◆ GameSizeChanged()

void GameSizeChanged | ( |  | ) |

Size of the application screen changed.

Adapt the game screen-size, re-allocate the open windows, and repaint everything

Definition at line 583 of file main_gui.cpp.

References _cur_resolution.

Referenced by VideoDriver_SDL_Base::ClientSizeChanged().

## ◆ 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] | front | Broadest digit, which is not 0. (Use this digit as first digit for numbers with more than one digit.)
  [out] | next | Broadest digit, including 0. (Use this digit for all digits, except the first one; or for numbers with only one digit.)
  | size | Font of the digit

Definition at line 1278 of file gfx.cpp.

References GetCharacterWidth().

Referenced by SetDParamMaxDigits().

## ◆ GetCharacterHeight()

int GetCharacterHeight | ( | FontSize | size | ) |

Get height of a character for a given font size.

Parameters

  size | Font size to get height of

Returns
  Height of characters in the given font (pixels)

Definition at line 78 of file fontcache.cpp.

References FontCache::Get(), and FontCache::GetHeight().

Referenced by TextfileWindow::CheckHyperlinkClick(), CargoesField::Draw(), StationViewWindow::DrawAcceptedCargo(), TownAuthorityWindow::DrawActions(), StationViewWindow::DrawCargoRatings(), DrawCategory(), NetworkClientListWindow::DrawCompany(), NetworkContentListWindow::DrawDetails(), DrawFrame(), IndustryViewWindow::DrawInfo(), NetworkContentListWindow::DrawMatrix(), TownAuthorityWindow::DrawRatings(), DrawSliderWidget(), DrawString(), TimetableWindow::DrawSummaryPanel(), StoryBookWindow::EnsureStoryPageElementLayout(), TownViewWindow::GetDesiredInfoHeight(), GetEngineListHeight(), StoryBookWindow::GetHeadHeight(), SmallMapWindow::GetLegendHeight(), SmallMapWindow::GetPositionOnLegend(), VehicleDetailsWindow::GetRoadVehDetailsHeight(), GetTotalCategoriesHeight(), GetVehicleListHeight(), LocalGetWindowPlacement(), ViewportSign::MarkDirty(), NetworkReInitChatBoxSize(), IConsoleWindow::OnInit(), BuildIndustryWindow::OnInit(), IndustryViewWindow::OnInit(), PaymentRatesGraphWindow::OnInit(), IndustryCargoesWindow::OnInit(), ReplaceVehicleWindow::OnPaint(), BuildVehicleWindow::OnPaint(), TextfileWindow::ReflowContent(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetMinimalTextLines(), NWidgetBackground::SetupSmallestSize(), and ViewportAddString().

## ◆ GetCharacterWidth()

byte GetCharacterWidth | ( | FontSize | size,
|  | char32_t | key
| ) |  |

Return width of character glyph.

Parameters

  size | Font of the character
  key | Character code glyph

Returns
  Width of the character glyph

Definition at line 1250 of file gfx.cpp.

References _stringwidth_table, and GetGlyphWidth().

Referenced by GetBroadestDigit(), and GetDigitWidth().

## ◆ GetCharAtPosition()

ptrdiff_t GetCharAtPosition | ( | std::string_view | str,
|  | int | x,
|  | FontSize | start_fontsize
| ) |  |

Get the character from a string that is drawn at a specific position.

Parameters

  str | String to test.
  x | Position relative to the start of the string.
  start_fontsize | Font size to start the text with.

Returns
  Index of the character position or -1 if there is no character at the position.

Definition at line 909 of file gfx.cpp.

## ◆ GetCharPosInString()

Point GetCharPosInString | ( | std::string_view | str,
|  | const char * | ch,
|  | FontSize | start_fontsize
| ) |  |

Get the leading corner of a character in a single-line string relative to the start of the string.

Parameters

  str | String containing the character.
  ch | Pointer to the character in the string.
  start_fontsize | Font size to start the text with.

Returns
  Upper left corner of the glyph associated with the character.

Definition at line 892 of file gfx.cpp.

Referenced by Textbuf::UpdateCaretPosition(), and Textbuf::UpdateMarkedText().

## ◆ GetDigitWidth()

byte GetDigitWidth | ( | FontSize | size | ) |

Return the maximum width of single digit.

Parameters

  size | Font of the digit

Returns
  Width of the digit.

Definition at line 1263 of file gfx.cpp.

References GetCharacterWidth().

## ◆ GetScaledSpriteSize()

Dimension GetScaledSpriteSize | ( | SpriteID | sprid | ) |

Scale sprite size for GUI.

Offset is ignored.

Definition at line 54 of file widget.cpp.

References GetSpriteSize(), ScaleGUITrad(), and ZOOM_LVL_OUT_4X.

Referenced by DepotWindow::OnInit(), and NWidgetLeaf::SetupSmallestSize().

## ◆ GetSpriteSize()

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

Get the size of a sprite.

Parameters

  | sprid | Sprite to examine.
  [out] | offset | Optionally returns the sprite position offset.
  | zoom | The 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 941 of file gfx.cpp.

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), StoryBookWindow::DrawActionElement(), NetworkClientListWindow::DrawCompany(), DrawCompanyManagerFace(), BuildSignalWindow::DrawSignalSprite(), TimetableWindow::DrawTimetablePanel(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehicleRefitWindow(), GetLargestCargoIconSize(), StoryBookWindow::GetPageElementHeight(), GetScaledSpriteSize(), MakeCompanyButtonRows(), MakeNWidgetCompanyLines(), TownAuthorityWindow::OnInit(), CheatWindow::OnInit(), NetworkGameWindow::OnInit(), NetworkContentListWindow::OnInit(), SelectCompanyManagerFaceWindow::OnInit(), and GameSettingsWindow::OnInit().

## ◆ 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

  str | string to calculate pixel-width
  start_fontsize | Fontsize to start the text with

Returns
  string width and height in pixels

Definition at line 852 of file gfx.cpp.

Referenced by DrawCaption(), DrawText(), TimetableWindow::DrawTimetablePanel(), BaseVehicleListWindow::GetActionDropdownSize(), IndustryDirectoryWindow::GetIndustryListWidth(), ExpensesList::GetListWidth(), GetMaxCategoriesWidth(), StoryBookWindow::GetPageElementFloatWidth(), StoryBookWindow::GetPageElementHeight(), GetStringBoundingBox(), GetStringListWidth(), BaseGraphWindow::GetYLabelWidth(), TextfileWindow::LoadText(), BaseVehicleListWindow::OnInit(), IConsoleWindow::OnInit(), SelectCompanyManagerFaceWindow::OnInit(), IndustryCargoesWindow::OnInit(), RefitWindow::OnInvalidateData(), ScriptDebugWindow::OnInvalidateData(), GoalListWindow::OnPaint(), NWidgetBackground::SetupSmallestSize(), ViewportSign::UpdatePosition(), 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

  strid | String to examine.

Returns
  Width and height of the bounding box for the string in pixels.

Definition at line 864 of file gfx.cpp.

References GetString(), and GetStringBoundingBox().

## ◆ GetStringHeight() [1/2]

int GetStringHeight | ( | std::string_view | str,
|  | int | maxw,
|  | FontSize | fontsize
| ) |  |

Calculates height of string (in pixels).

The string is changed to a multiline string if needed.

Parameters

  str | string to check
  maxw | maximum string width

Returns
  height of pixels of string when it is drawn

Definition at line 705 of file gfx.cpp.

Referenced by StoryBookWindow::GetHeadHeight(), SettingEntry::GetMaxHelpHeight(), StoryBookWindow::GetPageElementHeight(), GetStringHeight(), and TextfileWindow::ReflowContent().

## ◆ 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

  str | string to check
  maxw | maximum string width

Returns
  height of pixels of string when it is drawn

Definition at line 718 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

  str | string to check
  maxw | maximum string width

Returns
  number of lines of string when it is drawn

Definition at line 729 of file gfx.cpp.

References GetString().

## ◆ GetStringListWidth()

uint GetStringListWidth | ( | const StringID * | list,
|  | FontSize | fontsize
| ) |  |

Get maximum width of a list of strings.

Parameters

  list | List of strings, terminated with INVALID_STRING_ID.
  fontsize | Font size to use.

Returns
  Width of longest string within the list.

Definition at line 875 of file gfx.cpp.

References GetStringBoundingBox(), and INVALID_STRING_ID.

## ◆ GetStringMultiLineBoundingBox() [1/2]

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

Calculate string bounding box for multi-line strings.

Parameters

  str | String to check.
  suggestion | Suggested bounding box.

Returns
  Bounding box for the multi-line string, may be bigger than suggestion.

Definition at line 753 of file gfx.cpp.

## ◆ GetStringMultiLineBoundingBox() [2/2]

Dimension GetStringMultiLineBoundingBox | ( | StringID | str,
|  | const Dimension & | suggestion
| ) |  |

Calculate string bounding box for multi-line strings.

Parameters

  str | String to check.
  suggestion | Suggested bounding box.

Returns
  Bounding box for the multi-line string, may be bigger than suggestion.

Definition at line 741 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_NORMAL

Parameters

  shape | List of points on the polygon.
  colour | An 8 bit palette index (FILLRECT_OPAQUE and FILLRECT_CHECKER) or a recolour spritenumber (FILLRECT_RECOLOUR).
  mode | FILLRECT_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 209 of file gfx.cpp.

References BlitterFactory::GetCurrentBlitter().

## ◆ 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_NORMAL, right >= left, bottom >= top

Parameters

  left | Minimum X (inclusive)
  top | Minimum Y (inclusive)
  right | Maximum X (inclusive)
  bottom | Maximum Y (inclusive)
  colour | A 8 bit palette index (FILLRECT_OPAQUE and FILLRECT_CHECKER) or a recolour spritenumber (FILLRECT_RECOLOUR)
  mode | FILLRECT_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 113 of file gfx.cpp.

References BlitterFactory::GetCurrentBlitter().

Referenced by NWidgetMatrix::Draw(), NWidgetViewport::Draw(), NWidgetToolbarContainer::Draw(), DrawCaption(), NetworkContentListWindow::DrawDetails(), DrawFrame(), NetworkContentListWindow::DrawMatrix(), and IConsoleWindow::OnPaint().

## ◆ HandleKeypress()

void HandleKeypress | ( | uint | keycode,
|  | char32_t | key
| ) |  |

Handle keyboard input.

Parameters

  keycode | Virtual keycode of the key.
  key | Unicode character of the key.

Definition at line 2563 of file window.cpp.

References EditBoxInGlobalFocus(), HasModalProgress(), and IsLocalCompany().

Referenced by HandleCharMsg().

## ◆ HandleTextInput()

void HandleTextInput | ( | const char * | str,
|  | bool | marked,
|  | const char * | caret,
|  | const char * | insert_location,
|  | const char * | replacement_end
| ) |  |

Handle text input.

Parameters

  str | Text string to input.
  marked | Is the input a marked composition string from an IME?
  caret | Move the caret to this point in the insertion string.

Definition at line 2649 of file window.cpp.

References EditBoxInGlobalFocus().

Referenced by CancelIMEComposition().

## ◆ HandleToolbarHotkey()

void HandleToolbarHotkey | ( | int | hotkey | ) |

Handle Toolbar hotkey events - can come from a source like the MacBook Touch Bar.

Parameters

  hotkey | Hotkey code

Definition at line 2546 of file window.cpp.

References ES_HANDLED, FindWindowById(), HasModalProgress(), WindowDesc::hotkeys, IsLocalCompany(), Window::OnHotkey(), WC_MAIN_TOOLBAR, and Window::window_desc.

## ◆ LoadStringWidthTable()

void LoadStringWidthTable | ( | bool | monospace | ) |

Initialize _stringwidth_table cache.

Parameters

  monospace | Whether to load the monospace cache or the normal fonts.

Definition at line 1233 of file gfx.cpp.

Referenced by ReloadNewGRFData().

## ◆ SetAnimatedMouseCursor()

void SetAnimatedMouseCursor | ( | const AnimCursor * | table | ) |

Assign an animation to the cursor.

Parameters

  table | Array of animation states.

See also
  SetMouseCursor

Definition at line 1721 of file gfx.cpp.

## ◆ SetMouseCursor()

void SetMouseCursor | ( | CursorID | sprite,
|  | PaletteID | pal
| ) |  |

Assign a single non-animated sprite to the cursor.

Parameters

  sprite | Sprite to draw for the cursor.
  pal | Palette to use for recolouring.

See also
  SetAnimatedMouseCursor

Definition at line 1708 of file gfx.cpp.

## ◆ SetMouseCursorBusy()

void SetMouseCursorBusy | ( | bool | busy | ) |

Set or unset the ZZZ cursor.

Parameters

  busy | Whether to show the ZZZ cursor.

Definition at line 1693 of file gfx.cpp.

Referenced by CleanupGeneration(), SaveFileDone(), and SaveFileStart().

## ◆ UpdateCursorSize()

void UpdateCursorSize | ( |  | ) |

Update cursor dimension.

Called when changing cursor sprite resp. reloading grfs.

Definition at line 1621 of file gfx.cpp.

References GetMaxSpriteID(), and lengthof.

Referenced by AdjustGUIZoom().