fixed double tap registered during pinch gesture, mouse cursor

Former-commit-id: 58fa2af1042fa4ecb906a41ae5b1deba84886c5b
Former-commit-id: 2411214bb4b74323f7dbef5817659c08461e4473
This commit is contained in:
nathan 2020-03-21 20:30:23 -07:00
parent 2a0f6e01eb
commit 07429b75c3
5 changed files with 48 additions and 37 deletions

View file

@ -4,7 +4,7 @@ static uint64_t mstime(void) {
struct timeval tv; struct timeval tv;
uint64_t mst; uint64_t mst;
gettimeofday(&tv, NULL); gettimeofday(&tv, nullptr);
mst = ((uint64_t)tv.tv_sec)*1000; mst = ((uint64_t)tv.tv_sec)*1000;
mst += tv.tv_usec/1000; mst += tv.tv_usec/1000;
return mst; return mst;
@ -17,7 +17,7 @@ Aircraft *AircraftList::find(uint32_t addr) {
if (p->addr == addr) return (p); if (p->addr == addr) return (p);
p = p->next; p = p->next;
} }
return (NULL); return (nullptr);
} }
//instead of this, net_io should call this class directly to update info //instead of this, net_io should call this class directly to update info
@ -90,7 +90,7 @@ void AircraftList::update(Modes *modes) {
} }
p = head; p = head;
Aircraft *prev = NULL; Aircraft *prev = nullptr;
while(p) { while(p) {
if(!p->live) { if(!p->live) {
@ -111,11 +111,11 @@ void AircraftList::update(Modes *modes) {
} }
AircraftList::AircraftList() { AircraftList::AircraftList() {
head = NULL; head = nullptr;
} }
AircraftList::~AircraftList() { AircraftList::~AircraftList() {
while(head != NULL) { while(head != nullptr) {
Aircraft *temp = head; Aircraft *temp = head;
head = head->next; head = head->next;
delete(temp); delete(temp);

View file

@ -60,7 +60,10 @@ void Input::getInput()
break; break;
case SDL_FINGERMOTION:; case SDL_FINGERMOTION:;
touchDownTime = 0; if(mstime() - touchDownTime > 150) {
tapCount = 0;
touchDownTime = 0;
}
view->moveCenterRelative( view->screen_width * event.tfinger.dx, view->screen_height * event.tfinger.dy); view->moveCenterRelative( view->screen_width * event.tfinger.dx, view->screen_height * event.tfinger.dy);
break; break;
@ -68,11 +71,14 @@ void Input::getInput()
if(mstime() - touchDownTime > 500) { if(mstime() - touchDownTime > 500) {
tapCount = 0; tapCount = 0;
} }
touchDownTime = mstime();
if(SDL_GetNumTouchFingers(event.tfinger.touchId) == 0) {
touchDownTime = mstime();
}
break; break;
case SDL_FINGERUP: case SDL_FINGERUP:
if(mstime() - touchDownTime < 120) { if(mstime() - touchDownTime < 150 && SDL_GetNumTouchFingers(event.tfinger.touchId) == 0) {
touchx = view->screen_width * event.tfinger.x; touchx = view->screen_width * event.tfinger.x;
touchy = view->screen_height * event.tfinger.y; touchy = view->screen_height * event.tfinger.y;
tapCount++; tapCount++;

View file

@ -3,7 +3,7 @@
# sure that the variable PREFIX is defined, e.g. make PREFIX=/usr/local # sure that the variable PREFIX is defined, e.g. make PREFIX=/usr/local
# #
CFLAGS=-O2 -g -Wall -W CFLAGS=-O2 -g -Wno-write-strings
LIBS=-lm -lSDL2 -lSDL2_ttf -lSDL2_gfx LIBS=-lm -lSDL2 -lSDL2_ttf -lSDL2_gfx
CC=g++ CC=g++

View file

@ -1095,32 +1095,12 @@ void View::drawPlanes() {
usey = y + (mstime() - p->msSeenLatLon) * vely; usey = y + (mstime() - p->msSeenLatLon) * vely;
} }
if(p == selectedAircraft) {
// this logic should be in input, register a callback for click?
float elapsed = mstime() - clickTime;
int boxSize;
if(elapsed < 300) {
boxSize = (int)(20.0 * (1.0 - (1.0 - elapsed / 300.0) * cos(sqrt(elapsed))));
} else {
boxSize = 20;
}
//rectangleRGBA(renderer, usex - boxSize, usey - boxSize, usex + boxSize, usey + boxSize, pink.r, pink.g, pink.b, 255);
lineRGBA(renderer, usex - boxSize, usey - boxSize, usex - boxSize/2, usey - boxSize, pink.r, pink.g, pink.b, 255);
lineRGBA(renderer, usex - boxSize, usey - boxSize, usex - boxSize, usey - boxSize/2, pink.r, pink.g, pink.b, 255);
lineRGBA(renderer, usex + boxSize, usey - boxSize, usex + boxSize/2, usey - boxSize, pink.r, pink.g, pink.b, 255);
lineRGBA(renderer, usex + boxSize, usey - boxSize, usex + boxSize, usey - boxSize/2, pink.r, pink.g, pink.b, 255);
lineRGBA(renderer, usex + boxSize, usey + boxSize, usex + boxSize/2, usey + boxSize, pink.r, pink.g, pink.b, 255);
lineRGBA(renderer, usex + boxSize, usey + boxSize, usex + boxSize, usey + boxSize/2, pink.r, pink.g, pink.b, 255);
lineRGBA(renderer, usex - boxSize, usey + boxSize, usex - boxSize/2, usey + boxSize, pink.r, pink.g, pink.b, 255);
lineRGBA(renderer, usex - boxSize, usey + boxSize, usex - boxSize, usey + boxSize/2, pink.r, pink.g, pink.b, 255);
}
planeColor = lerpColor(style.planeColor, style.planeGoneColor, (now - p->seen) / (float) DISPLAY_ACTIVE); planeColor = lerpColor(style.planeColor, style.planeGoneColor, (now - p->seen) / (float) DISPLAY_ACTIVE);
if(p == selectedAircraft) {
planeColor = style.selectedColor;
}
if(outOfBounds(x,y)) { if(outOfBounds(x,y)) {
drawPlaneOffMap(x, y, &(p->cx), &(p->cy), planeColor); drawPlaneOffMap(x, y, &(p->cx), &(p->cy), planeColor);
} else { } else {
@ -1261,6 +1241,31 @@ void View::drawClick() {
filledCircleRGBA(renderer, clickx, clicky, radius, white.r, white.g, white.b, alpha); filledCircleRGBA(renderer, clickx, clicky, radius, white.r, white.g, white.b, alpha);
} }
if(selectedAircraft) {
// this logic should be in input, register a callback for click?
float elapsed = mstime() - clickTime;
int boxSize;
if(elapsed < 300) {
boxSize = (int)(20.0 * (1.0 - (1.0 - elapsed / 300.0) * cos(sqrt(elapsed))));
} else {
boxSize = 20;
}
//rectangleRGBA(renderer, selectedAircraft->cx - boxSize, selectedAircraft->cy - boxSize, selectedAircraft->cx + boxSize, selectedAircraft->cy + boxSize, style.selectedColor.r, style.selectedColor.g, style.selectedColor.b, 255);
lineRGBA(renderer, selectedAircraft->cx - boxSize, selectedAircraft->cy - boxSize, selectedAircraft->cx - boxSize/2, selectedAircraft->cy - boxSize, style.selectedColor.r, style.selectedColor.g, style.selectedColor.b, 255);
lineRGBA(renderer, selectedAircraft->cx - boxSize, selectedAircraft->cy - boxSize, selectedAircraft->cx - boxSize, selectedAircraft->cy - boxSize/2, style.selectedColor.r, style.selectedColor.g, style.selectedColor.b, 255);
lineRGBA(renderer, selectedAircraft->cx + boxSize, selectedAircraft->cy - boxSize, selectedAircraft->cx + boxSize/2, selectedAircraft->cy - boxSize, style.selectedColor.r, style.selectedColor.g, style.selectedColor.b, 255);
lineRGBA(renderer, selectedAircraft->cx + boxSize, selectedAircraft->cy - boxSize, selectedAircraft->cx + boxSize, selectedAircraft->cy - boxSize/2, style.selectedColor.r, style.selectedColor.g, style.selectedColor.b, 255);
lineRGBA(renderer, selectedAircraft->cx + boxSize, selectedAircraft->cy + boxSize, selectedAircraft->cx + boxSize/2, selectedAircraft->cy + boxSize, style.selectedColor.r, style.selectedColor.g, style.selectedColor.b, 255);
lineRGBA(renderer, selectedAircraft->cx + boxSize, selectedAircraft->cy + boxSize, selectedAircraft->cx + boxSize, selectedAircraft->cy + boxSize/2, style.selectedColor.r, style.selectedColor.g, style.selectedColor.b, 255);
lineRGBA(renderer, selectedAircraft->cx - boxSize, selectedAircraft->cy + boxSize, selectedAircraft->cx - boxSize/2, selectedAircraft->cy + boxSize, style.selectedColor.r, style.selectedColor.g, style.selectedColor.b, 255);
lineRGBA(renderer, selectedAircraft->cx - boxSize, selectedAircraft->cy + boxSize, selectedAircraft->cx - boxSize, selectedAircraft->cy + boxSize/2, style.selectedColor.r, style.selectedColor.g, pink.b, 255);
}
} }
void View::registerClick(int tapcount, int x, int y) { void View::registerClick(int tapcount, int x, int y) {
@ -1297,8 +1302,7 @@ void View::registerClick(int tapcount, int x, int y) {
} }
void View::registerMouseMove(int x, int y) { void View::registerMouseMove(int x, int y) {
lastFrameTime = mstime(); mouseMovedTime = mstime();
this->mousex = x; this->mousex = x;
this->mousey = y; this->mousey = y;
} }
@ -1345,6 +1349,7 @@ void View::draw() {
drawPlanes(); drawPlanes();
drawStatus(); drawStatus();
drawMouse(); drawMouse();
drawClick();
char fps[13] = " "; char fps[13] = " ";
snprintf(fps,13," %.1ffps", 1000.0 / (mstime() - lastFrameTime)); snprintf(fps,13," %.1ffps", 1000.0 / (mstime() - lastFrameTime));

View file

@ -1 +1 @@
884676a0069dc93832d407eea2d3e612de57d44a 85bf9e07a831ad5a30abf7ae4737f9c8a543f9e2