vsg: include/vsg/platform/android/Android_Window.h Source File

vsg 1.1.3 VulkanSceneGraph library

Loading...
Searching...
No Matches
Android_Window.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
13</editor-fold> */
14
15#define VK_USE_PLATFORM_ANDROID_KHR
16
17#include <vsg/app/Window.h>
18#include <vsg/ui/KeyEvent.h>
19
20#include <android/input.h>
21#include <android/native_window.h>
22
23namespace vsgAndroid
24{
25
27 class KeyboardMap : public vsg::Object
28 {
29 public:
30 KeyboardMap();
31
32 using AKeyCodeToKeySymbolMap = std::map<uint32_t, vsg::KeySymbol>;
33
34 bool getKeySymbol(uint32_t keycode, uint32_t metastate, vsg::KeySymbol& keySymbol, vsg::KeySymbol& modifiedKeySymbol, vsg::KeyModifier& keyModifier)
35 {
36 auto itr = _keycodeMap.find(keycode);
37 if (itr == _keycodeMap.end()) return false;
38
39 keySymbol = itr->second;
40 modifiedKeySymbol = keySymbol;
41
42 uint16_t modifierMask = 0;
43
44 if (metastate & AMETA_ALT_ON) modifierMask |= vsg::KeyModifier::MODKEY_Alt;
45 if (metastate & AMETA_CTRL_ON) modifierMask |= vsg::KeyModifier::MODKEY_Control;
46 if (metastate & AMETA_SHIFT_ON) modifierMask |= vsg::KeyModifier::MODKEY_Shift;
47 if (metastate & AMETA_CAPS_LOCK_ON) modifierMask |= vsg::KeyModifier::MODKEY_CapsLock;
48 if (metastate & AMETA_NUM_LOCK_ON) modifierMask |= vsg::KeyModifier::MODKEY_NumLock;
49
50 keyModifier = (vsg::KeyModifier)modifierMask;
51
52 // need to get the modified key somehow but seems we may need to talk to java for that :(
53
54 return true;
55 }
56
57 protected:
58 AKeyCodeToKeySymbolMap _keycodeMap;
59 };
60
77 class Android_Window : public vsg::Inherit<vsg::Window, Android_Window>
78 {
79 public:
80 Android_Window(vsg::ref_ptr<vsg::WindowTraits> traits);
81 Android_Window() = delete;
82 Android_Window(const Android_Window&) = delete;
83 Android_Window operator=(const Android_Window&) = delete;
84
85 const char* instanceExtensionSurfaceName() const override { return "VK_KHR_android_surface"; }
86
87 bool valid() const override { return _window; }
88
89 bool pollEvents(vsg::UIEvents& events) override;
90
91 void resize() override;
92
93 bool handleAndroidInputEvent(AInputEvent* anEvent);
94
95 protected:
96 virtual ~Android_Window();
97
98 void _initSurface() override;
99
100 ANativeWindow* _window;
101
102 int64_t _first_android_timestamp = 0;
103 vsg::clock::time_point _first_android_time_point;
104
105 vsg::ref_ptr<KeyboardMap> _keyboard;
106 };
107
108} // namespace vsgAndroid
109
110EVSG_type_name(vsgAndroid::Android_Window);
vsg::Inherit
Definition Inherit.h:28
vsg::Object
Definition Object.h:60
vsgAndroid::Android_Window
Definition Android_Window.h:78
vsgAndroid::Android_Window::pollEvents
bool pollEvents(vsg::UIEvents &events) override
get the list of events since the last pollEvents() call by splicing bufferEvents with polled windowin...
vsgAndroid::KeyboardMap
KeyboardMap maps Android keyboard events to vsg::KeySymbol.
Definition Android_Window.h:28
vsg::allocator_affinity_nodes
std container adapter for allocating with MEMORY_AFFINITY_NODES
Definition Allocator.h:138