supertux
control.hpp
1 // SuperTux
2 // Copyright (C) 2020 A. Semphris <semphris@protonmail.com>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_INTERFACE_CONTROL_HPP
18 #define HEADER_SUPERTUX_INTERFACE_CONTROL_HPP
19 
20 #include <functional>
21 #include <SDL.h>
22 
23 #include "control/input_manager.hpp"
24 #include "editor/widget.hpp"
25 #include "interface/label.hpp"
26 #include "video/drawing_context.hpp"
27 
28 class InterfaceControl : public Widget
29 {
30 public:
32  ~InterfaceControl() override {}
33 
34  virtual void draw(DrawingContext& context) override { if (m_label) m_label->draw(context); }
35  virtual bool on_mouse_motion(const SDL_MouseMotionEvent& motion) override { if (m_label) m_label->on_mouse_motion(motion); return false; }
36 
37  void set_focus(bool focus) { m_has_focus = focus; }
38  bool has_focus() const { return m_has_focus; }
39 
40  void set_rect(const Rectf& rect) { m_rect = rect; }
41  Rectf get_rect() const { return m_rect; }
42 
43 public:
47  std::function<void()> m_on_change;
48 
50  std::unique_ptr<InterfaceLabel> m_label;
51 
52 protected:
59 
60 private:
61  InterfaceControl(const InterfaceControl&) = delete;
62  InterfaceControl& operator=(const InterfaceControl&) = delete;
63 };
64 
65 #endif
66 
67 /* EOF */
std::function< void()> m_on_change
Optional; a function that will be called each time the bound value is modified.
Definition: control.hpp:47
Rectf m_rect
The rectangle where the InterfaceControl should be rendered.
Definition: control.hpp:56
Definition: control.hpp:28
std::unique_ptr< InterfaceLabel > m_label
Optional; the label associated with the control.
Definition: control.hpp:50
InterfaceControl * m_parent
A pointer to the parent container, or null if not in any container.
Definition: control.hpp:58
Definition: rectf.hpp:31
bool m_has_focus
Whether or not the user has this InterfaceControl as focused.
Definition: control.hpp:54
Definition: widget.hpp:24
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42