FifeGUI 0.3.0
A C++ GUI library designed for games.
togglebutton.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_TOGGLEBUTTON_HPP_
6#define INCLUDE_FIFECHAN_WIDGETS_TOGGLEBUTTON_HPP_
7
8// Standard library includes
9#include <map>
10#include <string>
11
12// Platform config include
13#include "fifechan/platform.hpp"
14
15// Project headers (subdirs before local)
16#include "fifechan/widgets/imagebutton.hpp"
17
18namespace fcn
19{
30 class FIFEGUI_API ToggleButton : public fcn::ImageButton
31 {
32 public:
33 ToggleButton();
34
44 ToggleButton(std::string const & caption, std::string const & group, bool selected = false);
45
46 ~ToggleButton() override;
47
48 ToggleButton(ToggleButton const &) = delete;
49 ToggleButton& operator=(ToggleButton const &) = delete;
50 ToggleButton(ToggleButton&&) = delete;
51 ToggleButton& operator=(ToggleButton&&) = delete;
52
59 virtual bool isSelected() const;
60
67 virtual void setSelected(bool selected);
68
73 virtual void toggleSelected();
74
83 void setGroup(std::string const & group);
84
91 std::string const & getGroup() const;
92
93 // Inherited from KeyListener
94
95 void keyReleased(KeyEvent& keyEvent) override;
96
97 // Inherited from MouseListener
98
99 void mouseReleased(MouseEvent& mouseEvent) override;
100
101 protected:
102 // Inherited from Button
103
104 bool isPressed() const override;
105
109 bool mSelected{false};
110
114 std::string mGroup;
115
119 using GroupMap = std::multimap<std::string, ToggleButton*>;
120
124 using GroupIterator = GroupMap::iterator;
125
130 };
131} // namespace fcn
132
133#endif // INCLUDE_FIFECHAN_WIDGETS_TOGGLEBUTTON_HPP_
An implementation of a regular clickable button.
Represents a key event.
Definition keyevent.hpp:26
Represents a mouse event.
virtual bool isSelected() const
Checks if the check box is selected.
void mouseReleased(MouseEvent &mouseEvent) override
Called when a mouse button has been released on the widget area.
bool isPressed() const override
Checks if the button is pressed.
bool mSelected
True if the check box is selected, false otherwise.
std::multimap< std::string, ToggleButton * > GroupMap
Typdef.
virtual void toggleSelected()
Toggles the check box between being selected and not being selected.
virtual void setSelected(bool selected)
Sets the check box to be selected or not.
GroupMap::iterator GroupIterator
Typdef.
void keyReleased(KeyEvent &keyEvent) override
Called if a key is released when the widget has keyboard focus.
void setGroup(std::string const &group)
Sets the group the toggle button should belong to.
std::string mGroup
Holds the group of the toggle button.
static GroupMap mGroupMap
Holds all available toggle button groups.
std::string const & getGroup() const
Gets the group the toggle button belongs to.
Used replacement tokens by configure_file():