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