1 /* Focusable.hpp
2  * Copyright (C) 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_FOCUSABLE_HPP_
19 #define BWIDGETS_FOCUSABLE_HPP_
20 
21 #define BWIDGETS_DEFAULT_FOCUS_IN_MS 200
22 #define BWIDGETS_DEFAULT_FOCUS_OUT_MS 5000
23 #define BWIDGETS_DEFAULT_FOCUS_NAME "/focus"
24 
25 #include <chrono>
26 
27 namespace BWidgets
28 {
29 
30 class Focusable
31 {
32 protected:
33         std::chrono::milliseconds focusInMs;
34 	std::chrono::milliseconds focusOutMs;
35 
36 public:
Focusable(const std::chrono::milliseconds focusInMs,const std::chrono::milliseconds focusOutMs)37         Focusable (const std::chrono::milliseconds focusInMs, const std::chrono::milliseconds focusOutMs) :
38                 focusInMs (focusInMs), focusOutMs (focusOutMs) {}
39 
setFocusInMilliseconds(const std::chrono::milliseconds ms)40         void setFocusInMilliseconds (const std::chrono::milliseconds ms) {focusInMs = ms;}
41 
getFocusInMilliseconds() const42 	std::chrono::milliseconds getFocusInMilliseconds () const {return focusInMs;}
43 
setFocusOutMilliseconds(const std::chrono::milliseconds ms)44 	void setFocusOutMilliseconds (const std::chrono::milliseconds ms) {focusOutMs = ms;}
45 
getFocusOutMilliseconds() const46 	std::chrono::milliseconds getFocusOutMilliseconds () const {return focusOutMs;}
47 
isFocusActive(const std::chrono::milliseconds diffMs) const48         bool isFocusActive (const std::chrono::milliseconds diffMs) const {return ((diffMs >= focusInMs) && (diffMs < focusOutMs));}
49 };
50 
51 }
52 
53 #endif /*BWIDGETS_FOCUSABLE_HPP_*/
54