OpenTTD Source  12.2
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_func.h"
21 #include "newgrf_debug.h"
22 #include "thread.h"
23 #include "core/backup_type.hpp"
24 
25 #include "table/palettes.h"
26 #include "table/string_colours.h"
27 #include "table/sprites.h"
28 #include "table/control_codes.h"
29 
30 #include "safeguards.h"
31 
32 byte _dirkeys;
33 bool _fullscreen;
34 byte _support8bpp;
35 CursorVars _cursor;
38 uint16 _game_speed = 100;
43 DrawPixelInfo _screen;
44 bool _screen_disable_anim = false;
45 std::atomic<bool> _exit_game;
46 GameMode _game_mode;
50 
51 static byte _stringwidth_table[FS_END][224];
52 DrawPixelInfo *_cur_dpi;
53 byte _colour_gradient[COLOUR_END][8];
54 
55 static std::recursive_mutex _palette_mutex;
56 
57 static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = nullptr, SpriteID sprite_id = SPR_CURSOR_MOUSE);
58 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);
59 
60 static ReusableBuffer<uint8> _cursor_backup;
61 
64 
67 
68 
77 static const byte *_colour_remap_ptr;
78 static byte _string_colourremap[3];
79 
80 static const uint DIRTY_BLOCK_HEIGHT = 8;
81 static const uint DIRTY_BLOCK_WIDTH = 64;
82 
83 static uint _dirty_bytes_per_line = 0;
84 static byte *_dirty_blocks = nullptr;
85 extern uint _dirty_block_colour;
86 
87 void GfxScroll(int left, int top, int width, int height, int xo, int yo)
88 {
90 
91  if (xo == 0 && yo == 0) return;
92 
93  if (_cursor.visible) UndrawMouseCursor();
94 
96 
97  blitter->ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo);
98  /* This part of the screen is now dirty. */
99  VideoDriver::GetInstance()->MakeDirty(left, top, width, height);
100 }
101 
102 
117 void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
118 {
120  const DrawPixelInfo *dpi = _cur_dpi;
121  void *dst;
122  const int otop = top;
123  const int oleft = left;
124 
125  if (dpi->zoom != ZOOM_LVL_NORMAL) return;
126  if (left > right || top > bottom) return;
127  if (right < dpi->left || left >= dpi->left + dpi->width) return;
128  if (bottom < dpi->top || top >= dpi->top + dpi->height) return;
129 
130  if ( (left -= dpi->left) < 0) left = 0;
131  right = right - dpi->left + 1;
132  if (right > dpi->width) right = dpi->width;
133  right -= left;
134  assert(right > 0);
135 
136  if ( (top -= dpi->top) < 0) top = 0;
137  bottom = bottom - dpi->top + 1;
138  if (bottom > dpi->height) bottom = dpi->height;
139  bottom -= top;
140  assert(bottom > 0);
141 
142  dst = blitter->MoveTo(dpi->dst_ptr, left, top);
143 
144  switch (mode) {
145  default: // FILLRECT_OPAQUE
146  blitter->DrawRect(dst, right, bottom, (uint8)colour);
147  break;
148 
149  case FILLRECT_RECOLOUR:
150  blitter->DrawColourMappingRect(dst, right, bottom, GB(colour, 0, PALETTE_WIDTH));
151  break;
152 
153  case FILLRECT_CHECKER: {
154  byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
155  do {
156  for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)colour);
157  dst = blitter->MoveTo(dst, 0, 1);
158  } while (--bottom > 0);
159  break;
160  }
161  }
162 }
163 
164 typedef std::pair<Point, Point> LineSegment;
165 
174 static std::vector<LineSegment> MakePolygonSegments(const std::vector<Point> &shape, Point offset)
175 {
176  std::vector<LineSegment> segments;
177  if (shape.size() < 3) return segments; // fewer than 3 will always result in an empty polygon
178  segments.reserve(shape.size());
179 
180  /* Connect first and last point by having initial previous point be the last */
181  Point prev = shape.back();
182  prev.x -= offset.x;
183  prev.y -= offset.y;
184  for (Point pt : shape) {
185  pt.x -= offset.x;
186  pt.y -= offset.y;
187  /* Create segments for all non-horizontal lines in the polygon.
188  * The segments always have lowest Y coordinate first. */
189  if (prev.y > pt.y) {
190  segments.emplace_back(pt, prev);
191  } else if (prev.y < pt.y) {
192  segments.emplace_back(prev, pt);
193  }
194  prev = pt;
195  }
196 
197  return segments;
198 }
199 
213 void GfxFillPolygon(const std::vector<Point> &shape, int colour, FillRectMode mode)
214 {
216  const DrawPixelInfo *dpi = _cur_dpi;
217  if (dpi->zoom != ZOOM_LVL_NORMAL) return;
218 
219  std::vector<LineSegment> segments = MakePolygonSegments(shape, Point{ dpi->left, dpi->top });
220 
221  /* Remove segments appearing entirely above or below the clipping area. */
222  segments.erase(std::remove_if(segments.begin(), segments.end(), [dpi](const LineSegment &s) { return s.second.y <= 0 || s.first.y >= dpi->height; }), segments.end());
223 
224  /* Check that this wasn't an empty shape (all points on a horizontal line or outside clipping.) */
225  if (segments.empty()) return;
226 
227  /* Sort the segments by first point Y coordinate. */
228  std::sort(segments.begin(), segments.end(), [](const LineSegment &a, const LineSegment &b) { return a.first.y < b.first.y; });
229 
230  /* Segments intersecting current scanline. */
231  std::vector<LineSegment> active;
232  /* Intersection points with a scanline.
233  * Kept outside loop to avoid repeated re-allocations. */
234  std::vector<int> intersections;
235  /* Normal, reasonable polygons don't have many intersections per scanline. */
236  active.reserve(4);
237  intersections.reserve(4);
238 
239  /* Scan through the segments and paint each scanline. */
240  int y = segments.front().first.y;
241  std::vector<LineSegment>::iterator nextseg = segments.begin();
242  while (!active.empty() || nextseg != segments.end()) {
243  /* Clean up segments that have ended. */
244  active.erase(std::remove_if(active.begin(), active.end(), [y](const LineSegment &s) { return s.second.y == y; }), active.end());
245 
246  /* Activate all segments starting on this scanline. */
247  while (nextseg != segments.end() && nextseg->first.y == y) {
248  active.push_back(*nextseg);
249  ++nextseg;
250  }
251 
252  /* Check clipping. */
253  if (y < 0) {
254  ++y;
255  continue;
256  }
257  if (y >= dpi->height) return;
258 
259  /* Intersect scanline with all active segments. */
260  intersections.clear();
261  for (const LineSegment &s : active) {
262  const int sdx = s.second.x - s.first.x;
263  const int sdy = s.second.y - s.first.y;
264  const int ldy = y - s.first.y;
265  const int x = s.first.x + sdx * ldy / sdy;
266  intersections.push_back(x);
267  }
268 
269  /* Fill between pairs of intersections. */
270  std::sort(intersections.begin(), intersections.end());
271  for (size_t i = 1; i < intersections.size(); i += 2) {
272  /* Check clipping. */
273  const int x1 = std::max(0, intersections[i - 1]);
274  const int x2 = std::min(intersections[i], dpi->width);
275  if (x2 < 0) continue;
276  if (x1 >= dpi->width) continue;
277 
278  /* Fill line y from x1 to x2. */
279  void *dst = blitter->MoveTo(dpi->dst_ptr, x1, y);
280  switch (mode) {
281  default: // FILLRECT_OPAQUE
282  blitter->DrawRect(dst, x2 - x1, 1, (uint8)colour);
283  break;
284  case FILLRECT_RECOLOUR:
285  blitter->DrawColourMappingRect(dst, x2 - x1, 1, GB(colour, 0, PALETTE_WIDTH));
286  break;
287  case FILLRECT_CHECKER:
288  /* Fill every other pixel, offset such that the sum of filled pixels' X and Y coordinates is odd.
289  * This creates a checkerboard effect. */
290  for (int x = (x1 + y) & 1; x < x2 - x1; x += 2) {
291  blitter->SetPixel(dst, x, 0, (uint8)colour);
292  }
293  break;
294  }
295  }
296 
297  /* Next line */
298  ++y;
299  }
300 }
301 
316 static inline void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash = 0)
317 {
319 
320  assert(width > 0);
321 
322  if (y2 == y || x2 == x) {
323  /* Special case: horizontal/vertical line. All checks already done in GfxPreprocessLine. */
324  blitter->DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width, dash);
325  return;
326  }
327 
328  int grade_y = y2 - y;
329  int grade_x = x2 - x;
330 
331  /* Clipping rectangle. Slightly extended so we can ignore the width of the line. */
332  int extra = (int)CeilDiv(3 * width, 4); // not less then "width * sqrt(2) / 2"
333  Rect clip = { -extra, -extra, screen_width - 1 + extra, screen_height - 1 + extra };
334 
335  /* prevent integer overflows. */
336  int margin = 1;
337  while (INT_MAX / abs(grade_y) < std::max(abs(clip.left - x), abs(clip.right - x))) {
338  grade_y /= 2;
339  grade_x /= 2;
340  margin *= 2; // account for rounding errors
341  }
342 
343  /* Imagine that the line is infinitely long and it intersects with
344  * infinitely long left and right edges of the clipping rectangle.
345  * If both intersection points are outside the clipping rectangle
346  * and both on the same side of it, we don't need to draw anything. */
347  int left_isec_y = y + (clip.left - x) * grade_y / grade_x;
348  int right_isec_y = y + (clip.right - x) * grade_y / grade_x;
349  if ((left_isec_y > clip.bottom + margin && right_isec_y > clip.bottom + margin) ||
350  (left_isec_y < clip.top - margin && right_isec_y < clip.top - margin)) {
351  return;
352  }
353 
354  /* It is possible to use the line equation to further reduce the amount of
355  * work the blitter has to do by shortening the effective line segment.
356  * However, in order to get that right and prevent the flickering effects
357  * of rounding errors so much additional code has to be run here that in
358  * the general case the effect is not noticeable. */
359 
360  blitter->DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width, dash);
361 }
362 
374 static inline bool GfxPreprocessLine(DrawPixelInfo *dpi, int &x, int &y, int &x2, int &y2, int width)
375 {
376  x -= dpi->left;
377  x2 -= dpi->left;
378  y -= dpi->top;
379  y2 -= dpi->top;
380 
381  /* Check simple clipping */
382  if (x + width / 2 < 0 && x2 + width / 2 < 0 ) return false;
383  if (y + width / 2 < 0 && y2 + width / 2 < 0 ) return false;
384  if (x - width / 2 > dpi->width && x2 - width / 2 > dpi->width ) return false;
385  if (y - width / 2 > dpi->height && y2 - width / 2 > dpi->height) return false;
386  return true;
387 }
388 
389 void GfxDrawLine(int x, int y, int x2, int y2, int colour, int width, int dash)
390 {
391  DrawPixelInfo *dpi = _cur_dpi;
392  if (GfxPreprocessLine(dpi, x, y, x2, y2, width)) {
393  GfxDoDrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, colour, width, dash);
394  }
395 }
396 
397 void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int colour)
398 {
399  DrawPixelInfo *dpi = _cur_dpi;
400  if (GfxPreprocessLine(dpi, x, y, x2, y2, 1)) {
401  GfxDoDrawLine(dpi->dst_ptr,
402  UnScaleByZoom(x, dpi->zoom), UnScaleByZoom(y, dpi->zoom),
403  UnScaleByZoom(x2, dpi->zoom), UnScaleByZoom(y2, dpi->zoom),
404  UnScaleByZoom(dpi->width, dpi->zoom), UnScaleByZoom(dpi->height, dpi->zoom), colour, 1);
405  }
406 }
407 
421 void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
422 {
423  /* ....
424  * .. ....
425  * .. ....
426  * .. ^
427  * <--__(dx1,dy1) /(dx2,dy2)
428  * : --__ / :
429  * : --__ / :
430  * : *(x,y) :
431  * : | :
432  * : | ..
433  * .... |(dx3,dy3)
434  * .... | ..
435  * ....V.
436  */
437 
438  static const byte colour = PC_WHITE;
439 
440  GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, colour);
441  GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, colour);
442  GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, colour);
443 
444  GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, colour);
445  GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, colour);
446  GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, colour);
447  GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, colour);
448  GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, colour);
449  GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, colour);
450 }
451 
456 static void SetColourRemap(TextColour colour)
457 {
458  if (colour == TC_INVALID) return;
459 
460  /* Black strings have no shading ever; the shading is black, so it
461  * would be invisible at best, but it actually makes it illegible. */
462  bool no_shade = (colour & TC_NO_SHADE) != 0 || colour == TC_BLACK;
463  bool raw_colour = (colour & TC_IS_PALETTE_COLOUR) != 0;
464  colour &= ~(TC_NO_SHADE | TC_IS_PALETTE_COLOUR | TC_FORCED);
465 
466  _string_colourremap[1] = raw_colour ? (byte)colour : _string_colourmap[colour];
467  _string_colourremap[2] = no_shade ? 0 : 1;
468  _colour_remap_ptr = _string_colourremap;
469 }
470 
486 static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left, int right, StringAlignment align, bool underline, bool truncation)
487 {
488  if (line.CountRuns() == 0) return 0;
489 
490  int w = line.GetWidth();
491  int h = line.GetLeading();
492 
493  /*
494  * The following is needed for truncation.
495  * Depending on the text direction, we either remove bits at the rear
496  * or the front. For this we shift the entire area to draw so it fits
497  * within the left/right bounds and the side we do not truncate it on.
498  * Then we determine the truncation location, i.e. glyphs that fall
499  * outside of the range min_x - max_x will not be drawn; they are thus
500  * the truncated glyphs.
501  *
502  * At a later step we insert the dots.
503  */
504 
505  int max_w = right - left + 1; // The maximum width.
506 
507  int offset_x = 0; // The offset we need for positioning the glyphs
508  int min_x = left; // The minimum x position to draw normal glyphs on.
509  int max_x = right; // The maximum x position to draw normal glyphs on.
510 
511  truncation &= max_w < w; // Whether we need to do truncation.
512  int dot_width = 0; // Cache for the width of the dot.
513  const Sprite *dot_sprite = nullptr; // Cache for the sprite of the dot.
514 
515  if (truncation) {
516  /*
517  * Assumption may be made that all fonts of a run are of the same size.
518  * In any case, we'll use these dots for the abbreviation, so even if
519  * another size would be chosen it won't have truncated too little for
520  * the truncation dots.
521  */
522  FontCache *fc = ((const Font*)line.GetVisualRun(0).GetFont())->fc;
523  GlyphID dot_glyph = fc->MapCharToGlyph('.');
524  dot_width = fc->GetGlyphWidth(dot_glyph);
525  dot_sprite = fc->GetGlyph(dot_glyph);
526 
527  if (_current_text_dir == TD_RTL) {
528  min_x += 3 * dot_width;
529  offset_x = w - 3 * dot_width - max_w;
530  } else {
531  max_x -= 3 * dot_width;
532  }
533 
534  w = max_w;
535  }
536 
537  /* In case we have a RTL language we swap the alignment. */
538  if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT;
539 
540  /* right is the right most position to draw on. In this case we want to do
541  * calculations with the width of the string. In comparison right can be
542  * seen as lastof(todraw) and width as lengthof(todraw). They differ by 1.
543  * So most +1/-1 additions are to move from lengthof to 'indices'.
544  */
545  switch (align & SA_HOR_MASK) {
546  case SA_LEFT:
547  /* right + 1 = left + w */
548  right = left + w - 1;
549  break;
550 
551  case SA_HOR_CENTER:
552  left = RoundDivSU(right + 1 + left - w, 2);
553  /* right + 1 = left + w */
554  right = left + w - 1;
555  break;
556 
557  case SA_RIGHT:
558  left = right + 1 - w;
559  break;
560 
561  default:
562  NOT_REACHED();
563  }
564 
565  TextColour colour = TC_BLACK;
566  bool draw_shadow = false;
567  for (int run_index = 0; run_index < line.CountRuns(); run_index++) {
568  const ParagraphLayouter::VisualRun &run = line.GetVisualRun(run_index);
569  const Font *f = (const Font*)run.GetFont();
570 
571  FontCache *fc = f->fc;
572  colour = f->colour;
573  SetColourRemap(colour);
574 
575  DrawPixelInfo *dpi = _cur_dpi;
576  int dpi_left = dpi->left;
577  int dpi_right = dpi->left + dpi->width - 1;
578 
579  draw_shadow = fc->GetDrawGlyphShadow() && (colour & TC_NO_SHADE) == 0 && colour != TC_BLACK;
580 
581  for (int i = 0; i < run.GetGlyphCount(); i++) {
582  GlyphID glyph = run.GetGlyphs()[i];
583 
584  /* Not a valid glyph (empty) */
585  if (glyph == 0xFFFF) continue;
586 
587  int begin_x = (int)run.GetPositions()[i * 2] + left - offset_x;
588  int end_x = (int)run.GetPositions()[i * 2 + 2] + left - offset_x - 1;
589  int top = (int)run.GetPositions()[i * 2 + 1] + y;
590 
591  /* Truncated away. */
592  if (truncation && (begin_x < min_x || end_x > max_x)) continue;
593 
594  const Sprite *sprite = fc->GetGlyph(glyph);
595  /* Check clipping (the "+ 1" is for the shadow). */
596  if (begin_x + sprite->x_offs > dpi_right || begin_x + sprite->x_offs + sprite->width /* - 1 + 1 */ < dpi_left) continue;
597 
598  if (draw_shadow && (glyph & SPRITE_GLYPH) == 0) {
599  SetColourRemap(TC_BLACK);
600  GfxMainBlitter(sprite, begin_x + 1, top + 1, BM_COLOUR_REMAP);
601  SetColourRemap(colour);
602  }
603  GfxMainBlitter(sprite, begin_x, top, BM_COLOUR_REMAP);
604  }
605  }
606 
607  if (truncation) {
608  int x = (_current_text_dir == TD_RTL) ? left : (right - 3 * dot_width);
609  for (int i = 0; i < 3; i++, x += dot_width) {
610  if (draw_shadow) {
611  SetColourRemap(TC_BLACK);
612  GfxMainBlitter(dot_sprite, x + 1, y + 1, BM_COLOUR_REMAP);
613  SetColourRemap(colour);
614  }
615  GfxMainBlitter(dot_sprite, x, y, BM_COLOUR_REMAP);
616  }
617  }
618 
619  if (underline) {
620  GfxFillRect(left, y + h, right, y + h, _string_colourremap[1]);
621  }
622 
623  return (align & SA_HOR_MASK) == SA_RIGHT ? left : right;
624 }
625 
643 int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
644 {
645  /* The string may contain control chars to change the font, just use the biggest font for clipping. */
647 
648  /* Funny glyphs may extent outside the usual bounds, so relax the clipping somewhat. */
649  int extra = max_height / 2;
650 
651  if (_cur_dpi->top + _cur_dpi->height + extra < top || _cur_dpi->top > top + max_height + extra ||
652  _cur_dpi->left + _cur_dpi->width + extra < left || _cur_dpi->left > right + extra) {
653  return 0;
654  }
655 
656  Layouter layout(str, INT32_MAX, colour, fontsize);
657  if (layout.size() == 0) return 0;
658 
659  return DrawLayoutLine(*layout.front(), top, left, right, align, underline, true);
660 }
661 
679 int DrawString(int left, int right, int top, const std::string &str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
680 {
681  return DrawString(left, right, top, str.c_str(), colour, align, underline, fontsize);
682 }
683 
701 int DrawString(int left, int right, int top, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
702 {
703  char buffer[DRAW_STRING_BUFFER];
704  GetString(buffer, str, lastof(buffer));
705  return DrawString(left, right, top, buffer, colour, align, underline, fontsize);
706 }
707 
714 int GetStringHeight(const char *str, int maxw, FontSize fontsize)
715 {
716  Layouter layout(str, maxw, TC_FROMSTRING, fontsize);
717  return layout.GetBounds().height;
718 }
719 
726 int GetStringHeight(StringID str, int maxw)
727 {
728  char buffer[DRAW_STRING_BUFFER];
729  GetString(buffer, str, lastof(buffer));
730  return GetStringHeight(buffer, maxw);
731 }
732 
739 int GetStringLineCount(StringID str, int maxw)
740 {
741  char buffer[DRAW_STRING_BUFFER];
742  GetString(buffer, str, lastof(buffer));
743 
744  Layouter layout(buffer, maxw);
745  return (uint)layout.size();
746 }
747 
755 {
756  Dimension box = {suggestion.width, (uint)GetStringHeight(str, suggestion.width)};
757  return box;
758 }
759 
766 Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion)
767 {
768  Dimension box = {suggestion.width, (uint)GetStringHeight(str, suggestion.width)};
769  return box;
770 }
771 
788 int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
789 {
790  int maxw = right - left + 1;
791  int maxh = bottom - top + 1;
792 
793  /* It makes no sense to even try if it can't be drawn anyway, or
794  * do we really want to support fonts of 0 or less pixels high? */
795  if (maxh <= 0) return top;
796 
797  Layouter layout(str, maxw, colour, fontsize);
798  int total_height = layout.GetBounds().height;
799  int y;
800  switch (align & SA_VERT_MASK) {
801  case SA_TOP:
802  y = top;
803  break;
804 
805  case SA_VERT_CENTER:
806  y = RoundDivSU(bottom + top - total_height, 2);
807  break;
808 
809  case SA_BOTTOM:
810  y = bottom - total_height;
811  break;
812 
813  default: NOT_REACHED();
814  }
815 
816  int last_line = top;
817  int first_line = bottom;
818 
819  for (const auto &line : layout) {
820 
821  int line_height = line->GetLeading();
822  if (y >= top && y < bottom) {
823  last_line = y + line_height;
824  if (first_line > y) first_line = y;
825 
826  DrawLayoutLine(*line, y, left, right, align, underline, false);
827  }
828  y += line_height;
829  }
830 
831  return ((align & SA_VERT_MASK) == SA_BOTTOM) ? first_line : last_line;
832 }
833 
834 
851 int DrawStringMultiLine(int left, int right, int top, int bottom, const std::string &str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
852 {
853  return DrawStringMultiLine(left, right, top, bottom, str.c_str(), colour, align, underline, fontsize);
854 }
855 
872 int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
873 {
874  char buffer[DRAW_STRING_BUFFER];
875  GetString(buffer, str, lastof(buffer));
876  return DrawStringMultiLine(left, right, top, bottom, buffer, colour, align, underline, fontsize);
877 }
878 
889 Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
890 {
891  Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
892  return layout.GetBounds();
893 }
894 
905 Dimension GetStringBoundingBox(const std::string &str, FontSize start_fontsize)
906 {
907  return GetStringBoundingBox(str.c_str(), start_fontsize);
908 }
909 
917 {
918  char buffer[DRAW_STRING_BUFFER];
919 
920  GetString(buffer, strid, lastof(buffer));
921  return GetStringBoundingBox(buffer);
922 }
923 
932 Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize)
933 {
934  Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
935  return layout.GetCharPosition(ch);
936 }
937 
945 const char *GetCharAtPosition(const char *str, int x, FontSize start_fontsize)
946 {
947  if (x < 0) return nullptr;
948 
949  Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
950  return layout.GetCharAtPosition(x);
951 }
952 
960 void DrawCharCentered(WChar c, const Rect &r, TextColour colour)
961 {
962  SetColourRemap(colour);
963  GfxMainBlitter(GetGlyph(FS_NORMAL, c),
964  CenterBounds(r.left, r.right, GetCharacterWidth(FS_NORMAL, c)),
965  CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL),
967 }
968 
978 {
979  const Sprite *sprite = GetSprite(sprid, ST_NORMAL);
980 
981  if (offset != nullptr) {
982  offset->x = UnScaleByZoom(sprite->x_offs, zoom);
983  offset->y = UnScaleByZoom(sprite->y_offs, zoom);
984  }
985 
986  Dimension d;
987  d.width = std::max<int>(0, UnScaleByZoom(sprite->x_offs + sprite->width, zoom));
988  d.height = std::max<int>(0, UnScaleByZoom(sprite->y_offs + sprite->height, zoom));
989  return d;
990 }
991 
998 {
999  switch (pal) {
1000  case PAL_NONE: return BM_NORMAL;
1001  case PALETTE_CRASH: return BM_CRASH_REMAP;
1002  case PALETTE_ALL_BLACK: return BM_BLACK_REMAP;
1003  default: return BM_COLOUR_REMAP;
1004  }
1005 }
1006 
1015 void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
1016 {
1017  SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
1019  _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
1020  GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite);
1021  } else if (pal != PAL_NONE) {
1022  if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
1024  } else {
1025  _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
1026  }
1027  GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite);
1028  } else {
1029  GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite);
1030  }
1031 }
1032 
1042 void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
1043 {
1044  SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
1046  _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
1047  GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite, zoom);
1048  } else if (pal != PAL_NONE) {
1049  if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
1051  } else {
1052  _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
1053  }
1054  GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite, zoom);
1055  } else {
1056  GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite, zoom);
1057  }
1058 }
1059 
1072 template <int ZOOM_BASE, bool SCALED_XY>
1073 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)
1074 {
1075  const DrawPixelInfo *dpi = (dst != nullptr) ? dst : _cur_dpi;
1077 
1078  if (SCALED_XY) {
1079  /* Scale it */
1080  x = ScaleByZoom(x, zoom);
1081  y = ScaleByZoom(y, zoom);
1082  }
1083 
1084  /* Move to the correct offset */
1085  x += sprite->x_offs;
1086  y += sprite->y_offs;
1087 
1088  if (sub == nullptr) {
1089  /* No clipping. */
1090  bp.skip_left = 0;
1091  bp.skip_top = 0;
1092  bp.width = UnScaleByZoom(sprite->width, zoom);
1093  bp.height = UnScaleByZoom(sprite->height, zoom);
1094  } else {
1095  /* Amount of pixels to clip from the source sprite */
1096  int clip_left = std::max(0, -sprite->x_offs + sub->left * ZOOM_BASE );
1097  int clip_top = std::max(0, -sprite->y_offs + sub->top * ZOOM_BASE );
1098  int clip_right = std::max(0, sprite->width - (-sprite->x_offs + (sub->right + 1) * ZOOM_BASE));
1099  int clip_bottom = std::max(0, sprite->height - (-sprite->y_offs + (sub->bottom + 1) * ZOOM_BASE));
1100 
1101  if (clip_left + clip_right >= sprite->width) return;
1102  if (clip_top + clip_bottom >= sprite->height) return;
1103 
1104  bp.skip_left = UnScaleByZoomLower(clip_left, zoom);
1105  bp.skip_top = UnScaleByZoomLower(clip_top, zoom);
1106  bp.width = UnScaleByZoom(sprite->width - clip_left - clip_right, zoom);
1107  bp.height = UnScaleByZoom(sprite->height - clip_top - clip_bottom, zoom);
1108 
1109  x += ScaleByZoom(bp.skip_left, zoom);
1110  y += ScaleByZoom(bp.skip_top, zoom);
1111  }
1112 
1113  /* Copy the main data directly from the sprite */
1114  bp.sprite = sprite->data;
1115  bp.sprite_width = sprite->width;
1116  bp.sprite_height = sprite->height;
1117  bp.top = 0;
1118  bp.left = 0;
1119 
1120  bp.dst = dpi->dst_ptr;
1121  bp.pitch = dpi->pitch;
1122  bp.remap = _colour_remap_ptr;
1123 
1124  assert(sprite->width > 0);
1125  assert(sprite->height > 0);
1126 
1127  if (bp.width <= 0) return;
1128  if (bp.height <= 0) return;
1129 
1130  y -= SCALED_XY ? ScaleByZoom(dpi->top, zoom) : dpi->top;
1131  int y_unscaled = UnScaleByZoom(y, zoom);
1132  /* Check for top overflow */
1133  if (y < 0) {
1134  bp.height -= -y_unscaled;
1135  if (bp.height <= 0) return;
1136  bp.skip_top += -y_unscaled;
1137  y = 0;
1138  } else {
1139  bp.top = y_unscaled;
1140  }
1141 
1142  /* Check for bottom overflow */
1143  y += SCALED_XY ? ScaleByZoom(bp.height - dpi->height, zoom) : ScaleByZoom(bp.height, zoom) - dpi->height;
1144  if (y > 0) {
1145  bp.height -= UnScaleByZoom(y, zoom);
1146  if (bp.height <= 0) return;
1147  }
1148 
1149  x -= SCALED_XY ? ScaleByZoom(dpi->left, zoom) : dpi->left;
1150  int x_unscaled = UnScaleByZoom(x, zoom);
1151  /* Check for left overflow */
1152  if (x < 0) {
1153  bp.width -= -x_unscaled;
1154  if (bp.width <= 0) return;
1155  bp.skip_left += -x_unscaled;
1156  x = 0;
1157  } else {
1158  bp.left = x_unscaled;
1159  }
1160 
1161  /* Check for right overflow */
1162  x += SCALED_XY ? ScaleByZoom(bp.width - dpi->width, zoom) : ScaleByZoom(bp.width, zoom) - dpi->width;
1163  if (x > 0) {
1164  bp.width -= UnScaleByZoom(x, zoom);
1165  if (bp.width <= 0) return;
1166  }
1167 
1168  assert(bp.skip_left + bp.width <= UnScaleByZoom(sprite->width, zoom));
1169  assert(bp.skip_top + bp.height <= UnScaleByZoom(sprite->height, zoom));
1170 
1171  /* We do not want to catch the mouse. However we also use that spritenumber for unknown (text) sprites. */
1172  if (_newgrf_debug_sprite_picker.mode == SPM_REDRAW && sprite_id != SPR_CURSOR_MOUSE) {
1174  void *topleft = blitter->MoveTo(bp.dst, bp.left, bp.top);
1175  void *bottomright = blitter->MoveTo(topleft, bp.width - 1, bp.height - 1);
1176 
1178 
1179  if (topleft <= clicked && clicked <= bottomright) {
1180  uint offset = (((size_t)clicked - (size_t)topleft) / (blitter->GetScreenDepth() / 8)) % bp.pitch;
1181  if (offset < (uint)bp.width) {
1183  }
1184  }
1185  }
1186 
1187  BlitterFactory::GetCurrentBlitter()->Draw(&bp, mode, zoom);
1188 }
1189 
1197 std::unique_ptr<uint32[]> DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom)
1198 {
1199  /* Invalid zoom level requested? */
1200  if (zoom < _settings_client.gui.zoom_min || zoom > _settings_client.gui.zoom_max) return nullptr;
1201 
1203  if (blitter->GetScreenDepth() != 8 && blitter->GetScreenDepth() != 32) return nullptr;
1204 
1205  /* Gather information about the sprite to write, reserve memory */
1206  const SpriteID real_sprite = GB(spriteId, 0, SPRITE_WIDTH);
1207  const Sprite *sprite = GetSprite(real_sprite, ST_NORMAL);
1208  Dimension dim = GetSpriteSize(real_sprite, nullptr, zoom);
1209  std::unique_ptr<uint32[]> result(new uint32[dim.width * dim.height]);
1210  /* Set buffer to fully transparent. */
1211  MemSetT(result.get(), 0, dim.width * dim.height);
1212 
1213  /* Prepare new DrawPixelInfo - Normally this would be the screen but we want to draw to another buffer here.
1214  * Normally, pitch would be scaled screen width, but in our case our "screen" is only the sprite width wide. */
1215  DrawPixelInfo dpi;
1216  dpi.dst_ptr = result.get();
1217  dpi.pitch = dim.width;
1218  dpi.left = 0;
1219  dpi.top = 0;
1220  dpi.width = dim.width;
1221  dpi.height = dim.height;
1222  dpi.zoom = zoom;
1223 
1224  /* If the current blitter is a paletted blitter, we have to render to an extra buffer and resolve the palette later. */
1225  std::unique_ptr<byte[]> pal_buffer{};
1226  if (blitter->GetScreenDepth() == 8) {
1227  pal_buffer.reset(new byte[dim.width * dim.height]);
1228  MemSetT(pal_buffer.get(), 0, dim.width * dim.height);
1229 
1230  dpi.dst_ptr = pal_buffer.get();
1231  }
1232 
1233  /* Temporarily disable screen animations while blitting - This prevents 40bpp_anim from writing to the animation buffer. */
1234  Backup<bool> disable_anim(_screen_disable_anim, true, FILE_LINE);
1235  GfxBlitter<1, true>(sprite, 0, 0, BM_NORMAL, nullptr, real_sprite, zoom, &dpi);
1236  disable_anim.Restore();
1237 
1238  if (blitter->GetScreenDepth() == 8) {
1239  /* Resolve palette. */
1240  uint32 *dst = result.get();
1241  const byte *src = pal_buffer.get();
1242  for (size_t i = 0; i < dim.height * dim.width; ++i) {
1243  *dst++ = _cur_palette.palette[*src++].data;
1244  }
1245  }
1246 
1247  return result;
1248 }
1249 
1250 static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub, SpriteID sprite_id)
1251 {
1252  GfxBlitter<ZOOM_LVL_BASE, false>(sprite, x, y, mode, sub, sprite_id, _cur_dpi->zoom);
1253 }
1254 
1255 static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub, SpriteID sprite_id, ZoomLevel zoom)
1256 {
1257  GfxBlitter<1, true>(sprite, x, y, mode, sub, sprite_id, zoom);
1258 }
1259 
1260 void DoPaletteAnimations();
1261 
1262 void GfxInitPalettes()
1263 {
1264  std::lock_guard<std::recursive_mutex> lock(_palette_mutex);
1265  memcpy(&_cur_palette, &_palette, sizeof(_cur_palette));
1266  DoPaletteAnimations();
1267 }
1268 
1278 bool CopyPalette(Palette &local_palette, bool force_copy)
1279 {
1280  std::lock_guard<std::recursive_mutex> lock(_palette_mutex);
1281 
1282  if (!force_copy && _cur_palette.count_dirty == 0) return false;
1283 
1284  local_palette = _cur_palette;
1286 
1287  if (force_copy) {
1288  local_palette.first_dirty = 0;
1289  local_palette.count_dirty = 256;
1290  }
1291 
1292  return true;
1293 }
1294 
1295 #define EXTR(p, q) (((uint16)(palette_animation_counter * (p)) * (q)) >> 16)
1296 #define EXTR2(p, q) (((uint16)(~palette_animation_counter * (p)) * (q)) >> 16)
1297 
1298 void DoPaletteAnimations()
1299 {
1300  std::lock_guard<std::recursive_mutex> lock(_palette_mutex);
1301 
1302  /* Animation counter for the palette animation. */
1303  static int palette_animation_counter = 0;
1304  palette_animation_counter += 8;
1305 
1307  const Colour *s;
1309  Colour old_val[PALETTE_ANIM_SIZE];
1310  const uint old_tc = palette_animation_counter;
1311  uint i;
1312  uint j;
1313 
1314  if (blitter != nullptr && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
1315  palette_animation_counter = 0;
1316  }
1317 
1318  Colour *palette_pos = &_cur_palette.palette[PALETTE_ANIM_START]; // Points to where animations are taking place on the palette
1319  /* Makes a copy of the current animation palette in old_val,
1320  * so the work on the current palette could be compared, see if there has been any changes */
1321  memcpy(old_val, palette_pos, sizeof(old_val));
1322 
1323  /* Fizzy Drink bubbles animation */
1324  s = ev->fizzy_drink;
1325  j = EXTR2(512, EPV_CYCLES_FIZZY_DRINK);
1326  for (i = 0; i != EPV_CYCLES_FIZZY_DRINK; i++) {
1327  *palette_pos++ = s[j];
1328  j++;
1329  if (j == EPV_CYCLES_FIZZY_DRINK) j = 0;
1330  }
1331 
1332  /* Oil refinery fire animation */
1333  s = ev->oil_refinery;
1334  j = EXTR2(512, EPV_CYCLES_OIL_REFINERY);
1335  for (i = 0; i != EPV_CYCLES_OIL_REFINERY; i++) {
1336  *palette_pos++ = s[j];
1337  j++;
1338  if (j == EPV_CYCLES_OIL_REFINERY) j = 0;
1339  }
1340 
1341  /* Radio tower blinking */
1342  {
1343  byte i = (palette_animation_counter >> 1) & 0x7F;
1344  byte v;
1345 
1346  if (i < 0x3f) {
1347  v = 255;
1348  } else if (i < 0x4A || i >= 0x75) {
1349  v = 128;
1350  } else {
1351  v = 20;
1352  }
1353  palette_pos->r = v;
1354  palette_pos->g = 0;
1355  palette_pos->b = 0;
1356  palette_pos++;
1357 
1358  i ^= 0x40;
1359  if (i < 0x3f) {
1360  v = 255;
1361  } else if (i < 0x4A || i >= 0x75) {
1362  v = 128;
1363  } else {
1364  v = 20;
1365  }
1366  palette_pos->r = v;
1367  palette_pos->g = 0;
1368  palette_pos->b = 0;
1369  palette_pos++;
1370  }
1371 
1372  /* Handle lighthouse and stadium animation */
1373  s = ev->lighthouse;
1374  j = EXTR(256, EPV_CYCLES_LIGHTHOUSE);
1375  for (i = 0; i != EPV_CYCLES_LIGHTHOUSE; i++) {
1376  *palette_pos++ = s[j];
1377  j++;
1378  if (j == EPV_CYCLES_LIGHTHOUSE) j = 0;
1379  }
1380 
1381  /* Dark blue water */
1382  s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->dark_water_toyland : ev->dark_water;
1383  j = EXTR(320, EPV_CYCLES_DARK_WATER);
1384  for (i = 0; i != EPV_CYCLES_DARK_WATER; i++) {
1385  *palette_pos++ = s[j];
1386  j++;
1387  if (j == EPV_CYCLES_DARK_WATER) j = 0;
1388  }
1389 
1390  /* Glittery water */
1392  j = EXTR(128, EPV_CYCLES_GLITTER_WATER);
1393  for (i = 0; i != EPV_CYCLES_GLITTER_WATER / 3; i++) {
1394  *palette_pos++ = s[j];
1395  j += 3;
1397  }
1398 
1399  if (blitter != nullptr && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
1400  palette_animation_counter = old_tc;
1401  } else {
1402  if (memcmp(old_val, &_cur_palette.palette[PALETTE_ANIM_START], sizeof(old_val)) != 0 && _cur_palette.count_dirty == 0) {
1403  /* Did we changed anything on the palette? Seems so. Mark it as dirty */
1406  }
1407  }
1408 }
1409 
1416 TextColour GetContrastColour(uint8 background, uint8 threshold)
1417 {
1418  Colour c = _cur_palette.palette[background];
1419  /* Compute brightness according to http://www.w3.org/TR/AERT#color-contrast.
1420  * The following formula computes 1000 * brightness^2, with brightness being in range 0 to 255. */
1421  uint sq1000_brightness = c.r * c.r * 299 + c.g * c.g * 587 + c.b * c.b * 114;
1422  /* Compare with threshold brightness which defaults to 128 (50%) */
1423  return sq1000_brightness < ((uint) threshold) * ((uint) threshold) * 1000 ? TC_WHITE : TC_BLACK;
1424 }
1425 
1430 void LoadStringWidthTable(bool monospace)
1431 {
1432  ClearFontCache();
1433 
1434  for (FontSize fs = monospace ? FS_MONO : FS_BEGIN; fs < (monospace ? FS_END : FS_MONO); fs++) {
1435  for (uint i = 0; i != 224; i++) {
1436  _stringwidth_table[fs][i] = GetGlyphWidth(fs, i + 32);
1437  }
1438  }
1439 
1440  ReInitAllWindows(false);
1441 }
1442 
1450 {
1451  /* Use _stringwidth_table cache if possible */
1452  if (key >= 32 && key < 256) return _stringwidth_table[size][key - 32];
1453 
1454  return GetGlyphWidth(size, key);
1455 }
1456 
1463 {
1464  byte width = 0;
1465  for (char c = '0'; c <= '9'; c++) {
1466  width = std::max(GetCharacterWidth(size, c), width);
1467  }
1468  return width;
1469 }
1470 
1477 void GetBroadestDigit(uint *front, uint *next, FontSize size)
1478 {
1479  int width = -1;
1480  for (char c = '9'; c >= '0'; c--) {
1481  int w = GetCharacterWidth(size, c);
1482  if (w > width) {
1483  width = w;
1484  *next = c - '0';
1485  if (c != '0') *front = c - '0';
1486  }
1487  }
1488 }
1489 
1490 void ScreenSizeChanged()
1491 {
1492  _dirty_bytes_per_line = CeilDiv(_screen.width, DIRTY_BLOCK_WIDTH);
1493  _dirty_blocks = ReallocT<byte>(_dirty_blocks, _dirty_bytes_per_line * CeilDiv(_screen.height, DIRTY_BLOCK_HEIGHT));
1494 
1495  /* check the dirty rect */
1496  if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width;
1497  if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height;
1498 
1499  /* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */
1500  _cursor.visible = false;
1501 }
1502 
1503 void UndrawMouseCursor()
1504 {
1505  /* Don't undraw mouse cursor if it is handled by the video driver. */
1506  if (VideoDriver::GetInstance()->UseSystemCursor()) return;
1507 
1508  /* Don't undraw the mouse cursor if the screen is not ready */
1509  if (_screen.dst_ptr == nullptr) return;
1510 
1511  if (_cursor.visible) {
1513  _cursor.visible = false;
1514  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);
1515  VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
1516  }
1517 }
1518 
1519 void DrawMouseCursor()
1520 {
1521  /* Don't draw mouse cursor if it is handled by the video driver. */
1522  if (VideoDriver::GetInstance()->UseSystemCursor()) return;
1523 
1524  /* Don't draw the mouse cursor if the screen is not ready */
1525  if (_screen.dst_ptr == nullptr) return;
1526 
1528 
1529  /* Redraw mouse cursor but only when it's inside the window */
1530  if (!_cursor.in_window) return;
1531 
1532  /* Don't draw the mouse cursor if it's already drawn */
1533  if (_cursor.visible) {
1534  if (!_cursor.dirty) return;
1535  UndrawMouseCursor();
1536  }
1537 
1538  /* Determine visible area */
1539  int left = _cursor.pos.x + _cursor.total_offs.x;
1540  int width = _cursor.total_size.x;
1541  if (left < 0) {
1542  width += left;
1543  left = 0;
1544  }
1545  if (left + width > _screen.width) {
1546  width = _screen.width - left;
1547  }
1548  if (width <= 0) return;
1549 
1550  int top = _cursor.pos.y + _cursor.total_offs.y;
1551  int height = _cursor.total_size.y;
1552  if (top < 0) {
1553  height += top;
1554  top = 0;
1555  }
1556  if (top + height > _screen.height) {
1557  height = _screen.height - top;
1558  }
1559  if (height <= 0) return;
1560 
1561  _cursor.draw_pos.x = left;
1562  _cursor.draw_pos.y = top;
1563  _cursor.draw_size.x = width;
1564  _cursor.draw_size.y = height;
1565 
1566  uint8 *buffer = _cursor_backup.Allocate(blitter->BufferSize(_cursor.draw_size.x, _cursor.draw_size.y));
1567 
1568  /* Make backup of stuff below cursor */
1569  blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), buffer, _cursor.draw_size.x, _cursor.draw_size.y);
1570 
1571  /* Draw cursor on screen */
1572  _cur_dpi = &_screen;
1573  for (uint i = 0; i < _cursor.sprite_count; ++i) {
1574  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);
1575  }
1576 
1577  VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
1578 
1579  _cursor.visible = true;
1580  _cursor.dirty = false;
1581 }
1582 
1593 void RedrawScreenRect(int left, int top, int right, int bottom)
1594 {
1595  assert(right <= _screen.width && bottom <= _screen.height);
1596  if (_cursor.visible) {
1597  if (right > _cursor.draw_pos.x &&
1598  left < _cursor.draw_pos.x + _cursor.draw_size.x &&
1599  bottom > _cursor.draw_pos.y &&
1600  top < _cursor.draw_pos.y + _cursor.draw_size.y) {
1601  UndrawMouseCursor();
1602  }
1603  }
1604 
1606 
1607  DrawOverlappedWindowForAll(left, top, right, bottom);
1608 
1609  VideoDriver::GetInstance()->MakeDirty(left, top, right - left, bottom - top);
1610 }
1611 
1620 {
1621  byte *b = _dirty_blocks;
1622  const int w = Align(_screen.width, DIRTY_BLOCK_WIDTH);
1623  const int h = Align(_screen.height, DIRTY_BLOCK_HEIGHT);
1624  int x;
1625  int y;
1626 
1627  y = 0;
1628  do {
1629  x = 0;
1630  do {
1631  if (*b != 0) {
1632  int left;
1633  int top;
1634  int right = x + DIRTY_BLOCK_WIDTH;
1635  int bottom = y;
1636  byte *p = b;
1637  int h2;
1638 
1639  /* First try coalescing downwards */
1640  do {
1641  *p = 0;
1642  p += _dirty_bytes_per_line;
1643  bottom += DIRTY_BLOCK_HEIGHT;
1644  } while (bottom != h && *p != 0);
1645 
1646  /* Try coalescing to the right too. */
1647  h2 = (bottom - y) / DIRTY_BLOCK_HEIGHT;
1648  assert(h2 > 0);
1649  p = b;
1650 
1651  while (right != w) {
1652  byte *p2 = ++p;
1653  int h = h2;
1654  /* Check if a full line of dirty flags is set. */
1655  do {
1656  if (!*p2) goto no_more_coalesc;
1657  p2 += _dirty_bytes_per_line;
1658  } while (--h != 0);
1659 
1660  /* Wohoo, can combine it one step to the right!
1661  * Do that, and clear the bits. */
1662  right += DIRTY_BLOCK_WIDTH;
1663 
1664  h = h2;
1665  p2 = p;
1666  do {
1667  *p2 = 0;
1668  p2 += _dirty_bytes_per_line;
1669  } while (--h != 0);
1670  }
1671  no_more_coalesc:
1672 
1673  left = x;
1674  top = y;
1675 
1676  if (left < _invalid_rect.left ) left = _invalid_rect.left;
1677  if (top < _invalid_rect.top ) top = _invalid_rect.top;
1678  if (right > _invalid_rect.right ) right = _invalid_rect.right;
1679  if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom;
1680 
1681  if (left < right && top < bottom) {
1682  RedrawScreenRect(left, top, right, bottom);
1683  }
1684 
1685  }
1686  } while (b++, (x += DIRTY_BLOCK_WIDTH) != w);
1687  } while (b += -(int)(w / DIRTY_BLOCK_WIDTH) + _dirty_bytes_per_line, (y += DIRTY_BLOCK_HEIGHT) != h);
1688 
1689  ++_dirty_block_colour;
1690  _invalid_rect.left = w;
1691  _invalid_rect.top = h;
1692  _invalid_rect.right = 0;
1693  _invalid_rect.bottom = 0;
1694 }
1695 
1708 void AddDirtyBlock(int left, int top, int right, int bottom)
1709 {
1710  byte *b;
1711  int width;
1712  int height;
1713 
1714  if (left < 0) left = 0;
1715  if (top < 0) top = 0;
1716  if (right > _screen.width) right = _screen.width;
1717  if (bottom > _screen.height) bottom = _screen.height;
1718 
1719  if (left >= right || top >= bottom) return;
1720 
1721  if (left < _invalid_rect.left ) _invalid_rect.left = left;
1722  if (top < _invalid_rect.top ) _invalid_rect.top = top;
1723  if (right > _invalid_rect.right ) _invalid_rect.right = right;
1724  if (bottom > _invalid_rect.bottom) _invalid_rect.bottom = bottom;
1725 
1726  left /= DIRTY_BLOCK_WIDTH;
1727  top /= DIRTY_BLOCK_HEIGHT;
1728 
1729  b = _dirty_blocks + top * _dirty_bytes_per_line + left;
1730 
1731  width = ((right - 1) / DIRTY_BLOCK_WIDTH) - left + 1;
1732  height = ((bottom - 1) / DIRTY_BLOCK_HEIGHT) - top + 1;
1733 
1734  assert(width > 0 && height > 0);
1735 
1736  do {
1737  int i = width;
1738 
1739  do b[--i] = 0xFF; while (i != 0);
1740 
1741  b += _dirty_bytes_per_line;
1742  } while (--height != 0);
1743 }
1744 
1752 {
1753  AddDirtyBlock(0, 0, _screen.width, _screen.height);
1754 }
1755 
1770 bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
1771 {
1773  const DrawPixelInfo *o = _cur_dpi;
1774 
1775  n->zoom = ZOOM_LVL_NORMAL;
1776 
1777  assert(width > 0);
1778  assert(height > 0);
1779 
1780  if ((left -= o->left) < 0) {
1781  width += left;
1782  if (width <= 0) return false;
1783  n->left = -left;
1784  left = 0;
1785  } else {
1786  n->left = 0;
1787  }
1788 
1789  if (width > o->width - left) {
1790  width = o->width - left;
1791  if (width <= 0) return false;
1792  }
1793  n->width = width;
1794 
1795  if ((top -= o->top) < 0) {
1796  height += top;
1797  if (height <= 0) return false;
1798  n->top = -top;
1799  top = 0;
1800  } else {
1801  n->top = 0;
1802  }
1803 
1804  n->dst_ptr = blitter->MoveTo(o->dst_ptr, left, top);
1805  n->pitch = o->pitch;
1806 
1807  if (height > o->height - top) {
1808  height = o->height - top;
1809  if (height <= 0) return false;
1810  }
1811  n->height = height;
1812 
1813  return true;
1814 }
1815 
1821 {
1822  /* Ignore setting any cursor before the sprites are loaded. */
1823  if (GetMaxSpriteID() == 0) return;
1824 
1825  static_assert(lengthof(_cursor.sprite_seq) == lengthof(_cursor.sprite_pos));
1826  assert(_cursor.sprite_count <= lengthof(_cursor.sprite_seq));
1827  for (uint i = 0; i < _cursor.sprite_count; ++i) {
1828  const Sprite *p = GetSprite(GB(_cursor.sprite_seq[i].sprite, 0, SPRITE_WIDTH), ST_NORMAL);
1829  Point offs, size;
1830  offs.x = UnScaleGUI(p->x_offs) + _cursor.sprite_pos[i].x;
1831  offs.y = UnScaleGUI(p->y_offs) + _cursor.sprite_pos[i].y;
1832  size.x = UnScaleGUI(p->width);
1833  size.y = UnScaleGUI(p->height);
1834 
1835  if (i == 0) {
1836  _cursor.total_offs = offs;
1837  _cursor.total_size = size;
1838  } else {
1839  int right = std::max(_cursor.total_offs.x + _cursor.total_size.x, offs.x + size.x);
1840  int bottom = std::max(_cursor.total_offs.y + _cursor.total_size.y, offs.y + size.y);
1841  if (offs.x < _cursor.total_offs.x) _cursor.total_offs.x = offs.x;
1842  if (offs.y < _cursor.total_offs.y) _cursor.total_offs.y = offs.y;
1843  _cursor.total_size.x = right - _cursor.total_offs.x;
1844  _cursor.total_size.y = bottom - _cursor.total_offs.y;
1845  }
1846  }
1847 
1848  _cursor.dirty = true;
1849 }
1850 
1856 static void SetCursorSprite(CursorID cursor, PaletteID pal)
1857 {
1858  if (_cursor.sprite_count == 1 && _cursor.sprite_seq[0].sprite == cursor && _cursor.sprite_seq[0].pal == pal) return;
1859 
1860  _cursor.sprite_count = 1;
1861  _cursor.sprite_seq[0].sprite = cursor;
1862  _cursor.sprite_seq[0].pal = pal;
1863  _cursor.sprite_pos[0].x = 0;
1864  _cursor.sprite_pos[0].y = 0;
1865 
1866  UpdateCursorSize();
1867 }
1868 
1869 static void SwitchAnimatedCursor()
1870 {
1871  const AnimCursor *cur = _cursor.animate_cur;
1872 
1873  if (cur == nullptr || cur->sprite == AnimCursor::LAST) cur = _cursor.animate_list;
1874 
1875  SetCursorSprite(cur->sprite, _cursor.sprite_seq[0].pal);
1876 
1877  _cursor.animate_timeout = cur->display_time;
1878  _cursor.animate_cur = cur + 1;
1879 }
1880 
1881 void CursorTick()
1882 {
1883  if (_cursor.animate_timeout != 0 && --_cursor.animate_timeout == 0) {
1884  SwitchAnimatedCursor();
1885  }
1886 }
1887 
1892 void SetMouseCursorBusy(bool busy)
1893 {
1894  if (busy) {
1895  if (_cursor.sprite_seq[0].sprite == SPR_CURSOR_MOUSE) SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
1896  } else {
1897  if (_cursor.sprite_seq[0].sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
1898  }
1899 }
1900 
1908 {
1909  /* Turn off animation */
1910  _cursor.animate_timeout = 0;
1911  /* Set cursor */
1912  SetCursorSprite(sprite, pal);
1913 }
1914 
1921 {
1922  _cursor.animate_list = table;
1923  _cursor.animate_cur = nullptr;
1924  _cursor.sprite_seq[0].pal = PAL_NONE;
1925  SwitchAnimatedCursor();
1926 }
1927 
1933 void CursorVars::UpdateCursorPositionRelative(int delta_x, int delta_y)
1934 {
1935  if (this->fix_at) {
1936  this->delta.x = delta_x;
1937  this->delta.y = delta_y;
1938  } else {
1939  int last_position_x = this->pos.x;
1940  int last_position_y = this->pos.y;
1941 
1942  this->pos.x = Clamp(this->pos.x + delta_x, 0, _cur_resolution.width - 1);
1943  this->pos.y = Clamp(this->pos.y + delta_y, 0, _cur_resolution.height - 1);
1944 
1945  this->delta.x = last_position_x - this->pos.x;
1946  this->delta.y = last_position_y - this->pos.y;
1947 
1948  this->dirty = true;
1949  }
1950 }
1951 
1960 bool CursorVars::UpdateCursorPosition(int x, int y, bool queued_warp)
1961 {
1962  /* Detecting relative mouse movement is somewhat tricky.
1963  * - There may be multiple mouse move events in the video driver queue (esp. when OpenTTD lags a bit).
1964  * - When we request warping the mouse position (return true), a mouse move event is appended at the end of the queue.
1965  *
1966  * So, when this->fix_at is active, we use the following strategy:
1967  * - The first movement triggers the warp to reset the mouse position.
1968  * - Subsequent events have to compute movement relative to the previous event.
1969  * - The relative movement is finished, when we receive the event matching the warp.
1970  */
1971 
1972  if (x == this->pos.x && y == this->pos.y) {
1973  /* Warp finished. */
1974  this->queued_warp = false;
1975  }
1976 
1977  this->delta.x = x - (this->queued_warp ? this->last_position.x : this->pos.x);
1978  this->delta.y = y - (this->queued_warp ? this->last_position.y : this->pos.y);
1979 
1980  this->last_position.x = x;
1981  this->last_position.y = y;
1982 
1983  bool need_warp = false;
1984  if (this->fix_at) {
1985  if (this->delta.x != 0 || this->delta.y != 0) {
1986  /* Trigger warp.
1987  * Note: We also trigger warping again, if there is already a pending warp.
1988  * This makes it more tolerant about the OS or other software in between
1989  * botchering the warp. */
1990  this->queued_warp = queued_warp;
1991  need_warp = true;
1992  }
1993  } else if (this->pos.x != x || this->pos.y != y) {
1994  this->queued_warp = false; // Cancel warping, we are no longer confining the position.
1995  this->dirty = true;
1996  this->pos.x = x;
1997  this->pos.y = y;
1998  }
1999  return need_warp;
2000 }
2001 
2002 bool ChangeResInGame(int width, int height)
2003 {
2004  return (_screen.width == width && _screen.height == height) || VideoDriver::GetInstance()->ChangeResolution(width, height);
2005 }
2006 
2007 bool ToggleFullScreen(bool fs)
2008 {
2009  bool result = VideoDriver::GetInstance()->ToggleFullscreen(fs);
2010  if (_fullscreen != fs && _resolutions.empty()) {
2011  Debug(driver, 0, "Could not find a suitable fullscreen resolution");
2012  }
2013  return result;
2014 }
2015 
2016 void SortResolutions()
2017 {
2018  std::sort(_resolutions.begin(), _resolutions.end());
2019 }
2020 
2025 {
2026  /* Determine real GUI zoom to use. */
2027  if (_gui_zoom_cfg == ZOOM_LVL_CFG_AUTO) {
2029  } else {
2030  /* Ensure the gui_zoom is clamped between min/max. Change the
2031  * _gui_zoom_cfg if it isn't, as this is used to visually show the
2032  * selection in the Game Options. */
2034  _gui_zoom = static_cast<ZoomLevel>(_gui_zoom_cfg);
2035  }
2036 
2037  /* Determine real font zoom to use. */
2038  if (_font_zoom_cfg == ZOOM_LVL_CFG_AUTO) {
2040  } else {
2041  _font_zoom = static_cast<ZoomLevel>(_font_zoom_cfg);
2042  }
2043 }
2044 
2045 void ChangeGameSpeed(bool enable_fast_forward)
2046 {
2047  if (enable_fast_forward) {
2049  } else {
2050  _game_speed = 100;
2051  }
2052 }
_dirkeys
byte _dirkeys
1 = left, 2 = up, 4 = right, 8 = down
Definition: gfx.cpp:32
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:1430
PC_WHITE
static const uint8 PC_WHITE
White palette colour.
Definition: gfx_func.h:195
TC_FORCED
@ TC_FORCED
Ignore colour changes from strings.
Definition: gfx_type.h:275
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:1892
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:421
Palette::first_dirty
int first_dirty
The first dirty element.
Definition: gfx_type.h:315
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:331
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:164
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:35
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:1708
UnScaleByZoomLower
static int UnScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
Definition: zoom_func.h:56
_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:78
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:1522
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:39
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:1525
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:321
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:281
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:213
lock
std::mutex lock
synchronization for playback status fields
Definition: win32_m.cpp:34
FS_BEGIN
@ FS_BEGIN
First font.
Definition: gfx_type.h:213
GetContrastColour
TextColour GetContrastColour(uint8 background, uint8 threshold)
Determine a contrasty text colour for a coloured background.
Definition: gfx.cpp:1416
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:289
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:66
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:36
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:288
_font_zoom_cfg
int8 _font_zoom_cfg
Font zoom level in config.
Definition: gfx.cpp:66
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
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:21
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:335
Layouter::GetCharPosition
Point GetCharPosition(const char *ch) const
Get the position of a character in the layout.
Definition: gfx_layout.cpp:762
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:327
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:52
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:643
SetColourRemap
static void SetColourRemap(TextColour colour)
Set the colour remap to be for the given colour.
Definition: gfx.cpp:456
newgrf_debug.h
FillRectMode
FillRectMode
Define the operation GfxFillRect performs.
Definition: gfx_type.h:286
ST_NORMAL
@ ST_NORMAL
The most basic (normal) sprite.
Definition: gfx_type.h:302
CursorVars::UpdateCursorPositionRelative
void UpdateCursorPositionRelative(int delta_x, int delta_y)
Update cursor position on mouse movement for relative modes.
Definition: gfx.cpp:1933
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:330
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition: gfx_type.h:334
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:62
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:316
VideoDriver::GetSuggestedUIZoom
virtual ZoomLevel GetSuggestedUIZoom()
Get a suggested default GUI zoom taking screen DPI into account.
Definition: video_driver.hpp:172
CursorVars::draw_size
Point draw_size
position and size bounding-box for drawing
Definition: gfx_type.h:133
SubSprite
Used to only draw a part of the sprite.
Definition: gfx_type.h:222
GUISettings::zoom_max
ZoomLevel zoom_max
maximum zoom out level
Definition: settings_type.h:132
_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:53
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:889
GetStringLineCount
int GetStringLineCount(StringID str, int maxw)
Calculates number of lines of string.
Definition: gfx.cpp:739
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:788
_palette_mutex
static std::recursive_mutex _palette_mutex
To coordinate access to _cur_palette.
Definition: gfx.cpp:55
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:577
control_codes.h
UpdateCursorSize
void UpdateCursorSize()
Update cursor dimension.
Definition: gfx.cpp:1820
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:134
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:486
_extra_palette_values
static const ExtraPaletteValues _extra_palette_values
Actual palette animation tables.
Definition: palettes.h:115
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
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:970
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:174
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:207
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:333
SetMouseCursor
void SetMouseCursor(CursorID sprite, PaletteID pal)
Assign a single non-animated sprite to the cursor.
Definition: gfx.cpp:1907
PALETTE_WIDTH
@ PALETTE_WIDTH
number of bits of the sprite containing the recolour palette
Definition: sprites.h:1524
ReInitAllWindows
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
Definition: window.cpp:3347
CursorVars::UpdateCursorPosition
bool UpdateCursorPosition(int x, int y, bool queued_warp)
Update cursor position on mouse movement.
Definition: gfx.cpp:1960
_screen_disable_anim
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
Definition: gfx.cpp:44
Palette::palette
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition: gfx_type.h:314
Layouter::GetBounds
Dimension GetBounds()
Get the boundaries of this paragraph.
Definition: gfx_layout.cpp:746
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:153
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:1197
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:48
FONT_HEIGHT_MONO
#define FONT_HEIGHT_MONO
Height of characters in the large (FS_MONO) font.
Definition: gfx_func.h:173
_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:53
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:273
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:340
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:945
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:24
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:1593
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:274
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:57
_shift_pressed
bool _shift_pressed
Is Shift pressed?
Definition: gfx.cpp:37
DrawDirtyBlocks
void DrawDirtyBlocks()
Repaints the rectangle blocks which are marked as 'dirty'.
Definition: gfx.cpp:1619
FONT_HEIGHT_LARGE
#define FONT_HEIGHT_LARGE
Height of characters in the large (FS_LARGE) font.
Definition: gfx_func.h:170
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:1042
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:754
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:126
DrawCharCentered
void DrawCharCentered(WChar c, const Rect &r, TextColour colour)
Draw single character horizontally centered around (x,y)
Definition: gfx.cpp:960
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:1920
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:276
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:117
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:76
Palette::count_dirty
int count_dirty
The number of dirty elements.
Definition: gfx_type.h:316
PALETTE_MODIFIER_TRANSPARENT
@ PALETTE_MODIFIER_TRANSPARENT
when a sprite is to be displayed transparently, this bit needs to be set.
Definition: sprites.h:1539
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:199
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:329
PALETTE_ANIM_START
@ PALETTE_ANIM_START
Index in the _palettes array from which all animations are taking places (table/palettes....
Definition: gfx_type.h:282
GetDigitWidth
byte GetDigitWidth(FontSize size)
Return the maximum width of single digit.
Definition: gfx.cpp:1462
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:1477
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:1770
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:164
ParagraphLayouter::VisualRun
Visual run contains data about the bit of text with the same font.
Definition: gfx_layout.h:122
Colour
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:163
GetGlyphWidth
static uint GetGlyphWidth(FontSize size, WChar key)
Get the width of a glyph.
Definition: fontcache.h:204
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:714
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:977
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:131
_gui_zoom_cfg
int8 _gui_zoom_cfg
GUI zoom level in config.
Definition: gfx.cpp:65
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:47
_font_zoom
ZoomLevel _font_zoom
Font Zoom level.
Definition: gfx.cpp:63
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:1073
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:1600
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:336
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:167
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:220
Layouter::GetCharAtPosition
const char * GetCharAtPosition(int x) const
Get the character that is at a position.
Definition: gfx_layout.cpp:809
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
_stringwidth_table
static byte _stringwidth_table[FS_END][224]
Cache containing width of often used characters.
Definition: gfx.cpp:51
GetGlyph
static const Sprite * GetGlyph(FontSize size, WChar key)
Get the Sprite for a glyph.
Definition: fontcache.h:197
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:1278
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:997
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:174
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:374
SetCursorSprite
static void SetCursorSprite(CursorID cursor, PaletteID pal)
Switch cursor to different sprite.
Definition: gfx.cpp:1856
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
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:49
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:328
network.h
GetCharacterWidth
byte GetCharacterWidth(FontSize size, WChar key)
Return width of character glyph.
Definition: gfx.cpp:1449
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:139
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:378
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1751
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:210
ZOOM_LVL_NORMAL
@ ZOOM_LVL_NORMAL
The normal zoom level.
Definition: zoom_type.h:24
SPR_CURSOR_MOUSE
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1380
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:254
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:206
ST_RECOLOUR
@ ST_RECOLOUR
Recolour sprite.
Definition: gfx_type.h:305
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:47
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:42
Palette
Information about the currently used palette.
Definition: gfx_type.h:313
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:932
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:394
UpdateGUIZoom
void UpdateGUIZoom()
Resolve GUI zoom level, if auto-suggestion is requested.
Definition: gfx.cpp:2024
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:40
_cur_resolution
Dimension _cur_resolution
The current resolution.
Definition: driver.cpp:25
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:48
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:38
_right_button_down
bool _right_button_down
Is right mouse button pressed?
Definition: gfx.cpp:41
PALETTE_ALL_BLACK
static const PaletteID PALETTE_ALL_BLACK
Exchange any color by black, needed for painting fictive tiles outside map.
Definition: sprites.h:1606
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:594
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:155
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:1015