vsg 1.1.13
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::unordered_map<uint32_t, vsg::KeySymbol>;
33
35 static void initializeKeyCharacterMap(void* vm);
36
39
40 static int32_t getUnicodeChar(int32_t keyCode, int32_t metaState);
41
42 bool getKeySymbol(int32_t keyCode, int32_t metaState, vsg::KeySymbol& keySymbol, vsg::KeySymbol& modifiedKeySymbol, vsg::KeyModifier& keyModifier) const
43 {
44 auto itr = _keycodeMap.find(keyCode);
45 if (itr == _keycodeMap.end()) return false;
46
47 keySymbol = itr->second;
48
49 uint16_t modifierMask = 0;
50
51 if (metaState & AMETA_ALT_ON) modifierMask |= vsg::KeyModifier::MODKEY_Alt;
52 if (metaState & AMETA_CTRL_ON) modifierMask |= vsg::KeyModifier::MODKEY_Control;
53 if (metaState & AMETA_SHIFT_ON) modifierMask |= vsg::KeyModifier::MODKEY_Shift;
54 if (metaState & AMETA_CAPS_LOCK_ON) modifierMask |= vsg::KeyModifier::MODKEY_CapsLock;
55 if (metaState & AMETA_NUM_LOCK_ON) modifierMask |= vsg::KeyModifier::MODKEY_NumLock;
56
57 keyModifier = (vsg::KeyModifier)modifierMask;
58 modifiedKeySymbol = static_cast<vsg::KeySymbol>(getUnicodeChar(keyCode, metaState));
59
60 return true;
61 }
62
63 protected:
64 AKeyCodeToKeySymbolMap _keycodeMap;
65 };
66
83 class Android_Window : public vsg::Inherit<vsg::Window, Android_Window>
84 {
85 public:
86 Android_Window(vsg::ref_ptr<vsg::WindowTraits> traits);
87 Android_Window() = delete;
88 Android_Window(const Android_Window&) = delete;
89 Android_Window operator=(const Android_Window&) = delete;
90
91 const char* instanceExtensionSurfaceName() const override { return "VK_KHR_android_surface"; }
92
93 bool valid() const override { return _window; }
94
95 bool pollEvents(vsg::UIEvents& events) override;
96
97 void resize() override;
98
99 bool handleAndroidInputEvent(AInputEvent* anEvent);
100
101 protected:
102 virtual ~Android_Window();
103
104 void _initSurface() override;
105
106 ANativeWindow* _window;
107
108 int64_t _uptimeMs = 0;
109 vsg::clock::time_point _first_android_time_point;
110
112 };
113
114} // namespace vsgAndroid
115
116EVSG_type_name(vsgAndroid::Android_Window);
Definition Inherit.h:28
Definition Object.h:60
Definition ref_ptr.h:22
Definition Android_Window.h:84
bool pollEvents(vsg::UIEvents &events) override
get the list of events since the last pollEvents() call by splicing bufferEvents with polled windowin...
static void releaseKeyCharacterMap()
This method should be called after the APP_CMD_DESTROY message.
static void initializeKeyCharacterMap(void *vm)
This method should be called after the APP_CMD_INIT_WINDOW message.