tron@2186: /* $Id$ */ tron@2186: belugas@6505: /** @file gfx.h */ belugas@6505: truelight@0: #ifndef GFX_H truelight@0: #define GFX_H truelight@0: bjarni@6615: #include "openttd.h" truelight@7120: #include "zoom.hpp" KUDr@5887: KUDr@5887: enum WindowKeyCodes { KUDr@5887: WKC_SHIFT = 0x8000, KUDr@5887: WKC_CTRL = 0x4000, KUDr@5887: WKC_ALT = 0x2000, KUDr@5887: WKC_META = 0x1000, KUDr@5887: belugas@6505: /* Special ones */ KUDr@5887: WKC_NONE = 0, KUDr@5887: WKC_ESC = 1, KUDr@5887: WKC_BACKSPACE = 2, KUDr@5887: WKC_INSERT = 3, KUDr@5887: WKC_DELETE = 4, KUDr@5887: KUDr@5887: WKC_PAGEUP = 5, KUDr@5887: WKC_PAGEDOWN = 6, KUDr@5887: WKC_END = 7, KUDr@5887: WKC_HOME = 8, KUDr@5887: belugas@6505: /* Arrow keys */ KUDr@5887: WKC_LEFT = 9, KUDr@5887: WKC_UP = 10, KUDr@5887: WKC_RIGHT = 11, KUDr@5887: WKC_DOWN = 12, KUDr@5887: belugas@6505: /* Return & tab */ KUDr@5887: WKC_RETURN = 13, KUDr@5887: WKC_TAB = 14, KUDr@5887: belugas@6505: /* Numerical keyboard */ KUDr@5887: WKC_NUM_0 = 16, KUDr@5887: WKC_NUM_1 = 17, KUDr@5887: WKC_NUM_2 = 18, KUDr@5887: WKC_NUM_3 = 19, KUDr@5887: WKC_NUM_4 = 20, KUDr@5887: WKC_NUM_5 = 21, KUDr@5887: WKC_NUM_6 = 22, KUDr@5887: WKC_NUM_7 = 23, KUDr@5887: WKC_NUM_8 = 24, KUDr@5887: WKC_NUM_9 = 25, KUDr@5887: WKC_NUM_DIV = 26, KUDr@5887: WKC_NUM_MUL = 27, KUDr@5887: WKC_NUM_MINUS = 28, KUDr@5887: WKC_NUM_PLUS = 29, KUDr@5887: WKC_NUM_ENTER = 30, KUDr@5887: WKC_NUM_DECIMAL = 31, KUDr@5887: belugas@6505: /* Space */ KUDr@5887: WKC_SPACE = 32, KUDr@5887: belugas@6505: /* Function keys */ KUDr@5887: WKC_F1 = 33, KUDr@5887: WKC_F2 = 34, KUDr@5887: WKC_F3 = 35, KUDr@5887: WKC_F4 = 36, KUDr@5887: WKC_F5 = 37, KUDr@5887: WKC_F6 = 38, KUDr@5887: WKC_F7 = 39, KUDr@5887: WKC_F8 = 40, KUDr@5887: WKC_F9 = 41, KUDr@5887: WKC_F10 = 42, KUDr@5887: WKC_F11 = 43, KUDr@5887: WKC_F12 = 44, KUDr@5887: belugas@6505: /* backquote is the key left of "1" belugas@6505: * we only store this key here, no matter what character is really mapped to it belugas@6505: * on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °) */ KUDr@5887: WKC_BACKQUOTE = 45, KUDr@5887: WKC_PAUSE = 46, KUDr@5887: belugas@6505: /* 0-9 are mapped to 48-57 belugas@6505: * A-Z are mapped to 65-90 belugas@6505: * a-z are mapped to 97-122 */ KUDr@5887: }; KUDr@5887: KUDr@5887: enum GameModes { KUDr@5887: GM_MENU, KUDr@5887: GM_NORMAL, KUDr@5887: GM_EDITOR KUDr@5887: }; KUDr@5887: rubidium@6573: void GameLoop(); KUDr@5887: rubidium@6573: void CreateConsole(); KUDr@5887: KUDr@5887: typedef int32 CursorID; KUDr@5887: typedef byte Pixel; KUDr@5887: rubidium@6574: struct Point { KUDr@5887: int x,y; rubidium@6574: }; KUDr@5887: rubidium@6574: struct Rect { KUDr@5887: int left,top,right,bottom; rubidium@6574: }; KUDr@5887: rubidium@6464: /** A single sprite of a list of animated cursors */ rubidium@6464: struct AnimCursor { rubidium@6472: static const CursorID LAST = MAX_UVALUE(CursorID); rubidium@6464: CursorID sprite; ///< Must be set to LAST_ANIM when it is the last sprite of the loop rubidium@6464: byte display_time; ///< Amount of ticks this sprite will be shown rubidium@6464: }; KUDr@5887: rubidium@6574: struct CursorVars { KUDr@5887: Point pos, size, offs, delta; ///< position, size, offset from top-left, and movement KUDr@5887: Point draw_pos, draw_size; ///< position and size bounding-box for drawing peter1138@5919: SpriteID sprite; ///< current image of cursor peter1138@5919: SpriteID pal; KUDr@5887: KUDr@5887: int wheel; ///< mouse wheel movement bjarni@6615: bjarni@6615: /* We need two different vars to keep track of how far the scrollwheel moved. bjarni@6615: * OSX uses this for scrolling around the map. */ bjarni@6615: int v_wheel; bjarni@6615: int h_wheel; bjarni@6615: rubidium@6464: const AnimCursor *animate_list; ///< in case of animated cursor, list of frames rubidium@6464: const AnimCursor *animate_cur; ///< in case of animated cursor, current frame rubidium@6464: uint animate_timeout; ///< in case of animated cursor, number of ticks to show the current cursor KUDr@5887: KUDr@5887: bool visible; ///< cursor is visible KUDr@5887: bool dirty; ///< the rect occupied by the mouse is dirty (redraw) KUDr@5887: bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling) KUDr@5887: bool in_window; ///< mouse inside this window, determines drawing logic rubidium@6574: }; KUDr@5887: rubidium@6574: struct DrawPixelInfo { KUDr@5887: Pixel *dst_ptr; KUDr@5887: int left, top, width, height; KUDr@5887: int pitch; truelight@7120: ZoomLevel zoom; rubidium@6574: }; KUDr@5887: rubidium@6574: struct Colour { KUDr@5887: byte r; KUDr@5887: byte g; KUDr@5887: byte b; rubidium@6574: }; KUDr@5887: KUDr@5887: KUDr@5887: belugas@6505: extern byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down KUDr@5887: extern bool _fullscreen; KUDr@5887: extern CursorVars _cursor; belugas@6505: extern bool _ctrl_pressed; ///< Is Ctrl pressed? belugas@6505: extern bool _shift_pressed; ///< Is Shift pressed? KUDr@5887: extern byte _fast_forward; KUDr@5887: KUDr@5887: extern bool _left_button_down; KUDr@5887: extern bool _left_button_clicked; KUDr@5887: extern bool _right_button_down; KUDr@5887: extern bool _right_button_clicked; KUDr@5887: KUDr@5887: extern DrawPixelInfo _screen; KUDr@5887: extern bool _exit_game; KUDr@5887: extern bool _networking; ///< are we in networking mode? KUDr@5887: extern byte _game_mode; truelight@6557: extern byte _pause_game; KUDr@5887: KUDr@5887: extern int _pal_first_dirty; KUDr@5887: extern int _pal_last_dirty; KUDr@5887: extern int _num_resolutions; KUDr@5887: extern uint16 _resolutions[32][2]; KUDr@5887: extern uint16 _cur_resolution[2]; KUDr@5887: extern Colour _cur_palette[256]; KUDr@5887: KUDr@5887: void HandleKeypress(uint32 key); rubidium@6573: void HandleMouseEvents(); KUDr@5887: void CSleep(int milliseconds); rubidium@6573: void UpdateWindows(); KUDr@5887: rubidium@6573: uint32 InteractiveRandom(); //< Used for random sequences that are not the same on the other end of the multiplayer link KUDr@5887: uint InteractiveRandomRange(uint max); rubidium@6573: void DrawTextMessage(); rubidium@6573: void DrawMouseCursor(); rubidium@6573: void ScreenSizeChanged(); rubidium@6573: void HandleExitGameRequest(); rubidium@6573: void GameSizeChanged(); rubidium@6573: void UndrawMouseCursor(); KUDr@5887: rubidium@5838: #include "helpers.hpp" truelight@0: rubidium@6574: enum FontSize { peter1138@3798: FS_NORMAL, peter1138@3798: FS_SMALL, peter1138@3798: FS_LARGE, peter1138@3798: FS_END, rubidium@6574: }; peter1138@3798: rubidium@5838: 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: tron@2406: belugas@6505: /* XXX doesn't really belong here, but the only belugas@6505: * 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); truelight@0: Darkvater@4609: BoundingRect GetStringBoundingBox(const char *str); Darkvater@4954: uint32 FormatStringLinebreaks(char *str, int maxw); rubidium@6573: void LoadStringWidthTable(); tron@2634: void DrawStringMultiCenter(int x, int y, StringID str, int maxw); maedhros@6703: uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh = -1); rubidium@6573: void DrawDirtyBlocks(); truelight@0: void SetDirtyBlocks(int left, int top, int right, int bottom); rubidium@6573: void MarkWholeScreenDirty(); truelight@0: rubidium@6573: void GfxInitPalettes(); truelight@0: tron@4429: bool FillDrawPixelInfo(DrawPixelInfo* n, int left, int top, int width, int height); truelight@0: belugas@6505: /* window.cpp */ truelight@0: void DrawOverlappedWindowForAll(int left, int top, int right, int bottom); truelight@0: rubidium@5838: void SetMouseCursor(CursorID cursor); peter1138@5919: void SetMouseCursor(SpriteID sprite, SpriteID pal); rubidium@6464: void SetAnimatedMouseCursor(const AnimCursor *table); rubidium@6573: void CursorTick(); rubidium@6573: void DrawMouseCursor(); rubidium@6573: void ScreenSizeChanged(); rubidium@6573: void UndrawMouseCursor(); truelight@0: bool ChangeResInGame(int w, int h); Darkvater@1806: void SortResolutions(int count); bjarni@6192: void ToggleFullScreen(bool fs); truelight@0: belugas@6505: /* 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: 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@6574: enum StringColorFlags { belugas@6505: IS_PALETTE_COLOR = 0x100, ///< color value is already a real palette color index, not an index of a StringColor rubidium@6574: }; dominik@657: KUDr@5887: tron@2649: #ifdef _DEBUG tron@2649: extern bool _dbg_screen_rect; tron@2649: #endif tron@2649: Darkvater@2436: #endif /* GFX_H */