FifeGUI 0.3.0
A C++ GUI library designed for games.
imagebutton.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_WIDGETS_IMAGEBUTTON_HPP_
6#define INCLUDE_FIFECHAN_WIDGETS_IMAGEBUTTON_HPP_
7
8// Standard library includes
9#include <memory>
10#include <string>
11#include <vector>
12
13// Platform config include
14#include "fifechan/platform.hpp"
15
16// Project headers (subdirs before local)
17#include "fifechan/widgets/button.hpp"
18
19namespace fcn
20{
21 class Image;
22
36 class FIFEGUI_API ImageButton : public fcn::Button
37 {
38 public:
45 enum class ImageType : uint8_t
46 {
47 Up = 0,
48 Down = 1,
49 Hover = 2,
50 Up_Inactive = 3,
51 Down_Inactive = 4,
52 Hover_Inactive = 5
53 };
54
56
62 explicit ImageButton(std::string const & filename);
63
70 explicit ImageButton(Image const * image);
71
72 ImageButton(ImageButton const &) = delete;
73 ImageButton& operator=(ImageButton const &) = delete;
74 ImageButton(ImageButton&&) = delete;
75 ImageButton& operator=(ImageButton&&) = delete;
76
77 ~ImageButton() override;
78
87 void setUpImage(std::string const & filename);
88
97 void setUpImage(Image const * image);
98
104 Image const * getUpImage() const;
105
114 void setDownImage(std::string const & filename);
115
124 void setDownImage(Image const * image);
125
131 Image const * getDownImage() const;
132
141 void setHoverImage(std::string const & filename);
142
151 void setHoverImage(Image const * image);
152
158 Image const * getHoverImage() const;
159
168 void setInactiveUpImage(std::string const & filename);
169
178 void setInactiveUpImage(Image const * image);
179
185 Image const * getInactiveUpImage() const;
186
193 void setInactiveDownImage(std::string const & filename);
194
201 void setInactiveDownImage(Image const * image);
202
208 Image const * getInactiveDownImage() const;
209
216 void setInactiveHoverImage(std::string const & filename);
217
224 void setInactiveHoverImage(Image const * image);
225
231 Image const * getInactiveHoverImage() const;
232
233 // Inherited from Widget
234
240 void resizeToContent(bool recursion = true) override;
241
245 void adjustSize() override;
246
252 void draw(fcn::Graphics* graphics) override;
253
254 protected:
264 void adjustSizeImpl() override; // cppcheck-suppress virtualCallInConstructor
265
271 void setImage(std::string const & filename, ImageType type);
272
279 void setImage(Image const * image, ImageType type);
280
284 std::vector<Image const *> mImages;
285
289 std::vector<std::unique_ptr<Image const>> mOwnedImages;
290 };
291} // namespace fcn
292
293#endif // INCLUDE_FIFECHAN_WIDGETS_IMAGEBUTTON_HPP_
A standard clickable button widget.
Definition button.hpp:42
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
An implementation of a regular clickable button.
std::vector< Image const * > mImages
The images to display.
std::vector< std::unique_ptr< Image const > > mOwnedImages
Owned images loaded by filename.
ImageType
Types of images used by ImageButton.
Abstract holder for image data.
Definition image.hpp:34
Used replacement tokens by configure_file():