FifeGUI 0.2.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#include <memory>
9#include <string>
10#include <vector>
11
12#include "fifechan/platform.hpp"
13#include "fifechan/widgets/button.hpp"
14
15namespace fcn
16{
17 class Image;
18
32 class FIFEGUI_API ImageButton : public fcn::Button
33 {
34 public:
41 enum class ImageType : uint8_t
42 {
43 Up = 0,
44 Down = 1,
45 Hover = 2,
46 Up_Inactive = 3,
47 Down_Inactive = 4,
48 Hover_Inactive = 5
49 };
50
52
58 explicit ImageButton(std::string const & filename);
59
66 explicit ImageButton(Image const * image);
67
68 ImageButton(ImageButton const &) = delete;
69 ImageButton& operator=(ImageButton const &) = delete;
70 ImageButton(ImageButton&&) = delete;
71 ImageButton& operator=(ImageButton&&) = delete;
72
73 ~ImageButton() override;
74
83 void setUpImage(std::string const & filename);
84
93 void setUpImage(Image const * image);
94
100 Image const * getUpImage() const;
101
110 void setDownImage(std::string const & filename);
111
120 void setDownImage(Image const * image);
121
127 Image const * getDownImage() const;
128
137 void setHoverImage(std::string const & filename);
138
147 void setHoverImage(Image const * image);
148
154 Image const * getHoverImage() const;
155
164 void setInactiveUpImage(std::string const & filename);
165
174 void setInactiveUpImage(Image const * image);
175
181 Image const * getInactiveUpImage() const;
182
189 void setInactiveDownImage(std::string const & filename);
190
197 void setInactiveDownImage(Image const * image);
198
204 Image const * getInactiveDownImage() const;
205
212 void setInactiveHoverImage(std::string const & filename);
213
220 void setInactiveHoverImage(Image const * image);
221
227 Image const * getInactiveHoverImage() const;
228
229 // Inherited from Widget
230
236 void resizeToContent(bool recursion) override;
237
241 void adjustSize() override;
242
248 void draw(fcn::Graphics* graphics) override;
249
250 protected:
260 void adjustSizeImpl() override;
261
267 void setImage(std::string const & filename, ImageType type);
268
275 void setImage(Image const * image, ImageType type);
276
280 std::vector<Image const *> mImages;
281
285 std::vector<std::unique_ptr<Image const>> mOwnedImages;
286 };
287} // namespace fcn
288
289#endif // INCLUDE_FIFECHAN_WIDGETS_IMAGEBUTTON_HPP_
A standard clickable button widget.
Definition button.hpp:38
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:57
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:32