Go to the documentation of this file.
45 std::atomic<bool> _exit_game;
77 static const byte *_colour_remap_ptr;
80 static const uint DIRTY_BLOCK_HEIGHT = 8;
81 static const uint DIRTY_BLOCK_WIDTH = 64;
83 static uint _dirty_bytes_per_line = 0;
84 static byte *_dirty_blocks =
nullptr;
85 extern uint _dirty_block_colour;
87 void GfxScroll(
int left,
int top,
int width,
int height,
int xo,
int yo)
91 if (xo == 0 && yo == 0)
return;
93 if (_cursor.
visible) UndrawMouseCursor();
97 blitter->
ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo);
122 const int otop = top;
123 const int oleft = left;
126 if (left > right || top > bottom)
return;
127 if (right < dpi->left || left >= dpi->left + dpi->width)
return;
128 if (bottom < dpi->top || top >= dpi->top + dpi->height)
return;
130 if ( (left -= dpi->left) < 0) left = 0;
131 right = right - dpi->left + 1;
132 if (right > dpi->width) right = dpi->width;
136 if ( (top -= dpi->top) < 0) top = 0;
137 bottom = bottom - dpi->top + 1;
138 if (bottom > dpi->height) bottom = dpi->height;
142 dst = blitter->
MoveTo(dpi->dst_ptr, left, top);
146 blitter->
DrawRect(dst, right, bottom, (uint8)colour);
154 byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
156 for (
int i = (bo ^= 1); i < right; i += 2) blitter->
SetPixel(dst, i, 0, (uint8)colour);
157 dst = blitter->
MoveTo(dst, 0, 1);
158 }
while (--bottom > 0);
164 typedef std::pair<Point, Point> LineSegment;
176 std::vector<LineSegment> segments;
177 if (shape.size() < 3)
return segments;
178 segments.reserve(shape.size());
181 Point prev = shape.back();
184 for (
Point pt : shape) {
190 segments.emplace_back(pt, prev);
191 }
else if (prev.y < pt.y) {
192 segments.emplace_back(prev, pt);
222 segments.erase(std::remove_if(segments.begin(), segments.end(), [dpi](
const LineSegment &s) { return s.second.y <= 0 || s.first.y >= dpi->height; }), segments.end());
225 if (segments.empty())
return;
228 std::sort(segments.begin(), segments.end(), [](
const LineSegment &a,
const LineSegment &b) { return a.first.y < b.first.y; });
231 std::vector<LineSegment> active;
234 std::vector<int> intersections;
237 intersections.reserve(4);
240 int y = segments.front().first.y;
241 std::vector<LineSegment>::iterator nextseg = segments.begin();
242 while (!active.empty() || nextseg != segments.end()) {
244 active.erase(std::remove_if(active.begin(), active.end(), [y](
const LineSegment &s) { return s.second.y == y; }), active.end());
247 while (nextseg != segments.end() && nextseg->first.y == y) {
248 active.push_back(*nextseg);
257 if (y >= dpi->height)
return;
260 intersections.clear();
261 for (
const LineSegment &s : active) {
262 const int sdx = s.second.x - s.first.x;
263 const int sdy = s.second.y - s.first.y;
264 const int ldy = y - s.first.y;
265 const int x = s.first.x + sdx * ldy / sdy;
266 intersections.push_back(x);
270 std::sort(intersections.begin(), intersections.end());
271 for (
size_t i = 1; i < intersections.size(); i += 2) {
273 const int x1 = std::max(0, intersections[i - 1]);
274 const int x2 = std::min(intersections[i], dpi->width);
275 if (x2 < 0)
continue;
276 if (x1 >= dpi->width)
continue;
279 void *dst = blitter->
MoveTo(dpi->dst_ptr, x1, y);
282 blitter->
DrawRect(dst, x2 - x1, 1, (uint8)colour);
290 for (
int x = (x1 + y) & 1; x < x2 - x1; x += 2) {
291 blitter->
SetPixel(dst, x, 0, (uint8)colour);
316 static inline void GfxDoDrawLine(
void *video,
int x,
int y,
int x2,
int y2,
int screen_width,
int screen_height, uint8 colour,
int width,
int dash = 0)
322 if (y2 == y || x2 == x) {
324 blitter->
DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width, dash);
328 int grade_y = y2 - y;
329 int grade_x = x2 - x;
332 int extra = (int)
CeilDiv(3 * width, 4);
333 Rect clip = { -extra, -extra, screen_width - 1 + extra, screen_height - 1 + extra };
337 while (INT_MAX /
abs(grade_y) < std::max(
abs(clip.left - x),
abs(clip.right - x))) {
347 int left_isec_y = y + (clip.left - x) * grade_y / grade_x;
348 int right_isec_y = y + (clip.right - x) * grade_y / grade_x;
349 if ((left_isec_y > clip.bottom + margin && right_isec_y > clip.bottom + margin) ||
350 (left_isec_y < clip.top - margin && right_isec_y < clip.top - margin)) {
360 blitter->
DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width, dash);
382 if (x + width / 2 < 0 && x2 + width / 2 < 0 )
return false;
383 if (y + width / 2 < 0 && y2 + width / 2 < 0 )
return false;
384 if (x - width / 2 > dpi->width && x2 - width / 2 > dpi->width )
return false;
385 if (y - width / 2 > dpi->height && y2 - width / 2 > dpi->height)
return false;
389 void GfxDrawLine(
int x,
int y,
int x2,
int y2,
int colour,
int width,
int dash)
393 GfxDoDrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, colour, width, dash);
397 void GfxDrawLineUnscaled(
int x,
int y,
int x2,
int y2,
int colour)
421 void DrawBox(
int x,
int y,
int dx1,
int dy1,
int dx2,
int dy2,
int dx3,
int dy3)
438 static const byte colour =
PC_WHITE;
440 GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, colour);
441 GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, colour);
442 GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, colour);
444 GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, colour);
445 GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, colour);
446 GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, colour);
447 GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, colour);
448 GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, colour);
449 GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, colour);
458 if (colour == TC_INVALID)
return;
462 bool no_shade = (colour &
TC_NO_SHADE) != 0 || colour == TC_BLACK;
488 if (line.CountRuns() == 0)
return 0;
490 int w = line.GetWidth();
491 int h = line.GetLeading();
505 int max_w = right - left + 1;
511 truncation &= max_w < w;
513 const Sprite *dot_sprite =
nullptr;
522 FontCache *fc = ((
const Font*)line.GetVisualRun(0).GetFont())->fc;
525 dot_sprite = fc->
GetGlyph(dot_glyph);
528 min_x += 3 * dot_width;
529 offset_x = w - 3 * dot_width - max_w;
531 max_x -= 3 * dot_width;
548 right = left + w - 1;
554 right = left + w - 1;
558 left = right + 1 - w;
566 bool draw_shadow =
false;
567 for (
int run_index = 0; run_index < line.CountRuns(); run_index++) {
569 const Font *f = (
const Font*)run.GetFont();
576 int dpi_left = dpi->left;
577 int dpi_right = dpi->left + dpi->width - 1;
581 for (
int i = 0; i < run.GetGlyphCount(); i++) {
582 GlyphID glyph = run.GetGlyphs()[i];
585 if (glyph == 0xFFFF)
continue;
587 int begin_x = (int)run.GetPositions()[i * 2] + left - offset_x;
588 int end_x = (int)run.GetPositions()[i * 2 + 2] + left - offset_x - 1;
589 int top = (int)run.GetPositions()[i * 2 + 1] + y;
592 if (truncation && (begin_x < min_x || end_x > max_x))
continue;
596 if (begin_x + sprite->
x_offs > dpi_right || begin_x + sprite->
x_offs + sprite->
width < dpi_left)
continue;
598 if (draw_shadow && (glyph & SPRITE_GLYPH) == 0) {
609 for (
int i = 0; i < 3; i++, x += dot_width) {
649 int extra = max_height / 2;
651 if (_cur_dpi->top + _cur_dpi->height + extra < top || _cur_dpi->top > top + max_height + extra ||
652 _cur_dpi->left + _cur_dpi->width + extra < left || _cur_dpi->left > right + extra) {
656 Layouter layout(str, INT32_MAX, colour, fontsize);
657 if (layout.size() == 0)
return 0;
659 return DrawLayoutLine(*layout.front(), top, left, right, align, underline,
true);
681 return DrawString(left, right, top, str.c_str(), colour, align, underline, fontsize);
704 GetString(buffer, str,
lastof(buffer));
705 return DrawString(left, right, top, buffer, colour, align, underline, fontsize);
716 Layouter layout(str, maxw, TC_FROMSTRING, fontsize);
729 GetString(buffer, str,
lastof(buffer));
742 GetString(buffer, str,
lastof(buffer));
745 return (uint)layout.size();
790 int maxw = right - left + 1;
791 int maxh = bottom - top + 1;
795 if (maxh <= 0)
return top;
797 Layouter layout(str, maxw, colour, fontsize);
798 int total_height = layout.
GetBounds().height;
806 y =
RoundDivSU(bottom + top - total_height, 2);
810 y = bottom - total_height;
813 default: NOT_REACHED();
817 int first_line = bottom;
819 for (
const auto &line : layout) {
821 int line_height = line->GetLeading();
822 if (y >= top && y < bottom) {
823 last_line = y + line_height;
824 if (first_line > y) first_line = y;
853 return DrawStringMultiLine(left, right, top, bottom, str.c_str(), colour, align, underline, fontsize);
875 GetString(buffer, str,
lastof(buffer));
876 return DrawStringMultiLine(left, right, top, bottom, buffer, colour, align, underline, fontsize);
891 Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
920 GetString(buffer, strid,
lastof(buffer));
934 Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
947 if (x < 0)
return nullptr;
949 Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
981 if (offset !=
nullptr) {
1021 }
else if (pal != PAL_NONE) {
1029 GfxMainBlitterViewport(GetSprite(real_sprite,
ST_NORMAL), x, y,
BM_NORMAL, sub, real_sprite);
1048 }
else if (pal != PAL_NONE) {
1056 GfxMainBlitter(GetSprite(real_sprite,
ST_NORMAL), x, y,
BM_NORMAL, sub, real_sprite, zoom);
1072 template <
int ZOOM_BASE,
bool SCALED_XY>
1075 const DrawPixelInfo *dpi = (dst !=
nullptr) ? dst : _cur_dpi;
1088 if (sub ==
nullptr) {
1096 int clip_left = std::max(0, -sprite->
x_offs + sub->left * ZOOM_BASE );
1097 int clip_top = std::max(0, -sprite->
y_offs + sub->top * ZOOM_BASE );
1098 int clip_right = std::max(0, sprite->
width - (-sprite->
x_offs + (sub->right + 1) * ZOOM_BASE));
1099 int clip_bottom = std::max(0, sprite->
height - (-sprite->
y_offs + (sub->bottom + 1) * ZOOM_BASE));
1101 if (clip_left + clip_right >= sprite->
width)
return;
1102 if (clip_top + clip_bottom >= sprite->
height)
return;
1120 bp.
dst = dpi->dst_ptr;
1121 bp.
pitch = dpi->pitch;
1122 bp.
remap = _colour_remap_ptr;
1124 assert(sprite->
width > 0);
1125 assert(sprite->
height > 0);
1127 if (bp.
width <= 0)
return;
1128 if (bp.
height <= 0)
return;
1130 y -= SCALED_XY ?
ScaleByZoom(dpi->top, zoom) : dpi->top;
1134 bp.
height -= -y_unscaled;
1135 if (bp.
height <= 0)
return;
1139 bp.
top = y_unscaled;
1146 if (bp.
height <= 0)
return;
1149 x -= SCALED_XY ?
ScaleByZoom(dpi->left, zoom) : dpi->left;
1153 bp.
width -= -x_unscaled;
1154 if (bp.
width <= 0)
return;
1158 bp.
left = x_unscaled;
1165 if (bp.
width <= 0)
return;
1179 if (topleft <= clicked && clicked <= bottomright) {
1180 uint offset = (((size_t)clicked - (
size_t)topleft) / (blitter->
GetScreenDepth() / 8)) % bp.
pitch;
1181 if (offset < (uint)bp.
width) {
1209 std::unique_ptr<uint32[]> result(
new uint32[dim.width * dim.height]);
1211 MemSetT(result.get(), 0, dim.width * dim.height);
1216 dpi.dst_ptr = result.get();
1217 dpi.pitch = dim.width;
1220 dpi.width = dim.width;
1221 dpi.height = dim.height;
1225 std::unique_ptr<byte[]> pal_buffer{};
1227 pal_buffer.reset(
new byte[dim.width * dim.height]);
1228 MemSetT(pal_buffer.get(), 0, dim.width * dim.height);
1230 dpi.dst_ptr = pal_buffer.get();
1235 GfxBlitter<1, true>(sprite, 0, 0,
BM_NORMAL,
nullptr, real_sprite, zoom, &dpi);
1240 uint32 *dst = result.get();
1241 const byte *src = pal_buffer.get();
1242 for (
size_t i = 0; i < dim.height * dim.width; ++i) {
1252 GfxBlitter<ZOOM_LVL_BASE, false>(sprite, x, y, mode, sub, sprite_id, _cur_dpi->zoom);
1257 GfxBlitter<1, true>(sprite, x, y, mode, sub, sprite_id, zoom);
1260 void DoPaletteAnimations();
1262 void GfxInitPalettes()
1266 DoPaletteAnimations();
1295 #define EXTR(p, q) (((uint16)(palette_animation_counter * (p)) * (q)) >> 16)
1296 #define EXTR2(p, q) (((uint16)(~palette_animation_counter * (p)) * (q)) >> 16)
1298 void DoPaletteAnimations()
1303 static int palette_animation_counter = 0;
1304 palette_animation_counter += 8;
1310 const uint old_tc = palette_animation_counter;
1315 palette_animation_counter = 0;
1321 memcpy(old_val, palette_pos,
sizeof(old_val));
1327 *palette_pos++ = s[j];
1336 *palette_pos++ = s[j];
1343 byte i = (palette_animation_counter >> 1) & 0x7F;
1348 }
else if (i < 0x4A || i >= 0x75) {
1361 }
else if (i < 0x4A || i >= 0x75) {
1376 *palette_pos++ = s[j];
1385 *palette_pos++ = s[j];
1394 *palette_pos++ = s[j];
1400 palette_animation_counter = old_tc;
1421 uint sq1000_brightness = c.r * c.r * 299 + c.g * c.g * 587 + c.b * c.b * 114;
1423 return sq1000_brightness < ((uint) threshold) * ((uint) threshold) * 1000 ? TC_WHITE : TC_BLACK;
1435 for (uint i = 0; i != 224; i++) {
1465 for (
char c =
'0'; c <=
'9'; c++) {
1480 for (
char c =
'9'; c >=
'0'; c--) {
1485 if (c !=
'0') *front = c -
'0';
1490 void ScreenSizeChanged()
1492 _dirty_bytes_per_line =
CeilDiv(_screen.width, DIRTY_BLOCK_WIDTH);
1493 _dirty_blocks = ReallocT<byte>(_dirty_blocks, _dirty_bytes_per_line *
CeilDiv(_screen.height, DIRTY_BLOCK_HEIGHT));
1503 void UndrawMouseCursor()
1509 if (_screen.dst_ptr ==
nullptr)
return;
1519 void DrawMouseCursor()
1525 if (_screen.dst_ptr ==
nullptr)
return;
1534 if (!_cursor.
dirty)
return;
1535 UndrawMouseCursor();
1539 int left = _cursor.
pos.x + _cursor.total_offs.x;
1545 if (left + width > _screen.width) {
1546 width = _screen.width - left;
1548 if (width <= 0)
return;
1550 int top = _cursor.
pos.y + _cursor.total_offs.y;
1556 if (top + height > _screen.height) {
1557 height = _screen.height - top;
1559 if (height <= 0)
return;
1561 _cursor.draw_pos.x = left;
1562 _cursor.draw_pos.y = top;
1572 _cur_dpi = &_screen;
1580 _cursor.
dirty =
false;
1595 assert(right <= _screen.width && bottom <= _screen.height);
1597 if (right > _cursor.draw_pos.x &&
1598 left < _cursor.draw_pos.x + _cursor.
draw_size.x &&
1599 bottom > _cursor.draw_pos.y &&
1600 top < _cursor.draw_pos.y + _cursor.
draw_size.y) {
1601 UndrawMouseCursor();
1621 byte *b = _dirty_blocks;
1622 const int w =
Align(_screen.width, DIRTY_BLOCK_WIDTH);
1623 const int h =
Align(_screen.height, DIRTY_BLOCK_HEIGHT);
1634 int right = x + DIRTY_BLOCK_WIDTH;
1642 p += _dirty_bytes_per_line;
1643 bottom += DIRTY_BLOCK_HEIGHT;
1644 }
while (bottom != h && *p != 0);
1647 h2 = (bottom - y) / DIRTY_BLOCK_HEIGHT;
1651 while (right != w) {
1656 if (!*p2)
goto no_more_coalesc;
1657 p2 += _dirty_bytes_per_line;
1662 right += DIRTY_BLOCK_WIDTH;
1668 p2 += _dirty_bytes_per_line;
1681 if (left < right && top < bottom) {
1686 }
while (b++, (x += DIRTY_BLOCK_WIDTH) != w);
1687 }
while (b += -(
int)(w / DIRTY_BLOCK_WIDTH) + _dirty_bytes_per_line, (y += DIRTY_BLOCK_HEIGHT) != h);
1689 ++_dirty_block_colour;
1714 if (left < 0) left = 0;
1715 if (top < 0) top = 0;
1716 if (right > _screen.width) right = _screen.width;
1717 if (bottom > _screen.height) bottom = _screen.height;
1719 if (left >= right || top >= bottom)
return;
1726 left /= DIRTY_BLOCK_WIDTH;
1727 top /= DIRTY_BLOCK_HEIGHT;
1729 b = _dirty_blocks + top * _dirty_bytes_per_line + left;
1731 width = ((right - 1) / DIRTY_BLOCK_WIDTH) - left + 1;
1732 height = ((bottom - 1) / DIRTY_BLOCK_HEIGHT) - top + 1;
1734 assert(width > 0 && height > 0);
1739 do b[--i] = 0xFF;
while (i != 0);
1741 b += _dirty_bytes_per_line;
1742 }
while (--height != 0);
1780 if ((left -= o->left) < 0) {
1782 if (width <= 0)
return false;
1789 if (width > o->width - left) {
1790 width = o->width - left;
1791 if (width <= 0)
return false;
1795 if ((top -= o->top) < 0) {
1797 if (height <= 0)
return false;
1804 n->dst_ptr = blitter->
MoveTo(o->dst_ptr, left, top);
1805 n->pitch = o->pitch;
1807 if (height > o->height - top) {
1808 height = o->height - top;
1809 if (height <= 0)
return false;
1836 _cursor.total_offs = offs;
1839 int right = std::max(_cursor.total_offs.x + _cursor.
total_size.x, offs.x + size.x);
1840 int bottom = std::max(_cursor.total_offs.y + _cursor.
total_size.y, offs.y + size.y);
1841 if (offs.x < _cursor.total_offs.x) _cursor.total_offs.x = offs.x;
1842 if (offs.y < _cursor.total_offs.y) _cursor.total_offs.y = offs.y;
1843 _cursor.
total_size.x = right - _cursor.total_offs.x;
1844 _cursor.
total_size.y = bottom - _cursor.total_offs.y;
1848 _cursor.
dirty =
true;
1869 static void SwitchAnimatedCursor()
1884 SwitchAnimatedCursor();
1925 SwitchAnimatedCursor();
1936 this->
delta.x = delta_x;
1937 this->
delta.y = delta_y;
1939 int last_position_x = this->
pos.x;
1940 int last_position_y = this->
pos.y;
1945 this->
delta.x = last_position_x - this->
pos.x;
1946 this->
delta.y = last_position_y - this->
pos.y;
1972 if (x == this->
pos.x && y == this->pos.y) {
1974 this->queued_warp =
false;
1977 this->
delta.x = x - (this->queued_warp ? this->last_position.x : this->
pos.x);
1978 this->
delta.y = y - (this->queued_warp ? this->last_position.y : this->
pos.y);
1980 this->last_position.x = x;
1981 this->last_position.y = y;
1983 bool need_warp =
false;
1985 if (this->
delta.x != 0 || this->delta.y != 0) {
1990 this->queued_warp = queued_warp;
1993 }
else if (this->
pos.x != x || this->pos.y != y) {
1994 this->queued_warp =
false;
2002 bool ChangeResInGame(
int width,
int height)
2007 bool ToggleFullScreen(
bool fs)
2011 Debug(driver, 0,
"Could not find a suitable fullscreen resolution");
2016 void SortResolutions()
2045 void ChangeGameSpeed(
bool enable_fast_forward)
2047 if (enable_fast_forward) {
byte _dirkeys
1 = left, 2 = up, 4 = right, 8 = down
void * clicked_pixel
Clicked pixel (pointer to blitter buffer)
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
static const uint8 PC_WHITE
White palette colour.
@ TC_FORCED
Ignore colour changes from strings.
uint32 GlyphID
Glyphs are characters from a font.
void SetMouseCursorBusy(bool busy)
Set or unset the ZZZ cursor.
SwitchMode
Mode which defines what mode we're switching to.
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
Draws the projection of a parallelepiped.
int first_dirty
The first dirty element.
virtual void SetPixel(void *video, int x, int y, uint8 colour)=0
Draw a pixel with a given colour on the video-buffer.
@ SA_HOR_MASK
Mask for horizontal alignment.
Collection of variables for cursor-display and -animation.
uint32 data
Conversion of the channel information to a 32 bit number.
char32_t WChar
Type for wide characters, i.e.
void AddDirtyBlock(int left, int top, int right, int bottom)
Extend the internal _invalid_rect rectangle to contain the rectangle defined by the given parameters.
static int UnScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
static byte _string_colourremap[3]
Recoloursprite for stringdrawing. The grf loader ensures that ST_FONT sprites only use colours 0 to 2...
@ PALETTE_TEXT_RECOLOUR
Set if palette is actually a magic text recolour.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
const AnimCursor * animate_cur
in case of animated cursor, current frame
A reusable buffer that can be used for places that temporary allocate a bit of memory and do that ver...
Dimensions (a width and height) of a rectangle in 2D.
int top
The top offset in the 'dst' in pixels to start drawing.
@ BM_TRANSPARENT
Perform transparency colour remapping.
virtual void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)=0
Draw a colourtable to the screen.
uint sprite_count
number of sprites to draw
int skip_left
How much pixels of the source to skip on the left (based on zoom of dst)
bool dirty
the rect occupied by the mouse is dirty (redraw)
BlitterMode
The modes of blitting we can do.
bool _left_button_down
Is left mouse button pressed?
int width
The width in pixels that needs to be drawn to dst.
@ SPRITE_WIDTH
number of bits for the sprite number
byte landscape
the landscape we're currently in
Class to backup a specific variable and restore it later.
@ PALETTE_ANIM_SIZE
number of animated colours
virtual Blitter::PaletteAnimation UsePaletteAnimation()=0
Check if the blitter uses palette animation at all.
void GfxFillPolygon(const std::vector< Point > &shape, int colour, FillRectMode mode)
Fill a polygon with colour.
std::mutex lock
synchronization for playback status fields
TextColour GetContrastColour(uint8 background, uint8 threshold)
Determine a contrasty text colour for a coloured background.
How all blitters should look like.
static const Palette _palette
Colour palette (DOS)
int sprite_height
Real height of the sprite.
bool visible
cursor is visible
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
virtual uint8 GetScreenDepth()=0
Get the screen depth this blitter works for.
virtual void CopyToBuffer(const void *video, void *dst, int width, int height)=0
Copy from the screen to a buffer.
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
std::vector< SpriteID > sprites
Sprites found.
virtual void MakeDirty(int left, int top, int width, int height)=0
Mark a particular area dirty.
virtual bool ToggleFullscreen(bool fullscreen)=0
Change the full screen setting.
NewGrfDebugSpritePickerMode mode
Current state.
const AnimCursor * animate_list
in case of animated cursor, list of frames
SpriteID sprite
The 'real' sprite.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
void * dst
Destination buffer.
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
bool include(std::vector< T > &vec, const T &item)
Helper function to append an item to a vector if it is not already contained Consider using std::set,...
virtual void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)=0
Scroll the videobuffer some 'x' and 'y' value.
uint16 height
Height of the sprite.
bool _ctrl_pressed
Is Ctrl pressed?
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
int8 _font_zoom_cfg
Font zoom level in config.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
int16 x_offs
Number of pixels to shift the sprite to the right.
int sprite_width
Real width of the sprite.
ZoomLevel
All zoom levels we know.
@ SA_BOTTOM
Bottom align the text.
Point GetCharPosition(const char *ch) const
Get the position of a character in the layout.
int pitch
The pitch of the destination buffer.
StringAlignment
How to align the to-be drawn text.
ClientSettings _settings_client
The current settings for this game.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
static void SetColourRemap(TextColour colour)
Set the colour remap to be for the given colour.
FillRectMode
Define the operation GfxFillRect performs.
@ ST_NORMAL
The most basic (normal) sprite.
void UpdateCursorPositionRelative(int delta_x, int delta_y)
Update cursor position on mouse movement for relative modes.
@ SA_RIGHT
Right align the text (must be a single bit).
@ SA_VERT_CENTER
Vertically center the text.
static const uint EPV_CYCLES_FIZZY_DRINK
length of the fizzy drinks animation
ZoomLevel _gui_zoom
GUI Zoom level.
static void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash=0)
Check line clipping by using a linear equation and draw the visible part of the line given by x/y and...
virtual ZoomLevel GetSuggestedUIZoom()
Get a suggested default GUI zoom taking screen DPI into account.
Point draw_size
position and size bounding-box for drawing
Used to only draw a part of the sprite.
ZoomLevel zoom_max
maximum zoom out level
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Point sprite_pos[16]
relative position of individual sprites
virtual void DrawRect(void *video, int width, int height, uint8 colour)=0
Make a single horizontal line in a single colour on the video-buffer.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
int GetStringLineCount(StringID str, int maxw)
Calculates number of lines of string.
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
static std::recursive_mutex _palette_mutex
To coordinate access to _cur_palette.
virtual bool GetDrawGlyphShadow()=0
Do we need to draw a glyph shadow?
GameCreationSettings game_creation
settings used during the creation of a game (map)
void UpdateCursorSize()
Update cursor dimension.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
@ BM_NORMAL
Perform the simple blitting.
A single line worth of VisualRuns.
static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left, int right, StringAlignment align, bool underline, bool truncation)
Drawing routine for drawing a laid out line of text.
static const ExtraPaletteValues _extra_palette_values
Actual palette animation tables.
const void * sprite
Pointer to the sprite how ever the encoder stored it.
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
From a rectangle that needs redrawing, find the windows that intersect with the rectangle.
virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)=0
Draw an image to the screen, given an amount of params defined above.
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash=0)=0
Draw a line with a given colour.
uint16 fast_forward_speed_limit
Game speed to use when fast-forward is enabled.
static T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
uint32 CursorID
The number of the cursor (sprite)
@ FS_NORMAL
Index of the normal font in the font tables.
@ SA_TOP
Top align the text.
void SetMouseCursor(CursorID sprite, PaletteID pal)
Assign a single non-animated sprite to the cursor.
@ PALETTE_WIDTH
number of bits of the sprite containing the recolour palette
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
bool UpdateCursorPosition(int x, int y, bool queued_warp)
Update cursor position on mouse movement.
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Dimension GetBounds()
Get the boundaries of this paragraph.
@ BM_COLOUR_REMAP
Perform a colour remapping.
The layouter performs all the layout work.
std::unique_ptr< uint32[]> DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom)
Draws a sprite to a new RGBA buffer (see Colour union) instead of drawing to the screen.
PauseMode _pause_mode
The current pause mode.
#define FONT_HEIGHT_MONO
Height of characters in the large (FS_MONO) font.
static const byte _string_colourmap[17]
Colour mapping for TextColour.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
@ TC_IS_PALETTE_COLOUR
Colour value is already a real palette colour index, not an index of a StringColour.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Point total_size
union of sprite properties
const char * GetCharAtPosition(const char *str, int x, FontSize start_fontsize)
Get the character from a string that is drawn at a specific position.
@ BM_CRASH_REMAP
Perform a crash remapping.
static const uint EPV_CYCLES_OIL_REFINERY
length of the oil refinery's fire animation
uint16 width
Width of the sprite.
CursorID sprite
Must be set to LAST_ANIM when it is the last sprite of the loop.
std::vector< Dimension > _resolutions
List of resolutions.
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
void RedrawScreenRect(int left, int top, int right, int bottom)
Repaints a specific rectangle of the screen.
virtual bool ChangeResolution(int w, int h)=0
Change the resolution of the window.
@ TC_NO_SHADE
Do not add shading to this text colour.
bool _networking
are we in networking mode?
bool _shift_pressed
Is Shift pressed?
void DrawDirtyBlocks()
Repaints the rectangle blocks which are marked as 'dirty'.
#define FONT_HEIGHT_LARGE
Height of characters in the large (FS_LARGE) font.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Coordinates of a point in 2D.
void NetworkUndrawChatMessage()
Hide the chatbox.
void DrawCharCentered(WChar c, const Rect &r, TextColour colour)
Draw single character horizontally centered around (x,y)
PauseMode
Modes of pausing we've got.
@ BM_BLACK_REMAP
Perform remapping to a completely blackened sprite.
static int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
void SetAnimatedMouseCursor(const AnimCursor *table)
Assign an animation to the cursor.
GameMode
Mode which defines the state of the game.
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
virtual uint GetGlyphWidth(GlyphID key)=0
Get the width of the glyph with the given key.
static Rect _invalid_rect
The rect for repaint.
int count_dirty
The number of dirty elements.
@ PALETTE_MODIFIER_TRANSPARENT
when a sprite is to be displayed transparently, this bit needs to be set.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
@ SA_HOR_CENTER
Horizontally center the text.
@ PALETTE_ANIM_START
Index in the _palettes array from which all animations are taking places (table/palettes....
byte GetDigitWidth(FontSize size)
Return the maximum width of single digit.
void GetBroadestDigit(uint *front, uint *next, FontSize size)
Determine the broadest digits for guessing the maximum width of a n-digit number.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Visual run contains data about the bit of text with the same font.
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
static uint GetGlyphWidth(FontSize size, WChar key)
Get the width of a glyph.
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
ZoomLevel zoom_min
minimum zoom out level
int8 _gui_zoom_cfg
GUI zoom level in config.
SwitchMode _switch_mode
The next mainloop command.
ZoomLevel _font_zoom
Font Zoom level.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static void GfxBlitter(const Sprite *const sprite, int x, int y, BlitterMode mode, const SubSprite *const sub, SpriteID sprite_id, ZoomLevel zoom, const DrawPixelInfo *dst=nullptr)
The code for setting up the blitter mode and sprite information before finally drawing the sprite.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
uint animate_timeout
in case of animated cursor, number of ticks to show the current cursor
static int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
@ SA_VERT_MASK
Mask for vertical alignment.
Font cache for basic fonts.
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
void Restore()
Restore the variable.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
virtual const Sprite * GetGlyph(GlyphID key)=0
Get the glyph (sprite) of the given key.
uint GetMaxSpriteID()
Get a reasonable (upper bound) estimate of the maximum SpriteID used in OpenTTD; there will be no spr...
const char * GetCharAtPosition(int x) const
Get the character that is at a position.
uint32 PaletteID
The number of the palette.
static byte _stringwidth_table[FS_END][224]
Cache containing width of often used characters.
static const Sprite * GetGlyph(FontSize size, WChar key)
Get the Sprite for a glyph.
static const uint EPV_CYCLES_LIGHTHOUSE
length of the lighthouse/stadium animation
bool CopyPalette(Palette &local_palette, bool force_copy)
Copy the current palette if the palette was updated.
byte display_time
Amount of ticks this sprite will be shown.
int left
The left offset in the 'dst' in pixels to start drawing.
Point delta
relative mouse movement in this tick
static BlitterMode GetBlitterMode(PaletteID pal)
Helper function to get the blitter mode for different types of palettes.
static std::vector< LineSegment > MakePolygonSegments(const std::vector< Point > &shape, Point offset)
Make line segments from a polygon defined by points, translated by an offset.
static bool GfxPreprocessLine(DrawPixelInfo *dpi, int &x, int &y, int &x2, int &y2, int width)
Align parameters of a line to the given DPI and check simple clipping.
static void SetCursorSprite(CursorID cursor, PaletteID pal)
Switch cursor to different sprite.
int16 y_offs
Number of pixels to shift the sprite downwards.
@ PALETTE_ANIMATION_NONE
No palette animation.
A single sprite of a list of animated cursors.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Palette _cur_palette
Current palette.
@ SA_LEFT
Left align the text.
byte GetCharacterWidth(FontSize size, WChar key)
Return width of character glyph.
virtual void CopyFromBuffer(void *video, const void *src, int width, int height)=0
Copy from a buffer to the screen.
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
PalSpriteID sprite_seq[16]
current image of cursor
static const uint EPV_CYCLES_DARK_WATER
Description of the length of the palette cycle animations.
#define lengthof(x)
Return the length of an fixed size array.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Parameters related to blitting.
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
@ FS_MONO
Index of the monospaced font in the font tables.
@ ZOOM_LVL_NORMAL
The normal zoom level.
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
PaletteID pal
The palette (use PAL_NONE) if not needed)
int height
The height in pixels that needs to be drawn to dst.
FontSize
Available font sizes.
@ ST_RECOLOUR
Recolour sprite.
Specification of a rectangle with absolute coordinates of all edges.
Point pos
logical mouse position
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst)
virtual GlyphID MapCharToGlyph(WChar key)=0
Map a character into a glyph.
bool _right_button_clicked
Is right mouse button clicked?
Information about the currently used palette.
static const uint EPV_CYCLES_GLITTER_WATER
length of the glittery water animation
Data structure describing a sprite.
Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize)
Get the leading corner of a character in a single-line string relative to the start of the string.
bool in_window
mouse inside this window, determines drawing logic
const byte * remap
XXX – Temporary storage for remap array.
#define lastof(x)
Get the last element of an fixed size array.
void UpdateGUIZoom()
Resolve GUI zoom level, if auto-suggestion is requested.
bool _left_button_clicked
Is left mouse button clicked?
Dimension _cur_resolution
The current resolution.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
uint16 _game_speed
Current game-speed; 100 is 1x, 0 is infinite.
bool _right_button_down
Is right mouse button pressed?
static const PaletteID PALETTE_ALL_BLACK
Exchange any color by black, needed for painting fictive tiles outside map.
GUISettings gui
settings related to the GUI
Data about how and where to blit pixels.
virtual int BufferSize(int width, int height)=0
Calculate how much memory there is needed for an image of this size in the video-buffer.
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
Draw a sprite in a viewport.