FifeGUI 0.3.0
A C++ GUI library designed for games.
icon.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_ICON_HPP_
6#define INCLUDE_FIFECHAN_WIDGETS_ICON_HPP_
7
8// Standard library includes
9#include <string>
10
11// Platform config include
12#include "fifechan/platform.hpp"
13
14// Project headers (subdirs before local)
15#include "fifechan/image.hpp"
16#include "fifechan/widget.hpp"
17
18namespace fcn
19{
25 class FIFEGUI_API Icon : public Widget
26 {
27 public:
28 Icon();
29
35 explicit Icon(std::string const & filename);
36
42 explicit Icon(Image const * image);
43
44 ~Icon() override;
45
46 Icon(Icon const &) = delete;
47 Icon& operator=(Icon const &) = delete;
48 Icon(Icon&&) = delete;
49 Icon& operator=(Icon&&) = delete;
50
57 void setImage(std::string const & filename);
58
65 void setImage(Image const * image);
66
72 Image const * getImage() const;
73
79 void setScaling(bool scale);
80
86 bool isScaling() const;
87
93 void setTiling(bool tile);
94
100 bool isTiling() const;
101
107 void setOpaque(bool opaque);
108
112 bool isOpaque() const;
113
114 // Inherited from Widget
115
117
118 void resizeToContent(bool recursion = true) override;
119 void adjustSize() override;
120 void draw(Graphics* graphics) override;
121
122 protected:
126 Image const * mImage{nullptr};
127
133 bool mInternalImage{false};
134
136 bool mScale{false};
137
139 bool mTile{false};
140
142 bool mOpaque{true};
143
153 void adjustSizeImpl();
154 };
155} // namespace fcn
156
157#endif // INCLUDE_FIFECHAN_WIDGETS_ICON_HPP_
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
bool mOpaque
True if opaque, otherwise false.
Definition icon.hpp:142
void setTiling(bool tile)
Sets if the image should be tiled to widget size.
Definition icon.cpp:82
void adjustSize() override
Resizes the widget's size to fit the content exactly.
Definition icon.cpp:103
bool mTile
True if tiling is enabled, otherwise false.
Definition icon.hpp:139
bool mInternalImage
True if the image has been loaded internally, false otherwise.
Definition icon.hpp:133
bool isTiling() const
Gets if the image is tiled to widget size.
Definition icon.cpp:77
bool isScaling() const
Gets if the image is scaled to widget size.
Definition icon.cpp:67
void resizeToContent(bool recursion=true) override
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition icon.cpp:97
bool isOpaque() const
Definition icon.cpp:92
Image const * getImage() const
Gets the current image.
Definition icon.cpp:62
bool mScale
True if scaling is enabled, otherwise false.
Definition icon.hpp:136
Image const * mImage
The image to display.
Definition icon.hpp:126
void draw(Graphics *graphics) override
Draws the widget.
Definition icon.cpp:123
void setOpaque(bool opaque)
Sets the opacity of the background.
Definition icon.cpp:87
void setScaling(bool scale)
Sets if the image should be scaled to widget size.
Definition icon.cpp:72
void setImage(std::string const &filename)
Sets the image to display.
Definition icon.cpp:40
Abstract holder for image data.
Definition image.hpp:34
Widget()
Constructor.
Definition widget.cpp:52
virtual void resizeToContent(bool recursion=true)
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition widget.hpp:1580
Used replacement tokens by configure_file():