The Battle for Wesnoth  1.17.0-dev
image.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 namespace gui2
24 {
25 namespace implementation
26 {
27  struct builder_image;
28 }
29 
30 // ------------ WIDGET -----------{
31 
32 /**
33  * @ingroup GUIWidgetWML
34  *
35  * An image shows a static image.
36  *
37  * The label field of the widget is used as the name of file to show. The widget normally has no event interaction so only one state is defined:
38  * * state_enabled - the image is enabled.
39  */
40 class image : public styled_widget
41 {
42 public:
43  explicit image(const implementation::builder_image& builder);
44 
45  /**
46  * Wrapper for set_label.
47  *
48  * Some people considered this function missing and confusing so added
49  * this forward version.
50  *
51  * @param label The filename image to show.
52  */
53  void set_image(const t_string& label)
54  {
55  set_label(label);
56  }
57 
58  /**
59  * Wrapper for label.
60  *
61  * Some people considered this function missing and confusing so added
62  * this forward version.
63  *
64  * @returns The filename of the image shown.
65  */
67  {
68  return get_label();
69  }
70 
71  virtual bool can_mouse_focus() const override { return !tooltip().empty(); }
72 
73  /***** ***** ***** ***** layout functions ***** ***** ***** *****/
74 
75 private:
76  /** See @ref widget::calculate_best_size. */
77  virtual point calculate_best_size() const override;
78 
79 public:
80  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
81 
82  /** See @ref styled_widget::set_active. */
83  virtual void set_active(const bool active) override;
84 
85  /** See @ref styled_widget::get_active. */
86  virtual bool get_active() const override;
87 
88  /** See @ref styled_widget::get_state. */
89  virtual unsigned get_state() const override;
90 
91  /** See @ref widget::disable_click_dismiss. */
92  bool disable_click_dismiss() const override;
93 
94 private:
95  /**
96  * Possible states of the widget.
97  *
98  * Note the order of the states must be the same as defined in settings.hpp.
99  */
100  enum state_t {
102  };
103 
104 public:
105  /** Static type getter that does not rely on the widget being constructed. */
106  static const std::string& type();
107 
108 private:
109  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
110  virtual const std::string& get_control_type() const override;
111 };
112 
113 // }---------- DEFINITION ---------{
114 
116 {
117  explicit image_definition(const config& cfg);
118 
120  {
121  explicit resolution(const config& cfg);
122  };
123 };
124 
125 // }---------- BUILDER -----------{
126 
127 namespace implementation
128 {
129 
131 {
132  explicit builder_image(const config& cfg);
133 
135 
136  virtual widget* build() const override;
137 };
138 
139 } // namespace implementation
140 
141 // }------------ END --------------
142 
143 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
virtual widget * build() const =0
virtual bool can_mouse_focus() const override
Whether the mouse move/click event go &#39;through&#39; this widget.
Definition: image.hpp:71
Base class for all widgets.
Definition: widget.hpp:49
t_string get_image() const
Wrapper for label.
Definition: image.hpp:66
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:57
Generic file dialog.
Definition: field-fwd.hpp:23
state_t
Possible states of the widget.
Definition: image.hpp:100
Holds a 2D point.
Definition: point.hpp:24
Base class for all visible items.
void set_image(const t_string &label)
Wrapper for set_label.
Definition: image.hpp:53
Functions to load and save images from/to disk.
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.
std::string tooltip
Shown when hovering over an entry in the filter&#39;s drop-down list.
Definition: manager.cpp:219