-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
93 lines (80 loc) · 3.11 KB
/
main.cpp
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
#include <stdio.h>
#include <SFML/Graphics.hpp>
#include <manymouse/manymouse.h>
using namespace std;
int main() {
ManyMouseEvent mmevent;
const int available_mice = ManyMouse_Init();
int i;
if (available_mice < 0) {
printf("Error initializing ManyMouse!\n");
ManyMouse_Quit();
return 2;
}
printf("ManyMouse driver: %s\n", ManyMouse_DriverName());
if (available_mice == 0) {
printf("No mice detected!\n");
ManyMouse_Quit();
return 1;
}
for (i = 0; i < available_mice; i++) {
printf("#%d: %s\n", i, ManyMouse_DeviceName(i));
}
printf("\n");
sf::RenderWindow window(sf::VideoMode(800, 600), "MMSFML");
vector<sf::CircleShape> circles;
for(int i = 0; i < available_mice; i++) {
sf::CircleShape circle;
circle.setRadius(10);
circle.setFillColor(sf::Color::Red);
circle.setOrigin(10, 10);
circle.setPosition(400, 300);
circles.push_back(circle);
}
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
while (ManyMouse_PollEvent(&mmevent)) {
if (mmevent.type == MANYMOUSE_EVENT_RELMOTION) {
printf("Mouse #%u relative motion %s %d\n", mmevent.device, mmevent.item == 0 ? "X" : "Y", mmevent.value);
sf::CircleShape *circle = &circles[mmevent.device];
sf::Vector2f vec = circle->getPosition();
if (mmevent.item == 0) {
vec.x += mmevent.value;
} else {
vec.y += mmevent.value;
}
circle->setPosition(vec);
} else if (mmevent.type == MANYMOUSE_EVENT_ABSMOTION) { // I have never witnessed this event
printf("Mouse #%u absolute motion %s %d\n", mmevent.device, mmevent.item == 0 ? "X" : "Y", mmevent.value);
} else if (mmevent.type == MANYMOUSE_EVENT_BUTTON) {
printf("Mouse #%u button %u %s\n", mmevent.device, mmevent.item, mmevent.value ? "down" : "up");
} else if (mmevent.type == MANYMOUSE_EVENT_SCROLL) {
const char *wheel;
const char *direction;
if (mmevent.item == 0) {
wheel = "vertical";
direction = ((mmevent.value > 0) ? "up" : "down");
} else {
wheel = "horizontal";
direction = ((mmevent.value > 0) ? "right" : "left");
}
printf("Mouse #%u wheel %s %s\n", mmevent.device, wheel, direction);
} else if (mmevent.type == MANYMOUSE_EVENT_DISCONNECT) {
printf("Mouse #%u disconnect\n", mmevent.device);
} else {
printf("Mouse #%u unhandled event type %d\n", mmevent.device, mmevent.type);
}
}
window.clear();
for (int i = 0; i < available_mice; i++) {
window.draw(circles[i]);
}
window.display();
}
return 0;
}