The Battle for Wesnoth  1.15.2+dev
minimap.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
16 
18 
21 
22 class config;
23 
24 namespace gui2
25 {
26 namespace implementation
27 {
28 struct builder_minimap;
29 }
30 
31 // ------------ WIDGET -----------{
32 
33 /**
34  * The basic minimap class.
35  *
36  * This minimap can only show a minimap, but it can't be interacted with. For
37  * that the tminimap_interactive class will be created.
38  */
39 class minimap : public styled_widget
40 {
41 public:
42  explicit minimap(const implementation::builder_minimap& builder);
43 
44  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
45 
46  /** See @ref styled_widget::set_active. */
47  virtual void set_active(const bool active) override;
48 
49  /** See @ref styled_widget::get_active. */
50  virtual bool get_active() const override;
51 
52  /** See @ref styled_widget::get_state. */
53  virtual unsigned get_state() const override;
54 
55  /** See @ref widget::disable_click_dismiss. */
56  bool disable_click_dismiss() const override;
57 
58  /***** ***** ***** setters / getters for members ***** ****** *****/
59 
60  void set_map_data(const std::string& map_data)
61  {
62  if(map_data != map_data_) {
63  map_data_ = map_data;
64  set_is_dirty(true);
65  }
66  }
67 
68  std::string get_map_data() const
69  {
70  return map_data_;
71  }
72 
73  const std::string& map_data() const
74  {
75  return map_data_;
76  }
77 
78  void set_config(const ::config* terrain)
79  {
80  terrain_ = terrain;
81  }
82 
83 private:
84  /** The map data to be used to generate the map. */
85  std::string map_data_;
86 
87  /**
88  * The config object with the terrain data.
89  *
90  * This config must be set before the object can be drawn.
91  */
92  const ::config* terrain_;
93 
94  /**
95  * Gets the image for the minimap.
96  *
97  * @param w The wanted width of the image.
98  * @param h The wanted height of the image.
99  *
100  * @returns The image, nullptr upon error.
101  */
102  const surface get_image(const int w, const int h) const;
103 
104  /** See @ref widget::impl_draw_background. */
105  virtual void impl_draw_background(surface& frame_buffer,
106  int x_offset,
107  int y_offset) override;
108 
109 public:
110  /** Static type getter that does not rely on the widget being constructed. */
111  static const std::string& type();
112 
113 private:
114  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
115  virtual const std::string& get_control_type() const override;
116 };
117 
118 // }---------- DEFINITION ---------{
119 
121 {
122  explicit minimap_definition(const config& cfg);
123 
125  {
126  explicit resolution(const config& cfg);
127  };
128 };
129 
130 // }---------- BUILDER -----------{
131 
132 namespace implementation
133 {
134 
136 {
137  explicit builder_minimap(const config& cfg);
138 
140 
141  widget* build() const;
142 };
143 
144 } // namespace implementation
145 
146 // }------------ END --------------
147 
148 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
Definition: picture.cpp:875
virtual widget * build() const =0
void set_map_data(const std::string &map_data)
Definition: minimap.hpp:60
std::string get_map_data() const
Definition: minimap.hpp:68
std::string map_data_
The map data to be used to generate the map.
Definition: minimap.hpp:85
Base class for all widgets.
Definition: widget.hpp:47
const std::string & map_data() const
Definition: minimap.hpp:73
#define h
Generic file dialog.
Definition: field-fwd.hpp:22
const ::config * terrain_
The config object with the terrain data.
Definition: minimap.hpp:92
static const ::config * terrain
The terrain used to create the cache.
Definition: minimap.cpp:130
void set_config(const ::config *terrain)
Definition: minimap.hpp:78
window * build(const builder_window::window_resolution *definition)
Builds a window.
int w
Base class for all visible items.
The basic minimap class.
Definition: minimap.hpp:39
point resolution()
Definition: general.cpp:373
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.