The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
display.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  *
18  * map_display and display: classes which take care of
19  * displaying the map and game-data on the screen.
20  *
21  * The display is divided into two main sections:
22  * - the game area, which displays the tiles of the game board, and units on them,
23  * - and the side bar, which appears on the right hand side.
24  * The side bar display is divided into three sections:
25  * - the minimap, which is displayed at the top right
26  * - the game status, which includes the day/night image,
27  * the turn number, information about the current side,
28  * and information about the hex currently moused over (highlighted)
29  * - the unit status, which displays an image and stats
30  * for the current unit.
31  */
32 
33 #ifndef DISPLAY_H_INCLUDED
34 #define DISPLAY_H_INCLUDED
35 
36 class config;
37 class fake_unit_manager;
38 class terrain_builder;
39 class map_labels;
40 class arrow;
41 class reports;
42 
43 namespace halo {
44  class manager;
45 }
46 
47 namespace wb {
48  class manager;
49 }
50 
51 #include "animated.hpp"
52 #include "display_context.hpp"
53 #include "filter_context.hpp"
54 #include "font.hpp"
55 #include "image.hpp" //only needed for enums (!)
56 #include "key.hpp"
57 #include "team.hpp"
58 #include "time_of_day.hpp"
59 #include "sdl/rect.hpp"
60 #include "sdl/image.hpp"
61 #include "theme.hpp"
62 #include "video.hpp"
63 #include "widgets/button.hpp"
64 #include "widgets/slider.hpp"
65 
66 #include "overlay.hpp"
67 
68 #include "utils/functional.hpp"
69 #include <boost/weak_ptr.hpp>
70 #include <boost/scoped_ptr.hpp>
71 #include <deque>
72 #include <list>
73 #include <map>
74 #include <memory>
75 
76 class gamemap;
77 
79 {
80 public:
81  display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::manager> wb,
82  reports & reports_object,
83  const config& theme_cfg, const config& level, bool auto_join=true);
84  virtual ~display();
85  /// Returns the display object if a display object exists. Otherwise it returns nullptr.
86  /// the display object represents the game gui which handles themewml and drawing the map.
87  /// A display object only exists during a game or while the mapeditor is running.
88  static display* get_singleton() { return singleton_ ;}
89 
90  bool show_everything() const { return !dont_show_all_ && !is_blindfolded(); }
91 
92  const gamemap& get_map() const { return dc_->map(); }
93 
94  const std::vector<team>& get_teams() const {return dc_->teams();}
95 
96  /** The playing team is the team whose turn it is. */
97  size_t playing_team() const { return activeTeam_; }
98 
99  bool team_valid() const { return currentTeam_ < dc_->teams().size(); }
100 
101  /** The viewing team is the team currently viewing the game. */
102  size_t viewing_team() const { return currentTeam_; }
103  int viewing_side() const { return currentTeam_ + 1; }
104 
105  /**
106  * Sets the team controlled by the player using the computer.
107  * Data from this team will be displayed in the game status.
108  */
109  void set_team(size_t team, bool observe=false);
110 
111  /**
112  * set_playing_team sets the team whose turn it currently is
113  */
114  void set_playing_team(size_t team);
115 
116 
117  /**
118  * Cancels all the exclusive draw requests.
119  */
121  const unit_map& get_units() const {return dc_->units();}
122 
123  /**
124  * Allows a unit to request to be the only one drawn in its hex. Useful for situations where
125  * multiple units (one real, multiple temporary) can end up stacked, such as with the whiteboard.
126  * @param loc The location of the unit requesting exclusivity.
127  * @param unit The unit requesting exclusivity.
128  * @return false if there's already an exclusive draw request for this location.
129  */
130  bool add_exclusive_draw(const map_location& loc, unit& unit);
131  /**
132  * Cancels an exclusive draw request.
133  * @return The id of the unit whose exclusive draw request was canceled, or else
134  * the empty string if there was no exclusive draw request for this location.
135  */
137 
138  /**
139  * Check the overlay_map for proper team-specific overlays to be
140  * displayed/hidden
141  */
142  void parse_team_overlays();
143 
144  /**
145  * Functions to add and remove overlays from locations.
146  *
147  * An overlay is an image that is displayed on top of the tile.
148  * One tile may have multiple overlays.
149  */
150  void add_overlay(const map_location& loc, const std::string& image,
151  const std::string& halo="", const std::string& team_name="",const std::string& item_id="",
152  bool visible_under_fog = true);
153 
154  /** remove_overlay will remove all overlays on a tile. */
155  void remove_overlay(const map_location& loc);
156 
157  /** remove_single_overlay will remove a single overlay from a tile */
158  void remove_single_overlay(const map_location& loc, const std::string& toDelete);
159 
160  /**
161  * Updates internals that cache map size. This should be called when the map
162  * size has changed.
163  */
164  void reload_map();
165 
166  void change_display_context(const display_context * dc);
167  const display_context & get_disp_context() const { return *dc_; }
168  virtual const tod_manager & get_tod_man() const; //!< This is implemented properly in game_display. The display:: impl could be pure virtual here but we decide not to.
169  virtual const game_data * get_game_data() const { return nullptr; }
170  virtual game_lua_kernel * get_lua_kernel() const { return nullptr; } //!< TODO: display should not work as a filter context, this was only done for expedience so that the unit animation code can have a convenient and correct filter context readily available. a more correct solution is most likely to pass it a filter context from unit_animator when it needs to be matched. (it's not possible to store filter contexts with animations, because animations are cached across scenarios.) Note that after these lines which return nullptr, unit filters used in animations will not be able to make use of wml variables or lua scripting (but the latter was a bad idea anyways because it would be slow to constantly recompile the script.)
171 
172  void reset_halo_manager();
175 
176  static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
177  { return 0xFF000000 | (red << 16) | (green << 8) | blue; }
178  static Uint8 red(Uint32 color)
179  { return (color & 0x00FF0000) >> 16;}
180  static Uint8 green(Uint32 color)
181  { return (color & 0x0000FF00) >> 8;}
182  static Uint8 blue(Uint32 color)
183  { return (color & 0x000000FF) ;}
184  static Uint32 max_rgb(Uint32 first,Uint32 second)
185  { return rgb(std::max(red(first),red(second)),std::max(green(first),green(second)),std::max(blue(first),blue(second))) ; }
186 
187  /**
188  * Add r,g,b from tod_manager to the map
189  *
190  */
191  void update_tod();
192 
193  /**
194  * Add r,g,b to the colors for all images displayed on the map.
195  *
196  * Used for special effects like flashes.
197  */
198  void adjust_color_overlay(int r, int g, int b);
199 
200 
201  /** Gets the underlying screen object. */
202  CVideo& video() { return screen_; }
203 
204  /** return the screen surface or the surface used for map_screenshot. */
206 
207  virtual bool in_game() const { return false; }
208  virtual bool in_editor() const { return false; }
209 
210  /** Virtual functions shadowed in game_display. These are needed to generate reports easily, without dynamic casting. Hope to factor out eventually. */
211  virtual const map_location & displayed_unit_hex() const { return map_location::null_location(); }
212  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. */
213  virtual const std::set<std::string>& observers() const { static const std::set<std::string> fake_obs = std::set<std::string> (); return fake_obs; }
214 
215  /**
216  * the dimensions of the display. x and y are width/height.
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  int w() const { return screen_.getx(); } /**< width */
221  int h() const { return screen_.gety(); } /**< height */
222  const SDL_Rect& minimap_area() const
223  { return theme_.mini_map_location(screen_area()); }
224  const SDL_Rect& palette_area() const
225  { return theme_.palette_location(screen_area()); }
226  const SDL_Rect& unit_image_area() const
227  { return theme_.unit_image_location(screen_area()); }
228 
229  SDL_Rect screen_area() const
230  { return sdl::create_rect(0, 0, w(), h()); }
231 
232  /**
233  * Returns the maximum area used for the map
234  * regardless to resolution and view size
235  */
236  const SDL_Rect& max_map_area() const;
237 
238  /**
239  * Returns the area used for the map
240  */
241  const SDL_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  const SDL_Rect& map_outside_area() const { return map_screenshot_ ?
250 
251  /** Check if the bbox of the hex at x,y has pixels outside the area rectangle. */
252  bool outside_area(const SDL_Rect& area, const int x,const int y) const;
253 
254  /**
255  * Function which returns the width of a hex in pixels,
256  * up to where the next hex starts.
257  * (i.e. not entirely from tip to tip -- use hex_size()
258  * to get the distance from tip to tip)
259  */
260  int hex_width() const { return (zoom_*3)/4; }
261 
262  /**
263  * Function which returns the size of a hex in pixels
264  * (from top tip to bottom tip or left edge to right edge).
265  */
266  int hex_size() const { return zoom_; }
267 
268  /** Returns the current zoom factor. */
269  double get_zoom_factor() const { return double(zoom_)/double(game_config::tile_size); }
270 
271  /**
272  * given x,y co-ordinates of an onscreen pixel, will return the
273  * location of the hex that this pixel corresponds to.
274  * Returns an invalid location if the mouse isn't over any valid location.
275  */
276  const map_location hex_clicked_on(int x, int y) const;
277 
278  /**
279  * given x,y co-ordinates of a pixel on the map, will return the
280  * location of the hex that this pixel corresponds to.
281  * Returns an invalid location if the mouse isn't over any valid location.
282  */
283  const map_location pixel_position_to_hex(int x, int y) const;
284 
285  /**
286  * given x,y co-ordinates of the mouse, will return the location of the
287  * hex in the minimap that the mouse is currently over, or an invalid
288  * location if the mouse isn't over the minimap.
289  */
291 
292  const map_location& selected_hex() const { return selectedHex_; }
293  const map_location& mouseover_hex() const { return mouseoverHex_; }
294 
295  virtual void select_hex(map_location hex);
296  virtual void highlight_hex(map_location hex);
297 
298  /** Function to invalidate the game status displayed on the sidebar. */
300 
301  /** Functions to get the on-screen positions of hexes. */
302  int get_location_x(const map_location& loc) const;
303  int get_location_y(const map_location& loc) const;
304 
305  /**
306  * Rectangular area of hexes, allowing to decide how the top and bottom
307  * edges handles the vertical shift for each parity of the x coordinate
308  */
310  int left;
311  int right;
312  int top[2]; // for even and odd values of x, respectively
313  int bottom[2];
314 
315  /** very simple iterator to walk into the rect_of_hexes */
316  struct iterator {
317  iterator(const map_location &loc, const rect_of_hexes &rect)
318  : loc_(loc), rect_(rect){}
319 
320  /** increment y first, then when reaching bottom, increment x */
321  iterator& operator++();
322  bool operator==(const iterator &that) const { return that.loc_ == loc_; }
323  bool operator!=(const iterator &that) const { return that.loc_ != loc_; }
324  const map_location& operator*() const {return loc_;}
325 
326  typedef std::forward_iterator_tag iterator_category;
328  typedef int difference_type;
329  typedef const map_location *pointer;
330  typedef const map_location &reference;
331 
332  private:
335  };
337 
338  iterator begin() const;
339  iterator end() const;
340  };
341 
342  /** Return the rectangular area of hexes overlapped by r (r is in screen coordinates) */
343  const rect_of_hexes hexes_under_rect(const SDL_Rect& r) const;
344 
345  /** Returns the rectangular area of visible hexes */
347 
348  /** Returns true if location (x,y) is covered in shroud. */
349  bool shrouded(const map_location& loc) const {
350  return is_blindfolded() || (dont_show_all_ && dc_->teams()[currentTeam_].shrouded(loc));
351  }
352  /** Returns true if location (x,y) is covered in fog. */
353  bool fogged(const map_location& loc) const {
354  return is_blindfolded() || (dont_show_all_ && dc_->teams()[currentTeam_].fogged(loc));
355  }
356 
357  /**
358  * Determines whether a grid should be overlayed on the game board.
359  * (to more clearly show where hexes are)
360  */
361  void set_grid(const bool grid) { grid_ = grid; }
362 
363  /** Getter for the x,y debug overlay on tiles */
364  bool get_draw_coordinates() const { return draw_coordinates_; }
365  /** Setter for the x,y debug overlay on tiles */
367 
368  /** Getter for the terrain code debug overlay on tiles */
370  /** Setter for the terrain code debug overlay on tiles */
372 
373  /** Save a (map-)screenshot and return whether the operation succeeded. */
374  bool screenshot(const std::string& filename, bool map_screenshot = false);
375 
376  /** Invalidates entire screen, including all tiles and sidebar. Calls redraw observers. */
377  void redraw_everything();
378 
379  /** Adds a redraw observer, a function object to be called when redraw_everything is used */
380  void add_redraw_observer(std::function<void(display&)> f);
381 
382  /** Clear the redraw observers */
383  void clear_redraw_observers();
384 
385  theme& get_theme() { return theme_; }
386 
387  /**
388  * Retrieves a pointer to a theme UI button.
389  *
390  * @note The returned pointer may either be nullptr, meaning the button
391  * isn't defined by the current theme, or point to a valid
392  * gui::button object. However, the objects retrieved will be
393  * destroyed and recreated by draw() method calls. Do *NOT* store
394  * these pointers for longer than strictly necessary to
395  * accomplish a specific task before the next screen refresh.
396  */
397  std::shared_ptr<gui::button> find_action_button(const std::string& id);
398  std::shared_ptr<gui::button> find_menu_button(const std::string& id);
399  std::shared_ptr<gui::zoom_slider> find_slider(const std::string& id);
400 
402  void create_buttons();
403 
404  void layout_buttons();
405 
406  void render_buttons();
407 
408  void invalidate_theme() { panelsDrawn_ = false; }
409 
410  void refresh_report(std::string const &report_name, const config * new_cfg=nullptr);
411 
412  void draw_minimap_units();
413 
414  /** Function to invalidate all tiles. */
415  void invalidate_all();
416 
417  /** Function to invalidate a specific tile for redrawing. */
418  bool invalidate(const map_location& loc);
419 
420  bool invalidate(const std::set<map_location>& locs);
421 
422  /**
423  * If this set is partially invalidated, invalidate all its hexes.
424  * Returns if any new invalidation was needed
425  */
426  bool propagate_invalidation(const std::set<map_location>& locs);
427 
428  /** invalidate all hexes under the rectangle rect (in screen coordinates) */
429  bool invalidate_locations_in_rect(const SDL_Rect& rect);
430  bool invalidate_visible_locations_in_rect(const SDL_Rect& rect);
431 
432  /**
433  * Function to invalidate animated terrains and units which may have changed.
434  */
435  void invalidate_animations();
436 
437  /**
438  * Per-location invalidation called by invalidate_animations()
439  * Extra game per-location invalidation (village ownership)
440  */
442 
443 #ifdef SDL_GPU
444  /**
445  * mouseover_hex_overlay_ require a prerendered surface
446  * and is drawn underneath the mouse's location
447  */
448  void set_mouseover_hex_overlay(const sdl::timage& image)
450 
452  { mouseover_hex_overlay_ = sdl::timage(); }
453 #else
454  /**
455  * mouseover_hex_overlay_ require a prerendered surface
456  * and is drawn underneath the mouse's location
457  */
460 
462  { mouseover_hex_overlay_ = nullptr; }
463 #endif
464 
465  /**
466  * Debug function to toggle the "sunset" mode.
467  * The map area become progressively darker,
468  * except where hexes are refreshed.
469  * delay is the number of frames between each darkening
470  * (0 to toggle).
471  */
472  static void sunset(const size_t delay = 0);
473 
474  /** Toggle to continuously redraw the screen. */
475  static void toggle_benchmark();
476 
477  /**
478  * Toggle to debug foreground terrain.
479  * Separate background and foreground layer
480  * to better spot any error there.
481  */
482  static void toggle_debug_foreground();
483 
485 
486  void flip();
487 
488  /** Copy the backbuffer to the framebuffer. */
489  void update_display();
490 
491  /** Rebuild all dynamic terrain. */
492  void rebuild_all();
493 
494  const theme::action* action_pressed();
495  const theme::menu* menu_pressed();
496 
497  /**
498  * Finds the menu which has a given item in it,
499  * and enables or disables it.
500  */
501  void enable_menu(const std::string& item, bool enable);
502 
503  void set_diagnostic(const std::string& msg);
504 
505  /**
506  * Set/Get whether 'turbo' mode is on.
507  * When turbo mode is on, everything moves much faster.
508  */
509  void set_turbo(const bool turbo) { turbo_ = turbo; }
510 
511  double turbo_speed() const;
512 
513  void set_turbo_speed(const double speed) { turbo_speed_ = speed; }
514 
515  /** control unit idle animations and their frequency */
516  void set_idle_anim(bool ison) { idle_anim_ = ison; }
517  bool idle_anim() const { return idle_anim_; }
518  void set_idle_anim_rate(int rate);
519  double idle_anim_rate() const { return idle_anim_rate_; }
520 
521  void bounds_check_position();
522  void bounds_check_position(int& xpos, int& ypos);
523 
524  /**
525  * Scrolls the display by xmov,ymov pixels.
526  * Invalidation and redrawing will be scheduled.
527  * @return true if the map actually moved.
528  */
529  bool scroll(int xmov, int ymov, bool force = false);
530 
531  /**
532  * Zooms the display by the specified amount.
533  * Negative values zoom out.
534  * Note the amount should be a multiple of four,
535  * otherwise the images might start to look odd
536  * (hex_width() gets rounding errors).
537  */
538  bool set_zoom(int amount, bool absolute = false);
539 
540  bool zoom_at_max() const;
541  bool zoom_at_min() const;
542 
543  /** Sets the zoom amount to the default. */
544  void set_default_zoom();
545 
546  bool view_locked() const { return view_locked_; }
547 
548  /** Sets whether the map view is locked (e.g. so the user can't scroll away) */
550 
552 
553  /**
554  * Scroll such that location loc is on-screen.
555  * WARP jumps to loc; SCROLL uses scroll speed;
556  * ONSCREEN only scrolls if x,y is offscreen
557  * force : scroll even if preferences tell us not to,
558  * or the view is locked.
559  */
560  void scroll_to_tile(const map_location& loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true,bool force = true);
561 
562  /**
563  * Scroll such that location loc1 is on-screen.
564  * It will also try to make it such that loc2 is on-screen,
565  * but this is not guaranteed. For ONSCREEN scrolls add_spacing
566  * sets the desired minimum distance from the border in hexes.
567  */
568  void scroll_to_tiles(map_location loc1, map_location loc2,
569  SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true,
570  double add_spacing=0.0, bool force=true);
571 
572  /** Scroll to fit as many locations on-screen as possible, starting with the first. */
573  void scroll_to_tiles(const std::vector<map_location>::const_iterator & begin,
574  const std::vector<map_location>::const_iterator & end,
575  SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true,
576  bool only_if_possible=false, double add_spacing=0.0,
577  bool force=true);
578  /** Scroll to fit as many locations on-screen as possible, starting with the first. */
579  void scroll_to_tiles(const std::vector<map_location>& locs,
580  SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true,
581  bool only_if_possible=false,
582  double add_spacing=0.0, bool force=true)
583  {
584  scroll_to_tiles(locs.begin(), locs.end(), scroll_type, check_fogged,
585  only_if_possible, add_spacing, force);
586  }
587 
588  /** Expose the event, so observers can be notified about map scrolling. */
590 
592 
593  /** Check if a tile is fully visible on screen. */
594  bool tile_fully_on_screen(const map_location& loc);
595 
596  /** Checks if location @a loc or one of the adjacent tiles is visible on screen. */
597  bool tile_nearly_on_screen(const map_location &loc) const;
598 
599  /**
600  * Draws invalidated items.
601  * If update is true, will also copy the display to the frame buffer.
602  * If force is true, will not skip frames, even if running behind.
603  * Not virtual, since it gathers common actions. Calls various protected
604  * virtuals (further below) to allow specialized behavior in derived classes.
605  */
606  virtual void draw();
607 
608  void draw(bool update);
609 
610  void draw(bool update, bool force);
611 
612  map_labels& labels();
613  const map_labels& labels() const;
614 
615  /** Announce a message prominently. */
616  void announce(const std::string& msg,
617  const SDL_Color& color = font::GOOD_COLOR);
618 
619  /**
620  * Schedule the minimap for recalculation.
621  * Useful if any terrain in the map has changed.
622  */
623  void recalculate_minimap() {minimap_ = nullptr; redrawMinimap_ = true; }
624 
625  /**
626  * Schedule the minimap to be redrawn.
627  * Useful if units have moved about on the map.
628  */
629  void redraw_minimap() { redrawMinimap_ = true; }
630 
631  virtual const time_of_day& get_time_of_day(const map_location& loc = map_location::null_location()) const;
632 
633  virtual bool has_time_area() const {return false;}
634 
635  void blindfold(bool flag);
636  bool is_blindfolded() const;
637 
638  void write(config& cfg) const;
639 
640  virtual void handle_event(const SDL_Event& );
641  virtual void handle_window_event(const SDL_Event& event);
642 
643 private:
644  void read(const config& cfg);
645 
646 public:
647  /** Init the flag list and the team colors used by ~TC */
648  void init_flags();
649 
650  /** Rebuild the flag list (not team colors) for a single side. */
651  void reinit_flags_for_side(size_t side);
652  void reset_reports(reports& reports_object)
653  {
654  reports_object_ = &reports_object;
655  }
656 private:
657  void init_flags_for_side_internal(size_t side, const std::string& side_color);
658 
660 
661 protected:
662  //TODO sort
664  boost::scoped_ptr<halo::manager> halo_man_;
665  boost::weak_ptr<wb::manager> wb_;
666 
667  typedef std::map<map_location, std::string> exclusive_unit_draw_requests_t;
668  /// map of hexes where only one unit should be drawn, the one identified by the associated id string
669  exclusive_unit_draw_requests_t exclusive_unit_draw_requests_;
670 
671 
672  /** Clear the screen contents */
673  void clear_screen();
674 
675  /**
676  * Called near the beginning of each draw() call.
677  * Derived classes can use this to add extra actions before redrawing
678  * invalidated hexes takes place. No action here by default.
679  */
680  virtual void pre_draw() {}
681 
682  /**
683  * Called at the very end of each draw() call.
684  * Derived classes can use this to add extra actions after redrawing
685  * invalidated hexes takes place. No action here by default.
686  */
687  virtual void post_draw() {}
688 
689  /**
690  * Get the clipping rectangle for drawing.
691  * Virtual since the editor might use a slightly different approach.
692  */
693  virtual const SDL_Rect& get_clip_rect();
694 
695  /**
696  * Only called when there's actual redrawing to do. Loops through
697  * invalidated locations and redraws them. Derived classes can override
698  * this, possibly to insert pre- or post-processing around a call to the
699  * base class's function.
700  */
701  virtual void draw_invalidated();
702 
703  /**
704  * Hook for actions to take right after draw() calls drawing_buffer_commit
705  * No action here by default.
706  */
707  virtual void post_commit() {}
708 
709  /**
710  * Redraws a single gamemap location.
711  */
712  virtual void draw_hex(const map_location& loc);
713 
714  /**
715  * @returns the image type to be used for the passed hex
716  */
717  virtual image::TYPE get_image_type(const map_location& loc);
718 
719  /**
720  * Called near the end of a draw operation, derived classes can use this
721  * to render a specific sidebar. Very similar to post_commit.
722  */
723  virtual void draw_sidebar() {}
724 
725  /**
726  * Draws the border tile overlay.
727  * The routine determines by itself which border it is on
728  * and draws an overlay accordingly. The definition of the
729  * border is stored in the 'main_map_border' part of the theme.
730  *
731  * @param loc the map location of the tile
732  * @param xpos the on-screen pixels x coordinate of the tile
733  * @param ypos the on-screen pixels y coordinate of the tile
734  */
735  virtual void draw_border(const map_location& loc,
736  const int xpos, const int ypos);
737 
738  void draw_minimap();
739 
741 
742 #ifdef SDL_GPU
743  std::vector<sdl::timage> get_terrain_images(const map_location &loc,
744  const std::string& timeid,
747 
748  std::vector<sdl::timage> get_fog_shroud_images(const map_location& loc, image::TYPE image_type);
749 
750  void draw_image_for_report(sdl::timage& img, SDL_Rect& rect);
751 #else
752  std::vector<surface> get_terrain_images(const map_location &loc,
753  const std::string& timeid,
756 
757  std::vector<surface> get_fog_shroud_images(const map_location& loc, image::TYPE image_type);
758 
759  void draw_image_for_report(surface& img, SDL_Rect& rect);
760 #endif
761 
762  void scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type,bool force = true);
763 
764  void fill_images_list(const std::string& prefix, std::vector<std::string>& images);
765 
766  const std::string& get_variant(const std::vector<std::string>& variants, const map_location &loc) const;
767 
769  size_t currentTeam_;
770  bool dont_show_all_; //const team *viewpoint_;
771  std::map<surface,SDL_Rect> energy_bar_rects_;
772  int xpos_, ypos_;
775  int zoom_;
776  static int last_zoom_;
777  boost::scoped_ptr<fake_unit_manager> fake_unit_man_;
778  boost::scoped_ptr<terrain_builder> builder_;
784  bool grid_;
787  double turbo_speed_;
788  bool turbo_;
790  boost::scoped_ptr<map_labels> map_labels_;
792 
793  /** Event raised when the map is being scrolled */
795 
796  /**
797  * notify observers that the screen has been redrawn completely
798  * atm this is used for replay_controller to add replay controls to the standard theme
799  */
801 
802  /**
803  * Holds the tick count for when the next drawing event is scheduled.
804  * Drawing shouldn't occur before this time.
805  */
807 
808  // Not set by the initializer:
809  std::map<std::string, SDL_Rect> reportRects_;
810 #ifdef SDL_GPU
811  std::map<std::string, sdl::timage> reportImages_;
812 #else
813  std::map<std::string, surface> reportSurfaces_;
814 #endif
815  std::map<std::string, config> reports_;
816  std::vector<std::shared_ptr<gui::button>> menu_buttons_, action_buttons_;
817  std::vector<std::shared_ptr<gui::zoom_slider>> sliders_;
818  std::set<map_location> invalidated_;
819  std::set<map_location> previous_invalidated_;
820 #ifdef SDL_GPU
821  sdl::timage mouseover_hex_overlay_;
822  // If we're transitioning from one time of day to the next,
823  // then we will use these two masks on top of all hexes when we blit.
824  sdl::timage tod_hex_mask1, tod_hex_mask2;
825 #else
827  // If we're transitioning from one time of day to the next,
828  // then we will use these two masks on top of all hexes when we blit.
830 #endif
831  std::vector<std::string> fog_images_;
832  std::vector<std::string> shroud_images_;
833 
837 
838  /** Local cache for preferences::animate_map, since it is constantly queried. */
840 
841  /** Local version of preferences::animate_water, used to detect when it's changed. */
843 
844 private:
845 
846 #ifdef SDL_GPU
847  // This surface must be freed by the caller
848  sdl::timage get_flag(const map_location& loc);
849 #else
850  // This surface must be freed by the caller
851  surface get_flag(const map_location& loc);
852 #endif
853 
854  /** Animated flags for each team */
855  std::vector<animated<image::locator> > flags_;
856 
857 public:
858  /**
859  * The layers to render something on. This value should never be stored
860  * it's the internal drawing order and adding removing and reordering
861  * the layers should be safe.
862  * If needed in WML use the name and map that to the enum value.
863  */
866  * Layer for the terrain drawn behind the
867  * unit.
868  */
869  LAYER_GRID_TOP, /**< Top half part of grid image */
870  LAYER_MOUSEOVER_OVERLAY, /**< Mouseover overlay used by editor*/
871  LAYER_FOOTSTEPS, /**< Footsteps showing path from unit to mouse */
872  LAYER_MOUSEOVER_TOP, /**< Top half of image following the mouse */
873  LAYER_UNIT_FIRST, /**< Reserve layers to be selected for WML. */
874  LAYER_UNIT_BG = LAYER_UNIT_FIRST+10, /**< Used for the ellipse behind the unit. */
875  LAYER_UNIT_DEFAULT=LAYER_UNIT_FIRST+40,/**<default layer for drawing units */
877  * Layer for the terrain drawn in front of
878  * the unit.
879  */
881  * Used for the bottom half part of grid image.
882  * Should be under moving units, to avoid masking south move.
883  */
884  LAYER_UNIT_MOVE_DEFAULT=LAYER_UNIT_FIRST+60/**<default layer for drawing moving units */,
886  * Used for the ellipse in front of the
887  * unit.
888  */
889  LAYER_UNIT_MISSILE_DEFAULT = LAYER_UNIT_FIRST+90, /**< default layer for missile frames*/
891  LAYER_REACHMAP, /**< "black stripes" on unreachable hexes. */
892  LAYER_MOUSEOVER_BOTTOM, /**< Bottom half of image following the mouse */
893  LAYER_FOG_SHROUD, /**< Fog and shroud. */
894  LAYER_ARROWS, /**< Arrows from the arrows framework. Used for planned moves display. */
895  LAYER_ACTIONS_NUMBERING, /**< Move numbering for the whiteboard. */
896  LAYER_SELECTED_HEX, /**< Image on the selected unit */
897  LAYER_ATTACK_INDICATOR, /**< Layer which holds the attack indicator. */
899  * Unit bars and overlays are drawn on this
900  * layer (for testing here).
901  */
902  LAYER_MOVE_INFO, /**< Movement info (defense%, etc...). */
903  LAYER_LINGER_OVERLAY, /**< The overlay used for the linger mode. */
904  LAYER_BORDER, /**< The border of the map. */
905 
907  * Don't draw to this layer it's a dummy to
908  * size the vector.
909  */
910  };
911 
912 #ifdef SDL_GPU
913  /**
914  * Draw an image at a certain location.
915  * x,y: pixel location on screen to draw the image
916  * image: the image to draw
917  * reverse: if the image should be flipped across the x axis
918  * greyscale: used for instance to give the petrified appearance to a unit image
919  * alpha: the merging to use with the background
920  * blendto: blend to this color using blend_ratio
921  * submerged: the amount of the unit out of 1.0 that is submerged
922  * (presumably under water) and thus shouldn't be drawn
923  */
924  void render_image(int x, int y, const display::tdrawing_layer drawing_layer,
925  const map_location& loc, sdl::timage image,
926  bool hreverse=false, bool greyscale=false,
927  fixed_t alpha=ftofxp(1.0), Uint32 blendto=0,
928  double blend_ratio=0, double submerged=0.0,bool vreverse =false);
929 #else
930  /**
931  * Draw an image at a certain location.
932  * x,y: pixel location on screen to draw the image
933  * image: the image to draw
934  * reverse: if the image should be flipped across the x axis
935  * greyscale: used for instance to give the petrified appearance to a unit image
936  * alpha: the merging to use with the background
937  * blendto: blend to this color using blend_ratio
938  * submerged: the amount of the unit out of 1.0 that is submerged
939  * (presumably under water) and thus shouldn't be drawn
940  */
941  void render_image(int x, int y, const display::tdrawing_layer drawing_layer,
942  const map_location& loc, surface image,
943  bool hreverse=false, bool greyscale=false,
944  fixed_t alpha=ftofxp(1.0), Uint32 blendto=0,
945  double blend_ratio=0, double submerged=0.0,bool vreverse =false);
946 #endif
947 
948  /**
949  * Draw text on a hex. (0.5, 0.5) is the center.
950  * The font size is adjusted to the zoom factor.
951  */
952  void draw_text_in_hex(const map_location& loc,
953  const tdrawing_layer layer, const std::string& text, size_t font_size,
954  SDL_Color color, double x_in_hex=0.5, double y_in_hex=0.5);
955 
956 protected:
957 
958  //TODO sort
959  size_t activeTeam_;
960 
961  /**
962  * In order to render a hex properly it needs to be rendered per row. On
963  * this row several layers need to be drawn at the same time. Mainly the
964  * unit and the background terrain. This is needed since both can spill
965  * in the next hex. The foreground terrain needs to be drawn before to
966  * avoid decapitation a unit.
967  *
968  * In other words:
969  * for every layer
970  * for every row (starting from the top)
971  * for every hex in the row
972  * ...
973  *
974  * this is modified to:
975  * for every layer group
976  * for every row (starting from the top)
977  * for every layer in the group
978  * for every hex in the row
979  * ...
980  *
981  * * Surfaces are rendered per level in a map.
982  * * Per level the items are rendered per location these locations are
983  * stored in the drawing order required for units.
984  * * every location has a vector with surfaces, each with its own screen
985  * coordinate to render at.
986  * * every vector element has a vector with surfaces to render.
987  */
989  {
990  private:
991  unsigned int key_;
992 
993  static const tdrawing_layer layer_groups[];
994  static const unsigned int max_layer_group;
995 
996  public:
998 
999  bool operator<(const drawing_buffer_key &rhs) const { return key_ < rhs.key_; }
1000  };
1001 
1002  /** Helper structure for rendering the terrains. */
1003  class tblit
1004  {
1005  public:
1006 #ifdef SDL_GPU
1007  tblit(const tdrawing_layer layer, const map_location& loc,
1008  const int x, const int y, const sdl::timage& image)
1009  : x_(x), y_(y), images_(1, image), key_(loc, layer)
1010  {}
1011 
1012  tblit(const tdrawing_layer layer, const map_location& loc,
1013  const int x, const int y,
1014  const std::vector<sdl::timage>& images)
1015  : x_(x), y_(y), images_(images), key_(loc, layer)
1016  {}
1017 #else
1018  tblit(const tdrawing_layer layer, const map_location& loc,
1019  const int x, const int y, const surface& surf,
1020  const SDL_Rect& clip)
1021  : x_(x), y_(y), surf_(1, surf), clip_(clip),
1022  key_(loc, layer)
1023  {}
1024 
1025  tblit(const tdrawing_layer layer, const map_location& loc,
1026  const int x, const int y, const std::vector<surface>& surf,
1027  const SDL_Rect& clip)
1028  : x_(x), y_(y), surf_(surf), clip_(clip),
1029  key_(loc, layer)
1030  {}
1031 #endif
1032 
1033  int x() const { return x_; }
1034  int y() const { return y_; }
1035 #ifdef SDL_GPU
1036  std::vector<sdl::timage> &images() { return images_; }
1037 #else
1038  const std::vector<surface> &surf() const { return surf_; }
1039  const SDL_Rect &clip() const { return clip_; }
1040 #endif
1041 
1042  bool operator<(const tblit &rhs) const { return key_ < rhs.key_; }
1043 
1044  private:
1045  int x_; /**< x screen coordinate to render at. */
1046  int y_; /**< y screen coordinate to render at. */
1047 #ifdef SDL_GPU
1048  std::vector<sdl::timage> images_;
1049 #else
1050  std::vector<surface> surf_; /**< surface(s) to render. */
1051  SDL_Rect clip_; /**<
1052  * The clipping area of the source if
1053  * omitted the entire source is used.
1054  */
1055 #endif
1057  };
1058 
1059  typedef std::list<tblit> tdrawing_buffer;
1060  tdrawing_buffer drawing_buffer_;
1061 
1062 public:
1063 #ifdef SDL_GPU
1065  const map_location& loc, int x, int y,
1066  const sdl::timage& img);
1067 
1069  const map_location& loc, int x, int y,
1070  const std::vector<sdl::timage> &imgs);
1071 #else
1072  /**
1073  * Add an item to the drawing buffer. You need to update screen on affected area
1074  *
1075  * @param layer The layer to draw on.
1076  * @param loc The hex the image belongs to, needed for the
1077  * drawing order.
1078  */
1080  const map_location& loc, int x, int y, const surface& surf,
1081  const SDL_Rect &clip = SDL_Rect());
1082 
1083  void drawing_buffer_add(const tdrawing_layer layer,
1084  const map_location& loc, int x, int y,
1085  const std::vector<surface> &surf,
1086  const SDL_Rect &clip = SDL_Rect());
1087 #endif
1088 
1089 protected:
1090 
1091  /** Draws the drawing_buffer_ and clears it. */
1092  void drawing_buffer_commit();
1093 
1094  /** Clears the drawing buffer. */
1095  void drawing_buffer_clear();
1096 
1097  /** redraw all panels associated with the map display */
1098  void draw_all_panels();
1099 
1100 #ifdef SDL_GPU
1101  void draw_panel_image(SDL_Rect *clip = nullptr);
1102 #endif
1103 
1104  /**
1105  * Initiate a redraw.
1106  *
1107  * Invalidate controls and panels when changed after they have been drawn
1108  * initially. Useful for dynamic theme modification.
1109  */
1110  void draw_init();
1111  void draw_wrap(bool update,bool force);
1112 
1113  /** Used to indicate to drawing functions that we are doing a map screenshot */
1115 
1116 public: //operations for the arrow framework
1117 
1118  void add_arrow(arrow&);
1119 
1120  void remove_arrow(arrow&);
1121 
1122  /** Called by arrow objects when they change. You should not need to call this directly. */
1123  void update_arrow(arrow & a);
1124 
1125 protected:
1126 
1127  // Tiles lit for showing where unit(s) can reach
1128  typedef std::map<map_location,unsigned int> reach_map;
1129  reach_map reach_map_;
1130  reach_map reach_map_old_;
1132  void process_reachmap_changes();
1133 
1134  typedef std::multimap<map_location, overlay> overlay_map;
1135 
1136 private:
1137 
1138 
1139  overlay_map* overlays_;
1140 
1141  /** Handle for the label which displays frames per second. */
1143  /** Count work done for the debug info displayed under fps */
1146 
1149 
1151 
1152  std::vector<std::function<void(display&)> > redraw_observers_;
1153 
1154  /** Debug flag - overlay x,y coords on tiles */
1156  /** Debug flag - overlay terrain codes on tiles */
1158 
1159  typedef std::list<arrow*> arrows_list_t;
1160  typedef std::map<map_location, arrows_list_t > arrows_map_t;
1161  /** Maps the list of arrows for each location */
1162  arrows_map_t arrows_map_;
1163 
1165 
1166  bool dirty_;
1167 
1168 #ifdef SDL_GPU
1169  bool update_panel_image_;
1170  sdl::timage panel_image_;
1171 #endif
1172 
1173 
1174 public:
1175  void replace_overlay_map(overlay_map* overlays) { overlays_ = overlays; }
1176 
1177 protected:
1179 };
1180 
1182 {
1183  blindfold(display& d, bool lock=true) : display_(d), blind(lock) {
1184  if(blind) {
1185  display_.blindfold(true);
1186  }
1187  }
1188 
1190  unblind();
1191  }
1192 
1193  void unblind() {
1194  if(blind) {
1195  display_.blindfold(false);
1196  blind = false;
1197  }
1198  }
1199 
1200 private:
1202  bool blind;
1203 };
1204 
1205 
1206 #endif
1207 
std::shared_ptr< gui::button > find_action_button(const std::string &id)
Retrieves a pointer to a theme UI button.
Definition: display.cpp:826
TYPE
UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM :...
Definition: image.hpp:208
void drawing_buffer_add(const tdrawing_layer layer, const map_location &loc, int x, int y, const surface &surf, const SDL_Rect &clip=SDL_Rect())
Add an item to the drawing buffer.
Definition: display.cpp:1241
static void sunset(const size_t delay=0)
Debug function to toggle the "sunset" mode.
Definition: display.cpp:1395
virtual const std::set< std::string > & observers() const
Definition: display.hpp:213
void drawing_buffer_commit()
Draws the drawing_buffer_ and clears it.
Definition: display.cpp:1324
boost::scoped_ptr< fake_unit_manager > fake_unit_man_
Definition: display.hpp:777
void draw_minimap_units()
Definition: display.cpp:2149
Don't draw to this layer it's a dummy to size the vector.
Definition: display.hpp:906
std::set< map_location > previous_invalidated_
Definition: display.hpp:819
virtual void pre_draw()
Called near the beginning of each draw() call.
Definition: display.hpp:680
halo::manager & get_halo_manager()
Definition: display.hpp:174
bool fogged(const map_location &loc) const
Returns true if location (x,y) is covered in fog.
Definition: display.hpp:353
GLboolean enable
Definition: glew.h:2589
virtual void select_hex(map_location hex)
Definition: display.cpp:1792
static const unsigned int max_layer_group
Definition: display.hpp:994
size_t currentTeam_
Definition: display.hpp:769
reports * reports_object_
Definition: display.hpp:791
Used for the bottom half part of grid image.
Definition: display.hpp:880
virtual void handle_window_event(const SDL_Event &event)
Definition: display.cpp:3778
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:88
bool operator==(const iterator &that) const
Definition: display.hpp:322
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
Definition: display.hpp:299
Small struct to store and manipulate ToD colors.
Definition: time_of_day.hpp:30
In order to render a hex properly it needs to be rendered per row.
Definition: display.hpp:988
std::shared_ptr< gui::zoom_slider > find_slider(const std::string &id)
Definition: display.cpp:846
std::vector< surface > surf_
surface(s) to render.
Definition: display.hpp:1050
virtual bool in_editor() const
Definition: display.hpp:208
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:592
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:452
theme & get_theme()
Definition: display.hpp:385
void set_draw_terrain_codes(bool value)
Setter for the terrain code debug overlay on tiles.
Definition: display.hpp:371
void invalidate_animations()
Function to invalidate animated terrains and units which may have changed.
Definition: display.cpp:3620
virtual void draw_sidebar()
Called near the end of a draw operation, derived classes can use this to render a specific sidebar...
Definition: display.hpp:723
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3536
iterator end() const
Definition: display.cpp:661
void draw_wrap(bool update, bool force)
Definition: display.cpp:1869
void flip()
Definition: display.cpp:1411
Definition: unit.hpp:95
boost::weak_ptr< wb::manager > wb_
Definition: display.hpp:665
bool animate_water_
Local version of preferences::animate_water, used to detect when it's changed.
Definition: display.hpp:842
void set_grid(const bool grid)
Determines whether a grid should be overlayed on the game board.
Definition: display.hpp:361
GLint level
Definition: glew.h:1220
std::map< surface, SDL_Rect > energy_bar_rects_
Definition: display.hpp:771
bool get_draw_terrain_codes() const
Getter for the terrain code debug overlay on tiles.
Definition: display.hpp:369
const std::string & get_variant(const std::vector< std::string > &variants, const map_location &loc) const
Definition: display.cpp:476
static void toggle_benchmark()
Toggle to continuously redraw the screen.
Definition: display.cpp:1401
CKey keys_
Definition: display.hpp:836
const SDL_Rect & mini_map_location(const SDL_Rect &screen) const
Definition: theme.hpp:282
void change_display_context(const display_context *dc)
Definition: display.cpp:493
const SDL_Rect & minimap_area() const
Definition: display.hpp:222
bool operator!=(const iterator &that) const
Definition: display.hpp:323
int ypos_
Definition: display.hpp:772
bool team_valid() const
Definition: display.hpp:99
bool reach_map_changed_
Definition: display.hpp:1131
const SDL_Rect & clip() const
Definition: display.hpp:1039
int y_
y screen coordinate to render at.
Definition: display.hpp:1046
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
void draw_init()
Initiate a redraw.
Definition: display.cpp:1825
void set_turbo(const bool turbo)
Set/Get whether 'turbo' mode is on.
Definition: display.hpp:509
void set_default_zoom()
Sets the zoom amount to the default.
Definition: display.cpp:2326
void set_idle_anim_rate(int rate)
Definition: display.cpp:2645
Sint32 fixed_t
Definition: drawer.hpp:40
void clear_exclusive_draws()
Cancels all the exclusive draw requests.
Definition: display.hpp:120
Top half of image following the mouse.
Definition: display.hpp:872
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:579
Definition: video.hpp:58
std::map< std::string, SDL_Rect > reportRects_
Definition: display.hpp:809
Used for the ellipse in front of the unit.
Definition: display.hpp:885
void draw_all_panels()
redraw all panels associated with the map display
Definition: display.cpp:1568
virtual void draw_invalidated()
Only called when there's actual redrawing to do.
Definition: display.cpp:2795
map_location mouseoverHex_
Definition: display.hpp:835
void init_flags()
Init the flag list and the team colors used by ~TC.
Definition: display.cpp:265
Manages a list of fake units for the display object.
bool draw_coordinates_
Debug flag - overlay x,y coords on tiles.
Definition: display.hpp:1155
Arrows from the arrows framework.
Definition: display.hpp:894
tblit(const tdrawing_layer layer, const map_location &loc, const int x, const int y, const surface &surf, const SDL_Rect &clip)
Definition: display.hpp:1018
void redraw_everything()
Invalidates entire screen, including all tiles and sidebar.
Definition: display.cpp:2650
int fps_handle_
Handle for the label which displays frames per second.
Definition: display.hpp:1142
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glew.h:3783
The class terrain_builder is constructed from a config object, and a gamemap object.
Definition: builder.hpp:43
virtual bool has_time_area() const
Definition: display.hpp:633
Footsteps showing path from unit to mouse.
Definition: display.hpp:871
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:723
bool blind
Definition: display.hpp:1202
Layer for the terrain drawn behind the unit.
Definition: display.hpp:865
Movement info (defense%, etc...).
Definition: display.hpp:902
void reset_halo_manager()
Definition: display.cpp:499
std::map< map_location, std::string > exclusive_unit_draw_requests_t
Definition: display.hpp:667
virtual void draw_border(const map_location &loc, const int xpos, const int ypos)
Draws the border tile overlay.
Definition: display.cpp:1963
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:2345
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:577
Layer which holds the attack indicator.
Definition: display.hpp:897
reach_map reach_map_
Definition: display.hpp:1129
const rect_of_hexes & rect_
Definition: display.hpp:334
double get_zoom_factor() const
Returns the current zoom factor.
Definition: display.hpp:269
iterator & operator++()
increment y first, then when reaching bottom, increment x
Definition: display.cpp:644
std::vector< std::function< void(display &)> > redraw_observers_
Definition: display.hpp:1152
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
Definition: display.cpp:713
bool tile_fully_on_screen(const map_location &loc)
Check if a tile is fully visible on screen.
Definition: display.cpp:2338
std::vector< surface > get_terrain_images(const map_location &loc, const std::string &timeid, image::TYPE type, TERRAIN_TYPE terrain_type)
Definition: display.cpp:1126
GLboolean GLboolean g
Definition: glew.h:7319
void clear_mouseover_hex_overlay()
Definition: display.hpp:461
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
map_location selectedHex_
Definition: display.hpp:834
void draw_text_in_hex(const map_location &loc, const tdrawing_layer layer, const std::string &text, size_t font_size, SDL_Color color, double x_in_hex=0.5, double y_in_hex=0.5)
Draw text on a hex.
Definition: display.cpp:1668
virtual int playing_side() const
Definition: display.hpp:212
CVideo & screen_
Definition: display.hpp:768
static Uint8 blue(Uint32 color)
Definition: display.hpp:182
static display * singleton_
Definition: display.hpp:1178
#define d
virtual void draw()
Draws invalidated items.
Definition: display.cpp:2706
terrain_builder & get_builder()
Definition: display.hpp:484
events::generic_event & scroll_event() const
Expose the event, so observers can be notified about map scrolling.
Definition: display.hpp:589
void enable_menu(const std::string &item, bool enable)
Finds the menu which has a given item in it, and enables or disables it.
Definition: display.cpp:1932
Rectangular area of hexes, allowing to decide how the top and bottom edges handles the vertical shift...
Definition: display.hpp:309
double idle_anim_rate() const
Definition: display.hpp:519
events::generic_event & complete_redraw_event()
Definition: display.hpp:591
-file sdl_utils.hpp
void clear_redraw_observers()
Clear the redraw observers.
Definition: display.cpp:2701
-file util.hpp
virtual bool in_game() const
Definition: display.hpp:207
void redraw_minimap()
Schedule the minimap to be redrawn.
Definition: display.hpp:629
virtual const gamemap & map() const =0
bool idle_anim() const
Definition: display.hpp:517
std::vector< surface > get_fog_shroud_images(const map_location &loc, image::TYPE image_type)
Definition: display.cpp:1019
void remove_arrow(arrow &)
Definition: display.cpp:3698
surface & getSurface()
Definition: dummy_video.cpp:22
drawing_buffer_key key_
Definition: display.hpp:1056
bool panelsDrawn_
Definition: display.hpp:786
surface tod_hex_mask2
Definition: display.hpp:829
Unit bars and overlays are drawn on this layer (for testing here).
Definition: display.hpp:898
Layer for the terrain drawn in front of the unit.
Definition: display.hpp:876
Top half part of grid image.
Definition: display.hpp:869
void update_display()
Copy the backbuffer to the framebuffer.
Definition: display.cpp:1446
Unit and team statistics.
Mouseover overlay used by editor.
Definition: display.hpp:870
int get_location_y(const map_location &loc) const
Definition: display.cpp:718
very simple iterator to walk into the rect_of_hexes
Definition: display.hpp:316
virtual const tod_manager & get_tod_man() const
This is implemented properly in game_display. The display:: impl could be pure virtual here but we de...
Definition: display.cpp:440
const SDL_Color GOOD_COLOR
Definition: font.cpp:567
"black stripes" on unreachable hexes.
Definition: display.hpp:891
std::vector< std::shared_ptr< gui::button > > action_buttons_
Definition: display.hpp:816
surface map_screenshot_surf_
Definition: display.hpp:1150
static const tdrawing_layer layer_groups[]
Definition: display.hpp:993
const theme::action * action_pressed()
Definition: display.cpp:1899
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
std::vector< std::string > shroud_images_
Definition: display.hpp:832
void draw_image_for_report(surface &img, SDL_Rect &rect)
Definition: display.cpp:3060
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:48
void blindfold(bool flag)
Definition: display.cpp:509
tdrawing_layer
The layers to render something on.
Definition: display.hpp:864
static Uint8 green(Uint32 color)
Definition: display.hpp:180
events::generic_event complete_redraw_event_
notify observers that the screen has been redrawn completely atm this is used for replay_controller t...
Definition: display.hpp:800
void parse_team_overlays()
Check the overlay_map for proper team-specific overlays to be displayed/hidden.
Definition: display.cpp:81
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
virtual const map_location & displayed_unit_hex() const
Virtual functions shadowed in game_display.
Definition: display.hpp:211
GLuint GLuint end
Definition: glew.h:1221
const map_location & mouseover_hex() const
Definition: display.hpp:293
std::list< tblit > tdrawing_buffer
Definition: display.hpp:1059
GLclampf GLclampf blue
Definition: glew.h:1488
void draw_minimap()
Definition: display.cpp:2088
size_t playing_team() const
The playing team is the team whose turn it is.
Definition: display.hpp:97
const theme::menu * menu_pressed()
Definition: display.cpp:1916
GLenum GLenum GLuint GLint GLint layer
Definition: glew.h:3455
Arrows destined to be drawn on the map.
Definition: arrow.hpp:30
GLclampf green
Definition: glew.h:1488
int gety() const
Definition: video.cpp:481
Animate units.
bool invalidate_visible_locations_in_rect(const SDL_Rect &rect)
Definition: display.cpp:3593
void recalculate_minimap()
Schedule the minimap for recalculation.
Definition: display.hpp:623
void scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type, bool force=true)
Definition: display.cpp:2355
const map_location & reference
Definition: display.hpp:330
virtual const game_data * get_game_data() const
Definition: display.hpp:169
GLsizei const GLfloat * value
Definition: glew.h:1817
bool get_draw_coordinates() const
Getter for the x,y debug overlay on tiles.
Definition: display.hpp:364
static Uint8 red(Uint32 color)
Definition: display.hpp:178
void set_draw_coordinates(bool value)
Setter for the x,y debug overlay on tiles.
Definition: display.hpp:366
bool map_screenshot_
Used to indicate to drawing functions that we are doing a map screenshot.
Definition: display.hpp:1114
arrows_map_t arrows_map_
Maps the list of arrows for each location.
Definition: display.hpp:1162
virtual image::TYPE get_image_type(const map_location &loc)
Definition: display.cpp:3041
This class is the frontend of the whiteboard framework for the rest of the Wesnoth code...
Definition: manager.hpp:43
int xpos_
Definition: display.hpp:772
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
void render_buttons()
Definition: display.cpp:984
bool dirty_
Definition: display.hpp:1166
Encapsulates the map of the game.
Definition: map.hpp:37
void unblind()
Definition: display.hpp:1193
bool idle_anim_
Definition: display.hpp:1147
SDL_Rect minimap_location_
Definition: display.hpp:780
void render_image(int x, int y, const display::tdrawing_layer drawing_layer, const map_location &loc, surface image, bool hreverse=false, bool greyscale=false, fixed_t alpha=ftofxp(1.0), Uint32 blendto=0, double blend_ratio=0, double submerged=0.0, bool vreverse=false)
Draw an image at a certain location.
Definition: display.cpp:1724
int w() const
the dimensions of the display.
Definition: display.hpp:220
const SDL_Rect & max_map_area() const
Returns the maximum area used for the map regardless to resolution and view size. ...
Definition: display.cpp:523
GLclampf GLclampf GLclampf alpha
Definition: glew.h:1488
tod_color color_adjust_
Definition: display.hpp:1164
bool operator<(const drawing_buffer_key &rhs) const
Definition: display.hpp:999
const SDL_Rect & unit_image_location(const SDL_Rect &screen) const
Definition: theme.hpp:284
default layer for missile frames
Definition: display.hpp:889
default layer for drawing moving units
Definition: display.hpp:884
void bounds_check_position()
Definition: display.cpp:2587
virtual void post_draw()
Called at the very end of each draw() call.
Definition: display.hpp:687
bool invalidateGameStatus_
Definition: display.hpp:789
void update_arrow(arrow &a)
Called by arrow objects when they change.
Definition: display.cpp:3707
bool zoom_at_min() const
Definition: display.cpp:2280
virtual const unit_map & units() const =0
int h() const
height
Definition: display.hpp:221
int nextDraw_
Holds the tick count for when the next drawing event is scheduled.
Definition: display.hpp:806
void set_mouseover_hex_overlay(const surface &image)
mouseover_hex_overlay_ require a prerendered surface and is drawn underneath the mouse's location ...
Definition: display.hpp:458
void create_buttons()
Definition: display.cpp:897
virtual const time_of_day & get_time_of_day(const map_location &loc=map_location::null_location()) const
Definition: display.cpp:430
static const map_location & null_location()
Definition: location.hpp:195
int zoom_
Definition: display.hpp:775
int x() const
Definition: display.hpp:1033
void invalidate_all()
Function to invalidate all tiles.
Definition: display.cpp:3525
void layout_buttons()
Definition: display.cpp:856
bool is_blindfolded() const
Definition: display.cpp:517
int viewing_side() const
Definition: display.hpp:103
int invalidated_hexes_
Count work done for the debug info displayed under fps.
Definition: display.hpp:1144
bool draw_terrain_codes_
Debug flag - overlay terrain codes on tiles.
Definition: display.hpp:1157
surf
Definition: filter.cpp:143
const SDL_Rect & palette_area() const
Definition: display.hpp:224
GLuint color
Definition: glew.h:5801
tdrawing_buffer drawing_buffer_
Definition: display.hpp:1060
const std::string &parameters float amount
Definition: filter.cpp:132
const unit_map & get_units() const
Definition: display.hpp:121
int x_
x screen coordinate to render at.
Definition: display.hpp:1045
void write(config &cfg) const
Definition: display.cpp:3721
Encapsulates the map of the game.
Definition: location.hpp:38
Used for the ellipse behind the unit.
Definition: display.hpp:874
double turbo_speed() const
Definition: display.cpp:2631
Reserve layers to be selected for WML.
Definition: display.hpp:873
boost::scoped_ptr< terrain_builder > builder_
Definition: display.hpp:778
default layer for drawing units
Definition: display.hpp:875
boost::scoped_ptr< map_labels > map_labels_
Definition: display.hpp:790
void process_reachmap_changes()
Definition: display.cpp:3737
virtual void handle_event(const SDL_Event &)
Definition: display.cpp:3793
surface & get_screen_surface()
return the screen surface or the surface used for map_screenshot.
Definition: display.hpp:205
surface tod_hex_mask1
Definition: display.hpp:829
const SDL_Rect & palette_location(const SDL_Rect &screen) const
Definition: theme.hpp:286
void set_playing_team(size_t team)
set_playing_team sets the team whose turn it currently is
Definition: display.cpp:398
SDL_Rect screen_area() const
Definition: display.hpp:229
virtual const std::vector< team > & teams() const =0
Move numbering for the whiteboard.
Definition: display.hpp:895
static int last_zoom_
Definition: display.hpp:776
Fog and shroud.
Definition: display.hpp:893
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:2434
int hex_width() const
Function which returns the width of a hex in pixels, up to where the next hex starts.
Definition: display.hpp:260
virtual void highlight_hex(map_location hex)
Definition: display.cpp:1800
int getx() const
Definition: video.cpp:472
static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
Definition: display.hpp:176
std::vector< std::shared_ptr< gui::button > > menu_buttons_
Definition: display.hpp:816
int y() const
Definition: display.hpp:1034
Contains a wrapper class for the GPU_Image class.
void set_diagnostic(const std::string &msg)
Definition: display.cpp:1807
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:2446
void invalidate_animations_location(const map_location &loc)
Per-location invalidation called by invalidate_animations() Extra game per-location invalidation (vil...
Definition: display.cpp:3610
bool shrouded(const map_location &loc) const
Returns true if location (x,y) is covered in shroud.
Definition: display.hpp:349
blindfold(display &d, bool lock=true)
Definition: display.hpp:1183
static Uint32 max_rgb(Uint32 first, Uint32 second)
Definition: display.hpp:184
void set_turbo_speed(const double speed)
Definition: display.hpp:513
drawing_buffer_key(const map_location &loc, tdrawing_layer layer)
Definition: display.cpp:1296
Definition: theme.hpp:37
virtual ~display()
Definition: display.cpp:258
bool redraw_background_
Definition: display.hpp:782
void read(const config &cfg)
Definition: display.cpp:3729
bool dont_show_all_
Definition: display.hpp:770
Definitions related to theme-support.
void init_flags_for_side_internal(size_t side, const std::string &side_color)
Definition: display.cpp:292
display(const display_context *dc, CVideo &video, boost::weak_ptr< wb::manager > wb, reports &reports_object, const config &theme_cfg, const config &level, bool auto_join=true)
Definition: display.cpp:147
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:112
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
bool invalidate_locations_in_rect(const SDL_Rect &rect)
invalidate all hexes under the rectangle rect (in screen coordinates)
Definition: display.cpp:3598
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:405
const map_location * pointer
Definition: display.hpp:329
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
Definition: display.cpp:2833
const SDL_Rect & unit_image_area() const
Definition: display.hpp:226
theme theme_
Definition: display.hpp:774
GLdouble GLdouble GLdouble r
Definition: glew.h:1374
virtual const SDL_Rect & get_clip_rect()
Get the clipping rectangle for drawing.
Definition: display.cpp:2790
bool view_locked_
Definition: display.hpp:773
The overlay used for the linger mode.
Definition: display.hpp:903
surface mouseover_hex_overlay_
Definition: display.hpp:826
std::map< map_location, arrows_list_t > arrows_map_t
Definition: display.hpp:1160
void set_view_locked(bool value)
Sets whether the map view is locked (e.g.
Definition: display.hpp:549
void set_idle_anim(bool ison)
control unit idle animations and their frequency
Definition: display.hpp:516
Helper structure for rendering the terrains.
Definition: display.hpp:1003
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:666
std::list< arrow * > arrows_list_t
Definition: display.hpp:1159
std::vector< std::string > fog_images_
Definition: display.hpp:831
const rect_of_hexes get_visible_hexes() const
Returns the rectangular area of visible hexes.
Definition: display.hpp:346
display & display_
Definition: display.hpp:1201
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
Definition: rect.cpp:28
std::map< map_location, unsigned int > reach_map
Definition: display.hpp:1128
bool redrawMinimap_
Definition: display.hpp:781
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)
Functions to add and remove overlays from locations.
Definition: display.cpp:97
overlay_map * overlays_
Definition: display.hpp:1139
size_t activeTeam_
Definition: display.hpp:959
Definition: display.hpp:43
reach_map reach_map_old_
Definition: display.hpp:1130
static std::map< std::string, std::string > images
Definition: about.cpp:58
const SDL_Rect & map_area() const
Returns the area used for the map.
Definition: display.cpp:540
virtual void post_commit()
Hook for actions to take right after draw() calls drawing_buffer_commit No action here by default...
Definition: display.hpp:707
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:669
Contains the SDL_Rect helper code.
iterator(const map_location &loc, const rect_of_hexes &rect)
Definition: display.hpp:317
bool invalidateAll_
Definition: display.hpp:783
events::generic_event scroll_event_
Event raised when the map is being scrolled.
Definition: display.hpp:794
void reload_map()
Updates internals that cache map size.
Definition: display.cpp:487
SDL_Rect clip_
The clipping area of the source if omitted the entire source is used.
Definition: display.hpp:1051
const gamemap & get_map() const
Definition: display.hpp:92
std::map< std::string, surface > reportSurfaces_
Definition: display.hpp:813
std::set< map_location > invalidated_
Definition: display.hpp:818
cl_event event
Definition: glew.h:3070
void clear_screen()
Clear the screen contents.
Definition: display.cpp:2783
Image on the selected unit.
Definition: display.hpp:896
void drawing_buffer_clear()
Clears the drawing buffer.
Definition: display.cpp:1390
const SDL_Rect & main_map_location(const SDL_Rect &screen) const
Definition: theme.hpp:280
std::map< std::string, config > reports_
Definition: display.hpp:815
const display_context * dc_
Definition: display.hpp:663
std::forward_iterator_tag iterator_category
Definition: display.hpp:326
GLint GLvoid * img
Definition: glew.h:1353
bool show_everything() const
Definition: display.hpp:90
this module manages the cache of images.
Definition: image.cpp:75
double idle_anim_rate_
Definition: display.hpp:1148
void update_tod()
Add r,g,b from tod_manager to the map.
Definition: display.cpp:446
int drawn_hexes_
Definition: display.hpp:1145
double turbo_speed_
Definition: display.hpp:787
gui::button::TYPE string_to_button_type(std::string type)
Definition: display.cpp:1000
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
Definition: display.hpp:248
int diagnostic_label_
Definition: display.hpp:785
void add_redraw_observer(std::function< void(display &)> f)
Adds a redraw observer, a function object to be called when redraw_everything is used.
Definition: display.cpp:2696
CVideo & video()
Gets the underlying screen object.
Definition: display.hpp:202
GLint * first
Definition: glew.h:1496
GLint GLint bottom
Definition: glew.h:5907
Container associating units to locations.
Definition: map.hpp:90
void reinit_flags_for_side(size_t side)
Rebuild the flag list (not team colors) for a single side.
Definition: display.cpp:282
Bottom half of image following the mouse.
Definition: display.hpp:892
const display_context & get_disp_context() const
Definition: display.hpp:167
map_labels & labels()
Definition: display.cpp:2773
bool outside_area(const SDL_Rect &area, const int x, const int y) const
Check if the bbox of the hex at x,y has pixels outside the area rectangle.
Definition: display.cpp:568
void fill_images_list(const std::string &prefix, std::vector< std::string > &images)
Definition: display.cpp:458
std::vector< animated< image::locator > > flags_
Animated flags for each team.
Definition: display.hpp:855
size_t viewing_team() const
The viewing team is the team currently viewing the game.
Definition: display.hpp:102
const map_location & operator*() const
Definition: display.hpp:324
bool zoom_at_max() const
Definition: display.cpp:2275
boost::scoped_ptr< halo::manager > halo_man_
Definition: display.hpp:664
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void refresh_report(std::string const &report_name, const config *new_cfg=nullptr)
Redraws the specified report (if anything has changed).
Definition: display.cpp:3099
Class that keeps track of all the keys on the keyboard.
Definition: key.hpp:27
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:124
int hex_size() const
Function which returns the size of a hex in pixels (from top tip to bottom tip or left edge to right ...
Definition: display.hpp:266
bool view_locked() const
Definition: display.hpp:546
surface get_flag(const map_location &loc)
Definition: display.cpp:358
std::vector< std::shared_ptr< gui::zoom_slider > > sliders_
Definition: display.hpp:817
const int font_size
iterator begin() const
Definition: display.cpp:657
void announce(const std::string &msg, const SDL_Color &color=font::GOOD_COLOR)
Announce a message prominently.
Definition: display.cpp:1950
bool operator<(const tblit &rhs) const
Definition: display.hpp:1042
bool scroll(int xmov, int ymov, bool force=false)
Scrolls the display by xmov,ymov pixels.
Definition: display.cpp:2206
bool turbo_
Definition: display.hpp:788
void add_arrow(arrow &)
Definition: display.cpp:3689
void remove_overlay(const map_location &loc)
remove_overlay will remove all overlays on a tile.
Definition: display.cpp:108
const std::vector< team > & get_teams() const
Definition: display.hpp:94
bool animate_map_
Local cache for preferences::animate_map, since it is constantly queried.
Definition: display.hpp:839
static void toggle_debug_foreground()
Toggle to debug foreground terrain.
Definition: display.cpp:1406
GLsizei const GLcharARB ** string
Definition: glew.h:4503
virtual game_lua_kernel * get_lua_kernel() const
TODO: display should not work as a filter context, this was only done for expedience so that the unit...
Definition: display.hpp:170
void invalidate_theme()
Definition: display.hpp:408
std::multimap< map_location, overlay > overlay_map
Definition: display.hpp:1134
void reset_reports(reports &reports_object)
Definition: display.hpp:652
std::shared_ptr< gui::button > find_menu_button(const std::string &id)
Definition: display.cpp:836
const map_location & selected_hex() const
Definition: display.hpp:292
Definition: display.hpp:47
The border of the map.
Definition: display.hpp:904
int blindfold_ctr_
Definition: display.hpp:659
TERRAIN_TYPE
Definition: display.hpp:740
bool grid_
Definition: display.hpp:784
#define ftofxp(x)
IN: float or int - OUT: fixed_t.
Definition: util.hpp:503
std::string remove_exclusive_draw(const map_location &loc)
Cancels an exclusive draw request.
Definition: display.cpp:418
void rebuild_all()
Rebuild all dynamic terrain.
Definition: display.cpp:482
bool set_zoom(int amount, bool absolute=false)
Zooms the display by the specified amount.
Definition: display.cpp:2285
bool propagate_invalidation(const std::set< map_location > &locs)
If this set is partially invalidated, invalidate all its hexes.
Definition: display.cpp:3563
void replace_overlay_map(overlay_map *overlays)
Definition: display.hpp:1175
bool screenshot(const std::string &filename, bool map_screenshot=false)
Save a (map-)screenshot and return whether the operation succeeded.
Definition: display.cpp:753
GLclampf f
Definition: glew.h:3024
const std::vector< surface > & surf() const
Definition: display.hpp:1038
surface minimap_
Definition: display.hpp:779
void set_team(size_t team, bool observe=false)
Sets the team controlled by the player using the computer.
Definition: display.cpp:379
tblit(const tdrawing_layer layer, const map_location &loc, const int x, const int y, const std::vector< surface > &surf, const SDL_Rect &clip)
Definition: display.hpp:1025