The Battle for Wesnoth  1.15.10+dev
display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Routines to set up the display, scroll and zoom the map.
18  */
19 
20 #include "arrow.hpp"
21 #include "cursor.hpp"
22 #include "display.hpp"
23 #include "fake_unit_manager.hpp"
24 #include "font/sdl_ttf.hpp"
25 #include "font/text.hpp"
26 #include "preferences/game.hpp"
27 #include "gettext.hpp"
28 #include "halo.hpp"
30 #include "language.hpp"
31 #include "log.hpp"
32 #include "font/marked-up_text.hpp"
33 #include "map/map.hpp"
34 #include "map/label.hpp"
35 #include "minimap.hpp"
36 #include "overlay.hpp"
37 #include "play_controller.hpp" //note: this can probably be refactored out
38 #include "reports.hpp"
39 #include "resources.hpp"
40 #include "color.hpp"
41 #include "synced_context.hpp"
42 #include "team.hpp"
43 #include "terrain/builder.hpp"
44 #include "time_of_day.hpp"
45 #include "tooltips.hpp"
46 #include "tod_manager.hpp"
47 #include "units/unit.hpp"
49 #include "units/drawer.hpp"
50 #include "units/orb_status.hpp"
51 #include "whiteboard/manager.hpp"
52 #include "show_dialog.hpp"
54 
55 #include <SDL2/SDL_image.h>
56 
57 #include <algorithm>
58 #include <array>
59 #include <cmath>
60 #include <iomanip>
61 #include <utility>
62 
63 #ifdef _WIN32
64 #include <windows.h>
65 #endif
66 
67 // Includes for bug #17573
68 
69 static lg::log_domain log_display("display");
70 #define ERR_DP LOG_STREAM(err, log_display)
71 #define LOG_DP LOG_STREAM(info, log_display)
72 #define DBG_DP LOG_STREAM(debug, log_display)
73 
74 // These are macros instead of proper constants so that they auto-update if the game config is reloaded.
75 #define zoom_levels (game_config::zoom_levels)
76 #define final_zoom_index (static_cast<int>(zoom_levels.size()) - 1)
77 #define DefaultZoom (game_config::tile_size)
78 #define SmallZoom (DefaultZoom / 2)
79 #define MinZoom (zoom_levels.front())
80 #define MaxZoom (zoom_levels.back())
81 
82 namespace {
83  bool benchmark = false;
84 
85  bool debug_foreground = false;
86 
87  int prevLabel = 0;
88 }
89 
90 unsigned int display::zoom_ = DefaultZoom;
91 unsigned int display::last_zoom_ = SmallZoom;
92 
93 // Returns index of zoom_levels which is closest match to input zoom_level
94 // Assumption: zoom_levels is a sorted vector of ascending tile sizes
95 int get_zoom_levels_index(unsigned int zoom_level)
96 {
97  zoom_level = std::clamp(zoom_level, MinZoom, MaxZoom); // ensure zoom_level is within zoom_levels bounds
98  auto iter = std::lower_bound(zoom_levels.begin(), zoom_levels.end(), zoom_level);
99 
100  // find closest match
101  if(iter != zoom_levels.begin() && iter != zoom_levels.end()) {
102  float diff = *iter - *(iter - 1);
103  float lower = (zoom_level - *(iter - 1)) / diff;
104  float upper = (*iter - zoom_level) / diff;
105 
106  // the previous element is closer to zoom_level than the current one
107  if(lower < upper) {
108  iter--;
109  }
110  }
111 
112  return std::distance(zoom_levels.begin(), iter);
113 }
114 
116 {
117  const team& curr_team = dc_->teams()[playing_team()];
118  const team& prev_team = playing_team() == 0
119  ? dc_->teams().back()
120  : dc_->get_team(playing_team());
121  for (const auto& i : get_overlays()) {
122  for(const overlay& ov : i.second) {
123  if(!ov.team_name.empty() &&
124  ((ov.team_name.find(curr_team.team_name()) + 1) != 0) !=
125  ((ov.team_name.find(prev_team.team_name()) + 1) != 0))
126  {
127  invalidate(i.first);
128  }
129  }
130  }
131 }
132 
133 
134 void display::add_overlay(const map_location& loc, const std::string& img, const std::string& halo, const std::string& team_name, const std::string& item_id, bool visible_under_fog, float z_order)
135 {
136  if (halo_man_) {
137  halo::handle halo_handle;
138  if(halo != "") {
139  halo_handle = halo_man_->add(get_location_x(loc) + hex_size() / 2,
140  get_location_y(loc) + hex_size() / 2, halo, loc);
141  }
142 
143  std::vector<overlay>& overlays = get_overlays()[loc];
144  auto it = std::find_if(overlays.begin(), overlays.end(), [z_order](const overlay& ov) { return ov.z_order > z_order; });
145  overlays.emplace(it, img, halo, halo_handle, team_name, item_id, visible_under_fog, z_order);
146  }
147 }
148 
150 {
151  get_overlays().erase(loc);
152 }
153 
154 void display::remove_single_overlay(const map_location& loc, const std::string& toDelete)
155 {
156  std::vector<overlay>& overlays = get_overlays()[loc];
157  overlays.erase(
158  std::remove_if(
159  overlays.begin(), overlays.end(),
160  [&toDelete](const overlay& ov) { return ov.image == toDelete || ov.halo == toDelete || ov.id == toDelete; }
161  ),
162  overlays.end()
163  );
164 }
165 
167  std::weak_ptr<wb::manager> wb,
168  reports& reports_object,
169  const config& theme_cfg,
170  const config& level,
171  bool auto_join)
172  : video2::draw_layering(auto_join)
173  , dc_(dc)
174  , halo_man_(new halo::manager(*this))
175  , wb_(wb)
178  , currentTeam_(0)
179  , dont_show_all_(false)
180  , xpos_(0)
181  , ypos_(0)
182  , view_locked_(false)
183  , theme_(theme_cfg, screen_.screen_area())
184  , zoom_index_(0)
185  , fake_unit_man_(new fake_unit_manager(*this))
186  , builder_(new terrain_builder(level, (dc_ ? &dc_->map() : nullptr), theme_.border().tile_image, theme_.border().show_border))
187  , minimap_(nullptr)
189  , redrawMinimap_(false)
190  , redraw_background_(true)
191  , invalidateAll_(true)
192  , grid_(false)
193  , diagnostic_label_(0)
194  , panelsDrawn_(false)
195  , turbo_speed_(2)
196  , turbo_(false)
197  , invalidateGameStatus_(true)
198  , map_labels_(new map_labels(nullptr))
199  , reports_object_(&reports_object)
200  , scroll_event_("scrolled")
201  , frametimes_(50)
202  , fps_counter_()
203  , fps_start_()
204  , fps_actual_()
205  , reportRects_()
206  , reportSurfaces_()
207  , reports_()
208  , menu_buttons_()
209  , action_buttons_()
210  , invalidated_()
211  , mouseover_hex_overlay_(nullptr)
212  , tod_hex_mask1(nullptr)
213  , tod_hex_mask2(nullptr)
214  , fog_images_()
215  , shroud_images_()
216  , selectedHex_()
217  , mouseoverHex_()
218  , keys_()
219  , animate_map_(true)
220  , animate_water_(true)
221  , flags_()
222  , activeTeam_(0)
223  , drawing_buffer_()
224  , map_screenshot_(false)
225  , reach_map_()
226  , reach_map_old_()
227  , reach_map_changed_(true)
228  , fps_handle_(0)
229  , invalidated_hexes_(0)
230  , drawn_hexes_(0)
232  , idle_anim_rate_(1.0)
233  , map_screenshot_surf_(nullptr)
235  , draw_coordinates_(false)
236  , draw_terrain_codes_(false)
237  , draw_num_of_bitmaps_(false)
238  , arrows_map_()
239  , color_adjust_()
240  , dirty_()
241 {
242  //The following assertion fails when starting a campaign
243  assert(singleton_ == nullptr);
244  singleton_ = this;
245 
247 
248  blindfold_ctr_ = 0;
249 
250  read(level.child_or_empty("display"));
251 
253  && (screen_.getSurface() != nullptr
254  && screen_.faked())) {
255  screen_.lock_updates(true);
256  }
257 
260 
262 
263  unsigned int tile_size = preferences::tile_size();
264  if(tile_size < MinZoom || tile_size > MaxZoom)
265  tile_size = DefaultZoom;
266  zoom_index_ = get_zoom_levels_index(tile_size);
268  if(zoom_ != preferences::tile_size()) // correct saved tile_size if necessary
270 
272 
273  init_flags();
274 
275  if(!menu_buttons_.empty() || !action_buttons_.empty()) {
276  create_buttons();
277  }
278 
279 #ifdef _WIN32
280  // Increase timer resolution to prevent delays getting much longer than they should.
281  timeBeginPeriod(1u);
282 #endif
283 }
284 
286 {
287 #ifdef _WIN32
288  timeEndPeriod(1u);
289 #endif
290 
291  singleton_ = nullptr;
292  resources::fake_units = nullptr;
293 }
294 
295 void display::set_theme(config theme_cfg) {
296  theme_ = theme(theme_cfg, screen_.screen_area());
297  builder_->set_draw_border(theme_.border().show_border);
298  menu_buttons_.clear();
299  action_buttons_.clear();
300  create_buttons();
302  rebuild_all();
304 }
305 
307 
308  flags_.clear();
309  if (!dc_) return;
310  flags_.resize(dc_->teams().size());
311 
312  std::vector<std::string> side_colors;
313  side_colors.reserve(dc_->teams().size());
314 
315  for(const team& t : dc_->teams()) {
316  std::string side_color = t.color();
317  side_colors.push_back(side_color);
318  init_flags_for_side_internal(t.side() - 1, side_color);
319  }
320 }
321 
323 {
325 }
326 
327 void display::init_flags_for_side_internal(std::size_t n, const std::string& side_color)
328 {
329  assert(dc_ != nullptr);
330  assert(n < dc_->teams().size());
331  assert(n < flags_.size());
332 
333  std::string flag = dc_->teams()[n].flag();
334  std::string old_rgb = game_config::flag_rgb;
335  std::string new_rgb = side_color;
336 
337  if(flag.empty()) {
339  }
340 
341  LOG_DP << "Adding flag for team " << n << " from animation " << flag << "\n";
342 
343  // Must recolor flag image
344  animated<image::locator> temp_anim;
345 
346  std::vector<std::string> items = utils::square_parenthetical_split(flag);
347 
348  for(const std::string& item : items) {
349  const std::vector<std::string>& sub_items = utils::split(item, ':');
350  std::string str = item;
351  int time = 100;
352 
353  if(sub_items.size() > 1) {
354  str = sub_items.front();
355  try {
356  time = std::max<int>(1, std::stoi(sub_items.back()));
357  } catch(const std::invalid_argument&) {
358  ERR_DP << "Invalid time value found when constructing flag for side " << n << ": " << sub_items.back() << "\n";
359  }
360  }
361 
362  std::stringstream temp;
363  temp << str << "~RC(" << old_rgb << ">"<< new_rgb << ")";
364  image::locator flag_image(temp.str());
365  temp_anim.add_frame(time, flag_image);
366  }
367 
369  f = temp_anim;
370  auto time = f.get_end_time();
371  if (time > 0) {
372  f.start_animation(randomness::rng::default_instance().get_random_int(0, time-1), true);
373  }
374  else {
375  // this can happen if both flag and game_config::images::flag are empty.
376  ERR_DP << "missing flag for team" << n << "\n";
377  }
378 }
379 
381 {
382  if(!get_map().is_village(loc)) {
383  return surface(nullptr);
384  }
385 
386  for (const team& t : dc_->teams()) {
387  if (t.owns_village(loc) && (!fogged(loc) || !dc_->get_team(viewing_side()).is_enemy(t.side())))
388  {
389  auto& flag = flags_[t.side() - 1];
390  flag.update_last_draw_time();
391  const image::locator &image_flag = animate_map_ ?
392  flag.get_current_frame() : flag.get_first_frame();
393  return image::get_image(image_flag, image::TOD_COLORED);
394  }
395  }
396 
397  return surface(nullptr);
398 }
399 
400 void display::set_team(std::size_t teamindex, bool show_everything)
401 {
402  assert(teamindex < dc_->teams().size());
403  currentTeam_ = teamindex;
404  if (!show_everything)
405  {
406  labels().set_team(&dc_->teams()[teamindex]);
407  dont_show_all_ = true;
408  }
409  else
410  {
411  labels().set_team(nullptr);
412  dont_show_all_ = false;
413  }
415  if(std::shared_ptr<wb::manager> w = wb_.lock())
416  w->on_viewer_change(teamindex);
417 }
418 
419 void display::set_playing_team(std::size_t teamindex)
420 {
421  assert(teamindex < dc_->teams().size());
422  activeTeam_ = teamindex;
424 }
425 
427 {
428  if (loc.valid() && exclusive_unit_draw_requests_.find(loc) == exclusive_unit_draw_requests_.end())
429  {
430  exclusive_unit_draw_requests_[loc] = unit.id();
431  return true;
432  }
433  else
434  {
435  return false;
436  }
437 }
438 
440 {
441  std::string id = "";
442  if(loc.valid())
443  {
445  //id will be set to the default "" string by the [] operator if the map doesn't have anything for that loc.
447  }
448  return id;
449 }
450 
451 const time_of_day & display::get_time_of_day(const map_location& /*loc*/) const
452 {
453  static time_of_day tod;
454  return tod;
455 }
456 
457 void display::update_tod(const time_of_day* tod_override)
458 {
459  const time_of_day* tod = tod_override;
460  if(tod == nullptr) {
461  tod = &get_time_of_day();
462  }
463 
464  const tod_color col = color_adjust_ + tod->color;
465  image::set_color_adjustment(col.r, col.g, col.b);
466 }
467 
468 void display::adjust_color_overlay(int r, int g, int b)
469 {
470  color_adjust_ = tod_color(r, g, b);
471  update_tod();
472 }
473 
474 void display::fill_images_list(const std::string& prefix, std::vector<std::string>& images)
475 {
476  if(prefix == ""){
477  return;
478  }
479 
480  // search prefix.png, prefix1.png, prefix2.png ...
481  for(int i=0; ; ++i){
482  std::ostringstream s;
483  s << prefix;
484  if(i != 0)
485  s << i;
486  s << ".png";
487  if(image::exists(s.str()))
488  images.push_back(s.str());
489  else if(i>0)
490  break;
491  }
492  if (images.empty())
493  images.emplace_back();
494 }
495 
496 const std::string& display::get_variant(const std::vector<std::string>& variants, const map_location &loc)
497 {
498  //TODO use better noise function
499  return variants[std::abs(loc.x + loc.y) % variants.size()];
500 }
501 
503 {
504  builder_->rebuild_all();
505 }
506 
508 {
509  redraw_background_ = true;
510  builder_->reload_map();
511 }
512 
514 {
515  dc_ = dc;
516  builder_->change_map(&dc_->map()); //TODO: Should display_context own and initialize the builder object?
517 }
518 
520 {
521  halo_man_.reset(new halo::manager(*this));
522 }
523 
525 {
526  halo_man_.reset(&halo_man);
527 }
528 
529 void display::blindfold(bool value)
530 {
531  if(value == true)
532  ++blindfold_ctr_;
533  else
534  --blindfold_ctr_;
535 }
536 
538 {
539  return blindfold_ctr_ > 0;
540 }
541 
542 
543 const SDL_Rect& display::max_map_area() const
544 {
545  static SDL_Rect max_area {0, 0, 0, 0};
546 
547  // hex_size() is always a multiple of 4
548  // and hex_width() a multiple of 3,
549  // so there shouldn't be off-by-one-errors
550  // due to rounding.
551  // To display a hex fully on screen,
552  // a little bit extra space is needed.
553  // Also added the border two times.
554  max_area.w = static_cast<int>((get_map().w() + 2 * theme_.border().size + 1.0/3.0) * hex_width());
555  max_area.h = static_cast<int>((get_map().h() + 2 * theme_.border().size + 0.5) * hex_size());
556 
557  return max_area;
558 }
559 
560 const SDL_Rect& display::map_area() const
561 {
562  static SDL_Rect max_area;
563  max_area = max_map_area();
564 
565  // if it's for map_screenshot, maximize and don't recenter
566  if (map_screenshot_) {
567  return max_area;
568  }
569 
570  static SDL_Rect res;
571  res = map_outside_area();
572 
573  if(max_area.w < res.w) {
574  // map is smaller, center
575  res.x += (res.w - max_area.w)/2;
576  res.w = max_area.w;
577  }
578 
579  if(max_area.h < res.h) {
580  // map is smaller, center
581  res.y += (res.h - max_area.h)/2;
582  res.h = max_area.h;
583  }
584 
585  return res;
586 }
587 
588 bool display::outside_area(const SDL_Rect& area, const int x, const int y)
589 {
590  const int x_thresh = hex_size();
591  const int y_thresh = hex_size();
592  return (x < area.x || x > area.x + area.w - x_thresh ||
593  y < area.y || y > area.y + area.h - y_thresh);
594 }
595 
596 // This function uses the screen as reference
597 const map_location display::hex_clicked_on(int xclick, int yclick) const
598 {
599  const SDL_Rect& rect = map_area();
600  if(sdl::point_in_rect(xclick,yclick,rect) == false) {
601  return map_location();
602  }
603 
604  xclick -= rect.x;
605  yclick -= rect.y;
606 
607  return pixel_position_to_hex(xpos_ + xclick, ypos_ + yclick);
608 }
609 
610 
611 // This function uses the rect of map_area as reference
613 {
614  // adjust for the border
615  x -= static_cast<int>(theme_.border().size * hex_width());
616  y -= static_cast<int>(theme_.border().size * hex_size());
617  // The editor can modify the border and this will result in a negative y
618  // value. Instead of adding extra cases we just shift the hex. Since the
619  // editor doesn't use the direction this is no problem.
620  const int offset = y < 0 ? 1 : 0;
621  if(offset) {
622  x += hex_width();
623  y += hex_size();
624  }
625  const int s = hex_size();
626  const int tesselation_x_size = hex_width() * 2;
627  const int tesselation_y_size = s;
628  const int x_base = x / tesselation_x_size * 2;
629  const int x_mod = x % tesselation_x_size;
630  const int y_base = y / tesselation_y_size;
631  const int y_mod = y % tesselation_y_size;
632 
633  int x_modifier = 0;
634  int y_modifier = 0;
635 
636  if (y_mod < tesselation_y_size / 2) {
637  if ((x_mod * 2 + y_mod) < (s / 2)) {
638  x_modifier = -1;
639  y_modifier = -1;
640  } else if ((x_mod * 2 - y_mod) < (s * 3 / 2)) {
641  x_modifier = 0;
642  y_modifier = 0;
643  } else {
644  x_modifier = 1;
645  y_modifier = -1;
646  }
647 
648  } else {
649  if ((x_mod * 2 - (y_mod - s / 2)) < 0) {
650  x_modifier = -1;
651  y_modifier = 0;
652  } else if ((x_mod * 2 + (y_mod - s / 2)) < s * 2) {
653  x_modifier = 0;
654  y_modifier = 0;
655  } else {
656  x_modifier = 1;
657  y_modifier = 0;
658  }
659  }
660 
661  return map_location(x_base + x_modifier - offset, y_base + y_modifier - offset);
662 }
663 
665 {
666  if (loc_.y < rect_.bottom[loc_.x & 1])
667  ++loc_.y;
668  else {
669  ++loc_.x;
670  loc_.y = rect_.top[loc_.x & 1];
671  }
672 
673  return *this;
674 }
675 
676 // begin is top left, and end is after bottom right
678 {
679  return iterator(map_location(left, top[left & 1]), *this);
680 }
682 {
683  return iterator(map_location(right+1, top[(right+1) & 1]), *this);
684 }
685 
686 const display::rect_of_hexes display::hexes_under_rect(const SDL_Rect& r) const
687 {
688  rect_of_hexes res;
689 
690  if (r.w<=0 || r.h<=0) {
691  // empty rect, return dummy values giving begin=end
692  res.left = 0;
693  res.right = -1; // end is right+1
694  res.top[0] = 0;
695  res.top[1] = 0;
696  res.bottom[0] = 0;
697  res.bottom[1] = 0;
698  return res;
699  }
700 
701  SDL_Rect map_rect = map_area();
702  // translate rect coordinates from screen-based to map_area-based
703  int x = xpos_ - map_rect.x + r.x;
704  int y = ypos_ - map_rect.y + r.y;
705  // we use the "double" type to avoid important rounding error (size of an hex!)
706  // we will also need to use std::floor to avoid bad rounding at border (negative values)
707  double tile_width = hex_width();
708  double tile_size = hex_size();
709  double border = theme_.border().size;
710  // we minus "0.(3)", for horizontal imbrication.
711  // reason is: two adjacent hexes each overlap 1/4 of their width, so for
712  // grid calculation 3/4 of tile width is used, which by default gives
713  // 18/54=0.(3). Note that, while tile_width is zoom dependent, 0.(3) is not.
714  res.left = static_cast<int>(std::floor(-border + x / tile_width - 0.3333333));
715  // we remove 1 pixel of the rectangle dimensions
716  // (the rounded division take one pixel more than needed)
717  res.right = static_cast<int>(std::floor(-border + (x + r.w-1) / tile_width));
718 
719  // for odd x, we must shift up one half-hex. Since x will vary along the edge,
720  // we store here the y values for even and odd x, respectively
721  res.top[0] = static_cast<int>(std::floor(-border + y / tile_size));
722  res.top[1] = static_cast<int>(std::floor(-border + y / tile_size - 0.5));
723  res.bottom[0] = static_cast<int>(std::floor(-border + (y + r.h-1) / tile_size));
724  res.bottom[1] = static_cast<int>(std::floor(-border + (y + r.h-1) / tile_size - 0.5));
725 
726  // TODO: in some rare cases (1/16), a corner of the big rect is on a tile
727  // (the 72x72 rectangle containing the hex) but not on the hex itself
728  // Can maybe be optimized by using pixel_position_to_hex
729 
730  return res;
731 }
732 
734 {
735  return currentTeam_ < dc_->teams().size();
736 }
737 
738 bool display::shrouded(const map_location& loc) const
739 {
740  return is_blindfolded() || (dont_show_all_ && dc_->teams()[currentTeam_].shrouded(loc));
741 }
742 
743 bool display::fogged(const map_location& loc) const
744 {
745  return is_blindfolded() || (dont_show_all_ && dc_->teams()[currentTeam_].fogged(loc));
746 }
747 
749 {
750  return static_cast<int>(map_area().x + (loc.x + theme_.border().size) * hex_width() - xpos_);
751 }
752 
754 {
755  return static_cast<int>(map_area().y + (loc.y + theme_.border().size) * zoom_ - ypos_ + (is_odd(loc.x) ? zoom_/2 : 0));
756 }
757 
759 {
760  //TODO: don't return location for this,
761  // instead directly scroll to the clicked pixel position
762 
763  if (!sdl::point_in_rect(x, y, minimap_area())) {
764  return map_location();
765  }
766 
767  // we transform the coordinates from minimap to the full map image
768  // probably more adjustments to do (border, minimap shift...)
769  // but the mouse and human capacity to evaluate the rectangle center
770  // is not pixel precise.
771  int px = (x - minimap_location_.x) * get_map().w()*hex_width() / std::max (minimap_location_.w, 1);
772  int py = (y - minimap_location_.y) * get_map().h()*hex_size() / std::max(minimap_location_.h, 1);
773 
774  map_location loc = pixel_position_to_hex(px, py);
775  if (loc.x < 0)
776  loc.x = 0;
777  else if (loc.x >= get_map().w())
778  loc.x = get_map().w() - 1;
779 
780  if (loc.y < 0)
781  loc.y = 0;
782  else if (loc.y >= get_map().h())
783  loc.y = get_map().h() - 1;
784 
785  return loc;
786 }
787 
788 surface display::screenshot(bool map_screenshot)
789 {
790  if (!map_screenshot) {
791  return screen_.getSurface().clone();
792  } else {
793  if (get_map().empty()) {
794  ERR_DP << "No map loaded, cannot create a map screenshot.\n";
795  return nullptr;
796  }
797 
798  SDL_Rect area = max_map_area();
799  map_screenshot_surf_ = surface(area.w, area.h);
800 
801  if (map_screenshot_surf_ == nullptr) {
802  // Memory problem ?
803  ERR_DP << "Could not create screenshot surface, try zooming out.\n";
804  return nullptr;
805  }
806 
807  // back up the current map view position and move to top-left
808  int old_xpos = xpos_;
809  int old_ypos = ypos_;
810  xpos_ = 0;
811  ypos_ = 0;
812 
813  // we reroute render output to the screenshot surface and invalidate all
814  map_screenshot_= true;
815  invalidateAll_ = true;
816  DBG_DP << "draw() with map_screenshot\n";
817  draw(true,true);
818 
819  // restore normal rendering
820  map_screenshot_= false;
821  xpos_ = old_xpos;
822  ypos_ = old_ypos;
823 
824  // Clear map_screenshot_surf_ and return a new surface that contains the same data
825  surface surf(std::move(map_screenshot_surf_));
826  return surf;
827  }
828 }
829 
830 std::shared_ptr<gui::button> display::find_action_button(const std::string& id)
831 {
832  for (std::size_t i = 0; i < action_buttons_.size(); ++i) {
833  if(action_buttons_[i]->id() == id) {
834  return action_buttons_[i];
835  }
836  }
837  return nullptr;
838 }
839 
840 std::shared_ptr<gui::button> display::find_menu_button(const std::string& id)
841 {
842  for (std::size_t i = 0; i < menu_buttons_.size(); ++i) {
843  if(menu_buttons_[i]->id() == id) {
844  return menu_buttons_[i];
845  }
846  }
847  return nullptr;
848 }
849 
851 {
852  DBG_DP << "positioning menu buttons...\n";
853  for(const auto& menu : theme_.menus()) {
854  std::shared_ptr<gui::button> b = find_menu_button(menu.get_id());
855  if(b) {
856  const SDL_Rect& loc = menu.location(screen_.screen_area());
857  b->set_location(loc);
858  b->set_measurements(0,0);
859  b->set_label(menu.title());
860  b->set_image(menu.image());
861  }
862  }
863 
864  DBG_DP << "positioning action buttons...\n";
865  for(const auto& action : theme_.actions()) {
866  std::shared_ptr<gui::button> b = find_action_button(action.get_id());
867  if(b) {
868  const SDL_Rect& loc = action.location(screen_.screen_area());
869  b->set_location(loc);
870  b->set_measurements(0,0);
871  b->set_label(action.title());
872  b->set_image(action.image());
873  }
874  }
875 }
876 
878 {
879  std::vector<std::shared_ptr<gui::button>> menu_work;
880  std::vector<std::shared_ptr<gui::button>> action_work;
881 
882  DBG_DP << "creating menu buttons...\n";
883  for(const auto& menu : theme_.menus()) {
884  if (!menu.is_button()) continue;
885 
886  std::shared_ptr<gui::button> b(new gui::button(screen_, menu.title(), gui::button::TYPE_PRESS, menu.image(),
887  gui::button::DEFAULT_SPACE, false, menu.overlay()));
888  DBG_DP << "drawing button " << menu.get_id() << "\n";
889  b->join_same(this);
890  b->set_id(menu.get_id());
891  if (!menu.tooltip().empty()){
892  b->set_tooltip_string(menu.tooltip());
893  }
894 
895  std::shared_ptr<gui::button> b_prev = find_menu_button(b->id());
896  if(b_prev) {
897  b->enable(b_prev->enabled());
898  }
899 
900  menu_work.push_back(b);
901  }
902 
903  DBG_DP << "creating action buttons...\n";
904  for(const auto& action : theme_.actions()) {
905  std::shared_ptr<gui::button> b(new gui::button(screen_, action.title(), string_to_button_type(action.type()), action.image(),
906  gui::button::DEFAULT_SPACE, false, action.overlay()));
907 
908  DBG_DP << "drawing button " << action.get_id() << "\n";
909  b->set_id(action.get_id());
910  b->join_same(this);
911  if (!action.tooltip(0).empty()){
912  b->set_tooltip_string(action.tooltip(0));
913  }
914 
915  std::shared_ptr<gui::button> b_prev = find_action_button(b->id());
916  if(b_prev) {
917  b->enable(b_prev->enabled());
918  if (b_prev->get_type() == gui::button::TYPE_CHECK) {
919  b->set_check(b_prev->checked());
920  }
921  }
922 
923  action_work.push_back(b);
924  }
925 
926 
927  menu_buttons_.clear();
928  menu_buttons_.assign(menu_work.begin(), menu_work.end());
929  action_buttons_.clear();
930  action_buttons_.assign(action_work.begin(), action_work.end());
931 
932  layout_buttons();
933  DBG_DP << "buttons created\n";
934 }
935 
937 {
938  for (std::shared_ptr<gui::button> btn : menu_buttons_) {
939  btn->set_dirty(true);
940  btn->draw();
941  }
942 
943  for (std::shared_ptr<gui::button> btn : action_buttons_) {
944  btn->set_dirty(true);
945  btn->draw();
946  }
947 }
948 
949 
951 {
953  if (type == "checkbox") { res = gui::button::TYPE_CHECK; }
954  else if (type == "image") { res = gui::button::TYPE_IMAGE; }
955  else if (type == "radiobox") { res = gui::button::TYPE_RADIO; }
956  else if (type == "turbo") { res = gui::button::TYPE_TURBO; }
957  return res;
958 }
959 
960 static const std::string& get_direction(std::size_t n)
961 {
962  static const std::array<std::string, 6> dirs {{ "-n", "-ne", "-se", "-s", "-sw", "-nw" }};
963  return dirs[n >= dirs.size() ? 0 : n];
964 }
965 
966 std::vector<surface> display::get_fog_shroud_images(const map_location& loc, image::TYPE image_type)
967 {
968  std::vector<std::string> names;
969  const auto adjacent = get_adjacent_tiles(loc);
970 
971  enum visibility {FOG=0, SHROUD=1, CLEAR=2};
972  visibility tiles[6];
973 
974  const std::string* image_prefix[] =
976 
977  for(int i = 0; i < 6; ++i) {
978  if(shrouded(adjacent[i])) {
979  tiles[i] = SHROUD;
980  } else if(!fogged(loc) && fogged(adjacent[i])) {
981  tiles[i] = FOG;
982  } else {
983  tiles[i] = CLEAR;
984  }
985  }
986 
987  for(int v = FOG; v != CLEAR; ++v) {
988  // Find somewhere that doesn't have overlap to use as a starting point
989  int start;
990  for(start = 0; start != 6; ++start) {
991  if(tiles[start] != v) {
992  break;
993  }
994  }
995 
996  if(start == 6) {
997  // Completely surrounded by fog or shroud. This might have
998  // a special graphic.
999  const std::string name = *image_prefix[v] + "-all.png";
1000  if ( image::exists(name) ) {
1001  names.push_back(name);
1002  // Proceed to the next visibility (fog -> shroud -> clear).
1003  continue;
1004  }
1005  // No special graphic found. We'll just combine some other images
1006  // and hope it works out.
1007  start = 0;
1008  }
1009 
1010  // Find all the directions overlap occurs from
1011  for (int i = (start+1)%6, cap1 = 0; i != start && cap1 != 6; ++cap1) {
1012  if(tiles[i] == v) {
1013  std::ostringstream stream;
1014  std::string name;
1015  stream << *image_prefix[v];
1016 
1017  for (int cap2 = 0; v == tiles[i] && cap2 != 6; i = (i+1)%6, ++cap2) {
1018  stream << get_direction(i);
1019 
1020  if(!image::exists(stream.str() + ".png")) {
1021  // If we don't have any surface at all,
1022  // then move onto the next overlapped area
1023  if(name.empty()) {
1024  i = (i+1)%6;
1025  }
1026  break;
1027  } else {
1028  name = stream.str();
1029  }
1030  }
1031 
1032  if(!name.empty()) {
1033  names.push_back(name + ".png");
1034  }
1035  } else {
1036  i = (i+1)%6;
1037  }
1038  }
1039  }
1040 
1041  // now get the surfaces
1042  std::vector<surface> res;
1043 
1044  for (std::string& name : names) {
1045  surface surf(image::get_image(name, image_type));
1046  if (surf)
1047  res.push_back(std::move(surf));
1048  }
1049 
1050  return res;
1051 }
1052 
1054  const std::string& timeid,
1056 {
1057  terrain_image_vector_.clear();
1058 
1059  terrain_builder::TERRAIN_TYPE builder_terrain_type =
1060  (terrain_type == FOREGROUND ?
1062 
1063  const terrain_builder::imagelist* const terrains = builder_->get_terrain_at(loc,
1064  timeid, builder_terrain_type);
1065 
1067 
1068  const time_of_day& tod = get_time_of_day(loc);
1069 
1070  //get all the light transitions
1071  const auto adjs = get_adjacent_tiles(loc);
1072  std::array<const time_of_day*, 6> atods;
1073  for(size_t d = 0; d < adjs.size(); ++d){
1074  atods[d] = &get_time_of_day(adjs[d]);
1075  }
1076 
1077  for(int d=0; d<6; ++d){
1078  /*
1079  concave
1080  _____
1081  / \
1082  / atod1 \_____
1083  \ !tod / \
1084  \_____/ atod2 \
1085  / \__\ !tod /
1086  / \_____/
1087  \ tod /
1088  \_____/
1089  */
1090 
1091  const time_of_day& atod1 = *atods[d];
1092  const time_of_day& atod2 = *atods[(d + 1) % 6];
1093 
1094  if(atod1.color == tod.color || atod2.color == tod.color || atod1.color != atod2.color)
1095  continue;
1096 
1097  if(lt.empty()) {
1098  //color the full hex before adding transitions
1099  tod_color col = tod.color + color_adjust_;
1100  lt = image::get_light_string(0, col.r, col.g, col.b);
1101  }
1102 
1103  // add the directional transitions
1104  tod_color acol = atod1.color + color_adjust_;
1105  lt += image::get_light_string(d + 1, acol.r, acol.g, acol.b);
1106  }
1107  for(int d=0; d<6; ++d){
1108  /*
1109  convex 1
1110  _____
1111  / \
1112  / atod1 \_____
1113  \ !tod / \
1114  \_____/ atod2 \
1115  / \__\ tod /
1116  / \_____/
1117  \ tod /
1118  \_____/
1119  */
1120 
1121  const time_of_day& atod1 = *atods[d];
1122  const time_of_day& atod2 = *atods[(d + 1) % 6];
1123 
1124  if(atod1.color == tod.color || atod1.color == atod2.color)
1125  continue;
1126 
1127  if(lt.empty()) {
1128  //color the full hex before adding transitions
1129  tod_color col = tod.color + color_adjust_;
1130  lt = image::get_light_string(0, col.r, col.g, col.b);
1131  }
1132 
1133  // add the directional transitions
1134  tod_color acol = atod1.color + color_adjust_;
1135  lt += image::get_light_string(d + 7, acol.r, acol.g, acol.b);
1136  }
1137  for(int d=0; d<6; ++d){
1138  /*
1139  convex 2
1140  _____
1141  / \
1142  / atod1 \_____
1143  \ tod / \
1144  \_____/ atod2 \
1145  / \__\ !tod /
1146  / \_____/
1147  \ tod /
1148  \_____/
1149  */
1150 
1151  const time_of_day& atod1 = *atods[d];
1152  const time_of_day& atod2 = *atods[(d + 1) % 6];
1153 
1154  if(atod2.color == tod.color || atod1.color == atod2.color)
1155  continue;
1156 
1157  if(lt.empty()) {
1158  //color the full hex before adding transitions
1159  tod_color col = tod.color + color_adjust_;
1160  lt = image::get_light_string(0, col.r, col.g, col.b);
1161  }
1162 
1163  // add the directional transitions
1164  tod_color acol = atod2.color + color_adjust_;
1165  lt += image::get_light_string(d + 13, acol.r, acol.g, acol.b);
1166  }
1167 
1168  if(lt.empty()){
1169  tod_color col = tod.color + color_adjust_;
1170  if(!col.is_zero()){
1171  // no real lightmap needed but still color the hex
1172  lt = image::get_light_string(-1, col.r, col.g, col.b);
1173  }
1174  }
1175 
1176  if(terrains != nullptr) {
1177  // Cache the offmap name.
1178  // Since it is themeable it can change,
1179  // so don't make it static.
1180  const std::string off_map_name = "terrain/" + theme_.border().tile_image;
1181  for(const auto& terrain : *terrains) {
1182  const image::locator &image = animate_map_ ?
1183  terrain.get_current_frame() : terrain.get_first_frame();
1184 
1185  // We prevent ToD coloring and brightening of off-map tiles,
1186  // We need to test for the tile to be rendered and
1187  // not the location, since the transitions are rendered
1188  // over the offmap-terrain and these need a ToD coloring.
1189  surface surf;
1190  const bool off_map = (image.get_filename() == off_map_name || image.get_modifications().find("NO_TOD_SHIFT()") != std::string::npos);
1191 
1192  if(off_map) {
1193  surf = image::get_image(image, image::SCALED_TO_HEX);
1194  } else if(lt.empty()) {
1195  surf = image::get_image(image, image::SCALED_TO_HEX);
1196  } else {
1198  }
1199 
1200  if (surf) {
1201  terrain_image_vector_.push_back(std::move(surf));
1202  }
1203  }
1204  }
1205 }
1206 
1208  const map_location& loc, int x, int y, const surface& surf,
1209  const SDL_Rect &clip)
1210 {
1211  drawing_buffer_.emplace_back(layer, loc, x, y, surf, clip);
1212 }
1213 
1215  const map_location& loc, int x, int y,
1216  const std::vector<surface> &surf,
1217  const SDL_Rect &clip)
1218 {
1219  drawing_buffer_.emplace_back(layer, loc, x, y, surf, clip);
1220 }
1221 
1222 // FIXME: temporary method. Group splitting should be made
1223 // public into the definition of drawing_layer
1224 //
1225 // The drawing is done per layer_group, the range per group is [low, high).
1226 const std::array<display::drawing_layer, 4> display::drawing_buffer_key::layer_groups {{
1230  // Make sure the movement doesn't show above fog and reachmap.
1232 }};
1233 
1234 enum {
1235  // you may adjust the following when needed:
1236 
1237  // maximum border. 3 should be safe even if a larger border is in use somewhere
1239 
1240  // store x, y, and layer in one 32 bit integer
1241  // 4 most significant bits == layer group => 16
1243 
1244  // 10 second most significant bits == y => 1024
1246 
1247  // 1 third most significant bit == x parity => 2
1249 
1250  // 8 fourth most significant bits == layer => 256
1252 
1253  // 9 least significant bits == x / 2 => 512 (really 1024 for x)
1255 };
1256 
1258  : key_(0)
1259 {
1260  // Start with the index of last group entry...
1261  unsigned int group_i = layer_groups.size() - 1;
1262 
1263  // ...and works backwards until the group containing the specified layer is found.
1264  while(layer < layer_groups[group_i]) {
1265  --group_i;
1266  }
1267 
1268  enum {
1269  SHIFT_LAYER = BITS_FOR_X_OVER_2,
1270  SHIFT_X_PARITY = BITS_FOR_LAYER + SHIFT_LAYER,
1271  SHIFT_Y = BITS_FOR_X_PARITY + SHIFT_X_PARITY,
1272  SHIFT_LAYER_GROUP = BITS_FOR_Y + SHIFT_Y
1273  };
1274  static_assert(SHIFT_LAYER_GROUP + BITS_FOR_LAYER_GROUP == sizeof(key_) * 8, "Bit field too small");
1275 
1276  // the parity of x must be more significant than the layer but less significant than y.
1277  // Thus basically every row is split in two: First the row containing all the odd x
1278  // then the row containing all the even x. Since thus the least significant bit of x is
1279  // not required for x ordering anymore it can be shifted out to the right.
1280  const unsigned int x_parity = static_cast<unsigned int>(loc.x) & 1;
1281  key_ = (group_i << SHIFT_LAYER_GROUP) | (static_cast<unsigned int>(loc.y + MAX_BORDER) << SHIFT_Y);
1282  key_ |= (x_parity << SHIFT_X_PARITY);
1283  key_ |= (static_cast<unsigned int>(layer) << SHIFT_LAYER) | static_cast<unsigned int>(loc.x + MAX_BORDER) / 2;
1284 }
1285 
1287 {
1288  // std::list::sort() is a stable sort
1289  drawing_buffer_.sort();
1290 
1291  SDL_Rect clip_rect = map_area();
1292  surface& screen = get_screen_surface();
1293  clip_rect_setter set_clip_rect(screen, &clip_rect);
1294 
1295  /*
1296  * Info regarding the rendering algorithm.
1297  *
1298  * In order to render a hex properly it needs to be rendered per row. On
1299  * this row several layers need to be drawn at the same time. Mainly the
1300  * unit and the background terrain. This is needed since both can spill
1301  * in the next hex. The foreground terrain needs to be drawn before to
1302  * avoid decapitation a unit.
1303  *
1304  * This ended in the following priority order:
1305  * layergroup > location > layer > 'blit_helper' > surface
1306  */
1307 
1308  for (const blit_helper &blit : drawing_buffer_) {
1309  for (const surface& surf : blit.surf()) {
1310  // Note that dstrect can be changed by sdl_blit
1311  // and so a new instance should be initialized
1312  // to pass to each call to sdl_blit.
1313  SDL_Rect dstrect {blit.x(), blit.y(), 0, 0};
1314  SDL_Rect srcrect = blit.clip();
1315  SDL_Rect *srcrectArg = (srcrect.x | srcrect.y | srcrect.w | srcrect.h)
1316  ? &srcrect : nullptr;
1317  sdl_blit(surf, srcrectArg, screen, &dstrect);
1318  //NOTE: the screen part should already be marked as 'to update'
1319  }
1320  }
1322 }
1323 
1325 {
1326  drawing_buffer_.clear();
1327 }
1328 
1330 {
1331  benchmark = !benchmark;
1332 }
1333 
1335 {
1336  debug_foreground = !debug_foreground;
1337 }
1338 
1340 {
1341  if(video().faked()) {
1342  return;
1343  }
1344 
1345  surface& frameBuffer = video().getSurface();
1346 
1347  font::draw_floating_labels(frameBuffer);
1349 
1350  video().flip();
1351 
1353  font::undraw_floating_labels(frameBuffer);
1354 }
1355 
1356 // frametime is in milliseconds
1357 static unsigned calculate_fps(unsigned frametime)
1358 {
1359  return frametime != 0u ? 1000u / frametime : 999u;
1360 }
1361 
1363 {
1364  if (screen_.update_locked()) {
1365  return;
1366  }
1367 
1368  if(preferences::show_fps() || benchmark) {
1369  static int frames = 0;
1370  ++frames;
1371  const int sample_freq = 10;
1372  if(frames == sample_freq) {
1373  const auto minmax_it = std::minmax_element(frametimes_.begin(), frametimes_.end());
1374  const unsigned render_avg = std::accumulate(frametimes_.begin(), frametimes_.end(), 0) / frametimes_.size();
1375  const int avg_fps = calculate_fps(render_avg);
1376  const int max_fps = calculate_fps(*minmax_it.first);
1377  const int min_fps = calculate_fps(*minmax_it.second);
1378  frames = 0;
1379 
1380  if(fps_handle_ != 0) {
1382  fps_handle_ = 0;
1383  }
1384  std::ostringstream stream;
1385  stream << "<tt> min/avg/max/act</tt>\n";
1386  stream << "<tt>FPS: " << std::setfill(' ') << std::setw(3) << min_fps << '/'<< std::setw(3) << avg_fps << '/' << std::setw(3) << max_fps << '/' << std::setw(3) << fps_actual_ << "</tt>\n";
1387  stream << "<tt>Time: " << std::setfill(' ') << std::setw(3) << *minmax_it.first << '/' << std::setw(3) << render_avg << '/' << std::setw(3) << *minmax_it.second << " ms</tt>\n";
1388  if (game_config::debug) {
1389  stream << "\nhex: " << drawn_hexes_*1.0/sample_freq;
1391  stream << " (" << (invalidated_hexes_-drawn_hexes_)*1.0/sample_freq << ")";
1392  }
1393  drawn_hexes_ = 0;
1394  invalidated_hexes_ = 0;
1395 
1396  font::floating_label flabel(stream.str());
1397  flabel.set_font_size(12);
1398  flabel.set_color(benchmark ? font::BAD_COLOR : font::NORMAL_COLOR);
1399  flabel.set_position(10, 100);
1400  flabel.set_alignment(font::LEFT_ALIGN);
1401 
1403  }
1404  } else if(fps_handle_ != 0) {
1406  fps_handle_ = 0;
1407  drawn_hexes_ = 0;
1408  invalidated_hexes_ = 0;
1409  }
1410 
1411  flip();
1412 }
1413 static void draw_panel(CVideo &video, const theme::panel& panel, std::vector<std::shared_ptr<gui::button>>& /*buttons*/)
1414 {
1415  //log_scope("draw panel");
1416  DBG_DP << "drawing panel " << panel.get_id() << "\n";
1417 
1418  surface surf(image::get_image(panel.image()));
1419 
1420  const SDL_Rect screen = video.screen_area();
1421  SDL_Rect& loc = panel.location(screen);
1422 
1423  DBG_DP << "panel location: x=" << loc.x << ", y=" << loc.y
1424  << ", w=" << loc.w << ", h=" << loc.h << "\n";
1425 
1426  if(surf) {
1427  if(surf->w != loc.w || surf->h != loc.h) {
1428  surf = tile_surface(surf,loc.w,loc.h);
1429  }
1430  video.blit_surface(loc.x, loc.y, surf);
1431  }
1432 }
1433 
1434 static void draw_label(CVideo& video, surface target, const theme::label& label)
1435 {
1436  //log_scope("draw label");
1437 
1438  const color_t& RGB = label.font_rgb();
1439 
1440  std::string c_start="<";
1441  std::string c_sep=",";
1442  std::string c_end=">";
1443  std::stringstream color;
1444  color<< c_start << RGB.r << c_sep << RGB.g << c_sep << RGB.b << c_end;
1445  std::string text = label.text();
1446 
1447  if(label.font_rgb_set()) {
1448  color<<text;
1449  text = color.str();
1450  }
1451  const std::string& icon = label.icon();
1452  SDL_Rect& loc = label.location(video.screen_area());
1453 
1454  if(icon.empty() == false) {
1455  surface surf(image::get_image(icon));
1456  if(surf) {
1457  if(surf->w > loc.w || surf->h > loc.h) {
1458  surf = scale_surface(surf,loc.w,loc.h);
1459  }
1460 
1461  sdl_blit(surf,nullptr,target,&loc);
1462  }
1463 
1464  if(text.empty() == false) {
1465  tooltips::add_tooltip(loc,text);
1466  }
1467  } else if(text.empty() == false) {
1468  font::draw_text(&video,loc,label.font_size(),font::NORMAL_COLOR,text,loc.x,loc.y);
1469  }
1470 
1471 }
1472 
1474 {
1475  surface& screen(screen_.getSurface());
1476 
1477  /*
1478  * The minimap is also a panel, force it to update its contents.
1479  * This is required when the size of the minimap has been modified.
1480  */
1482 
1483  for(const auto& panel : theme_.panels()) {
1484  draw_panel(video(), panel, menu_buttons_);
1485  }
1486 
1487  for(const auto& label : theme_.labels()) {
1488  draw_label(video(), screen, label);
1489  }
1490 
1491  render_buttons();
1492 }
1493 
1494 static void draw_background(surface screen, const SDL_Rect& area, const std::string& image)
1495 {
1496  // No background image, just fill in black.
1497  if(image.empty()) {
1498  sdl::fill_rectangle(area, color_t(0, 0, 0));
1499  return;
1500  }
1501 
1502  const surface background(image::get_image(image));
1503  if(!background) {
1504  return;
1505  }
1506 
1507  const unsigned int width = background->w;
1508  const unsigned int height = background->h;
1509 
1510  const unsigned int w_count = static_cast<int>(std::ceil(static_cast<double>(area.w) / static_cast<double>(width)));
1511  const unsigned int h_count = static_cast<int>(std::ceil(static_cast<double>(area.h) / static_cast<double>(height)));
1512 
1513  for(unsigned int w = 0, w_off = area.x; w < w_count; ++w, w_off += width) {
1514  for(unsigned int h = 0, h_off = area.y; h < h_count; ++h, h_off += height) {
1515  SDL_Rect clip = sdl::create_rect(w_off, h_off, 0, 0);
1516  sdl_blit(background, nullptr, screen, &clip);
1517  }
1518  }
1519 }
1520 
1522  const drawing_layer layer,
1523  const std::string& text,
1524  std::size_t font_size,
1525  color_t color,
1526  double x_in_hex,
1527  double y_in_hex)
1528 {
1529  if (text.empty()) return;
1530 
1531  const std::size_t font_sz = static_cast<std::size_t>(font_size * get_zoom_factor());
1532 
1533  surface text_surf = font::get_rendered_text(text, font_sz, color);
1534  surface back_surf = font::get_rendered_text(text, font_sz, font::BLACK_COLOR);
1535  const int x = get_location_x(loc) - text_surf->w/2
1536  + static_cast<int>(x_in_hex* hex_size());
1537  const int y = get_location_y(loc) - text_surf->h/2
1538  + static_cast<int>(y_in_hex* hex_size());
1539  for (int dy=-1; dy <= 1; ++dy) {
1540  for (int dx=-1; dx <= 1; ++dx) {
1541  if (dx!=0 || dy!=0) {
1542  drawing_buffer_add(layer, loc, x + dx, y + dy, back_surf);
1543  }
1544  }
1545  }
1546  drawing_buffer_add(layer, loc, x, y, text_surf);
1547 }
1548 
1549 //TODO: convert this to use sdl::ttexture
1551  const map_location& loc, surface image,
1552  bool hreverse, bool greyscale, fixed_t alpha,
1553  color_t blendto, double blend_ratio, double submerged, bool vreverse)
1554 {
1555  if (image==nullptr)
1556  return;
1557 
1558  SDL_Rect image_rect {x, y, image->w, image->h};
1559  SDL_Rect clip_rect = map_area();
1560  if (!sdl::rects_overlap(image_rect, clip_rect))
1561  return;
1562 
1563  surface surf(image);
1564 
1565  if(hreverse) {
1566  surf = image::reverse_image(surf);
1567  }
1568  if(vreverse) {
1569  surf = flop_surface(surf);
1570  }
1571 
1572  if(greyscale) {
1573  surf = greyscale_image(surf);
1574  }
1575 
1576  if(blend_ratio != 0) {
1577  surf = blend_surface(surf, blend_ratio, blendto);
1578  }
1579  if(alpha > ftofxp(1.0)) {
1580  surf = brighten_image(surf, alpha);
1581  //} else if(alpha != 1.0 && blendto != 0) {
1582  // surf.assign(blend_surface(surf,1.0-alpha,blendto));
1583  } else if(alpha != ftofxp(1.0)) {
1584  surf = surf.clone();
1585  adjust_surface_alpha(surf, alpha);
1586  }
1587 
1588  if(surf == nullptr) {
1589  ERR_DP << "surface lost..." << std::endl;
1590  return;
1591  }
1592 
1593  if(submerged > 0.0) {
1594  // divide the surface into 2 parts
1595  const int submerge_height = std::max<int>(0, surf->h*(1.0-submerged));
1596  const int depth = surf->h - submerge_height;
1597  SDL_Rect srcrect {0, 0, surf->w, submerge_height};
1598  drawing_buffer_add(drawing_layer, loc, x, y, surf, srcrect);
1599 
1600  if(submerge_height != surf->h) {
1601  //the lower part will be transparent
1602  float alpha_base = 0.3f; // 30% alpha at surface of water
1603  float alpha_delta = 0.015f; // lose 1.5% per pixel depth
1604  alpha_delta *= zoom_ / DefaultZoom; // adjust with zoom
1605  surf = submerge_alpha(surf, depth, alpha_base, alpha_delta);
1606 
1607  srcrect.y = submerge_height;
1608  srcrect.h = surf->h-submerge_height;
1609  y += submerge_height;
1610 
1611  drawing_buffer_add(drawing_layer, loc, x, y, surf, srcrect);
1612  }
1613  } else {
1614  // simple blit
1615  drawing_buffer_add(drawing_layer, loc, x, y, surf);
1616  }
1617 }
1619 {
1621  selectedHex_ = hex;
1624 }
1625 
1627 {
1629  mouseoverHex_ = hex;
1631 }
1632 
1633 void display::set_diagnostic(const std::string& msg)
1634 {
1635  if(diagnostic_label_ != 0) {
1637  diagnostic_label_ = 0;
1638  }
1639 
1640  if(!msg.empty()) {
1641  font::floating_label flabel(msg);
1643  flabel.set_color(font::YELLOW_COLOR);
1644  flabel.set_position(300, 50);
1645  flabel.set_clip_rect(map_outside_area());
1646 
1648  }
1649 }
1650 
1652 {
1653  if (get_map().empty()) {
1654  return;
1655  }
1656 
1657  if(benchmark) {
1658  invalidateAll_ = true;
1659  }
1660 
1661  if(!panelsDrawn_) {
1662  draw_all_panels();
1663  panelsDrawn_ = true;
1664  }
1665 
1666  if(redraw_background_) {
1667  // Full redraw of the background
1668  const SDL_Rect clip_rect = map_outside_area();
1669  const surface& screen = get_screen_surface();
1670  clip_rect_setter set_clip_rect(screen, &clip_rect);
1671  SDL_FillRect(screen, &clip_rect, 0x00000000);
1672  draw_background(screen, clip_rect, theme_.border().background_image);
1673  redraw_background_ = false;
1674 
1675  // Force a full map redraw
1676  invalidateAll_ = true;
1677  }
1678 
1679  if(invalidateAll_) {
1680  DBG_DP << "draw() with invalidateAll\n";
1681 
1682  // toggle invalidateAll_ first to allow regular invalidations
1683  invalidateAll_ = false;
1685 
1686  redrawMinimap_ = true;
1687  }
1688 }
1689 
1690 void display::draw_wrap(bool update, bool force)
1691 {
1692  static int time_between_draws = preferences::draw_delay();
1693  if(time_between_draws < 0) {
1694  time_between_draws = 1000 / screen_.current_refresh_rate();
1695  }
1696 
1697  if(redrawMinimap_) {
1698  redrawMinimap_ = false;
1699  draw_minimap();
1700  }
1701 
1702  if(update) {
1703  update_display();
1704 
1705  frametimes_.push_back(SDL_GetTicks() - last_frame_finished_);
1706  fps_counter_++;
1707  using std::chrono::duration_cast;
1708  using std::chrono::seconds;
1709  using std::chrono::steady_clock;
1710  const seconds current_second = duration_cast<seconds>(steady_clock::now().time_since_epoch());
1711  if(current_second != fps_start_) {
1712  fps_start_ = current_second;
1714  fps_counter_ = 0;
1715  }
1716  int longest_frame = *std::max_element(frametimes_.begin(), frametimes_.end());
1717  int wait_time = time_between_draws - longest_frame;
1718 
1719  if(!force && !benchmark && wait_time > 0) {
1720  // If it's not time yet to draw, delay until it is
1721  SDL_Delay(wait_time);
1722  }
1723 
1724  last_frame_finished_ = SDL_GetTicks();
1725  }
1726 }
1727 
1729 {
1730  for(auto i = action_buttons_.begin(); i != action_buttons_.end(); ++i) {
1731  if((*i)->pressed()) {
1732  const std::size_t index = std::distance(action_buttons_.begin(), i);
1733  if(index >= theme_.actions().size()) {
1734  assert(false);
1735  return nullptr;
1736  }
1737  return &theme_.actions()[index];
1738  }
1739  }
1740 
1741  return nullptr;
1742 }
1743 
1745 {
1746  for(auto i = menu_buttons_.begin(); i != menu_buttons_.end(); ++i) {
1747  if((*i)->pressed()) {
1748  const std::size_t index = std::distance(menu_buttons_.begin(), i);
1749  if(index >= theme_.menus().size()) {
1750  assert(false);
1751  return nullptr;
1752  }
1753  return theme_.get_menu_item((*i)->id());
1754  }
1755  }
1756 
1757  return nullptr;
1758 }
1759 
1760 void display::enable_menu(const std::string& item, bool enable)
1761 {
1762  for(auto menu = theme_.menus().begin(); menu != theme_.menus().end(); ++menu) {
1763 
1764  const auto hasitem = std::find_if(menu->items().begin(), menu->items().end(),
1765  [&item](const config& c) { return c["id"].str() == item; }
1766  );
1767 
1768  if(hasitem != menu->items().end()) {
1769  const std::size_t index = std::distance(theme_.menus().begin(), menu);
1770  if(index >= menu_buttons_.size()) {
1771  continue;
1772  }
1773  menu_buttons_[index]->enable(enable);
1774  }
1775  }
1776 }
1777 
1778 void display::announce(const std::string& message, const color_t& color, const announce_options& options)
1779 {
1780  if(options.discard_previous) {
1781  font::remove_floating_label(prevLabel);
1782  }
1783  font::floating_label flabel(message);
1785  flabel.set_color(color);
1787  map_outside_area().y + map_outside_area().h/3);
1788  flabel.set_lifetime(options.lifetime);
1789  flabel.set_clip_rect(map_outside_area());
1790 
1791  prevLabel = font::add_floating_label(flabel);
1792 }
1793 
1795 {
1796  const SDL_Rect& area = minimap_area();
1797 
1798  if(area.w == 0 || area.h == 0) {
1799  return;
1800  }
1801 
1802  if(minimap_ == nullptr || minimap_->w > area.w || minimap_->h > area.h) {
1803  minimap_ = image::getMinimap(area.w, area.h, get_map(),
1804  dc_->teams().empty() ? nullptr : &dc_->teams()[currentTeam_],
1805  (selectedHex_.valid() && !is_blindfolded()) ? &reach_map_ : nullptr);
1806  if(minimap_ == nullptr) {
1807  return;
1808  }
1809  }
1810 
1811  const surface& screen(screen_.getSurface());
1812  clip_rect_setter clip_setter(screen, &area);
1813 
1814  color_t back_color {31,31,23,SDL_ALPHA_OPAQUE};
1815  draw_centered_on_background(minimap_, area, back_color, screen);
1816 
1817  //update the minimap location for mouse and units functions
1818  minimap_location_.x = area.x + (area.w - minimap_->w) / 2;
1819  minimap_location_.y = area.y + (area.h - minimap_->h) / 2;
1820  minimap_location_.w = minimap_->w;
1821  minimap_location_.h = minimap_->h;
1822 
1824 
1825  // calculate the visible portion of the map:
1826  // scaling between minimap and full map images
1827  double xscaling = 1.0*minimap_->w / (get_map().w()*hex_width());
1828  double yscaling = 1.0*minimap_->h / (get_map().h()*hex_size());
1829 
1830  // we need to shift with the border size
1831  // and the 0.25 from the minimap balanced drawing
1832  // and the possible difference between real map and outside off-map
1833  SDL_Rect map_rect = map_area();
1834  SDL_Rect map_out_rect = map_outside_area();
1835  double border = theme_.border().size;
1836  double shift_x = - border*hex_width() - (map_out_rect.w - map_rect.w) / 2;
1837  double shift_y = - (border+0.25)*hex_size() - (map_out_rect.h - map_rect.h) / 2;
1838 
1839  int view_x = static_cast<int>((xpos_ + shift_x) * xscaling);
1840  int view_y = static_cast<int>((ypos_ + shift_y) * yscaling);
1841  int view_w = static_cast<int>(map_out_rect.w * xscaling);
1842  int view_h = static_cast<int>(map_out_rect.h * yscaling);
1843 
1844  SDL_Rect outline_rect {
1845  minimap_location_.x + view_x - 1,
1846  minimap_location_.y + view_y - 1,
1847  view_w + 2,
1848  view_h + 2
1849  };
1850 
1851  // SDL 2.0.10's render batching changes result in the
1852  // surface's clipping rectangle being overridden even if
1853  // no render clipping rectangle set operaton was queued,
1854  // so let's not use the render API to draw the rectangle.
1855 
1856  const SDL_Rect outline_parts[] = {
1857  // top
1858  { outline_rect.x, outline_rect.y, outline_rect.w, 1 },
1859  // bottom
1860  { outline_rect.x, outline_rect.y + outline_rect.h, outline_rect.w, 1 },
1861  // left
1862  { outline_rect.x, outline_rect.y, 1, outline_rect.h },
1863  // right
1864  { outline_rect.x + outline_rect.w - 1, outline_rect.y, 1, outline_rect.h },
1865  };
1866 
1867  for(const auto& r : outline_parts) {
1868  SDL_FillRect(screen_.getSurface(), &r, 0x00FFFFFF);
1869  }
1870 }
1871 
1873 {
1874  if (!preferences::minimap_draw_units() || is_blindfolded()) return;
1875 
1876  double xscaling = 1.0 * minimap_location_.w / get_map().w();
1877  double yscaling = 1.0 * minimap_location_.h / get_map().h();
1878 
1879  for(const auto& u : dc_->units()) {
1880  if (fogged(u.get_location()) ||
1881  (dc_->teams()[currentTeam_].is_enemy(u.side()) &&
1882  u.invisible(u.get_location())) ||
1883  u.get_hidden()) {
1884  continue;
1885  }
1886 
1887  int side = u.side();
1888  color_t col = team::get_minimap_color(side);
1889 
1891  auto status = orb_status::allied;
1892  if(dc_->teams()[currentTeam_].is_enemy(side)) {
1893  status = orb_status::enemy;
1894  } else if(currentTeam_ + 1 == static_cast<unsigned>(side)) {
1895  status = dc_->unit_orb_status(u);
1896  } else {
1897  // no-op, status is already set to orb_status::allied;
1898  }
1900  }
1901 
1902  double u_x = u.get_location().x * xscaling;
1903  double u_y = (u.get_location().y + (is_odd(u.get_location().x) ? 1 : -1)/4.0) * yscaling;
1904  // use 4/3 to compensate the horizontal hexes imbrication
1905  double u_w = 4.0 / 3.0 * xscaling;
1906  double u_h = yscaling;
1907 
1908  SDL_Rect r {
1909  minimap_location_.x + int(std::round(u_x))
1910  , minimap_location_.y + int(std::round(u_y))
1911  , int(std::round(u_w))
1912  , int(std::round(u_h))
1913  };
1914 
1915  // SDL 2.0.10's render batching changes result in the
1916  // surface's clipping rectangle being overridden even if
1917  // no render clipping rectangle set operaton was queued,
1918  // so let's not use the render API to draw the rectangle.
1919 
1920  SDL_FillRect(screen_.getSurface(), &r, col.to_argb_bytes());
1921  }
1922 }
1923 
1924 bool display::scroll(int xmove, int ymove, bool force)
1925 {
1926  if(view_locked_ && !force) {
1927  return false;
1928  }
1929 
1930  // No move offset, do nothing.
1931  if(xmove == 0 && ymove == 0) {
1932  return false;
1933  }
1934 
1935  int new_x = xpos_ + xmove;
1936  int new_y = ypos_ + ymove;
1937 
1938  bounds_check_position(new_x, new_y);
1939 
1940  // Camera position doesn't change, exit.
1941  if(xpos_ == new_x && ypos_ == new_y) {
1942  return false;
1943  }
1944 
1945  const int diff_x = xpos_ - new_x;
1946  const int diff_y = ypos_ - new_y;
1947 
1948  xpos_ = new_x;
1949  ypos_ = new_y;
1950 
1951  /* Adjust floating label positions. This only affects labels whose position is anchored
1952  * to the map instead of the screen. In order to do that, we want to adjust their drawing
1953  * coordinates in the opposite direction of the screen scroll.
1954  *
1955  * The check a few lines up prevents any scrolling from happening if the camera position
1956  * doesn't change. Without that, the label still scroll even when the map edge is reached.
1957  * If that's removed, the following formula should work instead:
1958  *
1959  * const int label_[x,y]_adjust = [x,y]pos_ - new_[x,y];
1960  */
1961  font::scroll_floating_labels(diff_x, diff_y);
1962 
1964 
1965  //
1966  // NOTE: the next three blocks can be removed once we switch to accelerated rendering.
1967  //
1968 
1969  if(!screen_.update_locked()) {
1970  surface& screen(screen_.getSurface());
1971 
1972  SDL_Rect dstrect = map_area();
1973  dstrect.x += diff_x;
1974  dstrect.y += diff_y;
1975  dstrect = sdl::intersect_rects(dstrect, map_area());
1976 
1977  SDL_Rect srcrect = dstrect;
1978  srcrect.x -= diff_x;
1979  srcrect.y -= diff_y;
1980 
1981  // This is a workaround for a SDL2 bug when blitting on overlapping surfaces. The bug
1982  // only strikes during scrolling, but will then duplicate textures across the entire map.
1983  surface screen_copy = screen.clone();
1984 
1985  SDL_SetSurfaceBlendMode(screen_copy, SDL_BLENDMODE_NONE);
1986  SDL_BlitSurface(screen_copy, &srcrect, screen, &dstrect);
1987  }
1988 
1989  if(diff_y != 0) {
1990  SDL_Rect r = map_area();
1991 
1992  if(diff_y < 0) {
1993  r.y = r.y + r.h + diff_y;
1994  }
1995 
1996  r.h = std::abs(diff_y);
1998  }
1999 
2000  if(diff_x != 0) {
2001  SDL_Rect r = map_area();
2002 
2003  if(diff_x < 0) {
2004  r.x = r.x + r.w + diff_x;
2005  }
2006 
2007  r.w = std::abs(diff_x);
2009  }
2010 
2012 
2013  redrawMinimap_ = true;
2014 
2015  return true;
2016 }
2017 
2019 {
2020  return zoom_ == MaxZoom;
2021 }
2022 
2024 {
2025  return zoom_ == MinZoom;
2026 }
2027 
2028 bool display::set_zoom(bool increase)
2029 {
2030  // Ensure we don't try to access nonexistent vector indices.
2031  zoom_index_ = std::clamp(increase ? zoom_index_ + 1 : zoom_index_ - 1, 0, final_zoom_index);
2032 
2033  // No validation check is needed in the next step since we've already set the index here and
2034  // know the new zoom value is indeed valid.
2035  return set_zoom(zoom_levels[zoom_index_], false);
2036 }
2037 
2038 bool display::set_zoom(unsigned int amount, const bool validate_value_and_set_index)
2039 {
2040  unsigned int new_zoom = std::clamp(amount, MinZoom, MaxZoom);
2041 
2042  LOG_DP << "new_zoom = " << new_zoom << std::endl;
2043 
2044  if(new_zoom == zoom_) {
2045  return false;
2046  }
2047 
2048  if(validate_value_and_set_index) {
2049  zoom_index_ = get_zoom_levels_index (new_zoom);
2050  new_zoom = zoom_levels[zoom_index_];
2051  }
2052 
2053  const SDL_Rect& outside_area = map_outside_area();
2054  const SDL_Rect& area = map_area();
2055 
2056  // Turn the zoom factor to a double in order to avoid rounding errors.
2057  double zoom_factor = static_cast<double>(new_zoom) / static_cast<double>(zoom_);
2058 
2059  // INVARIANT: xpos_ + area.w == xend where xend is as in bounds_check_position()
2060  //
2061  // xpos_: Position of the leftmost visible map pixel of the viewport, in pixels.
2062  // Affected by the current zoom: this->zoom_ pixels to the hex.
2063  //
2064  // xpos_ + area.w/2: Position of the center of the viewport, in pixels.
2065  //
2066  // (xpos_ + area.w/2) * new_zoom/zoom_: Position of the center of the
2067  // viewport, as it would be under new_zoom.
2068  //
2069  // (xpos_ + area.w/2) * new_zoom/zoom_ - area.w/2: Position of the
2070  // leftmost visible map pixel, as it would be under new_zoom.
2071  xpos_ = std::round(((xpos_ + area.w / 2) * zoom_factor) - (area.w / 2));
2072  ypos_ = std::round(((ypos_ + area.h / 2) * zoom_factor) - (area.h / 2));
2073  xpos_ -= (outside_area.w - area.w) / 2;
2074  ypos_ -= (outside_area.h - area.h) / 2;
2075 
2076  zoom_ = new_zoom;
2078  if(zoom_ != DefaultZoom) {
2079  last_zoom_ = zoom_;
2080  }
2081 
2084 
2086  redraw_background_ = true;
2087  invalidate_all();
2088 
2089  // Forces a redraw after zooming.
2090  // This prevents some graphic glitches from occurring.
2091  draw();
2092 
2093  return true;
2094 }
2095 
2097 {
2098  if (zoom_ != DefaultZoom) {
2099  last_zoom_ = zoom_;
2101  } else {
2102  // When we are already at the default zoom,
2103  // switch to the last zoom used
2105  }
2106 }
2107 
2109 {
2110  int x = get_location_x(loc);
2111  int y = get_location_y(loc);
2112  return !outside_area(map_area(), x, y);
2113 }
2114 
2116 {
2117  int x = get_location_x(loc);
2118  int y = get_location_y(loc);
2119  const SDL_Rect &area = map_area();
2120  int hw = hex_width(), hs = hex_size();
2121  return x + hs >= area.x - hw && x < area.x + area.w + hw &&
2122  y + hs >= area.y - hs && y < area.y + area.h + hs;
2123 }
2124 
2125 void display::scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type, bool force)
2126 {
2127  if(!force && (view_locked_ || !preferences::scroll_to_action())) return;
2128  if(screen_.update_locked()) {
2129  return;
2130  }
2131  const SDL_Rect area = map_area();
2132  const int xmove_expected = screenxpos - (area.x + area.w/2);
2133  const int ymove_expected = screenypos - (area.y + area.h/2);
2134 
2135  int xpos = xpos_ + xmove_expected;
2136  int ypos = ypos_ + ymove_expected;
2137  bounds_check_position(xpos, ypos);
2138  int xmove = xpos - xpos_;
2139  int ymove = ypos - ypos_;
2140 
2141  if(scroll_type == WARP || scroll_type == ONSCREEN_WARP || turbo_speed() > 2.0 || preferences::scroll_speed() > 99) {
2142  scroll(xmove,ymove,true);
2143  draw();
2144  return;
2145  }
2146 
2147  // Doing an animated scroll, with acceleration etc.
2148 
2149  int x_old = 0;
2150  int y_old = 0;
2151 
2152  const double dist_total = std::hypot(xmove, ymove);
2153  double dist_moved = 0.0;
2154 
2155  int t_prev = SDL_GetTicks();
2156 
2157  double velocity = 0.0;
2158  while (dist_moved < dist_total) {
2159  events::pump();
2160 
2161  int t = SDL_GetTicks();
2162  double dt = (t - t_prev) / 1000.0;
2163  if (dt > 0.200) {
2164  // Do not skip too many frames on slow PCs
2165  dt = 0.200;
2166  }
2167  t_prev = t;
2168 
2169  const double accel_time = 0.3 / turbo_speed(); // seconds until full speed is reached
2170  const double decel_time = 0.4 / turbo_speed(); // seconds from full speed to stop
2171 
2172  double velocity_max = preferences::scroll_speed() * 60.0;
2173  velocity_max *= turbo_speed();
2174  double accel = velocity_max / accel_time;
2175  double decel = velocity_max / decel_time;
2176 
2177  // If we started to decelerate now, where would we stop?
2178  double stop_time = velocity / decel;
2179  double dist_stop = dist_moved + velocity*stop_time - 0.5*decel*stop_time*stop_time;
2180  if (dist_stop > dist_total || velocity > velocity_max) {
2181  velocity -= decel * dt;
2182  if (velocity < 1.0) velocity = 1.0;
2183  } else {
2184  velocity += accel * dt;
2185  if (velocity > velocity_max) velocity = velocity_max;
2186  }
2187 
2188  dist_moved += velocity * dt;
2189  if (dist_moved > dist_total) dist_moved = dist_total;
2190 
2191  int x_new = std::round(xmove * dist_moved / dist_total);
2192  int y_new = std::round(ymove * dist_moved / dist_total);
2193 
2194  int dx = x_new - x_old;
2195  int dy = y_new - y_old;
2196 
2197  scroll(dx,dy,true);
2198  x_old += dx;
2199  y_old += dy;
2200  draw();
2201  }
2202 }
2203 
2204 void display::scroll_to_tile(const map_location& loc, SCROLL_TYPE scroll_type, bool check_fogged, bool force)
2205 {
2206  if(get_map().on_board(loc) == false) {
2207  ERR_DP << "Tile at " << loc << " isn't on the map, can't scroll to the tile." << std::endl;
2208  return;
2209  }
2210 
2211  std::vector<map_location> locs;
2212  locs.push_back(loc);
2213  scroll_to_tiles(locs, scroll_type, check_fogged,false,0.0,force);
2214 }
2215 
2217  SCROLL_TYPE scroll_type, bool check_fogged,
2218  double add_spacing, bool force)
2219 {
2220  std::vector<map_location> locs;
2221  locs.push_back(loc1);
2222  locs.push_back(loc2);
2223  scroll_to_tiles(locs, scroll_type, check_fogged, false, add_spacing,force);
2224 }
2225 
2226 void display::scroll_to_tiles(const std::vector<map_location>::const_iterator & begin,
2227  const std::vector<map_location>::const_iterator & end,
2228  SCROLL_TYPE scroll_type, bool check_fogged,
2229  bool only_if_possible, double add_spacing, bool force)
2230 {
2231  // basically we calculate the min/max coordinates we want to have on-screen
2232  int minx = 0;
2233  int maxx = 0;
2234  int miny = 0;
2235  int maxy = 0;
2236  bool valid = false;
2237 
2238  for(std::vector<map_location>::const_iterator itor = begin; itor != end ; ++itor) {
2239  if(get_map().on_board(*itor) == false) continue;
2240  if(check_fogged && fogged(*itor)) continue;
2241 
2242  int x = get_location_x(*itor);
2243  int y = get_location_y(*itor);
2244 
2245  if (!valid) {
2246  minx = x;
2247  maxx = x;
2248  miny = y;
2249  maxy = y;
2250  valid = true;
2251  } else {
2252  int minx_new = std::min<int>(minx,x);
2253  int miny_new = std::min<int>(miny,y);
2254  int maxx_new = std::max<int>(maxx,x);
2255  int maxy_new = std::max<int>(maxy,y);
2256  SDL_Rect r = map_area();
2257  r.x = minx_new;
2258  r.y = miny_new;
2259  if(outside_area(r, maxx_new, maxy_new)) {
2260  // we cannot fit all locations to the screen
2261  if (only_if_possible) return;
2262  break;
2263  }
2264  minx = minx_new;
2265  miny = miny_new;
2266  maxx = maxx_new;
2267  maxy = maxy_new;
2268  }
2269  }
2270  //if everything is fogged or the location list is empty
2271  if(!valid) return;
2272 
2273  if (scroll_type == ONSCREEN || scroll_type == ONSCREEN_WARP) {
2274  SDL_Rect r = map_area();
2275  int spacing = std::round(add_spacing * hex_size());
2276  r.x += spacing;
2277  r.y += spacing;
2278  r.w -= 2*spacing;
2279  r.h -= 2*spacing;
2280  if (!outside_area(r, minx,miny) && !outside_area(r, maxx,maxy)) {
2281  return;
2282  }
2283  }
2284 
2285  // let's do "normal" rectangle math from now on
2286  SDL_Rect locs_bbox;
2287  locs_bbox.x = minx;
2288  locs_bbox.y = miny;
2289  locs_bbox.w = maxx - minx + hex_size();
2290  locs_bbox.h = maxy - miny + hex_size();
2291 
2292  // target the center
2293  int target_x = locs_bbox.x + locs_bbox.w/2;
2294  int target_y = locs_bbox.y + locs_bbox.h/2;
2295 
2296  if (scroll_type == ONSCREEN || scroll_type == ONSCREEN_WARP) {
2297  // when doing an ONSCREEN scroll we do not center the target unless needed
2298  SDL_Rect r = map_area();
2299  int map_center_x = r.x + r.w/2;
2300  int map_center_y = r.y + r.h/2;
2301 
2302  int h = r.h;
2303  int w = r.w;
2304 
2305  // we do not want to be only inside the screen rect, but center a bit more
2306  double inside_frac = 0.5; // 0.0 = always center the target, 1.0 = scroll the minimum distance
2307  w = static_cast<int>(w * inside_frac);
2308  h = static_cast<int>(h * inside_frac);
2309 
2310  // shrink the rectangle by the size of the locations rectangle we found
2311  // such that the new task to fit a point into a rectangle instead of rectangle into rectangle
2312  w -= locs_bbox.w;
2313  h -= locs_bbox.h;
2314 
2315  if (w < 1) w = 1;
2316  if (h < 1) h = 1;
2317 
2318  r.x = target_x - w/2;
2319  r.y = target_y - h/2;
2320  r.w = w;
2321  r.h = h;
2322 
2323  // now any point within r is a possible target to scroll to
2324  // we take the one with the minimum distance to map_center
2325  // which will always be at the border of r
2326 
2327  if (map_center_x < r.x) {
2328  target_x = r.x;
2329  target_y = map_center_y;
2330  if (target_y < r.y) target_y = r.y;
2331  if (target_y > r.y+r.h-1) target_y = r.y+r.h-1;
2332  } else if (map_center_x > r.x+r.w-1) {
2333  target_x = r.x+r.w-1;
2334  target_y = map_center_y;
2335  if (target_y < r.y) target_y = r.y;
2336  if (target_y >= r.y+r.h) target_y = r.y+r.h-1;
2337  } else if (map_center_y < r.y) {
2338  target_y = r.y;
2339  target_x = map_center_x;
2340  if (target_x < r.x) target_x = r.x;
2341  if (target_x > r.x+r.w-1) target_x = r.x+r.w-1;
2342  } else if (map_center_y > r.y+r.h-1) {
2343  target_y = r.y+r.h-1;
2344  target_x = map_center_x;
2345  if (target_x < r.x) target_x = r.x;
2346  if (target_x > r.x+r.w-1) target_x = r.x+r.w-1;
2347  } else {
2348  ERR_DP << "Bug in the scrolling code? Looks like we would not need to scroll after all..." << std::endl;
2349  // keep the target at the center
2350  }
2351  }
2352 
2353  scroll_to_xy(target_x, target_y,scroll_type,force);
2354 }
2355 
2356 
2358 {
2359  const unsigned int orig_zoom = zoom_;
2360 
2361  if(zoom_ < MinZoom) {
2362  zoom_ = MinZoom;
2363  }
2364 
2365  if(zoom_ > MaxZoom) {
2366  zoom_ = MaxZoom;
2367  }
2368 
2370 
2371  if(zoom_ != orig_zoom) {
2373  }
2374 }
2375 
2376 void display::bounds_check_position(int& xpos, int& ypos) const
2377 {
2378  const int tile_width = hex_width();
2379 
2380  // Adjust for the border 2 times
2381  const int xend = static_cast<int>(tile_width * (get_map().w() + 2 * theme_.border().size) + tile_width/3);
2382  const int yend = static_cast<int>(zoom_ * (get_map().h() + 2 * theme_.border().size) + zoom_/2);
2383 
2384  if(xpos > xend - map_area().w) {
2385  xpos = xend - map_area().w;
2386  }
2387 
2388  if(ypos > yend - map_area().h) {
2389  ypos = yend - map_area().h;
2390  }
2391 
2392  if(xpos < 0) {
2393  xpos = 0;
2394  }
2395 
2396  if(ypos < 0) {
2397  ypos = 0;
2398  }
2399 }
2400 
2401 double display::turbo_speed() const
2402 {
2403  bool res = turbo_;
2404  if(keys_[SDLK_LSHIFT] || keys_[SDLK_RSHIFT]) {
2405  res = !res;
2406  }
2407 
2408  res |= screen_.faked();
2409  if (res)
2410  return turbo_speed_;
2411  else
2412  return 1.0;
2413 }
2414 
2416 {
2417  idle_anim_rate_ = std::pow(2.0, -rate/10.0);
2418 }
2419 
2421 {
2422  if(screen_.update_locked())
2423  return;
2424 
2425  invalidateGameStatus_ = true;
2426 
2427  reportRects_.clear();
2428  reportSurfaces_.clear();
2429  reports_.clear();
2430 
2432 
2434 
2436 
2437  if(!menu_buttons_.empty() || !action_buttons_.empty()) {
2438  create_buttons();
2439  }
2440 
2441  if(resources::controller) {
2443  if(command_executor != nullptr) {
2444  // This function adds button overlays,
2445  // it needs to be run after recreating the buttons.
2446  command_executor->set_button_state();
2447  }
2448  }
2449 
2450  panelsDrawn_ = false;
2451  if (!gui::in_dialog()) {
2453  }
2454 
2455  redraw_background_ = true;
2456 
2457  for(std::function<void(display&)> f : redraw_observers_) {
2458  f(*this);
2459  }
2460 
2461  int ticks1 = SDL_GetTicks();
2462  invalidate_all();
2463  int ticks2 = SDL_GetTicks();
2464  draw(true,true);
2465  int ticks3 = SDL_GetTicks();
2466  LOG_DP << "invalidate and draw: " << (ticks3 - ticks2) << " and " << (ticks2 - ticks1) << "\n";
2467 }
2468 
2469 void display::add_redraw_observer(std::function<void(display&)> f)
2470 {
2471  redraw_observers_.push_back(f);
2472 }
2473 
2475 {
2476  redraw_observers_.clear();
2477 }
2478 
2480  draw(true, false);
2481 }
2482 
2483 void display::draw(bool update) {
2484  draw(update, false);
2485 }
2486 
2487 
2488 void display::draw(bool update,bool force) {
2489 // log_scope("display::draw");
2490 
2491  if (screen_.update_locked()) {
2492  return;
2493  }
2494 
2495  if (dirty_) {
2496  flip_locker flip_lock(screen_);
2497  dirty_ = false;
2499  return;
2500  }
2501 
2502  // Trigger cache rebuild when preference gets changed
2505  builder_->rebuild_cache_all();
2506  }
2507 
2509 
2510  draw_init();
2511  pre_draw();
2512  // invalidate all that needs to be invalidated
2514 
2515  if(!get_map().empty()) {
2516  //int simulate_delay = 0;
2517 
2518  /*
2519  * draw_invalidated() also invalidates the halos, so also needs to be
2520  * ran if invalidated_.empty() == true.
2521  */
2522  if(!invalidated_.empty()) {
2523  draw_invalidated();
2524  invalidated_.clear();
2525  }
2527  post_commit();
2528  draw_sidebar();
2529 
2530  // Simulate slow PC:
2531  //SDL_Delay(2*simulate_delay + rand() % 20);
2532  }
2533  draw_wrap(update, force);
2534  post_draw();
2535 }
2536 
2538 {
2539  return *map_labels_;
2540 }
2541 
2543 {
2544  return *map_labels_;
2545 }
2546 
2547 const SDL_Rect& display::get_clip_rect()
2548 {
2549  return map_area();
2550 }
2551 
2553 // log_scope("display::draw_invalidated");
2554  SDL_Rect clip_rect = get_clip_rect();
2555  surface& screen = get_screen_surface();
2556  clip_rect_setter set_clip_rect(screen, &clip_rect);
2557  for (const map_location& loc : invalidated_) {
2558  int xpos = get_location_x(loc);
2559  int ypos = get_location_y(loc);
2560 
2561  //const bool on_map = get_map().on_board(loc);
2562  SDL_Rect hex_rect = sdl::create_rect(xpos, ypos, zoom_, zoom_);
2563  if(!sdl::rects_overlap(hex_rect,clip_rect)) {
2564  continue;
2565  }
2566  draw_hex(loc);
2567  drawn_hexes_+=1;
2568  }
2569  invalidated_hexes_ += invalidated_.size();
2570 
2571  if (dc_->teams().empty())
2572  {
2573  // The unit drawer can't function without teams
2574  return;
2575  }
2576 
2577  unit_drawer drawer = unit_drawer(*this);
2578 
2579  for (const map_location& loc : invalidated_) {
2580  unit_map::const_iterator u_it = dc_->units().find(loc);
2582  if (u_it != dc_->units().end()
2583  && (request == exclusive_unit_draw_requests_.end() || request->second == u_it->id()))
2584  drawer.redraw_unit(*u_it);
2585  }
2586 
2587 }
2588 
2590  int xpos = get_location_x(loc);
2591  int ypos = get_location_y(loc);
2592  image::TYPE image_type = get_image_type(loc);
2593  const bool on_map = get_map().on_board(loc);
2594  const time_of_day& tod = get_time_of_day(loc);
2595 
2596  int num_images_fg = 0;
2597  int num_images_bg = 0;
2598 
2599  if(!shrouded(loc)) {
2600  // unshrouded terrain (the normal case)
2601  get_terrain_images(loc, tod.id, BACKGROUND); // updates terrain_image_vector_
2603  num_images_bg = terrain_image_vector_.size();
2604 
2605  get_terrain_images(loc, tod.id, FOREGROUND); // updates terrain_image_vector_
2607  num_images_fg = terrain_image_vector_.size();
2608 
2609  // Draw the grid, if that's been enabled
2610  if(grid_) {
2612  drawing_buffer_add(LAYER_GRID_TOP, loc, xpos, ypos,
2615  drawing_buffer_add(LAYER_GRID_BOTTOM, loc, xpos, ypos,
2616  image::get_image(grid_bottom, image::TOD_COLORED));
2617  }
2618  }
2619 
2620  if(!shrouded(loc)) {
2621  auto it = get_overlays().find(loc);
2622  if(it != get_overlays().end()) {
2623  std::vector<overlay>& overlays = it->second;
2624  if(overlays.size() != 0) {
2625  tod_color tod_col = tod.color + color_adjust_;
2626  image::light_string lt = image::get_light_string(-1, tod_col.r, tod_col.g, tod_col.b);
2627 
2628  for(const overlay& ov : overlays) {
2629  bool item_visible_for_team = true;
2630  if(dont_show_all_ && !ov.team_name.empty()) {
2631  //dont_show_all_ imples that viewing_team()is a valid index to get_teams()
2632  const std::string& current_team_name = get_teams()[viewing_team()].team_name();
2633  const std::vector<std::string>& current_team_names = utils::split(current_team_name);
2634  const std::vector<std::string>& team_names = utils::split(ov.team_name);
2635 
2636  item_visible_for_team = std::find_first_of(team_names.begin(), team_names.end(),
2637  current_team_names.begin(), current_team_names.end()) != team_names.end();
2638  }
2639  if(item_visible_for_team && !(fogged(loc) && !ov.visible_in_fog))
2640  {
2641  const surface surf = ov.image.find("~NO_TOD_SHIFT()") == std::string::npos ?
2643  drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, surf);
2644  }
2645  }
2646  }
2647  }
2648  }
2649 
2650  if(!shrouded(loc)) {
2651  // village-control flags.
2652  drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, get_flag(loc));
2653  }
2654 
2655  // Draw the time-of-day mask on top of the terrain in the hex.
2656  // tod may differ from tod if hex is illuminated.
2657  const std::string& tod_hex_mask = tod.image_mask;
2658  if(tod_hex_mask1 != nullptr || tod_hex_mask2 != nullptr) {
2661  } else if(!tod_hex_mask.empty()) {
2662  drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos,
2663  image::get_image(tod_hex_mask,image::SCALED_TO_HEX));
2664  }
2665 
2666  // Paint mouseover overlays
2667  if(loc == mouseoverHex_ && (on_map || (in_editor() && get_map().on_board_with_border(loc)))
2668  && mouseover_hex_overlay_ != nullptr) {
2670  }
2671 
2672  // Paint arrows
2673  arrows_map_t::const_iterator arrows_in_hex = arrows_map_.find(loc);
2674  if(arrows_in_hex != arrows_map_.end()) {
2675  for (arrow* const a : arrows_in_hex->second) {
2676  a->draw_hex(loc);
2677  }
2678  }
2679 
2680  // Apply shroud, fog and linger overlay
2681 
2682  if(shrouded(loc)) {
2683  // We apply void also on off-map tiles
2684  // to shroud the half-hexes too
2685  const std::string& shroud_image = get_variant(shroud_images_, loc);
2686  drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
2687  image::get_image(shroud_image, image_type));
2688  } else if(fogged(loc)) {
2689  const std::string& fog_image = get_variant(fog_images_, loc);
2690  drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
2691  image::get_image(fog_image, image_type));
2692  }
2693 
2694  if(!shrouded(loc)) {
2695  drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos, get_fog_shroud_images(loc, image_type));
2696  }
2697 
2698  if (on_map) {
2699  if (draw_coordinates_) {
2700  int off_x = xpos + hex_size()/2;
2701  int off_y = ypos + hex_size()/2;
2702  surface text = font::get_rendered_text(lexical_cast<std::string>(loc), font::SIZE_SMALL, font::NORMAL_COLOR);
2703  surface bg(text->w, text->h);
2704  SDL_Rect bg_rect {0, 0, text->w, text->h};
2705  sdl::fill_surface_rect(bg, &bg_rect, 0xaa000000);
2706  off_x -= text->w / 2;
2707  off_y -= text->h / 2;
2708  if (draw_terrain_codes_) {
2709  off_y -= text->h / 2;
2710  }
2711  if (draw_num_of_bitmaps_) {
2712  off_y -= text->h / 2;
2713  }
2714  drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, bg);
2715  drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, text);
2716  }
2717  if (draw_terrain_codes_ && (game_config::debug || !shrouded(loc))) {
2718  int off_x = xpos + hex_size()/2;
2719  int off_y = ypos + hex_size()/2;
2720  surface text = font::get_rendered_text(lexical_cast<std::string>(get_map().get_terrain(loc)), font::SIZE_SMALL, font::NORMAL_COLOR);
2721  surface bg(text->w, text->h);
2722  SDL_Rect bg_rect {0, 0, text->w, text->h};
2723  sdl::fill_surface_rect(bg, &bg_rect, 0xaa000000);
2724  off_x -= text->w / 2;
2725  off_y -= text->h / 2;
2727  off_y += text->h / 2;
2728  } else if (draw_num_of_bitmaps_ && !draw_coordinates_) {
2729  off_y -= text->h / 2;
2730  }
2731  drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, bg);
2732  drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, text);
2733  }
2734  if (draw_num_of_bitmaps_) {
2735  int off_x = xpos + hex_size()/2;
2736  int off_y = ypos + hex_size()/2;
2737  surface text = font::get_rendered_text(std::to_string(num_images_bg + num_images_fg), font::SIZE_SMALL, font::NORMAL_COLOR);
2738  surface bg(text->w, text->h);
2739  SDL_Rect bg_rect {0, 0, text->w, text->h};
2740  sdl::fill_surface_rect(bg, &bg_rect, 0xaa000000);
2741  off_x -= text->w / 2;
2742  off_y -= text->h / 2;
2743  if (draw_coordinates_) {
2744  off_y += text->h / 2;
2745  }
2746  if (draw_terrain_codes_) {
2747  off_y += text->h / 2;
2748  }
2749  drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, bg);
2750  drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, text);
2751  }
2752  }
2753 
2754  if(debug_foreground) {
2755  drawing_buffer_add(LAYER_UNIT_DEFAULT, loc, xpos, ypos,
2756  image::get_image("terrain/foreground.png", image_type));
2757  }
2758 
2759 }
2760 
2762  return image::TOD_COLORED;
2763 }
2764 
2765 /*void display::draw_sidebar() {
2766 
2767 }*/
2768 
2769 void display::draw_image_for_report(surface& img, SDL_Rect& rect)
2770 {
2771  SDL_Rect visible_area = get_non_transparent_portion(img);
2772  SDL_Rect target = rect;
2773  if(visible_area.x != 0 || visible_area.y != 0 || visible_area.w != img->w || visible_area.h != img->h) {
2774  if(visible_area.w == 0 || visible_area.h == 0) {
2775  return;
2776  }
2777 
2778  if(visible_area.w > rect.w || visible_area.h > rect.h) {
2779  img = get_surface_portion(img,visible_area);
2780  img = scale_surface(img,rect.w,rect.h);
2781  visible_area.x = 0;
2782  visible_area.y = 0;
2783  visible_area.w = img->w;
2784  visible_area.h = img->h;
2785  } else {
2786  target.x = rect.x + (rect.w - visible_area.w)/2;
2787  target.y = rect.y + (rect.h - visible_area.h)/2;
2788  target.w = visible_area.w;
2789  target.h = visible_area.h;
2790  }
2791 
2792  sdl_blit(img,&visible_area,screen_.getSurface(),&target);
2793  } else {
2794  if(img->w != rect.w || img->h != rect.h) {
2795  img = scale_surface(img,rect.w,rect.h);
2796  }
2797 
2798  sdl_blit(img,nullptr,screen_.getSurface(),&target);
2799  }
2800 }
2801 
2802 /**
2803  * Redraws the specified report (if anything has changed).
2804  * If a config is not supplied, it will be generated via
2805  * reports::generate_report().
2806  */
2807 void display::refresh_report(const std::string& report_name, const config * new_cfg)
2808 {
2809  const theme::status_item *item = theme_.get_status_item(report_name);
2810  if (!item) {
2811  reportSurfaces_[report_name] = nullptr;
2812  return;
2813  }
2814 
2815  // Now we will need the config. Generate one if needed.
2816 
2817  boost::optional <events::mouse_handler &> mhb = boost::none;
2818 
2819  if (resources::controller) {
2821  }
2822 
2823  reports::context temp_context = reports::context(*dc_, *this, *resources::tod_manager, wb_.lock(), mhb);
2824 
2825  const config generated_cfg = new_cfg ? config() : reports_object_->generate_report(report_name, temp_context);
2826  if ( new_cfg == nullptr )
2827  new_cfg = &generated_cfg;
2828 
2829  SDL_Rect &rect = reportRects_[report_name];
2830  const SDL_Rect &new_rect = item->location(screen_.screen_area());
2831  surface &surf = reportSurfaces_[report_name];
2832  config &report = reports_[report_name];
2833 
2834  // Report and its location is unchanged since last time. Do nothing.
2835  if (surf && rect == new_rect && report == *new_cfg) {
2836  return;
2837  }
2838 
2839  // Update the config in reports_.
2840  report = *new_cfg;
2841 
2842  if (surf) {
2843  sdl_blit(surf, nullptr, screen_.getSurface(), &rect);
2844  }
2845 
2846  // If the rectangle has just changed, assign the surface to it
2847  if (!surf || new_rect != rect)
2848  {
2849  surf = nullptr;
2850  rect = new_rect;
2851 
2852  // If the rectangle is present, and we are blitting text,
2853  // then we need to backup the surface.
2854  // (Images generally won't need backing up,
2855  // unless they are transparent, but that is done later).
2856  if (rect.w > 0 && rect.h > 0) {
2857  surf = get_surface_portion(screen_.getSurface(), rect);
2858  if (reportSurfaces_[report_name] == nullptr) {
2859  ERR_DP << "Could not backup background for report!" << std::endl;
2860  }
2861  }
2862  }
2863 
2865 
2866  if (report.empty()) return;
2867 
2868  int x = rect.x, y = rect.y;
2869 
2870  // Add prefix, postfix elements.
2871  // Make sure that they get the same tooltip
2872  // as the guys around them.
2873  std::string str = item->prefix();
2874  if (!str.empty()) {
2875  config &e = report.add_child_at("element", config(), 0);
2876  e["text"] = str;
2877  e["tooltip"] = report.child("element")["tooltip"];
2878  }
2879  str = item->postfix();
2880  if (!str.empty()) {
2881  config &e = report.add_child("element");
2882  e["text"] = str;
2883  e["tooltip"] = report.child("element", -1)["tooltip"];
2884  }
2885 
2886  // Loop through and display each report element.
2887  int tallest = 0;
2888  int image_count = 0;
2889  bool used_ellipsis = false;
2890  std::ostringstream ellipsis_tooltip;
2891  SDL_Rect ellipsis_area = rect;
2892 
2893  for (config::const_child_itors elements = report.child_range("element");
2894  elements.begin() != elements.end(); elements.pop_front())
2895  {
2896  SDL_Rect area {x, y, rect.w + rect.x - x, rect.h + rect.y - y};
2897  if (area.h <= 0) break;
2898 
2899  std::string t = elements.front()["text"];
2900  if (!t.empty())
2901  {
2902  if (used_ellipsis) goto skip_element;
2903 
2904  // Draw a text element.
2905  font::pango_text text;
2906  if (item->font_rgb_set()) {
2907  text.set_foreground_color(item->font_rgb());
2908  }
2909  bool eol = false;
2910  if (t[t.size() - 1] == '\n') {
2911  eol = true;
2912  t = t.substr(0, t.size() - 1);
2913  }
2914  text.set_font_size(item->font_size());
2915  text.set_text(t, true);
2916  text.set_maximum_width(area.w);
2917  text.set_maximum_height(area.h, false);
2918  surface s = text.render();
2919 
2920  // check if next element is text with almost no space to show it
2921  const int minimal_text = 12; // width in pixels
2922  config::const_child_iterator ee = elements.begin();
2923  if (!eol && rect.w - (x - rect.x + s->w) < minimal_text &&
2924  ++ee != elements.end() && !(*ee)["text"].empty())
2925  {
2926  // make this element longer to trigger rendering of ellipsis
2927  // (to indicate that next elements have not enough space)
2928  //NOTE this space should be longer than minimal_text pixels
2929  t = t + " ";
2930  text.set_text(t, true);
2931  s = text.render();
2932  // use the area of this element for next tooltips
2933  used_ellipsis = true;
2934  ellipsis_area.x = x;
2935  ellipsis_area.y = y;
2936  ellipsis_area.w = s->w;
2937  ellipsis_area.h = s->h;
2938  }
2939 
2940  screen_.blit_surface(x, y, s);
2941  area.w = s->w;
2942  area.h = s->h;
2943  if (area.h > tallest) {
2944  tallest = area.h;
2945  }
2946  if (eol) {
2947  x = rect.x;
2948  y += tallest;
2949  tallest = 0;
2950  } else {
2951  x += area.w;
2952  }
2953  }
2954  else if (!(t = elements.front()["image"].str()).empty())
2955  {
2956  if (used_ellipsis) goto skip_element;
2957 
2958  // Draw an image element.
2959  surface img(image::get_image(t));
2960 
2961  if (!img) {
2962  ERR_DP << "could not find image for report: '" << t << "'" << std::endl;
2963  continue;
2964  }
2965 
2966  if (area.w < img->w && image_count) {
2967  // We have more than one image, and this one doesn't fit.
2969  used_ellipsis = true;
2970  }
2971 
2972  if (img->w < area.w) area.w = img->w;
2973  if (img->h < area.h) area.h = img->h;
2974  draw_image_for_report(img, area);
2975 
2976  ++image_count;
2977  if (area.h > tallest) {
2978  tallest = area.h;
2979  }
2980 
2981  if (!used_ellipsis) {
2982  x += area.w;
2983  } else {
2984  ellipsis_area = area;
2985  }
2986  }
2987  else
2988  {
2989  // No text nor image, skip this element
2990  continue;
2991  }
2992 
2993  skip_element:
2994  t = elements.front()["tooltip"].t_str().c_str();
2995  if (!t.empty()) {
2996  if (!used_ellipsis) {
2997  tooltips::add_tooltip(area, t, elements.front()["help"].t_str().c_str());
2998  } else {
2999  // Collect all tooltips for the ellipsis.
3000  // TODO: need a better separator
3001  // TODO: assign an action
3002  ellipsis_tooltip << t;
3003  config::const_child_iterator ee = elements.begin();
3004  if (++ee != elements.end())
3005  ellipsis_tooltip << "\n _________\n\n";
3006  }
3007  }
3008  }
3009 
3010  if (used_ellipsis) {
3011  tooltips::add_tooltip(ellipsis_area, ellipsis_tooltip.str());
3012  }
3013 }
3014 
3016 {
3017  DBG_DP << "invalidate_all()\n";
3018  invalidateAll_ = true;
3019  invalidated_.clear();
3020 }
3021 
3023 {
3024  if(invalidateAll_)
3025  return false;
3026 
3027  bool tmp;
3028  tmp = invalidated_.insert(loc).second;
3029  return tmp;
3030 }
3031 
3032 bool display::invalidate(const std::set<map_location>& locs)
3033 {
3034  if(invalidateAll_)
3035  return false;
3036  bool ret = false;
3037  for (const map_location& loc : locs) {
3038  ret = invalidated_.insert(loc).second || ret;
3039  }
3040  return ret;
3041 }
3042 
3043 bool display::propagate_invalidation(const std::set<map_location>& locs)
3044 {
3045  if(invalidateAll_)
3046  return false;
3047 
3048  if(locs.size()<=1)
3049  return false; // propagation never needed
3050 
3051  bool result = false;
3052  {
3053  // search the first hex invalidated (if any)
3054  std::set<map_location>::const_iterator i = locs.begin();
3055  for(; i != locs.end() && invalidated_.count(*i) == 0 ; ++i) {}
3056 
3057  if (i != locs.end()) {
3058 
3059  // propagate invalidation
3060  // 'i' is already in, but I suspect that splitting the range is bad
3061  // especially because locs are often adjacents
3062  size_t previous_size = invalidated_.size();
3063  invalidated_.insert(locs.begin(), locs.end());
3064  result = previous_size < invalidated_.size();
3065  }
3066  }
3067  return result;
3068 }
3069 
3071 {
3073 }
3074 
3075 bool display::invalidate_locations_in_rect(const SDL_Rect& rect)
3076 {
3077  if(invalidateAll_)
3078  return false;
3079 
3080  bool result = false;
3081  for (const map_location &loc : hexes_under_rect(rect)) {
3082  result |= invalidate(loc);
3083  }
3084  return result;
3085 }
3086 
3088  if (get_map().is_village(loc)) {
3089  const int owner = dc_->village_owner(loc) - 1;
3090  if (owner >= 0 && flags_[owner].need_update()
3091  && (!fogged(loc) || !dc_->teams()[currentTeam_].is_enemy(owner+1))) {
3092  invalidate(loc);
3093  }
3094  }
3095 }
3096 
3098 {
3101  if (animate_map_) {
3102  for (const map_location &loc : get_visible_hexes())
3103  {
3104  if (shrouded(loc)) continue;
3105  if (builder_->update_animation(loc)) {
3106  invalidate(loc);
3107  } else {
3109  }
3110  }
3111  }
3112 
3113  for(const unit& u : dc_->units()) {
3114  u.anim_comp().refresh();
3115  }
3116  for (const unit* u : *fake_unit_man_) {
3117  u->anim_comp().refresh();
3118  }
3119 
3120 
3121  bool new_inval;
3122  do {
3123  new_inval = false;
3124  for (const unit & u : dc_->units()) {
3125  new_inval |= u.anim_comp().invalidate(*this);
3126  }
3127  for (const unit* u : *fake_unit_man_) {
3128  new_inval |= u->anim_comp().invalidate(*this);
3129  }
3130  } while (new_inval);
3131 }
3132 
3134 {
3135  for(const unit & u : dc_->units()) {
3136  u.anim_comp().set_standing();
3137  }
3138 }
3139 
3141 {
3142  const arrow_path_t & arrow_path = arrow.get_path();
3143  for (const map_location& loc : arrow_path)
3144  {
3145  arrows_map_[loc].push_back(&arrow);
3146  }
3147 }
3148 
3150 {
3151  const arrow_path_t & arrow_path = arrow.get_path();
3152  for (const map_location& loc : arrow_path)
3153  {
3154  arrows_map_[loc].remove(&arrow);
3155  }
3156 }
3157 
3159 {
3160  const arrow_path_t & previous_path = arrow.get_previous_path();
3161  for (const map_location& loc : previous_path)
3162  {
3163  arrows_map_[loc].remove(&arrow);
3164  }
3165  const arrow_path_t & arrow_path = arrow.get_path();
3166  for (const map_location& loc : arrow_path)
3167  {
3168  arrows_map_[loc].push_back(&arrow);
3169  }
3170 }
3171 
3173 {
3174  const SDL_Rect& rect = map_area();
3175  return pixel_position_to_hex(xpos_ + rect.x + rect.w / 2 , ypos_ + rect.y + rect.h / 2 );
3176 }
3177 
3178 void display::write(config& cfg) const
3179 {
3180  cfg["view_locked"] = view_locked_;
3181  cfg["color_adjust_red"] = color_adjust_.r;
3182  cfg["color_adjust_green"] = color_adjust_.g;
3183  cfg["color_adjust_blue"] = color_adjust_.b;
3184  get_middle_location().write(cfg.add_child("location"));
3185 }
3186 
3187 void display::read(const config& cfg)
3188 {
3189  view_locked_ = cfg["view_locked"].to_bool(false);
3190  color_adjust_.r = cfg["color_adjust_red"].to_int(0);
3191  color_adjust_.g = cfg["color_adjust_green"].to_int(0);
3192  color_adjust_.b = cfg["color_adjust_blue"].to_int(0);
3193 }
3194 
3196 {
3197  if (!reach_map_changed_) return;
3198  if (reach_map_.empty() != reach_map_old_.empty()) {
3199  // Invalidate everything except the non-darkened tiles
3200  reach_map &full = reach_map_.empty() ? reach_map_old_ : reach_map_;
3201 
3202  for (const auto& hex : get_visible_hexes()) {
3203  reach_map::iterator reach = full.find(hex);
3204  if (reach == full.end()) {
3205  // Location needs to be darkened or brightened
3206  invalidate(hex);
3207  } else if (reach->second != 1) {
3208  // Number needs to be displayed or cleared
3209  invalidate(hex);
3210  }
3211  }
3212  } else if (!reach_map_.empty()) {
3213  // Invalidate only changes
3214  reach_map::iterator reach, reach_old;
3215  for (reach = reach_map_.begin(); reach != reach_map_.end(); ++reach) {
3216  reach_old = reach_map_old_.find(reach->first);
3217  if (reach_old == reach_map_old_.end()) {
3218  invalidate(reach->first);
3219  } else {
3220  if (reach_old->second != reach->second) {
3221  invalidate(reach->first);
3222  }
3223  reach_map_old_.erase(reach_old);
3224  }
3225  }
3226  for (reach_old = reach_map_old_.begin(); reach_old != reach_map_old_.end(); ++reach_old) {
3227  invalidate(reach_old->first);
3228  }
3229  }
3231  reach_map_changed_ = false;
3232 }
3233 
3234 void display::handle_window_event(const SDL_Event& event) {
3235  if (event.type == SDL_WINDOWEVENT) {
3236  switch (event.window.event) {
3237  case SDL_WINDOWEVENT_RESIZED:
3238  case SDL_WINDOWEVENT_RESTORED:
3239  case SDL_WINDOWEVENT_EXPOSED:
3240  dirty_ = true;
3241 
3242  break;
3243  }
3244  }
3245 
3246 
3247 }
3248 
3249 void display::handle_event(const SDL_Event& event) {
3251  return;
3252  }
3253  if (event.type == DRAW_ALL_EVENT) {
3254  draw();
3255  }
3256 }
3257 
3258 display *display::singleton_ = nullptr;
std::shared_ptr< gui::button > find_action_button(const std::string &id)
Retrieves a pointer to a theme UI button.
Definition: display.cpp:830
static const std::array< drawing_layer, 4 > layer_groups
Definition: display.hpp:926
std::size_t font_size() const
Definition: theme.hpp:112
play_controller * controller
Definition: resources.cpp:21
TYPE
Used to specify the rendering format of images.
Definition: picture.hpp:228
void drawing_buffer_commit()
Draws the drawing_buffer_ and clears it.
Definition: display.cpp:1286
int village_owner(const map_location &loc) const
Given the location of a village, will return the 1-based number of the team that currently owns it...
void draw_minimap_units()
Definition: display.cpp:1872
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
Definition: picture.cpp:815
const std::string & get_modifications() const
Definition: picture.hpp:82
int zoom_index_
Definition: display.hpp:751
void raise_volatile_undraw_event()
Definition: events.cpp:813
void recalculate_shroud()
Definition: label.cpp:277
Reserve layers to be selected for WML.
Definition: display.hpp:830
virtual void pre_draw()
Called near the beginning of each draw() call.
Definition: display.hpp:671
bool discard_previous
An announcement according these options should replace the previous announce (typical of fast announc...
Definition: display.hpp:598
virtual SDL_Rect & location(const SDL_Rect &screen) const
Definition: theme.cpp:317
draw_layering(const bool auto_join=true)
Definition: video.cpp:54
const std::string & icon() const
Definition: theme.hpp:108
bool is_odd(T num)
Definition: math.hpp:35
virtual void select_hex(map_location hex)
Definition: display.cpp:1618
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:414
::tod_manager * tod_manager
Definition: resources.cpp:29
Arrows destined to be drawn on the map.
int h() const
Effective map height, in hexes.
Definition: map.hpp:124
reports * reports_object_
Definition: display.hpp:768
unit_iterator end()
Definition: map.hpp:428
bool update_locked() const
Whether the screen has been &#39;locked&#39; or not.
Definition: video.cpp:348
bool minimap_draw_units()
Definition: general.cpp:809
void write(config &cfg) const
Definition: display.cpp:3178
virtual void handle_window_event(const SDL_Event &event)
Definition: display.cpp:3234
hotkey::command_executor * get_hotkey_command_executor() override
Optionally get a command executor to handle context menu events.
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:90
bool show_fps()
Definition: general.cpp:849
const team & get_team(int side) const
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
Definition: display.hpp:293
Small struct to store and manipulate ToD color adjusts.
Definition: time_of_day.hpp:26
void adjust_color_overlay(int r, int g, int b)
Add r,g,b to the colors for all images displayed on the map.
Definition: display.cpp:468
const arrow_path_t & get_path() const
Definition: arrow.cpp:120
#define DefaultZoom
Definition: display.cpp:77
std::string image_mask
The image that is to be laid over all images while this time of day lasts.
Definition: time_of_day.hpp:95
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
Definition: location.cpp:474
void invalidate_animations()
Function to invalidate animated terrains and units which may have changed.
Definition: display.cpp:3097
#define ERR_DP
Definition: display.cpp:70
virtual void draw_sidebar()
Called near the end of a draw operation, derived classes can use this to render a specific sidebar...
Definition: display.hpp:714
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3022
color_t font_rgb() const
Definition: theme.hpp:113
static int hex_size()
Function which returns the size of a hex in pixels (from top tip to bottom tip or left edge to right ...
Definition: display.hpp:257
void draw_wrap(bool update, bool force)
Definition: display.cpp:1690
void flip()
Definition: display.cpp:1339
This class represents a single unit of a specific type.
Definition: unit.hpp:120
bool animate_water_
Local version of preferences::animate_water, used to detect when it&#39;s changed.
Definition: display.hpp:800
virtual void notify_observers()
tod_color color
The color modifications that should be made to the game board to reflect the time of day...
static void toggle_benchmark()
Toggle to continuously redraw the screen.
Definition: display.cpp:1329
CKey keys_
Definition: display.hpp:794
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
Definition: text.cpp:283
void set_clip_rect(const SDL_Rect &r)
bool set_zoom(bool increase)
Zooms the display in (true) or out (false).
Definition: display.cpp:2028
void change_display_context(const display_context *dc)
Definition: display.cpp:513
const map_location hex_clicked_on(int x, int y) const
given x,y co-ordinates of an onscreen pixel, will return the location of the hex that this pixel corr...
Definition: display.cpp:597
boost::circular_buffer< unsigned > frametimes_
Definition: display.hpp:773
bool rects_overlap(const SDL_Rect &rect1, const SDL_Rect &rect2)
Tests whether two rectangles overlap.
Definition: rect.cpp:33
int ypos_
Definition: display.hpp:743
bool reach_map_changed_
Definition: display.hpp:1037
static double get_zoom_factor()
Returns the current zoom factor.
Definition: display.hpp:260
drawing_buffer drawing_buffer_
Definition: display.hpp:975
void set_playing_team(std::size_t team)
set_playing_team sets the team whose turn it currently is
Definition: display.cpp:419
surface reverse_image(const surface &surf)
Horizontally flips an image.
Definition: picture.cpp:988
void draw_init()
Initiate a redraw.
Definition: display.cpp:1651
void set_idle_anim_rate(int rate)
Definition: display.cpp:2415
const map_location pixel_position_to_hex(int x, int y) const
given x,y co-ordinates of a pixel on the map, will return the location of the hex that this pixel cor...
Definition: display.cpp:612
void scroll_floating_labels(double xmove, double ymove)
moves all floating labels that have &#39;scroll_mode&#39; set to ANCHOR_LABEL_MAP
#define a
int draw_delay()
Definition: general.cpp:859
Definition: video.hpp:31
bool minimap_movement_coding()
Definition: general.cpp:789
std::map< std::string, SDL_Rect > reportRects_
Definition: display.hpp:780
void draw_all_panels()
redraw all panels associated with the map display
Definition: display.cpp:1473
void render_image(int x, int y, const display::drawing_layer drawing_layer, const map_location &loc, surface image, bool hreverse=false, bool greyscale=false, fixed_t alpha=ftofxp(1.0), color_t blendto={0, 0, 0}, double blend_ratio=0, double submerged=0.0, bool vreverse=false)
Draw an image at a certain location.
Definition: display.cpp:1550
bool in_dialog()
Definition: show_dialog.cpp:56
virtual void draw_invalidated()
Only called when there&#39;s actual redrawing to do.
Definition: display.cpp:2552
map_location mouseoverHex_
Definition: display.hpp:793
void flip()
Renders the screen.
Definition: video.cpp:328
void init_flags()
Init the flag list and the team colors used by ~TC.
Definition: display.cpp:306
Manages a list of fake units for the display object.
Mouseover overlay used by editor.
Definition: display.hpp:827
virtual void draw_hex(const map_location &hex)
Definition: arrow.cpp:136
child_itors child_range(config_key_type key)
Definition: config.cpp:356
static void draw_background(surface screen, const SDL_Rect &area, const std::string &image)
Definition: display.cpp:1494
std::string id
Definition: time_of_day.hpp:89
void lock_updates(bool value)
Stop the screen being redrawn.
Definition: video.cpp:339
bool draw_coordinates_
Debug flag - overlay x,y coords on tiles.
Definition: display.hpp:1059
const SDL_Rect & map_area() const
Returns the area used for the map.
Definition: display.cpp:560
int scroll_speed()
Definition: general.cpp:745
void remove_floating_label(int handle)
removes the floating label given by &#39;handle&#39; from the screen
void redraw_everything()
Invalidates entire screen, including all tiles and sidebar.
Definition: display.cpp:2420
static lg::log_domain log_display("display")
int fps_handle_
Handle for the label which displays frames per second.
Definition: display.hpp:1046
bool show_everything() const
Definition: display.hpp:92
The class terrain_builder is constructed from a config object, and a gamemap object.
Definition: builder.hpp:47
map_location minimap_location_on(int x, int y)
given x,y co-ordinates of the mouse, will return the location of the hex in the minimap that the mous...
Definition: display.cpp:758
void fill_surface_rect(surface &dst, SDL_Rect *dst_rect, const uint32_t color)
Fill a rectangle on a given surface.
Definition: rect.hpp:114
void reset_halo_manager()
Definition: display.cpp:519
int viewing_side() const
Definition: display.hpp:105
int get_zoom_levels_index(unsigned int zoom_level)
Definition: display.cpp:95
void set_tile_size(const unsigned int size)
Definition: general.cpp:624
reach_map reach_map_
Definition: display.hpp:1035
bool non_interactive() const
Definition: video.cpp:140
SDL_Rect intersect_rects(const SDL_Rect &rect1, const SDL_Rect &rect2)
Calculates the intersection of two rectangles.
Definition: rect.cpp:39
#define h
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109
iterator & operator++()
increment y first, then when reaching bottom, increment x
Definition: display.cpp:664
std::vector< std::function< void(display &)> > redraw_observers_
Definition: display.hpp:1056
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Definition: map.cpp:382
#define MaxZoom
Definition: display.cpp:80
map_location selectedHex_
Definition: display.hpp:792
void set_font_size(int font_size)
const std::vector< std::string > items
CVideo & screen_
Definition: display.hpp:734
surface scale_surface(const surface &surf, int w, int h)
Scale a surface using alpha-weighted modified bilinear filtering Note: causes artifacts with alpha gr...
Definition: utils.cpp:196
static display * singleton_
Definition: display.hpp:1075
void blit_surface(int x, int y, surface surf, SDL_Rect *srcrect=nullptr, SDL_Rect *clip_rect=nullptr)
Draws a surface directly onto the screen framebuffer.
Definition: video.cpp:168
#define d
Belongs to a friendly side.
virtual void draw()
Draws invalidated items.
Definition: display.cpp:2479
surface blend_surface(const surface &surf, const double amount, const color_t color)
Blends a surface with a color.
Definition: utils.cpp:1716
bool animate_water()
Definition: general.cpp:784
const int SIZE_PLUS
Definition: constants.cpp:26
Top half part of grid image.
Definition: display.hpp:826
surface get_surface_portion(const surface &src, SDL_Rect &area)
Get a portion of the screen.
Definition: utils.cpp:2157
void enable_menu(const std::string &item, bool enable)
Finds the menu which has a given item in it, and enables or disables it.
Definition: display.cpp:1760
Rectangular area of hexes, allowing to decide how the top and bottom edges handles the vertical shift...
Definition: display.hpp:303
An object to leave the synced context during draw or unsynced wml items when we don’t know whether w...
surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::map< map_location, unsigned int > *reach_map, bool ignore_terrain_disabled)
function to create the minimap for a given map the surface returned must be freed by the user ...
Definition: minimap.cpp:39
const std::vector< label > & labels() const
Definition: theme.hpp:253
static unsigned int zoom_
The current zoom, in pixels (on screen) per 72 pixels (in the graphic assets), i.e., 72 means 100%.
Definition: display.hpp:750
void clear_redraw_observers()
Clear the redraw observers.
Definition: display.cpp:2474
const SDL_Rect & minimap_area() const
mapx is the width of the portion of the display which shows the game area.
Definition: display.hpp:216
drawing_layer
The layers to render something on.
Definition: display.hpp:821
Same as SCALED_TO_HEX, but with Time of Day color tint applied.
Definition: picture.hpp:239
virtual const gamemap & map() const =0
std::vector< surface > get_fog_shroud_images(const map_location &loc, image::TYPE image_type)
Definition: display.cpp:966
void reset_standing_animations()
Definition: display.cpp:3133
void remove_arrow(arrow &)
Definition: display.cpp:3149
surface clone() const
Makes a copy of this surface.
Definition: surface.cpp:75
surface & getSurface()
Returns a reference to the framebuffer.
Definition: video.cpp:503
void add_frame(int duration, const T &value, bool force_change=false)
Adds a frame to an animation.
bool panelsDrawn_
Definition: display.hpp:763
#define DBG_DP
Definition: display.cpp:72
void draw_centered_on_background(surface surf, const SDL_Rect &rect, const color_t &color, surface target)
Definition: utils.cpp:2272
surface tod_hex_mask2
Definition: display.hpp:788
SDL_Rect get_non_transparent_portion(const surface &surf)
Definition: utils.cpp:2203
void init_flags_for_side_internal(std::size_t side, const std::string &side_color)
Definition: display.cpp:327
void update_display()
Copy the backbuffer to the framebuffer.
Definition: display.cpp:1362
std::vector< map_location > arrow_path_t
Definition: arrow.hpp:24
Unit and team statistics.
very simple iterator to walk into the rect_of_hexes
Definition: display.hpp:310
iterator begin() const
Definition: display.cpp:677
const rect_of_hexes get_visible_hexes() const
Returns the rectangular area of visible hexes.
Definition: display.hpp:340
surface submerge_alpha(const surface &surf, int depth, float alpha_base, float alpha_delta)
Progressively reduce alpha of bottom part of the surface.
Definition: utils.cpp:1248
std::vector< std::shared_ptr< gui::button > > action_buttons_
Definition: display.hpp:783
map_location loc_
surface map_screenshot_surf_
Definition: display.hpp:1054
void clear_tooltips()
Definition: tooltips.cpp:120
virtual bool in_editor() const
Definition: display.hpp:204
bool team_valid() const
Definition: display.cpp:733
#define b
const theme::action * action_pressed()
Definition: display.cpp:1728
const int SIZE_XLARGE
Definition: constants.cpp:29
const std::string & text() const
Definition: theme.hpp:106
std::vector< std::string > shroud_images_
Definition: display.hpp:790
void draw_image_for_report(surface &img, SDL_Rect &rect)
Definition: display.cpp:2769
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:55
bool exists(const image::locator &i_locator)
Returns true if the given image actually exists, without loading it.
Definition: picture.cpp:1010
void blindfold(bool flag)
Definition: display.cpp:529
void parse_team_overlays()
Check the overlay_map for proper team-specific overlays to be displayed/hidden.
Definition: display.cpp:115
const config & options()
Definition: game.cpp:563
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
Belongs to a non-friendly side; normally visualised by not displaying an orb.
surface flop_surface(const surface &surf)
Definition: utils.cpp:1980
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
const std::string & id() const
Gets this unit&#39;s id.
Definition: unit.hpp:370
uint32_t last_frame_finished_
Definition: display.hpp:777
void adjust_surface_alpha(surface &surf, fixed_t amount)
Definition: utils.cpp:1086
void get_terrain_images(const map_location &loc, const std::string &timeid, TERRAIN_TYPE terrain_type)
Definition: display.cpp:1053
const arrow_path_t & get_previous_path() const
Definition: arrow.cpp:125
double turbo_speed() const
Definition: display.cpp:2401
static bool zoom_at_max()
Definition: display.cpp:2018
void draw_minimap()
Definition: display.cpp:1794
light_string get_light_string(int op, int r, int g, int b)
Returns the light_string for one light operation.
Definition: picture.cpp:592
const std::string & prefix() const
Definition: theme.hpp:130
void new_animation_frame()
Definition: animated.cpp:30
static unsigned calculate_fps(unsigned frametime)
Definition: display.cpp:1357
static bool outside_area(const SDL_Rect &area, const int x, const int y)
Check if the bbox of the hex at x,y has pixels outside the area rectangle.
Definition: display.cpp:588
bool tile_fully_on_screen(const map_location &loc) const
Check if a tile is fully visible on screen.
Definition: display.cpp:2108
const theme::menu * menu_pressed()
Definition: display.cpp:1744
Arrows destined to be drawn on the map.
Definition: arrow.hpp:29
surface screenshot(bool map_screenshot=false)
Capture a (map-)screenshot into a surface.
Definition: display.cpp:788
std::string theme()
Definition: game.cpp:809
void set_lifetime(int lifetime)
std::string get_orb_color(orb_status os)
Wrapper for the various preferences::unmoved_color(), moved_color(), etc methods, using the enum inst...
Definition: orb_status.cpp:39
bool font_rgb_set() const
Definition: theme.hpp:114
bool invalidate_visible_locations_in_rect(const SDL_Rect &rect)
Definition: display.cpp:3070
void recalculate_minimap()
Schedule the minimap for recalculation.
Definition: display.hpp:616
void scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type, bool force=true)
Definition: display.cpp:2125
config & add_child_at(config_key_type key, const config &val, unsigned index)
Definition: config.cpp:532
bool valid() const
Definition: location.hpp:88
bool map_screenshot_
Used to indicate to drawing functions that we are doing a map screenshot.
Definition: display.hpp:1020
arrows_map_t arrows_map_
Maps the list of arrows for each location.
Definition: display.hpp:1068
virtual image::TYPE get_image_type(const map_location &loc)
Definition: display.cpp:2761
bool idle_anim() const
Definition: display.hpp:494
const std::unique_ptr< map_labels > map_labels_
Definition: display.hpp:767
int xpos_
Position of the top-left corner of the viewport, in pixels.
Definition: display.hpp:743
config generate_report(const std::string &name, context &ct, bool only_static=false)
Definition: reports.cpp:1747
pango_text & set_font_size(const unsigned font_size)
Definition: text.cpp:331
void update_tod(const time_of_day *tod_override=nullptr)
Applies r,g,b coloring to the map.
Definition: display.cpp:457
void render_buttons()
Definition: display.cpp:936
bool dirty_
Definition: display.hpp:1072
std::string background_image
Definition: theme.hpp:90
bool idle_anim_
Definition: display.hpp:1051
SDL_Rect minimap_location_
Definition: display.hpp:757
double size
Definition: theme.hpp:88
void set_zoom(unsigned int amount)
Sets the scaling factor for images.
Definition: picture.cpp:704
TERRAIN_TYPE
Used as a parameter for the get_terrain_at function.
Definition: builder.hpp:51
display(const display_context *dc, std::weak_ptr< wb::manager > wb, reports &reports_object, const config &theme_cfg, const config &level, bool auto_join=true)
Definition: display.cpp:166
std::string grid_bottom
tod_color color_adjust_
Definition: display.hpp:1070
void reinit_flags_for_team(const team &)
Rebuild the flag list (not team colors) for a single side.
Definition: display.cpp:322
uint8_t r
Red value.
Definition: color.hpp:177
fake_unit_manager * fake_units
Definition: resources.cpp:30
bool is_enemy(int n) const
Definition: team.hpp:251
void draw_text_in_hex(const map_location &loc, const drawing_layer layer, const std::string &text, std::size_t font_size, color_t color, double x_in_hex=0.5, double y_in_hex=0.5)
Draw text on a hex.
Definition: display.cpp:1521
void bounds_check_position()
Definition: display.cpp:2357
virtual void post_draw()
Called at the very end of each draw() call.
Definition: display.hpp:678
Modify, read and display user preferences.
bool font_rgb_set() const
Definition: theme.hpp:138
bool invalidateGameStatus_
Definition: display.hpp:766
#define MinZoom
Definition: display.cpp:79
void set_position(double xpos, double ypos)
void update_arrow(arrow &a)
Called by arrow objects when they change.
Definition: display.cpp:3158
map_display and display: classes which take care of displaying the map and game-data on the screen...
unsigned int fps_actual_
Definition: display.hpp:776
virtual const unit_map & units() const =0
void add_overlay(const map_location &loc, const std::string &image, const std::string &halo="", const std::string &team_name="", const std::string &item_id="", bool visible_under_fog=true, float z_order=0)
Functions to add and remove overlays from locations.
Definition: display.cpp:134
bool animate_map()
Definition: general.cpp:779
std::string shroud_prefix
Definition: game_config.cpp:70
void create_buttons()
Definition: display.cpp:877
const std::string & get_id() const
Definition: theme.hpp:52
const color_t YELLOW_COLOR
static const std::string & get_direction(std::size_t n)
Definition: display.cpp:960
const rect_of_hexes hexes_under_rect(const SDL_Rect &r) const
Return the rectangular area of hexes overlapped by r (r is in screen coordinates) ...
Definition: display.cpp:686
void invalidate_all()
Function to invalidate all tiles.
Definition: display.cpp:3015
void layout_buttons()
Definition: display.cpp:850
int invalidated_hexes_
Count work done for the debug info displayed under fps.
Definition: display.hpp:1048
bool draw_terrain_codes_
Debug flag - overlay terrain codes on tiles.
Definition: display.hpp:1061
int32_t fixed_t
Definition: math.hpp:312
void pump()
Definition: events.cpp:472
const color_t NORMAL_COLOR
bool fogged(const map_location &loc) const
Returns true if location (x,y) is covered in fog.
Definition: display.cpp:743
Generic locator abstracting the location of an image.
Definition: picture.hpp:59
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
Definition: rect.cpp:22
static int hex_width()
Function which returns the width of a hex in pixels, up to where the next hex starts.
Definition: display.hpp:251
lu_byte right
Definition: lparser.cpp:1227
std::string flag_rgb
static unsigned int last_zoom_
The previous value of zoom_.
Definition: display.hpp:753
Fog and shroud.
Definition: display.hpp:850
void set_color_adjustment(int r, int g, int b)
Changes Time of Day color tint for all applicable image types.
Definition: picture.cpp:690
std::unique_ptr< halo::manager > halo_man_
Definition: display.hpp:658
#define ftofxp(x)
IN: float or int - OUT: fixed_t.
Definition: math.hpp:317
int idle_anim_rate()
Definition: general.cpp:479
Encapsulates the map of the game.
Definition: location.hpp:37
void set_color(const color_t &color)
void set_team(const team *)
Definition: label.cpp:138
bool shrouded(const map_location &loc) const
Returns true if location (x,y) is covered in shroud.
Definition: display.cpp:738
boost::iterator_range< const_child_iterator > const_child_itors
Definition: config.hpp:204
#define DRAW_ALL_EVENT
Definition: events.hpp:29
unit_iterator find(std::size_t id)
Definition: map.cpp:309
void process_reachmap_changes()
Definition: display.cpp:3195
bool faked() const
Definition: video.hpp:65
const border_t & border() const
Definition: theme.hpp:283
A button is a control that can be pushed to start an action or close a dialog.
Definition: button.hpp:49
Definition: video.cpp:50
void recalculate_labels()
Definition: label.cpp:244
int w() const
Effective map width, in hexes.
Definition: map.hpp:121
virtual void handle_event(const SDL_Event &)
Definition: display.cpp:3249
surface & get_screen_surface()
return the screen surface or the surface used for map_screenshot.
Definition: display.hpp:201
surface tod_hex_mask1
Definition: display.hpp:788
const color_t BLACK_COLOR
virtual overlay_map & get_overlays()=0
std::size_t i
Definition: function.cpp:934
virtual const std::vector< team > & teams() const =0
int current_refresh_rate() const
Definition: video.hpp:164
bool is_blindfolded() const
Definition: display.cpp:537
bool show_border
Definition: theme.hpp:93
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
Definition: display.cpp:2204
void announce(const std::string &msg, const color_t &color=font::GOOD_COLOR, const announce_options &options=announce_options())
Announce a message prominently.
Definition: display.cpp:1778
virtual void highlight_hex(map_location hex)
Definition: display.cpp:1626
Holds options for calls to function &#39;announce&#39; (announce).
Definition: display.hpp:588
default layer for drawing moving units
Definition: display.hpp:841
std::size_t activeTeam_
Definition: display.hpp:892
const std::string & postfix() const
Definition: theme.hpp:131
std::vector< std::shared_ptr< gui::button > > menu_buttons_
Definition: display.hpp:783
unsigned int tile_size()
Definition: general.cpp:619
void set_diagnostic(const std::string &msg)
Definition: display.cpp:1633
void scroll_to_tiles(map_location loc1, map_location loc2, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, double add_spacing=0.0, bool force=true)
Scroll such that location loc1 is on-screen.
Definition: display.cpp:2216
void invalidate_animations_location(const map_location &loc)
Per-location invalidation called by invalidate_animations() Extra game per-location invalidation (vil...
Definition: display.cpp:3087
default layer for drawing units
Definition: display.hpp:832
map_location get_middle_location() const
Definition: display.cpp:3172
static map_location::DIRECTION s
std::vector< std::string > names
Definition: build_info.cpp:64
unsigned int fps_counter_
Definition: display.hpp:774
virtual ~display()
Definition: display.cpp:285
double g
Definition: astarsearch.cpp:64
color_t font_rgb() const
Definition: theme.hpp:137
std::size_t playing_team() const
The playing team is the team whose turn it is.
Definition: display.hpp:99
bool draw_num_of_bitmaps_
Debug flag - overlay number of bitmaps on tiles.
Definition: display.hpp:1063
bool redraw_background_
Definition: display.hpp:759
void read(const config &cfg)
Definition: display.cpp:3187
bool dont_show_all_
Definition: display.hpp:736
int get_location_y(const map_location &loc) const
Definition: display.cpp:753
std::string name
Definition: sdl_ttf.cpp:70
std::basic_string< signed char > light_string
Type used to store color information of central and adjacent hexes.
Definition: picture.hpp:175
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
Definition: display.hpp:239
void start_animation(int start_time, bool cycles=false)
Starts an animation cycle.
Helper structure for rendering the terrains.
Definition: display.hpp:935
void undraw_floating_labels(surface screen)
void raise_volatile_draw_event()
Definition: events.cpp:795
surface get_rendered_text(const std::string &str, int size, const color_t &color, int style)
Definition: sdl_ttf.cpp:295
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
const std::string & image() const
Definition: theme.hpp:155
bool tile_nearly_on_screen(const map_location &loc) const
Checks if location loc or one of the adjacent tiles is visible on screen.
Definition: display.cpp:2115
bool invalidate_locations_in_rect(const SDL_Rect &rect)
invalidate all hexes under the rectangle rect (in screen coordinates)
Definition: display.cpp:3075
Layer for the terrain drawn in front of the unit.
Definition: display.hpp:833
bool add_exclusive_draw(const map_location &loc, unit &unit)
Allows a unit to request to be the only one drawn in its hex.
Definition: display.cpp:426
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
Definition: display.cpp:2589
Represents terrains which are to be drawn in front of them.
Definition: builder.hpp:56
bool is_zero() const
Definition: time_of_day.hpp:35
static bool zoom_at_min()
Definition: display.cpp:2023
int w
const menu * get_menu_item(const std::string &key) const
Definition: theme.cpp:948
Used for the bottom half part of grid image.
Definition: display.hpp:837
theme theme_
Definition: display.hpp:745
virtual const SDL_Rect & get_clip_rect()
Get the clipping rectangle for drawing.
Definition: display.cpp:2547
const bool & debug
bool view_locked_
Definition: display.hpp:744
surface mouseover_hex_overlay_
Definition: display.hpp:785
const std::vector< action > & actions() const
Definition: theme.hpp:256
const std::string & get_filename() const
Definition: picture.hpp:77
Definitions for the terrain builder.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
surface greyscale_image(const surface &surf)
Definition: utils.cpp:640
Represents terrains which are to be drawn behind unit sprites.
Definition: builder.hpp:52
static gui::button::TYPE string_to_button_type(const std::string &type)
Definition: display.cpp:950
Layer for the terrain drawn behind the unit.
Definition: display.hpp:822
config & add_child(config_key_type key)
Definition: config.cpp:500
drawing_buffer_key(const map_location &loc, drawing_layer layer)
Definition: display.cpp:1257
std::vector< std::string > fog_images_
Definition: display.hpp:789
Text class.
Definition: text.hpp:74
std::chrono::seconds fps_start_
Definition: display.hpp:775
std::vector< animated< image::locator > > imagelist
A shorthand typedef for a list of animated image locators, the base data type returned by the get_ter...
Definition: builder.hpp:74
void set_team(std::size_t team, bool observe=false)
Sets the team controlled by the player using the computer.
Definition: display.cpp:400
surface get_lighted_image(const image::locator &i_locator, const light_string &ls, TYPE type)
Caches and returns an image with a lightmap applied to it.
Definition: picture.cpp:888
const status_item * get_status_item(const std::string &item) const
Definition: theme.cpp:907
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an SDL_Rect with the given dimensions.
Definition: rect.hpp:39
std::map< map_location, unsigned int > reach_map
Definition: display.hpp:1034
bool redrawMinimap_
Definition: display.hpp:758
bool set_resolution(const SDL_Rect &screen)
Definition: theme.cpp:603
Definition: display.hpp:44
void drawing_buffer_add(const drawing_layer layer, const map_location &loc, int x, int y, const surface &surf, const SDL_Rect &clip=SDL_Rect())
Add an item to the drawing buffer.
Definition: display.cpp:1207
pango_text & set_maximum_width(int width)
Definition: text.cpp:364
const std::vector< team > & get_teams() const
Definition: display.hpp:96
static color_t get_minimap_color(int side)
Definition: team.cpp:952
reach_map reach_map_old_
Definition: display.hpp:1036
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
Definition: display.cpp:748
const gamemap & get_map() const
Definition: display.hpp:94
Image rescaled to fit into a hexagonal tile according to the zoom settings.
Definition: picture.hpp:237
const std::string & color() const
Definition: team.hpp:264
events::mouse_handler & get_mouse_handler_base() override
Get a reference to a mouse handler member a derived class uses.
virtual void post_commit()
Hook for actions to take right after draw() calls drawing_buffer_commit No action here by default...
Definition: display.hpp:698
exclusive_unit_draw_requests_t exclusive_unit_draw_requests_
map of hexes where only one unit should be drawn, the one identified by the associated id string ...
Definition: display.hpp:663
bool invalidateAll_
Definition: display.hpp:760
void redraw_unit(const unit &u) const
draw a unit.
Definition: drawer.cpp:91
events::generic_event scroll_event_
Event raised when the map is being scrolled.
Definition: display.hpp:771
iterator end() const
Definition: display.cpp:681
#define f
int lifetime
Lifetime measured in milliseconds.
Definition: display.hpp:591
double t
Definition: astarsearch.cpp:64
void reload_map()
Updates internals that cache map size.
Definition: display.cpp:507
uint32_t to_argb_bytes() const
Returns the stored color as a uint32_t, an ARGB format.
Definition: color.hpp:145
color_t rep() const
High-contrast shade, intended for the minimap markers.
Definition: color_range.hpp:94
orb_status unit_orb_status(const unit &u) const
Returns an enumurated summary of whether this unit can move and/or attack.
std::string tile_image
Definition: theme.hpp:91
constexpr const SDL_Rect empty_rect
Definition: rect.hpp:31
std::map< std::string, surface > reportSurfaces_
Definition: display.hpp:781
std::set< map_location > invalidated_
Definition: display.hpp:784
std::vector< std::string > split(const config_attribute_value &val)
unsigned int tile_size
Definition: game_config.cpp:67
void toggle_default_zoom()
Sets the zoom amount to the default.
Definition: display.cpp:2096
lu_byte left
Definition: lparser.cpp:1226
void drawing_buffer_clear()
Clears the drawing buffer.
Definition: display.cpp:1324
std::map< std::string, config > reports_
Definition: display.hpp:782
const display_context * dc_
Definition: display.hpp:657
surface brighten_image(const surface &surf, fixed_t amount)
Definition: utils.cpp:1044
std::size_t viewing_team() const
The viewing team is the team currently viewing the game.
Definition: display.hpp:104
surface tile_surface(const surface &surf, int w, int h, bool centered)
Tile a surface.
Definition: utils.cpp:552
SDL_Rect draw_text(surface &dst, const SDL_Rect &area, int size, const color_t &color, const std::string &txt, int x, int y, bool use_tooltips, int style)
Function to draw text on a surface.
const color_range & color_info(const std::string &name)
std::vector< surface > terrain_image_vector_
Definition: display.hpp:812
Functions to load and save images from/to disk.
double idle_anim_rate_
Definition: display.hpp:1052
void fill_rectangle(const SDL_Rect &rect, const color_t &color)
Draws a filled rectangle.
Definition: rect.cpp:65
int drawn_hexes_
Definition: display.hpp:1049
Standard logging facilities (interface).
double turbo_speed_
Definition: display.hpp:764
int diagnostic_label_
Definition: display.hpp:762
void add_redraw_observer(std::function< void(display &)> f)
Adds a redraw observer, a function object to be called when redraw_everything is used.
Definition: display.cpp:2469
CVideo & video()
Gets the underlying screen object.
Definition: display.hpp:198
std::string ellipsis
std::size_t font_size() const
Definition: theme.hpp:136
EXIT_STATUS start(const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
Definition: editor_main.cpp:28
static void draw_label(CVideo &video, surface target, const theme::label &label)
Definition: display.cpp:1434
bool scroll_to_action()
Definition: general.cpp:377
A RAII object to temporary leave the synced context like in wesnoth.synchronize_choice.
map_labels & labels()
Definition: display.cpp:2537
const std::vector< menu > & menus() const
Definition: theme.hpp:254
#define e
static void fill_images_list(const std::string &prefix, std::vector< std::string > &images)
Definition: display.cpp:474
const std::unique_ptr< fake_unit_manager > fake_unit_man_
Definition: display.hpp:754
#define SmallZoom
Definition: display.cpp:78
#define final_zoom_index
Definition: display.cpp:76
std::vector< animated< image::locator > > flags_
Animated flags for each team.
Definition: display.hpp:808
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
Definition: config.cpp:477
surface & render()
Returns the rendered text.
Definition: text.cpp:90
pango_text & set_maximum_height(int height, bool multiline)
Definition: text.cpp:391
#define zoom_levels
Definition: display.cpp:75
int get_end_time() const
std::string team_name
Definition: overlay.hpp:53
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
Definition: utils.hpp:31
static void draw_panel(CVideo &video, const theme::panel &panel, std::vector< std::shared_ptr< gui::button >> &)
Definition: display.cpp:1413
int side() const
Definition: team.hpp:196
uint8_t g
Green value.
Definition: color.hpp:180
uint8_t b
Blue value.
Definition: color.hpp:183
virtual const time_of_day & get_time_of_day(const map_location &loc=map_location::null_location()) const
Definition: display.cpp:451
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
mock_char c
void remove_single_overlay(const map_location &loc, const std::string &toDelete)
remove_single_overlay will remove a single overlay from a tile
Definition: display.cpp:154
SDL_Rect screen_area(bool as_pixels=true) const
Returns the current window renderer area, either in pixels or screen coordinates. ...
Definition: video.cpp:291
surface get_flag(const map_location &loc)
Definition: display.cpp:380
pango_text & set_foreground_color(const color_t &color)
Definition: text.cpp:354
const int font_size
Definition: button.cpp:40
static map_location::DIRECTION n
std::shared_ptr< halo_record > handle
Definition: halo.hpp:29
int add_tooltip(const SDL_Rect &rect, const std::string &message, const std::string &action, bool use_markup, const surface &foreground)
Definition: tooltips.cpp:175
bool scroll(int xmov, int ymov, bool force=false)
Scrolls the display by xmov,ymov pixels.
Definition: display.cpp:1924
bool turbo_
Definition: display.hpp:765
void add_arrow(arrow &)
Definition: display.cpp:3140
void remove_overlay(const map_location &loc)
remove_overlay will remove all overlays on a tile.
Definition: display.cpp:149
bool animate_map_
Local cache for preferences::animate_map, since it is constantly queried.
Definition: display.hpp:797
const SDL_Rect & max_map_area() const
Returns the maximum area used for the map regardless to resolution and view size. ...
Definition: display.cpp:543
static rng & default_instance()
Definition: random.cpp:73
#define LOG_DP
Definition: display.cpp:71
const std::vector< panel > & panels() const
Definition: theme.hpp:252
static void toggle_debug_foreground()
Toggle to debug foreground terrain.
Definition: display.cpp:1334
std::string grid_top
const std::unique_ptr< terrain_builder > builder_
Definition: display.hpp:755
static const std::string & get_variant(const std::vector< std::string > &variants, const map_location &loc)
Definition: display.cpp:496
void invalidate_theme()
Definition: display.hpp:404
std::string::const_iterator iterator
Definition: tokenizer.hpp:24
std::string fog_prefix
Definition: game_config.cpp:70
bool empty() const
Definition: config.cpp:916
void refresh_report(const std::string &report_name, const config *new_cfg=nullptr)
Redraws the specified report (if anything has changed).
Definition: display.cpp:2807
std::weak_ptr< wb::manager > wb_
Definition: display.hpp:659
std::shared_ptr< gui::button > find_menu_button(const std::string &id)
Definition: display.cpp:840
Definition: display.hpp:48
void set_theme(config theme_cfg)
Definition: display.cpp:295
int blindfold_ctr_
Definition: display.hpp:653
const std::string & team_name() const
Definition: team.hpp:305
void draw_floating_labels(surface screen)
TERRAIN_TYPE
Definition: display.hpp:718
bool grid_
Definition: display.hpp:761
std::vector< std::string > square_parenthetical_split(const std::string &val, const char separator, const std::string &left, const std::string &right, const int flags)
Similar to parenthetical_split, but also expands embedded square brackets.
std::string remove_exclusive_draw(const map_location &loc)
Cancels an exclusive draw request.
Definition: display.cpp:439
const int SIZE_SMALL
Definition: constants.cpp:23
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:407
const color_t BAD_COLOR
"black stripes" on unreachable hexes.
Definition: display.hpp:848
std::size_t currentTeam_
Definition: display.hpp:735
void rebuild_all()
Rebuild all dynamic terrain.
Definition: display.cpp:502
bool propagate_invalidation(const std::set< map_location > &locs)
If this set is partially invalidated, invalidate all its hexes.
Definition: display.cpp:3043
void write(config &cfg) const
Definition: location.cpp:211
surface minimap_
Definition: display.hpp:756