The Battle for Wesnoth  1.17.0-dev
minimap.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
19 
22 
23 class config;
24 namespace gui2
25 {
26 namespace implementation
27 {
28 struct builder_minimap;
29 }
30 
31 // ------------ WIDGET -----------{
32 
33 /**
34  * @ingroup GUIWidgetWML
35  *
36  * The basic minimap class.
37  * This minimap can only show a minimap, but it can't be interacted with.
38  *
39  * The following states exist:
40  * * state_enabled - the minimap is enabled.
41  * A minimap has no extra fields.
42  */
43 class minimap : public styled_widget
44 {
45 public:
46  explicit minimap(const implementation::builder_minimap& builder);
47 
48  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
49 
50  /** See @ref styled_widget::set_active. */
51  virtual void set_active(const bool active) override;
52 
53  /** See @ref styled_widget::get_active. */
54  virtual bool get_active() const override;
55 
56  /** See @ref styled_widget::get_state. */
57  virtual unsigned get_state() const override;
58 
59  /** See @ref widget::disable_click_dismiss. */
60  bool disable_click_dismiss() const override;
61 
62  /***** ***** ***** setters / getters for members ***** ****** *****/
63 
64  void set_map_data(const std::string& map_data)
65  {
66  if(map_data != map_data_) {
67  map_data_ = map_data;
68  set_is_dirty(true);
69  }
70  }
71 
72  std::string get_map_data() const
73  {
74  return map_data_;
75  }
76 
77  const std::string& map_data() const
78  {
79  return map_data_;
80  }
81 
82 private:
83  /** The map data to be used to generate the map. */
84  std::string map_data_;
85 
86  /**
87  * Gets the image for the minimap.
88  *
89  * @param w The wanted width of the image.
90  * @param h The wanted height of the image.
91  *
92  * @returns The image, nullptr upon error.
93  */
94  const surface get_image(const int w, const int h) const;
95 
96  /** See @ref widget::impl_draw_background. */
97  virtual void impl_draw_background(surface& frame_buffer,
98  int x_offset,
99  int y_offset) override;
100 
101 public:
102  /** Static type getter that does not rely on the widget being constructed. */
103  static const std::string& type();
104 
105 private:
106  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
107  virtual const std::string& get_control_type() const override;
108 };
109 
110 // }---------- DEFINITION ---------{
111 
113 {
114  explicit minimap_definition(const config& cfg);
115 
117  {
118  explicit resolution(const config& cfg);
119  };
120 };
121 
122 // }---------- BUILDER -----------{
123 
124 namespace implementation
125 {
126 
128 {
129  explicit builder_minimap(const config& cfg);
130 
132 
133  virtual widget* build() const override;
134 };
135 
136 } // namespace implementation
137 
138 // }------------ END --------------
139 
140 } // 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:816
virtual widget * build() const =0
void set_map_data(const std::string &map_data)
Definition: minimap.hpp:64
std::string get_map_data() const
Definition: minimap.hpp:72
std::string map_data_
The map data to be used to generate the map.
Definition: minimap.hpp:84
Base class for all widgets.
Definition: widget.hpp:49
const std::string & map_data() const
Definition: minimap.hpp:77
#define h
Generic file dialog.
Definition: field-fwd.hpp:23
int w
Base class for all visible items.
The basic minimap class.
Definition: minimap.hpp:43
point resolution()
Definition: general.cpp:393
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:61
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.