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