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