1 | /*
|
---|
2 | Copyright (c) 2012 Arduino. All right reserved.
|
---|
3 |
|
---|
4 | This library is free software; you can redistribute it and/or
|
---|
5 | modify it under the terms of the GNU Lesser General Public
|
---|
6 | License as published by the Free Software Foundation; either
|
---|
7 | version 2.1 of the License, or (at your option) any later version.
|
---|
8 |
|
---|
9 | This library is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
12 | See the GNU Lesser General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU Lesser General Public
|
---|
15 | License along with this library; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include <MouseController.h>
|
---|
20 |
|
---|
21 | extern "C" {
|
---|
22 | void __mouseControllerEmptyCallback() { }
|
---|
23 | }
|
---|
24 |
|
---|
25 | void mouseClicked() __attribute__ ((weak, alias("__mouseControllerEmptyCallback")));
|
---|
26 | void mouseDragged() __attribute__ ((weak, alias("__mouseControllerEmptyCallback")));
|
---|
27 | void mouseMoved() __attribute__ ((weak, alias("__mouseControllerEmptyCallback")));
|
---|
28 | void mousePressed() __attribute__ ((weak, alias("__mouseControllerEmptyCallback")));
|
---|
29 | void mouseReleased() __attribute__ ((weak, alias("__mouseControllerEmptyCallback")));
|
---|
30 |
|
---|
31 | int MouseController::getXChange() {
|
---|
32 | int r = dx;
|
---|
33 | dx = 0;
|
---|
34 | return r;
|
---|
35 | }
|
---|
36 |
|
---|
37 | int MouseController::getYChange() {
|
---|
38 | int r = dy;
|
---|
39 | dy = 0;
|
---|
40 | return r;
|
---|
41 | }
|
---|
42 |
|
---|
43 | void MouseController::OnMouseMove(MOUSEINFO *mi) {
|
---|
44 | dx += mi->dX;
|
---|
45 | dy += mi->dY;
|
---|
46 | if (buttons != 0)
|
---|
47 | mouseDragged();
|
---|
48 | else
|
---|
49 | mouseMoved();
|
---|
50 | }
|
---|
51 |
|
---|
52 | void MouseController::OnLeftButtonUp(MOUSEINFO *mi) {
|
---|
53 | buttons &= ~LEFT_BUTTON;
|
---|
54 | mouseReleased();
|
---|
55 | mouseClicked();
|
---|
56 | }
|
---|
57 |
|
---|
58 | void MouseController::OnLeftButtonDown(MOUSEINFO *mi) {
|
---|
59 | buttons |= LEFT_BUTTON;
|
---|
60 | mousePressed();
|
---|
61 | }
|
---|
62 |
|
---|
63 | void MouseController::OnMiddleButtonUp(MOUSEINFO *mi) {
|
---|
64 | buttons &= ~MIDDLE_BUTTON;
|
---|
65 | mouseReleased();
|
---|
66 | mouseClicked();
|
---|
67 | }
|
---|
68 |
|
---|
69 | void MouseController::OnMiddleButtonDown(MOUSEINFO *mi) {
|
---|
70 | buttons |= MIDDLE_BUTTON;
|
---|
71 | mousePressed();
|
---|
72 | }
|
---|
73 |
|
---|
74 | void MouseController::OnRightButtonUp(MOUSEINFO *mi) {
|
---|
75 | buttons &= ~RIGHT_BUTTON;
|
---|
76 | mouseReleased();
|
---|
77 | mouseClicked();
|
---|
78 | }
|
---|
79 |
|
---|
80 | void MouseController::OnRightButtonDown(MOUSEINFO *mi) {
|
---|
81 | buttons |= RIGHT_BUTTON;
|
---|
82 | mousePressed();
|
---|
83 | }
|
---|