Blue Brain BioExplorer
KeyboardHandler.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  *
4  * The Blue Brain BioExplorer is a tool for scientists to extract and analyse
5  * scientific data from visualization
6  *
7  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License version 3.0 as published
11  * by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #pragma once
24 
26 
27 #include <functional>
28 
29 namespace core
30 {
32 {
33  std::string description;
34  std::function<void()> functor;
35 };
36 
37 enum class SpecialKey
38 {
39  LEFT,
40  RIGHT,
41  UP,
42  DOWN
43 };
44 
49 {
50 public:
57  void registerKeyboardShortcut(const unsigned char key, const std::string& description,
58  std::function<void()> functor);
59 
64  void unregisterKeyboardShortcut(const unsigned char key);
65 
70  void handleKeyboardShortcut(const unsigned char key);
71 
78  void registerSpecialKey(const SpecialKey key, const std::string& description, std::function<void()> functor);
79 
84  void unregisterSpecialKey(const SpecialKey key);
85 
90  void handle(const SpecialKey key);
91 
96  const std::vector<std::string>& help() const;
97 
103  const std::string getKeyboardShortcutDescription(const unsigned char key);
104 
105 private:
109  void _buildHelp();
110 
111  std::map<unsigned char, ShortcutInformation> _registeredShortcuts;
112  std::map<SpecialKey, ShortcutInformation> _registeredSpecialKeys;
113  std::vector<std::string> _helpStrings;
114 };
115 } // namespace core
The KeyboardHandler class manages keyboard shortcuts and special keys.
void handle(const SpecialKey key)
Handles a special key.
void registerSpecialKey(const SpecialKey key, const std::string &description, std::function< void()> functor)
Registers a special key.
void handleKeyboardShortcut(const unsigned char key)
Handles a keyboard shortcut.
const std::string getKeyboardShortcutDescription(const unsigned char key)
Returns the description of a specific keyboard shortcut.
void registerKeyboardShortcut(const unsigned char key, const std::string &description, std::function< void()> functor)
Registers a keyboard shortcut.
void unregisterKeyboardShortcut(const unsigned char key)
Unregisters a keyboard shortcut.
const std::vector< std::string > & help() const
Returns a vector of help string descriptions for all registered keyboard shortcuts and special keys.
void unregisterSpecialKey(const SpecialKey key)
Unregisters a special key.
std::function< void()> functor