1 /* HSlider.hpp
2  * Copyright (C) 2018, 2019  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_HSLIDER_HPP_
19 #define BWIDGETS_HSLIDER_HPP_
20 
21 #include "Knob.hpp"
22 #include "HScale.hpp"
23 #include "Label.hpp"
24 #include "Focusable.hpp"
25 
26 #define BWIDGETS_DEFAULT_HSLIDER_WIDTH BWIDGETS_DEFAULT_HSCALE_WIDTH
27 #define BWIDGETS_DEFAULT_HSLIDER_HEIGHT (BWIDGETS_DEFAULT_HSCALE_HEIGHT * 2)
28 #define BWIDGETS_DEFAULT_HSLIDER_DEPTH 1.0
29 
30 namespace BWidgets
31 {
32 /**
33  * Class BWidgets::HSlider
34  *
35  * RangeWidget class for a horizontal slider.
36  * The Widget is clickable by default.
37  */
38 class HSlider : public HScale, public Focusable
39 {
40 public:
41 	HSlider ();
42 	HSlider (const double x, const double y, const double width, const double height, const std::string& name,
43 			 const double value, const double min, const double max, const double step);
44 
45 	/**
46 	 * Creates a new (orphan) slider and copies the slider properties from a
47 	 * source slider.
48 	 * @param that Source slider
49 	 */
50 	HSlider (const HSlider& that);
51 
52 	/**
53 	 * Pattern cloning. Creates a new instance of the widget and copies all
54 	 * its properties.
55 	 */
56 	virtual Widget* clone () const override;
57 
58 	/**
59 	 * Changes the value of the widget and keeps it within the defined range.
60 	 * Passes the value to its predefined child widgets.
61 	 * Emits a value changed event and (if visible) an expose event.
62 	 * @param val Value
63 	 */
64 	virtual void setValue (const double val) override;
65 
66 	/**
67 	 * Assignment. Copies the slider properties from a source slider and keeps
68 	 * its name and its position within the widget tree. Emits an expose event
69 	 * if the widget is visible and a value changed event.
70 	 * @param that Source slider
71 	 */
72 	HSlider& operator= (const HSlider& that);
73 
74 	/**
75 	 * Calls a redraw of the widget and calls postRedisplay () if the the
76 	 * Widget is visible.
77 	 * This method should be called if the widgets properties are indirectly
78 	 * changed.
79 	 */
80 	virtual void update () override;
81 
82 	/**
83 	 * Scans theme for widget properties and applies these properties.
84 	 * @param theme Theme to be scanned.
85 	 * 				tyles used are:
86 	 * 				BWIDGETS_KEYWORD_BORDER
87 	 * 				BWIDGETS_KEYWORD_BACKGROUND
88 	 * 				BWIDGETS_KEYWORD_FGCOLORS
89 	 * 				BWIDGETS_KEYWORD_BGCOLORS
90 	 * @param name Name of the BStyles::StyleSet within the theme to be
91 	 * 		  	   applied.
92 	 */
93 	virtual void applyTheme (BStyles::Theme& theme) override;
94 	virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override;
95 
96 	/**
97 	 * Predefined empty method to handle a
98 	 * BEvents::EventType::FOCUS_IN_EVENT.
99 	 * @param event Focus event
100 	 */
101 	virtual void onFocusIn (BEvents::FocusEvent* event) override;
102 
103 	/**
104 	 * Predefined empty method to handle a
105 	 * BEvents::EventType::FOCUS_OUT_EVENT.
106 	 * @param event Focus event
107 	 */
108 	virtual void onFocusOut (BEvents::FocusEvent* event) override;
109 
110 protected:
111 	virtual void updateCoords () override;
112 
113 	Knob knob;
114 	Label focusLabel;
115 	double knobRadius;
116 	BUtilities::Point knobPosition;
117 };
118 
119 }
120 
121 #endif /* BWIDGETS_HSLIDER_HPP_ */
122