|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
46 std::atomic<bool> _exit_game;
73 static const byte *_colour_remap_ptr;
76 static const uint DIRTY_BLOCK_HEIGHT = 8;
77 static const uint DIRTY_BLOCK_WIDTH = 64;
79 static uint _dirty_bytes_per_line = 0;
80 static byte *_dirty_blocks =
nullptr;
81 extern uint _dirty_block_colour;
83 void GfxScroll(
int left,
int top,
int width,
int height,
int xo,
int yo)
87 if (xo == 0 && yo == 0)
return;
89 if (_cursor.
visible) UndrawMouseCursor();
93 blitter->
ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo);
118 const int otop = top;
119 const int oleft = left;
122 if (left > right || top > bottom)
return;
123 if (right < dpi->left || left >= dpi->left + dpi->width)
return;
124 if (bottom < dpi->top || top >= dpi->top + dpi->height)
return;
126 if ( (left -= dpi->left) < 0) left = 0;
127 right = right - dpi->left + 1;
128 if (right > dpi->width) right = dpi->width;
132 if ( (top -= dpi->top) < 0) top = 0;
133 bottom = bottom - dpi->top + 1;
134 if (bottom > dpi->height) bottom = dpi->height;
138 dst = blitter->
MoveTo(dpi->dst_ptr, left, top);
142 blitter->
DrawRect(dst, right, bottom, (uint8_t)colour);
150 byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
152 for (
int i = (bo ^= 1); i < right; i += 2) blitter->
SetPixel(dst, i, 0, (uint8_t)colour);
153 dst = blitter->
MoveTo(dst, 0, 1);
154 }
while (--bottom > 0);
160 typedef std::pair<Point, Point> LineSegment;
172 std::vector<LineSegment> segments;
173 if (shape.size() < 3)
return segments;
174 segments.reserve(shape.size());
177 Point prev = shape.back();
180 for (
Point pt : shape) {
186 segments.emplace_back(pt, prev);
187 }
else if (prev.y < pt.y) {
188 segments.emplace_back(prev, pt);
218 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());
221 if (segments.empty())
return;
224 std::sort(segments.begin(), segments.end(), [](
const LineSegment &a,
const LineSegment &b) { return a.first.y < b.first.y; });
227 std::vector<LineSegment> active;
230 std::vector<int> intersections;
233 intersections.reserve(4);
236 int y = segments.front().first.y;
237 std::vector<LineSegment>::iterator nextseg = segments.begin();
238 while (!active.empty() || nextseg != segments.end()) {
240 active.erase(std::remove_if(active.begin(), active.end(), [y](
const LineSegment &s) { return s.second.y == y; }), active.end());
243 while (nextseg != segments.end() && nextseg->first.y == y) {
244 active.push_back(*nextseg);
253 if (y >= dpi->height)
return;
256 intersections.clear();
257 for (
const LineSegment &s : active) {
258 const int sdx = s.second.x - s.first.x;
259 const int sdy = s.second.y - s.first.y;
260 const int ldy = y - s.first.y;
261 const int x = s.first.x + sdx * ldy / sdy;
262 intersections.push_back(x);
266 std::sort(intersections.begin(), intersections.end());
267 for (
size_t i = 1; i < intersections.size(); i += 2) {
269 const int x1 = std::max(0, intersections[i - 1]);
270 const int x2 = std::min(intersections[i], dpi->width);
271 if (x2 < 0)
continue;
272 if (x1 >= dpi->width)
continue;
275 void *dst = blitter->
MoveTo(dpi->dst_ptr, x1, y);
278 blitter->
DrawRect(dst, x2 - x1, 1, (uint8_t)colour);
286 for (
int x = (x1 + y) & 1; x < x2 - x1; x += 2) {
287 blitter->
SetPixel(dst, x, 0, (uint8_t)colour);
312 static inline void GfxDoDrawLine(
void *video,
int x,
int y,
int x2,
int y2,
int screen_width,
int screen_height, uint8_t colour,
int width,
int dash = 0)
318 if (y2 == y || x2 == x) {
320 blitter->
DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width, dash);
324 int grade_y = y2 - y;
325 int grade_x = x2 - x;
328 int extra = (int)
CeilDiv(3 * width, 4);
329 Rect clip = { -extra, -extra, screen_width - 1 + extra, screen_height - 1 + extra };
333 while (INT_MAX /
abs(grade_y) < std::max(
abs(clip.left - x),
abs(clip.right - x))) {
343 int left_isec_y = y + (clip.left - x) * grade_y / grade_x;
344 int right_isec_y = y + (clip.right - x) * grade_y / grade_x;
345 if ((left_isec_y > clip.bottom + margin && right_isec_y > clip.bottom + margin) ||
346 (left_isec_y < clip.top - margin && right_isec_y < clip.top - margin)) {
356 blitter->
DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width, dash);
378 if (x + width / 2 < 0 && x2 + width / 2 < 0 )
return false;
379 if (y + width / 2 < 0 && y2 + width / 2 < 0 )
return false;
380 if (x - width / 2 > dpi->width && x2 - width / 2 > dpi->width )
return false;
381 if (y - width / 2 > dpi->height && y2 - width / 2 > dpi->height)
return false;
385 void GfxDrawLine(
int x,
int y,
int x2,
int y2,
int colour,
int width,
int dash)
389 GfxDoDrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, colour, width, dash);
393 void GfxDrawLineUnscaled(
int x,
int y,
int x2,
int y2,
int colour)
417 void DrawBox(
int x,
int y,
int dx1,
int dy1,
int dx2,
int dy2,
int dx3,
int dy3)
434 static const byte colour =
PC_WHITE;
436 GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, colour);
437 GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, colour);
438 GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, colour);
440 GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, colour);
441 GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, colour);
442 GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, colour);
443 GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, colour);
444 GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, colour);
445 GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, colour);
457 GfxDrawLine(r.left, r.top, r.right, r.top, colour, width, dash);
458 GfxDrawLine(r.left, r.top, r.left, r.bottom, colour, width, dash);
459 GfxDrawLine(r.right, r.top, r.right, r.bottom, colour, width, dash);
460 GfxDrawLine(r.left, r.bottom, r.right, r.bottom, colour, width, dash);
469 if (colour == TC_INVALID)
return;
473 bool no_shade = (colour &
TC_NO_SHADE) != 0 || colour == TC_BLACK;
499 if (line.CountRuns() == 0)
return 0;
501 int w = line.GetWidth();
502 int h = line.GetLeading();
516 int max_w = right - left + 1;
522 truncation &= max_w < w;
524 const Sprite *dot_sprite =
nullptr;
533 FontCache *fc = line.GetVisualRun(0).GetFont()->
fc;
536 dot_sprite = fc->
GetGlyph(dot_glyph);
539 min_x += 3 * dot_width;
540 offset_x = w - 3 * dot_width - max_w;
542 max_x -= 3 * dot_width;
559 right = left + w - 1;
565 right = left + w - 1;
569 left = right + 1 - w;
579 bool draw_shadow =
false;
580 for (
int run_index = 0; run_index < line.CountRuns(); run_index++) {
582 const auto &glyphs = run.GetGlyphs();
583 const auto &positions = run.GetPositions();
584 const Font *f = run.GetFont();
591 int dpi_left = dpi->left;
592 int dpi_right = dpi->left + dpi->width - 1;
596 for (
int i = 0; i < run.GetGlyphCount(); i++) {
600 if (glyph == 0xFFFF)
continue;
602 int begin_x = positions[i].x + left - offset_x;
603 int end_x = positions[i + 1].x + left - offset_x - 1;
604 int top = positions[i].y + y;
607 if (truncation && (begin_x < min_x || end_x > max_x))
continue;
611 if (begin_x + sprite->
x_offs > dpi_right || begin_x + sprite->
x_offs + sprite->
width < dpi_left)
continue;
613 if (draw_shadow && (glyph & SPRITE_GLYPH) == 0) {
615 GfxMainBlitter(sprite, begin_x + shadow_offset, top + shadow_offset,
BM_COLOUR_REMAP);
624 for (
int i = 0; i < 3; i++, x += dot_width) {
627 GfxMainBlitter(dot_sprite, x + shadow_offset, y + shadow_offset,
BM_COLOUR_REMAP);
664 int extra = max_height / 2;
666 if (_cur_dpi->top + _cur_dpi->height + extra < top || _cur_dpi->top > top + max_height + extra ||
667 _cur_dpi->left + _cur_dpi->width + extra < left || _cur_dpi->left > right + extra) {
671 Layouter layout(str, INT32_MAX, colour, fontsize);
672 if (layout.empty())
return 0;
674 return DrawLayoutLine(*layout.front(), top, left, right, align, underline,
true);
708 Layouter layout(str, maxw, TC_FROMSTRING, fontsize);
732 return (uint)layout.size();
777 int maxw = right - left + 1;
778 int maxh = bottom - top + 1;
782 if (maxh <= 0)
return top;
784 Layouter layout(str, maxw, colour, fontsize);
785 int total_height = layout.
GetBounds().height;
793 y =
RoundDivSU(bottom + top - total_height, 2);
797 y = bottom - total_height;
800 default: NOT_REACHED();
804 int first_line = bottom;
806 for (
const auto &line : layout) {
808 int line_height = line->GetLeading();
809 if (y >= top && y + line_height - 1 <= bottom) {
810 last_line = y + line_height;
811 if (first_line > y) first_line = y;
854 Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
895 assert(ch >= str.data() && (ch - str.data()) <=
static_cast<ptrdiff_t
>(str.size()));
896 auto it_ch = str.begin() + (ch - str.data());
898 Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
911 if (x < 0)
return -1;
913 Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
945 if (offset !=
nullptr) {
986 }
else if (pal != PAL_NONE) {
1014 }
else if (pal != PAL_NONE) {
1038 template <
int ZOOM_BASE,
bool SCALED_XY>
1041 const DrawPixelInfo *dpi = (dst !=
nullptr) ? dst : _cur_dpi;
1054 if (sub ==
nullptr) {
1062 int clip_left = std::max(0, -sprite->
x_offs + sub->left * ZOOM_BASE );
1063 int clip_top = std::max(0, -sprite->
y_offs + sub->top * ZOOM_BASE );
1064 int clip_right = std::max(0, sprite->
width - (-sprite->
x_offs + (sub->right + 1) * ZOOM_BASE));
1065 int clip_bottom = std::max(0, sprite->
height - (-sprite->
y_offs + (sub->bottom + 1) * ZOOM_BASE));
1067 if (clip_left + clip_right >= sprite->
width)
return;
1068 if (clip_top + clip_bottom >= sprite->
height)
return;
1086 bp.
dst = dpi->dst_ptr;
1087 bp.
pitch = dpi->pitch;
1088 bp.
remap = _colour_remap_ptr;
1090 assert(sprite->
width > 0);
1091 assert(sprite->
height > 0);
1093 if (bp.
width <= 0)
return;
1094 if (bp.
height <= 0)
return;
1096 y -= SCALED_XY ?
ScaleByZoom(dpi->top, zoom) : dpi->top;
1100 bp.
height -= -y_unscaled;
1101 if (bp.
height <= 0)
return;
1105 bp.
top = y_unscaled;
1112 if (bp.
height <= 0)
return;
1115 x -= SCALED_XY ?
ScaleByZoom(dpi->left, zoom) : dpi->left;
1119 bp.
width -= -x_unscaled;
1120 if (bp.
width <= 0)
return;
1124 bp.
left = x_unscaled;
1131 if (bp.
width <= 0)
return;
1145 if (topleft <= clicked && clicked <= bottomright) {
1146 uint offset = (((size_t)clicked - (
size_t)topleft) / (blitter->
GetScreenDepth() / 8)) % bp.
pitch;
1147 if (offset < (uint)bp.
width) {
1175 size_t dim_size =
static_cast<size_t>(dim.width) * dim.height;
1176 std::unique_ptr<uint32_t[]> result(
new uint32_t[dim_size]);
1178 MemSetT(result.get(), 0, dim_size);
1183 dpi.dst_ptr = result.get();
1184 dpi.pitch = dim.width;
1187 dpi.width = dim.width;
1188 dpi.height = dim.height;
1191 dim_size =
static_cast<size_t>(dim.width) * dim.height;
1194 std::unique_ptr<
byte[]> pal_buffer{};
1195 if (blitter->GetScreenDepth() == 8) {
1196 pal_buffer.reset(
new byte[dim_size]);
1197 MemSetT(pal_buffer.get(), 0, dim_size);
1199 dpi.dst_ptr = pal_buffer.get();
1204 GfxBlitter<1, true>(sprite, 0, 0,
BM_NORMAL,
nullptr, real_sprite, zoom, &dpi);
1205 disable_anim.Restore();
1207 if (blitter->GetScreenDepth() == 8) {
1209 uint32_t *dst = result.get();
1210 const byte *src = pal_buffer.get();
1211 for (
size_t i = 0; i < dim_size; ++i) {
1221 GfxBlitter<ZOOM_LVL_BASE, false>(sprite, x, y, mode, sub, sprite_id, _cur_dpi->zoom);
1226 GfxBlitter<1, true>(sprite, x, y, mode, sub, sprite_id, zoom);
1238 for (uint i = 0; i != 224; i++) {
1266 for (
char c =
'0'; c <=
'9'; c++) {
1281 for (
char c =
'9'; c >=
'0'; c--) {
1286 if (c !=
'0') *front = c -
'0';
1291 void ScreenSizeChanged()
1293 _dirty_bytes_per_line =
CeilDiv(_screen.width, DIRTY_BLOCK_WIDTH);
1294 _dirty_blocks = ReallocT<byte>(_dirty_blocks,
static_cast<size_t>(_dirty_bytes_per_line) *
CeilDiv(_screen.height, DIRTY_BLOCK_HEIGHT));
1304 void UndrawMouseCursor()
1310 if (_screen.dst_ptr ==
nullptr)
return;
1320 void DrawMouseCursor()
1326 if (_screen.dst_ptr ==
nullptr)
return;
1335 if (!_cursor.
dirty)
return;
1336 UndrawMouseCursor();
1340 int left = _cursor.
pos.x + _cursor.total_offs.x;
1346 if (left + width > _screen.width) {
1347 width = _screen.width - left;
1349 if (width <= 0)
return;
1351 int top = _cursor.
pos.y + _cursor.total_offs.y;
1357 if (top + height > _screen.height) {
1358 height = _screen.height - top;
1360 if (height <= 0)
return;
1362 _cursor.draw_pos.x = left;
1363 _cursor.draw_pos.y = top;
1373 _cur_dpi = &_screen;
1381 _cursor.
dirty =
false;
1396 assert(right <= _screen.width && bottom <= _screen.height);
1398 if (right > _cursor.draw_pos.x &&
1399 left < _cursor.draw_pos.x + _cursor.
draw_size.x &&
1400 bottom > _cursor.draw_pos.y &&
1401 top < _cursor.draw_pos.y + _cursor.
draw_size.y) {
1402 UndrawMouseCursor();
1422 byte *b = _dirty_blocks;
1423 const int w =
Align(_screen.width, DIRTY_BLOCK_WIDTH);
1424 const int h =
Align(_screen.height, DIRTY_BLOCK_HEIGHT);
1435 int right = x + DIRTY_BLOCK_WIDTH;
1443 p += _dirty_bytes_per_line;
1444 bottom += DIRTY_BLOCK_HEIGHT;
1445 }
while (bottom != h && *p != 0);
1448 h2 = (bottom - y) / DIRTY_BLOCK_HEIGHT;
1452 while (right != w) {
1457 if (!*p2)
goto no_more_coalesc;
1458 p2 += _dirty_bytes_per_line;
1463 right += DIRTY_BLOCK_WIDTH;
1469 p2 += _dirty_bytes_per_line;
1482 if (left < right && top < bottom) {
1487 }
while (b++, (x += DIRTY_BLOCK_WIDTH) != w);
1488 }
while (b += -(
int)(w / DIRTY_BLOCK_WIDTH) + _dirty_bytes_per_line, (y += DIRTY_BLOCK_HEIGHT) != h);
1490 ++_dirty_block_colour;
1515 if (left < 0) left = 0;
1516 if (top < 0) top = 0;
1517 if (right > _screen.width) right = _screen.width;
1518 if (bottom > _screen.height) bottom = _screen.height;
1520 if (left >= right || top >= bottom)
return;
1527 left /= DIRTY_BLOCK_WIDTH;
1528 top /= DIRTY_BLOCK_HEIGHT;
1530 b = _dirty_blocks + top * _dirty_bytes_per_line + left;
1532 width = ((right - 1) / DIRTY_BLOCK_WIDTH) - left + 1;
1533 height = ((bottom - 1) / DIRTY_BLOCK_HEIGHT) - top + 1;
1535 assert(width > 0 && height > 0);
1540 do b[--i] = 0xFF;
while (i != 0);
1542 b += _dirty_bytes_per_line;
1543 }
while (--height != 0);
1581 if ((left -= o->left) < 0) {
1583 if (width <= 0)
return false;
1590 if (width > o->width - left) {
1591 width = o->width - left;
1592 if (width <= 0)
return false;
1596 if ((top -= o->top) < 0) {
1598 if (height <= 0)
return false;
1605 n->dst_ptr = blitter->
MoveTo(o->dst_ptr, left, top);
1606 n->pitch = o->pitch;
1608 if (height > o->height - top) {
1609 height = o->height - top;
1610 if (height <= 0)
return false;
1637 _cursor.total_offs = offs;
1640 int right = std::max(_cursor.total_offs.x + _cursor.
total_size.x, offs.x + size.x);
1641 int bottom = std::max(_cursor.total_offs.y + _cursor.
total_size.y, offs.y + size.y);
1642 if (offs.x < _cursor.total_offs.x) _cursor.total_offs.x = offs.x;
1643 if (offs.y < _cursor.total_offs.y) _cursor.total_offs.y = offs.y;
1644 _cursor.
total_size.x = right - _cursor.total_offs.x;
1645 _cursor.
total_size.y = bottom - _cursor.total_offs.y;
1649 _cursor.
dirty =
true;
1670 static void SwitchAnimatedCursor()
1685 SwitchAnimatedCursor();
1726 SwitchAnimatedCursor();
1739 this->
delta.x = delta_x;
1740 this->
delta.y = delta_y;
1755 return this->
delta.x != 0 || this->
delta.y != 0;
1756 }
else if (this->
pos.x != x || this->pos.y != y) {
1765 bool ChangeResInGame(
int width,
int height)
1770 bool ToggleFullScreen(
bool fs)
1774 Debug(driver, 0,
"Could not find a suitable fullscreen resolution");
1779 void SortResolutions()
1838 auto zoom_shift = old_gui_zoom -
_gui_zoom;
1841 w->left = (w->left *
_gui_scale) / old_scale;
1844 if (w->viewport !=
nullptr) {
1852 void ChangeGameSpeed(
bool enable_fast_forward)
1854 if (enable_fast_forward) {
Palette _cur_palette
Current palette.
uint16_t height
Height of the sprite.
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.
@ TC_FORCED
Ignore colour changes from strings.
void SetMouseCursorBusy(bool busy)
Set or unset the ZZZ cursor.
bool UpdateCursorPosition(int x, int y)
Update cursor position on mouse movement.
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.
@ SA_HOR_MASK
Mask for horizontal alignment.
Collection of variables for cursor-display and -animation.
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.
@ ZOOM_LVL_OUT_2X
Zoomed 2 times out.
static byte _string_colourremap[3]
Recoloursprite for stringdrawing. The grf loader ensures that SpriteType::Font sprites only use colou...
int16_t x_offs
Number of pixels to shift the sprite to the right.
@ PALETTE_TEXT_RECOLOUR
Set if palette is actually a magic text recolour.
const AnimCursor * animate_cur
in case of animated cursor, current frame
const Sprite * GetGlyph(FontSize size, char32_t key)
Get the Sprite for a glyph.
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 darkening remapping.
virtual void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)=0
Draw a colourtable to the screen.
FontCache * fc
The font we are using.
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
Class to backup a specific variable and restore it later.
void GfxFillPolygon(const std::vector< Point > &shape, int colour, FillRectMode mode)
Fill a polygon with colour.
How all blitters should look like.
int sprite_height
Real height of the sprite.
bool visible
cursor is visible
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const uint8_t PC_WHITE
White palette colour.
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
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.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
virtual uint8_t GetScreenDepth()=0
Get the screen depth this blitter works for.
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
virtual void SetPixel(void *video, int x, int y, uint8_t colour)=0
Draw a pixel with a given colour on the video-buffer.
SpriteID sprite
The 'real' sprite.
void * dst
Destination buffer.
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
byte GetCharacterWidth(FontSize size, char32_t key)
Return width of character glyph.
@ FS_LARGE
Index of the large font in the font tables.
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.
bool _ctrl_pressed
Is Ctrl pressed?
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
uint GetStringListWidth(const StringID *list, FontSize fontsize)
Get maximum width of a list of strings.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
int sprite_width
Real width of the sprite.
std::unique_ptr< uint32_t[]> DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom)
Draws a sprite to a new RGBA buffer (see Colour union) instead of drawing to the screen.
ZoomLevel
All zoom levels we know.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
@ SA_BOTTOM
Bottom align the text.
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.
static void SetColourRemap(TextColour colour)
Set the colour remap to be for the given colour.
FillRectMode
Define the operation GfxFillRect performs.
void UpdateCursorPositionRelative(int delta_x, int delta_y)
Update cursor position based on a relative change.
@ SA_RIGHT
Right align the text (must be a single bit).
@ SA_VERT_CENTER
Vertically center the text.
ZoomLevel _gui_zoom
GUI Zoom level.
Point draw_size
position and size bounding-box for drawing
virtual void ClearSystemSprites()
Clear all cached sprites.
Used to only draw a part of the sprite.
uint32_t PaletteID
The number of the palette.
ZoomLevel zoom_max
maximum zoom out level
Point sprite_pos[16]
relative position of individual sprites
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
int _gui_scale
GUI scale, 100 is 100%.
int GetStringLineCount(StringID str, int maxw)
Calculates number of lines of string.
virtual bool GetDrawGlyphShadow()=0
Do we need to draw a glyph shadow?
@ Recolour
Recolour sprite.
static void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t 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...
void UpdateCursorSize()
Update cursor dimension.
@ 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.
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
bool AdjustGUIZoom(bool automatic)
Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested.
bool include(Container &container, typename Container::const_reference &item)
Helper function to append an item to a container if it is not already contained.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
const void * sprite
Pointer to the sprite how ever the encoder stored it.
int _gui_scale_cfg
GUI scale in config.
@ ZOOM_LVL_MIN
Minimum zoom level.
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.
uint16_t fast_forward_speed_limit
Game speed to use when fast-forward is enabled.
virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash=0)=0
Draw a line with a given colour.
@ 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
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
virtual size_t BufferSize(uint width, uint height)=0
Calculate how much memory there is needed for an image of this size in the video-buffer.
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
@ FS_SMALL
Index of the small font in the font tables.
Dimension GetBounds()
Get the boundaries of this paragraph.
@ BM_COLOUR_REMAP
Perform a colour remapping.
The layouter performs all the layout work.
uint16_t width
Width of the sprite.
uint GetGlyphWidth(FontSize size, char32_t key)
Get the width of a glyph.
PauseMode _pause_mode
The current pause mode.
static const byte _string_colourmap[17]
Colour mapping for TextColour.
@ 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
@ BM_CRASH_REMAP
Perform a crash remapping.
CursorID sprite
Must be set to LAST_ANIM when it is the last sprite of the loop.
std::vector< Dimension > _resolutions
List of resolutions.
uint32_t CursorID
The number of the cursor (sprite)
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
std::chrono::steady_clock::time_point _switch_mode_time
The time when the switch mode was requested.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
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'.
uint32_t GlyphID
Glyphs are characters from a 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.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
PauseMode
Modes of pausing we've got.
@ BM_BLACK_REMAP
Perform remapping to a completely blackened sprite.
void SetAnimatedMouseCursor(const AnimCursor *table)
Assign an animation to the cursor.
uint16_t _game_speed
Current game-speed; 100 is 1x, 0 is infinite.
GameMode
Mode which defines the state of the game.
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.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ 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.
Iterable ensemble of all valid Windows.
Container with information about a font.
byte GetDigitWidth(FontSize size)
Return the maximum width of single digit.
int UnScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
uint32_t data
Conversion of the channel information to a 32 bit number.
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.
Visual run contains data about the bit of text with the same font.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
ZoomLevel zoom_min
minimum zoom out level
TextColour colour
The colour this font has to be.
SwitchMode _switch_mode
The next mainloop command.
ZoomLevel _font_zoom
Sprite font Zoom level (not clamped)
virtual GlyphID MapCharToGlyph(char32_t key, bool fallback=true)=0
Map a character into a glyph.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
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 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
int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (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...
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
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...
virtual void DrawRect(void *video, int width, int height, uint8_t colour)=0
Make a single horizontal line in a single colour on the video-buffer.
int16_t y_offs
Number of pixels to shift the sprite downwards.
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
static byte _stringwidth_table[FS_END][224]
Cache containing width of often used characters.
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.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
void GfxClearFontSpriteCache()
Remove all encoded font sprites from the sprite cache without discarding sprite location information.
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.
A single sprite of a list of animated cursors.
virtual int GetSuggestedUIScale()
Get a suggested default GUI scale taking screen DPI into account.
void DrawCharCentered(char32_t c, const Rect &r, TextColour colour)
Draw single character horizontally centered around (x,y)
@ SA_LEFT
Left align the text.
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
virtual void CopyFromBuffer(void *video, const void *src, int width, int height)=0
Copy from a buffer to the screen.
PalSpriteID sprite_seq[16]
current image of cursor
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
#define lengthof(x)
Return the length of an fixed size array.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
void DrawRectOutline(const Rect &r, int colour, int width, int dash)
Draw the outline of a Rect.
Parameters related to blitting.
@ FS_MONO
Index of the monospaced font in the font tables.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
@ ZOOM_LVL_NORMAL
The normal zoom level.
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Point GetCharPosInString(std::string_view 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.
PaletteID pal
The palette (use PAL_NONE) if not needed)
Point GetCharPosition(std::string_view::const_iterator ch) const
Get the position of a character in the layout.
int height
The height in pixels that needs to be drawn to dst.
FontSize
Available font sizes.
ptrdiff_t GetCharAtPosition(std::string_view str, int x, FontSize start_fontsize)
Get the character from a string that is drawn at a specific position.
Data structure for an opened window.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
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)
bool _right_button_clicked
Is right mouse button clicked?
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Data structure describing a sprite.
bool in_window
mouse inside this window, determines drawing logic
const byte * remap
XXX – Temporary storage for remap array.
@ BM_TRANSPARENT_REMAP
Perform transparency colour remapping.
void UpdateGUIZoom()
Resolve GUI zoom level, if auto-suggestion is requested.
constexpr T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
bool _left_button_clicked
Is left mouse button clicked?
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
@ Normal
The most basic (normal) sprite.
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.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
GUISettings gui
settings related to the GUI
Data about how and where to blit pixels.
ptrdiff_t GetCharAtPosition(int x, size_t line_index) const
Get the character that is at a pixel position in the first line of the layouted text.
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
Draw a sprite in a viewport.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.