OpenTTD Source: src/gfx.cpp Source File

OpenTTD Source 13.2.1

gfx.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "gfx_layout.h"
12 #include "progress.h"
13 #include "zoom_func.h"
14 #include "blitter/factory.hpp"
15 #include "video/video_driver.hpp"
16 #include "strings_func.h"
17 #include "settings_type.h"
18 #include "network/network.h"
19 #include "network/network_func.h"
20 #include "window_gui.h"
21 #include "window_func.h"
22 #include "newgrf_debug.h"
23 #include "thread.h"
24 #include "core/backup_type.hpp"
25 #include "viewport_func.h"
26
27 #include "table/palettes.h"
28 #include "table/string_colours.h"
29 #include "table/sprites.h"
30 #include "table/control_codes.h"
31
32 #include "safeguards.h"
33
34 byte _dirkeys;
35 bool _fullscreen;
36 byte _support8bpp;
37 CursorVars _cursor;
38 bool _ctrl_pressed;
39 bool _shift_pressed;
40 uint16 _game_speed = 100;
41 bool _left_button_down;
42 bool _left_button_clicked;
43 bool _right_button_down;
44 bool _right_button_clicked;
45 DrawPixelInfo _screen;
46 bool _screen_disable_anim = false;
47 std::atomic<bool> _exit_game;
48 GameMode _game_mode;
49 SwitchMode _switch_mode;
50 PauseMode _pause_mode;
51 Palette _cur_palette;
52
53 static byte _stringwidth_table[FS_END][224];
54 DrawPixelInfo *_cur_dpi;
55 byte _colour_gradient[COLOUR_END][8];
56
57 static std::recursive_mutex _palette_mutex;
58
59 static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = nullptr, SpriteID sprite_id = SPR_CURSOR_MOUSE);
60 static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = nullptr, SpriteID sprite_id = SPR_CURSOR_MOUSE, ZoomLevel zoom = ZOOM_LVL_NORMAL);
61
62 static ReusableBuffer<uint8> _cursor_backup;
63
64 ZoomLevel _gui_zoom = ZOOM_LVL_OUT_4X;
65 int _gui_scale = MIN_INTERFACE_SCALE;
66 int _gui_scale_cfg;
67
75 static Rect _invalid_rect;
76 static const byte *_colour_remap_ptr;
77 static byte _string_colourremap[3];
78
79 static const uint DIRTY_BLOCK_HEIGHT = 8;
80 static const uint DIRTY_BLOCK_WIDTH = 64;
81
82 static uint _dirty_bytes_per_line = 0;
83 static byte *_dirty_blocks = nullptr;
84 extern uint _dirty_block_colour;
85
86 void GfxScroll(int left, int top, int width, int height, int xo, int yo)
87 {
88 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
89
90 if (xo == 0 && yo == 0) return;
91
92 if (_cursor.visible) UndrawMouseCursor();
93
94 if (_networking) NetworkUndrawChatMessage();
95
96 blitter->ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo);
97 /* This part of the screen is now dirty. */
98 VideoDriver::GetInstance()->MakeDirty(left, top, width, height);
99 }
100
101
116 void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
117 {
118 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
119 const DrawPixelInfo *dpi = _cur_dpi;
120 void *dst;
121 const int otop = top;
122 const int oleft = left;
123
124 if (dpi->zoom != ZOOM_LVL_NORMAL) return;
125 if (left > right || top > bottom) return;
126 if (right < dpi->left || left >= dpi->left + dpi->width) return;
127 if (bottom < dpi->top || top >= dpi->top + dpi->height) return;
128
129 if ( (left -= dpi->left) < 0) left = 0;
130 right = right - dpi->left + 1;
131 if (right > dpi->width) right = dpi->width;
132 right -= left;
133 assert(right > 0);
134
135 if ( (top -= dpi->top) < 0) top = 0;
136 bottom = bottom - dpi->top + 1;
137 if (bottom > dpi->height) bottom = dpi->height;
138 bottom -= top;
139 assert(bottom > 0);
140
141 dst = blitter->MoveTo(dpi->dst_ptr, left, top);
142
143 switch (mode) {
144 default: // FILLRECT_OPAQUE
145 blitter->DrawRect(dst, right, bottom, (uint8)colour);
146 break;
147
148 case FILLRECT_RECOLOUR:
149 blitter->DrawColourMappingRect(dst, right, bottom, GB(colour, 0, PALETTE_WIDTH));
150 break;
151
152 case FILLRECT_CHECKER: {
153 byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
154 do {
155 for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)colour);
156 dst = blitter->MoveTo(dst, 0, 1);
157 } while (--bottom > 0);
158 break;
159 }
160 }
161 }
162
163 typedef std::pair<Point, Point> LineSegment;
164
173 static std::vector<LineSegment> MakePolygonSegments(const std::vector<Point> &shape, Point offset)
174 {
175 std::vector<LineSegment> segments;
176 if (shape.size() < 3) return segments; // fewer than 3 will always result in an empty polygon
177 segments.reserve(shape.size());
178
179 /* Connect first and last point by having initial previous point be the last */
180 Point prev = shape.back();
181 prev.x -= offset.x;
182 prev.y -= offset.y;
183 for (Point pt : shape) {
184 pt.x -= offset.x;
185 pt.y -= offset.y;
186 /* Create segments for all non-horizontal lines in the polygon.
187 * The segments always have lowest Y coordinate first. */
188 if (prev.y > pt.y) {
189 segments.emplace_back(pt, prev);
190 } else if (prev.y < pt.y) {
191 segments.emplace_back(prev, pt);
192 }
193 prev = pt;
194 }
195
196 return segments;
197 }
198
212 void GfxFillPolygon(const std::vector<Point> &shape, int colour, FillRectMode mode)
213 {
214 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
215 const DrawPixelInfo *dpi = _cur_dpi;
216 if (dpi->zoom != ZOOM_LVL_NORMAL) return;
217
218 std::vector<LineSegment> segments = MakePolygonSegments(shape, Point{ dpi->left, dpi->top });
219
220 /* Remove segments appearing entirely above or below the clipping area. */
221 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());
222
223 /* Check that this wasn't an empty shape (all points on a horizontal line or outside clipping.) */
224 if (segments.empty()) return;
225
226 /* Sort the segments by first point Y coordinate. */
227 std::sort(segments.begin(), segments.end(), [](const LineSegment &a, const LineSegment &b) { return a.first.y < b.first.y; });
228
229 /* Segments intersecting current scanline. */
230 std::vector<LineSegment> active;
231 /* Intersection points with a scanline.
232 * Kept outside loop to avoid repeated re-allocations. */
233 std::vector<int> intersections;
234 /* Normal, reasonable polygons don't have many intersections per scanline. */
235 active.reserve(4);
236 intersections.reserve(4);
237
238 /* Scan through the segments and paint each scanline. */
239 int y = segments.front().first.y;
240 std::vector<LineSegment>::iterator nextseg = segments.begin();
241 while (!active.empty() || nextseg != segments.end()) {
242 /* Clean up segments that have ended. */
243 active.erase(std::remove_if(active.begin(), active.end(), [y](const LineSegment &s) { return s.second.y == y; }), active.end());
244
245 /* Activate all segments starting on this scanline. */
246 while (nextseg != segments.end() && nextseg->first.y == y) {
247 active.push_back(*nextseg);
248 ++nextseg;
249 }
250
251 /* Check clipping. */
252 if (y < 0) {
253 ++y;
254 continue;
255 }
256 if (y >= dpi->height) return;
257
258 /* Intersect scanline with all active segments. */
259 intersections.clear();
260 for (const LineSegment &s : active) {
261 const int sdx = s.second.x - s.first.x;
262 const int sdy = s.second.y - s.first.y;
263 const int ldy = y - s.first.y;
264 const int x = s.first.x + sdx * ldy / sdy;
265 intersections.push_back(x);
266 }
267
268 /* Fill between pairs of intersections. */
269 std::sort(intersections.begin(), intersections.end());
270 for (size_t i = 1; i < intersections.size(); i += 2) {
271 /* Check clipping. */
272 const int x1 = std::max(0, intersections[i - 1]);
273 const int x2 = std::min(intersections[i], dpi->width);
274 if (x2 < 0) continue;
275 if (x1 >= dpi->width) continue;
276
277 /* Fill line y from x1 to x2. */
278 void *dst = blitter->MoveTo(dpi->dst_ptr, x1, y);
279 switch (mode) {
280 default: // FILLRECT_OPAQUE
281 blitter->DrawRect(dst, x2 - x1, 1, (uint8)colour);
282 break;
283 case FILLRECT_RECOLOUR:
284 blitter->DrawColourMappingRect(dst, x2 - x1, 1, GB(colour, 0, PALETTE_WIDTH));
285 break;
286 case FILLRECT_CHECKER:
287 /* Fill every other pixel, offset such that the sum of filled pixels' X and Y coordinates is odd.
288 * This creates a checkerboard effect. */
289 for (int x = (x1 + y) & 1; x < x2 - x1; x += 2) {
290 blitter->SetPixel(dst, x, 0, (uint8)colour);
291 }
292 break;
293 }
294 }
295
296 /* Next line */
297 ++y;
298 }
299 }
300
315 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)
316 {
317 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
318
319 assert(width > 0);
320
321 if (y2 == y || x2 == x) {
322 /* Special case: horizontal/vertical line. All checks already done in GfxPreprocessLine. */
323 blitter->DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width, dash);
324 return;
325 }
326
327 int grade_y = y2 - y;
328 int grade_x = x2 - x;
329
330 /* Clipping rectangle. Slightly extended so we can ignore the width of the line. */
331 int extra = (int)CeilDiv(3 * width, 4); // not less then "width * sqrt(2) / 2"
332 Rect clip = { -extra, -extra, screen_width - 1 + extra, screen_height - 1 + extra };
333
334 /* prevent integer overflows. */
335 int margin = 1;
336 while (INT_MAX / abs(grade_y) < std::max(abs(clip.left - x), abs(clip.right - x))) {
337 grade_y /= 2;
338 grade_x /= 2;
339 margin *= 2; // account for rounding errors
340 }
341
342 /* Imagine that the line is infinitely long and it intersects with
343 * infinitely long left and right edges of the clipping rectangle.
344 * If both intersection points are outside the clipping rectangle
345 * and both on the same side of it, we don't need to draw anything. */
346 int left_isec_y = y + (clip.left - x) * grade_y / grade_x;
347 int right_isec_y = y + (clip.right - x) * grade_y / grade_x;
348 if ((left_isec_y > clip.bottom + margin && right_isec_y > clip.bottom + margin) ||
349 (left_isec_y < clip.top - margin && right_isec_y < clip.top - margin)) {
350 return;
351 }
352
353 /* It is possible to use the line equation to further reduce the amount of
354 * work the blitter has to do by shortening the effective line segment.
355 * However, in order to get that right and prevent the flickering effects
356 * of rounding errors so much additional code has to be run here that in
357 * the general case the effect is not noticeable. */
358
359 blitter->DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width, dash);
360 }
361
373 static inline bool GfxPreprocessLine(DrawPixelInfo *dpi, int &x, int &y, int &x2, int &y2, int width)
374 {
375 x -= dpi->left;
376 x2 -= dpi->left;
377 y -= dpi->top;
378 y2 -= dpi->top;
379
380 /* Check simple clipping */
381 if (x + width / 2 < 0 && x2 + width / 2 < 0 ) return false;
382 if (y + width / 2 < 0 && y2 + width / 2 < 0 ) return false;
383 if (x - width / 2 > dpi->width && x2 - width / 2 > dpi->width ) return false;
384 if (y - width / 2 > dpi->height && y2 - width / 2 > dpi->height) return false;
385 return true;
386 }
387
388 void GfxDrawLine(int x, int y, int x2, int y2, int colour, int width, int dash)
389 {
390 DrawPixelInfo *dpi = _cur_dpi;
391 if (GfxPreprocessLine(dpi, x, y, x2, y2, width)) {
392 GfxDoDrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, colour, width, dash);
393 }
394 }
395
396 void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int colour)
397 {
398 DrawPixelInfo *dpi = _cur_dpi;
399 if (GfxPreprocessLine(dpi, x, y, x2, y2, 1)) {
400 GfxDoDrawLine(dpi->dst_ptr,
401 UnScaleByZoom(x, dpi->zoom), UnScaleByZoom(y, dpi->zoom),
402 UnScaleByZoom(x2, dpi->zoom), UnScaleByZoom(y2, dpi->zoom),
403 UnScaleByZoom(dpi->width, dpi->zoom), UnScaleByZoom(dpi->height, dpi->zoom), colour, 1);
404 }
405 }
406
420 void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
421 {
422 /* ....
423 * .. ....
424 * .. ....
425 * .. ^
426 * <--__(dx1,dy1) /(dx2,dy2)
427 * : --__ / :
428 * : --__ / :
429 * : *(x,y) :
430 * : | :
431 * : | ..
432 * .... |(dx3,dy3)
433 * .... | ..
434 * ....V.
435 */
436
437 static const byte colour = PC_WHITE;
438
439 GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, colour);
440 GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, colour);
441 GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, colour);
442
443 GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, colour);
444 GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, colour);
445 GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, colour);
446 GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, colour);
447 GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, colour);
448 GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, colour);
449 }
450
455 static void SetColourRemap(TextColour colour)
456 {
457 if (colour == TC_INVALID) return;
458
459 /* Black strings have no shading ever; the shading is black, so it
460 * would be invisible at best, but it actually makes it illegible. */
461 bool no_shade = (colour & TC_NO_SHADE) != 0 || colour == TC_BLACK;
462 bool raw_colour = (colour & TC_IS_PALETTE_COLOUR) != 0;
463 colour &= ~(TC_NO_SHADE | TC_IS_PALETTE_COLOUR | TC_FORCED);
464
465 _string_colourremap[1] = raw_colour ? (byte)colour : _string_colourmap[colour];
466 _string_colourremap[2] = no_shade ? 0 : 1;
467 _colour_remap_ptr = _string_colourremap;
468 }
469
485 static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left, int right, StringAlignment align, bool underline, bool truncation)
486 {
487 if (line.CountRuns() == 0) return 0;
488
489 int w = line.GetWidth();
490 int h = line.GetLeading();
491
492 /*
493 * The following is needed for truncation.
494 * Depending on the text direction, we either remove bits at the rear
495 * or the front. For this we shift the entire area to draw so it fits
496 * within the left/right bounds and the side we do not truncate it on.
497 * Then we determine the truncation location, i.e. glyphs that fall
498 * outside of the range min_x - max_x will not be drawn; they are thus
499 * the truncated glyphs.
500 *
501 * At a later step we insert the dots.
502 */
503
504 int max_w = right - left + 1; // The maximum width.
505
506 int offset_x = 0; // The offset we need for positioning the glyphs
507 int min_x = left; // The minimum x position to draw normal glyphs on.
508 int max_x = right; // The maximum x position to draw normal glyphs on.
509
510 truncation &= max_w < w; // Whether we need to do truncation.
511 int dot_width = 0; // Cache for the width of the dot.
512 const Sprite *dot_sprite = nullptr; // Cache for the sprite of the dot.
513
514 if (truncation) {
515 /*
516 * Assumption may be made that all fonts of a run are of the same size.
517 * In any case, we'll use these dots for the abbreviation, so even if
518 * another size would be chosen it won't have truncated too little for
519 * the truncation dots.
520 */
521 FontCache *fc = ((const Font*)line.GetVisualRun(0).GetFont())->fc;
522 GlyphID dot_glyph = fc->MapCharToGlyph('.');
523 dot_width = fc->GetGlyphWidth(dot_glyph);
524 dot_sprite = fc->GetGlyph(dot_glyph);
525
526 if (_current_text_dir == TD_RTL) {
527 min_x += 3 * dot_width;
528 offset_x = w - 3 * dot_width - max_w;
529 } else {
530 max_x -= 3 * dot_width;
531 }
532
533 w = max_w;
534 }
535
536 /* In case we have a RTL language we swap the alignment. */
537 if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT;
538
539 /* right is the right most position to draw on. In this case we want to do
540 * calculations with the width of the string. In comparison right can be
541 * seen as lastof(todraw) and width as lengthof(todraw). They differ by 1.
542 * So most +1/-1 additions are to move from lengthof to 'indices'.
543 */
544 switch (align & SA_HOR_MASK) {
545 case SA_LEFT:
546 /* right + 1 = left + w */
547 right = left + w - 1;
548 break;
549
550 case SA_HOR_CENTER:
551 left = RoundDivSU(right + 1 + left - w, 2);
552 /* right + 1 = left + w */
553 right = left + w - 1;
554 break;
555
556 case SA_RIGHT:
557 left = right + 1 - w;
558 break;
559
560 default:
561 NOT_REACHED();
562 }
563
564 const uint shadow_offset = ScaleGUITrad(1);
565
566 TextColour colour = TC_BLACK;
567 bool draw_shadow = false;
568 for (int run_index = 0; run_index < line.CountRuns(); run_index++) {
569 const ParagraphLayouter::VisualRun &run = line.GetVisualRun(run_index);
570 const Font *f = (const Font*)run.GetFont();
571
572 FontCache *fc = f->fc;
573 colour = f->colour;
574 SetColourRemap(colour);
575
576 DrawPixelInfo *dpi = _cur_dpi;
577 int dpi_left = dpi->left;
578 int dpi_right = dpi->left + dpi->width - 1;
579
580 draw_shadow = fc->GetDrawGlyphShadow() && (colour & TC_NO_SHADE) == 0 && colour != TC_BLACK;
581
582 for (int i = 0; i < run.GetGlyphCount(); i++) {
583 GlyphID glyph = run.GetGlyphs()[i];
584
585 /* Not a valid glyph (empty) */
586 if (glyph == 0xFFFF) continue;
587
588 int begin_x = (int)run.GetPositions()[i * 2] + left - offset_x;
589 int end_x = (int)run.GetPositions()[i * 2 + 2] + left - offset_x - 1;
590 int top = (int)run.GetPositions()[i * 2 + 1] + y;
591
592 /* Truncated away. */
593 if (truncation && (begin_x < min_x || end_x > max_x)) continue;
594
595 const Sprite *sprite = fc->GetGlyph(glyph);
596 /* Check clipping (the "+ 1" is for the shadow). */
597 if (begin_x + sprite->x_offs > dpi_right || begin_x + sprite->x_offs + sprite->width /* - 1 + 1 */ < dpi_left) continue;
598
599 if (draw_shadow && (glyph & SPRITE_GLYPH) == 0) {
600 SetColourRemap(TC_BLACK);
601 GfxMainBlitter(sprite, begin_x + shadow_offset, top + shadow_offset, BM_COLOUR_REMAP);
602 SetColourRemap(colour);
603 }
604 GfxMainBlitter(sprite, begin_x, top, BM_COLOUR_REMAP);
605 }
606 }
607
608 if (truncation) {
609 int x = (_current_text_dir == TD_RTL) ? left : (right - 3 * dot_width);
610 for (int i = 0; i < 3; i++, x += dot_width) {
611 if (draw_shadow) {
612 SetColourRemap(TC_BLACK);
613 GfxMainBlitter(dot_sprite, x + shadow_offset, y + shadow_offset, BM_COLOUR_REMAP);
614 SetColourRemap(colour);
615 }
616 GfxMainBlitter(dot_sprite, x, y, BM_COLOUR_REMAP);
617 }
618 }
619
620 if (underline) {
621 GfxFillRect(left, y + h, right, y + h, _string_colourremap[1]);
622 }
623
624 return (align & SA_HOR_MASK) == SA_RIGHT ? left : right;
625 }
626
644 int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
645 {
646 /* The string may contain control chars to change the font, just use the biggest font for clipping. */
647 int max_height = std::max({FONT_HEIGHT_SMALL, FONT_HEIGHT_NORMAL, FONT_HEIGHT_LARGE, FONT_HEIGHT_MONO});
648
649 /* Funny glyphs may extent outside the usual bounds, so relax the clipping somewhat. */
650 int extra = max_height / 2;
651
652 if (_cur_dpi->top + _cur_dpi->height + extra < top || _cur_dpi->top > top + max_height + extra ||
653 _cur_dpi->left + _cur_dpi->width + extra < left || _cur_dpi->left > right + extra) {
654 return 0;
655 }
656
657 Layouter layout(str, INT32_MAX, colour, fontsize);
658 if (layout.size() == 0) return 0;
659
660 return DrawLayoutLine(*layout.front(), top, left, right, align, underline, true);
661 }
662
680 int DrawString(int left, int right, int top, const std::string &str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
681 {
682 return DrawString(left, right, top, str.c_str(), colour, align, underline, fontsize);
683 }
684
702 int DrawString(int left, int right, int top, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
703 {
704 char buffer[DRAW_STRING_BUFFER];
705 GetString(buffer, str, lastof(buffer));
706 return DrawString(left, right, top, buffer, colour, align, underline, fontsize);
707 }
708
715 int GetStringHeight(const char *str, int maxw, FontSize fontsize)
716 {
717 Layouter layout(str, maxw, TC_FROMSTRING, fontsize);
718 return layout.GetBounds().height;
719 }
720
727 int GetStringHeight(StringID str, int maxw)
728 {
729 char buffer[DRAW_STRING_BUFFER];
730 GetString(buffer, str, lastof(buffer));
731 return GetStringHeight(buffer, maxw);
732 }
733
740 int GetStringLineCount(StringID str, int maxw)
741 {
742 char buffer[DRAW_STRING_BUFFER];
743 GetString(buffer, str, lastof(buffer));
744
745 Layouter layout(buffer, maxw);
746 return (uint)layout.size();
747 }
748
755 Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
756 {
757 Dimension box = {suggestion.width, (uint)GetStringHeight(str, suggestion.width)};
758 return box;
759 }
760
767 Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion)
768 {
769 Dimension box = {suggestion.width, (uint)GetStringHeight(str, suggestion.width)};
770 return box;
771 }
772
789 int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
790 {
791 int maxw = right - left + 1;
792 int maxh = bottom - top + 1;
793
794 /* It makes no sense to even try if it can't be drawn anyway, or
795 * do we really want to support fonts of 0 or less pixels high? */
796 if (maxh <= 0) return top;
797
798 Layouter layout(str, maxw, colour, fontsize);
799 int total_height = layout.GetBounds().height;
800 int y;
801 switch (align & SA_VERT_MASK) {
802 case SA_TOP:
803 y = top;
804 break;
805
806 case SA_VERT_CENTER:
807 y = RoundDivSU(bottom + top - total_height, 2);
808 break;
809
810 case SA_BOTTOM:
811 y = bottom - total_height;
812 break;
813
814 default: NOT_REACHED();
815 }
816
817 int last_line = top;
818 int first_line = bottom;
819
820 for (const auto &line : layout) {
821
822 int line_height = line->GetLeading();
823 if (y >= top && y + line_height - 1 <= bottom) {
824 last_line = y + line_height;
825 if (first_line > y) first_line = y;
826
827 DrawLayoutLine(*line, y, left, right, align, underline, false);
828 }
829 y += line_height;
830 }
831
832 return ((align & SA_VERT_MASK) == SA_BOTTOM) ? first_line : last_line;
833 }
834
835
852 int DrawStringMultiLine(int left, int right, int top, int bottom, const std::string &str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
853 {
854 return DrawStringMultiLine(left, right, top, bottom, str.c_str(), colour, align, underline, fontsize);
855 }
856
873 int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
874 {
875 char buffer[DRAW_STRING_BUFFER];
876 GetString(buffer, str, lastof(buffer));
877 return DrawStringMultiLine(left, right, top, bottom, buffer, colour, align, underline, fontsize);
878 }
879
890 Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
891 {
892 Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
893 return layout.GetBounds();
894 }
895
906 Dimension GetStringBoundingBox(const std::string &str, FontSize start_fontsize)
907 {
908 return GetStringBoundingBox(str.c_str(), start_fontsize);
909 }
910
917 Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize)
918 {
919 char buffer[DRAW_STRING_BUFFER];
920
921 GetString(buffer, strid, lastof(buffer));
922 return GetStringBoundingBox(buffer, start_fontsize);
923 }
924
931 uint GetStringListWidth(const StringID *list, FontSize fontsize)
932 {
933 uint width = 0;
934 for (const StringID *str = list; *str != INVALID_STRING_ID; str++) {
935 width = std::max(width, GetStringBoundingBox(*str, fontsize).width);
936 }
937 return width;
938 }
939
948 Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize)
949 {
950 Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
951 return layout.GetCharPosition(ch);
952 }
953
961 const char *GetCharAtPosition(const char *str, int x, FontSize start_fontsize)
962 {
963 if (x < 0) return nullptr;
964
965 Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
966 return layout.GetCharAtPosition(x);
967 }
968
976 void DrawCharCentered(WChar c, const Rect &r, TextColour colour)
977 {
978 SetColourRemap(colour);
979 GfxMainBlitter(GetGlyph(FS_NORMAL, c),
980 CenterBounds(r.left, r.right, GetCharacterWidth(FS_NORMAL, c)),
981 CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL),
982 BM_COLOUR_REMAP);
983 }
984
993 Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
994 {
995 const Sprite *sprite = GetSprite(sprid, ST_NORMAL);
996
997 if (offset != nullptr) {
998 offset->x = UnScaleByZoom(sprite->x_offs, zoom);
999 offset->y = UnScaleByZoom(sprite->y_offs, zoom);
1000 }
1001
1002 Dimension d;
1003 d.width = std::max<int>(0, UnScaleByZoom(sprite->x_offs + sprite->width, zoom));
1004 d.height = std::max<int>(0, UnScaleByZoom(sprite->y_offs + sprite->height, zoom));
1005 return d;
1006 }
1007
1013 static BlitterMode GetBlitterMode(PaletteID pal)
1014 {
1015 switch (pal) {
1016 case PAL_NONE: return BM_NORMAL;
1017 case PALETTE_CRASH: return BM_CRASH_REMAP;
1018 case PALETTE_ALL_BLACK: return BM_BLACK_REMAP;
1019 default: return BM_COLOUR_REMAP;
1020 }
1021 }
1022
1031 void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
1032 {
1033 SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
1034 if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
1035 _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
1036 GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite);
1037 } else if (pal != PAL_NONE) {
1038 if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
1039 SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
1040 } else {
1041 _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
1042 }
1043 GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite);
1044 } else {
1045 GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite);
1046 }
1047 }
1048
1058 void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
1059 {
1060 SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
1061 if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
1062 _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
1063 GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite, zoom);
1064 } else if (pal != PAL_NONE) {
1065 if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
1066 SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
1067 } else {
1068 _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
1069 }
1070 GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite, zoom);
1071 } else {
1072 GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite, zoom);
1073 }
1074 }
1075
1088 template <int ZOOM_BASE, bool SCALED_XY>
1089 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)
1090 {
1091 const DrawPixelInfo *dpi = (dst != nullptr) ? dst : _cur_dpi;
1092 Blitter::BlitterParams bp;
1093
1094 if (SCALED_XY) {
1095 /* Scale it */
1096 x = ScaleByZoom(x, zoom);
1097 y = ScaleByZoom(y, zoom);
1098 }
1099
1100 /* Move to the correct offset */
1101 x += sprite->x_offs;
1102 y += sprite->y_offs;
1103
1104 if (sub == nullptr) {
1105 /* No clipping. */
1106 bp.skip_left = 0;
1107 bp.skip_top = 0;
1108 bp.width = UnScaleByZoom(sprite->width, zoom);
1109 bp.height = UnScaleByZoom(sprite->height, zoom);
1110 } else {
1111 /* Amount of pixels to clip from the source sprite */
1112 int clip_left = std::max(0, -sprite->x_offs + sub->left * ZOOM_BASE );
1113 int clip_top = std::max(0, -sprite->y_offs + sub->top * ZOOM_BASE );
1114 int clip_right = std::max(0, sprite->width - (-sprite->x_offs + (sub->right + 1) * ZOOM_BASE));
1115 int clip_bottom = std::max(0, sprite->height - (-sprite->y_offs + (sub->bottom + 1) * ZOOM_BASE));
1116
1117 if (clip_left + clip_right >= sprite->width) return;
1118 if (clip_top + clip_bottom >= sprite->height) return;
1119
1120 bp.skip_left = UnScaleByZoomLower(clip_left, zoom);
1121 bp.skip_top = UnScaleByZoomLower(clip_top, zoom);
1122 bp.width = UnScaleByZoom(sprite->width - clip_left - clip_right, zoom);
1123 bp.height = UnScaleByZoom(sprite->height - clip_top - clip_bottom, zoom);
1124
1125 x += ScaleByZoom(bp.skip_left, zoom);
1126 y += ScaleByZoom(bp.skip_top, zoom);
1127 }
1128
1129 /* Copy the main data directly from the sprite */
1130 bp.sprite = sprite->data;
1131 bp.sprite_width = sprite->width;
1132 bp.sprite_height = sprite->height;
1133 bp.top = 0;
1134 bp.left = 0;
1135
1136 bp.dst = dpi->dst_ptr;
1137 bp.pitch = dpi->pitch;
1138 bp.remap = _colour_remap_ptr;
1139
1140 assert(sprite->width > 0);
1141 assert(sprite->height > 0);
1142
1143 if (bp.width <= 0) return;
1144 if (bp.height <= 0) return;
1145
1146 y -= SCALED_XY ? ScaleByZoom(dpi->top, zoom) : dpi->top;
1147 int y_unscaled = UnScaleByZoom(y, zoom);
1148 /* Check for top overflow */
1149 if (y < 0) {
1150 bp.height -= -y_unscaled;
1151 if (bp.height <= 0) return;
1152 bp.skip_top += -y_unscaled;
1153 y = 0;
1154 } else {
1155 bp.top = y_unscaled;
1156 }
1157
1158 /* Check for bottom overflow */
1159 y += SCALED_XY ? ScaleByZoom(bp.height - dpi->height, zoom) : ScaleByZoom(bp.height, zoom) - dpi->height;
1160 if (y > 0) {
1161 bp.height -= UnScaleByZoom(y, zoom);
1162 if (bp.height <= 0) return;
1163 }
1164
1165 x -= SCALED_XY ? ScaleByZoom(dpi->left, zoom) : dpi->left;
1166 int x_unscaled = UnScaleByZoom(x, zoom);
1167 /* Check for left overflow */
1168 if (x < 0) {
1169 bp.width -= -x_unscaled;
1170 if (bp.width <= 0) return;
1171 bp.skip_left += -x_unscaled;
1172 x = 0;
1173 } else {
1174 bp.left = x_unscaled;
1175 }
1176
1177 /* Check for right overflow */
1178 x += SCALED_XY ? ScaleByZoom(bp.width - dpi->width, zoom) : ScaleByZoom(bp.width, zoom) - dpi->width;
1179 if (x > 0) {
1180 bp.width -= UnScaleByZoom(x, zoom);
1181 if (bp.width <= 0) return;
1182 }
1183
1184 assert(bp.skip_left + bp.width <= UnScaleByZoom(sprite->width, zoom));
1185 assert(bp.skip_top + bp.height <= UnScaleByZoom(sprite->height, zoom));
1186
1187 /* We do not want to catch the mouse. However we also use that spritenumber for unknown (text) sprites. */
1188 if (_newgrf_debug_sprite_picker.mode == SPM_REDRAW && sprite_id != SPR_CURSOR_MOUSE) {
1189 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
1190 void *topleft = blitter->MoveTo(bp.dst, bp.left, bp.top);
1191 void *bottomright = blitter->MoveTo(topleft, bp.width - 1, bp.height - 1);
1192
1193 void *clicked = _newgrf_debug_sprite_picker.clicked_pixel;
1194
1195 if (topleft <= clicked && clicked <= bottomright) {
1196 uint offset = (((size_t)clicked - (size_t)topleft) / (blitter->GetScreenDepth() / 8)) % bp.pitch;
1197 if (offset < (uint)bp.width) {
1198 include(_newgrf_debug_sprite_picker.sprites, sprite_id);
1199 }
1200 }
1201 }
1202
1203 BlitterFactory::GetCurrentBlitter()->Draw(&bp, mode, zoom);
1204 }
1205
1213 std::unique_ptr<uint32[]> DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom)
1214 {
1215 /* Invalid zoom level requested? */
1216 if (zoom < _settings_client.gui.zoom_min || zoom > _settings_client.gui.zoom_max) return nullptr;
1217
1218 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
1219 if (blitter->GetScreenDepth() != 8 && blitter->GetScreenDepth() != 32) return nullptr;
1220
1221 /* Gather information about the sprite to write, reserve memory */
1222 const SpriteID real_sprite = GB(spriteId, 0, SPRITE_WIDTH);
1223 const Sprite *sprite = GetSprite(real_sprite, ST_NORMAL);
1224 Dimension dim = GetSpriteSize(real_sprite, nullptr, zoom);
1225 std::unique_ptr<uint32[]> result(new uint32[dim.width * dim.height]);
1226 /* Set buffer to fully transparent. */
1227 MemSetT(result.get(), 0, dim.width * dim.height);
1228
1229 /* Prepare new DrawPixelInfo - Normally this would be the screen but we want to draw to another buffer here.
1230 * Normally, pitch would be scaled screen width, but in our case our "screen" is only the sprite width wide. */
1231 DrawPixelInfo dpi;
1232 dpi.dst_ptr = result.get();
1233 dpi.pitch = dim.width;
1234 dpi.left = 0;
1235 dpi.top = 0;
1236 dpi.width = dim.width;
1237 dpi.height = dim.height;
1238 dpi.zoom = zoom;
1239
1240 /* If the current blitter is a paletted blitter, we have to render to an extra buffer and resolve the palette later. */
1241 std::unique_ptr<byte[]> pal_buffer{};
1242 if (blitter->GetScreenDepth() == 8) {
1243 pal_buffer.reset(new byte[dim.width * dim.height]);
1244 MemSetT(pal_buffer.get(), 0, dim.width * dim.height);
1245
1246 dpi.dst_ptr = pal_buffer.get();
1247 }
1248
1249 /* Temporarily disable screen animations while blitting - This prevents 40bpp_anim from writing to the animation buffer. */
1250 Backup<bool> disable_anim(_screen_disable_anim, true, FILE_LINE);
1251 GfxBlitter<1, true>(sprite, 0, 0, BM_NORMAL, nullptr, real_sprite, zoom, &dpi);
1252 disable_anim.Restore();
1253
1254 if (blitter->GetScreenDepth() == 8) {
1255 /* Resolve palette. */
1256 uint32 *dst = result.get();
1257 const byte *src = pal_buffer.get();
1258 for (size_t i = 0; i < dim.height * dim.width; ++i) {
1259 *dst++ = _cur_palette.palette[*src++].data;
1260 }
1261 }
1262
1263 return result;
1264 }
1265
1266 static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub, SpriteID sprite_id)
1267 {
1268 GfxBlitter<ZOOM_LVL_BASE, false>(sprite, x, y, mode, sub, sprite_id, _cur_dpi->zoom);
1269 }
1270
1271 static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub, SpriteID sprite_id, ZoomLevel zoom)
1272 {
1273 GfxBlitter<1, true>(sprite, x, y, mode, sub, sprite_id, zoom);
1274 }
1275
1276 void DoPaletteAnimations();
1277
1278 void GfxInitPalettes()
1279 {
1280 std::lock_guard<std::recursive_mutex> lock(_palette_mutex);
1281 memcpy(&_cur_palette, &_palette, sizeof(_cur_palette));
1282 DoPaletteAnimations();
1283 }
1284
1294 bool CopyPalette(Palette &local_palette, bool force_copy)
1295 {
1296 std::lock_guard<std::recursive_mutex> lock(_palette_mutex);
1297
1298 if (!force_copy && _cur_palette.count_dirty == 0) return false;
1299
1300 local_palette = _cur_palette;
1301 _cur_palette.count_dirty = 0;
1302
1303 if (force_copy) {
1304 local_palette.first_dirty = 0;
1305 local_palette.count_dirty = 256;
1306 }
1307
1308 return true;
1309 }
1310
1311 #define EXTR(p, q) (((uint16)(palette_animation_counter * (p)) * (q)) >> 16)
1312 #define EXTR2(p, q) (((uint16)(~palette_animation_counter * (p)) * (q)) >> 16)
1313
1314 void DoPaletteAnimations()
1315 {
1316 std::lock_guard<std::recursive_mutex> lock(_palette_mutex);
1317
1318 /* Animation counter for the palette animation. */
1319 static int palette_animation_counter = 0;
1320 palette_animation_counter += 8;
1321
1322 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
1323 const Colour *s;
1324 const ExtraPaletteValues *ev = &_extra_palette_values;
1325 Colour old_val[PALETTE_ANIM_SIZE];
1326 const uint old_tc = palette_animation_counter;
1327 uint i;
1328 uint j;
1329
1330 if (blitter != nullptr && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
1331 palette_animation_counter = 0;
1332 }
1333
1334 Colour *palette_pos = &_cur_palette.palette[PALETTE_ANIM_START]; // Points to where animations are taking place on the palette
1335 /* Makes a copy of the current animation palette in old_val,
1336 * so the work on the current palette could be compared, see if there has been any changes */
1337 memcpy(old_val, palette_pos, sizeof(old_val));
1338
1339 /* Fizzy Drink bubbles animation */
1340 s = ev->fizzy_drink;
1341 j = EXTR2(512, EPV_CYCLES_FIZZY_DRINK);
1342 for (i = 0; i != EPV_CYCLES_FIZZY_DRINK; i++) {
1343 *palette_pos++ = s[j];
1344 j++;
1345 if (j == EPV_CYCLES_FIZZY_DRINK) j = 0;
1346 }
1347
1348 /* Oil refinery fire animation */
1349 s = ev->oil_refinery;
1350 j = EXTR2(512, EPV_CYCLES_OIL_REFINERY);
1351 for (i = 0; i != EPV_CYCLES_OIL_REFINERY; i++) {
1352 *palette_pos++ = s[j];
1353 j++;
1354 if (j == EPV_CYCLES_OIL_REFINERY) j = 0;
1355 }
1356
1357 /* Radio tower blinking */
1358 {
1359 byte i = (palette_animation_counter >> 1) & 0x7F;
1360 byte v;
1361
1362 if (i < 0x3f) {
1363 v = 255;
1364 } else if (i < 0x4A || i >= 0x75) {
1365 v = 128;
1366 } else {
1367 v = 20;
1368 }
1369 palette_pos->r = v;
1370 palette_pos->g = 0;
1371 palette_pos->b = 0;
1372 palette_pos++;
1373
1374 i ^= 0x40;
1375 if (i < 0x3f) {
1376 v = 255;
1377 } else if (i < 0x4A || i >= 0x75) {
1378 v = 128;
1379 } else {
1380 v = 20;
1381 }
1382 palette_pos->r = v;
1383 palette_pos->g = 0;
1384 palette_pos->b = 0;
1385 palette_pos++;
1386 }
1387
1388 /* Handle lighthouse and stadium animation */
1389 s = ev->lighthouse;
1390 j = EXTR(256, EPV_CYCLES_LIGHTHOUSE);
1391 for (i = 0; i != EPV_CYCLES_LIGHTHOUSE; i++) {
1392 *palette_pos++ = s[j];
1393 j++;
1394 if (j == EPV_CYCLES_LIGHTHOUSE) j = 0;
1395 }
1396
1397 /* Dark blue water */
1398 s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->dark_water_toyland : ev->dark_water;
1399 j = EXTR(320, EPV_CYCLES_DARK_WATER);
1400 for (i = 0; i != EPV_CYCLES_DARK_WATER; i++) {
1401 *palette_pos++ = s[j];
1402 j++;
1403 if (j == EPV_CYCLES_DARK_WATER) j = 0;
1404 }
1405
1406 /* Glittery water */
1407 s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->glitter_water_toyland : ev->glitter_water;
1408 j = EXTR(128, EPV_CYCLES_GLITTER_WATER);
1409 for (i = 0; i != EPV_CYCLES_GLITTER_WATER / 3; i++) {
1410 *palette_pos++ = s[j];
1411 j += 3;
1412 if (j >= EPV_CYCLES_GLITTER_WATER) j -= EPV_CYCLES_GLITTER_WATER;
1413 }
1414
1415 if (blitter != nullptr && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
1416 palette_animation_counter = old_tc;
1417 } else {
1418 if (memcmp(old_val, &_cur_palette.palette[PALETTE_ANIM_START], sizeof(old_val)) != 0 && _cur_palette.count_dirty == 0) {
1419 /* Did we changed anything on the palette? Seems so. Mark it as dirty */
1420 _cur_palette.first_dirty = PALETTE_ANIM_START;
1421 _cur_palette.count_dirty = PALETTE_ANIM_SIZE;
1422 }
1423 }
1424 }
1425
1432 TextColour GetContrastColour(uint8 background, uint8 threshold)
1433 {
1434 Colour c = _cur_palette.palette[background];
1435 /* Compute brightness according to http://www.w3.org/TR/AERT#color-contrast.
1436 * The following formula computes 1000 * brightness^2, with brightness being in range 0 to 255. */
1437 uint sq1000_brightness = c.r * c.r * 299 + c.g * c.g * 587 + c.b * c.b * 114;
1438 /* Compare with threshold brightness which defaults to 128 (50%) */
1439 return sq1000_brightness < ((uint) threshold) * ((uint) threshold) * 1000 ? TC_WHITE : TC_BLACK;
1440 }
1441
1446 void LoadStringWidthTable(bool monospace)
1447 {
1448 ClearFontCache();
1449
1450 for (FontSize fs = monospace ? FS_MONO : FS_BEGIN; fs < (monospace ? FS_END : FS_MONO); fs++) {
1451 for (uint i = 0; i != 224; i++) {
1452 _stringwidth_table[fs][i] = GetGlyphWidth(fs, i + 32);
1453 }
1454 }
1455
1456 ReInitAllWindows(false);
1457 }
1458
1465 byte GetCharacterWidth(FontSize size, WChar key)
1466 {
1467 /* Use _stringwidth_table cache if possible */
1468 if (key >= 32 && key < 256) return _stringwidth_table[size][key - 32];
1469
1470 return GetGlyphWidth(size, key);
1471 }
1472
1478 byte GetDigitWidth(FontSize size)
1479 {
1480 byte width = 0;
1481 for (char c = '0'; c <= '9'; c++) {
1482 width = std::max(GetCharacterWidth(size, c), width);
1483 }
1484 return width;
1485 }
1486
1493 void GetBroadestDigit(uint *front, uint *next, FontSize size)
1494 {
1495 int width = -1;
1496 for (char c = '9'; c >= '0'; c--) {
1497 int w = GetCharacterWidth(size, c);
1498 if (w > width) {
1499 width = w;
1500 *next = c - '0';
1501 if (c != '0') *front = c - '0';
1502 }
1503 }
1504 }
1505
1506 void ScreenSizeChanged()
1507 {
1508 _dirty_bytes_per_line = CeilDiv(_screen.width, DIRTY_BLOCK_WIDTH);
1509 _dirty_blocks = ReallocT<byte>(_dirty_blocks, _dirty_bytes_per_line * CeilDiv(_screen.height, DIRTY_BLOCK_HEIGHT));
1510
1511 /* check the dirty rect */
1512 if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width;
1513 if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height;
1514
1515 /* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */
1516 _cursor.visible = false;
1517 }
1518
1519 void UndrawMouseCursor()
1520 {
1521 /* Don't undraw mouse cursor if it is handled by the video driver. */
1522 if (VideoDriver::GetInstance()->UseSystemCursor()) return;
1523
1524 /* Don't undraw the mouse cursor if the screen is not ready */
1525 if (_screen.dst_ptr == nullptr) return;
1526
1527 if (_cursor.visible) {
1528 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
1529 _cursor.visible = false;
1530 blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup.GetBuffer(), _cursor.draw_size.x, _cursor.draw_size.y);
1531 VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
1532 }
1533 }
1534
1535 void DrawMouseCursor()
1536 {
1537 /* Don't draw mouse cursor if it is handled by the video driver. */
1538 if (VideoDriver::GetInstance()->UseSystemCursor()) return;
1539
1540 /* Don't draw the mouse cursor if the screen is not ready */
1541 if (_screen.dst_ptr == nullptr) return;
1542
1543 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
1544
1545 /* Redraw mouse cursor but only when it's inside the window */
1546 if (!_cursor.in_window) return;
1547
1548 /* Don't draw the mouse cursor if it's already drawn */
1549 if (_cursor.visible) {
1550 if (!_cursor.dirty) return;
1551 UndrawMouseCursor();
1552 }
1553
1554 /* Determine visible area */
1555 int left = _cursor.pos.x + _cursor.total_offs.x;
1556 int width = _cursor.total_size.x;
1557 if (left < 0) {
1558 width += left;
1559 left = 0;
1560 }
1561 if (left + width > _screen.width) {
1562 width = _screen.width - left;
1563 }
1564 if (width <= 0) return;
1565
1566 int top = _cursor.pos.y + _cursor.total_offs.y;
1567 int height = _cursor.total_size.y;
1568 if (top < 0) {
1569 height += top;
1570 top = 0;
1571 }
1572 if (top + height > _screen.height) {
1573 height = _screen.height - top;
1574 }
1575 if (height <= 0) return;
1576
1577 _cursor.draw_pos.x = left;
1578 _cursor.draw_pos.y = top;
1579 _cursor.draw_size.x = width;
1580 _cursor.draw_size.y = height;
1581
1582 uint8 *buffer = _cursor_backup.Allocate(blitter->BufferSize(_cursor.draw_size.x, _cursor.draw_size.y));
1583
1584 /* Make backup of stuff below cursor */
1585 blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), buffer, _cursor.draw_size.x, _cursor.draw_size.y);
1586
1587 /* Draw cursor on screen */
1588 _cur_dpi = &_screen;
1589 for (uint i = 0; i < _cursor.sprite_count; ++i) {
1590 DrawSprite(_cursor.sprite_seq[i].sprite, _cursor.sprite_seq[i].pal, _cursor.pos.x + _cursor.sprite_pos[i].x, _cursor.pos.y + _cursor.sprite_pos[i].y);
1591 }
1592
1593 VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
1594
1595 _cursor.visible = true;
1596 _cursor.dirty = false;
1597 }
1598
1609 void RedrawScreenRect(int left, int top, int right, int bottom)
1610 {
1611 assert(right <= _screen.width && bottom <= _screen.height);
1612 if (_cursor.visible) {
1613 if (right > _cursor.draw_pos.x &&
1614 left < _cursor.draw_pos.x + _cursor.draw_size.x &&
1615 bottom > _cursor.draw_pos.y &&
1616 top < _cursor.draw_pos.y + _cursor.draw_size.y) {
1617 UndrawMouseCursor();
1618 }
1619 }
1620
1621 if (_networking) NetworkUndrawChatMessage();
1622
1623 DrawOverlappedWindowForAll(left, top, right, bottom);
1624
1625 VideoDriver::GetInstance()->MakeDirty(left, top, right - left, bottom - top);
1626 }
1627
1635 void DrawDirtyBlocks()
1636 {
1637 byte *b = _dirty_blocks;
1638 const int w = Align(_screen.width, DIRTY_BLOCK_WIDTH);
1639 const int h = Align(_screen.height, DIRTY_BLOCK_HEIGHT);
1640 int x;
1641 int y;
1642
1643 y = 0;
1644 do {
1645 x = 0;
1646 do {
1647 if (*b != 0) {
1648 int left;
1649 int top;
1650 int right = x + DIRTY_BLOCK_WIDTH;
1651 int bottom = y;
1652 byte *p = b;
1653 int h2;
1654
1655 /* First try coalescing downwards */
1656 do {
1657 *p = 0;
1658 p += _dirty_bytes_per_line;
1659 bottom += DIRTY_BLOCK_HEIGHT;
1660 } while (bottom != h && *p != 0);
1661
1662 /* Try coalescing to the right too. */
1663 h2 = (bottom - y) / DIRTY_BLOCK_HEIGHT;
1664 assert(h2 > 0);
1665 p = b;
1666
1667 while (right != w) {
1668 byte *p2 = ++p;
1669 int h = h2;
1670 /* Check if a full line of dirty flags is set. */
1671 do {
1672 if (!*p2) goto no_more_coalesc;
1673 p2 += _dirty_bytes_per_line;
1674 } while (--h != 0);
1675
1676 /* Wohoo, can combine it one step to the right!
1677 * Do that, and clear the bits. */
1678 right += DIRTY_BLOCK_WIDTH;
1679
1680 h = h2;
1681 p2 = p;
1682 do {
1683 *p2 = 0;
1684 p2 += _dirty_bytes_per_line;
1685 } while (--h != 0);
1686 }
1687 no_more_coalesc:
1688
1689 left = x;
1690 top = y;
1691
1692 if (left < _invalid_rect.left ) left = _invalid_rect.left;
1693 if (top < _invalid_rect.top ) top = _invalid_rect.top;
1694 if (right > _invalid_rect.right ) right = _invalid_rect.right;
1695 if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom;
1696
1697 if (left < right && top < bottom) {
1698 RedrawScreenRect(left, top, right, bottom);
1699 }
1700
1701 }
1702 } while (b++, (x += DIRTY_BLOCK_WIDTH) != w);
1703 } while (b += -(int)(w / DIRTY_BLOCK_WIDTH) + _dirty_bytes_per_line, (y += DIRTY_BLOCK_HEIGHT) != h);
1704
1705 ++_dirty_block_colour;
1706 _invalid_rect.left = w;
1707 _invalid_rect.top = h;
1708 _invalid_rect.right = 0;
1709 _invalid_rect.bottom = 0;
1710 }
1711
1724 void AddDirtyBlock(int left, int top, int right, int bottom)
1725 {
1726 byte *b;
1727 int width;
1728 int height;
1729
1730 if (left < 0) left = 0;
1731 if (top < 0) top = 0;
1732 if (right > _screen.width) right = _screen.width;
1733 if (bottom > _screen.height) bottom = _screen.height;
1734
1735 if (left >= right || top >= bottom) return;
1736
1737 if (left < _invalid_rect.left ) _invalid_rect.left = left;
1738 if (top < _invalid_rect.top ) _invalid_rect.top = top;
1739 if (right > _invalid_rect.right ) _invalid_rect.right = right;
1740 if (bottom > _invalid_rect.bottom) _invalid_rect.bottom = bottom;
1741
1742 left /= DIRTY_BLOCK_WIDTH;
1743 top /= DIRTY_BLOCK_HEIGHT;
1744
1745 b = _dirty_blocks + top * _dirty_bytes_per_line + left;
1746
1747 width = ((right - 1) / DIRTY_BLOCK_WIDTH) - left + 1;
1748 height = ((bottom - 1) / DIRTY_BLOCK_HEIGHT) - top + 1;
1749
1750 assert(width > 0 && height > 0);
1751
1752 do {
1753 int i = width;
1754
1755 do b[--i] = 0xFF; while (i != 0);
1756
1757 b += _dirty_bytes_per_line;
1758 } while (--height != 0);
1759 }
1760
1767 void MarkWholeScreenDirty()
1768 {
1769 AddDirtyBlock(0, 0, _screen.width, _screen.height);
1770 }
1771
1786 bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
1787 {
1788 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
1789 const DrawPixelInfo *o = _cur_dpi;
1790
1791 n->zoom = ZOOM_LVL_NORMAL;
1792
1793 assert(width > 0);
1794 assert(height > 0);
1795
1796 if ((left -= o->left) < 0) {
1797 width += left;
1798 if (width <= 0) return false;
1799 n->left = -left;
1800 left = 0;
1801 } else {
1802 n->left = 0;
1803 }
1804
1805 if (width > o->width - left) {
1806 width = o->width - left;
1807 if (width <= 0) return false;
1808 }
1809 n->width = width;
1810
1811 if ((top -= o->top) < 0) {
1812 height += top;
1813 if (height <= 0) return false;
1814 n->top = -top;
1815 top = 0;
1816 } else {
1817 n->top = 0;
1818 }
1819
1820 n->dst_ptr = blitter->MoveTo(o->dst_ptr, left, top);
1821 n->pitch = o->pitch;
1822
1823 if (height > o->height - top) {
1824 height = o->height - top;
1825 if (height <= 0) return false;
1826 }
1827 n->height = height;
1828
1829 return true;
1830 }
1831
1836 void UpdateCursorSize()
1837 {
1838 /* Ignore setting any cursor before the sprites are loaded. */
1839 if (GetMaxSpriteID() == 0) return;
1840
1841 static_assert(lengthof(_cursor.sprite_seq) == lengthof(_cursor.sprite_pos));
1842 assert(_cursor.sprite_count <= lengthof(_cursor.sprite_seq));
1843 for (uint i = 0; i < _cursor.sprite_count; ++i) {
1844 const Sprite *p = GetSprite(GB(_cursor.sprite_seq[i].sprite, 0, SPRITE_WIDTH), ST_NORMAL);
1845 Point offs, size;
1846 offs.x = UnScaleGUI(p->x_offs) + _cursor.sprite_pos[i].x;
1847 offs.y = UnScaleGUI(p->y_offs) + _cursor.sprite_pos[i].y;
1848 size.x = UnScaleGUI(p->width);
1849 size.y = UnScaleGUI(p->height);
1850
1851 if (i == 0) {
1852 _cursor.total_offs = offs;
1853 _cursor.total_size = size;
1854 } else {
1855 int right = std::max(_cursor.total_offs.x + _cursor.total_size.x, offs.x + size.x);
1856 int bottom = std::max(_cursor.total_offs.y + _cursor.total_size.y, offs.y + size.y);
1857 if (offs.x < _cursor.total_offs.x) _cursor.total_offs.x = offs.x;
1858 if (offs.y < _cursor.total_offs.y) _cursor.total_offs.y = offs.y;
1859 _cursor.total_size.x = right - _cursor.total_offs.x;
1860 _cursor.total_size.y = bottom - _cursor.total_offs.y;
1861 }
1862 }
1863
1864 _cursor.dirty = true;
1865 }
1866
1872 static void SetCursorSprite(CursorID cursor, PaletteID pal)
1873 {
1874 if (_cursor.sprite_count == 1 && _cursor.sprite_seq[0].sprite == cursor && _cursor.sprite_seq[0].pal == pal) return;
1875
1876 _cursor.sprite_count = 1;
1877 _cursor.sprite_seq[0].sprite = cursor;
1878 _cursor.sprite_seq[0].pal = pal;
1879 _cursor.sprite_pos[0].x = 0;
1880 _cursor.sprite_pos[0].y = 0;
1881
1882 UpdateCursorSize();
1883 }
1884
1885 static void SwitchAnimatedCursor()
1886 {
1887 const AnimCursor *cur = _cursor.animate_cur;
1888
1889 if (cur == nullptr || cur->sprite == AnimCursor::LAST) cur = _cursor.animate_list;
1890
1891 SetCursorSprite(cur->sprite, _cursor.sprite_seq[0].pal);
1892
1893 _cursor.animate_timeout = cur->display_time;
1894 _cursor.animate_cur = cur + 1;
1895 }
1896
1897 void CursorTick()
1898 {
1899 if (_cursor.animate_timeout != 0 && --_cursor.animate_timeout == 0) {
1900 SwitchAnimatedCursor();
1901 }
1902 }
1903
1908 void SetMouseCursorBusy(bool busy)
1909 {
1910 if (busy) {
1911 if (_cursor.sprite_seq[0].sprite == SPR_CURSOR_MOUSE) SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
1912 } else {
1913 if (_cursor.sprite_seq[0].sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
1914 }
1915 }
1916
1923 void SetMouseCursor(CursorID sprite, PaletteID pal)
1924 {
1925 /* Turn off animation */
1926 _cursor.animate_timeout = 0;
1927 /* Set cursor */
1928 SetCursorSprite(sprite, pal);
1929 }
1930
1936 void SetAnimatedMouseCursor(const AnimCursor *table)
1937 {
1938 _cursor.animate_list = table;
1939 _cursor.animate_cur = nullptr;
1940 _cursor.sprite_seq[0].pal = PAL_NONE;
1941 SwitchAnimatedCursor();
1942 }
1943
1950 void CursorVars::UpdateCursorPositionRelative(int delta_x, int delta_y)
1951 {
1952 assert(this->fix_at);
1953
1954 this->delta.x = delta_x;
1955 this->delta.y = delta_y;
1956 }
1957
1964 bool CursorVars::UpdateCursorPosition(int x, int y)
1965 {
1966 this->delta.x = x - this->pos.x;
1967 this->delta.y = y - this->pos.y;
1968
1969 if (this->fix_at) {
1970 return this->delta.x != 0 || this->delta.y != 0;
1971 } else if (this->pos.x != x || this->pos.y != y) {
1972 this->dirty = true;
1973 this->pos.x = x;
1974 this->pos.y = y;
1975 }
1976
1977 return false;
1978 }
1979
1980 bool ChangeResInGame(int width, int height)
1981 {
1982 return (_screen.width == width && _screen.height == height) || VideoDriver::GetInstance()->ChangeResolution(width, height);
1983 }
1984
1985 bool ToggleFullScreen(bool fs)
1986 {
1987 bool result = VideoDriver::GetInstance()->ToggleFullscreen(fs);
1988 if (_fullscreen != fs && _resolutions.empty()) {
1989 Debug(driver, 0, "Could not find a suitable fullscreen resolution");
1990 }
1991 return result;
1992 }
1993
1994 void SortResolutions()
1995 {
1996 std::sort(_resolutions.begin(), _resolutions.end());
1997 }
1998
2002 void UpdateGUIZoom()
2003 {
2004 /* Determine real GUI zoom to use. */
2005 if (_gui_scale_cfg == -1) {
2006 _gui_scale = VideoDriver::GetInstance()->GetSuggestedUIScale();
2007 } else {
2008 _gui_scale = Clamp(_gui_scale_cfg, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE);
2009 }
2010
2011 int8 new_zoom = ScaleGUITrad(1) <= 1 ? ZOOM_LVL_OUT_4X : ScaleGUITrad(1) >= 4 ? ZOOM_LVL_MIN : ZOOM_LVL_OUT_2X;
2012 /* Ensure the gui_zoom is clamped between min/max. */
2013 new_zoom = Clamp(new_zoom, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
2014 _gui_zoom = static_cast<ZoomLevel>(new_zoom);
2015 }
2016
2023 bool AdjustGUIZoom(bool automatic)
2024 {
2025 ZoomLevel old_zoom = _gui_zoom;
2026 int old_scale = _gui_scale;
2027 UpdateGUIZoom();
2028 if (old_scale == _gui_scale) return false;
2029
2030 /* Reload sprites if sprite zoom level has changed. */
2031 if (old_zoom != _gui_zoom) {
2032 GfxClearSpriteCache();
2033 VideoDriver::GetInstance()->ClearSystemSprites();
2034 UpdateCursorSize();
2035 }
2036
2037 ClearFontCache();
2038 LoadStringWidthTable();
2039 UpdateAllVirtCoords();
2040
2041 /* Adjust all window sizes to match the new zoom level, so that they don't appear
2042 to move around when the application is moved to a screen with different DPI. */
2043 auto zoom_shift = old_zoom - _gui_zoom;
2044 for (Window *w : Window::Iterate()) {
2045 if (automatic) {
2046 w->left = (w->left * _gui_scale) / old_scale;
2047 w->top = (w->top * _gui_scale) / old_scale;
2048 w->width = (w->width * _gui_scale) / old_scale;
2049 w->height = (w->height * _gui_scale) / old_scale;
2050 }
2051 if (w->viewport != nullptr) {
2052 w->viewport->zoom = Clamp(ZoomLevel(w->viewport->zoom - zoom_shift), _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
2053 }
2054 }
2055
2056 return true;
2057 }
2058
2059 void ChangeGameSpeed(bool enable_fast_forward)
2060 {
2061 if (enable_fast_forward) {
2062 _game_speed = _settings_client.gui.fast_forward_speed_limit;
2063 } else {
2064 _game_speed = 100;
2065 }
2066 }
_dirkeys
byte _dirkeys
1 = left, 2 = up, 4 = right, 8 = down
Definition: gfx.cpp:34
NewGrfDebugSpritePicker::clicked_pixel
void * clicked_pixel
Clicked pixel (pointer to blitter buffer)
Definition: newgrf_debug.h:28
LoadStringWidthTable
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
Definition: gfx.cpp:1446
PC_WHITE
static const uint8 PC_WHITE
White palette colour.
Definition: gfx_func.h:245
TC_FORCED
@ TC_FORCED
Ignore colour changes from strings.
Definition: gfx_type.h:278
GlyphID
uint32 GlyphID
Glyphs are characters from a font.
Definition: fontcache.h:17
SetMouseCursorBusy
void SetMouseCursorBusy(bool busy)
Set or unset the ZZZ cursor.
Definition: gfx.cpp:1908
CursorVars::UpdateCursorPosition
bool UpdateCursorPosition(int x, int y)
Update cursor position on mouse movement.
Definition: gfx.cpp:1964
SwitchMode
SwitchMode
Mode which defines what mode we're switching to.
Definition: openttd.h:25
factory.hpp
DrawBox
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
Draws the projection of a parallelepiped.
Definition: gfx.cpp:420
Palette::first_dirty
int first_dirty
The first dirty element.
Definition: gfx_type.h:321
Blitter::SetPixel
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
@ SA_HOR_MASK
Mask for horizontal alignment.
Definition: gfx_type.h:337
CursorVars
Collection of variables for cursor-display and -animation.
Definition: gfx_type.h:115
Colour::data
uint32 data
Conversion of the channel information to a 32 bit number.
Definition: gfx_type.h:160
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:36
AddDirtyBlock
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.
Definition: gfx.cpp:1724
ZOOM_LVL_OUT_2X
@ ZOOM_LVL_OUT_2X
Zoomed 2 times out.
Definition: zoom_type.h:23
UnScaleByZoomLower
static int UnScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
Definition: zoom_func.h:67
_string_colourremap
static byte _string_colourremap[3]
Recoloursprite for stringdrawing. The grf loader ensures that ST_FONT sprites only use colours 0 to 2...
Definition: gfx.cpp:77
ExtraPaletteValues
Description of tables for the palette animation.
Definition: palettes.h:104
PALETTE_TEXT_RECOLOUR
@ PALETTE_TEXT_RECOLOUR
Set if palette is actually a magic text recolour.
Definition: sprites.h:1520
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
CursorVars::animate_cur
const AnimCursor * animate_cur
in case of animated cursor, current frame
Definition: gfx_type.h:136
ReusableBuffer
A reusable buffer that can be used for places that temporary allocate a bit of memory and do that ver...
Definition: alloc_type.hpp:24
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Blitter::BlitterParams::top
int top
The top offset in the 'dst' in pixels to start drawing.
Definition: base.hpp:42
BM_TRANSPARENT
@ BM_TRANSPARENT
Perform transparency colour remapping.
Definition: base.hpp:20
Blitter::DrawColourMappingRect
virtual void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)=0
Draw a colourtable to the screen.
CursorVars::sprite_count
uint sprite_count
number of sprites to draw
Definition: gfx_type.h:130
palettes.h
Blitter::BlitterParams::skip_left
int skip_left
How much pixels of the source to skip on the left (based on zoom of dst)
Definition: base.hpp:35
CursorVars::dirty
bool dirty
the rect occupied by the mouse is dirty (redraw)
Definition: gfx_type.h:140
BlitterMode
BlitterMode
The modes of blitting we can do.
Definition: base.hpp:17
_left_button_down
bool _left_button_down
Is left mouse button pressed?
Definition: gfx.cpp:41
Blitter::BlitterParams::width
int width
The width in pixels that needs to be drawn to dst.
Definition: base.hpp:37
SPRITE_WIDTH
@ SPRITE_WIDTH
number of bits for the sprite number
Definition: sprites.h:1523
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:328
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
PALETTE_ANIM_SIZE
@ PALETTE_ANIM_SIZE
number of animated colours
Definition: gfx_type.h:287
Blitter::UsePaletteAnimation
virtual Blitter::PaletteAnimation UsePaletteAnimation()=0
Check if the blitter uses palette animation at all.
Sprite::data
byte data[]
Sprite data.
Definition: spritecache.h:22
GfxFillPolygon
void GfxFillPolygon(const std::vector< Point > &shape, int colour, FillRectMode mode)
Fill a polygon with colour.
Definition: gfx.cpp:212
lock
std::mutex lock
synchronization for playback status fields
Definition: win32_m.cpp:34
FS_BEGIN
@ FS_BEGIN
First font.
Definition: gfx_type.h:209
GetContrastColour
TextColour GetContrastColour(uint8 background, uint8 threshold)
Determine a contrasty text colour for a coloured background.
Definition: gfx.cpp:1432
Blitter
How all blitters should look like.
Definition: base.hpp:28
ExtraPaletteValues::lighthouse
Colour lighthouse[EPV_CYCLES_LIGHTHOUSE]
lighthouse & stadium
Definition: palettes.h:107
_palette
static const Palette _palette
Colour palette (DOS)
Definition: palettes.h:15
Blitter::BlitterParams::sprite_height
int sprite_height
Real height of the sprite.
Definition: base.hpp:40
CursorVars::visible
bool visible
cursor is visible
Definition: gfx_type.h:139
_newgrf_debug_sprite_picker
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
Definition: newgrf_debug_gui.cpp:48
Blitter::GetScreenDepth
virtual uint8 GetScreenDepth()=0
Get the screen depth this blitter works for.
Blitter::CopyToBuffer
virtual void CopyToBuffer(const void *video, void *dst, int width, int height)=0
Copy from the screen to a buffer.
FILLRECT_RECOLOUR
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:295
NewGrfDebugSpritePicker::sprites
std::vector< SpriteID > sprites
Sprites found.
Definition: newgrf_debug.h:29
VideoDriver::MakeDirty
virtual void MakeDirty(int left, int top, int width, int height)=0
Mark a particular area dirty.
VideoDriver::ToggleFullscreen
virtual bool ToggleFullscreen(bool fullscreen)=0
Change the full screen setting.
NewGrfDebugSpritePicker::mode
NewGrfDebugSpritePickerMode mode
Current state.
Definition: newgrf_debug.h:27
CursorVars::animate_list
const AnimCursor * animate_list
in case of animated cursor, list of frames
Definition: gfx_type.h:135
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
Blitter::BlitterParams::dst
void * dst
Destination buffer.
Definition: base.hpp:44
UnScaleGUI
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:77
include
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,...
Definition: smallvec_type.hpp:27
Blitter::ScrollBuffer
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.
Sprite::height
uint16 height
Height of the sprite.
Definition: spritecache.h:18
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:294
GetStringListWidth
uint GetStringListWidth(const StringID *list, FontSize fontsize)
Get maximum width of a list of strings.
Definition: gfx.cpp:931
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
zoom_func.h
Sprite::x_offs
int16 x_offs
Number of pixels to shift the sprite to the right.
Definition: spritecache.h:20
Blitter::BlitterParams::sprite_width
int sprite_width
Real width of the sprite.
Definition: base.hpp:39
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:341
Layouter::GetCharPosition
Point GetCharPosition(const char *ch) const
Get the position of a character in the layout.
Definition: gfx_layout.cpp:768
Blitter::BlitterParams::pitch
int pitch
The pitch of the destination buffer.
Definition: base.hpp:45
StringAlignment
StringAlignment
How to align the to-be drawn text.
Definition: gfx_type.h:333
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
DrawString
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.
Definition: gfx.cpp:644
SetColourRemap
static void SetColourRemap(TextColour colour)
Set the colour remap to be for the given colour.
Definition: gfx.cpp:455
newgrf_debug.h
FillRectMode
FillRectMode
Define the operation GfxFillRect performs.
Definition: gfx_type.h:292
ST_NORMAL
@ ST_NORMAL
The most basic (normal) sprite.
Definition: gfx_type.h:308
CursorVars::UpdateCursorPositionRelative
void UpdateCursorPositionRelative(int delta_x, int delta_y)
Update cursor position based on a relative change.
Definition: gfx.cpp:1950
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:336
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition: gfx_type.h:340
EPV_CYCLES_FIZZY_DRINK
static const uint EPV_CYCLES_FIZZY_DRINK
length of the fizzy drinks animation
Definition: palettes.h:100
_gui_zoom
ZoomLevel _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:64
GfxDoDrawLine
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...
Definition: gfx.cpp:315
CursorVars::draw_size
Point draw_size
position and size bounding-box for drawing
Definition: gfx_type.h:133
VideoDriver::ClearSystemSprites
virtual void ClearSystemSprites()
Clear all cached sprites.
Definition: video_driver.hpp:108
SubSprite
Used to only draw a part of the sprite.
Definition: gfx_type.h:225
GUISettings::zoom_max
ZoomLevel zoom_max
maximum zoom out level
Definition: settings_type.h:135
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:55
CursorVars::sprite_pos
Point sprite_pos[16]
relative position of individual sprites
Definition: gfx_type.h:129
Blitter::DrawRect
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.
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
_gui_scale
int _gui_scale
GUI scale, 100 is 100%.
Definition: gfx.cpp:65
GetStringLineCount
int GetStringLineCount(StringID str, int maxw)
Calculates number of lines of string.
Definition: gfx.cpp:740
DrawStringMultiLine
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.
Definition: gfx.cpp:789
_palette_mutex
static std::recursive_mutex _palette_mutex
To coordinate access to _cur_palette.
Definition: gfx.cpp:57
FontCache::GetDrawGlyphShadow
virtual bool GetDrawGlyphShadow()=0
Do we need to draw a glyph shadow?
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
control_codes.h
UpdateCursorSize
void UpdateCursorSize()
Update cursor dimension.
Definition: gfx.cpp:1836
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
BM_NORMAL
@ BM_NORMAL
Perform the simple blitting.
Definition: base.hpp:18
ParagraphLayouter::Line
A single line worth of VisualRuns.
Definition: gfx_layout.h:135
DrawLayoutLine
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.
Definition: gfx.cpp:485
_extra_palette_values
static const ExtraPaletteValues _extra_palette_values
Actual palette animation tables.
Definition: palettes.h:115
AdjustGUIZoom
bool AdjustGUIZoom(bool automatic)
Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested.
Definition: gfx.cpp:2023
ExtraPaletteValues::oil_refinery
Colour oil_refinery[EPV_CYCLES_OIL_REFINERY]
oil refinery
Definition: palettes.h:108
Blitter::BlitterParams::sprite
const void * sprite
Pointer to the sprite how ever the encoder stored it.
Definition: base.hpp:32
window_gui.h
_gui_scale_cfg
int _gui_scale_cfg
GUI scale in config.
Definition: gfx.cpp:66
ZOOM_LVL_MIN
@ ZOOM_LVL_MIN
Minimum zoom level.
Definition: zoom_type.h:45
DrawOverlappedWindowForAll
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
From a rectangle that needs redrawing, find the windows that intersect with the rectangle.
Definition: window.cpp:985
Blitter::Draw
virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)=0
Draw an image to the screen, given an amount of params defined above.
DRAW_STRING_BUFFER
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
Definition: gfx_func.h:86
Blitter::DrawLine
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.
GUISettings::fast_forward_speed_limit
uint16 fast_forward_speed_limit
Game speed to use when fast-forward is enabled.
Definition: settings_type.h:178
Align
static T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
Definition: math_func.hpp:35
CursorID
uint32 CursorID
The number of the cursor (sprite)
Definition: gfx_type.h:19
ExtraPaletteValues::glitter_water_toyland
Colour glitter_water_toyland[EPV_CYCLES_GLITTER_WATER]
glittery water Toyland
Definition: palettes.h:111
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:339
SetMouseCursor
void SetMouseCursor(CursorID sprite, PaletteID pal)
Assign a single non-animated sprite to the cursor.
Definition: gfx.cpp:1923
PALETTE_WIDTH
@ PALETTE_WIDTH
number of bits of the sprite containing the recolour palette
Definition: sprites.h:1522
ReInitAllWindows
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
Definition: window.cpp:3377
GfxClearSpriteCache
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information.
Definition: spritecache.cpp:1042
_screen_disable_anim
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
Definition: gfx.cpp:46
Palette::palette
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition: gfx_type.h:320
Layouter::GetBounds
Dimension GetBounds()
Get the boundaries of this paragraph.
Definition: gfx_layout.cpp:752
BM_COLOUR_REMAP
@ BM_COLOUR_REMAP
Perform a colour remapping.
Definition: base.hpp:19
Layouter
The layouter performs all the layout work.
Definition: gfx_layout.h:154
DrawSpriteToRgbaBuffer
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.
Definition: gfx.cpp:1213
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:50
FONT_HEIGHT_MONO
#define FONT_HEIGHT_MONO
Height of characters in the large (FS_MONO) font.
Definition: gfx_func.h:212
_string_colourmap
static const byte _string_colourmap[17]
Colour mapping for TextColour.
Definition: string_colours.h:11
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
TC_IS_PALETTE_COLOUR
@ TC_IS_PALETTE_COLOUR
Colour value is already a real palette colour index, not an index of a StringColour.
Definition: gfx_type.h:276
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:141
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:346
CursorVars::total_size
Point total_size
union of sprite properties
Definition: gfx_type.h:131
GetCharAtPosition
const char * GetCharAtPosition(const char *str, int x, FontSize start_fontsize)
Get the character from a string that is drawn at a specific position.
Definition: gfx.cpp:961
BM_CRASH_REMAP
@ BM_CRASH_REMAP
Perform a crash remapping.
Definition: base.hpp:21
EPV_CYCLES_OIL_REFINERY
static const uint EPV_CYCLES_OIL_REFINERY
length of the oil refinery's fire animation
Definition: palettes.h:99
safeguards.h
Sprite::width
uint16 width
Width of the sprite.
Definition: spritecache.h:19
AnimCursor::sprite
CursorID sprite
Must be set to LAST_ANIM when it is the last sprite of the loop.
Definition: gfx_type.h:110
_resolutions
std::vector< Dimension > _resolutions
List of resolutions.
Definition: driver.cpp:31
CursorVars::fix_at
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
Definition: gfx_type.h:120
RedrawScreenRect
void RedrawScreenRect(int left, int top, int right, int bottom)
Repaints a specific rectangle of the screen.
Definition: gfx.cpp:1609
VideoDriver::ChangeResolution
virtual bool ChangeResolution(int w, int h)=0
Change the resolution of the window.
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition: gfx_type.h:277
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:58
_shift_pressed
bool _shift_pressed
Is Shift pressed?
Definition: gfx.cpp:39
DrawDirtyBlocks
void DrawDirtyBlocks()
Repaints the rectangle blocks which are marked as 'dirty'.
Definition: gfx.cpp:1635
FONT_HEIGHT_LARGE
#define FONT_HEIGHT_LARGE
Height of characters in the large (FS_LARGE) font.
Definition: gfx_func.h:209
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1058
gfx_layout.h
settings_type.h
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition: gfx.cpp:755
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
NetworkUndrawChatMessage
void NetworkUndrawChatMessage()
Hide the chatbox.
Definition: network_chat_gui.cpp:127
DrawCharCentered
void DrawCharCentered(WChar c, const Rect &r, TextColour colour)
Draw single character horizontally centered around (x,y)
Definition: gfx.cpp:976
PauseMode
PauseMode
Modes of pausing we've got.
Definition: openttd.h:60
BM_BLACK_REMAP
@ BM_BLACK_REMAP
Perform remapping to a completely blackened sprite.
Definition: base.hpp:22
UnScaleByZoom
static int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Definition: zoom_func.h:34
SetAnimatedMouseCursor
void SetAnimatedMouseCursor(const AnimCursor *table)
Assign an animation to the cursor.
Definition: gfx.cpp:1936
stdafx.h
GameMode
GameMode
Mode which defines the state of the game.
Definition: openttd.h:17
RoundDivSU
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
Definition: math_func.hpp:302
GfxFillRect
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.
Definition: gfx.cpp:116
FontCache::GetGlyphWidth
virtual uint GetGlyphWidth(GlyphID key)=0
Get the width of the glyph with the given key.
_invalid_rect
static Rect _invalid_rect
The rect for repaint.
Definition: gfx.cpp:75
Palette::count_dirty
int count_dirty
The number of dirty elements.
Definition: gfx_type.h:322
PALETTE_MODIFIER_TRANSPARENT
@ PALETTE_MODIFIER_TRANSPARENT
when a sprite is to be displayed transparently, this bit needs to be set.
Definition: sprites.h:1537
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:202
viewport_func.h
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:335
Window::AllWindows
Iterable ensemble of all valid Windows.
Definition: window_gui.h:803
PALETTE_ANIM_START
@ PALETTE_ANIM_START
Index in the _palettes array from which all animations are taking places (table/palettes....
Definition: gfx_type.h:288
GetDigitWidth
byte GetDigitWidth(FontSize size)
Return the maximum width of single digit.
Definition: gfx.cpp:1478
string_colours.h
GetBroadestDigit
void GetBroadestDigit(uint *front, uint *next, FontSize size)
Determine the broadest digits for guessing the maximum width of a n-digit number.
Definition: gfx.cpp:1493
FillDrawPixelInfo
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1786
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:203
ParagraphLayouter::VisualRun
Visual run contains data about the bit of text with the same font.
Definition: gfx_layout.h:123
Colour
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:159
GetGlyphWidth
static uint GetGlyphWidth(FontSize size, WChar key)
Get the width of a glyph.
Definition: fontcache.h:191
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:715
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:993
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:134
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:49
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
GfxBlitter
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.
Definition: gfx.cpp:1089
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1598
strings_func.h
CursorVars::animate_timeout
uint animate_timeout
in case of animated cursor, number of ticks to show the current cursor
Definition: gfx_type.h:137
ScaleByZoom
static int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Definition: zoom_func.h:22
SA_VERT_MASK
@ SA_VERT_MASK
Mask for vertical alignment.
Definition: gfx_type.h:342
FontCache
Font cache for basic fonts.
Definition: fontcache.h:21
Blitter::MoveTo
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...
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:112
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
video_driver.hpp
FontCache::GetGlyph
virtual const Sprite * GetGlyph(GlyphID key)=0
Get the glyph (sprite) of the given key.
GetMaxSpriteID
uint GetMaxSpriteID()
Get a reasonable (upper bound) estimate of the maximum SpriteID used in OpenTTD; there will be no spr...
Definition: spritecache.cpp:221
Layouter::GetCharAtPosition
const char * GetCharAtPosition(int x) const
Get the character that is at a position.
Definition: gfx_layout.cpp:815
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
UpdateAllVirtCoords
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition: afterload.cpp:218
_stringwidth_table
static byte _stringwidth_table[FS_END][224]
Cache containing width of often used characters.
Definition: gfx.cpp:53
GetGlyph
static const Sprite * GetGlyph(FontSize size, WChar key)
Get the Sprite for a glyph.
Definition: fontcache.h:184
EPV_CYCLES_LIGHTHOUSE
static const uint EPV_CYCLES_LIGHTHOUSE
length of the lighthouse/stadium animation
Definition: palettes.h:98
CopyPalette
bool CopyPalette(Palette &local_palette, bool force_copy)
Copy the current palette if the palette was updated.
Definition: gfx.cpp:1294
AnimCursor::display_time
byte display_time
Amount of ticks this sprite will be shown.
Definition: gfx_type.h:111
Blitter::BlitterParams::left
int left
The left offset in the 'dst' in pixels to start drawing.
Definition: base.hpp:41
CursorVars::delta
Point delta
relative mouse movement in this tick
Definition: gfx_type.h:118
GetBlitterMode
static BlitterMode GetBlitterMode(PaletteID pal)
Helper function to get the blitter mode for different types of palettes.
Definition: gfx.cpp:1013
ExtraPaletteValues::dark_water
Colour dark_water[EPV_CYCLES_DARK_WATER]
dark blue water
Definition: palettes.h:105
MakePolygonSegments
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.
Definition: gfx.cpp:173
progress.h
GfxPreprocessLine
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.
Definition: gfx.cpp:373
SetCursorSprite
static void SetCursorSprite(CursorID cursor, PaletteID pal)
Switch cursor to different sprite.
Definition: gfx.cpp:1872
Sprite::y_offs
int16 y_offs
Number of pixels to shift the sprite downwards.
Definition: spritecache.h:21
Blitter::PALETTE_ANIMATION_NONE
@ PALETTE_ANIMATION_NONE
No palette animation.
Definition: base.hpp:50
AnimCursor
A single sprite of a list of animated cursors.
Definition: gfx_type.h:108
VideoDriver::GetSuggestedUIScale
virtual int GetSuggestedUIScale()
Get a suggested default GUI scale taking screen DPI into account.
Definition: video_driver.hpp:172
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:21
_cur_palette
Palette _cur_palette
Current palette.
Definition: gfx.cpp:51
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:334
network.h
GetCharacterWidth
byte GetCharacterWidth(FontSize size, WChar key)
Return width of character glyph.
Definition: gfx.cpp:1465
Blitter::CopyFromBuffer
virtual void CopyFromBuffer(void *video, const void *src, int width, int height)=0
Copy from a buffer to the screen.
window_func.h
CenterBounds
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:178
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
CursorVars::sprite_seq
PalSpriteID sprite_seq[16]
current image of cursor
Definition: gfx_type.h:128
EPV_CYCLES_DARK_WATER
static const uint EPV_CYCLES_DARK_WATER
Description of the length of the palette cycle animations.
Definition: palettes.h:97
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1767
Blitter::BlitterParams
Parameters related to blitting.
Definition: base.hpp:31
MemSetT
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
Definition: mem_func.hpp:49
FS_MONO
@ FS_MONO
Index of the monospaced font in the font tables.
Definition: gfx_type.h:206
ZOOM_LVL_NORMAL
@ ZOOM_LVL_NORMAL
The normal zoom level.
Definition: zoom_type.h:22
SPR_CURSOR_MOUSE
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1378
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:280
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
Blitter::BlitterParams::height
int height
The height in pixels that needs to be drawn to dst.
Definition: base.hpp:38
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
Window
Data structure for an opened window.
Definition: window_gui.h:213
ST_RECOLOUR
@ ST_RECOLOUR
Recolour sprite.
Definition: gfx_type.h:311
ZOOM_LVL_OUT_4X
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
Definition: zoom_type.h:24
ExtraPaletteValues::dark_water_toyland
Colour dark_water_toyland[EPV_CYCLES_DARK_WATER]
dark blue water Toyland
Definition: palettes.h:106
ExtraPaletteValues::fizzy_drink
Colour fizzy_drink[EPV_CYCLES_FIZZY_DRINK]
fizzy drinks
Definition: palettes.h:109
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
Blitter::BlitterParams::skip_top
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst)
Definition: base.hpp:36
FontCache::MapCharToGlyph
virtual GlyphID MapCharToGlyph(WChar key)=0
Map a character into a glyph.
_right_button_clicked
bool _right_button_clicked
Is right mouse button clicked?
Definition: gfx.cpp:44
Palette
Information about the currently used palette.
Definition: gfx_type.h:319
EPV_CYCLES_GLITTER_WATER
static const uint EPV_CYCLES_GLITTER_WATER
length of the glittery water animation
Definition: palettes.h:101
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17
GetCharPosInString
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.
Definition: gfx.cpp:948
thread.h
CursorVars::in_window
bool in_window
mouse inside this window, determines drawing logic
Definition: gfx_type.h:141
Blitter::BlitterParams::remap
const byte * remap
XXX – Temporary storage for remap array.
Definition: base.hpp:33
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
UpdateGUIZoom
void UpdateGUIZoom()
Resolve GUI zoom level, if auto-suggestion is requested.
Definition: gfx.cpp:2002
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:42
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
network_func.h
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:49
ExtraPaletteValues::glitter_water
Colour glitter_water[EPV_CYCLES_GLITTER_WATER]
glittery water
Definition: palettes.h:110
_game_speed
uint16 _game_speed
Current game-speed; 100 is 1x, 0 is infinite.
Definition: gfx.cpp:40
_right_button_down
bool _right_button_down
Is right mouse button pressed?
Definition: gfx.cpp:43
PALETTE_ALL_BLACK
static const PaletteID PALETTE_ALL_BLACK
Exchange any color by black, needed for painting fictive tiles outside map.
Definition: sprites.h:1604
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:168
backup_type.hpp
Blitter::BufferSize
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.
DrawSpriteViewport
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
Draw a sprite in a viewport.
Definition: gfx.cpp:1031