The Battle for Wesnoth  1.17.21+dev
display.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2023
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  *
19  * map_display and display: classes which take care of
20  * displaying the map and game-data on the screen.
21  *
22  * The display is divided into two main sections:
23  * - the game area, which displays the tiles of the game board, and units on them,
24  * - and the side bar, which appears on the right hand side.
25  * The side bar display is divided into three sections:
26  * - the minimap, which is displayed at the top right
27  * - the game status, which includes the day/night image,
28  * the turn number, information about the current side,
29  * and information about the hex currently moused over (highlighted)
30  * - the unit status, which displays an image and stats
31  * for the current unit.
32  */
33 
34 #pragma once
35 
36 class config;
37 class fake_unit_manager;
38 class terrain_builder;
39 class map_labels;
40 class arrow;
41 class reports;
42 class team;
43 struct overlay;
44 
45 namespace halo {
46  class manager;
47 }
48 
49 namespace wb {
50  class manager;
51 }
52 
53 #include "animated.hpp"
54 #include "display_context.hpp"
55 #include "filesystem.hpp"
56 #include "font/standard_colors.hpp"
57 #include "game_config.hpp"
59 #include "halo.hpp"
60 #include "picture.hpp" //only needed for enums (!)
61 #include "key.hpp"
62 #include "time_of_day.hpp"
63 #include "sdl/rect.hpp"
64 #include "sdl/surface.hpp"
65 #include "sdl/texture.hpp"
66 #include "theme.hpp"
67 #include "widgets/button.hpp"
68 
69 #include <boost/circular_buffer.hpp>
70 
71 #include <bitset>
72 #include <functional>
73 #include <chrono>
74 #include <cstdint>
75 #include <deque>
76 #include <list>
77 #include <map>
78 #include <memory>
79 #include <vector>
80 
81 class gamemap;
82 
83 /**
84  * Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
85  */
87 {
88 public:
89  display(const display_context* dc,
90  std::weak_ptr<wb::manager> wb,
91  reports& reports_object,
92  const std::string& theme_id,
93  const config& level);
94 
95  virtual ~display();
96  /**
97  * Returns the display object if a display object exists. Otherwise it returns nullptr.
98  * the display object represents the game gui which handles themewml and drawing the map.
99  * A display object only exists during a game or while the mapeditor is running.
100  */
101  static display* get_singleton() { return singleton_ ;}
102 
103  bool show_everything() const { return !dont_show_all_ && !is_blindfolded(); }
104 
105  const gamemap& get_map() const { return dc_->map(); }
106 
107  const std::vector<team>& get_teams() const {return dc_->teams();}
108 
109  /** The playing team is the team whose turn it is. */
110  std::size_t playing_team() const { return activeTeam_; }
111 
112  bool team_valid() const;
113 
114  /**
115  * The viewing team is the team currently viewing the game. It's the team whose gold and income
116  * is shown in the top bar of the default theme.
117  *
118  * For players, it will be their side (or one of them, if they control multiple sides).
119  *
120  * The value returned is a 0-based index into the vector returned by get_teams().
121  */
122  std::size_t viewing_team() const { return currentTeam_; }
123  /**
124  * The 1-based equivalent of the 0-based viewing_team() function. This is the side-number that
125  * WML uses.
126  *
127  * TODO: provide a better interface in a better place (consistent base numbers, and not in a GUI
128  * class).
129  */
130  int viewing_side() const { return static_cast<int>(currentTeam_ + 1); }
131 
132  /**
133  * Sets the team controlled by the player using the computer.
134  * Data from this team will be displayed in the game status.
135  */
136  void set_team(std::size_t team, bool observe=false);
137 
138  /**
139  * set_playing_team sets the team whose turn it currently is
140  */
141  void set_playing_team(std::size_t team);
142 
143 
144  /**
145  * Cancels all the exclusive draw requests.
146  */
148  const unit_map& get_units() const {return dc_->units();}
149 
150  /**
151  * Allows a unit to request to be the only one drawn in its hex. Useful for situations where
152  * multiple units (one real, multiple temporary) can end up stacked, such as with the whiteboard.
153  * @param loc The location of the unit requesting exclusivity.
154  * @param unit The unit requesting exclusivity.
155  * @return false if there's already an exclusive draw request for this location.
156  */
157  bool add_exclusive_draw(const map_location& loc, unit& unit);
158  /**
159  * Cancels an exclusive draw request.
160  * @return The id of the unit whose exclusive draw request was canceled, or else
161  * the empty string if there was no exclusive draw request for this location.
162  */
163  std::string remove_exclusive_draw(const map_location& loc);
164 
165  /**
166  * Functions to add and remove overlays from locations.
167  *
168  * An overlay is an image that is displayed on top of the tile.
169  * One tile may have multiple overlays.
170  */
171  void add_overlay(const map_location& loc, const std::string& image,
172  const std::string& halo="", const std::string& team_name="",const std::string& item_id="",
173  bool visible_under_fog = true, float submerge = 0.0f, float z_order = 0);
174 
175  /** remove_overlay will remove all overlays on a tile. */
176  void remove_overlay(const map_location& loc);
177 
178  /** remove_single_overlay will remove a single overlay from a tile */
179  void remove_single_overlay(const map_location& loc, const std::string& toDelete);
180 
181  /**
182  * Updates internals that cache map size. This should be called when the map
183  * size has changed.
184  */
185  void reload_map();
186 
187  void change_display_context(const display_context* dc);
188 
190  {
191  return *dc_;
192  }
193 
195 
196  /**
197  * Applies r,g,b coloring to the map.
198  *
199  * The color is usually taken from @ref get_time_of_day unless @a tod_override is given, in which
200  * case that color is used.
201  *
202  * @param tod_override The ToD to apply to the map instead of that of the current ToD's.
203  */
204  void update_tod(const time_of_day* tod_override = nullptr);
205 
206  /**
207  * Add r,g,b to the colors for all images displayed on the map.
208  *
209  * Used for special effects like flashes.
210  */
211  void adjust_color_overlay(int r, int g, int b);
213 
214  virtual bool in_game() const { return false; }
215  virtual bool in_editor() const { return false; }
216 
217  /** Virtual functions shadowed in game_display. These are needed to generate reports easily, without dynamic casting. Hope to factor out eventually. */
218  virtual const map_location & displayed_unit_hex() const { return map_location::null_location(); }
219  virtual int playing_side() const { return -100; } //In this case give an obviously wrong answer to fail fast, since this could actually cause a big bug. */
220  virtual const std::set<std::string>& observers() const { static const std::set<std::string> fake_obs = std::set<std::string> (); return fake_obs; }
221 
222  /**
223  * mapx is the width of the portion of the display which shows the game area.
224  * Between mapx and x is the sidebar region.
225  */
226 
227  const rect& minimap_area() const;
228  const rect& palette_area() const;
229  const rect& unit_image_area() const;
230 
231  /**
232  * Returns the maximum area used for the map
233  * regardless to resolution and view size
234  */
235  rect max_map_area() const;
236 
237  /**
238  * Returns the area used for the map
239  */
240  rect map_area() const;
241 
242  /**
243  * Returns the available area for a map, this may differ
244  * from the above. This area will get the background area
245  * applied to it.
246  */
247  rect map_outside_area() const;
248 
249  /** Check if the bbox of the hex at x,y has pixels outside the area rectangle. */
250  static bool outside_area(const SDL_Rect& area, const int x,const int y);
251 
252  /**
253  * Function which returns the width of a hex in pixels,
254  * up to where the next hex starts.
255  * (i.e. not entirely from tip to tip -- use hex_size()
256  * to get the distance from tip to tip)
257  */
258  static int hex_width() { return (zoom_*3)/4; }
259 
260  /**
261  * Function which returns the size of a hex in pixels
262  * (from top tip to bottom tip or left edge to right edge).
263  */
264  static int hex_size(){ return zoom_; }
265 
266  /** Returns the current zoom factor. */
267  static double get_zoom_factor()
268  {
269  return static_cast<double>(zoom_) / static_cast<double>(game_config::tile_size);
270  }
271 
272  /** Scale the width and height of a rect by the current zoom factor */
273  static rect scaled_to_zoom(const SDL_Rect& r)
274  {
275  const double zf = get_zoom_factor();
276  return {r.x, r.y, int(r.w * zf), int(r.h * zf)};
277  }
278 
279  static point scaled_to_zoom(const point& p)
280  {
281  const double zf = get_zoom_factor();
282  return {int(p.x * zf), int(p.y * zf)};
283  }
284 
285  /**
286  * given x,y co-ordinates of an onscreen pixel, will return the
287  * location of the hex that this pixel corresponds to.
288  * Returns an invalid location if the mouse isn't over any valid location.
289  */
290  const map_location hex_clicked_on(int x, int y) const;
291 
292  /**
293  * given x,y co-ordinates of a pixel on the map, will return the
294  * location of the hex that this pixel corresponds to.
295  * Returns an invalid location if the mouse isn't over any valid location.
296  */
297  const map_location pixel_position_to_hex(int x, int y) const;
298 
299  /**
300  * given x,y co-ordinates of the mouse, will return the location of the
301  * hex in the minimap that the mouse is currently over, or an invalid
302  * location if the mouse isn't over the minimap.
303  */
304  map_location minimap_location_on(int x, int y);
305 
306  const map_location& selected_hex() const { return selectedHex_; }
307  const map_location& mouseover_hex() const { return mouseoverHex_; }
308 
309  virtual void select_hex(map_location hex);
310  virtual void highlight_hex(map_location hex);
311 
312  /** Function to invalidate the game status displayed on the sidebar. */
314 
315  /** Functions to get the on-screen positions of hexes. */
316  int get_location_x(const map_location& loc) const;
317  int get_location_y(const map_location& loc) const;
318  point get_location(const map_location& loc) const;
319 
320  /**
321  * Rectangular area of hexes, allowing to decide how the top and bottom
322  * edges handles the vertical shift for each parity of the x coordinate
323  */
325  int left;
326  int right;
327  int top[2]; // for even and odd values of x, respectively
328  int bottom[2];
329 
330  /** very simple iterator to walk into the rect_of_hexes */
331  struct iterator {
333  : loc_(loc), rect_(rect){}
334 
335  /** increment y first, then when reaching bottom, increment x */
336  iterator& operator++();
337  bool operator==(const iterator &that) const { return that.loc_ == loc_; }
338  bool operator!=(const iterator &that) const { return that.loc_ != loc_; }
339  const map_location& operator*() const {return loc_;}
340 
341  typedef std::forward_iterator_tag iterator_category;
343  typedef int difference_type;
344  typedef const map_location *pointer;
345  typedef const map_location &reference;
346 
347  private:
350  };
352 
353  iterator begin() const;
354  iterator end() const;
355  };
356 
357  /** Return the rectangular area of hexes overlapped by r (r is in screen coordinates) */
358  const rect_of_hexes hexes_under_rect(const SDL_Rect& r) const;
359 
360  /** Returns the rectangular area of visible hexes */
362 
363  /** Returns true if location (x,y) is covered in shroud. */
364  bool shrouded(const map_location& loc) const;
365 
366  /** Returns true if location (x,y) is covered in fog. */
367  bool fogged(const map_location& loc) const;
368 
369  /** Capture a (map-)screenshot into a surface. */
370  surface screenshot(bool map_screenshot = false);
371 
372  /** Marks everything for rendering including all tiles and sidebar.
373  * Also calls redraw observers. */
374  void queue_rerender();
375 
376  /** Queues repainting to the screen, but doesn't rerender. */
377  void queue_repaint();
378 
379  /** Adds a redraw observer, a function object to be called when a
380  * full rerender is queued. */
381  void add_redraw_observer(std::function<void(display&)> f);
382 
383  /** Clear the redraw observers */
384  void clear_redraw_observers();
385 
386  theme& get_theme() { return theme_; }
387  void set_theme(const std::string& new_theme);
388 
389  /**
390  * Retrieves a pointer to a theme UI button.
391  *
392  * @note The returned pointer may either be nullptr, meaning the button
393  * isn't defined by the current theme, or point to a valid
394  * gui::button object. However, the objects retrieved will be
395  * destroyed and recreated by draw() method calls. Do *NOT* store
396  * these pointers for longer than strictly necessary to
397  * accomplish a specific task before the next screen refresh.
398  */
399  std::shared_ptr<gui::button> find_action_button(const std::string& id);
400  std::shared_ptr<gui::button> find_menu_button(const std::string& id);
401 
402  void create_buttons();
403 
404  void layout_buttons();
405 
406  void draw_buttons();
407 
408  /** Update the given report. Actual drawing is done in draw_report(). */
409  void refresh_report(const std::string& report_name, const config * new_cfg=nullptr);
410 
411  /**
412  * Draw the specified report.
413  *
414  * If test_run is true, it will simulate the draw without actually
415  * drawing anything. This will add any overflowing information to the
416  * report tooltip, and also registers the tooltip.
417  */
418  void draw_report(const std::string& report_name, bool test_run = false);
419 
420  /** Draw all reports in the given region.
421  * Returns true if something was drawn, false otherwise. */
422  bool draw_reports(const rect& region);
423 
424  void draw_minimap_units();
425 
426  /** Function to invalidate all tiles. */
427  void invalidate_all();
428 
429  /** Function to invalidate a specific tile for redrawing. */
430  bool invalidate(const map_location& loc);
431 
432  bool invalidate(const std::set<map_location>& locs);
433 
434  /**
435  * If this set is partially invalidated, invalidate all its hexes.
436  * Returns if any new invalidation was needed
437  */
438  bool propagate_invalidation(const std::set<map_location>& locs);
439 
440  /** invalidate all hexes under the rectangle rect (in screen coordinates) */
441  bool invalidate_locations_in_rect(const SDL_Rect& rect);
442  bool invalidate_visible_locations_in_rect(const SDL_Rect& rect);
443 
444  /**
445  * Function to invalidate animated terrains and units which may have changed.
446  */
447  void invalidate_animations();
448 
449  /**
450  * Per-location invalidation called by invalidate_animations()
451  * Extra game per-location invalidation (village ownership)
452  */
454 
456 
458 
459  void update_fps_label();
460  void clear_fps_label();
461  void update_fps_count();
462 
463  /** Rebuild all dynamic terrain. */
464  void rebuild_all();
465 
466  const theme::action* action_pressed();
467  const theme::menu* menu_pressed();
468 
469  void set_diagnostic(const std::string& msg);
470 
471  double turbo_speed() const;
472 
473  void bounds_check_position();
474  void bounds_check_position(int& xpos, int& ypos) const;
475 
476  /**
477  * Scrolls the display by xmov,ymov pixels.
478  * Invalidation and redrawing will be scheduled.
479  * @return true if the map actually moved.
480  */
481  bool scroll(int xmov, int ymov, bool force = false);
482 
483  /** Zooms the display in (true) or out (false). */
484  bool set_zoom(bool increase);
485 
486  /** Sets the display zoom to the specified amount. */
487  bool set_zoom(unsigned int amount, const bool validate_value_and_set_index = true);
488 
489  static bool zoom_at_max();
490  static bool zoom_at_min();
491 
492  /** Sets the zoom amount to the default. */
493  void toggle_default_zoom();
494 
495  bool view_locked() const { return view_locked_; }
496 
497  /** Sets whether the map view is locked (e.g. so the user can't scroll away) */
498  void set_view_locked(bool value) { view_locked_ = value; }
499 
501 
502  /**
503  * Scroll such that location loc is on-screen.
504  * WARP jumps to loc; SCROLL uses scroll speed;
505  * ONSCREEN only scrolls if x,y is offscreen
506  * force : scroll even if preferences tell us not to,
507  * or the view is locked.
508  */
509  void scroll_to_tile(const map_location& loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true,bool force = true);
510 
511  /**
512  * Scroll such that location loc1 is on-screen.
513  * It will also try to make it such that loc2 is on-screen,
514  * but this is not guaranteed. For ONSCREEN scrolls add_spacing
515  * sets the desired minimum distance from the border in hexes.
516  */
517  void scroll_to_tiles(map_location loc1, map_location loc2,
518  SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true,
519  double add_spacing=0.0, bool force=true);
520 
521  /** Scroll to fit as many locations on-screen as possible, starting with the first. */
522  void scroll_to_tiles(const std::vector<map_location>::const_iterator & begin,
523  const std::vector<map_location>::const_iterator & end,
524  SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true,
525  bool only_if_possible=false, double add_spacing=0.0,
526  bool force=true);
527  /** Scroll to fit as many locations on-screen as possible, starting with the first. */
528  void scroll_to_tiles(const std::vector<map_location>& locs,
529  SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true,
530  bool only_if_possible=false,
531  double add_spacing=0.0, bool force=true)
532  {
533  scroll_to_tiles(locs.begin(), locs.end(), scroll_type, check_fogged,
534  only_if_possible, add_spacing, force);
535  }
536 
537  /** Expose the event, so observers can be notified about map scrolling. */
539 
540  /** Check if a tile is fully visible on screen. */
541  bool tile_fully_on_screen(const map_location& loc) const;
542 
543  /** Checks if location @a loc or one of the adjacent tiles is visible on screen. */
544  bool tile_nearly_on_screen(const map_location &loc) const;
545 
546  /** Prevent the game display from drawing.
547  * Used while story screen is showing to prevent flicker. */
548  void set_prevent_draw(bool pd) { prevent_draw_ = pd; }
549  bool get_prevent_draw() { return prevent_draw_; }
550 
551 private:
552  bool prevent_draw_ = false;
553 
554 public:
555  /** ToD mask smooth fade */
556  void fade_tod_mask(const std::string& old, const std::string& new_);
557 
558  /** Screen fade */
559  void fade_to(const color_t& color, int duration);
560  void set_fade(const color_t& color);
561 
562 private:
563  color_t fade_color_ = {0,0,0,0};
564 
565 public:
566  /*-------------------------------------------------------*/
567  /* top_level_drawable interface (called by draw_manager) */
568  /*-------------------------------------------------------*/
569 
570  /** Update animations and internal state */
571  virtual void update() override;
572 
573  /** Finalize screen layout. */
574  virtual void layout() override;
575 
576  /** Update offscreen render buffers. */
577  virtual void render() override;
578 
579  /** Paint the indicated region to the screen. */
580  virtual bool expose(const rect& region) override;
581 
582  /** Return the current draw location of the display, on the screen. */
583  virtual rect screen_location() override;
584 
585 private:
586  /** Render textures, for intermediate rendering. */
589 
590  /** Ensure render textures are valid and correct. */
591  void update_render_textures();
592 
593  /** Draw/redraw the off-map background area.
594  * This updates both render textures. */
596 
597  /** Perform rendering of invalidated items. */
598  void draw();
599 
600 public:
601  map_labels& labels();
602  const map_labels& labels() const;
603 
604  /** Holds options for calls to function 'announce' (@ref announce). */
606  {
607  /** Lifetime measured in milliseconds. */
608  int lifetime;
609 
610  /**
611  * An announcement according these options should replace the
612  * previous announce (typical of fast announcing) or not
613  * (typical of movement feedback).
614  */
616 
618  : lifetime(1600)
619  , discard_previous(false)
620  {
621  }
622  };
623 
624  /** Announce a message prominently. */
625  void announce(const std::string& msg,
626  const color_t& color = font::GOOD_COLOR,
627  const announce_options& options = announce_options());
628 
629  /**
630  * Schedule the minimap for recalculation.
631  * Useful if any terrain in the map has changed.
632  */
633  void recalculate_minimap();
634 
635  /**
636  * Schedule the minimap to be redrawn.
637  * Useful if units have moved about on the map.
638  */
639  void redraw_minimap();
640 
641 private:
642  /** Actually draw the minimap. */
643  void draw_minimap();
644 
645 public:
646 
647  virtual const time_of_day& get_time_of_day(const map_location& loc = map_location::null_location()) const;
648 
649  virtual bool has_time_area() const {return false;}
650 
651  void blindfold(bool flag);
652  bool is_blindfolded() const;
653 
654  void write(config& cfg) const;
655 
656 private:
657  void read(const config& cfg);
658 
659 public:
660  /** Init the flag list and the team colors used by ~TC */
661  void init_flags();
662 
663  /** Rebuild the flag list (not team colors) for a single side. */
664  void reinit_flags_for_team(const team&);
665  void reset_reports(reports& reports_object)
666  {
667  reports_object_ = &reports_object;
668  }
669 
670 private:
671  void init_flags_for_side_internal(std::size_t side, const std::string& side_color);
672 
674 
675 protected:
676  //TODO sort
679  std::weak_ptr<wb::manager> wb_;
680 
681  typedef std::map<map_location, std::string> exclusive_unit_draw_requests_t;
682  /** map of hexes where only one unit should be drawn, the one identified by the associated id string */
684 
686 
687  /**
688  * Get the clipping rectangle for drawing.
689  * Virtual since the editor might use a slightly different approach.
690  */
691  virtual rect get_clip_rect() const;
692 
693  /**
694  * Only called when there's actual redrawing to do. Loops through
695  * invalidated locations and redraws them. Derived classes can override
696  * this, possibly to insert pre- or post-processing around a call to the
697  * base class's function.
698  */
699  virtual void draw_invalidated();
700 
701  /**
702  * Redraws a single gamemap location.
703  */
704  virtual void draw_hex(const map_location& loc);
705 
707 
708  void get_terrain_images(const map_location &loc,
709  const std::string& timeid,
711 
712  std::vector<texture> get_fog_shroud_images(const map_location& loc, image::TYPE image_type);
713 
714  void scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type,bool force = true);
715 
716  static void fill_images_list(const std::string& prefix, std::vector<std::string>& images);
717 
718  static const std::string& get_variant(const std::vector<std::string>& variants, const map_location &loc);
719 
720  std::size_t currentTeam_;
721  bool dont_show_all_; //const team *viewpoint_;
722  /**
723  * Position of the top-left corner of the viewport, in pixels.
724  *
725  * Dependent on zoom_.. For example, ypos_==72 only means we're one
726  * hex below the top of the map when zoom_ == 72 (the default value).
727  */
728  int xpos_, ypos_;
731  /**
732  * The current zoom, in pixels (on screen) per 72 pixels (in the
733  * graphic assets), i.e., 72 means 100%.
734  */
735  static unsigned int zoom_;
737  /** The previous value of zoom_. */
738  static unsigned int last_zoom_;
739  const std::unique_ptr<fake_unit_manager> fake_unit_man_;
740  const std::unique_ptr<terrain_builder> builder_;
747  const std::unique_ptr<map_labels> map_labels_;
749 
750  /** Event raised when the map is being scrolled */
752 
753  boost::circular_buffer<unsigned> frametimes_; // in milliseconds
755  unsigned int fps_counter_;
756  std::chrono::seconds fps_start_;
757  unsigned int fps_actual_;
758  uint32_t last_frame_finished_ = 0u;
759 
760  // Not set by the initializer:
761  std::map<std::string, rect> reportLocations_;
762  std::map<std::string, texture> reportSurfaces_;
763  std::map<std::string, config> reports_;
764  std::vector<std::shared_ptr<gui::button>> menu_buttons_, action_buttons_;
765  std::set<map_location> invalidated_;
766  // If we're transitioning from one time of day to the next,
767  // then we will use these two masks on top of all hexes when we blit.
770  uint8_t tod_hex_alpha1 = 0;
771  uint8_t tod_hex_alpha2 = 0;
772  std::vector<std::string> fog_images_;
773  std::vector<std::string> shroud_images_;
774 
778 
779  /** Local cache for preferences::animate_map, since it is constantly queried. */
781 
782  /** Local version of preferences::animate_water, used to detect when it's changed. */
784 
785 private:
786 
787  texture get_flag(const map_location& loc);
788 
789  /** Animated flags for each team */
790  std::vector<animated<image::locator>> flags_;
791 
792  // This vector is a class member to avoid repeated memory allocations in get_terrain_images(),
793  // which turned out to be a significant bottleneck while profiling.
794  std::vector<texture> terrain_image_vector_;
795 
796 public:
797  /**
798  * The layers to render something on. This value should never be stored
799  * it's the internal drawing order and adding removing and reordering
800  * the layers should be safe.
801  * If needed in WML use the name and map that to the enum value.
802  */
804  LAYER_TERRAIN_BG, /**<
805  * Layer for the terrain drawn behind the
806  * unit.
807  */
808  LAYER_GRID_TOP, /**< Top half part of grid image */
809  LAYER_MOUSEOVER_OVERLAY, /**< Mouseover overlay used by editor*/
810  LAYER_FOOTSTEPS, /**< Footsteps showing path from unit to mouse */
811  LAYER_MOUSEOVER_TOP, /**< Top half of image following the mouse */
812  LAYER_UNIT_FIRST, /**< Reserve layers to be selected for WML. */
813  LAYER_UNIT_BG = LAYER_UNIT_FIRST+10, /**< Used for the ellipse behind the unit. */
814  LAYER_UNIT_DEFAULT=LAYER_UNIT_FIRST+40,/**<default layer for drawing units */
816  * Layer for the terrain drawn in front of
817  * the unit.
818  */
819  LAYER_GRID_BOTTOM, /**<
820  * Used for the bottom half part of grid image.
821  * Should be under moving units, to avoid masking south move.
822  */
823  LAYER_UNIT_MOVE_DEFAULT=LAYER_UNIT_FIRST+60/**<default layer for drawing moving units */,
825  * Used for the ellipse in front of the
826  * unit.
827  */
828  LAYER_UNIT_MISSILE_DEFAULT = LAYER_UNIT_FIRST+90, /**< default layer for missile frames*/
830  LAYER_REACHMAP, /**< "black stripes" on unreachable hexes. */
831  LAYER_MOUSEOVER_BOTTOM, /**< Bottom half of image following the mouse */
832  LAYER_FOG_SHROUD, /**< Fog and shroud. */
833  LAYER_ARROWS, /**< Arrows from the arrows framework. Used for planned moves display. */
834  LAYER_ACTIONS_NUMBERING, /**< Move numbering for the whiteboard. */
835  LAYER_SELECTED_HEX, /**< Image on the selected unit */
836  LAYER_ATTACK_INDICATOR, /**< Layer which holds the attack indicator. */
837  LAYER_UNIT_BAR, /**<
838  * Unit bars and overlays are drawn on this
839  * layer (for testing here).
840  */
841  LAYER_MOVE_INFO, /**< Movement info (defense%, etc...). */
842  LAYER_LINGER_OVERLAY, /**< The overlay used for the linger mode. */
843  LAYER_BORDER, /**< The border of the map. */
844  };
845 
846  static void add_submerge_ipf_mod(std::string& image_path, int image_height, double submersion_amount, int shift = 0);
847 
848  /**
849  * Draw text on a hex. (0.5, 0.5) is the center.
850  * The font size is adjusted to the zoom factor.
851  */
852  void draw_text_in_hex(const map_location& loc,
853  const drawing_layer layer, const std::string& text, std::size_t font_size,
854  color_t color, double x_in_hex=0.5, double y_in_hex=0.5);
855 
856 protected:
857 
858  //TODO sort
859  std::size_t activeTeam_;
860 
861  /**
862  * Helper for rendering the map by ordering draw operations.
863  *
864  * In order to render a hex properly, they need to be rendered per row.
865  * In this row several layers need to be drawn at the same time, mainly
866  * the unit and the background terrain. This is needed since both can spill
867  * into the next hex. The foreground terrain needs to be drawn before to
868  * avoid decapitating a unit.
869  *
870  * In other words:
871  * for every layer
872  * for every row (starting from the top)
873  * for every hex in the row
874  * ...
875  *
876  * this is modified to:
877  * for every layer group
878  * for every row (starting from the top)
879  * for every layer in the group
880  * for every hex in the row
881  * ...
882  */
883  struct draw_helper
884  {
885  /** Controls the ordering of draw calls by layer and location. */
886  const uint32_t key;
887 
888  /** Handles the actual drawing at this location. */
889  std::function<void(const rect&)> do_draw;
890 
891  /** The screen coordinates for the specified hex. This is passed to @ref do_draw */
893 
894  bool operator<(const draw_helper& rhs) const
895  {
896  return key < rhs.key;
897  }
898  };
899 
900  std::list<draw_helper> drawing_buffer_;
901 
902 public:
903  /**
904  * Add an item to the drawing buffer.
905  *
906  * @param layer The layer to draw on.
907  * @param loc The hex the image belongs to, needed for the drawing order.
908  * @param draw_func The draw operation to be run.
909  */
910  void drawing_buffer_add(const drawing_layer layer, const map_location& loc, decltype(draw_helper::do_draw) draw_func);
911 
912 protected:
913 
914  /** Draws the drawing_buffer_ and clears it. */
915  void drawing_buffer_commit();
916 
917  /** Redraws all panels intersecting the given region.
918  * Returns true if something was drawn, false otherwise. */
919  bool draw_all_panels(const rect& region);
920 
921 private:
922  void draw_panel(const theme::panel& panel);
923  void draw_label(const theme::label& label);
924 
925 protected:
926  /** Used to indicate to drawing functions that we are doing a map screenshot */
928 
929 public: //operations for the arrow framework
930 
931  void add_arrow(arrow&);
932 
933  void remove_arrow(arrow&);
934 
935  /** Called by arrow objects when they change. You should not need to call this directly. */
936  void update_arrow(arrow & a);
937 
938 protected:
939 
940  // Tiles lit for showing where unit(s) can reach
941  typedef std::map<map_location,unsigned int> reach_map;
946 
947  typedef std::map<map_location, std::vector<overlay>> overlay_map;
948 
949  virtual overlay_map& get_overlays() = 0;
950 
951 private:
952  /** Handle for the label which displays frames per second. */
954  /** Count work done for the debug info displayed under fps */
957 
958  std::vector<std::function<void(display&)>> redraw_observers_;
959 
960 public:
961  enum DEBUG_FLAG {
962  /** Overlays x,y coords on tiles */
964 
965  /** Overlays terrain codes on tiles */
967 
968  /** Overlays number of bitmaps on tiles */
970 
971  /** Separates background and foreground terrain layers. */
973 
974  /** Toggle to continuously redraw the whole map. */
976 
977  /** Dummy entry to size the bitmask. Keep this last! */
979  };
980 
982  {
983  return debug_flags_.test(flag);
984  }
985 
986  void set_debug_flag(DEBUG_FLAG flag, bool value)
987  {
988  debug_flags_.set(flag, value);
989  }
990 
992  {
993  debug_flags_.flip(flag);
994  }
995 
996 private:
997  /** Currently set debug flags. */
998  std::bitset<__NUM_DEBUG_FLAGS> debug_flags_;
999 
1000  typedef std::list<arrow*> arrows_list_t;
1001  typedef std::map<map_location, arrows_list_t > arrows_map_t;
1002  /** Maps the list of arrows for each location */
1004 
1006 
1007  std::vector<std::tuple<int, int, int>> fps_history_;
1008 
1009 protected:
1011 };
1012 
1014 {
1015  blindfold(display& d, bool lock=true) : display_(d), blind(lock) {
1016  if(blind) {
1017  display_.blindfold(true);
1018  }
1019  }
1020 
1022  unblind();
1023  }
1024 
1025  void unblind() {
1026  if(blind) {
1027  display_.blindfold(false);
1029  blind = false;
1030  }
1031  }
1032 
1033 private:
1035  bool blind;
1036 };
Animate units.
double g
Definition: astarsearch.cpp:65
Class that keeps track of all the keys on the keyboard.
Definition: key.hpp:29
Arrows destined to be drawn on the map.
Definition: arrow.hpp:30
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
virtual const gamemap & map() const =0
virtual const std::vector< team > & teams() const =0
virtual const unit_map & units() const =0
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition: display.hpp:87
arrows_map_t arrows_map_
Maps the list of arrows for each location.
Definition: display.hpp:1003
int xpos_
Position of the top-left corner of the viewport, in pixels.
Definition: display.hpp:728
void reset_reports(reports &reports_object)
Definition: display.hpp:665
bool map_screenshot_
Used to indicate to drawing functions that we are doing a map screenshot.
Definition: display.hpp:927
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:1445
void layout_buttons()
Definition: display.cpp:826
static void add_submerge_ipf_mod(std::string &image_path, int image_height, double submersion_amount, int shift=0)
Definition: display.cpp:1473
int viewing_side() const
The 1-based equivalent of the 0-based viewing_team() function.
Definition: display.hpp:130
bool redraw_background_
Definition: display.hpp:743
void update_render_textures()
Ensure render textures are valid and correct.
Definition: display.cpp:2511
void toggle_debug_flag(DEBUG_FLAG flag)
Definition: display.hpp:991
static unsigned int last_zoom_
The previous value of zoom_.
Definition: display.hpp:738
void write(config &cfg) const
Definition: display.cpp:3249
const unit_map & get_units() const
Definition: display.hpp:148
const display_context & get_disp_context() const
Definition: display.hpp:189
static bool zoom_at_min()
Definition: display.cpp:1858
std::map< map_location, std::vector< overlay > > overlay_map
Definition: display.hpp:947
void get_terrain_images(const map_location &loc, const std::string &timeid, TERRAIN_TYPE terrain_type)
Definition: display.cpp:1040
void remove_overlay(const map_location &loc)
remove_overlay will remove all overlays on a tile.
Definition: display.cpp:132
virtual bool has_time_area() const
Definition: display.hpp:649
map_location selectedHex_
Definition: display.hpp:775
std::size_t viewing_team() const
The viewing team is the team currently viewing the game.
Definition: display.hpp:122
void recalculate_minimap()
Schedule the minimap for recalculation.
Definition: display.cpp:1621
void clear_fps_label()
Definition: display.cpp:1361
void redraw_minimap()
Schedule the minimap to be redrawn.
Definition: display.cpp:1641
point get_location(const map_location &loc) const
Definition: display.cpp:722
unsigned int fps_counter_
Definition: display.hpp:755
bool invalidate_locations_in_rect(const SDL_Rect &rect)
invalidate all hexes under the rectangle rect (in screen coordinates)
Definition: display.cpp:3147
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:562
virtual void render() override
Update offscreen render buffers.
Definition: display.cpp:2428
void init_flags_for_side_internal(std::size_t side, const std::string &side_color)
Definition: display.cpp:285
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:137
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:554
void fade_tod_mask(const std::string &old, const std::string &new_)
ToD mask smooth fade.
Definition: display.cpp:2214
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3094
virtual const time_of_day & get_time_of_day(const map_location &loc=map_location::null_location()) const
Definition: display.cpp:404
uint8_t tod_hex_alpha1
Definition: display.hpp:770
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:1605
bool view_locked_
Definition: display.hpp:729
std::list< arrow * > arrows_list_t
Definition: display.hpp:1000
drawing_layer
The layers to render something on.
Definition: display.hpp:803
@ LAYER_UNIT_FG
Used for the ellipse in front of the unit.
Definition: display.hpp:824
@ LAYER_UNIT_LAST
Definition: display.hpp:829
@ LAYER_MOUSEOVER_BOTTOM
Bottom half of image following the mouse.
Definition: display.hpp:831
@ LAYER_ATTACK_INDICATOR
Layer which holds the attack indicator.
Definition: display.hpp:836
@ LAYER_BORDER
The border of the map.
Definition: display.hpp:843
@ LAYER_UNIT_FIRST
Reserve layers to be selected for WML.
Definition: display.hpp:812
@ LAYER_MOVE_INFO
Movement info (defense%, etc...).
Definition: display.hpp:841
@ LAYER_ACTIONS_NUMBERING
Move numbering for the whiteboard.
Definition: display.hpp:834
@ LAYER_MOUSEOVER_OVERLAY
Mouseover overlay used by editor.
Definition: display.hpp:809
@ LAYER_UNIT_MISSILE_DEFAULT
default layer for missile frames
Definition: display.hpp:828
@ LAYER_TERRAIN_BG
Layer for the terrain drawn behind the unit.
Definition: display.hpp:804
@ LAYER_UNIT_DEFAULT
default layer for drawing units
Definition: display.hpp:814
@ LAYER_FOG_SHROUD
Fog and shroud.
Definition: display.hpp:832
@ LAYER_UNIT_MOVE_DEFAULT
default layer for drawing moving units
Definition: display.hpp:823
@ LAYER_GRID_BOTTOM
Used for the bottom half part of grid image.
Definition: display.hpp:819
@ LAYER_UNIT_BG
Used for the ellipse behind the unit.
Definition: display.hpp:813
@ LAYER_FOOTSTEPS
Footsteps showing path from unit to mouse.
Definition: display.hpp:810
@ LAYER_LINGER_OVERLAY
The overlay used for the linger mode.
Definition: display.hpp:842
@ LAYER_GRID_TOP
Top half part of grid image.
Definition: display.hpp:808
@ LAYER_TERRAIN_FG
Layer for the terrain drawn in front of the unit.
Definition: display.hpp:815
@ LAYER_SELECTED_HEX
Image on the selected unit.
Definition: display.hpp:835
@ LAYER_ARROWS
Arrows from the arrows framework.
Definition: display.hpp:833
@ LAYER_UNIT_BAR
Unit bars and overlays are drawn on this layer (for testing here).
Definition: display.hpp:837
@ LAYER_REACHMAP
"black stripes" on unreachable hexes.
Definition: display.hpp:830
@ LAYER_MOUSEOVER_TOP
Top half of image following the mouse.
Definition: display.hpp:811
double turbo_speed() const
Definition: display.cpp:2200
void set_prevent_draw(bool pd)
Prevent the game display from drawing.
Definition: display.hpp:548
@ ONSCREEN
Definition: display.hpp:500
@ ONSCREEN_WARP
Definition: display.hpp:500
@ SCROLL
Definition: display.hpp:500
int current_frame_sample_
Definition: display.hpp:754
int invalidated_hexes_
Count work done for the debug info displayed under fps.
Definition: display.hpp:955
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:423
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:382
void set_fade(const color_t &color)
Definition: display.cpp:2270
void queue_repaint()
Queues repainting to the screen, but doesn't rerender.
Definition: display.cpp:2327
bool reach_map_changed_
Definition: display.hpp:944
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:264
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
Definition: display.cpp:712
static double get_zoom_factor()
Returns the current zoom factor.
Definition: display.hpp:267
const rect & unit_image_area() const
Definition: display.cpp:497
TERRAIN_TYPE
Definition: display.hpp:706
@ FOREGROUND
Definition: display.hpp:706
@ BACKGROUND
Definition: display.hpp:706
bool scroll(int xmov, int ymov, bool force=false)
Scrolls the display by xmov,ymov pixels.
Definition: display.cpp:1753
bool propagate_invalidation(const std::set< map_location > &locs)
If this set is partially invalidated, invalidate all its hexes.
Definition: display.cpp:3115
void clear_redraw_observers()
Clear the redraw observers.
Definition: display.cpp:2339
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
Definition: display.hpp:313
const theme::action * action_pressed()
Definition: display.cpp:1573
std::shared_ptr< gui::button > find_action_button(const std::string &id)
Retrieves a pointer to a theme UI button.
Definition: display.cpp:806
void set_theme(const std::string &new_theme)
Definition: display.cpp:253
void rebuild_all()
Rebuild all dynamic terrain.
Definition: display.cpp:457
void change_display_context(const display_context *dc)
Definition: display.cpp:468
void add_redraw_observer(std::function< void(display &)> f)
Adds a redraw observer, a function object to be called when a full rerender is queued.
Definition: display.cpp:2334
void clear_exclusive_draws()
Cancels all the exclusive draw requests.
Definition: display.hpp:147
unsigned int fps_actual_
Definition: display.hpp:757
virtual overlay_map & get_overlays()=0
theme theme_
Definition: display.hpp:730
tod_color color_adjust_
Definition: display.hpp:1005
bool get_prevent_draw()
Definition: display.hpp:549
virtual void layout() override
Finalize screen layout.
Definition: display.cpp:2397
virtual void highlight_hex(map_location hex)
Definition: display.cpp:1523
void update_tod(const time_of_day *tod_override=nullptr)
Applies r,g,b coloring to the map.
Definition: display.cpp:410
static bool zoom_at_max()
Definition: display.cpp:1853
static display * singleton_
Definition: display.hpp:1010
std::shared_ptr< gui::button > find_menu_button(const std::string &id)
Definition: display.cpp:816
void render_map_outside_area()
Draw/redraw the off-map background area.
Definition: display.cpp:2556
map_labels & labels()
Definition: display.cpp:2572
void set_team(std::size_t team, bool observe=false)
Sets the team controlled by the player using the computer.
Definition: display.cpp:358
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:576
void remove_arrow(arrow &)
Definition: display.cpp:3225
@ DEBUG_COORDINATES
Overlays x,y coords on tiles.
Definition: display.hpp:963
@ DEBUG_BENCHMARK
Toggle to continuously redraw the whole map.
Definition: display.hpp:975
@ __NUM_DEBUG_FLAGS
Dummy entry to size the bitmask.
Definition: display.hpp:978
@ DEBUG_NUM_BITMAPS
Overlays number of bitmaps on tiles.
Definition: display.hpp:969
@ DEBUG_FOREGROUND
Separates background and foreground terrain layers.
Definition: display.hpp:972
@ DEBUG_TERRAIN_CODES
Overlays terrain codes on tiles.
Definition: display.hpp:966
void process_reachmap_changes()
Definition: display.cpp:3266
void draw_minimap_units()
Definition: display.cpp:1706
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:2037
void invalidate_animations_location(const map_location &loc)
Per-location invalidation called by invalidate_animations() Extra game per-location invalidation (vil...
Definition: display.cpp:3162
map_location mouseoverHex_
Definition: display.hpp:776
bool fogged(const map_location &loc) const
Returns true if location (x,y) is covered in fog.
Definition: display.cpp:707
bool view_locked() const
Definition: display.hpp:495
const gamemap & get_map() const
Definition: display.hpp:105
bool set_zoom(bool increase)
Zooms the display in (true) or out (false).
Definition: display.cpp:1863
std::map< std::string, rect > reportLocations_
Definition: display.hpp:761
const rect_of_hexes get_visible_hexes() const
Returns the rectangular area of visible hexes.
Definition: display.hpp:361
bool invalidateAll_
Definition: display.hpp:744
int drawn_hexes_
Definition: display.hpp:956
texture get_flag(const map_location &loc)
Definition: display.cpp:338
tod_color get_color_overlay() const
Definition: display.hpp:212
void invalidate_all()
Function to invalidate all tiles.
Definition: display.cpp:3087
std::map< std::string, config > reports_
Definition: display.hpp:763
std::bitset< __NUM_DEBUG_FLAGS > debug_flags_
Currently set debug flags.
Definition: display.hpp:998
SDL_Rect minimap_location_
Definition: display.hpp:742
map_location get_middle_location() const
Definition: display.cpp:3243
void bounds_check_position()
Definition: display.cpp:2182
surface screenshot(bool map_screenshot=false)
Capture a (map-)screenshot into a surface.
Definition: display.cpp:762
void init_flags()
Init the flag list and the team colors used by ~TC.
Definition: display.cpp:264
std::vector< std::shared_ptr< gui::button > > action_buttons_
Definition: display.hpp:764
void drawing_buffer_add(const drawing_layer layer, const map_location &loc, decltype(draw_helper::do_draw) draw_func)
Add an item to the drawing buffer.
Definition: display.cpp:1259
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:650
void scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type, bool force=true)
Definition: display.cpp:1955
virtual int playing_side() const
Definition: display.hpp:219
rect map_outside_area() const
Returns the available area for a map, this may differ from the above.
Definition: display.cpp:545
bool prevent_draw_
Definition: display.hpp:552
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:683
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:1945
bool team_valid() const
Definition: display.cpp:697
void reload_map()
Updates internals that cache map size.
Definition: display.cpp:462
rect max_map_area() const
Returns the maximum area used for the map regardless to resolution and view size.
Definition: display.cpp:502
void update_fps_count()
Definition: display.cpp:1551
halo::manager & get_halo_manager()
Definition: display.hpp:194
bool tile_fully_on_screen(const map_location &loc) const
Check if a tile is fully visible on screen.
Definition: display.cpp:1938
void update_fps_label()
Definition: display.cpp:1309
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:730
std::map< map_location, arrows_list_t > arrows_map_t
Definition: display.hpp:1001
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:2049
bool is_blindfolded() const
Definition: display.cpp:482
std::vector< texture > terrain_image_vector_
Definition: display.hpp:794
std::vector< std::string > fog_images_
Definition: display.hpp:772
virtual bool in_editor() const
Definition: display.hpp:215
int fps_handle_
Handle for the label which displays frames per second.
Definition: display.hpp:953
texture tod_hex_mask2
Definition: display.hpp:769
theme & get_theme()
Definition: display.hpp:386
bool invalidate_visible_locations_in_rect(const SDL_Rect &rect)
Definition: display.cpp:3142
std::map< map_location, std::string > exclusive_unit_draw_requests_t
Definition: display.hpp:681
std::vector< std::function< void(display &)> > redraw_observers_
Definition: display.hpp:958
void read(const config &cfg)
Definition: display.cpp:3258
const theme::menu * menu_pressed()
Definition: display.cpp:1589
const std::unique_ptr< terrain_builder > builder_
Definition: display.hpp:740
virtual const map_location & displayed_unit_hex() const
Virtual functions shadowed in game_display.
Definition: display.hpp:218
std::vector< animated< image::locator > > flags_
Animated flags for each team.
Definition: display.hpp:790
const map_location & selected_hex() const
Definition: display.hpp:306
events::generic_event & scroll_event() const
Expose the event, so observers can be notified about map scrolling.
Definition: display.hpp:538
static void fill_images_list(const std::string &prefix, std::vector< std::string > &images)
Definition: display.cpp:429
int ypos_
Definition: display.hpp:728
void draw_report(const std::string &report_name, bool test_run=false)
Draw the specified report.
Definition: display.cpp:2913
std::set< map_location > invalidated_
Definition: display.hpp:765
color_t fade_color_
Definition: display.hpp:563
std::vector< texture > get_fog_shroud_images(const map_location &loc, image::TYPE image_type)
Definition: display.cpp:954
void fade_to(const color_t &color, int duration)
Screen fade.
Definition: display.cpp:2237
void queue_rerender()
Marks everything for rendering including all tiles and sidebar.
Definition: display.cpp:2275
std::size_t activeTeam_
Definition: display.hpp:859
void create_buttons()
Definition: display.cpp:876
int blindfold_ctr_
Definition: display.hpp:673
std::string remove_exclusive_draw(const map_location &loc)
Cancels an exclusive draw request.
Definition: display.cpp:392
bool invalidateGameStatus_
Definition: display.hpp:746
reach_map reach_map_old_
Definition: display.hpp:943
virtual void draw_invalidated()
Only called when there's actual redrawing to do.
Definition: display.cpp:2587
void drawing_buffer_commit()
Draws the drawing_buffer_ and clears it.
Definition: display.cpp:1277
rect map_area() const
Returns the area used for the map.
Definition: display.cpp:519
int zoom_index_
Definition: display.hpp:736
void draw_panel(const theme::panel &panel)
Definition: display.cpp:1371
void set_playing_team(std::size_t team)
set_playing_team sets the team whose turn it currently is
Definition: display.cpp:375
std::chrono::seconds fps_start_
Definition: display.hpp:756
void draw_buttons()
Definition: display.cpp:932
static int hex_width()
Function which returns the width of a hex in pixels, up to where the next hex starts.
Definition: display.hpp:258
void set_debug_flag(DEBUG_FLAG flag, bool value)
Definition: display.hpp:986
void reset_standing_animations()
Definition: display.cpp:3211
bool animate_water_
Local version of preferences::animate_water, used to detect when it's changed.
Definition: display.hpp:783
bool debug_flag_set(DEBUG_FLAG flag) const
Definition: display.hpp:981
void toggle_default_zoom()
Sets the zoom amount to the default.
Definition: display.cpp:1926
virtual rect get_clip_rect() const
Get the clipping rectangle for drawing.
Definition: display.cpp:2582
void scroll_to_tiles(const std::vector< map_location > &locs, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool only_if_possible=false, double add_spacing=0.0, bool force=true)
Scroll to fit as many locations on-screen as possible, starting with the first.
Definition: display.hpp:528
CKey keys_
Definition: display.hpp:777
reports * reports_object_
Definition: display.hpp:748
bool draw_reports(const rect &region)
Draw all reports in the given region.
Definition: display.cpp:3073
void invalidate_animations()
Function to invalidate animated terrains and units which may have changed.
Definition: display.cpp:3173
virtual rect screen_location() override
Return the current draw location of the display, on the screen.
Definition: display.cpp:2503
static const std::string & get_variant(const std::vector< std::string > &variants, const map_location &loc)
Definition: display.cpp:451
virtual bool expose(const rect &region) override
Paint the indicated region to the screen.
Definition: display.cpp:2458
std::list< draw_helper > drawing_buffer_
Definition: display.hpp:900
uint8_t tod_hex_alpha2
Definition: display.hpp:771
std::vector< std::shared_ptr< gui::button > > menu_buttons_
Definition: display.hpp:764
virtual void update() override
Update animations and internal state.
Definition: display.cpp:2380
void draw()
Perform rendering of invalidated items.
Definition: display.cpp:2344
int get_location_y(const map_location &loc) const
Definition: display.cpp:717
const rect & minimap_area() const
mapx is the width of the portion of the display which shows the game area.
Definition: display.cpp:487
texture back_
Definition: display.hpp:588
events::generic_event scroll_event_
Event raised when the map is being scrolled.
Definition: display.hpp:751
bool show_everything() const
Definition: display.hpp:103
terrain_builder & get_builder()
Definition: display.hpp:457
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
Definition: display.cpp:2628
std::size_t currentTeam_
Definition: display.hpp:720
texture tod_hex_mask1
Definition: display.hpp:768
virtual bool in_game() const
Definition: display.hpp:214
virtual ~display()
Definition: display.cpp:243
const rect & palette_area() const
Definition: display.cpp:492
std::map< map_location, unsigned int > reach_map
Definition: display.hpp:941
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:101
std::vector< std::tuple< int, int, int > > fps_history_
Definition: display.hpp:1007
halo::manager halo_man_
Definition: display.hpp:678
void reinit_flags_for_team(const team &)
Rebuild the flag list (not team colors) for a single side.
Definition: display.cpp:280
void draw_minimap()
Actually draw the minimap.
Definition: display.cpp:1646
texture front_
Render textures, for intermediate rendering.
Definition: display.hpp:587
texture minimap_
Definition: display.hpp:741
const map_location & mouseover_hex() const
Definition: display.hpp:307
void update_arrow(arrow &a)
Called by arrow objects when they change.
Definition: display.cpp:3232
void draw_label(const theme::label &label)
Definition: display.cpp:1396
const std::unique_ptr< fake_unit_manager > fake_unit_man_
Definition: display.hpp:739
const display_context * dc_
Definition: display.hpp:677
bool animate_map_
Local cache for preferences::animate_map, since it is constantly queried.
Definition: display.hpp:780
static point scaled_to_zoom(const point &p)
Definition: display.hpp:279
std::vector< std::string > shroud_images_
Definition: display.hpp:773
void set_view_locked(bool value)
Sets whether the map view is locked (e.g.
Definition: display.hpp:498
static rect scaled_to_zoom(const SDL_Rect &r)
Scale the width and height of a rect by the current zoom factor.
Definition: display.hpp:273
virtual const std::set< std::string > & observers() const
Definition: display.hpp:220
static unsigned int zoom_
The current zoom, in pixels (on screen) per 72 pixels (in the graphic assets), i.e....
Definition: display.hpp:735
bool shrouded(const map_location &loc) const
Returns true if location (x,y) is covered in shroud.
Definition: display.cpp:702
bool dont_show_all_
Definition: display.hpp:721
void blindfold(bool flag)
Definition: display.cpp:474
void refresh_report(const std::string &report_name, const config *new_cfg=nullptr)
Update the given report.
Definition: display.cpp:2843
std::weak_ptr< wb::manager > wb_
Definition: display.hpp:679
void add_arrow(arrow &)
Definition: display.cpp:3218
const std::unique_ptr< map_labels > map_labels_
Definition: display.hpp:747
boost::circular_buffer< unsigned > frametimes_
Definition: display.hpp:753
uint32_t last_frame_finished_
Definition: display.hpp:758
void set_diagnostic(const std::string &msg)
Definition: display.cpp:1533
virtual void select_hex(map_location hex)
Definition: display.cpp:1515
int diagnostic_label_
Definition: display.hpp:745
const std::vector< team > & get_teams() const
Definition: display.hpp:107
std::map< std::string, texture > reportSurfaces_
Definition: display.hpp:762
std::size_t playing_team() const
The playing team is the team whose turn it is.
Definition: display.hpp:110
bool draw_all_panels(const rect &region)
Redraws all panels intersecting the given region.
Definition: display.cpp:1423
reach_map reach_map_
Definition: display.hpp:942
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 submerge=0.0f, float z_order=0)
Functions to add and remove overlays from locations.
Definition: display.cpp:119
display(const display_context *dc, std::weak_ptr< wb::manager > wb, reports &reports_object, const std::string &theme_id, const config &level)
Definition: display.cpp:149
Manages a list of fake units for the display object.
Encapsulates the map of the game.
Definition: map.hpp:172
A top-level drawable item (TLD), such as a window.
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:76
The class terrain_builder is constructed from a config object, and a gamemap object.
Definition: builder.hpp:49
Wrapper class to encapsulate creation and management of an SDL_Texture.
Definition: texture.hpp:33
Definition: theme.hpp:43
Container associating units to locations.
Definition: map.hpp:99
This class represents a single unit of a specific type.
Definition: unit.hpp:134
This class is the frontend of the whiteboard framework for the rest of the Wesnoth code.
Definition: manager.hpp:44
Declarations for File-IO.
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:217
const color_t GOOD_COLOR
unsigned int tile_size
Definition: game_config.cpp:51
Definition: display.hpp:45
Functions to load and save images from/to disk.
TYPE
Used to specify the rendering format of images.
Definition: picture.hpp:231
const config & options()
Definition: game.cpp:555
Unit and team statistics.
Definition: display.hpp:49
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:110
Contains the SDL_Rect helper code.
This file contains object "key", which is used to store information about keys while annotation parsi...
bool blind
Definition: display.hpp:1035
blindfold(display &d, bool lock=true)
Definition: display.hpp:1015
void unblind()
Definition: display.hpp:1025
display & display_
Definition: display.hpp:1034
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
Holds options for calls to function 'announce' (announce).
Definition: display.hpp:606
bool discard_previous
An announcement according these options should replace the previous announce (typical of fast announc...
Definition: display.hpp:615
int lifetime
Lifetime measured in milliseconds.
Definition: display.hpp:608
Helper for rendering the map by ordering draw operations.
Definition: display.hpp:884
std::function< void(const rect &)> do_draw
Handles the actual drawing at this location.
Definition: display.hpp:889
const uint32_t key
Controls the ordering of draw calls by layer and location.
Definition: display.hpp:886
rect dest
The screen coordinates for the specified hex.
Definition: display.hpp:892
bool operator<(const draw_helper &rhs) const
Definition: display.hpp:894
very simple iterator to walk into the rect_of_hexes
Definition: display.hpp:331
const map_location & operator*() const
Definition: display.hpp:339
std::forward_iterator_tag iterator_category
Definition: display.hpp:341
iterator & operator++()
increment y first, then when reaching bottom, increment x
Definition: display.cpp:628
const rect_of_hexes & rect_
Definition: display.hpp:349
bool operator==(const iterator &that) const
Definition: display.hpp:337
const map_location * pointer
Definition: display.hpp:344
bool operator!=(const iterator &that) const
Definition: display.hpp:338
iterator(const map_location &loc, const rect_of_hexes &rect)
Definition: display.hpp:332
const map_location & reference
Definition: display.hpp:345
Rectangular area of hexes, allowing to decide how the top and bottom edges handles the vertical shift...
Definition: display.hpp:324
iterator end() const
Definition: display.cpp:645
iterator begin() const
Definition: display.cpp:641
Encapsulates the map of the game.
Definition: location.hpp:38
static const map_location & null_location()
Definition: location.hpp:81
Holds a 2D point.
Definition: point.hpp:25
An abstract description of a rectangle with integer coordinates.
Definition: rect.hpp:47
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57
Small struct to store and manipulate ToD color adjusts.
Definition: time_of_day.hpp:27
mock_party p
Definitions related to theme-support.
#define d
#define f
#define a
#define b