Defines | 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/sprites.h"
#include "table/control_codes.h"

Go to the source code of this file.

Defines

#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.
void GfxDrawLine (int x, int y, int x2, int y2, int colour, int width)
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.
static void SetColourRemap (TextColour colour)
 Set the colour remap to be for the given colour.
static int DrawLayoutLine (const ParagraphLayouter::Line *line, int y, int left, int right, StringAlignment align, bool underline, bool truncation)
 Drawing routine for drawing a laid out line of text.
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.
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.
static int GetStringHeight (const char *str, int maxw)
 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.
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.
int DrawStringMultiLine (int left, int right, int top, int bottom, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
 Draw string, possibly over multiple lines.
Dimension GetStringBoundingBox (const char *str, FontSize start_fontsize)
 Return the string dimension in pixels.
Dimension GetStringBoundingBox (StringID strid)
 Get bounding box of a string.
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.
const char * GetCharAtPosition (const char *str, int x, FontSize start_fontsize)
 Get the character from a string that is drawn at a specific position.
void DrawCharCentered (WChar c, int x, int y, TextColour colour)
 Draw single character horizontally centered around (x,y).
Dimension GetSpriteSize (SpriteID sprid, Point *offset, ZoomLevel zoom)
 Get the size of a sprite.
void DrawSpriteViewport (SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
 Draw a sprite in a viewport.
void DrawSprite (SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
 Draw a sprite, not in a viewport.
void DoPaletteAnimations ()
void GfxInitPalettes ()
TextColour GetContrastColour (uint8 background)
 Determine a contrasty text colour for a coloured background.
void LoadStringWidthTable (bool monospace)
 Initialize _stringwidth_table cache.
byte GetCharacterWidth (FontSize size, WChar key)
 Return width of character glyph.
byte GetDigitWidth (FontSize size)
 Return the maximum width of single digit.
void GetBroadestDigit (uint *front, uint *next, FontSize size)
 Determine the broadest digits for guessing the maximum width of a n-digit number.
void ScreenSizeChanged ()
void UndrawMouseCursor ()
void DrawMouseCursor ()
void RedrawScreenRect (int left, int top, int right, int bottom)
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.
bool FillDrawPixelInfo (DrawPixelInfo *n, int left, int top, int width, int height)
 Set up a clipping area for only drawing into a certain area.
void UpdateCursorSize ()
 Update cursor dimension.
static void SetCursorSprite (CursorID cursor, PaletteID pal)
 Switch cursor to different sprite.
static void SwitchAnimatedCursor ()
void CursorTick ()
void SetMouseCursor (CursorID sprite, PaletteID pal)
 Assign a single non-animated sprite to the cursor.
void SetAnimatedMouseCursor (const AnimCursor *table)
 Assign an animation to the cursor.
bool ChangeResInGame (int width, int height)
bool ToggleFullScreen (bool fs)
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
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.
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
static Rect _invalid_rect
 The rect for repaint.
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

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

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

Referenced by OskWindow::DrawWidget().

void DrawDirtyBlocks (  ) 
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:
line String to draw.
y The top most position to draw on.
left The left most position to draw on.
right The right most position to draw on.
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.
truncation Whether 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 273 of file gfx.cpp.

References _current_text_dir, _string_colourremap, BM_COLOUR_REMAP, FontCache::GetDrawGlyphShadow(), FontCache::GetGlyph(), FontCache::GetGlyphWidth(), GfxFillRect(), FontCache::MapCharToGlyph(), RoundDivSU(), SA_FORCE, SA_HOR_CENTER, SA_HOR_MASK, SA_LEFT, SA_RIGHT, SetColourRemap(), TD_RTL, Sprite::width, and Sprite::x_offs.

Referenced by DrawString(), and DrawStringMultiLine().

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

References BM_COLOUR_REMAP, BM_NORMAL, BM_TRANSPARENT, GB(), HasBit(), PALETTE_MODIFIER_TRANSPARENT, PALETTE_WIDTH, SPRITE_WIDTH, ST_NORMAL, and ST_RECOLOUR.

Referenced by SettingEntry::Draw(), DrawAircraftImage(), DrawArrowButtons(), DrawCargoIcons(), DrawCommonTileSeqInGUI(), DrawCompanyIcon(), DrawCompanyManagerFace(), DrawDebugBox(), DrawEngineList(), VehicleGroupWindow::DrawGroupInfo(), DrawHorizontalScrollbar(), DrawImageButtons(), NetworkContentListWindow::DrawMatrix(), DrawNewObjectTileInGUI(), DrawOrderString(), TownAuthorityWindow::DrawRatings(), DrawResizeBox(), DrawRoadDepotSprite(), DrawRoadVehEngine(), DrawRoadVehImage(), NetworkGameWindow::DrawServerLine(), DrawShadeBox(), DrawShipImage(), BuildSignalWindow::DrawSignalSprite(), DrawStationTile(), DrawStickyBox(), DrawTrainDetails(), DrawTrainImage(), DepotWindow::DrawVehicleInDepot(), DrawVehicleProfitButton(), VehicleViewWindow::DrawWidget(), BuildTreesWindow::DrawWidget(), TransparenciesWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), ScenarioEditorLandscapeGenerationWindow::DrawWidget(), StatusBarWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), CompanyWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), CheatWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), BuildAirportWindow::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 714 of file gfx.cpp.

