]> git.sesse.net Git - casparcg/blob - core/interaction/interaction_event.h
Merge pull request #462 from pkeuter/patch-1
[casparcg] / core / interaction / interaction_event.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Helge Norberg, helge.norberg@svt.se
20 */
21
22 #pragma once
23
24 #include <common/memory.h>
25
26 #include "../frame/frame_transform.h"
27
28 #include "util.h"
29
30 namespace caspar { namespace core {
31
32 struct interaction_event
33                 : public spl::enable_shared_from_this<interaction_event>
34 {
35         typedef spl::shared_ptr<const interaction_event> ptr;
36
37         const int source_id;
38
39         interaction_event(int source_id)
40                 : source_id(source_id)
41         {
42         }
43
44         virtual ~interaction_event()
45         {
46         }
47 };
48
49 struct position_event : public interaction_event
50 {
51         const double x;
52         const double y;
53
54         position_event(int source_id, double x, double y)
55                 : interaction_event(source_id)
56                 , x(x), y(y)
57         {
58         }
59
60         virtual interaction_event::ptr translate(
61                         const frame_transform& transform) const
62         {
63                 auto translated = ::caspar::core::translate(x, y, transform);
64
65                 if (translated.first == x && translated.second == y)
66                         return shared_from_this();
67                 else
68                         return clone(translated.first, translated.second);
69         }
70 protected:
71         virtual interaction_event::ptr clone(double new_x, double new_y) const = 0;
72 };
73
74 struct mouse_move_event : public position_event
75 {
76         typedef spl::shared_ptr<mouse_move_event> ptr;
77
78         mouse_move_event(int source_id, double x, double y)
79                 : position_event(source_id, x, y)
80         {
81         }
82 protected:
83         virtual interaction_event::ptr clone(
84                         double new_x, double new_y) const override
85         {
86                 return spl::make_shared<mouse_move_event>(source_id, new_x, new_y);
87         }
88 };
89
90 struct mouse_wheel_event : public position_event
91 {
92         typedef spl::shared_ptr<mouse_wheel_event> ptr;
93
94         const int ticks_delta;
95
96         mouse_wheel_event(int source_id, double x, double y, int ticks_delta)
97                 : position_event(source_id, x, y)
98                 , ticks_delta(ticks_delta)
99         {
100         }
101 protected:
102         virtual interaction_event::ptr clone(
103                         double new_x, double new_y) const override
104         {
105                 return spl::make_shared<mouse_wheel_event>(source_id, new_x, new_y, ticks_delta);
106         }
107 };
108
109 struct mouse_button_event : public position_event
110 {
111         typedef spl::shared_ptr<mouse_button_event> ptr;
112
113         const int button;
114         const bool pressed;
115
116         mouse_button_event(
117                         int source_id, double x, double y, int button, bool pressed)
118                 : position_event(source_id, x, y)
119                 , button(button)
120                 , pressed(pressed)
121         {
122         }
123 protected:
124         virtual interaction_event::ptr clone(
125                         double new_x, double new_y) const override
126         {
127                 return spl::make_shared<mouse_button_event>(
128                                 source_id, new_x, new_y, button, pressed);
129         }
130 };
131
132 }}