The Battle for Wesnoth  1.13.4+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 - 2016 by Tomasz Sniatowski <[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 #define GETTEXT_DOMAIN "wesnoth-editor"
15 
16 #include "editor_display.hpp"
17 #include "reports.hpp"
18 #include "terrain/builder.hpp"
19 #include "units/map.hpp"
20 
21 #include <boost/shared_ptr.hpp>
22 
23 namespace wb {
24  class manager;
25 }
26 
27 namespace editor {
28 
29 // Define dummy display context;
30 
32 {
34 
37  std::vector<team> t;
38  std::vector<std::string> lbls;
39 
40 public:
41  dummy_editor_display_context() : dummy_cfg1(), em(dummy_cfg1), u(), t(), lbls() {}
43 
44  virtual const gamemap & map() const { return em; }
45  virtual const unit_map & units() const { return u; }
46  virtual const std::vector<team> & teams() const { return t; }
47  virtual const std::vector<std::string> & hidden_label_categories() const { return lbls; }
48 };
49 
52  return &dedc;
53 }
54 
55 // End dummy display context
56 
58  reports & reports_object,
59  const config& theme_cfg, const config& level)
60  : display(dc, video, boost::shared_ptr<wb::manager>(), reports_object, theme_cfg, level)
61  , brush_locations_()
62 {
63  clear_screen();
64 }
65 
67 {
68  brush_locations_.insert(hex);
69  invalidate(hex);
70 }
71 
72 void editor_display::set_brush_locs(const std::set<map_location>& hexes)
73 {
75  brush_locations_ = hexes;
77 }
78 
80 {
82  brush_locations_.clear();
83 }
84 
86 {
87  brush_locations_.erase(hex);
88  invalidate(hex);
89 }
90 
92  builder_->rebuild_terrain(loc);
93 }
94 
96 {
97 }
98 
100 {
101  if (map().in_selection(loc)) {
102  return image::BRIGHTENED;
103  }
104  return image::TOD_COLORED;
105 }
106 
108 {
109  int xpos = get_location_x(loc);
110  int ypos = get_location_y(loc);
111  display::draw_hex(loc);
112  if (map().on_board_with_border(loc)) {
113 #ifdef SDL_GPU
114  if (map().in_selection(loc)) {
115  drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
116  image::get_texture("editor/selection-overlay.png", image::TOD_COLORED));
117  }
118 
119  if (brush_locations_.find(loc) != brush_locations_.end()) {
121  drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
122  image::get_texture(brush, image::SCALED_TO_HEX));
123  }
124 #else
125  if (map().in_selection(loc)) {
126  drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
127  image::get_image("editor/selection-overlay.png", image::TOD_COLORED));
128  }
129 
130  if (brush_locations_.find(loc) != brush_locations_.end()) {
132  drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
134  }
135 #endif
136  }
137 }
138 
140 {
141  return map_outside_area();
142 }
143 
145 {
146  config element;
147  config::attribute_value &text = element.add_child("element")["text"];
148  // Fill in the terrain report
149  if (get_map().on_board_with_border(mouseoverHex_)) {
151  refresh_report("terrain", &element);
152  refresh_report("terrain_info");
154  refresh_report("position", &element);
155  }
156 
157  if (dc_->teams().empty()) {
158  text = int(get_map().villages().size());
159  refresh_report("villages", &element);
160  } else {
161  refresh_report("villages");
162  refresh_report("num_units");
163  }
164 }
165 
166 
167 } //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: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
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
Definition: image.cpp:878
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3536
GLint level
Definition: glew.h:1220
std::string get_terrain_editor_string(const map_location &loc) const
Definition: map.cpp:65
editor_display(const display_context *dc, CVideo &video, reports &reports_object, const config &theme_cfg, const config &level)
image::TYPE get_image_type(const map_location &loc)
The editor uses different rules for terrain highlighting (e.g.
void set_brush_locs(const std::set< map_location > &hexes)
Definition: video.hpp:58
map_location mouseoverHex_
Definition: display.hpp:835
virtual const std::vector< std::string > & hidden_label_categories() const
void pre_draw()
Called near the beginning of each draw() call.
void draw_sidebar()
Called near the end of a draw operation, derived classes can use this to render a specific sidebar...
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
Definition: display.cpp:713
To lexical_cast(From value)
Lexical cast converts one type to another.
std::vector< std::string > lbls
Variant for storing WML attributes.
Definition: config.hpp:223
Unit and team statistics.
int get_location_y(const map_location &loc) const
Definition: display.cpp:718
void draw_hex(const map_location &loc)
Redraws a single gamemap location.
void remove_brush_loc(const map_location &hex)
Encapsulates the map of the game.
Definition: map.hpp:37
config & add_child(const std::string &key)
Definition: config.cpp:743
The brush class represents a single brush – a set of relative locations around a "hotspot"...
Definition: brush.hpp:26
Manage the empty-palette in the editor.
Definition: action.cpp:28
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
Encapsulates the map of the game.
Definition: location.hpp:38
boost::scoped_ptr< terrain_builder > builder_
Definition: display.hpp:778
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:70
virtual const std::vector< team > & teams() const =0
std::string editor_brush
Definition: game_config.cpp:84
Fog and shroud.
Definition: display.hpp:893
const display_context * get_dummy_display_context()
void rebuild_terrain(const map_location &loc)
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
Definition: display.cpp:2833
const SDL_Rect & get_clip_rect()
Get the clipping rectangle for drawing.
std::set< map_location > brush_locations_
Definitions for the terrain builder.
GLsizeiptr size
Definition: glew.h:1649
virtual const std::vector< team > & teams() const
virtual const unit_map & units() const
const gamemap & get_map() const
Definition: display.hpp:92
void clear_screen()
Clear the screen contents.
Definition: display.cpp:2783
Image on the selected unit.
Definition: display.hpp:896
const display_context * dc_
Definition: display.hpp:663
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:248
Container associating units to locations.
Definition: map.hpp:90
virtual const gamemap & map() const
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
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Definition: display.hpp:47
const editor_map & map() const