References BM_COLOUR_REMAP, BM_NORMAL, BM_TRANSPARENT, GB(), HasBit(), PALETTE_MODIFIER_TRANSPARENT, PALETTE_WIDTH, 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 422 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 SettingEntry::Draw(), CargoesField::Draw(), DrawAircraftDetails(), DrawButtonDropdown(), DrawCaption(), StationViewWindow::DrawCargoRatings(), DrawCategories(), DrawCloseBox(), NetworkContentListWindow::DrawDetails(), DrawDropDownButton(), DrawEngineList(), 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(), DrawShipDetails(), Window::DrawSortButtonState(), DrawString(), DrawText(), SmallMapWindow::DrawTowns(), DrawTrainDetails(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehiclePurchaseInfo(), DrawVehicleRefitWindow(), DrawVerticalScrollbar(), StationViewWindow::DrawWaitingCargo(), VehicleViewWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), TownViewWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), ScenarioEditorToolbarWindow::DrawWidget(), TimetableWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), StatusBarWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), CompanyStationsWindow::DrawWidget(), SmallMapWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), OrdersWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), NetworkClientListPopupWindow::DrawWidget(), NetworkStartServerWindow::DrawWidget(), NetworkChatWindow::DrawWidget(), MusicWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), AboutWindow::DrawWidget(), LandInfoWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), CompanyLeagueWindow::DrawWidget(), PaymentRatesGraphWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), GenerateLandscapeWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), CompanyWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), CheatWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), AIDebugWindow::DrawWidget(), AIConfigWindow::DrawWidget(), AISettingsWindow::DrawWidget(), AIListWindow::DrawWidget(), DrawYearColumn(), HighScoreWindow::OnPaint(), IConsoleWindow::OnPaint(), BuildAirportWindow::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 457 of file gfx.cpp.

References DRAW_STRING_BUFFER, DrawString(), and lastof.

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

References DRAW_STRING_BUFFER, DrawStringMultiLine(), 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 543 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(), RefitWindow::DrawWidget(), TownViewWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), NewsWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), QueryWindow::DrawWidget(), TooltipsWindow::DrawWidget(), LandInfoWindow::DrawWidget(), SelectGameWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), GoalQuestionWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), BuyCompanyWindow::DrawWidget(), CompanyWindow::DrawWidget(), CheatWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), AIListWindow::DrawWidget(), NetworkDrawChatMessage(), HighScoreWindow::OnPaint(), EndGameWindow::OnPaint(), IConsoleWindow::OnPaint(), ShowAdditionalText(), and ShowRefitOptionsList().

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

References BlitterFactoryBase::GetCurrentBlitter(), and Blitter::MoveTo().

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

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

References GetCharacterWidth().

Referenced by SetDParamMaxDigits().

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 1112 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 663 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 650 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 1081 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 1125 of file gfx.cpp.

References GetCharacterWidth(), and max().

Referenced by BaseVehicleListWindow::DrawVehicleListItems(), BuildSignalWindow::UpdateWidgetSize(), and DepotWindow::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 691 of file gfx.cpp.

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

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), DrawEngineList(), DrawOrderString(), TownAuthorityWindow::DrawRatings(), DrawResizeBox(), BuildSignalWindow::DrawSignalSprite(), BaseVehicleListWindow::DrawVehicleListItems(), VehicleViewWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), TimetableWindow::DrawWidget(), StatusBarWindow::DrawWidget(), OrdersWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), CompanyWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), QueryString::GetBoundingRect(), QueryString::GetCaretPosition(), QueryString::GetCharAtPosition(), BuildTreesWindow::GetMaxTreeSpriteSize(), MakeCompanyButtonRows(), MakeNWidgetCompanyLines(), NWidgetLeaf::NWidgetLeaf(), BuildSignalWindow::OnInit(), SelectCompanyManagerFaceWindow::OnInit(), MainWindow::OnPaint(), NWidgetLeaf::SetupSmallestSize(), VehicleViewWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), ScenarioEditorToolbarWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), CompanyLeagueWindow::UpdateWidgetSize(), BuyCompanyWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), BuildBridgeWindow::UpdateWidgetSize(), and BuildAirportWindow::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 622 of file gfx.cpp.

