22 #ifndef QDENGINE_SYSTEM_GRAPHICS_GR_DISPATCHER_H 23 #define QDENGINE_SYSTEM_GRAPHICS_GR_DISPATCHER_H 25 #include "common/std/vector.h" 26 #include "qdengine/xmath.h" 27 #include "qdengine/system/graphics/gr_screen_region.h" 44 const int GR_BLACK_FON = 0x01;
45 const int GR_CLIPPED = 0x02;
46 const int GR_NOCLIP = 0x04;
47 const int GR_FLIP_HORIZONTAL = 0x08;
48 const int GR_FLIP_VERTICAL = 0x10;
49 const int GR_IGNORE_ALPHA = 0x20;
52 const int GR_FILLED = 0x00;
53 const int GR_OUTLINED = 0x01;
56 const int GR_INITED = 0x01;
57 const int GR_PALETTE = 0x02;
58 const int GR_REINIT = 0x04;
60 #ifdef _GR_ENABLE_ZBUFFER 62 const GR_ZBUFFFER_MASK = 0xFFFF;
63 const GR_ZBUFFER_MAX_Z = 30000;
90 static bool sys_init();
92 bool init(
int sx,
int sy, grPixelFormat pixel_format);
94 void toggle_reinit() {
97 bool is_in_reinit_mode()
const {
98 return _flags & GR_REINIT;
101 void set_flag(
int fl) {
104 void drop_flag(
int fl) {
107 bool check_flag(
int fl) {
108 if (_flags & fl)
return true;
114 void *Get_hWnd()
const {
117 int get_SizeX()
const {
120 int get_SizeY()
const {
124 void setClipMode(
int m) {
127 int getClipMode()
const {
132 setClip(0, 0, _sizeX, _sizeY);
135 void getClip(
int &l,
int &t,
int &r,
int &b)
const {
136 l = _clipCoords[GR_LEFT];
137 t = _clipCoords[GR_TOP];
138 r = _clipCoords[GR_RIGHT];
139 b = _clipCoords[GR_BOTTOM];
142 void setClip(
int l,
int t,
int r,
int b) {
144 if (r > _sizeX) r = _sizeX;
147 if (b > _sizeY) b = _sizeY;
149 _clipCoords[GR_LEFT] = l;
150 _clipCoords[GR_TOP] = t;
151 _clipCoords[GR_RIGHT] = r;
152 _clipCoords[GR_BOTTOM] = b;
155 void limitClip(
int l,
int t,
int r,
int b) {
156 if (_clipCoords[GR_LEFT] < l) _clipCoords[GR_LEFT] = l;
157 if (_clipCoords[GR_TOP] < t) _clipCoords[GR_TOP] = t;
158 if (_clipCoords[GR_RIGHT] > r) _clipCoords[GR_RIGHT] = r;
159 if (_clipCoords[GR_BOTTOM] > b) _clipCoords[GR_BOTTOM] = b;
162 int clipCheck(
int x,
int y) {
163 if (x >= _clipCoords[GR_LEFT] && x < _clipCoords[GR_RIGHT] && y >= _clipCoords[GR_TOP] && y < _clipCoords[GR_BOTTOM])
169 int clipCheck(
int x,
int y,
int sx,
int sy) {
170 if (x - sx >= _clipCoords[GR_LEFT] && x + sx < _clipCoords[GR_RIGHT] && y - sy >= _clipCoords[GR_TOP] && y + sy < _clipCoords[GR_BOTTOM])
177 bool flush(
int x,
int y,
int sx,
int sy);
183 void putSpr(
int x,
int y,
int sx,
int sy,
const byte *p,
int mode,
int spriteFormat);
184 void putSpr(
int x,
int y,
int sx,
int sy,
const byte *p,
int mode,
int spriteFormat,
float scale);
185 void putSpr_rle(
int x,
int y,
int sx,
int sy,
const RLEBuffer *p,
int mode,
bool alpha_flag);
186 void putSpr_rle(
int x,
int y,
int sx,
int sy,
const RLEBuffer *p,
int mode,
float scale,
bool alpha_flag);
187 void putSpr_a(
int x,
int y,
int sx,
int sy,
const byte *p,
int mode);
188 void putSpr_a(
int x,
int y,
int sx,
int sy,
const byte *p,
int mode,
float scale);
190 void putSpr_rot(
const Vect2i &pos,
const Vect2i &size,
const byte *data,
bool has_alpha,
int mode,
float angle);
191 void putSpr_rot(
const Vect2i &pos,
const Vect2i &size,
const byte *data,
bool has_alpha,
int mode,
float angle,
const Vect2f &scale);
192 void putSpr_rle_rot(
const Vect2i &pos,
const Vect2i &size,
const RLEBuffer *data,
bool has_alpha,
int mode,
float angle);
193 void putSpr_rle_rot(
const Vect2i &pos,
const Vect2i &size,
const RLEBuffer *data,
bool has_alpha,
int mode,
float angle,
const Vect2f &scale);
195 void putSprMask_rot(
const Vect2i &pos,
const Vect2i &size,
const byte *data,
bool has_alpha, uint32 mask_color,
int mask_alpha,
int mode,
float angle);
196 void putSprMask_rot(
const Vect2i &pos,
const Vect2i &size,
const byte *data,
bool has_alpha, uint32 mask_color,
int mask_alpha,
int mode,
float angle,
const Vect2f &scale);
197 void putSprMask_rle_rot(
const Vect2i &pos,
const Vect2i &size,
const RLEBuffer *data,
bool has_alpha, uint32 mask_color,
int mask_alpha,
int mode,
float angle);
198 void putSprMask_rle_rot(
const Vect2i &pos,
const Vect2i &size,
const RLEBuffer *data,
bool has_alpha, uint32 mask_color,
int mask_alpha,
int mode,
float angle,
const Vect2f &scale);
200 void putSprMask(
int x,
int y,
int sx,
int sy,
const byte *p, uint32 mask_color,
int mask_alpha,
int mode);
201 void putSprMask(
int x,
int y,
int sx,
int sy,
const byte *p, uint32 mask_color,
int mask_alpha,
int mode,
float scale);
202 void putSprMask_rle(
int x,
int y,
int sx,
int sy,
const RLEBuffer *p, uint32 mask_color,
int mask_alpha,
int mode,
bool alpha_flag);
203 void putSprMask_rle(
int x,
int y,
int sx,
int sy,
const RLEBuffer *p, uint32 mask_color,
int mask_alpha,
int mode,
float scale,
bool alpha_flag);
204 void putSprMask_a(
int x,
int y,
int sx,
int sy,
const byte *p, uint32 mask_color,
int mask_alpha,
int mode);
205 void putSprMask_a(
int x,
int y,
int sx,
int sy,
const byte *p, uint32 mask_color,
int mask_alpha,
int mode,
float scale);
209 void putChar(
int x,
int y, uint32 color,
int font_sx,
int font_sy,
const byte *font_alpha,
const grScreenRegion &char_region);
211 void drawSprContour_a(
int x,
int y,
int sx,
int sy,
const byte *p,
int contour_color,
int mode);
212 void drawSprContour_a(
int x,
int y,
int sx,
int sy,
const byte *p,
int contour_color,
int mode,
float scale);
213 void drawSprContour(
int x,
int y,
int sx,
int sy,
const byte *p,
int contour_color,
int mode);
214 void drawSprContour(
int x,
int y,
int sx,
int sy,
const byte *p,
int contour_color,
int mode,
float scale);
215 void drawSprContour(
int x,
int y,
int sx,
int sy,
const RLEBuffer *p,
int contour_color,
int mode,
bool alpha_flag);
216 void drawSprContour(
int x,
int y,
int sx,
int sy,
const RLEBuffer *p,
int contour_color,
int mode,
float scale,
bool alpha_flag);
218 bool drawText(
int x,
int y, uint32 color,
const char *str,
int hspace = 0,
int vspace = 0,
const grFont *font = NULL);
219 bool drawAlignedText(
int x,
int y,
int sx,
int sy, uint32 color,
const char *str, grTextAlign align = GR_ALIGN_LEFT,
int hspace = 0,
int vspace = 0,
const grFont *font = NULL);
220 bool drawParsedText(
int x,
int y,
int sx,
int sy, uint32 color,
const UI_TextParser *parser, grTextAlign align = GR_ALIGN_LEFT,
const grFont *font = NULL);
221 int textWidth(
const char *str,
int hspace = 0,
const grFont *font = NULL,
bool first_string_only =
false)
const;
222 int textHeight(
const char *str,
int vspace = 0,
const grFont *font = NULL)
const;
224 #ifdef _GR_ENABLE_ZBUFFER 225 void putSpr_z(
int x,
int y,
int z,
int sx,
int sy,
const byte *p,
int mode);
226 void putSpr_z(
int x,
int y,
int z,
int sx,
int sy,
const byte *p,
int mode,
float scale);
227 void putSpr_rle_z(
int x,
int y,
int z,
int sx,
int sy,
const RLEBuffer *p,
int mode,
bool alpha_flag);
228 void putSpr_rle_z(
int x,
int y,
int z,
int sx,
int sy,
const RLEBuffer *p,
int mode,
float scale,
bool alpha_flag);
229 void putSpr_a_z(
int x,
int y,
int z,
int sx,
int sy,
const byte *p,
int mode);
230 void putSpr_a_z(
int x,
int y,
int z,
int sx,
int sy,
const byte *p,
int mode,
float scale);
233 void erase(
int x,
int y,
int sx,
int sy,
int col);
234 void erase(
int x,
int y,
int sx,
int sy,
int r,
int g,
int b);
236 void setPixel(
int x,
int y,
int col);
237 void setPixelFast(byte *buf, uint32 col);
238 void setPixelFast(
int x,
int y,
int col);
239 void setPixelFast(
int x,
int y,
int r,
int g,
int b);
241 void setPixel(
int x,
int y,
int r,
int g,
int b);
244 void resetSurfaceOverride();
246 void getPixel(
int x,
int y, uint32 &col);
247 void getPixel(
int x,
int y, uint16 &col);
248 void getPixel(
int x,
int y, byte &r, byte &g, byte &b);
250 void line(
int x1,
int y1,
int x2,
int y2,
int col,
int line_style = 0,
bool inverse_col =
false);
252 #ifdef _GR_ENABLE_ZBUFFER 253 void line_z(
int x1,
int y1,
int z1,
int x2,
int y2,
int z2,
int col,
int line_style = 0);
256 void lineTo(
int x,
int y,
int len,
int dir,
int col,
int line_style = 0);
257 void rectangle(
int x,
int y,
int sx,
int sy,
int outcol,
int incol,
int mode,
int line_style = 0);
258 void rectangleAlpha(
int x,
int y,
int sx,
int sy, uint32 color,
int alpha);
260 int PalettedMode()
const {
261 return (_flags & GR_PALETTE);
264 grPixelFormat pixel_format()
const {
265 return _pixel_format;
267 void set_pixel_format(grPixelFormat mode) {
268 _pixel_format = GR_RGB565;
271 inline int bytes_per_pixel()
const {
272 switch (_pixel_format) {
287 mask_565_r = 0xFFFF & (0x001F << 11),
288 mask_565_g = 0xFFFF & (0x003F << 5),
289 mask_565_b = 0xFFFF & (0x001F << 0),
291 mask_555_r = 0xFFFF & (0x001F << 10),
292 mask_555_g = 0xFFFF & (0x001F << 5),
293 mask_555_b = 0xFFFF & (0x001F << 0)
296 inline uint32 make_rgb(uint32 color)
const {
297 switch (_pixel_format) {
299 return make_rgb565u((color >> 0) & 0xFF, (color >> 8) & 0xFF, (color >> 16) & 0xFF);
301 return make_rgb555u((color >> 0) & 0xFF, (color >> 8) & 0xFF, (color >> 16) & 0xFF);
311 inline uint32 make_rgb(uint32 r, uint32 g, uint32 b)
const {
312 switch (_pixel_format) {
314 return make_rgb565u(r, g, b);
316 return make_rgb555u(r, g, b);
319 return ((b << 16) | (g << 8) | r);
321 return ((r << 16) | (g << 8) | b);
329 typedef bool (*char_input_hanler_t)(
int input);
330 static char_input_hanler_t set_input_handler(char_input_hanler_t h) {
331 char_input_hanler_t old_h = _input_handler;
336 static bool handle_char_input(
int input) {
337 if (_input_handler)
return (*_input_handler)(input);
341 static inline uint32 make_rgb888(uint32 r, uint32 g, uint32 b) {
342 return ((b << 16) | (g << 8) | r);
345 static inline uint16 make_rgb565u(uint32 r, uint32 g, uint32 b) {
346 return (((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0));
348 static inline uint16 make_rgb555u(uint32 r, uint32 g, uint32 b) {
349 return (((r >> 3) << 10) | ((g >> 3) << 5) | ((b >> 3) << 0));
352 static inline void split_rgb565u(uint32 col, byte &r, byte &g, byte &b) {
353 r = ((col & mask_565_r) >> 11) << 3;
354 g = ((col & mask_565_g) >> 5) << 2;
355 b = ((col & mask_565_b) >> 0) << 3;
357 static inline void split_rgb555u(uint32 col, byte &r, byte &g, byte &b) {
358 r = ((col & mask_555_r) >> 10) << 3;
359 g = ((col & mask_555_g) >> 5) << 3;
360 b = ((col & mask_555_b) >> 0) << 3;
363 static inline void split_rgb888(uint32 col, byte &r, byte &g, byte &b) {
364 r = (col >> 0) & 0xFF;
365 g = (col >> 8) & 0xFF;
366 b = (col >> 16) & 0xFF;
369 static inline uint16 make_rgb565(uint32 r, uint32 g, uint32 b) {
370 return ((r << 11) | (g << 5) | (b << 0));
372 static inline uint16 make_rgb555(uint32 r, uint32 g, uint32 b) {
373 return ((r << 10) | (g << 5) | (b << 0));
376 static inline uint16 alpha_blend_565(uint16 pic_col, uint16 scr_col, uint32 a) {
379 return pic_col + (((((scr_col & mask_565_r) * a) >> 8) & mask_565_r) |
380 ((((scr_col & mask_565_g) * a) >> 8) & mask_565_g) |
381 ((((scr_col & mask_565_b) * a) >> 8) & mask_565_b));
388 static inline uint16 alpha_blend_555(uint16 pic_col, uint16 scr_col, uint32 a) {
391 return pic_col + (((((scr_col & mask_555_r) * a) >> 8) & mask_555_r) |
392 ((((scr_col & mask_555_g) * a) >> 8) & mask_555_g) |
393 ((((scr_col & mask_555_b) * a) >> 8) & mask_555_b));
400 const void *mouse_cursor()
const {
401 return _mouse_cursor;
403 void set_default_mouse_cursor() {
404 _mouse_cursor = _default_mouse_cursor;
406 void set_null_mouse_cursor() {
407 _mouse_cursor = NULL;
412 bool is_mouse_hidden()
const {
422 bool clip_line(
int &x0,
int &y0,
int &x1,
int &y1)
const;
423 bool clip_line(
int &x0,
int &y0,
int &z0,
int &x1,
int &y1,
int &z1)
const;
424 bool clip_rectangle(
int &x,
int &y,
int &pic_x,
int &pic_y,
int &pic_sx,
int &pic_sy)
const;
426 bool is_rectangle_visible(
int x,
int y,
int sx,
int sy)
const {
427 if (x + sx < 0 || x >= _sizeX || y + sy < 0 || y >= _sizeY)
return false;
431 bool clip_rectangle(
int &x,
int &y,
int &sx,
int &sy)
const {
435 if (x < _clipCoords[0]) x = _clipCoords[0];
436 if (x1 >= _clipCoords[2]) x1 = _clipCoords[2] - 1;
438 if (y < _clipCoords[1]) y = _clipCoords[1];
439 if (y1 >= _clipCoords[3]) y1 = _clipCoords[3] - 1;
444 if (sx <= 0 || sy <= 0)
450 void clear_changes_mask();
453 typedef regions_container_t::const_iterator region_iterator;
455 const regions_container_t &changed_regions()
const {
456 return _changed_regions;
458 void build_changed_regions();
462 return _dispatcher_ptr;
470 static inline const char *wnd_class_name() {
471 return _wnd_class_name;
474 typedef void (*restore_handler_t)();
475 static restore_handler_t set_restore_handler(restore_handler_t h) {
476 restore_handler_t old_h = _restore_handler;
477 _restore_handler = h;
481 static bool is_active() {
484 static void activate(
bool state) {
485 if (state && !_is_active) {
486 if (_restore_handler)
487 (*_restore_handler)();
492 char *temp_buffer(
int size);
494 static bool convert_sprite(grPixelFormat src_fmt, grPixelFormat &dest_fmt,
int sx,
int sy, byte *data,
bool &has_alpha);
496 static grFont *load_font(
const char *file_name);
497 static void set_default_font(
grFont *p) {
500 static grFont *get_default_font() {
501 return _default_font;
515 grPixelFormat _pixel_format;
522 int _temp_buffer_size;
531 static void *_default_mouse_cursor;
540 inline int clip_out_code(
int x,
int y)
const {
542 if (y >= _clipCoords[3])
544 else if (y < _clipCoords[1])
546 if (x >= _clipCoords[2])
548 else if (x < _clipCoords[0])
554 #ifdef _GR_ENABLE_ZBUFFER 557 bool alloc_zbuffer(
int sx,
int sy);
559 bool clear_zbuffer();
561 zbuf_t get_z(
int x,
int y) {
562 return zbuffer_[x + y * _sizeX];
564 void put_z(
int x,
int y,
int z) {
565 zbuffer_[x + y * _sizeX] = z;
572 kChangesMaskTile = 16,
573 kChangesMaskTileShift = 4
576 int _changes_mask_size_x;
577 int _changes_mask_size_y;
579 changes_mask_t _changes_mask;
581 regions_container_t _changed_regions;
583 static char_input_hanler_t _input_handler;
585 static grFont *_default_font;
587 static bool _is_active;
588 static restore_handler_t _restore_handler;
591 static char *_wnd_class_name;
593 void putSpr_rot90(
const Vect2i &pos,
const Vect2i &size,
const byte *data,
bool has_alpha,
int mode,
float angle);
598 #endif // QDENGINE_SYSTEM_GRAPHICS_GR_DISPATCHER_H Definition: managed_surface.h:51
Definition: gr_dispatcher.h:85
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Массив, сжатый методом RLE.
Definition: rle_compress.h:29
Базовый класс для игровых ресурсов.
Definition: console.h:28
Definition: formatinfo.h:28
Definition: UI_TextParser.h:55
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168
Прямоугольная область на экране.
Definition: gr_screen_region.h:31
Тайл-спрайт
Definition: gr_tile_sprite.h:44