gfx_func.h File Reference

Functions related to the gfx engine. More...

#include "gfx_type.h"
#include "strings_type.h"

Go to the source code of this file.

Defines

#define ASCII_LETTERSTART   32

Functions

void GameLoop ()
void CreateConsole ()
void HandleKeypress (uint32 key)
 Handle keyboard input.
void HandleCtrlChanged ()
void HandleMouseEvents ()
void CSleep (int milliseconds)
void UpdateWindows ()
void DrawChatMessage ()
 Draw the chat message-box.
void DrawMouseCursor ()
void ScreenSizeChanged ()
void HandleExitGameRequest ()
void GameSizeChanged ()
void UndrawMouseCursor ()
void RedrawScreenRect (int left, int top, int right, int bottom)
void GfxScroll (int left, int top, int width, int height, int xo, int yo)
void DrawSprite (SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub=NULL)
int DrawStringCentered (int x, int y, StringID str, uint16 color)
int DrawStringCenteredTruncated (int xl, int xr, int y, StringID str, uint16 color)
int DoDrawStringCentered (int x, int y, const char *str, uint16 color)
int DrawString (int x, int y, StringID str, uint16 color)
int DrawStringTruncated (int x, int y, StringID str, uint16 color, uint maxw)
int DoDrawString (const char *string, int x, int y, uint16 color)
 Draw a string at the given coordinates with the given colour.
int DoDrawStringTruncated (const char *str, int x, int y, uint16 color, uint maxw)
void DrawStringCenterUnderline (int x, int y, StringID str, uint16 color)
void DrawStringCenterUnderlineTruncated (int xl, int xr, int y, StringID str, uint16 color)
int DrawStringRightAligned (int x, int y, StringID str, uint16 color)
void DrawStringRightAlignedTruncated (int x, int y, StringID str, uint16 color, uint maxw)
void DrawStringRightAlignedUnderline (int x, int y, StringID str, uint16 color)
void GfxFillRect (int left, int top, int right, int bottom, int color)
void GfxDrawLine (int left, int top, int right, int bottom, int color)
void DrawBox (int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
 Draws the projection of a parallelepiped.
Dimension GetStringBoundingBox (const char *str)
 Return the string dimension in pixels.
uint32 FormatStringLinebreaks (char *str, int maxw)
 'Correct' a string to a maximum length.
void LoadStringWidthTable ()
void DrawStringMultiCenter (int x, int y, StringID str, int maxw)
 Draw a given string with the centre around the given x coordinates.
uint DrawStringMultiLine (int x, int y, StringID str, int maxw, int maxh=-1)
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.
void GfxInitPalettes ()
bool FillDrawPixelInfo (DrawPixelInfo *n, int left, int top, int width, int height)
 Set up a clipping area for only drawing into a certain area.
void DrawOverlappedWindowForAll (int left, int top, int right, int bottom)
void SetMouseCursor (SpriteID sprite, SpriteID pal)
void SetAnimatedMouseCursor (const AnimCursor *table)
void CursorTick ()
bool ChangeResInGame (int w, int h)
void SortResolutions (int count)
bool ToggleFullScreen (bool fs)
byte GetCharacterWidth (FontSize size, uint32 key)
static byte GetCharacterHeight (FontSize size)

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
bool _left_button_clicked
bool _right_button_down
bool _right_button_clicked
DrawPixelInfo _screen
bool _screen_disable_anim
 Disable palette animation (important for 32bpp-anim blitter during giant screenshot).
int _pal_first_dirty
int _pal_count_dirty
int _num_resolutions
uint16 _resolutions [32][2]
uint16 _cur_resolution [2]
Colour _cur_palette [256]
FontSize _cur_fontsize
DrawPixelInfo * _cur_dpi
byte _colour_gradient [16][8]
 All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7).
bool _use_dos_palette


Detailed Description

Functions related to the gfx engine.

Definition in file gfx_func.h.


Function Documentation

int DoDrawString ( const char *  string,
int  x,
int  y,
uint16  real_color 
)

Draw a string at the given coordinates with the given colour.

Parameters:
string the string to draw
x offset from left side of the screen
y offset from top side of the screen
real_color colour of the string, see _string_colormap in table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
Returns:
the x-coordinates where the drawing has finished. If nothing is drawn the originally passed x-coordinate is returned

Definition at line 577 of file gfx.cpp.

References IS_PALETTE_COLOR, and Swap().

Referenced by DrawChatMessage(), DrawSortButtonState(), and DrawStringMultiCenter().

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

Referenced by ViewportDrawBoundingBoxes().

void DrawStringMultiCenter ( int  x,
int  y,
StringID  str,
int  maxw 
)

Draw a given string with the centre around the given x coordinates.

Parameters:
x Centre the string around this pixel width
y Draw the string at this pixel height (first line's bottom)
str String to draw
maxw Maximum width the string can have before it is wrapped

Definition at line 434 of file gfx.cpp.

References DoDrawString(), FormatStringLinebreaks(), GB(), and GetStringBoundingBox().

Referenced by EndGameWndProc(), and PlayerCompanyWndProc().

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

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

uint32 FormatStringLinebreaks ( char *  str,
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
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 372 of file gfx.cpp.

References IsWhitespace(), and Utf8PrevChar().

Referenced by DrawStringMultiCenter().

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

References max().

Referenced by DrawStringMultiCenter(), GetStringListMaxWidth(), and GuiShowTooltipsWithArgs().

void HandleKeypress ( uint32  key  ) 

Handle keyboard input.

Parameters:
key Lower 8 bits contain the ASCII character, the higher 16 bits the keycode

Definition at line 1637 of file window.cpp.

References _last_z_window, GB(), and IsGeneratingWorld().


Generated on Mon Sep 22 20:34:22 2008 for openttd by  doxygen 1.5.6