OpenTTD
Macros | Functions | Variables
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_func.h"
#include "newgrf_debug.h"
#include "table/palettes.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.

Macros

#define EXTR(p, q)   (((uint16)(palette_animation_counter * (p)) * (q)) >> 16)
 
#define EXTR2(p, q)   (((uint16)(~palette_animation_counter * (p)) * (q)) >> 16)
 

Functions

static void GfxMainBlitterViewport (const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub=NULL, SpriteID sprite_id=SPR_CURSOR_MOUSE)
 
static void GfxMainBlitter (const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub=NULL, SpriteID sprite_id=SPR_CURSOR_MOUSE, ZoomLevel zoom=ZOOM_LVL_NORMAL)
 
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. More...
 
static void GfxDoDrawLine (void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 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. More...
 
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. More...
 
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. More...
 
static void SetColourRemap (TextColour colour)
 Set the colour remap to be for the given colour. More...
 
static int DrawLayoutLine (const ParagraphLayouter::Line *line, int y, int left, int right, StringAlignment align, bool underline, bool truncation)
 Drawing routine for drawing a laid out line of text. More...
 
int DrawString (int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
 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, StringAlignment align, bool underline, FontSize fontsize)
 Draw string, possibly truncated to make it fit in its allocated space. More...
 
int GetStringHeight (const char *str, int maxw, FontSize fontsize)
 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 (const char *str, const Dimension &suggestion)
 Calculate string bounding box for multi-line strings. More...
 
int DrawStringMultiLine (int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
 Draw string, possibly over multiple lines. More...
 
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. More...
 
Dimension GetStringBoundingBox (const char *str, FontSize start_fontsize)
 Return the string dimension in pixels. More...
 
Dimension GetStringBoundingBox (StringID strid)
 Get bounding box of a string. More...
 
Point GetCharPosInString (const char *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. More...
 
const char * GetCharAtPosition (const char *str, int x, FontSize start_fontsize)
 Get the character from a string that is drawn at a specific position. More...
 
void DrawCharCentered (WChar c, int x, int y, TextColour colour)
 Draw single character horizontally centered around (x,y) More...
 
Dimension GetSpriteSize (SpriteID sprid, Point *offset, ZoomLevel zoom)
 Get the size of a sprite. More...
 
static BlitterMode GetBlitterMode (PaletteID pal)
 Helper function to get the blitter mode for different types of palettes. More...
 
void DrawSpriteViewport (SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
 Draw a sprite in a viewport. More...
 
void DrawSprite (SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
 Draw a sprite, not in a viewport. More...
 
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)
 The code for setting up the blitter mode and sprite information before finally drawing the sprite. More...
 
void DoPaletteAnimations ()
 
void GfxInitPalettes ()
 
TextColour GetContrastColour (uint8 background)
 Determine a contrasty text colour for a coloured background. More...
 
void LoadStringWidthTable (bool monospace)
 Initialize _stringwidth_table cache. More...
 
byte GetCharacterWidth (FontSize size, WChar key)
 Return width of character glyph. More...
 
byte GetDigitWidth (FontSize size)
 Return the maximum width of single digit. More...
 
void GetBroadestDigit (uint *front, uint *next, FontSize size)
 Determine the broadest digits for guessing the maximum width of a n-digit number. More...
 
void ScreenSizeChanged ()
 
void UndrawMouseCursor ()
 
void DrawMouseCursor ()
 
void RedrawScreenRect (int left, int top, int right, int bottom)
 
void DrawDirtyBlocks ()
 Repaints the rectangle blocks which are marked as 'dirty'. More...
 
void SetDirtyBlocks (int left, int top, int right, int bottom)
 This function extends the internal _invalid_rect rectangle as it now contains the rectangle defined by the given parameters. More...
 
void MarkWholeScreenDirty ()
 This function mark the whole screen as dirty. More...
 
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...
 
void UpdateCursorSize ()
 Update cursor dimension. More...
 
static void SetCursorSprite (CursorID cursor, PaletteID pal)
 Switch cursor to different sprite. More...
 
static void SwitchAnimatedCursor ()
 
void CursorTick ()
 
void SetMouseCursorBusy (bool busy)
 Set or unset the ZZZ cursor. More...
 
void SetMouseCursor (CursorID sprite, PaletteID pal)
 Assign a single non-animated sprite to the cursor. More...
 
void SetAnimatedMouseCursor (const AnimCursor *table)
 Assign an animation to the cursor. More...
 
bool ChangeResInGame (int width, int height)
 
bool ToggleFullScreen (bool fs)
 
static int CDECL compare_res (const Dimension *pa, const Dimension *pb)
 
void SortResolutions (int count)
 

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?
 
byte _fast_forward
 
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)
 
bool _exit_game
 
GameMode _game_mode
 
SwitchMode _switch_mode
 The next mainloop command.
 
PauseModeByte _pause_mode
 The current pause mode.
 
Palette _cur_palette
 Current palette.
 
static byte _stringwidth_table [FS_END][224]
 Cache containing width of often used characters. More...
 
DrawPixelInfo_cur_dpi
 
byte _colour_gradient [COLOUR_END][8]
 All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
 
static ReusableBuffer< uint8 > _cursor_backup
 
ZoomLevelByte _gui_zoom
 GUI Zoom level.
 
static Rect _invalid_rect
 The rect for repaint. More...
 
static const byte * _colour_remap_ptr
 
static byte _string_colourremap [3]
 Recoloursprite for stringdrawing. The grf loader ensures that ST_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 byte * _dirty_blocks = NULL
 
uint _dirty_block_colour
 

Detailed Description

Handling of drawing text and other gfx related stuff.

Definition in file gfx.cpp.

Function Documentation

◆ 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 278 of file gfx.cpp.

Referenced by ViewportDrawBoundingBoxes().

◆ DrawCharCentered()

void DrawCharCentered ( WChar  c,
int  x,
int  y,
TextColour  colour 
)

Draw single character horizontally centered around (x,y)

Parameters
cCharacter (glyph) to draw
xX position to draw character
yY position to draw character
colourColour to use, see DoDrawString() for details

Definition at line 755 of file gfx.cpp.

Referenced by OskWindow::DrawWidget().

◆ DrawDirtyBlocks()

void DrawDirtyBlocks ( )

Repaints the rectangle blocks which are marked as 'dirty'.

See also
SetDirtyBlocks

Definition at line 1307 of file gfx.cpp.

◆ DrawLayoutLine()

static int DrawLayoutLine ( const ParagraphLayouter::Line line,
int  y,
int  left,
int  right,
StringAlignment  align,
bool  underline,
bool  truncation 
)
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.
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 343 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
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 833 of file gfx.cpp.

Referenced by StoryBookWindow::DrawActionElement(), TransparenciesWindow::DrawWidget(), and BuildTreesWindow::DrawWidget().

◆ 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 806 of file gfx.cpp.

◆ DrawString() [1/2]

int DrawString ( int  left,
int  right,
int  top,
const char *  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, see DoDrawString() for details
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 499 of file gfx.cpp.

References FONT_HEIGHT_LARGE, FONT_HEIGHT_MONO, FONT_HEIGHT_NORMAL, FONT_HEIGHT_SMALL, and max().

Referenced by CargoesField::Draw(), DrawCaption(), NetworkContentListWindow::DrawDetails(), SelectCompanyManagerFaceWindow::DrawFaceStringLabel(), DrawFrame(), DrawInset(), DrawPrice(), DrawText(), StatusBarWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), NetworkChatWindow::DrawWidget(), GenerateLandscapeWindow::DrawWidget(), MusicWindow::DrawWidget(), NetworkContentListWindow::DrawWidget(), AIConfigWindow::DrawWidget(), NetworkStartServerWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), ScenarioEditorToolbarWindow::DrawWidget(), and NetworkGameWindow::OnPaint().

◆ 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, see DoDrawString() for details
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 534 of file gfx.cpp.

References DRAW_STRING_BUFFER.

◆ DrawStringMultiLine() [1/2]

int DrawStringMultiLine ( int  left,
int  right,
int  top,
int  bottom,
const char *  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, see DoDrawString() for details
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 620 of file gfx.cpp.

References Layouter::GetBounds().

Referenced by StationViewWindow::DrawAcceptedCargo(), SelectGameWindow::DrawWidget(), BootstrapAskForDownloadWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), GoalQuestionWindow::DrawWidget(), TooltipsWindow::DrawWidget(), QueryWindow::DrawWidget(), CompanyWindow::DrawWidget(), BuyCompanyWindow::DrawWidget(), 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
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, see DoDrawString() for details
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 682 of file gfx.cpp.

References DRAW_STRING_BUFFER.

◆ 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 1480 of file gfx.cpp.

Referenced by NWidgetMatrix::Draw(), NWidgetLeaf::Draw(), SmallMapWindow::DrawWidget(), and BuildRailStationWindow::DrawWidget().

◆ 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 788 of file gfx.cpp.

◆ 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 1176 of file gfx.cpp.

Referenced by SetDParamMaxDigits().

◆ GetCharacterWidth()

byte GetCharacterWidth ( FontSize  size,
WChar  key 
)

Return width of character glyph.

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

Definition at line 1148 of file gfx.cpp.

References _stringwidth_table, and GetGlyphWidth().

◆ GetCharAtPosition()

const char* GetCharAtPosition ( const char *  str,
int  x,
FontSize  start_fontsize 
)

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

Parameters
strString to test.
xPosition relative to the start of the string.
start_fontsizeFont size to start the text with.
Returns
Pointer to the character at the position or NULL if there is no character at the position.

Definition at line 740 of file gfx.cpp.

◆ GetCharPosInString()

Point GetCharPosInString ( const char *  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
strString containing the character.
chPointer to the character in the string.
start_fontsizeFont size to start the text with.
Returns
Upper left corner of the glyph associated with the character.

Definition at line 727 of file gfx.cpp.

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

◆ GetContrastColour()

TextColour GetContrastColour ( uint8  background)

Determine a contrasty text colour for a coloured background.

Parameters
backgroundBackground colour.
Returns
TC_BLACK or TC_WHITE depending on what gives a better contrast.

Definition at line 1116 of file gfx.cpp.

References Palette::palette.

◆ GetDigitWidth()

byte GetDigitWidth ( FontSize  size)

Return the maximum width of single digit.

Parameters
sizeFont of the digit
Returns
Width of the digit.

Definition at line 1161 of file gfx.cpp.

Referenced by BuildSignalWindow::UpdateWidgetSize().

◆ GetSpriteSize()

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

◆ GetStringBoundingBox() [1/2]

Dimension GetStringBoundingBox ( const char *  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 699 of file gfx.cpp.

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), DrawCaption(), DrawText(), TimetableWindow::DrawWidget(), OrdersWindow::DrawWidget(), BaseVehicleListWindow::GetActionDropdownSize(), BaseGraphWindow::GetYLabelWidth(), SelectCompanyManagerFaceWindow::OnInit(), IndustryCargoesWindow::OnInit(), TextfileWindow::SetupScrollbars(), SelectGameWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), SetDateWindow::UpdateWidgetSize(), StatusBarWindow::UpdateWidgetSize(), BuildObjectWindow::UpdateWidgetSize(), SubsidyListWindow::UpdateWidgetSize(), BootstrapAskForDownloadWindow::UpdateWidgetSize(), BuildBridgeWindow::UpdateWidgetSize(), GoalListWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), BuildAirportWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), NewsWindow::UpdateWidgetSize(), MusicTrackSelectionWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), NetworkChatWindow::UpdateWidgetSize(), SaveLoadWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), MusicWindow::UpdateWidgetSize(), NetworkContentListWindow::UpdateWidgetSize(), StoryBookWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), AIConfigWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), PaymentRatesGraphWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), BuildRailStationWindow::UpdateWidgetSize(), NetworkStartServerWindow::UpdateWidgetSize(), CompanyLeagueWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), IndustryDirectoryWindow::UpdateWidgetSize(), StationViewWindow::UpdateWidgetSize(), BuildVehicleWindow::UpdateWidgetSize(), CompanyInfrastructureWindow::UpdateWidgetSize(), NetworkClientListPopupWindow::UpdateWidgetSize(), GameSettingsWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), SavePresetWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), ScenarioEditorToolbarWindow::UpdateWidgetSize(), and Textbuf::UpdateWidth().

