tron@2186: /* $Id$ */ tron@2186: belugas@6179: /** @file gfx.h */ belugas@6179: rubidium@7545: /** rubidium@7545: * @defgroup dirty Dirty rubidium@7545: * rubidium@7545: * Handles the repaint of some part of the screen. rubidium@7545: * rubidium@7545: * Some places in the code are called functions which makes something "dirty". rubidium@7545: * This has nothing to do with making a Tile or Window darker or less visible. rubidium@7545: * This term comes from memory caching and is used to define an object must rubidium@7545: * be repaint. If some data of an object (like a Tile, Window, Vehicle, whatever) rubidium@7545: * are changed which are so extensive the object must be repaint its marked rubidium@7545: * as "dirty". The video driver repaint this object instead of the whole screen rubidium@7545: * (this is btw. also possible if needed). This is used to avoid a rubidium@7545: * flickering of the screen by the video driver constantly repainting it. rubidium@7545: * rubidium@7545: * This whole mechanism is controlled by an rectangle defined in #_invalid_rect. This rubidium@7545: * rectangle defines the area on the screen which must be repaint. If a new object rubidium@7545: * needs to be repainted this rectangle is extended to 'catch' the object on the rubidium@7545: * screen. At some point (which is normaly uninteressted for patch writers) this rubidium@7545: * rectangle is send to the video drivers method rubidium@7545: * VideoDriver::MakeDirty and it is truncated back to an empty rectangle. At some rubidium@7545: * later point (which is uninteressted, too) the video driver rubidium@7545: * repaints all these saved rectangle instead of the whole screen and drop the rubidium@7545: * rectangle informations. Then a new round begins by marking objects "dirty". rubidium@7545: * rubidium@7545: * @see VideoDriver::MakeDirty rubidium@7545: * @see _invalid_rect rubidium@7545: * @see _screen rubidium@7545: */ rubidium@7545: rubidium@7545: truelight@0: #ifndef GFX_H truelight@0: #define GFX_H truelight@0: bjarni@6289: #include "openttd.h" truelight@6624: #include "zoom.hpp" KUDr@5636: KUDr@5636: enum WindowKeyCodes { KUDr@5636: WKC_SHIFT = 0x8000, KUDr@5636: WKC_CTRL = 0x4000, KUDr@5636: WKC_ALT = 0x2000, KUDr@5636: WKC_META = 0x1000, KUDr@5636: belugas@6179: /* Special ones */ KUDr@5636: WKC_NONE = 0, KUDr@5636: WKC_ESC = 1, KUDr@5636: WKC_BACKSPACE = 2, KUDr@5636: WKC_INSERT = 3, KUDr@5636: WKC_DELETE = 4, KUDr@5636: KUDr@5636: WKC_PAGEUP = 5, KUDr@5636: WKC_PAGEDOWN = 6, KUDr@5636: WKC_END = 7, KUDr@5636: WKC_HOME = 8, KUDr@5636: belugas@6179: /* Arrow keys */ KUDr@5636: WKC_LEFT = 9, KUDr@5636: WKC_UP = 10, KUDr@5636: WKC_RIGHT = 11, KUDr@5636: WKC_DOWN = 12, KUDr@5636: belugas@6179: /* Return & tab */ KUDr@5636: WKC_RETURN = 13, KUDr@5636: WKC_TAB = 14, KUDr@5636: belugas@6179: /* Space */ KUDr@5636: WKC_SPACE = 32, KUDr@5636: belugas@6179: /* Function keys */ KUDr@5636: WKC_F1 = 33, KUDr@5636: WKC_F2 = 34, KUDr@5636: WKC_F3 = 35, KUDr@5636: WKC_F4 = 36, KUDr@5636: WKC_F5 = 37, KUDr@5636: WKC_F6 = 38, KUDr@5636: WKC_F7 = 39, KUDr@5636: WKC_F8 = 40, KUDr@5636: WKC_F9 = 41, KUDr@5636: WKC_F10 = 42, KUDr@5636: WKC_F11 = 43, KUDr@5636: WKC_F12 = 44, KUDr@5636: truelight@7311: /* Backquote is the key left of "1" belugas@6179: * we only store this key here, no matter what character is really mapped to it rubidium@6729: * on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °) */ KUDr@5636: WKC_BACKQUOTE = 45, KUDr@5636: WKC_PAUSE = 46, KUDr@5636: belugas@6179: /* 0-9 are mapped to 48-57 belugas@6179: * A-Z are mapped to 65-90 belugas@6179: * a-z are mapped to 97-122 */ truelight@7310: glx@7541: /* Numerical keyboard */ glx@7541: WKC_NUM_0 = 128, glx@7541: WKC_NUM_1 = 129, glx@7541: WKC_NUM_2 = 130, glx@7541: WKC_NUM_3 = 131, glx@7541: WKC_NUM_4 = 132, glx@7541: WKC_NUM_5 = 133, glx@7541: WKC_NUM_6 = 134, glx@7541: WKC_NUM_7 = 135, glx@7541: WKC_NUM_8 = 136, glx@7541: WKC_NUM_9 = 137, glx@7541: WKC_NUM_DIV = 138, glx@7541: WKC_NUM_MUL = 139, glx@7541: WKC_NUM_MINUS = 140, glx@7541: WKC_NUM_PLUS = 141, glx@7541: WKC_NUM_ENTER = 142, glx@7541: WKC_NUM_DECIMAL = 143, truelight@7310: glx@7541: /* Other keys */ glx@7541: WKC_SLASH = 144, ///< / Forward slash glx@7541: WKC_SEMICOLON = 145, ///< ; Semicolon glx@7541: WKC_EQUALS = 146, ///< = Equals glx@7541: WKC_L_BRACKET = 147, ///< [ Left square bracket glx@7541: WKC_BACKSLASH = 148, ///< \ Backslash glx@7541: WKC_R_BRACKET = 149, ///< ] Right square bracket glx@7541: WKC_SINGLEQUOTE = 150, ///< ' Single quote glx@7541: WKC_COMMA = 151, ///< , Comma glx@7541: WKC_PERIOD = 152, ///< . Period glx@7541: WKC_MINUS = 153, ///< - Minus KUDr@5636: }; KUDr@5636: KUDr@5636: enum GameModes { KUDr@5636: GM_MENU, KUDr@5636: GM_NORMAL, KUDr@5636: GM_EDITOR KUDr@5636: }; KUDr@5636: rubidium@6247: void GameLoop(); KUDr@5636: rubidium@6247: void CreateConsole(); KUDr@5636: KUDr@5636: typedef int32 CursorID; KUDr@5636: rubidium@6248: struct Point { rubidium@7318: int x, y; rubidium@6248: }; KUDr@5636: rubidium@6248: struct Rect { KUDr@5636: int left,top,right,bottom; rubidium@6248: }; KUDr@5636: rubidium@6138: /** A single sprite of a list of animated cursors */ rubidium@6138: struct AnimCursor { rubidium@6146: static const CursorID LAST = MAX_UVALUE(CursorID); rubidium@6138: CursorID sprite; ///< Must be set to LAST_ANIM when it is the last sprite of the loop rubidium@6138: byte display_time; ///< Amount of ticks this sprite will be shown rubidium@6138: }; KUDr@5636: rubidium@6248: struct CursorVars { KUDr@5636: Point pos, size, offs, delta; ///< position, size, offset from top-left, and movement KUDr@5636: Point draw_pos, draw_size; ///< position and size bounding-box for drawing peter1138@5668: SpriteID sprite; ///< current image of cursor peter1138@5668: SpriteID pal; KUDr@5636: KUDr@5636: int wheel; ///< mouse wheel movement bjarni@6289: bjarni@6289: /* We need two different vars to keep track of how far the scrollwheel moved. bjarni@6289: * OSX uses this for scrolling around the map. */ bjarni@6289: int v_wheel; bjarni@6289: int h_wheel; bjarni@6289: rubidium@6138: const AnimCursor *animate_list; ///< in case of animated cursor, list of frames rubidium@6138: const AnimCursor *animate_cur; ///< in case of animated cursor, current frame rubidium@6138: uint animate_timeout; ///< in case of animated cursor, number of ticks to show the current cursor KUDr@5636: KUDr@5636: bool visible; ///< cursor is visible KUDr@5636: bool dirty; ///< the rect occupied by the mouse is dirty (redraw) KUDr@5636: bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling) KUDr@5636: bool in_window; ///< mouse inside this window, determines drawing logic rubidium@6248: }; KUDr@5636: rubidium@6248: struct DrawPixelInfo { truelight@6878: void *dst_ptr; KUDr@5636: int left, top, width, height; KUDr@5636: int pitch; truelight@6624: ZoomLevel zoom; rubidium@6248: }; KUDr@5636: rubidium@6248: struct Colour { KUDr@5636: byte r; KUDr@5636: byte g; KUDr@5636: byte b; rubidium@6248: }; KUDr@5636: KUDr@5636: KUDr@5636: belugas@6179: extern byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down KUDr@5636: extern bool _fullscreen; KUDr@5636: extern CursorVars _cursor; belugas@6179: extern bool _ctrl_pressed; ///< Is Ctrl pressed? belugas@6179: extern bool _shift_pressed; ///< Is Shift pressed? KUDr@5636: extern byte _fast_forward; KUDr@5636: KUDr@5636: extern bool _left_button_down; KUDr@5636: extern bool _left_button_clicked; KUDr@5636: extern bool _right_button_down; KUDr@5636: extern bool _right_button_clicked; KUDr@5636: KUDr@5636: extern DrawPixelInfo _screen; KUDr@5636: extern bool _exit_game; KUDr@5636: extern bool _networking; ///< are we in networking mode? KUDr@5636: extern byte _game_mode; truelight@6231: extern byte _pause_game; KUDr@5636: KUDr@5636: extern int _pal_first_dirty; truelight@6960: extern int _pal_count_dirty; KUDr@5636: extern int _num_resolutions; KUDr@5636: extern uint16 _resolutions[32][2]; KUDr@5636: extern uint16 _cur_resolution[2]; KUDr@5636: extern Colour _cur_palette[256]; KUDr@5636: KUDr@5636: void HandleKeypress(uint32 key); rubidium@6247: void HandleMouseEvents(); KUDr@5636: void CSleep(int milliseconds); rubidium@6247: void UpdateWindows(); KUDr@5636: rubidium@6247: uint32 InteractiveRandom(); //< Used for random sequences that are not the same on the other end of the multiplayer link KUDr@5636: uint InteractiveRandomRange(uint max); rubidium@7454: void DrawChatMessage(); rubidium@6247: void DrawMouseCursor(); rubidium@6247: void ScreenSizeChanged(); rubidium@6247: void HandleExitGameRequest(); rubidium@6247: void GameSizeChanged(); rubidium@6247: void UndrawMouseCursor(); KUDr@5636: rubidium@5587: #include "helpers.hpp" truelight@0: rubidium@6248: enum FontSize { peter1138@3798: FS_NORMAL, peter1138@3798: FS_SMALL, peter1138@3798: FS_LARGE, peter1138@3798: FS_END, rubidium@6248: }; peter1138@3798: rubidium@5587: DECLARE_POSTFIX_INCREMENT(FontSize); peter1138@3798: truelight@0: void RedrawScreenRect(int left, int top, int right, int bottom); truelight@0: void GfxScroll(int left, int top, int width, int height, int xo, int yo); Darkvater@2097: rubidium@7681: /** rubidium@7681: * Used to only draw a part of the sprite. rubidium@7681: * Draw the subsprite in the rect (sprite_x_offset + left, sprite_y_offset + top) to (sprite_x_offset + right, sprite_y_offset + bottom). rubidium@7681: * Both corners are included in the drawing area. rubidium@7681: */ rubidium@7681: struct SubSprite { rubidium@7681: int left, top, right, bottom; rubidium@7681: }; rubidium@7681: rubidium@7681: void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub = NULL); tron@2406: belugas@6179: /* XXX doesn't really belong here, but the only belugas@6179: * consumers always use it in conjunction with DoDrawString() */ peter1138@5108: #define UPARROW "\xEE\x8A\x80" peter1138@5108: #define DOWNARROW "\xEE\x8A\xAA" tron@2406: tron@2406: Darkvater@2097: int DrawStringCentered(int x, int y, StringID str, uint16 color); Darkvater@2113: int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color); Darkvater@2134: int DoDrawStringCentered(int x, int y, const char *str, uint16 color); Darkvater@2097: Darkvater@2097: int DrawString(int x, int y, StringID str, uint16 color); Darkvater@2097: int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw); Darkvater@2097: tron@1323: int DoDrawString(const char *string, int x, int y, uint16 color); Darkvater@2097: int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw); Darkvater@2097: Darkvater@2097: void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color); Darkvater@2113: void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color); Darkvater@2097: rubidium@4314: int DrawStringRightAligned(int x, int y, StringID str, uint16 color); Darkvater@2097: void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw); rubidium@4314: void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color); Darkvater@2097: truelight@193: void GfxFillRect(int left, int top, int right, int bottom, int color); truelight@193: void GfxDrawLine(int left, int top, int right, int bottom, int color); rubidium@7643: void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3); truelight@0: Darkvater@4609: BoundingRect GetStringBoundingBox(const char *str); Darkvater@4954: uint32 FormatStringLinebreaks(char *str, int maxw); rubidium@6247: void LoadStringWidthTable(); tron@2634: void DrawStringMultiCenter(int x, int y, StringID str, int maxw); maedhros@6377: uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh = -1); rubidium@7545: rubidium@7545: /** rubidium@7545: * Let the dirty blocks repainting by the video driver. rubidium@7545: * rubidium@7545: * @ingroup dirty rubidium@7545: */ rubidium@6247: void DrawDirtyBlocks(); rubidium@7545: rubidium@7545: /** rubidium@7545: * Set a new dirty block. rubidium@7545: * rubidium@7545: * @ingroup dirty rubidium@7545: */ truelight@0: void SetDirtyBlocks(int left, int top, int right, int bottom); rubidium@7545: rubidium@7545: /** rubidium@7545: * Marks the whole screen as dirty. rubidium@7545: * rubidium@7545: * @ingroup dirty rubidium@7545: */ rubidium@6247: void MarkWholeScreenDirty(); truelight@0: rubidium@6247: void GfxInitPalettes(); truelight@0: tron@4429: bool FillDrawPixelInfo(DrawPixelInfo* n, int left, int top, int width, int height); truelight@0: belugas@6179: /* window.cpp */ truelight@0: void DrawOverlappedWindowForAll(int left, int top, int right, int bottom); truelight@0: peter1138@5668: void SetMouseCursor(SpriteID sprite, SpriteID pal); rubidium@6138: void SetAnimatedMouseCursor(const AnimCursor *table); rubidium@6247: void CursorTick(); rubidium@6247: void DrawMouseCursor(); rubidium@6247: void ScreenSizeChanged(); rubidium@6247: void UndrawMouseCursor(); truelight@0: bool ChangeResInGame(int w, int h); Darkvater@1806: void SortResolutions(int count); bjarni@5941: void ToggleFullScreen(bool fs); truelight@0: belugas@6179: /* gfx.cpp */ Darkvater@1390: #define ASCII_LETTERSTART 32 peter1138@3798: extern FontSize _cur_fontsize; peter1138@3798: peter1138@5108: byte GetCharacterWidth(FontSize size, uint32 key); peter1138@3798: peter1138@3798: static inline byte GetCharacterHeight(FontSize size) peter1138@3798: { peter1138@3798: switch (size) { peter1138@3798: default: NOT_REACHED(); peter1138@3798: case FS_NORMAL: return 10; peter1138@3798: case FS_SMALL: return 6; peter1138@3798: case FS_LARGE: return 18; peter1138@3798: } Darkvater@1391: } truelight@0: truelight@0: VARDEF DrawPixelInfo *_cur_dpi; truelight@0: tron@4444: enum { tron@4444: COLOUR_DARK_BLUE, tron@4444: COLOUR_PALE_GREEN, tron@4444: COLOUR_PINK, tron@4444: COLOUR_YELLOW, tron@4444: COLOUR_RED, tron@4444: COLOUR_LIGHT_BLUE, tron@4444: COLOUR_GREEN, tron@4444: COLOUR_DARK_GREEN, tron@4444: COLOUR_BLUE, tron@4444: COLOUR_CREAM, tron@4444: COLOUR_MAUVE, tron@4444: COLOUR_PURPLE, tron@4444: COLOUR_ORANGE, tron@4444: COLOUR_BROWN, tron@4444: COLOUR_GREY, tron@4444: COLOUR_WHITE tron@4444: }; tron@4444: belugas@7824: /** Colour of the strings, see _string_colormap in table/palettes.h or docs/ottd-colourtext-palette.png */ belugas@7824: enum TextColour { belugas@7824: TC_FROMSTRING = 0x00, belugas@7824: TC_BLUE = 0x00, belugas@7824: TC_SILVER = 0x01, belugas@7824: TC_GOLD = 0x02, belugas@7824: TC_RED = 0x03, belugas@7824: TC_PURPLE = 0x04, belugas@7824: TC_LIGHT_BROWN = 0x05, belugas@7824: TC_ORANGE = 0x06, belugas@7824: TC_GREEN = 0x07, belugas@7824: TC_YELLOW = 0x08, belugas@7824: TC_DARK_GREEN = 0x09, belugas@7824: TC_CREAM = 0x0A, belugas@7824: TC_BROWN = 0x0B, belugas@7824: TC_WHITE = 0x0C, belugas@7824: TC_LIGHT_BLUE = 0x0D, belugas@7824: TC_GREY = 0x0E, belugas@7824: TC_DARK_BLUE = 0x0F, belugas@7824: TC_BLACK = 0x10, belugas@7824: }; belugas@7824: tron@4444: /** tron@4444: * All 16 colour gradients tron@4444: * 8 colours per gradient from darkest (0) to lightest (7) tron@4444: */ tron@4444: VARDEF byte _colour_gradient[16][8]; tron@4444: dominik@614: VARDEF bool _use_dos_palette; dominik@614: rubidium@6248: enum StringColorFlags { belugas@6179: IS_PALETTE_COLOR = 0x100, ///< color value is already a real palette color index, not an index of a StringColor rubidium@6248: }; dominik@657: Darkvater@2436: #endif /* GFX_H */