OpenTTD Source  12.0-beta2
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.

Macros

#define FONT_HEIGHT_SMALL   (GetCharacterHeight(FS_SMALL))
 Height of characters in the small (FS_SMALL) font. More...
 
#define FONT_HEIGHT_NORMAL   (GetCharacterHeight(FS_NORMAL))
 Height of characters in the normal (FS_NORMAL) font. More...
 
#define FONT_HEIGHT_LARGE   (GetCharacterHeight(FS_LARGE))
 Height of characters in the large (FS_LARGE) font. More...
 
#define FONT_HEIGHT_MONO   (GetCharacterHeight(FS_MONO))
 Height of characters in the large (FS_MONO) font. More...
 
#define GREY_SCALE(level)   (level)
 Return the colour for a particular greyscale level. More...
 

Functions

void GameLoop ()
 
void CreateConsole ()
 
void HandleKeypress (uint keycode, WChar 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...
 
void UpdateGUIZoom ()
 Resolve GUI zoom level, if auto-suggestion is requested.
 
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...
 
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...
 
int DrawString (int left, int right, int top, const char *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, const std::string &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, const char *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, const std::string &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 (WChar 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...
 
Dimension GetStringBoundingBox (const char *str, FontSize start_fontsize=FS_NORMAL)
 Return the string dimension in pixels. More...
 
Dimension GetStringBoundingBox (const std::string &str, FontSize start_fontsize=FS_NORMAL)
 Return the string dimension in pixels. More...
 
Dimension GetStringBoundingBox (StringID strid)
 Get bounding box of a string. More...
 
int GetStringHeight (const char *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 (const char *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 (const char *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...
 
const char * GetCharAtPosition (const char *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...
 
bool CopyPalette (Palette &local_palette, bool force_copy=false)
 Copy the current palette if the palette was updated. More...
 
void GfxInitPalettes ()
 
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...
 
static 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, WChar 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...
 
TextColour GetContrastColour (uint8 background, uint8 threshold=128)
 Determine a contrasty text colour for a coloured background. 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 _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.
 
static const int DRAW_STRING_BUFFER = 2048
 Size of the buffer used for drawing strings.
 
DrawPixelInfo_cur_dpi
 
byte _colour_gradient [COLOUR_END][8]
 All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
 
static const uint8 PC_BLACK = GREY_SCALE(1)
 Black palette colour.
 
static const uint8 PC_DARK_GREY = GREY_SCALE(6)
 Dark grey palette colour.
 
static const uint8 PC_GREY = GREY_SCALE(10)
 Grey palette colour.
 
static const uint8 PC_WHITE = GREY_SCALE(15)
 White palette colour.
 
static const uint8 PC_VERY_DARK_RED = 0xB2
 Almost-black red palette colour.
 
static const uint8 PC_DARK_RED = 0xB4
 Dark red palette colour.
 
static const uint8 PC_RED = 0xB8
 Red palette colour.
 
static const uint8 PC_VERY_DARK_BROWN = 0x56
 Almost-black brown palette colour.
 
static const uint8 PC_ORANGE = 0xC2
 Orange palette colour.
 
static const uint8 PC_YELLOW = 0xBF
 Yellow palette colour.
 
static const uint8 PC_LIGHT_YELLOW = 0x44
 Light yellow palette colour.
 
static const uint8 PC_VERY_LIGHT_YELLOW = 0x45
 Almost-white yellow palette colour.
 
static const uint8 PC_GREEN = 0xD0
 Green palette colour.
 
static const uint8 PC_VERY_DARK_BLUE = 0x9A
 Almost-black blue palette colour.
 
static const uint8 PC_DARK_BLUE = 0x9D
 Dark blue palette colour.
 
static const uint8 PC_LIGHT_BLUE = 0x98
 Light blue palette colour.
 
static const uint8 PC_ROUGH_LAND = 0x52
 Dark green palette colour for rough land.
 
static const uint8 PC_GRASS_LAND = 0x54
 Dark green palette colour for grass land.
 
static const uint8 PC_BARE_LAND = 0x37
 Brown palette colour for bare land.
 
static const uint8 PC_RAINFOREST = 0x5C
 Pale green palette colour for rainforest.
 
static const uint8 PC_FIELDS = 0x25
 Light brown palette colour for fields.
 
static const uint8 PC_TREES = 0x57
 Green palette colour for trees.
 
static const uint8 PC_WATER = 0xC9
 Dark blue palette colour for water.
 

Detailed Description

Functions related to the gfx engine.

Definition in file gfx_func.h.

Macro Definition Documentation

◆ FONT_HEIGHT_LARGE

#define FONT_HEIGHT_LARGE   (GetCharacterHeight(FS_LARGE))

Height of characters in the large (FS_LARGE) font.

Note
Some characters may be oversized.

Definition at line 168 of file gfx_func.h.

◆ FONT_HEIGHT_MONO

#define FONT_HEIGHT_MONO   (GetCharacterHeight(FS_MONO))

Height of characters in the large (FS_MONO) font.

Note
Some characters may be oversized.

Definition at line 171 of file gfx_func.h.

◆ FONT_HEIGHT_NORMAL

#define FONT_HEIGHT_NORMAL   (GetCharacterHeight(FS_NORMAL))

Height of characters in the normal (FS_NORMAL) font.

Note
Some characters may be oversized.

Definition at line 165 of file gfx_func.h.

◆ FONT_HEIGHT_SMALL

#define FONT_HEIGHT_SMALL   (GetCharacterHeight(FS_SMALL))

Height of characters in the small (FS_SMALL) font.

Note
Some characters may be oversized.

Definition at line 162 of file gfx_func.h.

◆ GREY_SCALE

#define GREY_SCALE (   level)    (level)

Return the colour for a particular greyscale level.

Parameters
levelIntensity, 0 = black, 15 = white
Returns
colour

Definition at line 188 of file gfx_func.h.

Function Documentation

◆ CenterBounds()

static int CenterBounds ( int  min,
int  max,
int  size 
)
inlinestatic

Determine where to draw a centred object inside a widget.

Parameters
minThe top or left coordinate.
maxThe bottom or right coordinate.
sizeThe height or width of the object to draw.
Returns
Offset of where to start drawing the object.

Definition at line 137 of file gfx_func.h.

Referenced by GetAlignedPosition().

◆ CopyPalette()

bool CopyPalette ( Palette local_palette,
bool  force_copy 
)

Copy the current palette if the palette was updated.

Used by video-driver to get a current up-to-date version of the palette, to avoid two threads accessing the same piece of memory (with a good chance one is already updating the palette while the other is drawing based on it).

Parameters
local_paletteThe location to copy the palette to.
force_copyWhether to ignore if there is an update for the palette.
Returns
True iff a copy was done.

Definition at line 1216 of file gfx.cpp.

References _cur_palette, _palette_mutex, Palette::count_dirty, Palette::first_dirty, and lock.

Referenced by VideoDriver_SDL::CheckPaletteAnim(), VideoDriver_Win32Base::CheckPaletteAnim(), VideoDriver_SDL_Base::CheckPaletteAnim(), and VideoDriver_SDL_Base::ClientSizeChanged().

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

Referenced by ViewportDrawBoundingBoxes().

◆ DrawCharCentered()

void DrawCharCentered ( WChar  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 959 of file gfx.cpp.

References SetColourRemap().

Referenced by OskWindow::DrawWidget().

◆ 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
leftLeft edge of the rectangle that should be repainted
topTop edge of the rectangle that should be repainted
rightRight edge of the rectangle that should be repainted
bottomBottom edge of the rectangle that should be repainted

Definition at line 970 of file window.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 1041 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 1014 of file gfx.cpp.

◆ DrawString() [1/3]

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

References FONT_HEIGHT_LARGE, FONT_HEIGHT_MONO, FONT_HEIGHT_NORMAL, and FONT_HEIGHT_SMALL.

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

◆ DrawString() [2/3]

int DrawString ( int  left,
int  right,
int  top,
const std::string &  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 678 of file gfx.cpp.

References DrawString().

◆ DrawString() [3/3]

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

References DRAW_STRING_BUFFER.

◆ DrawStringMultiLine() [1/3]

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

References Layouter::GetBounds().

Referenced by StationViewWindow::DrawAcceptedCargo(), DrawStringMultiLine(), SelectGameWindow::DrawWidget(), BootstrapErrorWindow::DrawWidget(), BootstrapAskForDownloadWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), GoalQuestionWindow::DrawWidget(), TooltipsWindow::DrawWidget(), QueryStringWindow::DrawWidget(), QueryWindow::DrawWidget(), NetworkCompanyPasswordWindow::DrawWidget(), CompanyWindow::DrawWidget(), NetworkAskRelayWindow::DrawWidget(), BuyCompanyWindow::DrawWidget(), HighScoreWindow::OnPaint(), and IConsoleWindow::OnPaint().

◆ DrawStringMultiLine() [2/3]

int DrawStringMultiLine ( int  left,
int  right,
int  top,
int  bottom,
const std::string &  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 850 of file gfx.cpp.

References DrawStringMultiLine().

◆ DrawStringMultiLine() [3/3]

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

References BlitterFactory::GetCurrentBlitter().

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

◆ 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 561 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]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 1415 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
sizeFont size to get height of
Returns
Height of characters in the given font (pixels)

Definition at line 69 of file fontcache.cpp.

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

Referenced by NWidgetResizeBase::SetMinimalSize(), and NWidgetResizeBase::SetMinimalTextLines().

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

References _stringwidth_table, and GetGlyphWidth().

Referenced by GetBroadestDigit(), and GetDigitWidth().

◆ 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 nullptr if there is no character at the position.

Definition at line 944 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 931 of file gfx.cpp.

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

◆ GetContrastColour()

TextColour GetContrastColour ( uint8  background,
uint8  threshold 
)

Determine a contrasty text colour for a coloured background.

Parameters
backgroundBackground colour.
thresholdBackground colour brightness threshold below which the background is considered dark and TC_WHITE is returned, range: 0 - 255, default 128.
Returns
TC_BLACK or TC_WHITE depending on what gives a better contrast.

Definition at line 1354 of file gfx.cpp.

References _cur_palette, and 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 1400 of file gfx.cpp.

References GetCharacterWidth().

Referenced by BuildSignalWindow::UpdateWidgetSize().

◆ GetSpriteSize()

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

◆ GetStringBoundingBox() [1/3]

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

Referenced by DrawCaption(), DrawText(), OrdersWindow::DrawWidget(), BaseVehicleListWindow::GetActionDropdownSize(), ExpensesList::GetCategoriesWidth(), StoryBookWindow::GetPageElementFloatWidth(), StoryBookWindow::GetPageElementHeight(), GetStringBoundingBox(), BaseGraphWindow::GetYLabelWidth(), BaseVehicleListWindow::OnInit(), SelectCompanyManagerFaceWindow::OnInit(), IndustryCargoesWindow::OnInit(), GoalListWindow::OnPaint(), NWidgetBackground::SetupSmallestSize(), SelectGameWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), BootstrapErrorWindow::UpdateWidgetSize(), SetDateWindow::UpdateWidgetSize(), StatusBarWindow::UpdateWidgetSize(), SubsidyListWindow::UpdateWidgetSize(), BuildBridgeWindow::UpdateWidgetSize(), GoalListWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), BootstrapAskForDownloadWindow::UpdateWidgetSize(), BuildObjectWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), BuildAirportWindow::UpdateWidgetSize(), NewsWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), MusicTrackSelectionWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), SaveLoadWindow::UpdateWidgetSize(), NetworkContentListWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), MusicWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), StoryBookWindow::UpdateWidgetSize(), AIConfigWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), PaymentRatesGraphWindow::UpdateWidgetSize(), NetworkStartServerWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), BuildRailStationWindow::UpdateWidgetSize(), CompanyLeagueWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), StationViewWindow::UpdateWidgetSize(), SelectCompanyManagerFaceWindow::UpdateWidgetSize(), BuildVehicleWindow::UpdateWidgetSize(), IndustryDirectoryWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), CompanyInfrastructureWindow::UpdateWidgetSize(), GameSettingsWindow::UpdateWidgetSize(), SavePresetWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), NetworkAskRelayWindow::UpdateWidgetSize(), ScenarioEditorToolbarWindow::UpdateWidgetSize(), and Textbuf::UpdateWidth().

