2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
/** @file gfx_func.h Functions related to the gfx engine. */
|
2007-03-01 01:24:44 +00:00
|
|
|
|
2007-09-09 10:13:17 +00:00
|
|
|
/**
|
|
|
|
* @defgroup dirty Dirty
|
|
|
|
*
|
|
|
|
* Handles the repaint of some part of the screen.
|
|
|
|
*
|
|
|
|
* Some places in the code are called functions which makes something "dirty".
|
|
|
|
* This has nothing to do with making a Tile or Window darker or less visible.
|
|
|
|
* This term comes from memory caching and is used to define an object must
|
|
|
|
* be repaint. If some data of an object (like a Tile, Window, Vehicle, whatever)
|
|
|
|
* are changed which are so extensive the object must be repaint its marked
|
|
|
|
* as "dirty". The video driver repaint this object instead of the whole screen
|
|
|
|
* (this is btw. also possible if needed). This is used to avoid a
|
|
|
|
* flickering of the screen by the video driver constantly repainting it.
|
|
|
|
*
|
|
|
|
* This whole mechanism is controlled by an rectangle defined in #_invalid_rect. This
|
|
|
|
* rectangle defines the area on the screen which must be repaint. If a new object
|
|
|
|
* needs to be repainted this rectangle is extended to 'catch' the object on the
|
|
|
|
* screen. At some point (which is normaly uninteressted for patch writers) this
|
|
|
|
* rectangle is send to the video drivers method
|
|
|
|
* VideoDriver::MakeDirty and it is truncated back to an empty rectangle. At some
|
|
|
|
* later point (which is uninteressted, too) the video driver
|
|
|
|
* repaints all these saved rectangle instead of the whole screen and drop the
|
|
|
|
* rectangle informations. Then a new round begins by marking objects "dirty".
|
|
|
|
*
|
|
|
|
* @see VideoDriver::MakeDirty
|
|
|
|
* @see _invalid_rect
|
|
|
|
* @see _screen
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
#ifndef GFX_FUNC_H
|
|
|
|
#define GFX_FUNC_H
|
|
|
|
|
|
|
|
#include "gfx_type.h"
|
|
|
|
#include "strings_type.h"
|
2007-01-13 14:43:46 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void GameLoop();
|
2007-01-13 14:43:46 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void CreateConsole();
|
2007-01-13 14:43:46 +00:00
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
extern byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down
|
2007-01-13 14:43:46 +00:00
|
|
|
extern bool _fullscreen;
|
|
|
|
extern CursorVars _cursor;
|
2007-03-01 01:24:44 +00:00
|
|
|
extern bool _ctrl_pressed; ///< Is Ctrl pressed?
|
|
|
|
extern bool _shift_pressed; ///< Is Shift pressed?
|
2007-01-13 14:43:46 +00:00
|
|
|
extern byte _fast_forward;
|
|
|
|
|
|
|
|
extern bool _left_button_down;
|
|
|
|
extern bool _left_button_clicked;
|
|
|
|
extern bool _right_button_down;
|
|
|
|
extern bool _right_button_clicked;
|
|
|
|
|
|
|
|
extern DrawPixelInfo _screen;
|
2008-01-11 17:12:41 +00:00
|
|
|
extern bool _screen_disable_anim; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
|
2007-01-13 14:43:46 +00:00
|
|
|
|
|
|
|
extern int _num_resolutions;
|
2008-06-16 19:38:41 +00:00
|
|
|
extern Dimension _resolutions[32];
|
|
|
|
extern Dimension _cur_resolution;
|
2011-12-08 18:13:29 +00:00
|
|
|
extern Palette _cur_palette; ///< Current palette
|
2007-01-13 14:43:46 +00:00
|
|
|
|
|
|
|
void HandleKeypress(uint32 key);
|
2008-02-17 17:00:43 +00:00
|
|
|
void HandleCtrlChanged();
|
2007-03-07 11:47:46 +00:00
|
|
|
void HandleMouseEvents();
|
2007-01-13 14:43:46 +00:00
|
|
|
void CSleep(int milliseconds);
|
2007-03-07 11:47:46 +00:00
|
|
|
void UpdateWindows();
|
2007-01-13 14:43:46 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void DrawMouseCursor();
|
|
|
|
void ScreenSizeChanged();
|
|
|
|
void GameSizeChanged();
|
|
|
|
void UndrawMouseCursor();
|
2007-01-13 14:43:46 +00:00
|
|
|
|
2010-05-13 09:44:44 +00:00
|
|
|
/** Size of the buffer used for drawing strings. */
|
|
|
|
static const int DRAW_STRING_BUFFER = 2048;
|
2008-08-12 11:21:37 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void RedrawScreenRect(int left, int top, int right, int bottom);
|
|
|
|
void GfxScroll(int left, int top, int width, int height, int xo, int yo);
|
2005-07-17 15:54:57 +00:00
|
|
|
|
2011-11-24 12:38:48 +00:00
|
|
|
Dimension GetSpriteSize(SpriteID sprid, Point *offset = NULL, ZoomLevel zoom = ZOOM_LVL_GUI);
|
|
|
|
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL);
|
|
|
|
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL, ZoomLevel zoom = ZOOM_LVL_GUI);
|
2005-09-10 07:38:03 +00:00
|
|
|
|
2009-03-21 18:28:01 +00:00
|
|
|
/** How to align the to-be drawn text. */
|
2009-03-21 20:06:00 +00:00
|
|
|
enum StringAlignment {
|
2010-07-02 13:53:05 +00:00
|
|
|
SA_LEFT = 0 << 0, ///< Left align the text.
|
|
|
|
SA_HOR_CENTER = 1 << 0, ///< Horizontally center the text.
|
|
|
|
SA_RIGHT = 2 << 0, ///< Right align the text (must be a single bit).
|
|
|
|
SA_HOR_MASK = 3 << 0, ///< Mask for horizontal alignment.
|
|
|
|
|
|
|
|
SA_TOP = 0 << 2, ///< Top align the text.
|
|
|
|
SA_VERT_CENTER = 1 << 2, ///< Vertically center the text.
|
|
|
|
SA_BOTTOM = 2 << 2, ///< Bottom align the text.
|
|
|
|
SA_VERT_MASK = 3 << 2, ///< Mask for vertical alignment.
|
|
|
|
|
|
|
|
SA_CENTER = SA_HOR_CENTER | SA_VERT_CENTER, ///< Center both horizontally and vertically.
|
|
|
|
|
|
|
|
SA_FORCE = 1 << 4, ///< Force the alignment, i.e. don't swap for RTL languages.
|
|
|
|
SA_STRIP = 1 << 5, ///< Strip the SETX/SETXY commands from the string
|
2009-03-21 18:28:01 +00:00
|
|
|
};
|
2010-03-23 22:25:43 +00:00
|
|
|
DECLARE_ENUM_AS_BIT_SET(StringAlignment)
|
2009-03-21 18:28:01 +00:00
|
|
|
|
2011-11-20 11:50:12 +00:00
|
|
|
int DrawString(int left, int right, int top, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);
|
|
|
|
int DrawString(int left, int right, int top, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);
|
|
|
|
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL);
|
|
|
|
int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL);
|
2009-03-21 18:28:01 +00:00
|
|
|
|
2009-02-09 02:09:47 +00:00
|
|
|
void DrawCharCentered(uint32 c, int x, int y, TextColour colour);
|
2008-03-26 10:08:17 +00:00
|
|
|
|
2009-02-09 02:09:47 +00:00
|
|
|
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE);
|
2011-04-02 16:39:30 +00:00
|
|
|
void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1);
|
2007-09-26 19:27:29 +00:00
|
|
|
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-05-30 15:32:37 +00:00
|
|
|
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NORMAL);
|
2009-06-27 11:45:05 +00:00
|
|
|
Dimension GetStringBoundingBox(StringID strid);
|
2010-05-30 15:32:37 +00:00
|
|
|
uint32 FormatStringLinebreaks(char *str, const char *last, int maxw, FontSize start_fontsize = FS_NORMAL);
|
2008-07-22 19:25:47 +00:00
|
|
|
int GetStringHeight(StringID str, int maxw);
|
2009-09-02 20:40:56 +00:00
|
|
|
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
|
2012-01-12 19:11:51 +00:00
|
|
|
Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion);
|
2011-12-10 12:56:37 +00:00
|
|
|
void LoadStringWidthTable(bool monospace = false);
|
2007-09-09 10:13:17 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void DrawDirtyBlocks();
|
2004-08-09 17:04:08 +00:00
|
|
|
void SetDirtyBlocks(int left, int top, int right, int bottom);
|
2007-03-07 11:47:46 +00:00
|
|
|
void MarkWholeScreenDirty();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void GfxInitPalettes();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-01-10 00:31:47 +00:00
|
|
|
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* window.cpp */
|
2004-08-09 17:04:08 +00:00
|
|
|
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
|
|
|
|
|
2010-01-21 01:38:13 +00:00
|
|
|
void SetMouseCursor(CursorID cursor, PaletteID pal);
|
2007-02-24 15:05:14 +00:00
|
|
|
void SetAnimatedMouseCursor(const AnimCursor *table);
|
2007-03-07 11:47:46 +00:00
|
|
|
void CursorTick();
|
2010-08-05 19:23:19 +00:00
|
|
|
void UpdateCursorSize();
|
2004-08-09 17:04:08 +00:00
|
|
|
bool ChangeResInGame(int w, int h);
|
2005-05-14 21:01:57 +00:00
|
|
|
void SortResolutions(int count);
|
2008-01-01 14:20:48 +00:00
|
|
|
bool ToggleFullScreen(bool fs);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* gfx.cpp */
|
2006-11-16 22:05:33 +00:00
|
|
|
byte GetCharacterWidth(FontSize size, uint32 key);
|
2009-12-20 16:42:35 +00:00
|
|
|
byte GetDigitWidth(FontSize size = FS_NORMAL);
|
2006-05-09 13:23:04 +00:00
|
|
|
|
2008-08-01 09:34:34 +00:00
|
|
|
/**
|
|
|
|
* Get height of a character for a given font size.
|
|
|
|
* @param size Font size to get height of
|
|
|
|
* @return Height of characters in the given font (pixels)
|
|
|
|
*/
|
2006-05-09 13:23:04 +00:00
|
|
|
static inline byte GetCharacterHeight(FontSize size)
|
2005-02-21 19:14:16 +00:00
|
|
|
{
|
2009-03-25 20:01:34 +00:00
|
|
|
assert(size < FS_END);
|
|
|
|
extern int _font_height[FS_END];
|
|
|
|
return _font_height[size];
|
2005-02-21 19:14:16 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-06-20 15:48:55 +00:00
|
|
|
/** Height of characters in the small (#FS_SMALL) font. */
|
2009-03-25 20:01:34 +00:00
|
|
|
#define FONT_HEIGHT_SMALL (GetCharacterHeight(FS_SMALL))
|
2009-06-20 15:48:55 +00:00
|
|
|
|
|
|
|
/** Height of characters in the normal (#FS_NORMAL) font. */
|
2009-03-25 20:01:34 +00:00
|
|
|
#define FONT_HEIGHT_NORMAL (GetCharacterHeight(FS_NORMAL))
|
2009-06-20 15:48:55 +00:00
|
|
|
|
|
|
|
/** Height of characters in the large (#FS_LARGE) font. */
|
2009-03-25 20:01:34 +00:00
|
|
|
#define FONT_HEIGHT_LARGE (GetCharacterHeight(FS_LARGE))
|
|
|
|
|
2011-11-20 11:56:51 +00:00
|
|
|
/** Height of characters in the large (#FS_MONO) font. */
|
|
|
|
#define FONT_HEIGHT_MONO (GetCharacterHeight(FS_MONO))
|
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
extern DrawPixelInfo *_cur_dpi;
|
2007-11-04 00:08:57 +00:00
|
|
|
|
2006-08-29 19:26:13 +00:00
|
|
|
/**
|
|
|
|
* All 16 colour gradients
|
|
|
|
* 8 colours per gradient from darkest (0) to lightest (7)
|
|
|
|
*/
|
2008-08-04 17:27:06 +00:00
|
|
|
extern byte _colour_gradient[COLOUR_END][8];
|
2004-12-12 20:36:24 +00:00
|
|
|
|
2008-09-02 18:45:15 +00:00
|
|
|
extern bool _palette_remap_grf[];
|
2004-12-14 20:54:01 +00:00
|
|
|
|
2011-05-04 17:45:16 +00:00
|
|
|
/**
|
|
|
|
* Return the colour for a particular greyscale level.
|
|
|
|
* @param level Intensity, 0 = black, 15 = white
|
|
|
|
* @return colour
|
|
|
|
*/
|
|
|
|
#define GREY_SCALE(level) (level)
|
|
|
|
|
2011-05-06 21:13:29 +00:00
|
|
|
static const uint8 PC_BLACK = GREY_SCALE(1); ///< Black palette colour.
|
2011-05-07 00:22:46 +00:00
|
|
|
static const uint8 PC_DARK_GREY = GREY_SCALE(6); ///< Dark grey palette colour.
|
2011-05-06 21:13:29 +00:00
|
|
|
static const uint8 PC_GREY = GREY_SCALE(10); ///< Grey palette colour.
|
|
|
|
static const uint8 PC_WHITE = GREY_SCALE(15); ///< White palette colour.
|
|
|
|
|
|
|
|
static const uint8 PC_VERY_DARK_RED = 0xB2; ///< Almost-black red palette colour.
|
|
|
|
static const uint8 PC_DARK_RED = 0xB4; ///< Dark red palette colour.
|
|
|
|
static const uint8 PC_RED = 0xB8; ///< Red palette colour.
|
|
|
|
|
2011-05-07 00:22:46 +00:00
|
|
|
static const uint8 PC_VERY_DARK_BROWN = 0x56; ///< Almost-black brown palette colour.
|
|
|
|
|
|
|
|
static const uint8 PC_ORANGE = 0xC2; ///< Orange palette colour.
|
|
|
|
|
2011-05-06 21:13:29 +00:00
|
|
|
static const uint8 PC_YELLOW = 0xBF; ///< Yellow palette colour.
|
|
|
|
static const uint8 PC_LIGHT_YELLOW = 0x44; ///< Light yellow palette colour.
|
|
|
|
static const uint8 PC_VERY_LIGHT_YELLOW = 0x45; ///< Almost-white yellow palette colour.
|
|
|
|
|
|
|
|
static const uint8 PC_GREEN = 0xD0; ///< Green palette colour.
|
|
|
|
|
|
|
|
static const uint8 PC_DARK_BLUE = 0x9D; ///< Dark blue palette colour.
|
2011-05-07 00:22:46 +00:00
|
|
|
static const uint8 PC_LIGHT_BLUE = 0x98; ///< Light blue palette colour.
|
2011-05-06 21:13:29 +00:00
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
#endif /* GFX_FUNC_H */
|