src/gfx.h
changeset 5475 2e6990a8c7c4
parent 5108 aeaef6fe53b7
child 5587 167d9a91ef02
equal deleted inserted replaced
5474:ac55aefc54f3 5475:2e6990a8c7c4
       
     1 /* $Id$ */
       
     2 
       
     3 #ifndef GFX_H
       
     4 #define GFX_H
       
     5 
       
     6 typedef byte Pixel;
       
     7 
       
     8 struct DrawPixelInfo {
       
     9 	Pixel *dst_ptr;
       
    10 	int left, top, width, height;
       
    11 	int pitch;
       
    12 	uint16 zoom;
       
    13 };
       
    14 
       
    15 
       
    16 typedef struct CursorVars {
       
    17 	Point pos, size, offs, delta; ///< position, size, offset from top-left, and movement
       
    18 	Point draw_pos, draw_size;    ///< position and size bounding-box for drawing
       
    19 	CursorID sprite; ///< current image of cursor
       
    20 
       
    21 	int wheel;       ///< mouse wheel movement
       
    22 	const CursorID *animate_list, *animate_cur; ///< in case of animated cursor, list of frames
       
    23 	uint animate_timeout;                       ///< current frame in list of animated cursor
       
    24 
       
    25 	bool visible;    ///< cursor is visible
       
    26 	bool dirty;      ///< the rect occupied by the mouse is dirty (redraw)
       
    27 	bool fix_at;     ///< mouse is moving, but cursor is not (used for scrolling)
       
    28 	bool in_window;  ///< mouse inside this window, determines drawing logic
       
    29 } CursorVars;
       
    30 
       
    31 
       
    32 typedef enum FontSizes {
       
    33 	FS_NORMAL,
       
    34 	FS_SMALL,
       
    35 	FS_LARGE,
       
    36 	FS_END,
       
    37 } FontSize;
       
    38 
       
    39 
       
    40 void RedrawScreenRect(int left, int top, int right, int bottom);
       
    41 void GfxScroll(int left, int top, int width, int height, int xo, int yo);
       
    42 
       
    43 
       
    44 // XXX doesn't really belong here, but the only
       
    45 // consumers always use it in conjunction with DoDrawString()
       
    46 #define UPARROW   "\xEE\x8A\x80"
       
    47 #define DOWNARROW "\xEE\x8A\xAA"
       
    48 
       
    49 
       
    50 int DrawStringCentered(int x, int y, StringID str, uint16 color);
       
    51 int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color);
       
    52 int DoDrawStringCentered(int x, int y, const char *str, uint16 color);
       
    53 
       
    54 int DrawString(int x, int y, StringID str, uint16 color);
       
    55 int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw);
       
    56 
       
    57 int DoDrawString(const char *string, int x, int y, uint16 color);
       
    58 int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw);
       
    59 
       
    60 void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color);
       
    61 void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color);
       
    62 
       
    63 int DrawStringRightAligned(int x, int y, StringID str, uint16 color);
       
    64 void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw);
       
    65 void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color);
       
    66 
       
    67 void GfxFillRect(int left, int top, int right, int bottom, int color);
       
    68 void GfxDrawLine(int left, int top, int right, int bottom, int color);
       
    69 
       
    70 BoundingRect GetStringBoundingBox(const char *str);
       
    71 uint32 FormatStringLinebreaks(char *str, int maxw);
       
    72 void LoadStringWidthTable(void);
       
    73 void DrawStringMultiCenter(int x, int y, StringID str, int maxw);
       
    74 uint DrawStringMultiLine(int x, int y, StringID str, int maxw);
       
    75 void DrawDirtyBlocks(void);
       
    76 void SetDirtyBlocks(int left, int top, int right, int bottom);
       
    77 void MarkWholeScreenDirty(void);
       
    78 
       
    79 void GfxInitPalettes(void);
       
    80 
       
    81 bool FillDrawPixelInfo(DrawPixelInfo* n, int left, int top, int width, int height);
       
    82 
       
    83 /* window.c */
       
    84 void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
       
    85 
       
    86 void SetMouseCursor(uint cursor);
       
    87 void SetAnimatedMouseCursor(const CursorID *table);
       
    88 void CursorTick(void);
       
    89 void DrawMouseCursor(void);
       
    90 void ScreenSizeChanged(void);
       
    91 void UndrawMouseCursor(void);
       
    92 bool ChangeResInGame(int w, int h);
       
    93 void SortResolutions(int count);
       
    94 void ToggleFullScreen(bool fs);
       
    95 
       
    96 /* gfx.c */
       
    97 #define ASCII_LETTERSTART 32
       
    98 extern FontSize _cur_fontsize;
       
    99 
       
   100 byte GetCharacterWidth(FontSize size, uint32 key);
       
   101 
       
   102 static inline byte GetCharacterHeight(FontSize size)
       
   103 {
       
   104 	switch (size) {
       
   105 		default: NOT_REACHED();
       
   106 		case FS_NORMAL: return 10;
       
   107 		case FS_SMALL:  return 6;
       
   108 		case FS_LARGE:  return 18;
       
   109 	}
       
   110 }
       
   111 
       
   112 VARDEF DrawPixelInfo _screen;
       
   113 VARDEF DrawPixelInfo *_cur_dpi;
       
   114 VARDEF CursorVars _cursor;
       
   115 
       
   116 enum {
       
   117 	COLOUR_DARK_BLUE,
       
   118 	COLOUR_PALE_GREEN,
       
   119 	COLOUR_PINK,
       
   120 	COLOUR_YELLOW,
       
   121 	COLOUR_RED,
       
   122 	COLOUR_LIGHT_BLUE,
       
   123 	COLOUR_GREEN,
       
   124 	COLOUR_DARK_GREEN,
       
   125 	COLOUR_BLUE,
       
   126 	COLOUR_CREAM,
       
   127 	COLOUR_MAUVE,
       
   128 	COLOUR_PURPLE,
       
   129 	COLOUR_ORANGE,
       
   130 	COLOUR_BROWN,
       
   131 	COLOUR_GREY,
       
   132 	COLOUR_WHITE
       
   133 };
       
   134 
       
   135 /**
       
   136  * All 16 colour gradients
       
   137  * 8 colours per gradient from darkest (0) to lightest (7)
       
   138  */
       
   139 VARDEF byte _colour_gradient[16][8];
       
   140 
       
   141 VARDEF int _pal_first_dirty;
       
   142 VARDEF int _pal_last_dirty;
       
   143 
       
   144 VARDEF bool _use_dos_palette;
       
   145 
       
   146 typedef struct Colour {
       
   147 	byte r;
       
   148 	byte g;
       
   149 	byte b;
       
   150 } Colour;
       
   151 
       
   152 extern Colour _cur_palette[256];
       
   153 
       
   154 
       
   155 typedef enum StringColorFlags {
       
   156 	IS_PALETTE_COLOR = 0x100, // color value is already a real palette color index, not an index of a StringColor
       
   157 } StringColorFlags;
       
   158 
       
   159 #ifdef _DEBUG
       
   160 extern bool _dbg_screen_rect;
       
   161 #endif
       
   162 
       
   163 #endif /* GFX_H */