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