vsg: include/vsg/app/CloseHandler.h Source File

vsg 1.1.3 VulkanSceneGraph library

Loading...
Searching...
No Matches
CloseHandler.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#include <vsg/app/Viewer.h>
16#include <vsg/ui/KeyEvent.h>
17
18namespace vsg
19{
20
22 class CloseHandler : public Inherit<Visitor, CloseHandler>
23 {
24 public:
25 explicit CloseHandler(Viewer* viewer) :
26 _viewer(viewer) {}
27
28 KeySymbol closeKey = KEY_Escape; // KEY_Undefined
29
30 virtual void close()
31 {
32 // take a ref_ptr<> of the observer_ptr<> to be able to safely access it
33 ref_ptr<Viewer> viewer = _viewer;
34 if (viewer) viewer->close();
35 }
36
37 void apply(KeyPressEvent& keyPress) override
38 {
39 if (closeKey != KEY_Undefined && keyPress.keyBase == closeKey) close();
40 }
41
42 void apply(CloseWindowEvent&) override
43 {
44 close();
45 }
46
47 void apply(TerminateEvent&) override
48 {
49 close();
50 }
51
52 protected:
53 // use observer_ptr<> to avoid circular reference
54 observer_ptr<Viewer> _viewer;
55 };
56 VSG_type_name(vsg::CloseHandler);
57
58} // namespace vsg
vsg::CloseHandler
CloseHandler event handler used to respond to close events generated by a Window.
Definition CloseHandler.h:23
vsg::CloseWindowEvent
CloseWindowEvent represents a window close event.
Definition WindowEvent.h:87
vsg::Inherit
Definition Inherit.h:28
vsg::KeyPressEvent
KeyPressEvent represents a key press event.
Definition KeyEvent.h:309
vsg::TerminateEvent
TerminateEvent represents an application termination event.
Definition ApplicationEvent.h:24
vsg::Viewer
Definition Viewer.h:33
vsg::allocator_affinity_nodes
std container adapter for allocating with MEMORY_AFFINITY_NODES
Definition Allocator.h:138