The Battle for Wesnoth  1.13.11+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
editor_display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Tomasz Sniatowski <kailoran@gmail.com>
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 #define GETTEXT_DOMAIN "wesnoth-editor"
15 
18 #include "reports.hpp"
19 #include "team.hpp"
20 #include "terrain/builder.hpp"
21 #include "units/map.hpp"
22 
23 namespace wb {
24  class manager;
25 }
26 
27 namespace editor {
28 
30  : display(nullptr, std::shared_ptr<wb::manager>(), reports_object, theme_cfg, config())
31  , brush_locations_()
32  , controller_(controller)
33 {
34  video().clear_screen();
35 }
36 
38 {
39  brush_locations_.insert(hex);
40  invalidate(hex);
41 }
42 
43 void editor_display::set_brush_locs(const std::set<map_location>& hexes)
44 {
46  brush_locations_ = hexes;
48 }
49 
51 {
53  brush_locations_.clear();
54 }
55 
57 {
58  brush_locations_.erase(hex);
59  invalidate(hex);
60 }
61 
63  builder_->rebuild_terrain(loc);
64 }
65 
67 {
68 }
69 
71 {
72  if (map().in_selection(loc)) {
73  return image::BRIGHTENED;
74  }
75  return image::TOD_COLORED;
76 }
77 
79 {
80  int xpos = get_location_x(loc);
81  int ypos = get_location_y(loc);
82  display::draw_hex(loc);
83  if (map().on_board_with_border(loc)) {
84  if (map().in_selection(loc)) {
85  drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
86  image::get_image("editor/selection-overlay.png", image::TOD_COLORED));
87  }
88 
89  if (brush_locations_.find(loc) != brush_locations_.end()) {
91  drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
93  }
94  }
95 }
96 
98 {
99  return map_outside_area();
100 }
101 
103 {
104  config element;
105  config::attribute_value &text = element.add_child("element")["text"];
106  // Fill in the terrain report
107  if (get_map().on_board_with_border(mouseoverHex_)) {
109  refresh_report("terrain", &element);
110  refresh_report("terrain_info");
112  refresh_report("position", &element);
113  }
114 
115  if (dc_->teams().empty()) {
116  text = int(get_map().villages().size());
117  refresh_report("villages", &element);
118  } else {
119  refresh_report("villages");
120  refresh_report("num_units");
121  }
122 }
123 
125 {
127 }
128 
129 } //end namespace editor
editor_display(editor_controller &controller, reports &reports_object, const config &theme_cfg)
TYPE
UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM :...
Definition: image.hpp:189
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
Definition: image.cpp:920
image::TYPE get_image_type(const map_location &loc) override
The editor uses different rules for terrain highlighting (e.g.
std::vector< char_t > string
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3020
std::string get_terrain_editor_string(const map_location &loc) const
Definition: map.cpp:63
editor_controller & controller_
Variant for storing WML attributes.
const time_of_day & get_time_of_day(int for_turn=0) const
Returns global time of day for the passed turn.
Definition: tod_manager.hpp:54
void set_brush_locs(const std::set< map_location > &hexes)
map_location mouseoverHex_
Definition: display.hpp:783
STL namespace.
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
Definition: display.cpp:731
-file sdl_utils.hpp
To lexical_cast(From value)
Lexical cast converts one type to another.
The editor_controller class contains the mouse and keyboard event handling routines for the editor...
Unit and team statistics.
int get_location_y(const map_location &loc) const
Definition: display.cpp:736
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57
map_context & get_current_map_context() const
Image on the selected unit.
Definition: display.hpp:843
void draw_sidebar() override
Called near the end of a draw operation, derived classes can use this to render a specific sidebar...
void remove_brush_loc(const map_location &hex)
void pre_draw() override
Called near the beginning of each draw() call.
virtual const time_of_day & get_time_of_day(const map_location &loc=map_location::null_location()) const override
Inherited from display.
The brush class represents a single brush – a set of relative locations around a "hotspot"...
Definition: brush.hpp:25
Manage the empty-palette in the editor.
Definition: action.cpp:29
Fog and shroud.
Definition: display.hpp:840
Encapsulates the map of the game.
Definition: location.hpp:42
size_t size(const utf8::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
virtual const std::vector< team > & teams() const =0
std::string editor_brush
void rebuild_terrain(const map_location &loc)
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
Definition: display.cpp:2583
const SDL_Rect & get_clip_rect() override
Get the clipping rectangle for drawing.
std::set< map_location > brush_locations_
Definitions for the terrain builder.
config & add_child(config_key_type key)
Definition: config.cpp:475
void drawing_buffer_add(const drawing_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:1218
const gamemap & get_map() const
Definition: display.hpp:91
const display_context * dc_
Definition: display.hpp:652
void add_brush_loc(const map_location &hex)
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
Definition: display.hpp:236
CVideo & video()
Gets the underlying screen object.
Definition: display.hpp:195
const tod_manager * get_time_manager() const
void draw_hex(const map_location &loc) override
Redraws a single gamemap location.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
void clear_screen()
Clear the screen contents.
Definition: video.cpp:370
const std::unique_ptr< terrain_builder > builder_
Definition: display.hpp:739
void refresh_report(const std::string &report_name, const config *new_cfg=nullptr)
Redraws the specified report (if anything has changed).
Definition: display.cpp:2802
Definition: display.hpp:47
const editor_map & map() const