◆ GetStringBoundingBox() [2/3]

Dimension GetStringBoundingBox ( const std::string &  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 904 of file gfx.cpp.

References GetStringBoundingBox().

◆ GetStringBoundingBox() [3/3]

Dimension GetStringBoundingBox ( StringID  strid)

Get bounding box of a string.

Uses parameters set by SetDParam if needed. Has the same restrictions as GetStringBoundingBox(const char *str, FontSize start_fontsize).

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

Definition at line 915 of file gfx.cpp.

References DRAW_STRING_BUFFER.

◆ GetStringHeight() [1/2]

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

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

References DRAW_STRING_BUFFER.

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

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

Referenced by QueryWindow::UpdateWidgetSize().

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

References BlitterFactory::GetCurrentBlitter().

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

◆ HandleKeypress()

void HandleKeypress ( uint  keycode,
WChar  key 
)

Handle keyboard input.

Parameters
keycodeVirtual keycode of the key.
keyUnicode character of the key.

Definition at line 2594 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
strText string to input.
markedIs the input a marked composition string from an IME?
caretMove the caret to this point in the insertion string.

Definition at line 2680 of file window.cpp.

References EditBoxInGlobalFocus().

Referenced by CancelIMEComposition(), and HandleIMEComposition().

◆ LoadStringWidthTable()

void LoadStringWidthTable ( bool  monospace)

Initialize _stringwidth_table cache.

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

Definition at line 1368 of file gfx.cpp.

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

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

◆ SetMouseCursorBusy()

void SetMouseCursorBusy ( bool  busy)

Set or unset the ZZZ cursor.

Parameters
busyWhether to show the ZZZ cursor.

Definition at line 1830 of file gfx.cpp.

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

◆ UpdateCursorSize()

void UpdateCursorSize ( )

Update cursor dimension.

Called when changing cursor sprite resp. reloading grfs.

Definition at line 1758 of file gfx.cpp.

References GetMaxSpriteID(), and lengthof.