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

view_action.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 EventUI;
36 class PointerEvent;
37 class ActivationChangeEvent;
38 class FocusChangeEvent;
39 class KeyEvent;
40 class View;
41 class ViewActionImpl;
42
44 class ViewAction : public std::enable_shared_from_this<ViewAction>
45 {
46 public:
47 ViewAction();
48 virtual ~ViewAction();
49
51 View *view() const;
52
53 template<typename T>
54 T *view() const { return dynamic_cast<T*>(view<View>()); }
55
57 void remove_from_view();
58
60 void begin_action();
61
63 void end_action();
64
66 bool action_active() const;
67
69 virtual void any_event(EventUI *e) { }
70
72 virtual void pointer_press(PointerEvent &e) { }
73
75 virtual void pointer_double_click(PointerEvent &e) { }
76
78 virtual void pointer_release(PointerEvent &e) { }
79
81 virtual void pointer_move(PointerEvent &e) { }
82
84 virtual void pointer_enter(PointerEvent &e) { }
85
87 virtual void pointer_leave(PointerEvent &e) { }
88
90 virtual void pointer_proximity_change(PointerEvent &e) { }
91
93 virtual void activated(ActivationChangeEvent &e) { }
94
96 virtual void deactivated(ActivationChangeEvent &e) { }
97
99 virtual void focus_gained(FocusChangeEvent &e) { }
100
102 virtual void focus_lost(FocusChangeEvent &e) { }
103
105 virtual void key_press(KeyEvent &e) { }
106
108 virtual void key_release(KeyEvent &e) { }
109
110 private:
111 ViewAction(const ViewAction &) = delete;
112 ViewAction &operator=(const ViewAction &) = delete;
113
114 std::unique_ptr<ViewActionImpl> impl;
115
116 friend class ViewTree;
117 friend class View;
118 friend class ViewActionImpl;
119 };
120}
clan::ActivationChangeEvent
Window was activated or deactivated event.
Definition activation_change_event.h:44
clan::EventUI
Base class for events being dispatched through the view hiarchy.
Definition UI/Events/event.h:48
clan::FocusChangeEvent
View focus changed event.
Definition focus_change_event.h:44
clan::KeyEvent
Keyboard key event.
Definition key_event.h:48
clan::PointerEvent
Pointer event.
Definition pointer_event.h:68
clan::ViewAction
Recognizes actions in a view and captures input for the duration of the action.
Definition view_action.h:45
clan::ViewAction::View
friend class View
Definition view_action.h:117
clan::ViewAction::deactivated
virtual void deactivated(ActivationChangeEvent &e)
Handler for when the application is deactivated.
Definition view_action.h:96
clan::ViewAction::activated
virtual void activated(ActivationChangeEvent &e)
Handler for when the application is activated.
Definition view_action.h:93
clan::ViewAction::focus_gained
virtual void focus_gained(FocusChangeEvent &e)
Handler for focus gained events.
Definition view_action.h:99
clan::ViewAction::key_press
virtual void key_press(KeyEvent &e)
Handler for key press events.
Definition view_action.h:105
clan::ViewAction::ViewActionImpl
friend class ViewActionImpl
Definition view_action.h:118
clan::ViewAction::any_event
virtual void any_event(EventUI *e)
Handler for any UI event.
Definition view_action.h:69
clan::ViewAction::pointer_double_click
virtual void pointer_double_click(PointerEvent &e)
Handler for pointer double click events.
Definition view_action.h:75
clan::ViewAction::end_action
void end_action()
Releases capture of events.
clan::ViewAction::pointer_press
virtual void pointer_press(PointerEvent &e)
Handler for pointer press events.
Definition view_action.h:72
clan::ViewAction::pointer_leave
virtual void pointer_leave(PointerEvent &e)
Handler for pointer leave events.
Definition view_action.h:87
clan::ViewAction::focus_lost
virtual void focus_lost(FocusChangeEvent &e)
Handler for focus lost events.
Definition view_action.h:102
clan::ViewAction::remove_from_view
void remove_from_view()
Removes recognizer from the view it is attached to.
clan::ViewAction::~ViewAction
virtual ~ViewAction()
clan::ViewAction::pointer_proximity_change
virtual void pointer_proximity_change(PointerEvent &e)
Handler for pointer proximity change events.
Definition view_action.h:90
clan::ViewAction::view
View * view() const
Returns the view the action is attached to.
clan::ViewAction::view
T * view() const
Definition view_action.h:54
clan::ViewAction::key_release
virtual void key_release(KeyEvent &e)
Handler for key release events.
Definition view_action.h:108
clan::ViewAction::pointer_release
virtual void pointer_release(PointerEvent &e)
Handler for pointer release events.
Definition view_action.h:78
clan::ViewAction::pointer_move
virtual void pointer_move(PointerEvent &e)
Handler for pointer movement events.
Definition view_action.h:81
clan::ViewAction::action_active
bool action_active() const
Returns true if the action is capturing events.
clan::ViewAction::pointer_enter
virtual void pointer_enter(PointerEvent &e)
Handler for pointer enter events.
Definition view_action.h:84
clan::ViewAction::ViewTree
friend class ViewTree
Definition view_action.h:116
clan::ViewAction::begin_action
void begin_action()
Captures events until end is called.
clan::ViewAction::ViewAction
ViewAction()
clan::View
View for an area of the user interface.
Definition view.h:66
clan
Definition clanapp.h:36
clan::Key::e
@ e
Definition keys.h:85