Handling of drawing text and other gfx related stuff. More...
#include "stdafx.h"
#include "gfx_func.h"
#include "fontcache.h"
#include "genworld.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 "thread/thread.h"
#include "window_func.h"
#include "newgrf_debug.h"
#include "table/palettes.h"
#include "table/sprites.h"
#include "table/control_codes.h"
#include <unicode/ubidi.h>
#include <unicode/ushape.h>
Go to the source code of this file.
Data Structures | |
struct | DrawStringParams |
Text drawing parameters, which can change while drawing a line, but are kept between multiple parts of the same text, e.g. More... | |
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 | GfxMainBlitter (const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub=NULL, SpriteID sprite_id=SPR_CURSOR_MOUSE) |
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 UChar * | HandleBiDiAndArabicShapes (UChar *buffer) |
Function to be able to handle right-to-left text and Arabic chars properly. | |
static int | TruncateString (char *str, int maxw, bool ignore_setxy, FontSize start_fontsize) |
Truncate a given string to a maximum width if neccessary. | |
static int | ReallyDoDrawString (const UChar *string, int x, int y, DrawStringParams ¶ms, bool parse_string_also_when_clipped) |
Draw a string at the given coordinates with the given colour. | |
static int | GetStringWidth (const UChar *str, FontSize start_fontsize) |
Get the real width of the string. | |
static int | DrawString (int left, int right, int top, char *str, const char *last, DrawStringParams ¶ms, StringAlignment align, bool underline=false, bool truncate=true) |
Draw string, possibly truncated to make it fit in its allocated space. | |
int | DrawString (int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline) |
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) |
Draw string, possibly truncated to make it fit in its allocated space. | |
uint32 | FormatStringLinebreaks (char *str, const char *last, int maxw, FontSize size) |
'Correct' a string to a maximum length. | |
static int | GetMultilineStringHeight (const char *src, int num, FontSize start_fontsize) |
Calculates height of string (in pixels). | |
int | GetStringHeight (StringID str, int maxw) |
Calculates height of string (in pixels). | |
Dimension | GetStringMultiLineBoundingBox (StringID str, const Dimension &suggestion) |
Calculate string bounding box for multi-line strings. | |
static int | DrawStringMultiLine (int left, int right, int top, int bottom, char *str, const char *last, TextColour colour, StringAlignment align, bool underline) |
Draw string, possibly over multiple lines. | |
int | DrawStringMultiLine (int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline) |
Draw string, possibly over multiple lines. | |
int | DrawStringMultiLine (int left, int right, int top, int bottom, StringID str, TextColour colour, StringAlignment align, bool underline) |
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. | |
void | DrawCharCentered (WChar c, int x, int y, TextColour colour) |
Draw single character horizontally centered around (x,y). | |
Dimension | GetSpriteSize (SpriteID sprid) |
Get the size of a sprite. | |
void | DrawSprite (SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub) |
Draw a sprite. | |
void | DoPaletteAnimations () |
void | GfxInitPalettes () |
void | LoadStringWidthTable () |
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 | 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. | |
int | _pal_first_dirty |
int | _pal_count_dirty |
Colour | _cur_palette [256] |
Current palette. Entry 0 has to be always fully transparent! | |
static int | _max_char_height |
Cache of the height of the largest font. | |
static int | _max_char_width |
Cache of the width of the largest font. | |
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 |
Handling of drawing text and other gfx related stuff.
Definition in file gfx.cpp.
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.
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 250 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).
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 1034 of file gfx.cpp.
References BM_COLOUR_REMAP, FS_NORMAL, GetCharacterWidth(), and SetColourRemap().
Referenced by OskWindow::DrawWidget().
void DrawDirtyBlocks | ( | ) |
Repaints the rectangle blocks which are marked as 'dirty'.
Definition at line 1543 of file gfx.cpp.
References _genworld_mapgen_mutex, _genworld_paint_mutex, _realtime_tick, Align(), ThreadMutex::BeginCritical(), ThreadMutex::EndCritical(), GENWORLD_REDRAW_TIMEOUT, and IsGeneratingWorld().
Referenced by MakeScreenshot(), and UpdateWindows().
Draw a sprite.
img | Image number to draw | |
pal | Palette to use. | |
x | Left coordinate of image | |
y | Top coordinate of image | |
sub | If available, draw only specified part of the sprite |
Definition at line 1140 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(), 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(), ScenarioEditorLandscapeGenerationWindow::DrawWidget(), StatusBarWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), CompanyWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), CheatWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), and MainWindow::OnPaint().
int DrawString | ( | int | left, | |
int | right, | |||
int | top, | |||
StringID | str, | |||
TextColour | colour, | |||
StringAlignment | align, | |||
bool | underline | |||
) |
Draw string, possibly truncated to make it fit in its allocated space.
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. |
Definition at line 649 of file gfx.cpp.
References DRAW_STRING_BUFFER, DrawString(), and lastof.
int DrawString | ( | int | left, | |
int | right, | |||
int | top, | |||
const char * | str, | |||
TextColour | colour, | |||
StringAlignment | align, | |||
bool | underline | |||
) |
Draw string, possibly truncated to make it fit in its allocated space.
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. |
Definition at line 628 of file gfx.cpp.
References DRAW_STRING_BUFFER, DrawString(), lastof, and strecpy().
static int DrawString | ( | int | left, | |
int | right, | |||
int | top, | |||
char * | str, | |||
const char * | last, | |||
DrawStringParams & | params, | |||
StringAlignment | align, | |||
bool | underline = false , |
|||
bool | truncate = true | |||
) | [static] |
Draw string, possibly truncated to make it fit in its allocated space.
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. | |
last | The end of the string buffer to draw. | |
params | Text drawing parameters. | |
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. | |
truncate | Whether to truncate the string or not. |
Definition at line 482 of file gfx.cpp.
References _current_text_dir, _string_colourremap, SmallVector< T, S >::Append(), SmallVector< T, S >::Begin(), SmallVector< T, S >::Clear(), DEBUG, DRAW_STRING_BUFFER, SmallVector< T, S >::End(), FONT_HEIGHT_NORMAL, GetStringBoundingBox(), GetStringWidth(), GfxFillRect(), HandleBiDiAndArabicShapes(), lastof, max(), min(), ReallyDoDrawString(), RoundDivSU(), SA_FORCE, SA_HOR_CENTER, SA_HOR_MASK, SA_LEFT, SA_RIGHT, SA_STRIP, TD_RTL, TruncateString(), and Utf8Decode().
Referenced by SettingEntry::Draw(), CargoesField::Draw(), DrawAircraftDetails(), DrawButtonDropdown(), DrawCaption(), StationViewWindow::DrawCargoRatings(), DrawCategories(), DrawCloseBox(), NetworkContentListWindow::DrawDetails(), DrawEngineList(), SelectCompanyManagerFaceWindow::DrawFaceStringLabel(), DrawFrame(), BaseGraphWindow::DrawGraph(), IndustryViewWindow::DrawInfo(), DrawInset(), DrawLabel(), CargoDestinationList::DrawList(), NetworkContentListWindow::DrawMatrix(), DrawNewsString(), DrawOrderString(), DrawPrice(), TownAuthorityWindow::DrawRatings(), DrawRoadVehDetails(), NetworkGameWindow::DrawServerLine(), SettingEntry::DrawSetting(), DrawShipDetails(), StationViewWindow::DrawSingleDestEntry(), Window::DrawSortButtonState(), DrawString(), DrawStringMultiLine(), DrawText(), SmallMapWindow::DrawTowns(), DrawTrainDetails(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehiclePurchaseInfo(), DrawVehicleRefitWindow(), DrawVerticalScrollbar(), StationViewWindow::DrawWaitingCargo(), StationViewWindow::DrawWaitingCargoByDest(), 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(), SignListWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), OrdersWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), MessageOptionsWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), NewGRFWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), NetworkClientListPopupWindow::DrawWidget(), NetworkStartServerWindow::DrawWidget(), NetworkContentListWindow::DrawWidget(), NetworkContentDownloadStatusWindow::DrawWidget(), NetworkChatWindow::DrawWidget(), MusicWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), AboutWindow::DrawWidget(), LandInfoWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), CompanyLeagueWindow::DrawWidget(), PaymentRatesGraphWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), GenerateLandscapeWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), CompanyWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), CheatWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), AIDebugWindow::DrawWidget(), AIConfigWindow::DrawWidget(), AISettingsWindow::DrawWidget(), AIListWindow::DrawWidget(), DrawYearColumn(), NetworkDrawChatMessage(), HighScoreWindow::OnPaint(), IConsoleWindow::OnPaint(), BuildAirportWindow::OnPaint(), StationsWndShowStationRating(), TrainDetailsCapacityTab(), TrainDetailsCargoTab(), and TrainDetailsInfoTab().
int DrawStringMultiLine | ( | int | left, | |
int | right, | |||
int | top, | |||
int | bottom, | |||
StringID | str, | |||
TextColour | colour, | |||
StringAlignment | align, | |||
bool | underline | |||
) |
Draw string, possibly over multiple lines.
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 |
Definition at line 960 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 | |||
) |
Draw string, possibly over multiple lines.
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 |
Definition at line 939 of file gfx.cpp.
References DRAW_STRING_BUFFER, DrawStringMultiLine(), lastof, and strecpy().
static int DrawStringMultiLine | ( | int | left, | |
int | right, | |||
int | top, | |||
int | bottom, | |||
char * | str, | |||
const char * | last, | |||
TextColour | colour, | |||
StringAlignment | align, | |||
bool | underline | |||
) | [static] |
Draw string, possibly over multiple lines.
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. | |
last | The end of the string buffer 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 |
Definition at line 840 of file gfx.cpp.
References DRAW_STRING_BUFFER, DrawString(), FormatStringLinebreaks(), FS_LARGE, FS_SMALL, GB(), GetCharacterHeight(), lastof, RoundDivSU(), SA_BOTTOM, SA_TOP, SA_VERT_CENTER, SA_VERT_MASK, SCC_BIGFONT, SCC_TINYFONT, DrawStringParams::SetColour(), DrawStringParams::SetFontSize(), DrawStringParams::SetPreviousColour(), and strecpy().
Referenced by DrawCargoListText(), NetworkContentListWindow::DrawDetails(), BaseGraphWindow::DrawGraph(), IndustryViewWindow::DrawInfo(), DrawStringMultiLine(), RefitWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), NewsWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), NetworkContentDownloadStatusWindow::DrawWidget(), QueryWindow::DrawWidget(), TooltipsWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), LandInfoWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), BuyCompanyWindow::DrawWidget(), CompanyWindow::DrawWidget(), CheatWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), AIListWindow::DrawWidget(), 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
*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 |
Definition at line 1709 of file gfx.cpp.
References BlitterFactoryBase::GetCurrentBlitter(), Blitter::MoveTo(), and ZOOM_LVL_NORMAL.
Referenced by NWidgetMatrix::Draw(), DrawRoadVehImage(), DrawTrainImage(), SmallMapWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), and IndustryCargoesWindow::DrawWidget().
uint32 FormatStringLinebreaks | ( | char * | str, | |
const char * | last, | |||
int | maxw, | |||
FontSize | size | |||
) |
'Correct' a string to a maximum length.
Longer strings will be cut into additional lines at whitespace characters if possible. The string parameter is modified with terminating characters mid-string which are the placeholders for the newlines. The string WILL be truncated if there was no whitespace for the current line's maximum width.
str | string to check and correct for length restrictions | |
last | the last valid location (for '') in the buffer of str | |
maxw | the maximum width the string can have on one line | |
size | Fontsize to start the text with |
Definition at line 677 of file gfx.cpp.
References FS_LARGE, FS_SMALL, GetCharacterWidth(), IsTextDirectionChar(), IsWhitespace(), SCC_BIGFONT, SCC_TINYFONT, and Utf8PrevChar().
Referenced by DrawStringMultiLine(), GetStringHeight(), and NetworkAddChatMessage().
Return width of character glyph.
size | Font of the character | |
key | Character code glyph |
Definition at line 1406 of file gfx.cpp.
References _stringwidth_table.
Referenced by DrawCharCentered(), FormatStringLinebreaks(), GetDigitWidth(), GetStringBoundingBox(), GetStringWidth(), InsertTextBufferChar(), InsertTextBufferClipboard(), MoveTextBufferPos(), ReallyDoDrawString(), TruncateString(), and UpdateTextBufferSize().
byte GetDigitWidth | ( | FontSize | size | ) |
Return the maximum width of single digit.
size | Font of the digit |
Definition at line 1419 of file gfx.cpp.
References GetCharacterWidth(), and max().
Referenced by BaseVehicleListWindow::DrawVehicleListItems(), and DepotWindow::UpdateWidgetSize().
static int GetMultilineStringHeight | ( | const char * | src, | |
int | num, | |||
FontSize | start_fontsize | |||
) | [static] |
Calculates height of string (in pixels).
Accepts multiline string with '' as separators.
src | string to check | |
num | number of extra lines (output of FormatStringLinebreaks()) | |
start_fontsize | Fontsize to start the text with |
Definition at line 774 of file gfx.cpp.
References FS_LARGE, FS_SMALL, GetCharacterHeight(), SCC_BIGFONT, and SCC_TINYFONT.
Referenced by GetStringHeight().
Get the size of a sprite.
sprid | Sprite to examine. |
Definition at line 1122 of file gfx.cpp.
References Sprite::height, ST_NORMAL, Sprite::width, Sprite::x_offs, and Sprite::y_offs.
Referenced by DrawOrderString(), TownAuthorityWindow::DrawRatings(), BaseVehicleListWindow::DrawVehicleListItems(), TimetableWindow::DrawWidget(), StatusBarWindow::DrawWidget(), OrdersWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), MakeCompanyButtonRows(), SelectCompanyManagerFaceWindow::OnInit(), MainWindow::OnPaint(), NWidgetLeaf::SetupSmallestSize(), ScenarioEditorToolbarWindow::UpdateWidgetSize(), SignListWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), BuyCompanyWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), BuildBridgeWindow::UpdateWidgetSize(), and BuildAirportWindow::UpdateWidgetSize().
Get bounding box of a string.
Uses parameters set by DParam if needed. Has the same restrictions as GetStringBoundingBox(const char *str).
strid | String to examine. |
Definition at line 1019 of file gfx.cpp.
References DRAW_STRING_BUFFER, GetStringBoundingBox(), and lastof.
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
str | string to calculate pixel-width | |
start_fontsize | Fontsize to start the text with |
Definition at line 977 of file gfx.cpp.
References FS_LARGE, FS_SMALL, GetCharacterHeight(), GetCharacterWidth(), IsTextDirectionChar(), max(), SCC_BIGFONT, and SCC_TINYFONT.
Referenced by DrawLabel(), DrawString(), DrawText(), TimetableWindow::DrawWidget(), OrdersWindow::DrawWidget(), CheatWindow::DrawWidget(), BaseVehicleListWindow::GetActionDropdownSize(), ExpensesList::GetCategoriesWidth(), GetStringBoundingBox(), BaseGraphWindow::GetYLabelWidth(), SmallMapWindow::OnInit(), MessageOptionsWindow::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(), SignListWindow::UpdateWidgetSize(), CustomCurrencyWindow::UpdateWidgetSize(), GameDifficultyWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), BuildRailStationWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), BuildObjectWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), NewGRFWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), NetworkJoinStatusWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), NetworkClientListPopupWindow::UpdateWidgetSize(), NetworkStartServerWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), NetworkContentListWindow::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(), GenerateProgressWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), SaveLoadWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), SetDateWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), SelectCompanyManagerFaceWindow::UpdateWidgetSize(), SelectCompanyLiveryWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), CheatWindow::UpdateWidgetSize(), BuildVehicleWindow::UpdateWidgetSize(), BuildBridgeWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), and BuildAirportWindow::UpdateWidgetSize().
int GetStringHeight | ( | StringID | str, | |
int | maxw | |||
) |
Calculates height of string (in pixels).
The string is changed to a multiline string if needed.
str | string to check | |
maxw | maximum string width |
Definition at line 802 of file gfx.cpp.
References DRAW_STRING_BUFFER, FormatStringLinebreaks(), FS_NORMAL, GB(), GetMultilineStringHeight(), and lastof.
Referenced by EnginePreviewWindow::DrawWidget(), GetStringMultiLineBoundingBox(), GameOptionsWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), ErrmsgWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), EnginePreviewWindow::UpdateWidgetSize(), BuyCompanyWindow::UpdateWidgetSize(), and CheatWindow::UpdateWidgetSize().
Calculate string bounding box for multi-line strings.
str | String to check. | |
suggestion | Suggested bounding box. |
Definition at line 819 of file gfx.cpp.
References GetStringHeight().
Referenced by TownAuthorityWindow::UpdateWidgetSize(), NewsWindow::UpdateWidgetSize(), QueryWindow::UpdateWidgetSize(), and BuildAirportWindow::UpdateWidgetSize().
static int GetStringWidth | ( | const UChar * | str, | |
FontSize | start_fontsize | |||
) | [static] |
Get the real width of the string.
str | the string to draw | |
start_fontsize | Fontsize to start the text with |
Definition at line 432 of file gfx.cpp.
References FS_LARGE, FS_SMALL, GetCharacterWidth(), IsTextDirectionChar(), max(), SCC_BIGFONT, and SCC_TINYFONT.
Referenced by DrawString().
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.
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 148 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(), NWidgetScrollbar::Draw(), NWidgetViewport::Draw(), NWidgetBackground::Draw(), NWidgetMatrix::Draw(), NWidgetToolbarContainer::Draw(), CargoesField::Draw(), DrawArrowButtons(), DrawCaption(), NetworkContentListWindow::DrawDetails(), DrawFrame(), DrawFrameRect(), BaseGraphWindow::DrawGraph(), CargoesField::DrawHorConnection(), SmallMapWindow::DrawHorizMapIndicator(), DrawHorizontalScrollbar(), DrawMatrix(), NetworkContentListWindow::DrawMatrix(), SmallMapWindow::DrawRouteLinks(), NetworkGameWindow::DrawServerLine(), SmallMapWindow::DrawSmallMap(), DrawString(), DrawTrainDetails(), DrawVerticalScrollbar(), SmallMapWindow::DrawVertMapIndicator(), DropdownWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), SmallMapWindow::DrawWidget(), BuildRailWaypointWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), OrdersWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), NewsWindow::DrawWidget(), NewGRFWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), NetworkClientListPopupWindow::DrawWidget(), MusicWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), TooltipsWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), PaymentRatesGraphWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), AIDebugWindow::DrawWidget(), DrawYearColumn(), HighlightDragPosition(), NetworkDrawChatMessage(), IConsoleWindow::OnPaint(), and StationsWndShowStationRating().
static UChar* HandleBiDiAndArabicShapes | ( | UChar * | buffer | ) | [static] |
Function to be able to handle right-to-left text and Arabic chars properly.
First: right-to-left (RTL) is stored 'logically' in almost all applications and so do we. This means that their text is stored from right to the left in memory and any non-RTL text (like numbers or English) are then stored from left-to-right. When we want to actually draw the text we need to reverse the RTL text in memory, which is what happens in ubidi_writeReordered. Second: Arabic characters "differ" based on their context. To draw the correct variant we pass it through u_shapeArabic. This function can add or remove some characters. This is the reason for the lastof so we know till where we can fill the output.
Sadly enough these functions work with a custom character format, UChar, which isn't the same size as WChar. Because of that we need to transform our text first to UChars and then back to something we can use.
To be able to truncate strings properly you must truncate before passing to this function. This way the logical begin of the string remains and the end gets chopped of instead of the other way around.
The reshaping of Arabic characters might increase or decrease the width of the characters/string. So it might still overflow after truncation, though the chance is fairly slim as most characters get shorter instead of longer.
buffer | the buffer to read from/to | |
lastof | the end of the buffer |
Definition at line 336 of file gfx.cpp.
References _current_text_dir, DRAW_STRING_BUFFER, lengthof, and TD_RTL.
Referenced by DrawString().
static int ReallyDoDrawString | ( | const UChar * | string, | |
int | x, | |||
int | y, | |||
DrawStringParams & | params, | |||
bool | parse_string_also_when_clipped | |||
) | [static] |
Draw a string at the given coordinates with the given colour.
While drawing the string, parse it in case some formatting is specified, like new colour, new size or even positionning.
string | The string to draw. This is already bidi reordered. | |
x | Offset from left side of the screen | |
y | Offset from top side of the screen | |
params | Text drawing parameters | |
parse_string_also_when_clipped | By default, always test the available space where to draw the string. When in multipline drawing, it would already be done, so no need to re-perform the same kind (more or less) of verifications. It's not only an optimisation, it's also a way to ensures the string will be parsed (as there are certain side effects on global variables, which are important for the next line) |
Definition at line 1057 of file gfx.cpp.
References _max_char_width, BM_COLOUR_REMAP, DEBUG, FS_LARGE, FS_SMALL, GetCharacterHeight(), GetCharacterWidth(), IsTextDirectionChar(), SCC_BIGFONT, SCC_TINYFONT, DrawStringParams::SetColour(), SetColourRemap(), DrawStringParams::SetFontSize(), and DrawStringParams::SetPreviousColour().
Referenced by DrawString().
void SetAnimatedMouseCursor | ( | const AnimCursor * | table | ) |
Assign an animation to the cursor.
table | Array of animation states. |
Definition at line 1827 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.
colour | the new colour of the remap. |
Definition at line 285 of file gfx.cpp.
References _string_colourmap, _string_colourremap, TC_IS_PALETTE_COLOUR, and TC_NO_SHADE.
Referenced by DrawCharCentered(), and ReallyDoDrawString().
Switch cursor to different sprite.
cursor | Sprite to draw for the cursor. | |
pal | Palette to use for recolouring. |
Definition at line 1777 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.
left | The left edge of the rectangle | |
top | The top edge of the rectangle | |
right | The right edge of the rectangle | |
bottom | The bottm edge of the rectangle |
AddDirtyBlock
as it neither set a dirty rect nor add several dirty rects although the function name is in plural. (Progman) Definition at line 1647 of file gfx.cpp.
Referenced by MarkViewportDirty(), MarkWholeScreenDirty(), PositionWindow(), Window::SetDirty(), NWidgetBase::SetDirty(), and NewsWindow::SetWindowTop().
Assign a single non-animated sprite to the cursor.
sprite | Sprite to draw for the cursor. | |
pal | Palette to use for recolouring. |
Definition at line 1814 of file gfx.cpp.
References CursorVars::animate_timeout, and SetCursorSprite().
Referenced by CleanupGeneration(), GenerateProgressWindow::OnClick(), SaveFileDone(), and SaveFileStart().
static int TruncateString | ( | char * | str, | |
int | maxw, | |||
bool | ignore_setxy, | |||
FontSize | start_fontsize | |||
) | [static] |
Truncate a given string to a maximum width if neccessary.
If the string is truncated, add three dots ('...') to show this.
*str | string that is checked and possibly truncated | |
maxw | maximum width in pixels of the string | |
ignore_setxy | whether to ignore SETX(Y) or not | |
start_fontsize | Fontsize to start the text with |
Definition at line 374 of file gfx.cpp.
References DEBUG, FS_LARGE, FS_SMALL, GetCharacterWidth(), IsTextDirectionChar(), SCC_BIGFONT, and SCC_TINYFONT.
Referenced by DrawString().
void UpdateCursorSize | ( | ) |
Update cursor dimension.
Called when changing cursor sprite resp. reloading grfs.
Definition at line 1759 of file gfx.cpp.
References CursorVars::dirty, GB(), Sprite::height, CursorVars::sprite, SPRITE_WIDTH, ST_NORMAL, Sprite::width, Sprite::x_offs, and Sprite::y_offs.
Referenced by GfxLoadSprites(), and SetCursorSprite().
byte _stringwidth_table[FS_END][224] [static] |
Cache containing width of often used characters.
Definition at line 54 of file gfx.cpp.
Referenced by GetCharacterWidth(), and LoadStringWidthTable().