2005-07-24 15:12:37 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
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 11:13:17 +01: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 _pal_first_dirty;
|
2007-06-19 16:04:08 +01:00
|
|
|
extern int _pal_count_dirty;
|
2007-01-13 14:43:46 +00:00
|
|
|
extern int _num_resolutions;
|
2008-06-16 20:38:41 +01:00
|
|
|
extern Dimension _resolutions[32];
|
|
|
|
extern Dimension _cur_resolution;
|
2008-06-18 22:19:04 +01:00
|
|
|
extern Colour _cur_palette[256]; ///< Current palette. Entry 0 has to be always fully transparent!
|
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
|
|
|
|
2008-08-12 12:21:37 +01:00
|
|
|
enum {
|
|
|
|
/* Size of the buffer used for drawing strings. */
|
2009-01-17 16:53:32 +00:00
|
|
|
DRAW_STRING_BUFFER = 2048,
|
2008-08-12 12:21:37 +01:00
|
|
|
};
|
|
|
|
|
2004-08-09 18:04:08 +01: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 16:54:57 +01:00
|
|
|
|
2007-10-05 22:49:15 +01:00
|
|
|
void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub = NULL);
|
2005-09-10 08:38:03 +01: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 {
|
2009-03-25 01:10:24 +00:00
|
|
|
SA_LEFT, ///< Left align the text
|
|
|
|
SA_CENTER, ///< Center the text
|
|
|
|
SA_RIGHT, ///< Right align the text
|
|
|
|
SA_MASK = 3, ///< Mask for base alignment
|
|
|
|
SA_FORCE = 4, ///< Force the alignment, i.e. don't swap for RTL languages.
|
2009-03-21 18:28:01 +00:00
|
|
|
};
|
2009-03-25 01:10:24 +00:00
|
|
|
DECLARE_ENUM_AS_BIT_SET(StringAlignment);
|
2009-03-21 18:28:01 +00:00
|
|
|
|
2009-04-26 15:52:56 +01:00
|
|
|
int DrawString(int left, int right, int top, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false);
|
|
|
|
int DrawString(int left, int right, int top, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false);
|
2009-04-26 11:45:07 +01:00
|
|
|
int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false);
|
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);
|
|
|
|
void GfxDrawLine(int left, int top, int right, int bottom, int colour);
|
2007-09-26 20:27:29 +01:00
|
|
|
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-12-22 23:30:28 +00:00
|
|
|
Dimension GetStringBoundingBox(const char *str);
|
2006-10-27 10:55:38 +01:00
|
|
|
uint32 FormatStringLinebreaks(char *str, int maxw);
|
2008-07-22 20:25:47 +01:00
|
|
|
int GetStringHeight(StringID str, int maxw);
|
2007-03-07 11:47:46 +00:00
|
|
|
void LoadStringWidthTable();
|
2007-09-09 11:13:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Let the dirty blocks repainting by the video driver.
|
|
|
|
*
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void DrawDirtyBlocks();
|
2007-09-09 11:13:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a new dirty block.
|
|
|
|
*
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
2004-08-09 18:04:08 +01:00
|
|
|
void SetDirtyBlocks(int left, int top, int right, int bottom);
|
2007-09-09 11:13:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks the whole screen as dirty.
|
|
|
|
*
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void MarkWholeScreenDirty();
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void GfxInitPalettes();
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2009-01-10 00:31:47 +00:00
|
|
|
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* window.cpp */
|
2004-08-09 18:04:08 +01:00
|
|
|
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
void SetMouseCursor(SpriteID sprite, SpriteID pal);
|
2007-02-24 15:05:14 +00:00
|
|
|
void SetAnimatedMouseCursor(const AnimCursor *table);
|
2007-03-07 11:47:46 +00:00
|
|
|
void CursorTick();
|
2004-08-09 18:04:08 +01:00
|
|
|
bool ChangeResInGame(int w, int h);
|
2005-05-14 22:01:57 +01:00
|
|
|
void SortResolutions(int count);
|
2008-01-01 14:20:48 +00:00
|
|
|
bool ToggleFullScreen(bool fs);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* gfx.cpp */
|
2005-02-21 18:59:54 +00:00
|
|
|
#define ASCII_LETTERSTART 32
|
2006-05-09 14:23:04 +01:00
|
|
|
extern FontSize _cur_fontsize;
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
byte GetCharacterWidth(FontSize size, uint32 key);
|
2006-05-09 14:23:04 +01:00
|
|
|
|
2008-08-01 10:34:34 +01: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 14:23:04 +01: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 18:04:08 +01:00
|
|
|
|
2009-03-25 20:01:34 +00:00
|
|
|
#define FONT_HEIGHT_SMALL (GetCharacterHeight(FS_SMALL))
|
|
|
|
#define FONT_HEIGHT_NORMAL (GetCharacterHeight(FS_NORMAL))
|
|
|
|
#define FONT_HEIGHT_LARGE (GetCharacterHeight(FS_LARGE))
|
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
extern DrawPixelInfo *_cur_dpi;
|
2007-11-04 00:08:57 +00:00
|
|
|
|
2006-08-29 20:26:13 +01:00
|
|
|
/**
|
|
|
|
* All 16 colour gradients
|
|
|
|
* 8 colours per gradient from darkest (0) to lightest (7)
|
|
|
|
*/
|
2008-08-04 18:27:06 +01:00
|
|
|
extern byte _colour_gradient[COLOUR_END][8];
|
2004-12-12 20:36:24 +00:00
|
|
|
|
2008-08-24 10:48:21 +01:00
|
|
|
extern PaletteType _use_palette;
|
2008-09-02 19:45:15 +01:00
|
|
|
extern bool _palette_remap_grf[];
|
|
|
|
extern const byte *_palette_remap;
|
|
|
|
extern const byte *_palette_reverse_remap;
|
2004-12-14 20:54:01 +00:00
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
#endif /* GFX_FUNC_H */
|