gfx.cpp File Reference

Handling of drawing text and other gfx related stuff. More...

#include "stdafx.h"
#include "gfx_func.h"
#include "variables.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 "landscape_type.h"
#include "network/network_func.h"
#include "thread/thread.h"
#include "window_func.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)

Typedefs

typedef WChar UChar

Enumerations

enum  { DIRTY_BLOCK_HEIGHT = 8, DIRTY_BLOCK_WIDTH = 64 }

Functions

static void GfxMainBlitter (const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub=NULL)
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)
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 *text)
static int TruncateString (char *str, int maxw, bool ignore_setxy)
 Truncate a given string to a maximum width if neccessary.
static int ReallyDoDrawString (const UChar *string, int x, int y, TextColour &colour, bool parse_string_also_when_clipped)
 Draw a string at the given coordinates with the given colour.
static int GetStringWidth (const UChar *str)
 Get the real width of the string.
static int DrawString (int left, int right, int top, char *str, const char *last, TextColour colour, 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)
 'Correct' a string to a maximum length.
static int GetMultilineStringHeight (const char *src, int num)
 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.
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)
 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, SpriteID 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 ()
 Let the dirty blocks repainting by the video driver.
void SetDirtyBlocks (int left, int top, int right, int bottom)
 Set a new dirty block.
void MarkWholeScreenDirty ()
 Marks 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.
static void SetCursorSprite (SpriteID cursor, SpriteID pal)
static void SwitchAnimatedCursor ()
void CursorTick ()
void SetMouseCursor (SpriteID sprite, SpriteID pal)
void SetAnimatedMouseCursor (const AnimCursor *table)
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).
FontSize _cur_fontsize
 Currently selected font.
static FontSize _last_fontsize
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 uint _dirty_bytes_per_line = 0
static byte * _dirty_blocks = NULL


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

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

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

void DrawSprite ( SpriteID  img,
SpriteID  pal,
int  x,
int  y,
const SubSprite sub 
)

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.

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.

Definition at line 613 of file gfx.cpp.

References 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.

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.

Definition at line 593 of file gfx.cpp.

References DrawString(), lastof, and strecpy().

static int DrawString ( int  left,
int  right,
int  top,
char *  str,
const char *  last,
TextColour  colour,
StringAlignment  align,
bool  underline = false,
bool  truncate = true 
) [static]

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.
last The end of the string buffer 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.
truncate Whether to truncate the string 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 442 of file gfx.cpp.

References _cur_fontsize, _dynlang, _string_colourremap, SmallVector< T, S >::Append(), SmallVector< T, S >::Begin(), SmallVector< T, S >::Clear(), SmallVector< T, S >::End(), FONT_HEIGHT_NORMAL, FS_NORMAL, GetStringBoundingBox(), GetStringWidth(), GfxFillRect(), lastof, max(), min(), ReallyDoDrawString(), SA_CENTER, SA_FORCE, SA_LEFT, SA_MASK, SA_RIGHT, SA_STRIP, TD_RTL, DynamicLanguages::text_dir, and TruncateString().

Referenced by SettingEntry::Draw(), DrawAircraftDetails(), DrawButtonDropdown(), DrawCaption(), StationViewWindow::DrawCargoRatings(), DrawCategories(), DrawCloseBox(), DrawEngineList(), SelectCompanyManagerFaceWindow::DrawFaceStringLabel(), DrawFrame(), DrawInset(), DrawLabel(), DrawNewsString(), DrawOrderString(), DrawPrice(), TownAuthorityWindow::DrawRatings(), DrawRoadVehDetails(), SettingEntry::DrawSetting(), DrawShipDetails(), Window::DrawSortButtonState(), DrawString(), DrawStringMultiLine(), DrawText(), SmallMapWindow::DrawTowns(), DrawTrainDetails(), DrawVehiclePurchaseInfo(), DrawVehicleRefitWindow(), DrawVerticalScrollbar(), StationViewWindow::DrawWaitingCargo(), VehicleViewWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), CompanyStationsWindow::DrawWidget(), SmallMapWindow::DrawWidget(), OrdersWindow::DrawWidget(), NewGRFWindow::DrawWidget(), NewGRFAddWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), CompanyWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), AIDebugWindow::DrawWidget(), AIConfigWindow::DrawWidget(), AISettingsWindow::DrawWidget(), AIListWindow::DrawWidget(), DrawYearColumn(), 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.

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 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 all strings
Returns:
The bottom to where we have written.

