The Battle for Wesnoth  1.17.0-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 namespace gui2
24 {
25 namespace implementation
26 {
27 struct builder_minimap;
28 }
29 
30 // ------------ WIDGET -----------{
31 
32 /**
33  * @ingroup GUIWidgetWML
34  *
35  * The basic minimap class.
36  * This minimap can only show a minimap, but it can't be interacted with.
37  *
38  * The following states exist:
39  * * state_enabled - the minimap is enabled.
40  * A minimap has no extra fields.
41  */
42 class minimap : public styled_widget
43 {
44 public:
45  explicit minimap(const implementation::builder_minimap& builder);
46 
47  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
48 
49  /** See @ref styled_widget::set_active. */
50  virtual void set_active(const bool active) override;
51 
52  /** See @ref styled_widget::get_active. */
53  virtual bool get_active() const override;
54 
55  /** See @ref styled_widget::get_state. */
56  virtual unsigned get_state() const override;
57 
58  /** See @ref widget::disable_click_dismiss. */
59  bool disable_click_dismiss() const override;
60 
61  /***** ***** ***** setters / getters for members ***** ****** *****/
62 
63  void set_map_data(const std::string& map_data)
64  {
65  if(map_data != map_data_) {
66  map_data_ = map_data;
67  set_is_dirty(true);
68  }
69  }
70 
71  std::string get_map_data() const
72  {
73  return map_data_;
74  }
75 
76  const std::string& map_data() const
77  {
78  return map_data_;
79  }
80 
81 private:
82  /** The map data to be used to generate the map. */
83  std::string map_data_;
84 
85  /**
86  * Gets the image for the minimap.
87  *
88  * @param w The wanted width of the image.
89  * @param h The wanted height of the image.
90  *
91  * @returns The image, nullptr upon error.
92  */
93  const surface get_image(const int w, const int h) const;
94 
95  /** See @ref widget::impl_draw_background. */
96  virtual void impl_draw_background(surface& frame_buffer,
97  int x_offset,
98  int y_offset) override;
99 
100 public:
101  /** Static type getter that does not rely on the widget being constructed. */
102  static const std::string& type();
103 
104 private:
105  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
106  virtual const std::string& get_control_type() const override;
107 };
108 
109 // }---------- DEFINITION ---------{
110 
112 {
113  explicit minimap_definition(const config& cfg);
114 
116  {
117  explicit resolution(const config& cfg);
118  };
119 };
120 
121 // }---------- BUILDER -----------{
122 
123 namespace implementation
124 {
125 
127 {
128  explicit builder_minimap(const config& cfg);
129 
131 
132  virtual widget* build() const override;
133 };
134 
135 } // namespace implementation
136 
137 // }------------ END --------------
138 
139 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
Definition: picture.cpp:815
virtual widget * build() const =0
void set_map_data(const std::string &map_data)
Definition: minimap.hpp:63
std::string get_map_data() const
Definition: minimap.hpp:71
std::string map_data_
The map data to be used to generate the map.
Definition: minimap.hpp:83
Base class for all widgets.
Definition: widget.hpp:48
const std::string & map_data() const
Definition: minimap.hpp:76
#define h
Generic file dialog.
Definition: field-fwd.hpp:22
int w
Base class for all visible items.
The basic minimap class.
Definition: minimap.hpp:42
point resolution()
Definition: general.cpp:392
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.