OpenTTD
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 
24 #include "table/palettes.h"
25 #include "table/string_colours.h"
26 #include "table/sprites.h"
27 #include "table/control_codes.h"
28 
29 #include "safeguards.h"
30 
31 byte _dirkeys;
32 bool _fullscreen;
33 byte _support8bpp;
34 CursorVars _cursor;
37 byte _fast_forward;
42 DrawPixelInfo _screen;
43 bool _screen_disable_anim = false;
44 bool _exit_game;
45 GameMode _game_mode;
49 
50 static byte _stringwidth_table[FS_END][224];
51 DrawPixelInfo *_cur_dpi;
52 byte _colour_gradient[COLOUR_END][8];
53 
54 static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = nullptr, SpriteID sprite_id = SPR_CURSOR_MOUSE);
55 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);
56 
57 static ReusableBuffer<uint8> _cursor_backup;
58 
61 
70 static const byte *_colour_remap_ptr;
71 static byte _string_colourremap[3];
72 
73 static const uint DIRTY_BLOCK_HEIGHT = 8;
74 static const uint DIRTY_BLOCK_WIDTH = 64;
75 
76 static uint _dirty_bytes_per_line = 0;
77 static byte *_dirty_blocks = nullptr;
78 extern uint _dirty_block_colour;
79 
80 void GfxScroll(int left, int top, int width, int height, int xo, int yo)
81 {
83 
84  if (xo == 0 && yo == 0) return;
85 
86  if (_cursor.visible) UndrawMouseCursor();
87 
89 
90  blitter->ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo);
91  /* This part of the screen is now dirty. */
92  VideoDriver::GetInstance()->MakeDirty(left, top, width, height);
93 }
94 
95 
110 void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
111 {
113  const DrawPixelInfo *dpi = _cur_dpi;
114  void *dst;
115  const int otop = top;
116  const int oleft = left;
117 
118  if (dpi->zoom != ZOOM_LVL_NORMAL) return;
119  if (left > right || top > bottom) return;
120  if (right < dpi->left || left >= dpi->left + dpi->width) return;
121  if (bottom < dpi->top || top >= dpi->top + dpi->height) return;
122 
123  if ( (left -= dpi->left) < 0) left = 0;
124  right = right - dpi->left + 1;
125  if (right > dpi->width) right = dpi->width;
126  right -= left;
127  assert(right > 0);
128 
129  if ( (top -= dpi->top) < 0) top = 0;
130  bottom = bottom - dpi->top + 1;
131  if (bottom > dpi->height) bottom = dpi->height;
132  bottom -= top;
133  assert(bottom > 0);
134 
135  dst = blitter->MoveTo(dpi->dst_ptr, left, top);
136 
137  switch (mode) {
138  default: // FILLRECT_OPAQUE
139  blitter->DrawRect(dst, right, bottom, (uint8)colour);
140  break;
141 
142  case FILLRECT_RECOLOUR:
143  blitter->DrawColourMappingRect(dst, right, bottom, GB(colour, 0, PALETTE_WIDTH));
144  break;
145 
146  case FILLRECT_CHECKER: {
147  byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
148  do {
149  for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)colour);
150  dst = blitter->MoveTo(dst, 0, 1);
151  } while (--bottom > 0);
152  break;
153  }
154  }
155 }
156 
171 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)
172 {
174 
175  assert(width > 0);
176 
177  if (y2 == y || x2 == x) {
178  /* Special case: horizontal/vertical line. All checks already done in GfxPreprocessLine. */
179  blitter->DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width, dash);
180  return;
181  }
182 
183  int grade_y = y2 - y;
184  int grade_x = x2 - x;
185 
186  /* Clipping rectangle. Slightly extended so we can ignore the width of the line. */
187  int extra = (int)CeilDiv(3 * width, 4); // not less then "width * sqrt(2) / 2"
188  Rect clip = { -extra, -extra, screen_width - 1 + extra, screen_height - 1 + extra };
189 
190  /* prevent integer overflows. */
191  int margin = 1;
192  while (INT_MAX / abs(grade_y) < max(abs(clip.left - x), abs(clip.right - x))) {
193  grade_y /= 2;
194  grade_x /= 2;
195  margin *= 2; // account for rounding errors
196  }
197 
198  /* Imagine that the line is infinitely long and it intersects with
199  * infinitely long left and right edges of the clipping rectangle.
200  * If both intersection points are outside the clipping rectangle
201  * and both on the same side of it, we don't need to draw anything. */
202  int left_isec_y = y + (clip.left - x) * grade_y / grade_x;
203  int right_isec_y = y + (clip.right - x) * grade_y / grade_x;
204  if ((left_isec_y > clip.bottom + margin && right_isec_y > clip.bottom + margin) ||
205  (left_isec_y < clip.top - margin && right_isec_y < clip.top - margin)) {
206  return;
207  }
208 
209  /* It is possible to use the line equation to further reduce the amount of
210  * work the blitter has to do by shortening the effective line segment.
211  * However, in order to get that right and prevent the flickering effects
212  * of rounding errors so much additional code has to be run here that in
213  * the general case the effect is not noticeable. */
214 
215  blitter->DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width, dash);
216 }
217 
229 static inline bool GfxPreprocessLine(DrawPixelInfo *dpi, int &x, int &y, int &x2, int &y2, int width)
230 {
231  x -= dpi->left;
232  x2 -= dpi->left;
233  y -= dpi->top;
234  y2 -= dpi->top;
235 
236  /* Check simple clipping */
237  if (x + width / 2 < 0 && x2 + width / 2 < 0 ) return false;
238  if (y + width / 2 < 0 && y2 + width / 2 < 0 ) return false;
239  if (x - width / 2 > dpi->width && x2 - width / 2 > dpi->width ) return false;
240  if (y - width / 2 > dpi->height && y2 - width / 2 > dpi->height) return false;
241  return true;
242 }
243 
244 void GfxDrawLine(int x, int y, int x2, int y2, int colour, int width, int dash)
245 {
246  DrawPixelInfo *dpi = _cur_dpi;
247  if (GfxPreprocessLine(dpi, x, y, x2, y2, width)) {
248  GfxDoDrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, colour, width, dash);
249  }
250 }
251 
252 void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int colour)
253 {
254  DrawPixelInfo *dpi = _cur_dpi;
255  if (GfxPreprocessLine(dpi, x, y, x2, y2, 1)) {
256  GfxDoDrawLine(dpi->dst_ptr,
257  UnScaleByZoom(x, dpi->zoom), UnScaleByZoom(y, dpi->zoom),
258  UnScaleByZoom(x2, dpi->zoom), UnScaleByZoom(y2, dpi->zoom),
259  UnScaleByZoom(dpi->width, dpi->zoom), UnScaleByZoom(dpi->height, dpi->zoom), colour, 1);
260  }
261 }
262 
276 void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
277 {
278  /* ....
279  * .. ....
280  * .. ....
281  * .. ^
282  * <--__(dx1,dy1) /(dx2,dy2)
283  * : --__ / :
284  * : --__ / :
285  * : *(x,y) :
286  * : | :
287  * : | ..
288  * .... |(dx3,dy3)
289  * .... | ..
290  * ....V.
291  */
292 
293  static const byte colour = PC_WHITE;
294 
295  GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, colour);
296  GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, colour);
297  GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, colour);
298 
299  GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, colour);
300  GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, colour);
301  GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, colour);
302  GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, colour);
303  GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, colour);
304  GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, colour);
305 }
306 
311 static void SetColourRemap(TextColour colour)
312 {
313  if (colour == TC_INVALID) return;
314 
315  /* Black strings have no shading ever; the shading is black, so it
316  * would be invisible at best, but it actually makes it illegible. */
317  bool no_shade = (colour & TC_NO_SHADE) != 0 || colour == TC_BLACK;
318  bool raw_colour = (colour & TC_IS_PALETTE_COLOUR) != 0;
319  colour &= ~(TC_NO_SHADE | TC_IS_PALETTE_COLOUR | TC_FORCED);
320 
321  _string_colourremap[1] = raw_colour ? (byte)colour : _string_colourmap[colour];
322  _string_colourremap[2] = no_shade ? 0 : 1;
323  _colour_remap_ptr = _string_colourremap;
324 }
325 
341 static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left, int right, StringAlignment align, bool underline, bool truncation)
342 {
343  if (line.CountRuns() == 0) return 0;
344 
345  int w = line.GetWidth();
346  int h = line.GetLeading();
347 
348  /*
349  * The following is needed for truncation.
350  * Depending on the text direction, we either remove bits at the rear
351  * or the front. For this we shift the entire area to draw so it fits
352  * within the left/right bounds and the side we do not truncate it on.
353  * Then we determine the truncation location, i.e. glyphs that fall
354  * outside of the range min_x - max_x will not be drawn; they are thus
355  * the truncated glyphs.
356  *
357  * At a later step we insert the dots.
358  */
359 
360  int max_w = right - left + 1; // The maximum width.
361 
362  int offset_x = 0; // The offset we need for positioning the glyphs
363  int min_x = left; // The minimum x position to draw normal glyphs on.
364  int max_x = right; // The maximum x position to draw normal glyphs on.
365 
366  truncation &= max_w < w; // Whether we need to do truncation.
367  int dot_width = 0; // Cache for the width of the dot.
368  const Sprite *dot_sprite = nullptr; // Cache for the sprite of the dot.
369 
370  if (truncation) {
371  /*
372  * Assumption may be made that all fonts of a run are of the same size.
373  * In any case, we'll use these dots for the abbreviation, so even if
374  * another size would be chosen it won't have truncated too little for
375  * the truncation dots.
376  */
377  FontCache *fc = ((const Font*)line.GetVisualRun(0).GetFont())->fc;
378  GlyphID dot_glyph = fc->MapCharToGlyph('.');
379  dot_width = fc->GetGlyphWidth(dot_glyph);
380  dot_sprite = fc->GetGlyph(dot_glyph);
381 
382  if (_current_text_dir == TD_RTL) {
383  min_x += 3 * dot_width;
384  offset_x = w - 3 * dot_width - max_w;
385  } else {
386  max_x -= 3 * dot_width;
387  }
388 
389  w = max_w;
390  }
391 
392  /* In case we have a RTL language we swap the alignment. */
393  if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT;
394 
395  /* right is the right most position to draw on. In this case we want to do
396  * calculations with the width of the string. In comparison right can be
397  * seen as lastof(todraw) and width as lengthof(todraw). They differ by 1.
398  * So most +1/-1 additions are to move from lengthof to 'indices'.
399  */
400  switch (align & SA_HOR_MASK) {
401  case SA_LEFT:
402  /* right + 1 = left + w */
403  right = left + w - 1;
404  break;
405 
406  case SA_HOR_CENTER:
407  left = RoundDivSU(right + 1 + left - w, 2);
408  /* right + 1 = left + w */
409  right = left + w - 1;
410  break;
411 
412  case SA_RIGHT:
413  left = right + 1 - w;
414  break;
415 
416  default:
417  NOT_REACHED();
418  }
419 
420  TextColour colour = TC_BLACK;
421  bool draw_shadow = false;
422  for (int run_index = 0; run_index < line.CountRuns(); run_index++) {
423  const ParagraphLayouter::VisualRun &run = line.GetVisualRun(run_index);
424  const Font *f = (const Font*)run.GetFont();
425 
426  FontCache *fc = f->fc;
427  colour = f->colour;
428  SetColourRemap(colour);
429 
430  DrawPixelInfo *dpi = _cur_dpi;
431  int dpi_left = dpi->left;
432  int dpi_right = dpi->left + dpi->width - 1;
433 
434  draw_shadow = fc->GetDrawGlyphShadow() && (colour & TC_NO_SHADE) == 0 && colour != TC_BLACK;
435 
436  for (int i = 0; i < run.GetGlyphCount(); i++) {
437  GlyphID glyph = run.GetGlyphs()[i];
438 
439  /* Not a valid glyph (empty) */
440  if (glyph == 0xFFFF) continue;
441 
442  int begin_x = (int)run.GetPositions()[i * 2] + left - offset_x;
443  int end_x = (int)run.GetPositions()[i * 2 + 2] + left - offset_x - 1;
444  int top = (int)run.GetPositions()[i * 2 + 1] + y;
445 
446  /* Truncated away. */
447  if (truncation && (begin_x < min_x || end_x > max_x)) continue;
448 
449  const Sprite *sprite = fc->GetGlyph(glyph);
450  /* Check clipping (the "+ 1" is for the shadow). */
451  if (begin_x + sprite->x_offs > dpi_right || begin_x + sprite->x_offs + sprite->width /* - 1 + 1 */ < dpi_left) continue;
452 
453  if (draw_shadow && (glyph & SPRITE_GLYPH) == 0) {
454  SetColourRemap(TC_BLACK);
455  GfxMainBlitter(sprite, begin_x + 1, top + 1, BM_COLOUR_REMAP);
456  SetColourRemap(colour);
457  }
458  GfxMainBlitter(sprite, begin_x, top, BM_COLOUR_REMAP);
459  }
460  }
461 
462  if (truncation) {
463  int x = (_current_text_dir == TD_RTL) ? left : (right - 3 * dot_width);
464  for (int i = 0; i < 3; i++, x += dot_width) {
465  if (draw_shadow) {
466  SetColourRemap(TC_BLACK);
467  GfxMainBlitter(dot_sprite, x + 1, y + 1, BM_COLOUR_REMAP);
468  SetColourRemap(colour);
469  }
470  GfxMainBlitter(dot_sprite, x, y, BM_COLOUR_REMAP);
471  }
472  }
473 
474  if (underline) {
475  GfxFillRect(left, y + h, right, y + h, _string_colourremap[1]);
476  }
477 
478  return (align & SA_HOR_MASK) == SA_RIGHT ? left : right;
479 }
480 
498 int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
499 {
500  /* The string may contain control chars to change the font, just use the biggest font for clipping. */
502 
503  /* Funny glyphs may extent outside the usual bounds, so relax the clipping somewhat. */
504  int extra = max_height / 2;
505 
506  if (_cur_dpi->top + _cur_dpi->height + extra < top || _cur_dpi->top > top + max_height + extra ||
507  _cur_dpi->left + _cur_dpi->width + extra < left || _cur_dpi->left > right + extra) {
508  return 0;
509  }
510 
511  Layouter layout(str, INT32_MAX, colour, fontsize);
512  if (layout.size() == 0) return 0;
513 
514  return DrawLayoutLine(*layout.front(), top, left, right, align, underline, true);
515 }
516 
534 int DrawString(int left, int right, int top, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
535 {
536  char buffer[DRAW_STRING_BUFFER];
537  GetString(buffer, str, lastof(buffer));
538  return DrawString(left, right, top, buffer, colour, align, underline, fontsize);
539 }
540 
547 int GetStringHeight(const char *str, int maxw, FontSize fontsize)
548 {
549  Layouter layout(str, maxw, TC_FROMSTRING, fontsize);
550  return layout.GetBounds().height;
551 }
552 
559 int GetStringHeight(StringID str, int maxw)
560 {
561  char buffer[DRAW_STRING_BUFFER];
562  GetString(buffer, str, lastof(buffer));
563  return GetStringHeight(buffer, maxw);
564 }
565 
572 int GetStringLineCount(StringID str, int maxw)
573 {
574  char buffer[DRAW_STRING_BUFFER];
575  GetString(buffer, str, lastof(buffer));
576 
577  Layouter layout(buffer, maxw);
578  return (uint)layout.size();
579 }
580 
588 {
589  Dimension box = {suggestion.width, (uint)GetStringHeight(str, suggestion.width)};
590  return box;
591 }
592 
599 Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion)
600 {
601  Dimension box = {suggestion.width, (uint)GetStringHeight(str, suggestion.width)};
602  return box;
603 }
604 
621 int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
622 {
623  int maxw = right - left + 1;
624  int maxh = bottom - top + 1;
625 
626  /* It makes no sense to even try if it can't be drawn anyway, or
627  * do we really want to support fonts of 0 or less pixels high? */
628  if (maxh <= 0) return top;
629 
630  Layouter layout(str, maxw, colour, fontsize);
631  int total_height = layout.GetBounds().height;
632  int y;
633  switch (align & SA_VERT_MASK) {
634  case SA_TOP:
635  y = top;
636  break;
637 
638  case SA_VERT_CENTER:
639  y = RoundDivSU(bottom + top - total_height, 2);
640  break;
641 
642  case SA_BOTTOM:
643  y = bottom - total_height;
644  break;
645 
646  default: NOT_REACHED();
647  }
648 
649  int last_line = top;
650  int first_line = bottom;
651 
652  for (const auto &line : layout) {
653 
654  int line_height = line->GetLeading();
655  if (y >= top && y < bottom) {
656  last_line = y + line_height;
657  if (first_line > y) first_line = y;
658 
659  DrawLayoutLine(*line, y, left, right, align, underline, false);
660  }
661  y += line_height;
662  }
663 
664  return ((align & SA_VERT_MASK) == SA_BOTTOM) ? first_line : last_line;
665 }
666 
683 int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
684 {
685  char buffer[DRAW_STRING_BUFFER];
686  GetString(buffer, str, lastof(buffer));
687  return DrawStringMultiLine(left, right, top, bottom, buffer, colour, align, underline, fontsize);
688 }
689 
700 Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
701 {
702  Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
703  return layout.GetBounds();
704 }
705 
713 {
714  char buffer[DRAW_STRING_BUFFER];
715 
716  GetString(buffer, strid, lastof(buffer));
717  return GetStringBoundingBox(buffer);
718 }
719 
728 Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize)
729 {
730  Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
731  return layout.GetCharPosition(ch);
732 }
733 
741 const char *GetCharAtPosition(const char *str, int x, FontSize start_fontsize)
742 {
743  if (x < 0) return nullptr;
744 
745  Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
746  return layout.GetCharAtPosition(x);
747 }
748 
757 void DrawCharCentered(WChar c, int x, int y, TextColour colour)
758 {
759  SetColourRemap(colour);
760  GfxMainBlitter(GetGlyph(FS_NORMAL, c), x - GetCharacterWidth(FS_NORMAL, c) / 2, y, BM_COLOUR_REMAP);
761 }
762 
771 {
772  const Sprite *sprite = GetSprite(sprid, ST_NORMAL);
773 
774  if (offset != nullptr) {
775  offset->x = UnScaleByZoom(sprite->x_offs, zoom);
776  offset->y = UnScaleByZoom(sprite->y_offs, zoom);
777  }
778 
779  Dimension d;
780  d.width = max<int>(0, UnScaleByZoom(sprite->x_offs + sprite->width, zoom));
781  d.height = max<int>(0, UnScaleByZoom(sprite->y_offs + sprite->height, zoom));
782  return d;
783 }
784 
791 {
792  switch (pal) {
793  case PAL_NONE: return BM_NORMAL;
794  case PALETTE_CRASH: return BM_CRASH_REMAP;
795  case PALETTE_ALL_BLACK: return BM_BLACK_REMAP;
796  default: return BM_COLOUR_REMAP;
797  }
798 }
799 
808 void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
809 {
810  SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
812  _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
813  GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite);
814  } else if (pal != PAL_NONE) {
815  if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
817  } else {
818  _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
819  }
820  GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite);
821  } else {
822  GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite);
823  }
824 }
825 
835 void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
836 {
837  SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
839  _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
840  GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite, zoom);
841  } else if (pal != PAL_NONE) {
842  if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
844  } else {
845  _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
846  }
847  GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite, zoom);
848  } else {
849  GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite, zoom);
850  }
851 }
852 
864 template <int ZOOM_BASE, bool SCALED_XY>
865 static void GfxBlitter(const Sprite * const sprite, int x, int y, BlitterMode mode, const SubSprite * const sub, SpriteID sprite_id, ZoomLevel zoom)
866 {
867  const DrawPixelInfo *dpi = _cur_dpi;
869 
870  if (SCALED_XY) {
871  /* Scale it */
872  x = ScaleByZoom(x, zoom);
873  y = ScaleByZoom(y, zoom);
874  }
875 
876  /* Move to the correct offset */
877  x += sprite->x_offs;
878  y += sprite->y_offs;
879 
880  if (sub == nullptr) {
881  /* No clipping. */
882  bp.skip_left = 0;
883  bp.skip_top = 0;
884  bp.width = UnScaleByZoom(sprite->width, zoom);
885  bp.height = UnScaleByZoom(sprite->height, zoom);
886  } else {
887  /* Amount of pixels to clip from the source sprite */
888  int clip_left = max(0, -sprite->x_offs + sub->left * ZOOM_BASE );
889  int clip_top = max(0, -sprite->y_offs + sub->top * ZOOM_BASE );
890  int clip_right = max(0, sprite->width - (-sprite->x_offs + (sub->right + 1) * ZOOM_BASE));
891  int clip_bottom = max(0, sprite->height - (-sprite->y_offs + (sub->bottom + 1) * ZOOM_BASE));
892 
893  if (clip_left + clip_right >= sprite->width) return;
894  if (clip_top + clip_bottom >= sprite->height) return;
895 
896  bp.skip_left = UnScaleByZoomLower(clip_left, zoom);
897  bp.skip_top = UnScaleByZoomLower(clip_top, zoom);
898  bp.width = UnScaleByZoom(sprite->width - clip_left - clip_right, zoom);
899  bp.height = UnScaleByZoom(sprite->height - clip_top - clip_bottom, zoom);
900 
901  x += ScaleByZoom(bp.skip_left, zoom);
902  y += ScaleByZoom(bp.skip_top, zoom);
903  }
904 
905  /* Copy the main data directly from the sprite */
906  bp.sprite = sprite->data;
907  bp.sprite_width = sprite->width;
908  bp.sprite_height = sprite->height;
909  bp.top = 0;
910  bp.left = 0;
911 
912  bp.dst = dpi->dst_ptr;
913  bp.pitch = dpi->pitch;
914  bp.remap = _colour_remap_ptr;
915 
916  assert(sprite->width > 0);
917  assert(sprite->height > 0);
918 
919  if (bp.width <= 0) return;
920  if (bp.height <= 0) return;
921 
922  y -= SCALED_XY ? ScaleByZoom(dpi->top, zoom) : dpi->top;
923  int y_unscaled = UnScaleByZoom(y, zoom);
924  /* Check for top overflow */
925  if (y < 0) {
926  bp.height -= -y_unscaled;
927  if (bp.height <= 0) return;
928  bp.skip_top += -y_unscaled;
929  y = 0;
930  } else {
931  bp.top = y_unscaled;
932  }
933 
934  /* Check for bottom overflow */
935  y += SCALED_XY ? ScaleByZoom(bp.height - dpi->height, zoom) : ScaleByZoom(bp.height, zoom) - dpi->height;
936  if (y > 0) {
937  bp.height -= UnScaleByZoom(y, zoom);
938  if (bp.height <= 0) return;
939  }
940 
941  x -= SCALED_XY ? ScaleByZoom(dpi->left, zoom) : dpi->left;
942  int x_unscaled = UnScaleByZoom(x, zoom);
943  /* Check for left overflow */
944  if (x < 0) {
945  bp.width -= -x_unscaled;
946  if (bp.width <= 0) return;
947  bp.skip_left += -x_unscaled;
948  x = 0;
949  } else {
950  bp.left = x_unscaled;
951  }
952 
953  /* Check for right overflow */
954  x += SCALED_XY ? ScaleByZoom(bp.width - dpi->width, zoom) : ScaleByZoom(bp.width, zoom) - dpi->width;
955  if (x > 0) {
956  bp.width -= UnScaleByZoom(x, zoom);
957  if (bp.width <= 0) return;
958  }
959 
960  assert(bp.skip_left + bp.width <= UnScaleByZoom(sprite->width, zoom));
961  assert(bp.skip_top + bp.height <= UnScaleByZoom(sprite->height, zoom));
962 
963  /* We do not want to catch the mouse. However we also use that spritenumber for unknown (text) sprites. */
964  if (_newgrf_debug_sprite_picker.mode == SPM_REDRAW && sprite_id != SPR_CURSOR_MOUSE) {
966  void *topleft = blitter->MoveTo(bp.dst, bp.left, bp.top);
967  void *bottomright = blitter->MoveTo(topleft, bp.width - 1, bp.height - 1);
968 
970 
971  if (topleft <= clicked && clicked <= bottomright) {
972  uint offset = (((size_t)clicked - (size_t)topleft) / (blitter->GetScreenDepth() / 8)) % bp.pitch;
973  if (offset < (uint)bp.width) {
975  }
976  }
977  }
978 
979  BlitterFactory::GetCurrentBlitter()->Draw(&bp, mode, zoom);
980 }
981 
982 static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub, SpriteID sprite_id)
983 {
984  GfxBlitter<ZOOM_LVL_BASE, false>(sprite, x, y, mode, sub, sprite_id, _cur_dpi->zoom);
985 }
986 
987 static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub, SpriteID sprite_id, ZoomLevel zoom)
988 {
989  GfxBlitter<1, true>(sprite, x, y, mode, sub, sprite_id, zoom);
990 }
991 
992 void DoPaletteAnimations();
993 
994 void GfxInitPalettes()
995 {
996  memcpy(&_cur_palette, &_palette, sizeof(_cur_palette));
997  DoPaletteAnimations();
998 }
999 
1000 #define EXTR(p, q) (((uint16)(palette_animation_counter * (p)) * (q)) >> 16)
1001 #define EXTR2(p, q) (((uint16)(~palette_animation_counter * (p)) * (q)) >> 16)
1002 
1003 void DoPaletteAnimations()
1004 {
1005  /* Animation counter for the palette animation. */
1006  static int palette_animation_counter = 0;
1007  palette_animation_counter += 8;
1008 
1010  const Colour *s;
1012  Colour old_val[PALETTE_ANIM_SIZE];
1013  const uint old_tc = palette_animation_counter;
1014  uint i;
1015  uint j;
1016 
1017  if (blitter != nullptr && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
1018  palette_animation_counter = 0;
1019  }
1020 
1021  Colour *palette_pos = &_cur_palette.palette[PALETTE_ANIM_START]; // Points to where animations are taking place on the palette
1022  /* Makes a copy of the current animation palette in old_val,
1023  * so the work on the current palette could be compared, see if there has been any changes */
1024  memcpy(old_val, palette_pos, sizeof(old_val));
1025 
1026  /* Fizzy Drink bubbles animation */
1027  s = ev->fizzy_drink;
1028  j = EXTR2(512, EPV_CYCLES_FIZZY_DRINK);
1029  for (i = 0; i != EPV_CYCLES_FIZZY_DRINK; i++) {
1030  *palette_pos++ = s[j];
1031  j++;
1032  if (j == EPV_CYCLES_FIZZY_DRINK) j = 0;
1033  }
1034 
1035  /* Oil refinery fire animation */
1036  s = ev->oil_refinery;
1037  j = EXTR2(512, EPV_CYCLES_OIL_REFINERY);
1038  for (i = 0; i != EPV_CYCLES_OIL_REFINERY; i++) {
1039  *palette_pos++ = s[j];
1040  j++;
1041  if (j == EPV_CYCLES_OIL_REFINERY) j = 0;
1042  }
1043 
1044  /* Radio tower blinking */
1045  {
1046  byte i = (palette_animation_counter >> 1) & 0x7F;
1047  byte v;
1048 
1049  if (i < 0x3f) {
1050  v = 255;
1051  } else if (i < 0x4A || i >= 0x75) {
1052  v = 128;
1053  } else {
1054  v = 20;
1055  }
1056  palette_pos->r = v;
1057  palette_pos->g = 0;
1058  palette_pos->b = 0;
1059  palette_pos++;
1060 
1061  i ^= 0x40;
1062  if (i < 0x3f) {
1063  v = 255;
1064  } else if (i < 0x4A || i >= 0x75) {
1065  v = 128;
1066  } else {
1067  v = 20;
1068  }
1069  palette_pos->r = v;
1070  palette_pos->g = 0;
1071  palette_pos->b = 0;
1072  palette_pos++;
1073  }
1074 
1075  /* Handle lighthouse and stadium animation */
1076  s = ev->lighthouse;
1077  j = EXTR(256, EPV_CYCLES_LIGHTHOUSE);
1078  for (i = 0; i != EPV_CYCLES_LIGHTHOUSE; i++) {
1079  *palette_pos++ = s[j];
1080  j++;
1081  if (j == EPV_CYCLES_LIGHTHOUSE) j = 0;
1082  }
1083 
1084  /* Dark blue water */
1085  s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->dark_water_toyland : ev->dark_water;
1086  j = EXTR(320, EPV_CYCLES_DARK_WATER);
1087  for (i = 0; i != EPV_CYCLES_DARK_WATER; i++) {
1088  *palette_pos++ = s[j];
1089  j++;
1090  if (j == EPV_CYCLES_DARK_WATER) j = 0;
1091  }
1092 
1093  /* Glittery water */
1095  j = EXTR(128, EPV_CYCLES_GLITTER_WATER);
1096  for (i = 0; i != EPV_CYCLES_GLITTER_WATER / 3; i++) {
1097  *palette_pos++ = s[j];
1098  j += 3;
1100  }
1101 
1102  if (blitter != nullptr && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
1103  palette_animation_counter = old_tc;
1104  } else {
1105  if (memcmp(old_val, &_cur_palette.palette[PALETTE_ANIM_START], sizeof(old_val)) != 0 && _cur_palette.count_dirty == 0) {
1106  /* Did we changed anything on the palette? Seems so. Mark it as dirty */
1107  _cur_palette.first_dirty = PALETTE_ANIM_START;
1108  _cur_palette.count_dirty = PALETTE_ANIM_SIZE;
1109  }
1110  }
1111 }
1112 
1119 TextColour GetContrastColour(uint8 background, uint8 threshold)
1120 {
1121  Colour c = _cur_palette.palette[background];
1122  /* Compute brightness according to http://www.w3.org/TR/AERT#color-contrast.
1123  * The following formula computes 1000 * brightness^2, with brightness being in range 0 to 255. */
1124  uint sq1000_brightness = c.r * c.r * 299 + c.g * c.g * 587 + c.b * c.b * 114;
1125  /* Compare with threshold brightness which defaults to 128 (50%) */
1126  return sq1000_brightness < ((uint) threshold) * ((uint) threshold) * 1000 ? TC_WHITE : TC_BLACK;
1127 }
1128 
1133 void LoadStringWidthTable(bool monospace)
1134 {
1135  ClearFontCache();
1136 
1137  for (FontSize fs = monospace ? FS_MONO : FS_BEGIN; fs < (monospace ? FS_END : FS_MONO); fs++) {
1138  for (uint i = 0; i != 224; i++) {
1139  _stringwidth_table[fs][i] = GetGlyphWidth(fs, i + 32);
1140  }
1141  }
1142 
1143  ReInitAllWindows();
1144 }
1145 
1153 {
1154  /* Use _stringwidth_table cache if possible */
1155  if (key >= 32 && key < 256) return _stringwidth_table[size][key - 32];
1156 
1157  return GetGlyphWidth(size, key);
1158 }
1159 
1166 {
1167  byte width = 0;
1168  for (char c = '0'; c <= '9'; c++) {
1169  width = max(GetCharacterWidth(size, c), width);
1170  }
1171  return width;
1172 }
1173 
1180 void GetBroadestDigit(uint *front, uint *next, FontSize size)
1181 {
1182  int width = -1;
1183  for (char c = '9'; c >= '0'; c--) {
1184  int w = GetCharacterWidth(size, c);
1185  if (w > width) {
1186  width = w;
1187  *next = c - '0';
1188  if (c != '0') *front = c - '0';
1189  }
1190  }
1191 }
1192 
1193 void ScreenSizeChanged()
1194 {
1195  _dirty_bytes_per_line = CeilDiv(_screen.width, DIRTY_BLOCK_WIDTH);
1196  _dirty_blocks = ReallocT<byte>(_dirty_blocks, _dirty_bytes_per_line * CeilDiv(_screen.height, DIRTY_BLOCK_HEIGHT));
1197 
1198  /* check the dirty rect */
1199  if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width;
1200  if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height;
1201 
1202  /* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */
1203  _cursor.visible = false;
1204 }
1205 
1206 void UndrawMouseCursor()
1207 {
1208  /* Don't undraw the mouse cursor if the screen is not ready */
1209  if (_screen.dst_ptr == nullptr) return;
1210 
1211  if (_cursor.visible) {
1213  _cursor.visible = false;
1214  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);
1215  VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
1216  }
1217 }
1218 
1219 void DrawMouseCursor()
1220 {
1221  /* Don't draw the mouse cursor if the screen is not ready */
1222  if (_screen.dst_ptr == nullptr) return;
1223 
1225 
1226  /* Redraw mouse cursor but only when it's inside the window */
1227  if (!_cursor.in_window) return;
1228 
1229  /* Don't draw the mouse cursor if it's already drawn */
1230  if (_cursor.visible) {
1231  if (!_cursor.dirty) return;
1232  UndrawMouseCursor();
1233  }
1234 
1235  /* Determine visible area */
1236  int left = _cursor.pos.x + _cursor.total_offs.x;
1237  int width = _cursor.total_size.x;
1238  if (left < 0) {
1239  width += left;
1240  left = 0;
1241  }
1242  if (left + width > _screen.width) {
1243  width = _screen.width - left;
1244  }
1245  if (width <= 0) return;
1246 
1247  int top = _cursor.pos.y + _cursor.total_offs.y;
1248  int height = _cursor.total_size.y;
1249  if (top < 0) {
1250  height += top;
1251  top = 0;
1252  }
1253  if (top + height > _screen.height) {
1254  height = _screen.height - top;
1255  }
1256  if (height <= 0) return;
1257 
1258  _cursor.draw_pos.x = left;
1259  _cursor.draw_pos.y = top;
1260  _cursor.draw_size.x = width;
1261  _cursor.draw_size.y = height;
1262 
1263  uint8 *buffer = _cursor_backup.Allocate(blitter->BufferSize(_cursor.draw_size.x, _cursor.draw_size.y));
1264 
1265  /* Make backup of stuff below cursor */
1266  blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), buffer, _cursor.draw_size.x, _cursor.draw_size.y);
1267 
1268  /* Draw cursor on screen */
1269  _cur_dpi = &_screen;
1270  for (uint i = 0; i < _cursor.sprite_count; ++i) {
1271  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);
1272  }
1273 
1274  VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
1275 
1276  _cursor.visible = true;
1277  _cursor.dirty = false;
1278 }
1279 
1280 void RedrawScreenRect(int left, int top, int right, int bottom)
1281 {
1282  assert(right <= _screen.width && bottom <= _screen.height);
1283  if (_cursor.visible) {
1284  if (right > _cursor.draw_pos.x &&
1285  left < _cursor.draw_pos.x + _cursor.draw_size.x &&
1286  bottom > _cursor.draw_pos.y &&
1287  top < _cursor.draw_pos.y + _cursor.draw_size.y) {
1288  UndrawMouseCursor();
1289  }
1290  }
1291 
1293 
1294  DrawOverlappedWindowForAll(left, top, right, bottom);
1295 
1296  VideoDriver::GetInstance()->MakeDirty(left, top, right - left, bottom - top);
1297 }
1298 
1305 {
1306  byte *b = _dirty_blocks;
1307  const int w = Align(_screen.width, DIRTY_BLOCK_WIDTH);
1308  const int h = Align(_screen.height, DIRTY_BLOCK_HEIGHT);
1309  int x;
1310  int y;
1311 
1312  if (HasModalProgress()) {
1313  /* We are generating the world, so release our rights to the map and
1314  * painting while we are waiting a bit. */
1315  _modal_progress_paint_mutex.unlock();
1316  _modal_progress_work_mutex.unlock();
1317 
1318  /* Wait a while and update _realtime_tick so we are given the rights */
1321 
1322  /* Modal progress thread may need blitter access while we are waiting for it. */
1327 
1328  /* When we ended with the modal progress, do not draw the blocks.
1329  * Simply let the next run do so, otherwise we would be loading
1330  * the new state (and possibly change the blitter) when we hold
1331  * the drawing lock, which we must not do. */
1332  if (_switch_mode != SM_NONE && !HasModalProgress()) return;
1333  }
1334 
1335  y = 0;
1336  do {
1337  x = 0;
1338  do {
1339  if (*b != 0) {
1340  int left;
1341  int top;
1342  int right = x + DIRTY_BLOCK_WIDTH;
1343  int bottom = y;
1344  byte *p = b;
1345  int h2;
1346 
1347  /* First try coalescing downwards */
1348  do {
1349  *p = 0;
1350  p += _dirty_bytes_per_line;
1351  bottom += DIRTY_BLOCK_HEIGHT;
1352  } while (bottom != h && *p != 0);
1353 
1354  /* Try coalescing to the right too. */
1355  h2 = (bottom - y) / DIRTY_BLOCK_HEIGHT;
1356  assert(h2 > 0);
1357  p = b;
1358 
1359  while (right != w) {
1360  byte *p2 = ++p;
1361  int h = h2;
1362  /* Check if a full line of dirty flags is set. */
1363  do {
1364  if (!*p2) goto no_more_coalesc;
1365  p2 += _dirty_bytes_per_line;
1366  } while (--h != 0);
1367 
1368  /* Wohoo, can combine it one step to the right!
1369  * Do that, and clear the bits. */
1370  right += DIRTY_BLOCK_WIDTH;
1371 
1372  h = h2;
1373  p2 = p;
1374  do {
1375  *p2 = 0;
1376  p2 += _dirty_bytes_per_line;
1377  } while (--h != 0);
1378  }
1379  no_more_coalesc:
1380 
1381  left = x;
1382  top = y;
1383 
1384  if (left < _invalid_rect.left ) left = _invalid_rect.left;
1385  if (top < _invalid_rect.top ) top = _invalid_rect.top;
1386  if (right > _invalid_rect.right ) right = _invalid_rect.right;
1387  if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom;
1388 
1389  if (left < right && top < bottom) {
1390  RedrawScreenRect(left, top, right, bottom);
1391  }
1392 
1393  }
1394  } while (b++, (x += DIRTY_BLOCK_WIDTH) != w);
1395  } while (b += -(int)(w / DIRTY_BLOCK_WIDTH) + _dirty_bytes_per_line, (y += DIRTY_BLOCK_HEIGHT) != h);
1396 
1397  ++_dirty_block_colour;
1398  _invalid_rect.left = w;
1399  _invalid_rect.top = h;
1400  _invalid_rect.right = 0;
1401  _invalid_rect.bottom = 0;
1402 }
1403 
1419 void SetDirtyBlocks(int left, int top, int right, int bottom)
1420 {
1421  byte *b;
1422  int width;
1423  int height;
1424 
1425  if (left < 0) left = 0;
1426  if (top < 0) top = 0;
1427  if (right > _screen.width) right = _screen.width;
1428  if (bottom > _screen.height) bottom = _screen.height;
1429 
1430  if (left >= right || top >= bottom) return;
1431 
1432  if (left < _invalid_rect.left ) _invalid_rect.left = left;
1433  if (top < _invalid_rect.top ) _invalid_rect.top = top;
1434  if (right > _invalid_rect.right ) _invalid_rect.right = right;
1435  if (bottom > _invalid_rect.bottom) _invalid_rect.bottom = bottom;
1436 
1437  left /= DIRTY_BLOCK_WIDTH;
1438  top /= DIRTY_BLOCK_HEIGHT;
1439 
1440  b = _dirty_blocks + top * _dirty_bytes_per_line + left;
1441 
1442  width = ((right - 1) / DIRTY_BLOCK_WIDTH) - left + 1;
1443  height = ((bottom - 1) / DIRTY_BLOCK_HEIGHT) - top + 1;
1444 
1445  assert(width > 0 && height > 0);
1446 
1447  do {
1448  int i = width;
1449 
1450  do b[--i] = 0xFF; while (i != 0);
1451 
1452  b += _dirty_bytes_per_line;
1453  } while (--height != 0);
1454 }
1455 
1463 {
1464  SetDirtyBlocks(0, 0, _screen.width, _screen.height);
1465 }
1466 
1481 bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
1482 {
1484  const DrawPixelInfo *o = _cur_dpi;
1485 
1486  n->zoom = ZOOM_LVL_NORMAL;
1487 
1488  assert(width > 0);
1489  assert(height > 0);
1490 
1491  if ((left -= o->left) < 0) {
1492  width += left;
1493  if (width <= 0) return false;
1494  n->left = -left;
1495  left = 0;
1496  } else {
1497  n->left = 0;
1498  }
1499 
1500  if (width > o->width - left) {
1501  width = o->width - left;
1502  if (width <= 0) return false;
1503  }
1504  n->width = width;
1505 
1506  if ((top -= o->top) < 0) {
1507  height += top;
1508  if (height <= 0) return false;
1509  n->top = -top;
1510  top = 0;
1511  } else {
1512  n->top = 0;
1513  }
1514 
1515  n->dst_ptr = blitter->MoveTo(o->dst_ptr, left, top);
1516  n->pitch = o->pitch;
1517 
1518  if (height > o->height - top) {
1519  height = o->height - top;
1520  if (height <= 0) return false;
1521  }
1522  n->height = height;
1523 
1524  return true;
1525 }
1526 
1532 {
1533  /* Ignore setting any cursor before the sprites are loaded. */
1534  if (GetMaxSpriteID() == 0) return;
1535 
1536  assert_compile(lengthof(_cursor.sprite_seq) == lengthof(_cursor.sprite_pos));
1537  assert(_cursor.sprite_count <= lengthof(_cursor.sprite_seq));
1538  for (uint i = 0; i < _cursor.sprite_count; ++i) {
1539  const Sprite *p = GetSprite(GB(_cursor.sprite_seq[i].sprite, 0, SPRITE_WIDTH), ST_NORMAL);
1540  Point offs, size;
1541  offs.x = UnScaleGUI(p->x_offs) + _cursor.sprite_pos[i].x;
1542  offs.y = UnScaleGUI(p->y_offs) + _cursor.sprite_pos[i].y;
1543  size.x = UnScaleGUI(p->width);
1544  size.y = UnScaleGUI(p->height);
1545 
1546  if (i == 0) {
1547  _cursor.total_offs = offs;
1548  _cursor.total_size = size;
1549  } else {
1550  int right = max(_cursor.total_offs.x + _cursor.total_size.x, offs.x + size.x);
1551  int bottom = max(_cursor.total_offs.y + _cursor.total_size.y, offs.y + size.y);
1552  if (offs.x < _cursor.total_offs.x) _cursor.total_offs.x = offs.x;
1553  if (offs.y < _cursor.total_offs.y) _cursor.total_offs.y = offs.y;
1554  _cursor.total_size.x = right - _cursor.total_offs.x;
1555  _cursor.total_size.y = bottom - _cursor.total_offs.y;
1556  }
1557  }
1558 
1559  _cursor.dirty = true;
1560 }
1561 
1567 static void SetCursorSprite(CursorID cursor, PaletteID pal)
1568 {
1569  if (_cursor.sprite_count == 1 && _cursor.sprite_seq[0].sprite == cursor && _cursor.sprite_seq[0].pal == pal) return;
1570 
1571  _cursor.sprite_count = 1;
1572  _cursor.sprite_seq[0].sprite = cursor;
1573  _cursor.sprite_seq[0].pal = pal;
1574  _cursor.sprite_pos[0].x = 0;
1575  _cursor.sprite_pos[0].y = 0;
1576 
1577  UpdateCursorSize();
1578 }
1579 
1580 static void SwitchAnimatedCursor()
1581 {
1582  const AnimCursor *cur = _cursor.animate_cur;
1583 
1584  if (cur == nullptr || cur->sprite == AnimCursor::LAST) cur = _cursor.animate_list;
1585 
1586  SetCursorSprite(cur->sprite, _cursor.sprite_seq[0].pal);
1587 
1588  _cursor.animate_timeout = cur->display_time;
1589  _cursor.animate_cur = cur + 1;
1590 }
1591 
1592 void CursorTick()
1593 {
1594  if (_cursor.animate_timeout != 0 && --_cursor.animate_timeout == 0) {
1595  SwitchAnimatedCursor();
1596  }
1597 }
1598 
1603 void SetMouseCursorBusy(bool busy)
1604 {
1605  if (busy) {
1606  if (_cursor.sprite_seq[0].sprite == SPR_CURSOR_MOUSE) SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
1607  } else {
1608  if (_cursor.sprite_seq[0].sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
1609  }
1610 }
1611 
1619 {
1620  /* Turn off animation */
1621  _cursor.animate_timeout = 0;
1622  /* Set cursor */
1623  SetCursorSprite(sprite, pal);
1624 }
1625 
1632 {
1633  _cursor.animate_list = table;
1634  _cursor.animate_cur = nullptr;
1635  _cursor.sprite_seq[0].pal = PAL_NONE;
1636  SwitchAnimatedCursor();
1637 }
1638 
1647 bool CursorVars::UpdateCursorPosition(int x, int y, bool queued_warp)
1648 {
1649  /* Detecting relative mouse movement is somewhat tricky.
1650  * - There may be multiple mouse move events in the video driver queue (esp. when OpenTTD lags a bit).
1651  * - When we request warping the mouse position (return true), a mouse move event is appended at the end of the queue.
1652  *
1653  * So, when this->fix_at is active, we use the following strategy:
1654  * - The first movement triggers the warp to reset the mouse position.
1655  * - Subsequent events have to compute movement relative to the previous event.
1656  * - The relative movement is finished, when we receive the event matching the warp.
1657  */
1658 
1659  if (x == this->pos.x && y == this->pos.y) {
1660  /* Warp finished. */
1661  this->queued_warp = false;
1662  }
1663 
1664  this->delta.x = x - (this->queued_warp ? this->last_position.x : this->pos.x);
1665  this->delta.y = y - (this->queued_warp ? this->last_position.y : this->pos.y);
1666 
1667  this->last_position.x = x;
1668  this->last_position.y = y;
1669 
1670  bool need_warp = false;
1671  if (this->fix_at) {
1672  if (this->delta.x != 0 || this->delta.y != 0) {
1673  /* Trigger warp.
1674  * Note: We also trigger warping again, if there is already a pending warp.
1675  * This makes it more tolerant about the OS or other software in between
1676  * botchering the warp. */
1677  this->queued_warp = queued_warp;
1678  need_warp = true;
1679  }
1680  } else if (this->pos.x != x || this->pos.y != y) {
1681  this->queued_warp = false; // Cancel warping, we are no longer confining the position.
1682  this->dirty = true;
1683  this->pos.x = x;
1684  this->pos.y = y;
1685  }
1686  return need_warp;
1687 }
1688 
1689 bool ChangeResInGame(int width, int height)
1690 {
1691  return (_screen.width == width && _screen.height == height) || VideoDriver::GetInstance()->ChangeResolution(width, height);
1692 }
1693 
1694 bool ToggleFullScreen(bool fs)
1695 {
1696  bool result = VideoDriver::GetInstance()->ToggleFullscreen(fs);
1697  if (_fullscreen != fs && _resolutions.empty()) {
1698  DEBUG(driver, 0, "Could not find a suitable fullscreen resolution");
1699  }
1700  return result;
1701 }
1702 
1703 void SortResolutions()
1704 {
1705  std::sort(_resolutions.begin(), _resolutions.end());
1706 }
virtual void MakeDirty(int left, int top, int width, int height)=0
Mark a particular area dirty.
Functions related to OTTD&#39;s strings.
int left
The left offset in the &#39;dst&#39; in pixels to start drawing.
Definition: base.hpp:41
Functions/types related to NewGRF debugging.
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:79
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:341
bool _networking
are we in networking mode?
Definition: network.cpp:52
Base of all video drivers.
bool dirty
the rect occupied by the mouse is dirty (redraw)
Definition: gfx_type.h:140
Data about how and where to blit pixels.
Definition: gfx_type.h:154
static const uint8 PC_WHITE
White palette colour.
Definition: gfx_func.h:206
Horizontally center the text.
Definition: gfx_func.h:95
uint32 _realtime_tick
The real time in the game.
Definition: debug.cpp:48
Control codes that are embedded in the translation strings.
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:110
Point pos
logical mouse position
Definition: gfx_type.h:117
byte landscape
the landscape we&#39;re currently in
static void SetColourRemap(TextColour colour)
Set the colour remap to be for the given colour.
Definition: gfx.cpp:311
int sprite_width
Real width of the sprite.
Definition: base.hpp:39
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:66
Information about the currently used palette.
Definition: gfx_type.h:308
void SetMouseCursorBusy(bool busy)
Set or unset the ZZZ cursor.
Definition: gfx.cpp:1603
virtual void ReleaseBlitterLock()
Release any lock(s) required to be held when changing blitters.
static const PaletteID PALETTE_ALL_BLACK
Exchange any color by black, needed for painting fictive tiles outside map.
Definition: sprites.h:1593
int height
The height in pixels that needs to be drawn to dst.
Definition: base.hpp:38
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:71
bool _right_button_down
Is right mouse button pressed?
Definition: gfx.cpp:40
Point sprite_pos[16]
relative position of individual sprites
Definition: gfx_type.h:129
Perform transparency colour remapping.
Definition: base.hpp:20
static int UnScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
Definition: zoom_func.h:56
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition: gfx_type.h:309
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst)
Definition: base.hpp:36
Colour fizzy_drink[EPV_CYCLES_FIZZY_DRINK]
fizzy drinks
Definition: palettes.h:109
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:52
std::vector< SpriteID > sprites
Sprites found.
Definition: newgrf_debug.h:30
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
StringAlignment
How to align the to-be drawn text.
Definition: gfx_func.h:93
uint sprite_count
number of sprites to draw
Definition: gfx_type.h:130
#define FONT_HEIGHT_MONO
Height of characters in the large (FS_MONO) font.
Definition: gfx_func.h:182
Index of the monospaced font in the font tables.
Definition: gfx_type.h:205
Data structure describing a sprite.
Definition: spritecache.h:16
Mask for horizontal alignment.
Definition: gfx_func.h:97
int sprite_height
Real height of the sprite.
Definition: base.hpp:40
static const ExtraPaletteValues _extra_palette_values
Actual palette animation tables.
Definition: palettes.h:115
int width
The width in pixels that needs to be drawn to dst.
Definition: base.hpp:37
virtual void SetPixel(void *video, int x, int y, uint8 colour)=0
Draw a pixel with a given colour on the video-buffer.
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:229
const AnimCursor * animate_list
in case of animated cursor, list of frames
Definition: gfx_type.h:135
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
byte GetCharacterWidth(FontSize size, WChar key)
Return width of character glyph.
Definition: gfx.cpp:1152
virtual bool ToggleFullscreen(bool fullscreen)=0
Change the full screen setting.
void * clicked_pixel
Clicked pixel (pointer to blitter buffer)
Definition: newgrf_debug.h:28
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:547
void CSleep(int milliseconds)
Sleep on the current thread for a defined time.
Definition: thread.h:25
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
Definition: gfx_func.h:83
const char * GetCharAtPosition(int x) const
Get the character that is at a position.
Definition: gfx_layout.cpp:807
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:48
No palette animation.
Definition: base.hpp:50
int skip_left
How much pixels of the source to skip on the left (based on zoom of dst)
Definition: base.hpp:35
Visual run contains data about the bit of text with the same font.
Definition: gfx_layout.h:120
byte GetDigitWidth(FontSize size)
Return the maximum width of single digit.
Definition: gfx.cpp:1165
How all blitters should look like.
Definition: base.hpp:28
static const uint MODAL_PROGRESS_REDRAW_TIMEOUT
Timeout between redraws.
Definition: progress.h:15
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:24
Functions related to laying out the texts.
static const uint EPV_CYCLES_OIL_REFINERY
length of the oil refinery&#39;s fire animation
Definition: palettes.h:99
bool visible
cursor is visible
Definition: gfx_type.h:139
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
static uint GetGlyphWidth(FontSize size, WChar key)
Get the width of a glyph.
Definition: fontcache.h:201
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
Definition: math_func.hpp:336
FillRectMode
Define the operation GfxFillRect performs.
Definition: gfx_type.h:281
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:1481
Point total_size
union of sprite properties
Definition: gfx_type.h:131
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:39
Colour dark_water[EPV_CYCLES_DARK_WATER]
dark blue water
Definition: palettes.h:105
std::vector< Dimension > _resolutions
List of resolutions.
Definition: driver.cpp:20
Force the alignment, i.e. don&#39;t swap for RTL languages.
Definition: gfx_func.h:106
std::mutex _modal_progress_work_mutex
Rights for the performing work.
Definition: progress.cpp:21
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
Point draw_size
position and size bounding-box for drawing
Definition: gfx_type.h:133
Colour lighthouse[EPV_CYCLES_LIGHTHOUSE]
lighthouse & stadium
Definition: palettes.h:107
The colour translation of the GRF palettes.
CursorID sprite
Must be set to LAST_ANIM when it is the last sprite of the loop.
Definition: gfx_type.h:110
Collection of variables for cursor-display and -animation.
Definition: gfx_type.h:115
virtual bool ChangeResolution(int w, int h)=0
Change the resolution of the window.
bool IsFirstModalProgressLoop()
Check whether this is the first modal progress loop.
Definition: progress.cpp:41
Colour glitter_water[EPV_CYCLES_GLITTER_WATER]
glittery water
Definition: palettes.h:110
int16 y_offs
Number of pixels to shift the sprite downwards.
Definition: spritecache.h:20
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:173
A single line worth of VisualRuns.
Definition: gfx_layout.h:132
bool _right_button_clicked
Is right mouse button clicked?
Definition: gfx.cpp:41
static Rect _invalid_rect
The rect for repaint.
Definition: gfx.cpp:69
Base of all threads.
static T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
Definition: math_func.hpp:95
First font.
Definition: gfx_type.h:208
GameMode
Mode which defines the state of the game.
Definition: openttd.h:16
const T * GetBuffer() const
Get the currently allocated buffer.
Definition: alloc_type.hpp:75
Parameters related to blitting.
Definition: base.hpp:31
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
Draw a sprite in a viewport.
Definition: gfx.cpp:808
bool _left_button_down
Is left mouse button pressed?
Definition: gfx.cpp:38
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:176
virtual uint GetGlyphWidth(GlyphID key)=0
Get the width of the glyph with the given key.
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:284
Types related to global configuration settings.
Functions related to modal progress.
Definition of base types and functions in a cross-platform compatible way.
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
Definition: gfx.cpp:1133
Description of tables for the palette animation.
Definition: palettes.h:104
Bottom align the text.
Definition: gfx_func.h:101
Top align the text.
Definition: gfx_func.h:99
A number of safeguards to prevent using unsafe methods.
int pitch
The pitch of the destination buffer.
Definition: base.hpp:45
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:245
bool UpdateCursorPosition(int x, int y, bool queued_warp)
Update cursor position on mouse movement.
Definition: gfx.cpp:1647
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:314
virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)=0
Draw an image to the screen, given an amount of params defined above.
T * Allocate(size_t count)
Get buffer of at least count times T.
Definition: alloc_type.hpp:42
number of animated colours
Definition: gfx_type.h:276
byte _dirkeys
1 = left, 2 = up, 4 = right, 8 = down
Definition: gfx.cpp:31
Perform a crash remapping.
Definition: base.hpp:21
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
Definition: gfx_type.h:120
void DrawCharCentered(WChar c, int x, int y, TextColour colour)
Draw single character horizontally centered around (x,y)
Definition: gfx.cpp:757
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.
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot) ...
Definition: gfx.cpp:43
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:728
static const uint EPV_CYCLES_FIZZY_DRINK
length of the fizzy drinks animation
Definition: palettes.h:100
byte data[]
Sprite data.
Definition: spritecache.h:21
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
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:498
Basic functions/variables used all over the place.
static const Palette _palette
Colour palette (DOS)
Definition: palettes.h:15
A single sprite of a list of animated cursors.
Definition: gfx_type.h:108
byte display_time
Amount of ticks this sprite will be shown.
Definition: gfx_type.h:111
Mask for vertical alignment.
Definition: gfx_func.h:102
void SetDirtyBlocks(int left, int top, int right, int bottom)
This function extends the internal _invalid_rect rectangle as it now contains the rectangle defined b...
Definition: gfx.cpp:1419
#define FONT_HEIGHT_LARGE
Height of characters in the large (FS_LARGE) font.
Definition: gfx_func.h:179
virtual void AcquireBlitterLock()
Acquire any lock(s) required to be held when changing blitters.
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
void DrawDirtyBlocks()
Repaints the rectangle blocks which are marked as &#39;dirty&#39;.
Definition: gfx.cpp:1304
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:145
number of bits for the sprite number
Definition: sprites.h:1512
int first_dirty
The first dirty element.
Definition: gfx_type.h:310
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:47
Perform remapping to a completely blackened sprite.
Definition: base.hpp:22
static const Sprite * GetGlyph(FontSize size, WChar key)
Get the Sprite for a glyph.
Definition: fontcache.h:194
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
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:959
virtual void CopyToBuffer(const void *video, void *dst, int width, int height)=0
Copy from the screen to a buffer.
virtual GlyphID MapCharToGlyph(WChar key)=0
Map a character into a glyph.
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:276
PauseMode
Modes of pausing we&#39;ve got.
Definition: openttd.h:55
Font cache for basic fonts.
Definition: fontcache.h:21
Palette _cur_palette
Current palette.
Definition: gfx.cpp:48
uint16 height
Height of the sprite.
Definition: spritecache.h:17
The most basic (normal) sprite.
Definition: gfx_type.h:297
Dimension GetBounds()
Get the boundaries of this paragraph.
Definition: gfx_layout.cpp:744
bool _shift_pressed
Is Shift pressed?
Definition: gfx.cpp:36
void NetworkUndrawChatMessage()
Hide the chatbox.
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
virtual Blitter::PaletteAnimation UsePaletteAnimation()=0
Check if the blitter uses palette animation at all.
void SetMouseCursor(CursorID sprite, PaletteID pal)
Assign a single non-animated sprite to the cursor.
Definition: gfx.cpp:1618
static const uint EPV_CYCLES_DARK_WATER
Description of the length of the palette cycle animations.
Definition: palettes.h:97
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition: gfx.cpp:587
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:283
PalSpriteID sprite_seq[16]
current image of cursor
Definition: gfx_type.h:128
uint GetMaxSpriteID()
Get a reasonable (upper bound) estimate of the maximum SpriteID used in OpenTTD; there will be no spr...
virtual int BufferSize(int width, int height)=0
Calculate how much memory there is needed for an image of this size in the video-buffer.
void SetAnimatedMouseCursor(const AnimCursor *table)
Assign an animation to the cursor.
Definition: gfx.cpp:1631
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.
uint16 width
Width of the sprite.
Definition: spritecache.h:18
static void GfxBlitter(const Sprite *const sprite, int x, int y, BlitterMode mode, const SubSprite *const sub, SpriteID sprite_id, ZoomLevel zoom)
The code for setting up the blitter mode and sprite information before finally drawing the sprite...
Definition: gfx.cpp:865
int top
The top offset in the &#39;dst&#39; in pixels to start drawing.
Definition: base.hpp:42
void ReInitAllWindows()
Re-initialize all windows.
Definition: window.cpp:3451
Recolour sprite.
Definition: gfx_type.h:300
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
void UpdateCursorSize()
Update cursor dimension.
Definition: gfx.cpp:1531
int GetStringLineCount(StringID str, int maxw)
Calculates number of lines of string.
Definition: gfx.cpp:572
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:171
TextColour GetContrastColour(uint8 background, uint8 threshold)
Determine a contrasty text colour for a coloured background.
Definition: gfx.cpp:1119
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1587
uint animate_timeout
in case of animated cursor, number of ticks to show the current cursor
Definition: gfx_type.h:137
static const byte _string_colourmap[17]
Colour mapping for TextColour.
const byte * remap
XXX – Temporary storage for remap array.
Definition: base.hpp:33
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...
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
virtual void CopyFromBuffer(void *video, const void *src, int width, int height)=0
Copy from a buffer to the screen.
Ignore colour changes from strings.
Definition: gfx_type.h:270
const void * sprite
Pointer to the sprite how ever the encoder stored it.
Definition: base.hpp:32
static void SetCursorSprite(CursorID cursor, PaletteID pal)
Switch cursor to different sprite.
Definition: gfx.cpp:1567
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:1180
when a sprite is to be displayed transparently, this bit needs to be set.
Definition: sprites.h:1526
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:81
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Do not add shading to this text colour.
Definition: gfx_type.h:269
virtual const Sprite * GetGlyph(GlyphID key)=0
Get the glyph (sprite) of the given key.
Functions related to zooming.
FontSize
Available font sizes.
Definition: gfx_type.h:201
Perform a colour remapping.
Definition: base.hpp:19
ZoomLevel _font_zoom
Font Zoom level.
Definition: gfx.cpp:60
Set if palette is actually a magic text recolour.
Definition: sprites.h:1509
Index of the normal font in the font tables.
Definition: gfx_type.h:202
bool in_window
mouse inside this window, determines drawing logic
Definition: gfx_type.h:141
ZoomLevel _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:59
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:46
int16 x_offs
Number of pixels to shift the sprite to the right.
Definition: spritecache.h:19
Used to only draw a part of the sprite.
Definition: gfx_type.h:217
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...
The normal zoom level.
Definition: zoom_type.h:22
void * dst
Destination buffer.
Definition: base.hpp:44
virtual bool GetDrawGlyphShadow()=0
Do we need to draw a glyph shadow?
Network functions used by other parts of OpenTTD.
uint32 CursorID
The number of the cursor (sprite)
Definition: gfx_type.h:19
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:770
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:162
Perform the simple blitting.
Definition: base.hpp:18
The colour translation of GRF&#39;s strings.
virtual uint8 GetScreenDepth()=0
Get the screen depth this blitter works for.
Colour value is already a real palette colour index, not an index of a StringColour.
Definition: gfx_type.h:268
BlitterMode
The modes of blitting we can do.
Definition: base.hpp:17
number of bits of the sprite containing the recolour palette
Definition: sprites.h:1511
Colour dark_water_toyland[EPV_CYCLES_DARK_WATER]
dark blue water Toyland
Definition: palettes.h:106
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
virtual void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)=0
Draw a colourtable to the screen.
std::mutex _modal_progress_paint_mutex
Rights for the painting.
Definition: progress.cpp:23
The layouter performs all the layout work.
Definition: gfx_layout.h:151
GameCreationSettings game_creation
settings used during the creation of a game (map)
virtual void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)=0
Scroll the videobuffer some &#39;x&#39; and &#39;y&#39; value.
Specification of a rectangle with absolute coordinates of all edges.
Text is written right-to-left by default.
Definition: strings_type.h:24
Right align the text (must be a single bit).
Definition: gfx_func.h:96
Left align the text.
Definition: gfx_func.h:94
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:741
Window functions not directly related to making/drawing windows.
Point delta
relative mouse movement in this tick
Definition: gfx_type.h:118
const AnimCursor * animate_cur
in case of animated cursor, current frame
Definition: gfx_type.h:136
uint32 GlyphID
Glyphs are characters from a font.
Definition: fontcache.h:17
Vertically center the text.
Definition: gfx_func.h:100
static byte _stringwidth_table[FS_END][224]
Cache containing width of often used characters.
Definition: gfx.cpp:50
SpriteID sprite
The &#39;real&#39; sprite.
Definition: gfx_type.h:23
int count_dirty
The number of dirty elements.
Definition: gfx_type.h:311
Colour oil_refinery[EPV_CYCLES_OIL_REFINERY]
oil refinery
Definition: palettes.h:108
static const uint EPV_CYCLES_LIGHTHOUSE
length of the lighthouse/stadium animation
Definition: palettes.h:98
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1367
Index in the _palettes array from which all animations are taking places (table/palettes.h)
Definition: gfx_type.h:277
uint32 WChar
Type for wide characters, i.e.
Definition: string_type.h:35
static BlitterMode GetBlitterMode(PaletteID pal)
Helper function to get the blitter mode for different types of palettes.
Definition: gfx.cpp:790
Dimensions (a width and height) of a rectangle in 2D.
This file contains all sprite-related enums and defines.
NewGrfDebugSpritePickerMode mode
Current state.
Definition: newgrf_debug.h:27
Factory to &#39;query&#39; all available blitters.
Point GetCharPosition(const char *ch) const
Get the position of a character in the layout.
Definition: gfx_layout.cpp:760
static const uint EPV_CYCLES_GLITTER_WATER
length of the glittery water animation
Definition: palettes.h:101
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:835
SwitchMode
Mode which defines what mode we&#39;re switching to.
Definition: openttd.h:24
Colour glitter_water_toyland[EPV_CYCLES_GLITTER_WATER]
glittery water Toyland
Definition: palettes.h:111
static bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:21
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1462
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:621
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24