1 /* HSwitch.hpp
2  * Copyright (C) 2018  Sven Jähnichen
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 <https://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef BWIDGETS_HSWITCH_HPP_
19 #define BWIDGETS_HSWITCH_HPP_
20 
21 #include "Knob.hpp"
22 #include "HSlider.hpp"
23 
24 #define BWIDGETS_DEFAULT_HSWITCH_WIDTH 40.0
25 #define BWIDGETS_DEFAULT_HSWITCH_HEIGHT 20.0
26 #define BWIDGETS_DEFAULT_HSWITCH_DEPTH 1.0
27 
28 namespace BWidgets
29 {
30 /**
31  * Class BWidgets::HSwitch
32  *
33  * On/OFF switch widget. Is is a BWidgets::HSlider having two conditions: on
34  * (value != 0) or off (value == 0)
35  */
36 class HSwitch : public HSlider
37 {
38 public:
39 	HSwitch ();
40 	HSwitch (const double x, const double y, const double width, const double height, const std::string& name, const double defaultvalue);
41 
42 	/**
43 	 * Pattern cloning. Creates a new instance of the widget and copies all
44 	 * its properties.
45 	 */
46 	virtual Widget* clone () const override;
47 
48 	/**
49 	 * Handles the BEvents::BUTTON_PRESS_EVENT to move the slider.
50 	 * @param event Pointer to a pointer event emitted by the same widget.
51 	 */
52 	virtual void onButtonPressed (BEvents::PointerEvent* event) override;
53 
54 	/**
55 	 * Handles the BEvents::EventType::BUTTON_RELEASE_EVENT to move the slider.
56 	 * @param event Pointer event
57 	 */
58 	virtual void onButtonReleased (BEvents::PointerEvent* event) override;
59 
60 	/**
61 	 * Handles the BEvents::POINTER_DRAG_EVENT to move
62 	 * the slider.
63 	 * @param event Pointer to a pointer event emitted by the same widget.
64 	 */
65 	virtual void onPointerDragged (BEvents::PointerEvent* event) override;
66 
67 protected:
68 	virtual void updateCoords () override;
69 
70 	bool dragged;
71 };
72 
73 }
74 
75 #endif /* BWIDGETS_HSWITCH_HPP_ */
76