Correction d'un bug

Comme quoi, on en trouve tous les jours…
master
Darks 2 years ago
parent 23b49dc799
commit 5cb0d5fcba
  1. 358
      src/TouchLib.c

@ -1,180 +1,180 @@
#include "TouchLib.h"
void TL_getTouchXY(TL_Point *p)
{
int coordonnesX[TL_GET_TOUCH_ROUND];
int coordonnesY[TL_GET_TOUCH_ROUND];
int i = 0;
for(i=0; i<TL_GET_TOUCH_ROUND; i++) { coordonnesX[i] = -1; coordonnesY[i] = -1; } // initialization
i = 0;
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_0)) { coordonnesX[i] = 0; coordonnesY[i] = 20; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_DP)) { coordonnesX[i] = 5; coordonnesY[i] = 20; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_EXP)) { coordonnesX[i] = 10; coordonnesY[i] = 20; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_PMINUS)) { coordonnesX[i] = 15; coordonnesY[i] = 20; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CTRL_EXE)) { coordonnesX[i] = 20; coordonnesY[i] = 20; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_1)) { coordonnesX[i] = 0; coordonnesY[i] = 16; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_2)) { coordonnesX[i] = 5; coordonnesY[i] = 16; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_3)) { coordonnesX[i] = 10; coordonnesY[i] = 16; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_PLUS)) { coordonnesX[i] = 15; coordonnesY[i] = 16; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_MINUS)) { coordonnesX[i] = 20; coordonnesY[i] = 16; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_4)) { coordonnesX[i] = 0; coordonnesY[i] = 12; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_5)) { coordonnesX[i] = 5; coordonnesY[i] = 12; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_6)) { coordonnesX[i] = 10; coordonnesY[i] = 12; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_MULT)) { coordonnesX[i] = 15; coordonnesY[i] = 12; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_DIV)) { coordonnesX[i] = 20; coordonnesY[i] = 12; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_7)) { coordonnesX[i] = 0; coordonnesY[i] = 8; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_8)) { coordonnesX[i] = 5; coordonnesY[i] = 8; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_9)) { coordonnesX[i] = 10; coordonnesY[i] = 8; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CTRL_DEL)) { coordonnesX[i] = 15; coordonnesY[i] = 8; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CTRL_AC)) { coordonnesX[i] = 20; coordonnesY[i] = 8; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_FRAC)) { coordonnesX[i] = 0; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CTRL_FD)) { coordonnesX[i] = 4; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_LPAR)) { coordonnesX[i] = 8; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_RPAR)) { coordonnesX[i] = 12; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_COMMA)) { coordonnesX[i] = 16; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_STORE)) { coordonnesX[i] = 20; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CTRL_XTT)) { coordonnesX[i] = 0; coordonnesY[i] = 0; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_LOG)) { coordonnesX[i] = 4; coordonnesY[i] = 0; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_LN)) { coordonnesX[i] = 8; coordonnesY[i] = 0; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_SIN)) { coordonnesX[i] = 12; coordonnesY[i] = 0; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_COS)) { coordonnesX[i] = 16; coordonnesY[i] = 0; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_TAN)) { coordonnesX[i] = 20; coordonnesY[i] = 0; i++; }
p->x = TL_average(coordonnesX, TL_GET_TOUCH_ROUND);
p->y = TL_average(coordonnesY, TL_GET_TOUCH_ROUND);
}
void TL_waitTouchXY(int Xmin, int Xmax, int Ymin, int Ymax)
{
TL_Point p;
p.x = p.y = -1;
while(p.x < Xmin || p.x > Xmax || p.y < Ymin || p.y > Ymax)
{
TL_getTouchXY(&p);
Sleep(10);
}
}
/*TL_Point *TL_getSeveralTouchs(int nbPoints)
{
int i = 0, x = -1, y = -1;
TL_Point *points;
points = malloc(nbPoints * sizeof(TL_Point));
do
{
TL_getTouchXY(&x, &y);
if(x >= 0)
{
if(i == 0)
{
points[i].x = x;
points[i].y = y;
i++;
}
else
{
if(x != points[i-1].x && y != points[i-1].y)
{
points[i].x = x;
points[i].y = y;
i++;
}
}
}
}while(i<nbPoints);
return points;
}*/
void TL_waitGesture(int originX_min, int originX_max, int originY_min, int originY_max, int displacementX_min, int displacementX_max, int displacementY_min, int displacementY_max, int speed)
{
TL_Point p, p2;
int depX, depY;
int i;
p.x = p.y = p2.x = p2.y = -1;
while(1)
{
while(p.x < originX_min || p.x > originX_max || p.y < originY_min || p.y > originY_max) TL_getTouchXY(&p);
p2.x = p.x;
p2.x = p.y;
i = speed;
while(i>0)
{
TL_getTouchXY(&p);
if(p.x < 0)
{
i--;
}
else
{
i = speed;
depX = p.x-p2.x;
depY = p.y-p2.y;
}
if(depX >= displacementX_min && depX <= displacementX_max && depY >= displacementY_min && depY <= displacementY_max) return;
}
}
}
void TL_getGesture(int *originX, int *originY, int *displacementX, int *displacementY, int speed)
{
TL_Point p, p2;
int i;
p.x = p.y = p2.x = p2.y = -1;
i = speed;
while(p.x < 0) TL_getTouchXY(&p);
*originX = p.x;
*originY = p.x;
while(i > 0)
{
TL_getTouchXY(&p2);
if(p.x < 0)
{
i--;
}
else
{
i = speed;
*displacementX = p2.x-p.x;
*displacementY = p2.y-p.y;
}
}
return;
}
int TL_average(int *tableau, int taille)
{
int somme = 0, i=0;
if(tableau[0] < 0) return -1;
for(i=0; i<taille; i++)
{
if(tableau[i] < 0) taille = i;
else somme += tableau[i];
}
return somme/(taille);
#include "TouchLib.h"
void TL_getTouchXY(TL_Point *p)
{
int coordonnesX[TL_GET_TOUCH_ROUND];
int coordonnesY[TL_GET_TOUCH_ROUND];
int i = 0;
for(i=0; i<TL_GET_TOUCH_ROUND; i++) { coordonnesX[i] = -1; coordonnesY[i] = -1; } // initialization
i = 0;
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_0)) { coordonnesX[i] = 0; coordonnesY[i] = 20; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_DP)) { coordonnesX[i] = 5; coordonnesY[i] = 20; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_EXP)) { coordonnesX[i] = 10; coordonnesY[i] = 20; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_PMINUS)) { coordonnesX[i] = 15; coordonnesY[i] = 20; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CTRL_EXE)) { coordonnesX[i] = 20; coordonnesY[i] = 20; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_1)) { coordonnesX[i] = 0; coordonnesY[i] = 16; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_2)) { coordonnesX[i] = 5; coordonnesY[i] = 16; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_3)) { coordonnesX[i] = 10; coordonnesY[i] = 16; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_PLUS)) { coordonnesX[i] = 15; coordonnesY[i] = 16; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_MINUS)) { coordonnesX[i] = 20; coordonnesY[i] = 16; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_4)) { coordonnesX[i] = 0; coordonnesY[i] = 12; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_5)) { coordonnesX[i] = 5; coordonnesY[i] = 12; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_6)) { coordonnesX[i] = 10; coordonnesY[i] = 12; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_MULT)) { coordonnesX[i] = 15; coordonnesY[i] = 12; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_DIV)) { coordonnesX[i] = 20; coordonnesY[i] = 12; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_7)) { coordonnesX[i] = 0; coordonnesY[i] = 8; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_8)) { coordonnesX[i] = 5; coordonnesY[i] = 8; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_9)) { coordonnesX[i] = 10; coordonnesY[i] = 8; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CTRL_DEL)) { coordonnesX[i] = 15; coordonnesY[i] = 8; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CTRL_AC)) { coordonnesX[i] = 20; coordonnesY[i] = 8; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_FRAC)) { coordonnesX[i] = 0; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CTRL_FD)) { coordonnesX[i] = 4; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_LPAR)) { coordonnesX[i] = 8; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_RPAR)) { coordonnesX[i] = 12; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_COMMA)) { coordonnesX[i] = 16; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_STORE)) { coordonnesX[i] = 20; coordonnesY[i] = 4; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CTRL_XTT)) { coordonnesX[i] = 0; coordonnesY[i] = 0; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_LOG)) { coordonnesX[i] = 4; coordonnesY[i] = 0; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_LN)) { coordonnesX[i] = 8; coordonnesY[i] = 0; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_SIN)) { coordonnesX[i] = 12; coordonnesY[i] = 0; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_COS)) { coordonnesX[i] = 16; coordonnesY[i] = 0; i++; }
if(i < TL_GET_TOUCH_ROUND && IsKeyDown(KEY_CHAR_TAN)) { coordonnesX[i] = 20; coordonnesY[i] = 0; i++; }
p->x = TL_average(coordonnesX, TL_GET_TOUCH_ROUND);
p->y = TL_average(coordonnesY, TL_GET_TOUCH_ROUND);
}
void TL_waitTouchXY(int Xmin, int Xmax, int Ymin, int Ymax)
{
TL_Point p;
p.x = p.y = -1;
while(p.x < Xmin || p.x > Xmax || p.y < Ymin || p.y > Ymax)
{
TL_getTouchXY(&p);
Sleep(10);
}
}
/*TL_Point *TL_getSeveralTouchs(int nbPoints)
{
int i = 0, x = -1, y = -1;
TL_Point *points;
points = malloc(nbPoints * sizeof(TL_Point));
do
{
TL_getTouchXY(&x, &y);
if(x >= 0)
{
if(i == 0)
{
points[i].x = x;
points[i].y = y;
i++;
}
else
{
if(x != points[i-1].x && y != points[i-1].y)
{
points[i].x = x;
points[i].y = y;
i++;
}
}
}
}while(i<nbPoints);
return points;
}*/
void TL_waitGesture(int originX_min, int originX_max, int originY_min, int originY_max, int displacementX_min, int displacementX_max, int displacementY_min, int displacementY_max, int speed)
{
TL_Point p, p2;
int depX, depY;
int i;
p.x = p.y = p2.x = p2.y = -1;
while(1)
{
while(p.x < originX_min || p.x > originX_max || p.y < originY_min || p.y > originY_max) TL_getTouchXY(&p);
p2.x = p.x;
p2.y = p.y;
i = speed;
while(i>0)
{
TL_getTouchXY(&p);
if(p.x < 0)
{
i--;
}
else
{
i = speed;
depX = p.x-p2.x;
depY = p.y-p2.y;
}
if(depX >= displacementX_min && depX <= displacementX_max && depY >= displacementY_min && depY <= displacementY_max) return;
}
}
}
void TL_getGesture(int *originX, int *originY, int *displacementX, int *displacementY, int speed)
{
TL_Point p, p2;
int i;
p.x = p.y = p2.x = p2.y = -1;
i = speed;
while(p.x < 0) TL_getTouchXY(&p);
*originX = p.x;
*originY = p.x;
while(i > 0)
{
TL_getTouchXY(&p2);
if(p.x < 0)
{
i--;
}
else
{
i = speed;
*displacementX = p2.x-p.x;
*displacementY = p2.y-p.y;
}
}
return;
}
int TL_average(int *tableau, int taille)
{
int somme = 0, i=0;
if(tableau[0] < 0) return -1;
for(i=0; i<taille; i++)
{
if(tableau[i] < 0) taille = i;
else somme += tableau[i];
}
return somme/(taille);
}
Loading…
Cancel
Save