Definition at line 800 of file gfx.cpp.

References _cur_fontsize, DrawString(), FormatStringLinebreaks(), FS_NORMAL, GB(), GetCharacterHeight(), lastof, SA_CENTER, and strecpy().

Referenced by DrawCargoListText(), RefitWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), NewsWindow::DrawWidget(), QueryWindow::DrawWidget(), TooltipsWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), CompanyWindow::DrawWidget(), AIListWindow::DrawWidget(), EndGameWindow::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 1601 of file gfx.cpp.

References DrawPixelInfo::dst_ptr, BlitterFactoryBase::GetCurrentBlitter(), DrawPixelInfo::height, DrawPixelInfo::left, Blitter::MoveTo(), DrawPixelInfo::pitch, DrawPixelInfo::top, DrawPixelInfo::width, and DrawPixelInfo::zoom.

Referenced by DrawTrainImage(), and SmallMapWindow::DrawWidget().

uint32 FormatStringLinebreaks ( char *  str,
const char *  last,
int  maxw 
)

'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.

Note:
To know if the terminating '' is the string end or just a newline, the returned 'num' value should be consulted. The num'th '', starting with index 0 is the real string end.
Parameters:
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
Returns:
return a 32bit wide number consisting of 2 packed values: 0 - 15 the number of lines ADDED to the string 16 - 31 the fontsize in which the length calculation was done at

Definition at line 639 of file gfx.cpp.

References _cur_fontsize, FS_LARGE, FS_SMALL, GetCharacterWidth(), IsWhitespace(), SCC_BIGFONT, SCC_TINYFONT, and Utf8PrevChar().

Referenced by DrawStringMultiLine(), and GetStringHeight().

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

References _stringwidth_table, and GetGlyphWidth().

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.

Parameters:
size Font of the digit
Returns:
Width of the digit.

Definition at line 1314 of file gfx.cpp.

References GetCharacterWidth(), and max().

static int GetMultilineStringHeight ( const char *  src,
int  num 
) [static]

Calculates height of string (in pixels).

Accepts multiline string with '' as separators.

Parameters:
src string to check
num number of extra lines (output of FormatStringLinebreaks())
Note:
assumes text won't be truncated. FormatStringLinebreaks() is a good way to ensure that.
Returns:
height of pixels of string when it is drawn

Definition at line 735 of file gfx.cpp.

References _cur_fontsize, FS_LARGE, FS_SMALL, GetCharacterHeight(), SCC_BIGFONT, and SCC_TINYFONT.

Referenced by GetStringHeight().

Dimension GetSpriteSize ( SpriteID  sprid  ) 

Get the size of a sprite.

Parameters:
sprid Sprite to examine.
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 1012 of file gfx.cpp.

References Sprite::height, Dimension::height, ST_NORMAL, Sprite::width, Dimension::width, Sprite::x_offs, and Sprite::y_offs.

Referenced by DrawOrderString(), OrdersWindow::DrawWidget(), MakeCompanyButtonRows(), SelectCompanyManagerFaceWindow::OnInit(), and NWidgetLeaf::SetupSmallestSize().

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

References GetStringBoundingBox(), and lastof.

Dimension GetStringBoundingBox ( const char *  str  ) 

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
Returns:
string width and height in pixels

Definition at line 860 of file gfx.cpp.

References _cur_fontsize, FS_LARGE, FS_SMALL, GetCharacterHeight(), GetCharacterWidth(), Dimension::height, max(), SCC_BIGFONT, SCC_TINYFONT, and Dimension::width.

