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