-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatividade1.c
executable file
·58 lines (45 loc) · 1.06 KB
/
atividade1.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
55
56
57
58
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "mouse.h"
#include "cg2d.h"
#define MAX_POINTS 10000
int main(void) {
signed char* xy;
signed char xList[MAX_POINTS];
signed char yList[MAX_POINTS];
int count = 0;
int fd;
// Abre o mouse
fd = openMouse();
int clique = 0;
// Loop para esperar clique esquerdo
while (!clique) {
clique = esquerdoApertado(fd);
}
// Se saiu do loop, houve um clique, armazena os proximos movimentos do mouse ate um novo clique
clique = 0;
xList[0] = 0;
yList[0] = 0;
while (!clique) {
clique = esquerdoApertado(fd);
xy = coordenadasMouse(fd);
//Insere novos pontos apenas se o ponteiro do mouse mexer
signed char new_x = xy[0];
signed char new_y = xy[1];
if(new_x != xList[count] || new_y != yList[count]){
xList[count] = xy[0];
yList[count] = xy[1];
count ++;
}
//Limita ao tamanho máximo do array
if (count == MAX_POINTS){
free(xy);
break;
}
}
for(int i = 0; i<count; i++){
printf("X%d = %d ", i, xList[i]);
printf("Y%d = %d\n", i, yList[i]);
}
}