FifeGUI 0.2.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#include <map>
9#include <string>
10
11#include "fifechan/platform.hpp"
12#include "fifechan/widgets/imagebutton.hpp"
13
14namespace fcn
15{
26 class FIFEGUI_API ToggleButton : public fcn::ImageButton
27 {
28 public:
29 ToggleButton();
30
39 ToggleButton(std::string const & caption, std::string const & group, bool selected = false);
40
41 ~ToggleButton() override;
42
43 ToggleButton(ToggleButton const &) = delete;
44 ToggleButton& operator=(ToggleButton const &) = delete;
45 ToggleButton(ToggleButton&&) = delete;
46 ToggleButton& operator=(ToggleButton&&) = delete;
47
54 virtual bool isSelected() const;
55
62 virtual void setSelected(bool selected);
63
68 virtual void toggleSelected();
69
78 void setGroup(std::string const & group);
79
86 std::string const & getGroup() const;
87
88 // Inherited from KeyListener
89
90 void keyReleased(KeyEvent& keyEvent) override;
91
92 // Inherited from MouseListener
93
94 void mouseReleased(MouseEvent& mouseEvent) override;
95
96 protected:
97 // Inherited from Button
98
99 bool isPressed() const override;
100
104 bool mSelected{false};
105
109 std::string mGroup;
110
114 using GroupMap = std::multimap<std::string, ToggleButton*>;
115
119 using GroupIterator = GroupMap::iterator;
120
125 };
126} // namespace fcn
127
128#endif // INCLUDE_FIFECHAN_WIDGETS_TOGGLEBUTTON_HPP_
An implementation of a regular clickable button.
Represents a key event.
Definition keyevent.hpp:22
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.