The Battle for Wesnoth  1.15.0-dev
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 "lexical_cast.hpp"
19 #include "ogl/utils.hpp"
20 #include "overlay.hpp"
21 #include "reports.hpp"
22 #include "sdl/texture.hpp"
23 #include "team.hpp"
24 #include "terrain/builder.hpp"
25 #include "units/map.hpp"
26 
27 namespace wb {
28  class manager;
29 }
30 
31 namespace editor {
32 
33 editor_display::editor_display(editor_controller& controller, const config& theme_cfg)
34  : display(nullptr, std::shared_ptr<wb::manager>(), theme_cfg, config())
35  , brush_locations_()
36  , controller_(controller)
37 {
38 #ifdef USE_GL_RENDERING
39  gl::clear_screen();
40 #else
41  video().clear_screen();
42 #endif
43 }
44 
46 {
47  brush_locations_.insert(hex);
48 }
49 
50 void editor_display::set_brush_locs(const std::set<map_location>& hexes)
51 {
52  brush_locations_ = hexes;
53 }
54 
56 {
57  brush_locations_.clear();
58 }
59 
61 {
62  brush_locations_.erase(hex);
63 }
64 
66  builder_->rebuild_terrain(loc);
67 }
68 
70 {
71 }
72 
74 {
75  if (map().in_selection(loc)) {
76  return image::BRIGHTENED;
77  }
78  return image::TOD_COLORED;
79 }
80 
82 {
83  if(!map().on_board_with_border(loc)) {
84  return;
85  }
86 
88 
89  for(const map_location& b_loc : brush_locations_) {
90  render_scaled_to_zoom(brush, b_loc); // LAYER_SELECTED_HEX
91  }
92 }
93 
95 {
96  static texture selection_overlay(image::get_texture("editor/selection-overlay.png"));
97 
98  for(const map_location& s_loc : map().selection()) {
99  render_scaled_to_zoom(selection_overlay, s_loc); // LAYER_FOG_SHROUD
100  }
101 }
102 
104 {
105  return map_outside_area();
106 }
107 
108 // USE AS REFERENCE FOR WHAT NEEDS TO BE UPDATED IN GUI2 UI
109 #if 0
110 void editor_display::draw_sidebar()
111 {
112  config element;
113  config::attribute_value &text = element.add_child("element")["text"];
114  // Fill in the terrain report
115  if (get_map().on_board_with_border(mouseoverHex_)) {
117  refresh_report("terrain", &element);
118  refresh_report("terrain_info");
119  text = lexical_cast<std::string>(mouseoverHex_);
120  refresh_report("position", &element);
121  }
122 
123  if (dc_->teams().empty()) {
124  text = int(get_map().villages().size());
125  refresh_report("villages", &element);
126  } else {
127  refresh_report("villages");
128  refresh_report("num_units");
129  }
130 }
131 #endif
132 
134 {
136 }
137 
139 {
141 }
142 
143 } //end namespace editor
TYPE
UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM :...
Definition: image.hpp:181
const editor_map & map() const
image::TYPE get_image_type(const map_location &loc) override
The editor uses different rules for terrain highlighting (e.g.
editor_controller & controller_
static help_manager manager
The help manager.
Definition: help.cpp:34
virtual overlay_map & get_overlays() override
Inherited from display.
Variant for storing WML attributes.
New lexcical_cast header.
void set_brush_locs(const std::set< map_location > &hexes)
map_location mouseoverHex_
Definition: display.hpp:901
const SDL_Rect map_outside_area() const
Returns the available area for a map, this may differ from the above.
Definition: display.cpp:477
STL namespace.
-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...
Wrapper class to encapsulate creation and management of an SDL_Texture.
Definition: texture.hpp:26
overlay_map & get_overlays()
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
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
void remove_brush_loc(const map_location &hex)
void pre_draw() override
Called at the beginning of each draw cycle.
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
const SDL_Rect get_clip_rect() override
Get the clipping rectangle for drawing.
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
Encapsulates the map of the game.
Definition: location.hpp:42
virtual const std::vector< team > & teams() const =0
std::string editor_brush
std::string get_terrain_editor_string(const map_location &loc) const
Definition: map.cpp:61
void rebuild_terrain(const map_location &loc)
const tod_manager * get_time_manager() const
void render_scaled_to_zoom(const texture &tex, const int x_pos, const int y_pos, T &&... extra_args) const
Renders a texture directly to the screen (or current rendering target) scaled to the current zoom fac...
Definition: display.hpp:766
std::set< map_location > brush_locations_
Definitions for the terrain builder.
config & add_child(config_key_type key)
Definition: config.cpp:479
virtual void draw_hex_overlays() override
Draws various map overlays such as game reachmap.
const gamemap & get_map() const
Definition: display.hpp:109
const display_context * dc_
Definition: display.hpp:692
void add_brush_loc(const map_location &hex)
virtual void draw_hex_cursor(const map_location &loc) override
Draws the map&#39;s hex cursor.
CVideo & video()
Gets the underlying screen object.
Definition: display.hpp:237
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
void clear_screen()
Clear the screen contents.
Definition: video.cpp:309
const std::unique_ptr< terrain_builder > builder_
Definition: display.hpp:868
std::multimap< map_location, overlay > overlay_map
Definition: display.hpp:934
Definition: display.hpp:49
texture get_texture(const image::locator &i_locator, TYPE type)
Definition: image.cpp:1483