The Battle for Wesnoth  1.17.4+dev
video.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2022
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #include "video.hpp"
17 
18 #include "display.hpp"
19 #include "floating_label.hpp"
20 #include "font/sdl_ttf_compat.hpp"
21 #include "picture.hpp"
22 #include "log.hpp"
23 #include "preferences/general.hpp"
24 #include "sdl/point.hpp"
25 #include "sdl/userevent.hpp"
26 #include "sdl/utils.hpp"
27 #include "sdl/window.hpp"
28 #include "sdl/input.hpp"
29 
30 #ifdef TARGET_OS_OSX
31 #include "desktop/apple_video.hpp"
32 #include "game_version.hpp"
33 #endif
34 
35 #include <SDL2/SDL_render.h> // SDL_Texture
36 
37 #include <cassert>
38 #include <vector>
39 
40 static lg::log_domain log_display("display");
41 #define LOG_DP LOG_STREAM(info, log_display)
42 #define ERR_DP LOG_STREAM(err, log_display)
43 
44 CVideo* CVideo::singleton_ = nullptr;
45 
46 namespace
47 {
48 surface drawingSurface = nullptr;
49 bool fake_interactive = false;
50 
51 const unsigned MAGIC_DPI_SCALE_NUMBER = 96;
52 }
53 
54 namespace video2
55 {
56 std::list<events::sdl_handler*> draw_layers;
57 
58 draw_layering::draw_layering(const bool auto_join)
59  : sdl_handler(auto_join)
60 {
61  draw_layers.push_back(this);
62 }
63 
65 {
66  draw_layers.remove(this);
67 
69 }
70 
72 {
73  SDL_Event event;
74  event.type = SDL_WINDOWEVENT;
75  event.window.event = SDL_WINDOWEVENT_RESIZED;
76  event.window.data1 = (*drawingSurface).h;
77  event.window.data2 = (*drawingSurface).w;
78 
79  for(const auto& layer : draw_layers) {
80  layer->handle_window_event(event);
81  }
82 
83  SDL_Event drawEvent;
85 
86  drawEvent.type = DRAW_ALL_EVENT;
87  drawEvent.user = data;
88  SDL_FlushEvent(DRAW_ALL_EVENT);
89  SDL_PushEvent(&drawEvent);
90 }
91 
92 } // video2
93 
95  : window()
96  , drawing_texture_(nullptr)
97  , fake_screen_(false)
98  , help_string_(0)
99  , updated_locked_(0)
100  , flip_locked_(0)
101  , refresh_rate_(0)
102 {
103  assert(!singleton_);
104  singleton_ = this;
105 
106  initSDL();
107 
108  switch(type) {
109  case NO_FAKE:
110  break;
111  case FAKE:
112  make_fake();
113  break;
114  case FAKE_TEST:
115  make_test_fake();
116  break;
117  }
118 }
119 
121 {
122  const int res = SDL_InitSubSystem(SDL_INIT_VIDEO);
123 
124  if(res < 0) {
125  ERR_DP << "Could not initialize SDL_video: " << SDL_GetError() << std::endl;
126  throw CVideo::error();
127  }
128 }
129 
131 {
132  LOG_DP << "calling SDL_Quit()\n";
133  SDL_Quit();
134  assert(singleton_);
135  singleton_ = nullptr;
136  LOG_DP << "called SDL_Quit()\n";
137 }
138 
140 {
141  return fake_interactive ? false : (window == nullptr);
142 }
143 
145 {
146  if(event.type == SDL_WINDOWEVENT) {
147  switch(event.window.event) {
148  case SDL_WINDOWEVENT_RESIZED:
149  case SDL_WINDOWEVENT_RESTORED:
150  case SDL_WINDOWEVENT_SHOWN:
151  case SDL_WINDOWEVENT_EXPOSED:
152  // if(display::get_singleton())
153  // display::get_singleton()->redraw_everything();
154  SDL_Event drawEvent;
156 
157  drawEvent.type = DRAW_ALL_EVENT;
158  drawEvent.user = data;
159 
160  SDL_FlushEvent(DRAW_ALL_EVENT);
161  SDL_PushEvent(&drawEvent);
162  break;
163  }
164  }
165 }
166 
167 void CVideo::blit_surface(int x, int y, surface surf, SDL_Rect* srcrect, SDL_Rect* clip_rect)
168 {
169  surface& target(getDrawingSurface());
170  SDL_Rect dst{x, y, 0, 0};
171 
172  const clip_rect_setter clip_setter(target, clip_rect, clip_rect != nullptr);
173  sdl_blit(surf, srcrect, target, &dst);
174 }
175 
177 {
178  fake_screen_ = true;
179  refresh_rate_ = 1;
180 
181  drawingSurface = SDL_CreateRGBSurfaceWithFormat(0, 16, 16, 24, SDL_PIXELFORMAT_BGR888);
182 }
183 
184 void CVideo::make_test_fake(const unsigned width, const unsigned height)
185 {
186  drawingSurface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, SDL_PIXELFORMAT_BGR888);
187 
188  fake_interactive = true;
189  refresh_rate_ = 1;
190 }
191 
193 {
194  if(!window) {
195  return;
196  }
197 
198  // Find max valid pixel scale at current window size.
199  point wsize(window->get_size());
200  int max_scale = std::min(
203  max_scale = std::min(max_scale, preferences::max_pixel_scale);
204 
205  // Determine best pixel scale according to preference and window size
206  int scale = 1;
208  // Try to match the default size (1280x720) but do not reduce below
209  int def_scale = std::min(
212  scale = std::min(max_scale, def_scale);
213  // Otherwise reduce to keep below the max window size (1920x1080).
214  int min_scale = std::min(
215  wsize.x / (preferences::max_window_width+1) + 1,
216  wsize.y / (preferences::max_window_height+1) + 1);
217  scale = std::max(scale, min_scale);
218  } else {
219  scale = std::min(max_scale, preferences::pixel_scale());
220  }
221 
222  // Update logical size if it doesn't match the current resolution and scale.
223  point lsize(window->get_logical_size());
224  point osize(window->get_output_size());
225  if (lsize.x != wsize.x / scale || lsize.y != wsize.y / scale) {
227  LOG_DP << "reducing pixel scale from desired "
228  << preferences::pixel_scale() << " to maximum allowable "
229  << scale << std::endl;
230  }
231  LOG_DP << "pixel scale: " << scale << std::endl;
232  LOG_DP << "overriding logical size" << std::endl;
233  LOG_DP << " old lsize: " << lsize << std::endl;
234  LOG_DP << " old wsize: " << wsize << std::endl;
235  LOG_DP << " old osize: " << osize << std::endl;
236  window->set_logical_size(osize.x / scale, osize.y / scale);
237  lsize = window->get_logical_size();
238  wsize = window->get_size();
239  osize = window->get_output_size();
240  LOG_DP << " new lsize: " << lsize << std::endl;
241  LOG_DP << " new wsize: " << wsize << std::endl;
242  LOG_DP << " new osize: " << osize << std::endl;
243  }
244 
245  // Update the drawing surface if required.
246  if (!drawingSurface
247  || drawingSurface->w != wsize.x / scale
248  || drawingSurface->h != wsize.y / scale)
249  {
250  uint32_t format = window->pixel_format();
251  int bpp = SDL_BITSPERPIXEL(format);
252 
253  // This should match the old system, and so shouldn't cause any
254  // problems that weren't there already.
255  LOG_DP << "creating " << bpp << "bpp drawing surface with format "
256  << SDL_GetPixelFormatName(format) << std::endl;
257  // Note: "surface" destructor automatically frees the old surface
258  drawingSurface = SDL_CreateRGBSurfaceWithFormat(
259  0,
260  wsize.x / scale,
261  wsize.y / scale,
262  bpp,
263  format
264  );
265 
266  // Also update the drawing texture, with matching format and size.
267  if (drawing_texture_) {
268  LOG_DP << "destroying old drawing texture" << std::endl;
269  SDL_DestroyTexture(drawing_texture_);
270  }
271  LOG_DP << "creating drawing texture" << std::endl;
272  drawing_texture_ = SDL_CreateTexture(
273  *window.get(),
274  drawingSurface->format->format,
275  SDL_TEXTUREACCESS_STREAMING,
276  drawingSurface->w,
277  drawingSurface->h
278  );
279  }
280 
281  // Update sizes for input conversion.
282  sdl::update_input_dimensions(lsize.x, lsize.y, wsize.x, wsize.y);
283 }
284 
286 {
287  // Position
288  const int x = preferences::fullscreen() ? SDL_WINDOWPOS_UNDEFINED : SDL_WINDOWPOS_CENTERED;
289  const int y = preferences::fullscreen() ? SDL_WINDOWPOS_UNDEFINED : SDL_WINDOWPOS_CENTERED;
290 
291  // Dimensions
292  const point res = preferences::resolution();
293  const int w = res.x;
294  const int h = res.y;
295 
296  uint32_t window_flags = 0;
297 
298  // Add any more default flags here
299  window_flags |= SDL_WINDOW_RESIZABLE;
300 #ifdef __APPLE__
301  window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
302 #endif
303 
305  window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
306  } else if(preferences::maximized()) {
307  window_flags |= SDL_WINDOW_MAXIMIZED;
308  }
309 
310  uint32_t renderer_flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
311 
313  LOG_DP << "VSYNC on\n";
314  renderer_flags |= SDL_RENDERER_PRESENTVSYNC;
315  }
316 
317  // Initialize window
318  window.reset(new sdl::window("", x, y, w, h, window_flags, renderer_flags));
319 
320  std::cerr << "Setting mode to " << w << "x" << h << std::endl;
321 
323 
324  SDL_DisplayMode currentDisplayMode;
325  SDL_GetCurrentDisplayMode(window->get_display_index(), &currentDisplayMode);
326  refresh_rate_ = currentDisplayMode.refresh_rate != 0 ? currentDisplayMode.refresh_rate : 60;
327 
329 
331 }
332 
334 {
335  assert(window);
336  if(fake_screen_) {
337  return;
338  }
339 
340  switch(mode) {
341  case TO_FULLSCREEN:
342  window->full_screen();
343  break;
344 
345  case TO_WINDOWED:
346  window->to_window();
347  window->restore();
348  break;
349 
350  case TO_MAXIMIZED_WINDOW:
351  window->to_window();
352  window->maximize();
353  break;
354 
355  case TO_RES:
356  window->restore();
357  window->set_size(size.x, size.y);
358  window->center();
359  break;
360  }
361 
363 }
364 
365 SDL_Point CVideo::output_size() const
366 {
367  // As we are rendering to the drawingSurface, we should never need this.
368  return window->get_output_size();
369 }
370 
371 SDL_Point CVideo::window_size() const
372 {
373  return window->get_size();
374 }
375 
376 SDL_Rect CVideo::draw_area() const
377 {
378  return {0, 0, drawingSurface->w, drawingSurface->h};
379 }
380 
381 SDL_Rect CVideo::input_area() const
382 {
383  // This should always match draw_area.
384  SDL_Point p(window->get_logical_size());
385  return {0, 0, p.x, p.y};
386 }
387 
388 int CVideo::get_width() const
389 {
390  return drawingSurface->w;
391 }
392 
394 {
395  return drawingSurface->h;
396 }
397 
398 void CVideo::delay(unsigned int milliseconds)
399 {
400  if(!game_config::no_delay) {
401  SDL_Delay(milliseconds);
402  }
403 }
404 
406 {
407  if(fake_screen_ || flip_locked_ > 0) {
408  return;
409  }
410 
411  if (drawingSurface && drawing_texture_) {
412  // Upload the drawing surface to the drawing texture.
413  void* pixels_out; // somewhere we can write raw pixel data to
414  int pitch; // the length of one row of pixels in bytes
415  SDL_LockTexture(drawing_texture_, nullptr, &pixels_out, &pitch);
416  if (pitch != drawingSurface->pitch) {
417  // If these don't match we are not gonna have a good time.
418  throw game::error("drawing surface and texture are incompatible");
419  }
420  size_t num_bytes = drawingSurface->h * pitch;
421  memcpy(pixels_out, drawingSurface->pixels, num_bytes);
422  SDL_UnlockTexture(drawing_texture_);
423 
424  //SDL_UpdateTexture(drawing_texture_, nullptr, drawingSurface->pixels, drawingSurface->pitch);
425 
426  // Copy the drawing texture to the render target.
427  SDL_RenderCopy(*window.get(), drawing_texture_, nullptr, nullptr);
428  }
429 
430  if(window) {
431  window->render();
432  }
433 }
434 
435 void CVideo::lock_updates(bool value)
436 {
437  if(value == true) {
438  ++updated_locked_;
439  } else {
440  --updated_locked_;
441  }
442 }
443 
445 {
446  return updated_locked_ > 0;
447 }
448 
449 void CVideo::set_window_title(const std::string& title)
450 {
451  assert(window);
452  window->set_title(title);
453 }
454 
456 {
457  assert(window);
458  window->set_icon(icon);
459 }
460 
462 {
463  if(!window) {
464  return;
465  }
466 
467  window->fill(0, 0, 0, 255);
468 }
469 
471 {
472  return window.get();
473 }
474 
475 SDL_Renderer* CVideo::get_renderer()
476 {
477  if(window) {
478  return *window;
479  } else {
480  return nullptr;
481  }
482 }
483 
485 {
486  const char* const drvname = SDL_GetCurrentVideoDriver();
487  return drvname ? drvname : "<not initialized>";
488 }
489 
490 std::vector<std::string> CVideo::enumerate_drivers()
491 {
492  std::vector<std::string> res;
493  int num_drivers = SDL_GetNumVideoDrivers();
494 
495  for(int n = 0; n < num_drivers; ++n) {
496  const char* drvname = SDL_GetVideoDriver(n);
497  res.emplace_back(drvname ? drvname : "<invalid driver>");
498  }
499 
500  return res;
501 }
502 
503 bool CVideo::window_has_flags(uint32_t flags) const
504 {
505  if(!window) {
506  return false;
507  }
508 
509  return (window->get_flags() & flags) != 0;
510 }
511 
512 std::pair<float, float> CVideo::get_dpi() const
513 {
514  float hdpi, vdpi;
515  if(window && SDL_GetDisplayDPI(window->get_display_index(), nullptr, &hdpi, &vdpi) == 0) {
516 #ifdef TARGET_OS_OSX
517  // SDL 2.0.12 changes SDL_GetDisplayDPI. Function now returns DPI
518  // multiplied by screen's scale factor. This part of code reverts
519  // this multiplication.
520  //
521  // For more info see issue: https://github.com/wesnoth/wesnoth/issues/5019
522 
523  if(sdl_get_version() >= version_info{2, 0, 12}) {
524  float scale_factor = desktop::apple::get_scale_factor(window->get_display_index());
525  hdpi /= scale_factor;
526  vdpi /= scale_factor;
527  }
528 #endif
529  return { hdpi, vdpi };
530  }
531  // SDL doesn't know the screen dpi, there's a configuration issue, or we
532  // don't have a window yet.
533  return { 0.0f, 0.0f };
534 }
535 
536 std::pair<float, float> CVideo::get_dpi_scale_factor() const
537 {
538  auto dpi = get_dpi();
539  if(dpi.first != 0.0f && dpi.second != 0.0f) {
540  // adjust for pixel scale
541  SDL_Point wsize = window_size();
542  dpi.first /= wsize.x / get_width();
543  dpi.second /= wsize.y / get_height();
544  return { dpi.first / MAGIC_DPI_SCALE_NUMBER, dpi.second / MAGIC_DPI_SCALE_NUMBER };
545  }
546  // Assume a scale factor of 1.0 if the screen dpi is currently unknown.
547  return { 1.0f, 1.0f };
548 }
549 
550 std::vector<point> CVideo::get_available_resolutions(const bool include_current)
551 {
552  std::vector<point> result;
553 
554  if(!window) {
555  return result;
556  }
557 
558  const int display_index = window->get_display_index();
559 
560  const int modes = SDL_GetNumDisplayModes(display_index);
561  if(modes <= 0) {
562  std::cerr << "No modes supported\n";
563  return result;
564  }
565 
567 
568 #if 0
569  // DPI scale factor.
570  auto [scale_h, scale_v] = get_dpi_scale_factor();
571 #endif
572 
573  // The maximum size to which this window can be set. For some reason this won't
574  // pop up as a display mode of its own.
575  SDL_Rect bounds;
576  SDL_GetDisplayBounds(display_index, &bounds);
577 
578  SDL_DisplayMode mode;
579 
580  for(int i = 0; i < modes; ++i) {
581  if(SDL_GetDisplayMode(display_index, i, &mode) == 0) {
582  // Exclude any results outside the range of the current DPI.
583  if(mode.w > bounds.w && mode.h > bounds.h) {
584  continue;
585  }
586 
587  if(mode.w >= min_res.x && mode.h >= min_res.y) {
588  result.emplace_back(mode.w, mode.h);
589  }
590  }
591  }
592 
593  if(std::find(result.begin(), result.end(), min_res) == result.end()) {
594  result.push_back(min_res);
595  }
596 
597  if(include_current) {
598  result.push_back(current_resolution());
599  }
600 
601  std::sort(result.begin(), result.end());
602  result.erase(std::unique(result.begin(), result.end()), result.end());
603 
604  return result;
605 }
606 
608 {
609  return drawingSurface;
610 }
611 
613 {
614  return point(window->get_size()); // Convert from plain SDL_Point
615 }
616 
618 {
619  return (window->get_flags() & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
620 }
621 
623 {
624  return sdl_get_version() >= version_info{2, 0, 17};
625 }
626 
627 int CVideo::set_help_string(const std::string& str)
628 {
630 
631  const color_t color{0, 0, 0, 0xbb};
632 
633  int size = font::SIZE_LARGE;
634 
635  while(size > 0) {
636  if(font::pango_line_width(str, size) > get_width()) {
637  size--;
638  } else {
639  break;
640  }
641  }
642 
643  const int border = 5;
644 
645  font::floating_label flabel(str);
646  flabel.set_font_size(size);
647  flabel.set_position(get_width() / 2, get_height());
648  flabel.set_bg_color(color);
649  flabel.set_border_size(border);
650 
652 
653  const SDL_Rect& rect = font::get_floating_label_rect(help_string_);
654  font::move_floating_label(help_string_, 0.0, -double(rect.h));
655 
656  return help_string_;
657 }
658 
660 {
661  if(handle == help_string_) {
663  help_string_ = 0;
664  }
665 }
666 
668 {
670 }
671 
672 void CVideo::set_fullscreen(bool ison)
673 {
674  if(window && is_fullscreen() != ison) {
675  const point& res = preferences::resolution();
676 
677  MODE_EVENT mode;
678 
679  if(ison) {
680  mode = TO_FULLSCREEN;
681  } else {
683  }
684 
685  set_window_mode(mode, res);
686 
687  if(display* d = display::get_singleton()) {
688  d->redraw_everything();
689  }
690  }
691 
692  // Change the config value.
694 }
695 
697 {
699 }
700 
701 bool CVideo::set_resolution(const unsigned width, const unsigned height)
702 {
703  return set_resolution(point(width, height));
704 }
705 
707 {
708  if(resolution == current_resolution()) {
709  return false;
710  }
711 
712  set_window_mode(TO_RES, resolution);
713 
714  if(display* d = display::get_singleton()) {
715  d->redraw_everything();
716  }
717 
718  // Change the saved values in preferences.
719  LOG_DP << "updating resolution to " << resolution << std::endl;
720  preferences::_set_resolution(resolution);
722 
723  // Push a window-resized event to the queue. This is necessary so various areas
724  // of the game (like GUI2) update properly with the new size.
726 
727  return true;
728 }
729 
731 {
732  LOG_DP << "updating buffers" << std::endl;
733  // We could also double-check the resolution here.
734  /*if (preferences::resolution() != current_resolution()) {
735  LOG_DP << "updating resolution from " << current_resolution()
736  << " to " << preferences::resolution() << std::endl;
737  set_window_mode(TO_RES, preferences::resolution());
738  }*/
739 
741 
742  if(display* d = display::get_singleton()) {
743  d->redraw_everything();
744  }
745 
746  // Push a window-resized event to the queue. This is necessary so various areas
747  // of the game (like GUI2) update properly with the new size.
749 }
750 
751 void CVideo::lock_flips(bool lock)
752 {
753  if(lock) {
754  ++flip_locked_;
755  } else {
756  --flip_locked_;
757  }
758 }
SDL_Texture * drawing_texture_
The drawing texture.
Definition: video.hpp:305
void raise_resize_event()
Definition: events.cpp:762
void set_window_icon(surface &icon)
Sets the icon of the main window.
Definition: video.cpp:455
void _set_fullscreen(bool ison)
Definition: general.cpp:462
int get_height() const
Returns the height of the drawing surface in pixels.
Definition: video.cpp:393
draw_layering(const bool auto_join=true)
Definition: video.cpp:58
SDL_Rect input_area() const
Returns the size and location of the window&#39;s input area in pixels.
Definition: video.cpp:381
bool update_locked() const
Whether the screen has been &#39;locked&#39; or not.
Definition: video.cpp:444
point current_resolution()
Definition: video.cpp:612
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:96
const int min_window_height
Definition: general.cpp:67
std::list< events::sdl_handler * > draw_layers
Definition: video.cpp:56
void remove_floating_label(int handle, int fadeout)
removes the floating label given by &#39;handle&#39; from the screen
void _set_maximized(bool ison)
Definition: general.cpp:457
Interfaces for manipulating version numbers of engine, add-ons, etc.
FAKE_TYPES
Definition: video.hpp:41
std::pair< float, float > get_dpi_scale_factor() const
The current scale factor on High-DPI screens.
Definition: video.cpp:536
#define ERR_DP
Definition: video.cpp:42
#define LOG_DP
Definition: video.cpp:41
const int min_window_width
Definition: general.cpp:66
int help_string_
Curent ID of the help string.
Definition: video.hpp:332
Definition: video.hpp:35
const int max_window_width
Definition: general.cpp:72
int get_width() const
Returns the width of the drawing surface in pixels.
Definition: video.cpp:388
void lock_updates(bool value)
Stop the screen being redrawn.
Definition: video.cpp:435
bool vsync()
Definition: general.cpp:446
void _set_resolution(const point &res)
Definition: general.cpp:451
static CVideo * singleton_
Definition: video.hpp:299
void update_input_dimensions(int draw_width, int draw_height, int input_width, int input_height)
Update the cached drawing area and input area sizes.
Definition: input.cpp:57
MODE_EVENT
Definition: video.hpp:97
int refresh_rate_
Definition: video.hpp:336
bool non_interactive() const
Definition: video.cpp:139
int flip_locked_
Definition: video.hpp:335
#define h
void set_font_size(int font_size)
void blit_surface(int x, int y, surface surf, SDL_Rect *srcrect=nullptr, SDL_Rect *clip_rect=nullptr)
Copies an area of a surface to the drawing surface.
Definition: video.cpp:167
#define d
int updated_locked_
Definition: video.hpp:334
~CVideo()
Definition: video.cpp:130
Contains functions for cleanly handling SDL input.
bool supports_vsync() const
Definition: video.cpp:622
void render_screen()
Renders the screen.
Definition: video.cpp:405
bool maximized()
Definition: general.cpp:436
void move_floating_label(int handle, double xmove, double ymove)
moves the floating label given by &#39;handle&#39; by (xmove,ymove)
int x
x coordinate.
Definition: point.hpp:45
virtual ~draw_layering()
Definition: video.cpp:64
SDL_Rect draw_area() const
Returns the size and location of the current drawing area in pixels.
Definition: video.cpp:376
bool set_resolution(const unsigned width, const unsigned height)
Definition: video.cpp:701
void set_window_title(const std::string &title)
Sets the title of the main window.
Definition: video.cpp:449
void make_fake()
Definition: video.cpp:176
void initSDL()
Initializes the SDL video subsystem.
Definition: video.cpp:120
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:87
The wrapper class for the SDL_Window class.
Definition: window.hpp:45
void scale(size_t factor, const uint32_t *src, uint32_t *trg, int srcWidth, int srcHeight, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
Definition: xbrz.cpp:1190
void make_test_fake(const unsigned width=1024, const unsigned height=768)
Creates a fake frame buffer for the unit tests.
Definition: video.cpp:184
void lock_flips(bool)
Definition: video.cpp:751
static std::vector< std::string > enumerate_drivers()
Definition: video.cpp:490
bool fullscreen()
Definition: general.cpp:441
static lg::log_domain log_display("display")
void set_bg_color(const color_t &bg_color)
void set_position(double xpos, double ypos)
map_display and display: classes which take care of displaying the map and game-data on the screen...
sdl::window * get_window()
Returns a pointer to the underlying SDL window.
Definition: video.cpp:470
const int max_pixel_scale
Definition: general.cpp:79
SDL_Point output_size() const
Returns the size of the final render target.
Definition: video.cpp:365
int pixel_scale()
Definition: general.cpp:415
CGFloat get_scale_factor(int display_index)
#define DRAW_ALL_EVENT
Definition: events.hpp:30
const int def_window_width
Definition: general.cpp:69
Definition: video.cpp:54
virtual void handle_window_event(const SDL_Event &event)
Definition: video.cpp:144
std::size_t i
Definition: function.cpp:967
surface & getDrawingSurface()
Returns a reference to the drawing surface.
Definition: video.cpp:607
SDL_Point window_size() const
Returns the size of the window in display units / screen coordinates.
Definition: video.cpp:371
mock_party p
void init_window()
Initializes a new SDL window instance, taking into account any preiously saved states.
Definition: video.cpp:285
void toggle_fullscreen()
Definition: video.cpp:696
void update_buffers()
Update buffers to match current resolution and pixel scale settings.
Definition: video.cpp:730
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
void set_fullscreen(bool ison)
Definition: video.cpp:672
static std::string current_driver()
Definition: video.cpp:484
Holds a 2D point.
Definition: point.hpp:24
SDL_Rect get_floating_label_rect(int handle)
int w
version_info sdl_get_version()
Definition: utils.cpp:34
void set_border_size(int border)
Represents version numbers.
int set_help_string(const std::string &str)
Displays a help string with the given text.
Definition: video.cpp:627
const int SIZE_LARGE
Definition: constants.cpp:30
const int def_window_height
Definition: general.cpp:70
bool is_fullscreen() const
Definition: video.cpp:617
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:28
void trigger_full_redraw()
Definition: video.cpp:71
Standard logging facilities (interface).
video_event_handler event_handler_
Definition: video.hpp:329
void clear_all_help_strings()
Removes all help strings.
Definition: video.cpp:667
static void delay(unsigned int milliseconds)
Waits a given number of milliseconds before returning.
Definition: video.cpp:398
void set_window_mode(const MODE_EVENT mode, const point &size)
Sets the window&#39;s mode - ie, changing it to fullscreen, maximizing, etc.
Definition: video.cpp:333
Contains a wrapper class for the SDL_Window class.
bool fake_screen_
Definition: video.hpp:311
point resolution()
Definition: general.cpp:399
void update_framebuffer()
Updates and ensures the framebuffer surface is valid.
Definition: video.cpp:192
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
Definition: utils.hpp:32
CVideo(const CVideo &)=delete
void clear_screen()
Clear the screen contents.
Definition: video.cpp:461
static map_location::DIRECTION n
std::shared_ptr< halo_record > handle
Definition: halo.hpp:30
int y
y coordinate.
Definition: point.hpp:48
SDL_Renderer * get_renderer()
Returns a pointer to the underlying window&#39;s renderer.
Definition: video.cpp:475
Transitional API for porting SDL_ttf-based code to Pango.
std::vector< point > get_available_resolutions(const bool include_current=false)
Returns the list of available screen resolutions.
Definition: video.cpp:550
const int max_window_height
Definition: general.cpp:73
bool window_has_flags(uint32_t flags) const
Tests whether the given flags are currently set on the SDL window.
Definition: video.cpp:503
virtual void join_global()
Definition: events.cpp:363
bool auto_pixel_scale()
Definition: general.cpp:426
std::unique_ptr< sdl::window > window
The SDL window object.
Definition: video.hpp:302
std::pair< float, float > get_dpi() const
The current game screen dpi.
Definition: video.cpp:512
void clear_help_string(int handle)
Removes the help string with the given handle.
Definition: video.cpp:659
int pango_line_width(const std::string &line, int font_size, font::pango_text::FONT_STYLE font_style=font::pango_text::STYLE_NORMAL)
Determine the width of a line of text given a certain font size.