-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsouris.c
54 lines (43 loc) · 1.14 KB
/
souris.c
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
//
// Created by Hash on 4/14/2016.
//
#include "souris.h"
#define BOUTONS_SOURIS 10
static int tableau_souris[BOUTONS_SOURIS];
static int sx, sy;
bool souris_bouton_presse(int b){
return tableau_souris[b] & 1;
}
bool souris_bouton_relache(int b) {
return tableau_souris[b] & 2;
}
int souris_x(void) {
return sx;
}
int souris_y(void) {
return sy;
}
void souris_gerer_evenement(ALLEGRO_EVENT *event) {
switch (event->type) {
case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
tableau_souris[event->mouse.button] |= (1 << 0);
tableau_souris[event->mouse.button] |= (1 << 1);
break;
case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
tableau_souris[event->mouse.button] &= ~(1 << 0);
tableau_souris[event->mouse.button] |= (1 << 2);
break;
case ALLEGRO_EVENT_MOUSE_AXES:
sx = event->mouse.x;
sy = event->mouse.y;
break;
}
}
void souris_tick(void) {
// effacer les bits presse/relache
int i;
for(i = 0; i < BOUTONS_SOURIS; i++) {
tableau_souris[i] &= ~(1 << 1);
tableau_souris[i] &= ~(1 << 2);
}
}