vsg 1.1.3
VulkanSceneGraph library
Loading...
Searching...
No Matches
iOS_Window.h
1//
2// vsg_iOS_ApplicationDelegate.h
3// IOS_vsg_native_example
4//
5// Created by jaume dominguez faus on 23/5/21.
6//
7
8#ifndef vsg_iOS_Window_h
9#define vsg_iOS_Window_h
10
11
12
13#include <vsg/app/Window.h>
14#include <vsg/ui/KeyEvent.h>
15#include <vulkan/vulkan_metal.h>
16#include <UIKit/UiKit.h>
17
18@interface vsg_iOS_Window : UIWindow
19- (vsg::ref_ptr<vsg::Window>) vsgWindow;
20- (instancetype)initWithTraits:(vsg::ref_ptr<vsg::WindowTraits>)traits andVsgViewer:(vsg::ref_ptr<vsg::Viewer>) vsgViewer;
21@end
22
23
24@class vsg_iOS_View;
25
26namespace vsgiOS
27{
28 extern vsg::Names getInstanceExtensions();
29
31 class KeyboardMap : public vsg::Object
32 {
33 public:
35
36 using kVKKeyCodeToKeySymbolMap = std::map<unsigned short, vsg::KeySymbol>;
37
38 bool getKeySymbol(UIEvent* anEvent, vsg::KeySymbol& keySymbol, vsg::KeySymbol& modifiedKeySymbol, vsg::KeyModifier& keyModifier);
39
40 protected:
41 kVKKeyCodeToKeySymbolMap _keycodeMap;
42 };
43
44
46 class iOS_Window : public vsg::Inherit<vsg::Window, iOS_Window>
47 {
48 public:
49
51 iOS_Window() = delete;
52 iOS_Window(const iOS_Window&) = delete;
53 iOS_Window operator = (const iOS_Window&) = delete;
54
55 const char* instanceExtensionSurfaceName() const override { return VK_EXT_METAL_SURFACE_EXTENSION_NAME; }
56
57 bool valid() const override { return _window; }
58
59 bool pollEvents(vsg::UIEvents& events) override;
60
61 // bool resized() const override;
62
63 void resize() override;
64
65 bool handleUIEvent(UIEvent* anEvent);
66
67 // OS native objects
68 vsg_iOS_Window* window() { return _window; };
69 // vsg_iOS_View* view() { return _view; };
70 CAMetalLayer* layer() { return _metalLayer; };
71
72 vsg::clock::time_point getEventTime(double eventTime)
73 {
74 long elapsedmilli = long(double(eventTime - _first_macos_timestamp) * 1000.0f);
75 return _first_macos_time_point + std::chrono::milliseconds(elapsedmilli);
76 }
77
78 void queueEvent(vsg::UIEvent* anEvent) { _bufferedEvents.emplace_back(anEvent); }
79
80 protected:
81 virtual ~iOS_Window();
82
83 void _initSurface() override;
84
85 vsg_iOS_Window* _window;
86 vsg_iOS_View* _view;
87 CAMetalLayer* _metalLayer;
88
89 double _first_macos_timestamp = 0;
90 vsg::clock::time_point _first_macos_time_point;
91
92 vsg::UIEvents _bufferedEvents;
94 };
95
96} // namespace vsgMacOS
97
98EVSG_type_name(vsgiOS::iOS_Window);
99
100#endif /* vsg_iOS_Window_h */
Definition Inherit.h:28
Definition Object.h:60
UIEvent is a base class for user interface events.
Definition UIEvent.h:28
Definition ref_ptr.h:22
KeyboardMap maps iOS keyboard events to vsg::KeySymbol.
Definition iOS_Window.h:32
iOS_Window implements iOS specific window creation, event handling and vulkan Surface setup.
Definition iOS_Window.h:47
bool pollEvents(vsg::UIEvents &events) override
get the list of events since the last pollEvents call by splicing bufferEvents with polled windowing ...
Definition iOS_ViewController.h:10
Definition iOS_Window.h:19