OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Macros | Enumerations | Functions | Variables
gfx_func.h File Reference

Functions related to the gfx engine. More...

`#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.
#define | FONT_HEIGHT_NORMAL (GetCharacterHeight(FS_NORMAL))
| Height of characters in the normal (FS_NORMAL) font.
#define | FONT_HEIGHT_LARGE (GetCharacterHeight(FS_LARGE))
| Height of characters in the large (FS_LARGE) font.
#define | FONT_HEIGHT_MONO (GetCharacterHeight(FS_MONO))
| Height of characters in the large (FS_MONO) font.
#define | GREY_SCALE(level) (level)
| Return the colour for a particular greyscale level.

## Enumerations
enum | StringAlignment { SA_LEFT = 0 << 0, SA_HOR_CENTER = 1 << 0, SA_RIGHT = 2 << 0, SA_HOR_MASK = 3 << 0, SA_TOP = 0 << 2, SA_VERT_CENTER = 1 << 2, SA_BOTTOM = 2 << 2, SA_VERT_MASK = 3 << 2, SA_CENTER = SA_HOR_CENTER | SA_VERT_CENTER, SA_FORCE = 1 << 4 }
| How to align the to-be drawn text. More...

## Functions
void | GameLoop ()
void | CreateConsole ()
void | HandleKeypress (uint keycode, WChar key)
| Handle keyboard input.
void | HandleTextInput (const char *str, bool marked=false, const char *caret=NULL, const char *insert_location=NULL, const char *replacement_end=NULL)
| Handle text input.
void | HandleCtrlChanged ()
| State of CONTROL key has changed.
void | HandleMouseEvents ()
| Handle a mouse event from the video driver.
void | CSleep (int milliseconds)
void | UpdateWindows ()
| Update the continuously changing contents of the windows, such as the viewports.
void | DrawMouseCursor ()
void | ScreenSizeChanged ()
void | GameSizeChanged ()
| Size of the application screen changed.
void | UndrawMouseCursor ()
void | RedrawScreenRect (int left, int top, int right, int bottom)
void | GfxScroll (int left, int top, int width, int height, int xo, int yo)
Dimension | GetSpriteSize (SpriteID sprid, Point *offset=NULL, ZoomLevel zoom=ZOOM_LVL_GUI)
| Get the size of a sprite.
void | DrawSpriteViewport (SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub=NULL)
| Draw a sprite in a viewport.
void | DrawSprite (SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub=NULL, ZoomLevel zoom=ZOOM_LVL_GUI)
| Draw a sprite, not in a viewport.
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.
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.
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.
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.
void | DrawCharCentered (uint32 c, int x, int y, TextColour colour)
| Draw single character horizontally centered around (x,y)
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.
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.
Dimension | GetStringBoundingBox (const char *str, FontSize start_fontsize=FS_NORMAL)
| Return the string dimension in pixels.
Dimension | GetStringBoundingBox (StringID strid)
| Get bounding box of a string.
int | GetStringHeight (const char *str, int maxw, FontSize fontsize=FS_NORMAL)
| Calculates height of string (in pixels).
int | GetStringHeight (StringID str, int maxw)
| Calculates height of string (in pixels).
int | GetStringLineCount (StringID str, int maxw)
| Calculates number of lines of string.
Dimension | GetStringMultiLineBoundingBox (StringID str, const Dimension &suggestion)
| Calculate string bounding box for multi-line strings.
Dimension | GetStringMultiLineBoundingBox (const char *str, const Dimension &suggestion)
| Calculate string bounding box for multi-line strings.
void | LoadStringWidthTable (bool monospace=false)
| Initialize _stringwidth_table cache.
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.
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.
void | DrawDirtyBlocks ()
| Repaints the rectangle blocks which are marked as 'dirty'.
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.
void | MarkWholeScreenDirty ()
| This function mark the whole screen as dirty.
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.
void | DrawOverlappedWindowForAll (int left, int top, int right, int bottom)
| From a rectangle that needs redrawing, find the windows that intersect with the rectangle.
void | SetMouseCursorBusy (bool busy)
| Set or unset the ZZZ cursor.
void | SetMouseCursor (CursorID cursor, PaletteID pal)
| Assign a single non-animated sprite to the cursor.
void | SetAnimatedMouseCursor (const AnimCursor *table)
| Assign an animation to the cursor.
void | CursorTick ()
void | UpdateCursorSize ()
| Update cursor dimension.
bool | ChangeResInGame (int w, int h)
void | SortResolutions (int count)
bool | ToggleFullScreen (bool fs)
byte | GetCharacterWidth (FontSize size, uint32 key)
| Return width of character glyph.
byte | GetDigitWidth (FontSize size=FS_NORMAL)
| Return the maximum width of single digit.
void | GetBroadestDigit (uint *front, uint *next, FontSize size=FS_NORMAL)
| Determine the broadest digits for guessing the maximum width of a n-digit number.
int | GetCharacterHeight (FontSize size)
| Get height of a character for a given font size.
TextColour | GetContrastColour (uint8 background)
| Determine a contrasty text colour for a coloured background.

## 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
| Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
int | _num_resolutions
| The number of resolutions.
Dimension | _resolutions [32]
| 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)
bool | _palette_remap_grf []
| Whether the given NewGRFs must get a palette remap from windows to DOS or not.
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_DARK_BLUE = 0x9D
| Dark blue palette colour.
static const uint8 | PC_LIGHT_BLUE = 0x98
| Light blue palette colour.

## Detailed Description

Functions related to the gfx engine.

Definition in file gfx_func.h.

## Macro Definition Documentation

#define FONT_HEIGHT_LARGE (GetCharacterHeight(FS_LARGE))

Height of characters in the large (FS_LARGE) font.

Definition at line 171 of file gfx_func.h.

Referenced by DrawString(), and HighScoreWindow::OnPaint().

#define FONT_HEIGHT_MONO (GetCharacterHeight(FS_MONO))

Height of characters in the large (FS_MONO) font.

Definition at line 174 of file gfx_func.h.

Referenced by DrawString(), TextfileWindow::DrawWidget(), and TextfileWindow::SetupScrollbars().

#define FONT_HEIGHT_NORMAL (GetCharacterHeight(FS_NORMAL))

Height of characters in the normal (FS_NORMAL) font.

Definition at line 168 of file gfx_func.h.

Referenced by CargoesField::CargoClickedAt(), CargoesField::CargoLabelClickedAt(), CheckClickOnViewportSign(), CargoesField::Draw(), StationViewWindow::DrawAcceptedCargo(), DrawAircraftDetails(), DrawButtonDropdown(), StationViewWindow::DrawCargoRatings(), DrawCategories(), CompanyInfrastructureWindow::DrawCountLine(), NetworkContentListWindow::DrawDetails(), DrawEngineList(), StationViewWindow::DrawEntries(), DrawFrame(), CargoesField::DrawHorConnection(), IndustryViewWindow::DrawInfo(), NetworkContentListWindow::DrawMatrix(), DrawOrderString(), GoalListWindow::DrawPartialGoalList(), TownAuthorityWindow::DrawRatings(), DrawRoadVehDetails(), NetworkGameWindow::DrawServerLine(), SettingEntry::DrawSetting(), SettingsPage::DrawSetting(), DrawShipDetails(), DrawString(), DrawTrainDetails(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehiclePurchaseInfo(), DrawVehicleRefitWindow(), GraphLegendWindow::DrawWidget(), LandInfoWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), AIListWindow::DrawWidget(), StatusBarWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), SignListWindow::DrawWidget(), CheatWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), TownViewWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), TimetableWindow::DrawWidget(), AISettingsWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), StoryBookWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), NewGRFWindow::DrawWidget(), CompanyLeagueWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), NetworkClientListPopupWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), SavePresetWindow::DrawWidget(), CompanyWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), ScenarioEditorToolbarWindow::DrawWidget(), DrawYearColumn(), StoryBookWindow::GetContentHeight(), TownViewWindow::GetDesiredInfoHeight(), GetEngineListHeight(), StoryBookWindow::GetHeadHeight(), VehicleDetailsWindow::GetRoadVehDetailsHeight(), MakeAsdfgKeys(), MakeNumberKeys(), MakeNWidgetCompanyLines(), MakeQwertyKeys(), MakeSpacebarKeys(), MakeTopKeys(), MakeZxcvbKeys(), ViewportSign::MarkDirty(), NetworkDrawChatMessage(), NetworkReInitChatBoxSize(), TownAuthorityWindow::OnClick(), CompanyStationsWindow::OnClick(), StoryBookWindow::OnClick(), IndustryViewWindow::OnClick(), StationViewWindow::OnClick(), IndustryCargoesWindow::OnInit(), NetworkClientListPopupWindow::OnMouseLoop(), BuildAirportWindow::OnPaint(), GameSettingsWindow::OnPaint(), NWidgetBackground::SetupSmallestSize(), SelectGameWindow::UpdateWidgetSize(), EnginePreviewWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), AIListWindow::UpdateWidgetSize(), BuildObjectWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), TownAuthorityWindow::UpdateWidgetSize(), SignListWindow::UpdateWidgetSize(), CheatWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), BuildAirportWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), AISettingsWindow::UpdateWidgetSize(), NewGRFInspectWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), AboutWindow::UpdateWidgetSize(), SaveLoadWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), StoryBookWindow::UpdateWidgetSize(), RefitWindow::UpdateWidgetSize(), NewGRFWindow::UpdateWidgetSize(), AIConfigWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), SpriteAlignerWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), BuildRailStationWindow::UpdateWidgetSize(), AIDebugWindow::UpdateWidgetSize(), CompanyLeagueWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), PerformanceRatingDetailWindow::UpdateWidgetSize(), StationViewWindow::UpdateWidgetSize(), NetworkLobbyWindow::UpdateWidgetSize(), CompanyInfrastructureWindow::UpdateWidgetSize(), GameSettingsWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), VehicleDetailsWindow::UpdateWidgetSize(), NetworkJoinStatusWindow::UpdateWidgetSize(), SavePresetWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), and ViewportAddString().

#define FONT_HEIGHT_SMALL (GetCharacterHeight(FS_SMALL))

Height of characters in the small (FS_SMALL) font.

Definition at line 165 of file gfx_func.h.

Referenced by CheckClickOnViewportSign(), DrawEngineList(), DrawString(), SmallMapWindow::DrawTowns(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), LinkGraphLegendWindow::DrawWidget(), SmallMapWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), SmallMapWindow::GetLegendHeight(), SmallMapWindow::GetPositionOnLegend(), GetVehicleListHeight(), MusicTrackSelectionWindow::OnClick(), CompanyStationsWindow::UpdateWidgetSize(), and BaseGraphWindow::UpdateWidgetSize().

#define GREY_SCALE | ( |  | level | ) | (level)

Return the colour for a particular greyscale level.

Parameters

  level | Intensity, 0 = black, 15 = white

Returns
  colour

Definition at line 193 of file gfx_func.h.

## Enumeration Type Documentation

enum StringAlignment

How to align the to-be drawn text.

Enumerator:

  SA_LEFT | Left align the text.
  SA_HOR_CENTER | Horizontally center the text.
  SA_RIGHT | Right align the text (must be a single bit).
  SA_HOR_MASK | Mask for horizontal alignment.
  SA_TOP | Top align the text.
  SA_VERT_CENTER | Vertically center the text.
  SA_BOTTOM | Bottom align the text.
  SA_VERT_MASK | Mask for vertical alignment.
  SA_CENTER | Center both horizontally and vertically.
  SA_FORCE | Force the alignment, i.e. don't swap for RTL languages.

Definition at line 97 of file gfx_func.h.

## Function Documentation

void CheckBlitter | ( |  | ) |

Check whether we still use the right blitter, or use another (better) one.

Definition at line 302 of file gfxinit.cpp.

References GfxClearSpriteCache(), ReInitAllWindows(), and SwitchNewGRFBlitter().

Referenced by MenuClickSettings().

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

References PC_WHITE.

Referenced by ViewportDrawBoundingBoxes().

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

Draw single character horizontally centered around (x,y)

Parameters

  c | Character (glyph) to draw
  x | X position to draw character
  y | Y position to draw character
  colour | Colour to use, see DoDrawString() for details

Definition at line 755 of file gfx.cpp.

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

Referenced by OskWindow::DrawWidget().

void DrawDirtyBlocks | ( |  | ) |

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

See Also
  SetDirtyBlocks

Definition at line 1307 of file gfx.cpp.

References _modal_progress_paint_mutex, _modal_progress_work_mutex, _realtime_tick, _switch_mode, Align(), ThreadMutex::BeginCritical(), ThreadMutex::EndCritical(), HasModalProgress(), IsFirstModalProgressLoop(), and MODAL_PROGRESS_REDRAW_TIMEOUT.

Referenced by MakeScreenshot(), and UpdateWindows().

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 932 of file window.cpp.

References DrawOverlappedWindow(), Window::height, Window::left, MayBeShown(), Window::top, and Window::width.

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

References BM_NORMAL, BM_TRANSPARENT, GB(), GetBlitterMode(), HasBit(), PALETTE_MODIFIER_TRANSPARENT, PALETTE_TEXT_RECOLOUR, PALETTE_WIDTH, SetColourRemap(), SPRITE_WIDTH, ST_NORMAL, and ST_RECOLOUR.

Referenced by VehicleSpriteSeq::Draw(), StoryBookWindow::DrawActionElement(), DrawArrowButtons(), DrawButtonDropdown(), DrawCargoIcons(), DrawCloseBox(), DrawCommonTileSeqInGUI(), DrawCompanyIcon(), DrawCompanyManagerFace(), DrawDebugBox(), DrawDefSizeBox(), DrawDropDownButton(), DrawEngineList(), VehicleGroupWindow::DrawGroupInfo(), DrawHorizontalScrollbar(), DrawImageButtons(), NetworkContentListWindow::DrawMatrix(), DrawNewObjectTileInGUI(), DrawOrderString(), TownAuthorityWindow::DrawRatings(), DrawResizeBox(), DrawRoadDepotSprite(), NetworkGameWindow::DrawServerLine(), SettingsPage::DrawSetting(), DrawShadeBox(), BuildSignalWindow::DrawSignalSprite(), Window::DrawSortButtonState(), DrawStationTile(), DrawStickyBox(), DepotWindow::DrawVehicleInDepot(), DrawVehicleProfitButton(), DrawVehicleRefitWindow(), DrawVerticalScrollbar(), TransparenciesWindow::DrawWidget(), BuildTreesWindow::DrawWidget(), StatusBarWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), CheatWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), ScenarioEditorLandscapeGenerationWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), CompanyWindow::DrawWidget(), VehicleViewWindow::DrawWidget(), and MainWindow::OnPaint().

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

References BM_NORMAL, BM_TRANSPARENT, GB(), GetBlitterMode(), HasBit(), PALETTE_MODIFIER_TRANSPARENT, PALETTE_TEXT_RECOLOUR, PALETTE_WIDTH, SetColourRemap(), SPRITE_WIDTH, ST_NORMAL, and ST_RECOLOUR.

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

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

References SmallVector< T, S >::Begin(), DrawLayoutLine(), FONT_HEIGHT_LARGE, FONT_HEIGHT_MONO, FONT_HEIGHT_NORMAL, FONT_HEIGHT_SMALL, SmallVector< T, S >::Length(), and max().

Referenced by CargoesField::Draw(), StoryBookWindow::DrawActionElement(), DrawAircraftDetails(), DrawButtonDropdown(), DrawCaption(), StationViewWindow::DrawCargoRatings(), DrawCategories(), CompanyInfrastructureWindow::DrawCountLine(), NetworkContentListWindow::DrawDetails(), DrawEngineList(), StationViewWindow::DrawEntries(), SelectCompanyManagerFaceWindow::DrawFaceStringLabel(), DrawFrame(), BaseGraphWindow::DrawGraph(), VehicleGroupWindow::DrawGroupInfo(), IndustryViewWindow::DrawInfo(), DrawInset(), DrawLabel(), NetworkContentListWindow::DrawMatrix(), DrawNewsString(), DrawOrderString(), GoalListWindow::DrawPartialGoalList(), DrawPrice(), TownAuthorityWindow::DrawRatings(), DrawRoadVehDetails(), NetworkGameWindow::DrawServerLine(), SettingEntry::DrawSetting(), SettingsPage::DrawSetting(), DrawShipDetails(), DrawString(), DrawText(), SmallMapWindow::DrawTowns(), DrawTrainDetails(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehiclePurchaseInfo(), DrawVehicleRefitWindow(), TextfileWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), LandInfoWindow::DrawWidget(), LinkGraphLegendWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), AIListWindow::DrawWidget(), StatusBarWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), SmallMapWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), SignListWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), CheatWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), TownViewWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), TimetableWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), AISettingsWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), NetworkChatWindow::DrawWidget(), AboutWindow::DrawWidget(), StoryBookWindow::DrawWidget(), GenerateLandscapeWindow::DrawWidget(), MusicWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), AIConfigWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), PaymentRatesGraphWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), OrdersWindow::DrawWidget(), NetworkStartServerWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), CompanyLeagueWindow::DrawWidget(), AIDebugWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), NetworkClientListPopupWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), SavePresetWindow::DrawWidget(), CompanyWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), ScenarioEditorToolbarWindow::DrawWidget(), VehicleViewWindow::DrawWidget(), DrawYearColumn(), HighScoreWindow::OnPaint(), IConsoleWindow::OnPaint(), BuildAirportWindow::OnPaint(), GameSettingsWindow::OnPaint(), StationsWndShowStationRating(), TrainDetailsCapacityTab(), TrainDetailsCargoTab(), and TrainDetailsInfoTab().

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

References DRAW_STRING_BUFFER, DrawString(), and lastof.

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

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

References SmallVector< T, S >::Begin(), DrawLayoutLine(), SmallVector< T, S >::End(), Layouter::GetBounds(), RoundDivSU(), SA_BOTTOM, SA_TOP, SA_VERT_CENTER, and SA_VERT_MASK.

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

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

References DRAW_STRING_BUFFER, DrawStringMultiLine(), and lastof.

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

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

Referenced by NWidgetMatrix::Draw(), DrawRoadVehImage(), DrawTrainImage(), TextfileWindow::DrawWidget(), SmallMapWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), StoryBookWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), and IndustryCargoesWindow::DrawWidget().

void GameSizeChanged | ( |  | ) |

Size of the application screen changed.

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

Definition at line 591 of file main_gui.cpp.

References _cur_resolution, MarkWholeScreenDirty(), and RelocateAllWindows().

Referenced by VideoDriver_Win32::MakeWindow().

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

References GetCharacterWidth().

Referenced by SetDParamMaxDigits().

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 63 of file fontcache.cpp.

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

Referenced by BaseGraphWindow::DrawGraph(), NWidgetResizeBase::SetMinimalTextLines(), and StationsWndShowStationRating().

byte GetCharacterWidth | ( | FontSize | size,
|  | WChar | 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 1148 of file gfx.cpp.

References _stringwidth_table, and GetGlyphWidth().

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

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

  str | String to test.
  x | Position relative to the start of the string.
  start_fontsize | Font 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.

References Layouter::GetCharAtPosition().

Referenced by IConsoleWindow::GetTextCharacterAtPosition().

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

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

References Layouter::GetCharPosition().

Referenced by QueryString::GetBoundingRect(), IConsoleWindow::GetTextBoundingRect(), Textbuf::UpdateCaretPosition(), and Textbuf::UpdateMarkedText().

TextColour GetContrastColour | ( | uint8 | background | ) |

Determine a contrasty text colour for a coloured background.

Parameters

  background | Background 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.

Referenced by CompanyStationsWindow::DrawWidget(), and StationsWndShowStationRating().

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

References GetCharacterWidth(), and max().

Referenced by BaseVehicleListWindow::DrawVehicleListItems(), and BuildSignalWindow::UpdateWidgetSize().

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.

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

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

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), StoryBookWindow::DrawActionElement(), DrawEngineList(), DrawOrderString(), TownAuthorityWindow::DrawRatings(), DrawResizeBox(), NetworkGameWindow::DrawServerLine(), BuildSignalWindow::DrawSignalSprite(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehicleRefitWindow(), GraphLegendWindow::DrawWidget(), LinkGraphLegendWindow::DrawWidget(), StatusBarWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), TimetableWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), NewGRFWindow::DrawWidget(), OrdersWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), CompanyWindow::DrawWidget(), VehicleViewWindow::DrawWidget(), QueryString::GetBoundingRect(), QueryString::GetCaretPosition(), QueryString::GetCharAtPosition(), BuildTreesWindow::GetMaxTreeSpriteSize(), StoryBookWindow::GetPageElementHeight(), MakeCompanyButtonRows(), MakeNWidgetCompanyLines(), NetworkContentListWindow::NetworkContentListWindow(), SelectCompanyManagerFaceWindow::OnInit(), BuildSignalWindow::OnInit(), MainWindow::OnPaint(), NWidgetLeaf::SetupSmallestSize(), BuildBridgeWindow::UpdateWidgetSize(), ErrmsgWindow::UpdateWidgetSize(), SignListWindow::UpdateWidgetSize(), CheatWindow::UpdateWidgetSize(), BuildAirportWindow::UpdateWidgetSize(), NewsWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), NewGRFWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), SelectCompanyManagerFaceWindow::UpdateWidgetSize(), CompanyLeagueWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), ScenarioEditorToolbarWindow::UpdateWidgetSize(), BuyCompanyWindow::UpdateWidgetSize(), and VehicleViewWindow::UpdateWidgetSize().

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

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

Returns
  string width and height in pixels

Definition at line 699 of file gfx.cpp.

References Layouter::GetBounds().

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), DrawCaption(), DrawEngineList(), DrawLabel(), DrawText(), CheatWindow::DrawWidget(), TimetableWindow::DrawWidget(), OrdersWindow::DrawWidget(), BaseVehicleListWindow::GetActionDropdownSize(), ExpensesList::GetCategoriesWidth(), GetStringBoundingBox(), BaseGraphWindow::GetYLabelWidth(), SmallMapWindow::OnInit(), SelectCompanyManagerFaceWindow::OnInit(), IndustryCargoesWindow::OnInit(), RefitWindow::OnInvalidateData(), GoalListWindow::OnPaint(), TextfileWindow::SetupScrollbars(), NWidgetBackground::SetupSmallestSize(), NWidgetLeaf::SetupSmallestSize(), ViewportSign::UpdatePosition(), SelectGameWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), LinkGraphLegendWindow::UpdateWidgetSize(), SetDateWindow::UpdateWidgetSize(), StatusBarWindow::UpdateWidgetSize(), BuildObjectWindow::UpdateWidgetSize(), SubsidyListWindow::UpdateWidgetSize(), BuildBridgeWindow::UpdateWidgetSize(), GoalListWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), TownAuthorityWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), SignListWindow::UpdateWidgetSize(), CheatWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), BuildAirportWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), MusicTrackSelectionWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), NetworkChatWindow::UpdateWidgetSize(), AboutWindow::UpdateWidgetSize(), SaveLoadWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), MusicWindow::UpdateWidgetSize(), StoryBookWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), SelectCompanyLiveryWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), NewGRFWindow::UpdateWidgetSize(), AIConfigWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), PaymentRatesGraphWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), BuildRailStationWindow::UpdateWidgetSize(), NetworkStartServerWindow::UpdateWidgetSize(), SelectCompanyManagerFaceWindow::UpdateWidgetSize(), CompanyLeagueWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), IndustryDirectoryWindow::UpdateWidgetSize(), PerformanceRatingDetailWindow::UpdateWidgetSize(), StationViewWindow::UpdateWidgetSize(), BuildVehicleWindow::UpdateWidgetSize(), VehicleListWindow::UpdateWidgetSize(), CompanyInfrastructureWindow::UpdateWidgetSize(), NetworkClientListPopupWindow::UpdateWidgetSize(), GameSettingsWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), VehicleDetailsWindow::UpdateWidgetSize(), NetworkJoinStatusWindow::UpdateWidgetSize(), SavePresetWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), SelectStationWindow< T >::UpdateWidgetSize(), ScenarioEditorToolbarWindow::UpdateWidgetSize(), CustomCurrencyWindow::UpdateWidgetSize(), and Textbuf::UpdateWidth().

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

  strid | String 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, GetStringBoundingBox(), and lastof.

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

  str | string to check
  maxw | maximum string width

Returns
  height of pixels of string when it is drawn

Definition at line 547 of file gfx.cpp.

References Layouter::GetBounds().

Referenced by EnginePreviewWindow::DrawWidget(), TextfileWindow::GetContentHeight(), TownViewWindow::GetDesiredInfoHeight(), StoryBookWindow::GetHeadHeight(), SettingEntry::GetMaxHelpHeight(), StoryBookWindow::GetPageElementHeight(), GetStringHeight(), GetStringMultiLineBoundingBox(), SelectGameWindow::UpdateWidgetSize(), EnginePreviewWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), ErrmsgWindow::UpdateWidgetSize(), CheatWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), GoalQuestionWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), and BuyCompanyWindow::UpdateWidgetSize().

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

References DRAW_STRING_BUFFER, GetStringHeight(), and lastof.

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

References DRAW_STRING_BUFFER, lastof, and SmallVector< T, S >::Length().

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

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

References GetStringHeight().

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

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

References GetStringHeight().

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

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

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

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

Handle keyboard input.

Parameters

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

Definition at line 2580 of file window.cpp.

References HotkeyList::CheckMatch(), EditBoxInGlobalFocus(), ES_HANDLED, FindWindowById(), Window::HandleEditBoxKey(), HasModalProgress(), WindowDesc::hotkeys, NWidgetCore::index, IsLocalCompany(), Window::nested_focus, Window::OnHotkey(), Window::OnKeyPress(), WC_CONSOLE, WC_MAIN_TOOLBAR, Window::window_class, and Window::window_desc.

Referenced by HandleCharMsg().

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 2668 of file window.cpp.

References EditBoxInGlobalFocus(), NWidgetCore::index, Window::InsertTextString(), Window::nested_focus, WC_CONSOLE, and Window::window_class.

Referenced by CancelIMEComposition(), and HandleIMEComposition().

void LoadStringWidthTable | ( | bool | monospace | ) |

Initialize _stringwidth_table cache.

Parameters

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

Definition at line 1130 of file gfx.cpp.

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

Referenced by AfterLoadGame(), CheckForMissingGlyphs(), GenerateWorld(), GameOptionsWindow::OnDropdownSelect(), and ReloadNewGRFData().

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

Assign an animation to the cursor.

Parameters

  table | Array 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 SetObjectToPlace().

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

  left | The left edge of the rectangle
  top | The top edge of the rectangle
  right | The right edge of the rectangle
  bottom | The 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(), PositionWindow(), NWidgetBase::SetDirty(), Window::SetDirty(), and NewsWindow::SetWindowTop().

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

References CursorVars::animate_timeout, and SetCursorSprite().

Referenced by SetMouseCursorBusy(), and SetObjectToPlace().

void SetMouseCursorBusy | ( | bool | busy | ) |

Set or unset the ZZZ cursor.

Parameters

  busy | Whether 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 CleanupGeneration(), GenerateProgressWindow::OnClick(), SaveFileDone(), and SaveFileStart().

void UpdateCursorSize | ( |  | ) |

Update cursor dimension.

Called when changing cursor sprite resp. reloading grfs.

Definition at line 1530 of file gfx.cpp.

References CursorVars::dirty, GB(), GetMaxSpriteID(), Sprite::height, lengthof, max(), PalSpriteID::sprite, CursorVars::sprite_count, CursorVars::sprite_pos, CursorVars::sprite_seq, SPRITE_WIDTH, ST_NORMAL, CursorVars::total_size, UnScaleGUI(), Sprite::width, Sprite::x_offs, and Sprite::y_offs.

Referenced by GfxLoadSprites(), GameOptionsWindow::OnDropdownSelect(), SetCursorSprite(), and SetMouseCursorVehicle().

## Variable Documentation

bool _palette_remap_grf[]

Whether the given NewGRFs must get a palette remap from windows to DOS or not.

Definition at line 32 of file gfxinit.cpp.

Referenced by DecodeSingleSprite(), LoadNewGRFFile(), LoadSpriteTables(), and ReadRecolourSprite().

const int DRAW_STRING_BUFFER = 2048
| static

Size of the buffer used for drawing strings.

Definition at line 87 of file gfx_func.h.

Referenced by StringFilter::AddLine(), CopyOutDParam(), NetworkContentListWindow::DrawDetails(), DrawString(), DrawStringMultiLine(), GetLayouter(), GetStringBoundingBox(), GetStringHeight(), GetStringLineCount(), NetworkAddChatMessage(), NetworkHandlePauseChange(), ShowErrorMessage(), and ViewportSign::UpdatePosition().