Referenced by DrawLabel(), DrawString(), DrawText(), OrdersWindow::DrawWidget(), ExpensesList::GetCategoriesWidth(), GetStringBoundingBox(), SmallMapWindow::OnInit(), SelectCompanyManagerFaceWindow::OnInit(), NWidgetLeaf::SetupSmallestSize(), NWidgetBackground::SetupSmallestSize(), ViewportSign::UpdatePosition(), VehicleDetailsWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), TownAuthorityWindow::UpdateWidgetSize(), SelectStationWindow< T >::UpdateWidgetSize(), StationViewWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), NewGRFWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), IndustryDirectoryWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), SetDateWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), SelectCompanyManagerFaceWindow::UpdateWidgetSize(), SelectCompanyLiveryWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), and ReplaceVehicleWindow::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 762 of file gfx.cpp.

References FormatStringLinebreaks(), GB(), GetMultilineStringHeight(), and lastof.

Referenced by GetStringMultiLineBoundingBox(), TooltipsWindow::UpdateWidgetSize(), and ErrmsgWindow::UpdateWidgetSize().

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

References GetStringHeight(), and Dimension::width.

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

static int GetStringWidth ( const UChar *  str  )  [static]

Get the real width of the string.

Parameters:
str the string to draw
Returns:
the width.

Definition at line 392 of file gfx.cpp.

References _cur_fontsize, FS_LARGE, FS_SMALL, GetCharacterWidth(), 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.

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

References Blitter::DrawColourMappingRect(), Blitter::DrawRect(), DrawPixelInfo::dst_ptr, FILLRECT_CHECKER, FILLRECT_RECOLOUR, GB(), BlitterFactoryBase::GetCurrentBlitter(), DrawPixelInfo::height, DrawPixelInfo::left, Blitter::MoveTo(), PALETTE_WIDTH, Blitter::SetPixel(), DrawPixelInfo::top, DrawPixelInfo::width, and DrawPixelInfo::zoom.

Referenced by NWidgetLeaf::Draw(), NWidgetViewport::Draw(), NWidgetBackground::Draw(), NWidgetToolbarContainer::Draw(), DrawArrowButtons(), DrawCaption(), DrawFrame(), DrawFrameRect(), SmallMapWindow::DrawHorizMapIndicator(), DrawHorizontalScrollbar(), DrawMatrix(), SmallMapWindow::DrawSmallMap(), DrawString(), DrawTrainDetails(), DrawVerticalScrollbar(), SmallMapWindow::DrawVertMapIndicator(), DropdownWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), SmallMapWindow::DrawWidget(), NewsWindow::DrawWidget(), NewGRFAddWindow::DrawWidget(), TooltipsWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), DrawYearColumn(), and StationsWndShowStationRating().

static int ReallyDoDrawString ( const UChar *  string,
int  x,
int  y,
TextColour colour,
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.

Parameters:
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
colour Colour of the string, see _string_colourmap in table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
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)
Returns:
the x-coordinates where the drawing has finished. If nothing is drawn, the originally passed x-coordinate is returned

Definition at line 940 of file gfx.cpp.

References _cur_fontsize, _max_char_width, FS_LARGE, FS_SMALL, GetCharacterHeight(), GetCharacterWidth(), GetGlyph(), DrawPixelInfo::height, DrawPixelInfo::left, SCC_BIGFONT, SCC_TINYFONT, SetColourRemap(), Swap(), DrawPixelInfo::top, and DrawPixelInfo::width.

Referenced by DrawString().

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

References _string_colourremap, _use_palette, IS_PALETTE_COLOUR, and PAL_DOS.

Referenced by DrawCharCentered(), and ReallyDoDrawString().

static int TruncateString ( char *  str,
int  maxw,
bool  ignore_setxy 
) [static]

Truncate a given string to a maximum width if neccessary.

If the string is truncated, add three dots ('...') to show this.

Parameters:
*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
Returns:
new width of (truncated) string

Definition at line 335 of file gfx.cpp.

References _cur_fontsize, FS_LARGE, FS_SMALL, GetCharacterWidth(), SCC_BIGFONT, and SCC_TINYFONT.

Referenced by DrawString().


Variable Documentation

byte _stringwidth_table[FS_END][224] [static]

Cache containing width of often used characters.

See also:
GetCharacterWidth()

Definition at line 54 of file gfx.cpp.

Referenced by GetCharacterWidth(), and LoadStringWidthTable().


Generated on Sat Dec 26 20:06:10 2009 for OpenTTD by  doxygen 1.5.6