gfx.cpp File Reference

#include "stdafx.h"
#include "openttd.h"
#include "gfx_func.h"
#include "spritecache.h"
#include "variables.h"
#include "fontcache.h"
#include "genworld.h"
#include "debug.h"
#include "zoom_func.h"
#include "texteff.hpp"
#include "blitter/factory.hpp"
#include "video/video_driver.hpp"
#include "strings_func.h"
#include "core/math_func.hpp"
#include "settings_type.h"
#include "table/palettes.h"
#include "table/sprites.h"
#include "table/control_codes.h"

Go to the source code of this file.

Defines

#define DIRTY_BYTES_PER_LINE   (MAX_SCREEN_WIDTH / 64)
#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)
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 color)
void GfxDrawLine (int x, int y, int x2, int y2, int color)
void GfxDrawLineUnscaled (int x, int y, int x2, int y2, 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.
static int TruncateString (char *str, int maxw)
 Truncate a given string to a maximum width if neccessary.
static int TruncateStringID (StringID src, char *dest, int maxw, const char *last)
int DrawString (int x, int y, StringID str, uint16 color)
int DrawStringTruncated (int x, int y, StringID str, uint16 color, uint maxw)
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)
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)
void DrawStringCenterUnderline (int x, int y, StringID str, uint16 color)
void DrawStringCenterUnderlineTruncated (int xl, int xr, int y, StringID str, uint16 color)
uint32 FormatStringLinebreaks (char *str, int maxw)
 'Correct' a string to a maximum length.
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)
Dimension GetStringBoundingBox (const char *str)
 Return the string dimension in pixels.
int DoDrawString (const char *string, int x, int y, uint16 real_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 DrawSprite (SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub)
void DoPaletteAnimations ()
void GfxInitPalettes ()
void LoadStringWidthTable ()
byte GetCharacterWidth (FontSize size, WChar key)
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 void *pa, const void *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
bool _left_button_clicked
bool _right_button_down
bool _right_button_clicked
DrawPixelInfo _screen
bool _screen_disable_anim = false
 Disable palette animation (important for 32bpp-anim blitter during giant screenshot).
bool _exit_game
bool _networking
 are we in networking mode?
byte _game_mode
int8 _pause_game
int _pal_first_dirty
int _pal_count_dirty
Colour _cur_palette [256]
byte _stringwidth_table [FS_END][224]
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
FontSize _cur_fontsize
static FontSize _last_fontsize
static uint8 _cursor_backup [64 *64 *4]
static Rect _invalid_rect
 The rect for repaint.
static const byte * _color_remap_ptr
static byte _string_colorremap [3]
static byte _dirty_blocks [DIRTY_BYTES_PER_LINE *MAX_SCREEN_HEIGHT/8]


Detailed Description

Definition in file gfx.cpp.


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().

static int TruncateString ( char *  str,
int  maxw 
) [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
Returns:
new width of (truncated) string

Definition at line 217 of file gfx.cpp.


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