The Battle for Wesnoth  1.15.2+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 /** An image. */
32 class image : public styled_widget
33 {
34 public:
35  explicit image(const implementation::builder_image& builder);
36 
37  /**
38  * Wrapper for set_label.
39  *
40  * Some people considered this function missing and confusing so added
41  * this forward version.
42  *
43  * @param label The filename image to show.
44  */
45  void set_image(const t_string& label)
46  {
47  set_label(label);
48  }
49 
50  /**
51  * Wrapper for label.
52  *
53  * Some people considered this function missing and confusing so added
54  * this forward version.
55  *
56  * @returns The filename of the image shown.
57  */
59  {
60  return get_label();
61  }
62 
63  virtual bool can_mouse_focus() const override { return !tooltip().empty(); }
64 
65  /***** ***** ***** ***** layout functions ***** ***** ***** *****/
66 
67 private:
68  /** See @ref widget::calculate_best_size. */
69  virtual point calculate_best_size() const override;
70 
71 public:
72  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
73 
74  /** See @ref styled_widget::set_active. */
75  virtual void set_active(const bool active) override;
76 
77  /** See @ref styled_widget::get_active. */
78  virtual bool get_active() const override;
79 
80  /** See @ref styled_widget::get_state. */
81  virtual unsigned get_state() const override;
82 
83  /** See @ref widget::disable_click_dismiss. */
84  bool disable_click_dismiss() const override;
85 
86 private:
87  /**
88  * Possible states of the widget.
89  *
90  * Note the order of the states must be the same as defined in settings.hpp.
91  */
92  enum state_t {
94  };
95 
96 public:
97  /** Static type getter that does not rely on the widget being constructed. */
98  static const std::string& type();
99 
100 private:
101  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
102  virtual const std::string& get_control_type() const override;
103 };
104 
105 // }---------- DEFINITION ---------{
106 
108 {
109  explicit image_definition(const config& cfg);
110 
112  {
113  explicit resolution(const config& cfg);
114  };
115 };
116 
117 // }---------- BUILDER -----------{
118 
119 namespace implementation
120 {
121 
123 {
124  explicit builder_image(const config& cfg);
125 
127 
128  widget* build() const;
129 };
130 
131 } // namespace implementation
132 
133 // }------------ END --------------
134 
135 } // 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:63
Base class for all widgets.
Definition: widget.hpp:47
t_string get_image() const
Wrapper for label.
Definition: image.hpp:58
Label showing a text.
Definition: label.hpp:32
Generic file dialog.
Definition: field-fwd.hpp:22
state_t
Possible states of the widget.
Definition: image.hpp:92
window * build(const builder_window::window_resolution *definition)
Builds a window.
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:45
this module manages the cache of images.
Class to show the tips.
Definition: tooltip.cpp:71
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.