event.h Source File - ClanLib SDK
Description: event.h Source File

UI/Events/event.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 The ClanLib Team
4**
5** This software is provided 'as-is', without any express or implied
6** warranty. In no event will the authors be held liable for any damages
7** arising from the use of this software.
8**
9** Permission is granted to anyone to use this software for any purpose,
10** including commercial applications, and to alter it and redistribute it
11** freely, subject to the following restrictions:
12**
13** 1. The origin of this software must not be misrepresented; you must not
14** claim that you wrote the original software. If you use this software
15** in a product, an acknowledgment in the product documentation would be
16** appreciated but is not required.
17** 2. Altered source versions must be plainly marked as such, and must not be
18** misrepresented as being the original software.
19** 3. This notice may not be removed or altered from any source distribution.
20**
21** Note: Some of the libraries ClanLib may link to may have additional
22** requirements or restrictions.
23**
24** File Author(s):
25**
26** Magnus Norddahl
27*/
28
29#pragma once
30
31#include <memory>
32
33namespace clan
34{
35 class View;
36
38 enum class EventUIPhase
39 {
40 none,
41 capturing,
42 at_target,
43 bubbling
44 };
45
47 class EventUI
48 {
49 public:
50 virtual ~EventUI() { }
51
53 EventUIPhase phase() const { return _phase; }
54
56 std::shared_ptr<View> target() { return _target; }
57
59 std::shared_ptr<View> current_target() { return _current_target; }
60
62 bool default_prevented() const { return _default_prevented; }
63
65 void prevent_default() { _default_prevented = true; }
66
67 //bool immediate_propagation_stopped() const { return _immediate_propagation_stopped; }
68 //void stop_immediate_propagation() { _propagation_stopped = true; _immediate_propagation_stopped = true; }
69
71 bool propagation_stopped() const { return _propagation_stopped; }
72
74 void stop_propagation() { _propagation_stopped = true; }
75
77 long long timestamp() const { return _timestamp; }
78
80 void set_timestamp(long long ts) { _timestamp = ts; }
81
82 private:
83 bool _default_prevented = false;
84 bool _propagation_stopped = false;
85 //bool _immediate_propagation_stopped = true;
86 EventUIPhase _phase = EventUIPhase::none;
87 std::shared_ptr<View> _target;
88 std::shared_ptr<View> _current_target;
89 long long _timestamp = 0;
90
91 friend class View;
92 friend class ViewImpl;
93 friend class ViewTree;
94 };
95}
clan::EventUI
Base class for events being dispatched through the view hiarchy.
Definition UI/Events/event.h:48
clan::EventUI::View
friend class View
Definition UI/Events/event.h:91
clan::EventUI::default_prevented
bool default_prevented() const
Flag if the event default action should be executed after dispatch.
Definition UI/Events/event.h:62
clan::EventUI::timestamp
long long timestamp() const
Timestamp for event in milliseconds since 1970.
Definition UI/Events/event.h:77
clan::EventUI::ViewImpl
friend class ViewImpl
Definition UI/Events/event.h:92
clan::EventUI::stop_propagation
void stop_propagation()
Stops event from propagating further.
Definition UI/Events/event.h:74
clan::EventUI::current_target
std::shared_ptr< View > current_target()
View the event is currently being dispatched to.
Definition UI/Events/event.h:59
clan::EventUI::~EventUI
virtual ~EventUI()
Definition UI/Events/event.h:50
clan::EventUI::phase
EventUIPhase phase() const
Current active event phase during dispatch.
Definition UI/Events/event.h:53
clan::EventUI::set_timestamp
void set_timestamp(long long ts)
Set event timestamp.
Definition UI/Events/event.h:80
clan::EventUI::propagation_stopped
bool propagation_stopped() const
Flag if event propagation should stop.
Definition UI/Events/event.h:71
clan::EventUI::ViewTree
friend class ViewTree
Definition UI/Events/event.h:93
clan::EventUI::target
std::shared_ptr< View > target()
The target view the event is fired for.
Definition UI/Events/event.h:56
clan::EventUI::prevent_default
void prevent_default()
Prevent default action from being executed after dispatch.
Definition UI/Events/event.h:65
clan::View
View for an area of the user interface.
Definition view.h:66
clan::DrawBuffer::none
@ none
Definition graphic_context.h:119
clan
Definition clanapp.h:36
clan::EventUIPhase
EventUIPhase
UI event dispatch phase.
Definition UI/Events/event.h:39
clan::EventUIPhase::none
@ none
Definition UI/Events/event.h:40
clan::EventUIPhase::at_target
@ at_target
Capture phase (inverse bubble from root to the target view).
Definition UI/Events/event.h:42
clan::EventUIPhase::capturing
@ capturing
Event is not currently in any dispatch phase.
Definition UI/Events/event.h:41
clan::EventUIPhase::bubbling
@ bubbling
Currently being dispatched to the target view.
Definition UI/Events/event.h:43