tron@2186: /* $Id$ */ tron@2186: truelight@0: #ifndef GFX_H truelight@0: #define GFX_H truelight@0: 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: KUDr@5887: // 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: KUDr@5887: // Arrow keys KUDr@5887: WKC_LEFT = 9, KUDr@5887: WKC_UP = 10, KUDr@5887: WKC_RIGHT = 11, KUDr@5887: WKC_DOWN = 12, KUDr@5887: KUDr@5887: // Return & tab KUDr@5887: WKC_RETURN = 13, KUDr@5887: WKC_TAB = 14, KUDr@5887: KUDr@5887: // 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: KUDr@5887: // Space KUDr@5887: WKC_SPACE = 32, KUDr@5887: KUDr@5887: // 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: KUDr@5887: // backquote is the key left of "1" KUDr@5887: // we only store this key here, no matter what character is really mapped to it KUDr@5887: // on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °) KUDr@5887: WKC_BACKQUOTE = 45, KUDr@5887: WKC_PAUSE = 46, KUDr@5887: KUDr@5887: // 0-9 are mapped to 48-57 KUDr@5887: // A-Z are mapped to 65-90 KUDr@5887: // 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: KUDr@5887: void GameLoop(void); KUDr@5887: KUDr@5887: void CreateConsole(void); KUDr@5887: KUDr@5887: typedef int32 CursorID; KUDr@5887: typedef byte Pixel; KUDr@5887: KUDr@5887: typedef struct Point { KUDr@5887: int x,y; KUDr@5887: } Point; KUDr@5887: KUDr@5887: typedef struct Rect { KUDr@5887: int left,top,right,bottom; KUDr@5887: } Rect; 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: KUDr@5887: typedef 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 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 KUDr@5887: } CursorVars; KUDr@5887: KUDr@5887: typedef struct DrawPixelInfo { KUDr@5887: Pixel *dst_ptr; KUDr@5887: int left, top, width, height; KUDr@5887: int pitch; KUDr@5887: uint16 zoom; KUDr@5887: } DrawPixelInfo; KUDr@5887: KUDr@5887: typedef struct Colour { KUDr@5887: byte r; KUDr@5887: byte g; KUDr@5887: byte b; KUDr@5887: } Colour; KUDr@5887: KUDr@5887: KUDr@5887: KUDr@5887: extern byte _dirkeys; // 1 = left, 2 = up, 4 = right, 8 = down KUDr@5887: extern bool _fullscreen; KUDr@5887: extern CursorVars _cursor; KUDr@5887: extern bool _ctrl_pressed; // Is Ctrl pressed? KUDr@5887: 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; KUDr@5887: extern byte _pause; 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); KUDr@5887: void HandleMouseEvents(void); KUDr@5887: void CSleep(int milliseconds); KUDr@5887: void UpdateWindows(void); KUDr@5887: KUDr@5887: uint32 InteractiveRandom(void); /* Used for random sequences that are not the same on the other end of the multiplayer link */ KUDr@5887: uint InteractiveRandomRange(uint max); KUDr@5887: void DrawTextMessage(void); KUDr@5887: void DrawMouseCursor(void); KUDr@5887: void ScreenSizeChanged(void); KUDr@5887: void HandleExitGameRequest(void); KUDr@5887: void GameSizeChanged(void); KUDr@5887: void UndrawMouseCursor(void); KUDr@5887: rubidium@5838: #include "helpers.hpp" truelight@0: peter1138@3798: typedef enum FontSizes { peter1138@3798: FS_NORMAL, peter1138@3798: FS_SMALL, peter1138@3798: FS_LARGE, peter1138@3798: FS_END, peter1138@3798: } FontSize; 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: tron@2406: // XXX doesn't really belong here, but the only tron@2406: // 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); tron@1093: void LoadStringWidthTable(void); tron@2634: void DrawStringMultiCenter(int x, int y, StringID str, int maxw); peter1138@4928: uint DrawStringMultiLine(int x, int y, StringID str, int maxw); tron@1093: void DrawDirtyBlocks(void); truelight@0: void SetDirtyBlocks(int left, int top, int right, int bottom); tron@1093: void MarkWholeScreenDirty(void); truelight@0: tron@1093: void GfxInitPalettes(void); truelight@0: tron@4429: bool FillDrawPixelInfo(DrawPixelInfo* n, int left, int top, int width, int height); truelight@0: truelight@0: /* window.c */ 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); tron@1093: void CursorTick(void); tron@1093: void DrawMouseCursor(void); tron@1093: void ScreenSizeChanged(void); tron@1093: void UndrawMouseCursor(void); truelight@0: bool ChangeResInGame(int w, int h); Darkvater@1806: void SortResolutions(int count); bjarni@6192: void ToggleFullScreen(bool fs); truelight@0: truelight@0: /* gfx.c */ 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: dominik@657: typedef enum StringColorFlags { dominik@657: IS_PALETTE_COLOR = 0x100, // color value is already a real palette color index, not an index of a StringColor dominik@657: } StringColorFlags; 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 */