References Layouter::GetBounds().

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), DrawCaption(), DrawEngineList(), DrawLabel(), DrawText(), TimetableWindow::DrawWidget(), OrdersWindow::DrawWidget(), CheatWindow::DrawWidget(), BaseVehicleListWindow::GetActionDropdownSize(), ExpensesList::GetCategoriesWidth(), GetStringBoundingBox(), BaseGraphWindow::GetYLabelWidth(), TextfileWindow::LoadTextfile(), SmallMapWindow::OnInit(), IndustryCargoesWindow::OnInit(), SelectCompanyManagerFaceWindow::OnInit(), RefitWindow::OnInvalidateData(), NWidgetLeaf::SetupSmallestSize(), NWidgetBackground::SetupSmallestSize(), ViewportSign::UpdatePosition(), VehicleDetailsWindow::UpdateWidgetSize(), VehicleListWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), TownAuthorityWindow::UpdateWidgetSize(), ScenarioEditorToolbarWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), SubsidyListWindow::UpdateWidgetSize(), StatusBarWindow::UpdateWidgetSize(), SelectStationWindow< T >::UpdateWidgetSize(), StationViewWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), CustomCurrencyWindow::UpdateWidgetSize(), GameSettingsWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), BuildRailStationWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), BuildObjectWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), NetworkJoinStatusWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), NetworkClientListPopupWindow::UpdateWidgetSize(), NetworkStartServerWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), NetworkChatWindow::UpdateWidgetSize(), MusicWindow::UpdateWidgetSize(), MusicTrackSelectionWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), AboutWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), SelectGameWindow::UpdateWidgetSize(), IndustryDirectoryWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), PerformanceRatingDetailWindow::UpdateWidgetSize(), CompanyLeagueWindow::UpdateWidgetSize(), PaymentRatesGraphWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), GoalListWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), SaveLoadWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), CompanyInfrastructureWindow::UpdateWidgetSize(), SelectCompanyManagerFaceWindow::UpdateWidgetSize(), SelectCompanyLiveryWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), CheatWindow::UpdateWidgetSize(), BuildVehicleWindow::UpdateWidgetSize(), BuildBridgeWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), BuildAirportWindow::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 634 of file gfx.cpp.

References DRAW_STRING_BUFFER, GetStringBoundingBox(), and lastof.

static int GetStringHeight ( const char *  str,
int  maxw 
) [static]
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 482 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 495 of file gfx.cpp.

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

Referenced by NetworkDrawChatMessage().

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

References GetStringHeight().

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

References GetStringHeight().

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

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

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

Referenced by NWidgetLeaf::Draw(), NWidgetViewport::Draw(), NWidgetBackground::Draw(), NWidgetMatrix::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(), DrawVerticalScrollbar(), SmallMapWindow::DrawVertMapIndicator(), DropdownWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), SmallMapWindow::DrawWidget(), BuildRailWaypointWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), OrdersWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), NewsWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), NetworkClientListPopupWindow::DrawWidget(), MusicWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), TooltipsWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), PaymentRatesGraphWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), BootstrapBackground::DrawWidget(), BuildAirportWindow::DrawWidget(), AIDebugWindow::DrawWidget(), Window::DrawWidgets(), DrawYearColumn(), HighlightDragPosition(), NetworkDrawChatMessage(), IConsoleWindow::OnPaint(), and StationsWndShowStationRating().

void LoadStringWidthTable ( bool  monospace  ) 

Initialize _stringwidth_table cache.

Parameters:
monospace Whether to load the monospace cache or the normal fonts.

Definition at line 1095 of file gfx.cpp.

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

Referenced by AfterLoadGame(), CheckForMissingGlyphs(), GenerateWorld(), 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 1558 of file gfx.cpp.

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

static void SetColourRemap ( TextColour  colour  )  [static]

Set the colour remap to be for the given colour.

Parameters:
colour the new colour of the remap.

Definition at line 243 of file gfx.cpp.

References _string_colourmap, _string_colourremap, and TC_NO_SHADE.

Referenced by DrawCharCentered(), and DrawLayoutLine().

static void SetCursorSprite ( CursorID  cursor,
PaletteID  pal 
) [static]

Switch cursor to different sprite.

Parameters:
cursor Sprite to draw for the cursor.
pal Palette to use for recolouring.

Definition at line 1508 of file gfx.cpp.

References CursorVars::short_vehicle_offset, CursorVars::sprite, and UpdateCursorSize().

Referenced by SetMouseCursor().

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

Referenced by MarkViewportDirty(), MarkWholeScreenDirty(), PositionWindow(), Window::SetDirty(), NWidgetBase::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 1545 of file gfx.cpp.

References CursorVars::animate_timeout, and SetCursorSprite().

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

void UpdateCursorSize (  ) 

Update cursor dimension.

Called when changing cursor sprite resp. reloading grfs.

Definition at line 1490 of file gfx.cpp.

References CursorVars::dirty, GB(), Sprite::height, CursorVars::sprite, SPRITE_WIDTH, ST_NORMAL, UnScaleByZoom(), Sprite::width, Sprite::x_offs, Sprite::y_offs, and ZOOM_LVL_GUI.

Referenced by GfxLoadSprites(), and SetCursorSprite().


Variable Documentation

byte _stringwidth_table[FS_END][224] [static]

Cache containing width of often used characters.

See also:
GetCharacterWidth()

Definition at line 47 of file gfx.cpp.

Referenced by GetCharacterWidth(), and LoadStringWidthTable().