blob: b3b5057125f275d56e05b05ec32793d0b6857e63 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Input state keeper for the livecoding tool
*
* Authors:
* Sol Bekic <s+inkscape@s-ol.nu>
* Copyright (C) 2019 Authors
*
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include "livecode/input.h"
#include "livecode/context.h"
#include "desktop.h"
namespace Inkscape {
namespace Livecode {
Mouse::Mouse(Context &context)
: context(context)
{
}
void Mouse::finish_frame()
{
prev_mask = last_mask;
prev_pos = last_pos;
}
void Mouse::push_event(GdkEvent *event)
{
switch (event->type) {
case GDK_BUTTON_PRESS: {
last_mask |= 1 << event->button.button - 1;
break;
}
case GDK_BUTTON_RELEASE: {
last_mask &= ~(1 << event->button.button - 1);
break;
}
case GDK_MOTION_NOTIFY: {
last_pos = Geom::Point(event->motion.x, event->motion.y) * context.dt2ui();
break;
}
default:
break;
}
}
InputState Mouse::event(guint button) const {
guint const flag = 1 << button - 1;
bool last = last_mask & flag;
bool prev = prev_mask & flag;
if (last && prev) return INPUTSTATE_HELD;
else if (last) return INPUTSTATE_PRESSED;
else if (prev) return INPUTSTATE_RELEASED;
return INPUTSTATE_NONE;
}
bool Mouse::pressed(guint button) const {
guint const flag = 1 << button - 1;
return (last_mask & flag) && !(prev_mask & flag);
}
bool Mouse::held(guint button) const {
return last_mask & (1 << button -1);
}
bool Mouse::released(guint button) const {
guint const flag = 1 << button - 1;
return (prev_mask & flag) && !(last_mask & flag);
}
Geom::Point Mouse::pos() const {
return ui_pos() * context.ui2doc();
}
Geom::Point Mouse::delta() const {
return ui_delta() * context.ui2doc_vec();
}
Geom::Point Mouse::ui_pos() const {
return last_pos;
}
Geom::Point Mouse::ui_delta() const {
return last_pos - prev_pos;
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
|