◆ GetStringBoundingBox() [2/2]

Dimension GetStringBoundingBox ( StringID  strid)

Get bounding box of a string.

Uses parameters set by #DParam if needed. Has the same restrictions as #GetStringBoundingBox(const char *str).

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

Definition at line 711 of file gfx.cpp.

References DRAW_STRING_BUFFER.

◆ GetStringHeight() [1/2]

int GetStringHeight ( const char *  str,
int  maxw,
FontSize  fontsize 
)

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 547 of file gfx.cpp.

Referenced by TextfileWindow::GetContentHeight(), StoryBookWindow::GetHeadHeight(), SettingEntry::GetMaxHelpHeight(), StoryBookWindow::GetPageElementHeight(), SelectGameWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), BootstrapAskForDownloadWindow::UpdateWidgetSize(), ErrmsgWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), GoalQuestionWindow::UpdateWidgetSize(), and TooltipsWindow::UpdateWidgetSize().

◆ 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 559 of file gfx.cpp.

References DRAW_STRING_BUFFER.

◆ 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 572 of file gfx.cpp.

References DRAW_STRING_BUFFER.

◆ GetStringMultiLineBoundingBox() [1/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 587 of file gfx.cpp.

Referenced by QueryWindow::UpdateWidgetSize().

◆ GetStringMultiLineBoundingBox() [2/2]

Dimension GetStringMultiLineBoundingBox ( const char *  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 599 of file gfx.cpp.

◆ 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 
)
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.
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 863 of file gfx.cpp.

◆ GfxDoDrawLine()

static void GfxDoDrawLine ( void *  video,
int  x,
int  y,
int  x2,
int  y2,
int  screen_width,
int  screen_height,
uint8  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 173 of file gfx.cpp.

◆ 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
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 112 of file gfx.cpp.

References BlitterFactory::GetCurrentBlitter().

Referenced by NWidgetMatrix::Draw(), NWidgetViewport::Draw(), NWidgetToolbarContainer::Draw(), DrawCaption(), NetworkContentListWindow::DrawDetails(), DrawFrame(), BootstrapBackground::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), MusicWindow::DrawWidget(), TooltipsWindow::DrawWidget(), NewGRFWindow::DrawWidget(), NetworkClientListPopupWindow::DrawWidget(), BuildRailWaypointWindow::DrawWidget(), SavePresetWindow::DrawWidget(), and NetworkGameWindow::OnPaint().

◆ 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 231 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 1130 of file gfx.cpp.

References FS_BEGIN, and FS_MONO.

Referenced by ReloadNewGRFData().

◆ SetAnimatedMouseCursor()

void SetAnimatedMouseCursor ( const AnimCursor table)

Assign an animation to the cursor.

Parameters
tableArray of animation states.
See also
SetMouseCursor

Definition at line 1630 of file gfx.cpp.

References CursorVars::animate_cur, CursorVars::animate_list, PalSpriteID::pal, and CursorVars::sprite_seq.

Referenced by CenterBounds().

◆ 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 313 of file gfx.cpp.

◆ 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 1566 of file gfx.cpp.

References PalSpriteID::pal, PalSpriteID::sprite, CursorVars::sprite_count, CursorVars::sprite_pos, CursorVars::sprite_seq, and UpdateCursorSize().

Referenced by SetMouseCursor().

◆ SetDirtyBlocks()

void SetDirtyBlocks ( int  left,
int  top,
int  right,
int  bottom 
)

This function extends the internal _invalid_rect rectangle as it now contains the rectangle defined by the given parameters.

Note the point (0,0) is top left.

Parameters
leftThe left edge of the rectangle
topThe top edge of the rectangle
rightThe right edge of the rectangle
bottomThe bottom edge of the rectangle
See also
DrawDirtyBlocks
Todo:
The name of the function should be called like AddDirtyBlock as it neither set a dirty rect nor add several dirty rects although the function name is in plural. (Progman)

Definition at line 1418 of file gfx.cpp.

Referenced by MarkViewportDirty(), MarkWholeScreenDirty(), NWidgetBase::SetDirty(), Window::SetDirty(), and NewsWindow::SetWindowTop().

◆ 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 1617 of file gfx.cpp.

References CursorVars::animate_timeout, and SetCursorSprite().

Referenced by CenterBounds(), and SetMouseCursorBusy().

◆ SetMouseCursorBusy()

void SetMouseCursorBusy ( bool  busy)

Set or unset the ZZZ cursor.

Parameters
busyWhether to show the ZZZ cursor.

Definition at line 1602 of file gfx.cpp.

References SetMouseCursor(), SPR_CURSOR_MOUSE, PalSpriteID::sprite, and CursorVars::sprite_seq.

Referenced by CenterBounds(), CleanupGeneration(), and GenerateProgressWindow::OnClick().

◆ UpdateCursorSize()

void UpdateCursorSize ( )

Update cursor dimension.

Called when changing cursor sprite resp. reloading grfs.

Definition at line 1530 of file gfx.cpp.

References GetMaxSpriteID().

Referenced by SetCursorSprite().

Variable Documentation

◆ _stringwidth_table

byte _stringwidth_table[FS_END][224]
static

Cache containing width of often used characters.

See also
GetCharacterWidth()

Definition at line 51 of file gfx.cpp.

Referenced by GetCharacterWidth().