From 06276d33c20e4c351859291e44838b40050dda86 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 6 Mar 2020 15:44:45 -0800 Subject: [PATCH] double click zoom, other tap cleanup Former-commit-id: 0f130dbbdc9ea3f519912785beb2ccc6345f5a3f Former-commit-id: d6e0e41a4e1b355449f3312201ab79977c256071 --- draw.c | 162 +++++++++++++++++++++++++++++----------- init.c | 3 + input.c | 48 ++++++++---- structs.h | 6 ++ view1090.REMOVED.git-id | 2 +- 5 files changed, 162 insertions(+), 59 deletions(-) diff --git a/draw.c b/draw.c index 1697e0d..4456e1a 100644 --- a/draw.c +++ b/draw.c @@ -841,42 +841,24 @@ void drawPlanes() { // draw all trails first so they don't cover up planes and text // also find closest plane to selection point - - struct planeObj *selection = NULL; - while(p) { if ((now - p->seen) < Modes.interactive_display_ttl) { drawTrail(p->oldLon, p->oldLat, p->oldHeading, p->oldSeen, p->oldIdx); } - if(selectedPlane == NULL && appData.touchx && appData.touchy) { - if((p->cx - appData.touchx) * (p->cx - appData.touchx) + (p->cy - appData.touchy) * (p->cy - appData.touchy) < 900) { - if(selection) { - if((p->cx - appData.touchx) * (p->cx - appData.touchx) + (p->cy - appData.touchy) * (p->cy - appData.touchy) < - (selection->cx - appData.touchx) * (selection->cx - appData.touchx) + (selection->cy - appData.touchy) * (selection->cy - appData.touchy)) { - selection = p; - } - } else { - selection = p; - } - } - } - p = p->next; } - if(selectedPlane == NULL) { - selectedPlane = selection; + if(selectedPlane) { + appData.mapTargetLon = selectedPlane->lon; + appData.mapTargetLat = selectedPlane->lat; } - p = planes; while(p) { if ((now - p->seen) < Modes.interactive_display_ttl) { if (p->lon && p->lat) { - - int x, y; float dx, dy; @@ -910,14 +892,6 @@ void drawPlanes() { } if(p == selectedPlane) { - - if(fabs(p->lon - appData.centerLon) > 0.0001 || fabs(p->lat - appData.centerLat) > 0.0001) { - appData.centerLon += 0.1 * (p->lon - appData.centerLon); - appData.centerLat += 0.1 * (p->lat - appData.centerLat); - - appData.mapMoved = 1; - } - // this logic should be in input, register a callback for click? float elapsed = mstime() - appData.touchDownTime; @@ -980,20 +954,37 @@ void drawPlanes() { } } -void moveCenterAbsolute(float x, float y); -void moveCenterRelative(float dx, float dy) { - // - // need to make lonlat to screen conversion class - this is just the inverse of the stuff in draw.c, without offsets - // - - double scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height; +void animateCenterAbsolute(float x, float y) { + float scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height; - dx = -1.0 * (0.75*(double)appData.screen_width / (double)appData.screen_height) * dx * appData.maxDist / (0.95 * scale_factor * 0.5); - dy = 1.0 * dy * appData.maxDist / (0.95 * scale_factor * 0.5); + float dx = -1.0 * (0.75*(double)appData.screen_width / (double)appData.screen_height) * (x - appData.screen_width/2) * appData.maxDist / (0.95 * scale_factor * 0.5); + float dy = 1.0 * (y - appData.screen_height/2) * appData.maxDist / (0.95 * scale_factor * 0.5); - double outLat = dy * (1.0/6371.0) * (180.0f / M_PI); + float outLat = dy * (1.0/6371.0) * (180.0f / M_PI); - double outLon = dx * (1.0/6371.0) * (180.0f / M_PI) / cos(((appData.centerLat)/2.0f) * M_PI / 180.0f); + float outLon = dx * (1.0/6371.0) * (180.0f / M_PI) / cos(((appData.centerLat)/2.0f) * M_PI / 180.0f); + + //double outLon, outLat; + //latLonFromScreenCoords(&outLat, &outLon, event.tfinger.dx, event.tfinger.dy); + + appData.mapTargetLon = appData.centerLon - outLon; + appData.mapTargetLat = appData.centerLat - outLat; + + appData.mapTargetMaxDist = 0.25 * appData.maxDist; + + appData.mapMoved = 1; +} + + +void moveCenterAbsolute(float x, float y) { + float scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height; + + float dx = -1.0 * (0.75*(double)appData.screen_width / (double)appData.screen_height) * (x - appData.screen_width/2) * appData.maxDist / (0.95 * scale_factor * 0.5); + float dy = 1.0 * (y - appData.screen_height/2) * appData.maxDist / (0.95 * scale_factor * 0.5); + + float outLat = dy * (1.0/6371.0) * (180.0f / M_PI); + + float outLon = dx * (1.0/6371.0) * (180.0f / M_PI) / cos(((appData.centerLat)/2.0f) * M_PI / 180.0f); //double outLon, outLat; //latLonFromScreenCoords(&outLat, &outLon, event.tfinger.dx, event.tfinger.dy); @@ -1001,11 +992,65 @@ void moveCenterRelative(float dx, float dy) { appData.centerLon += outLon; appData.centerLat += outLat; + appData.mapTargetLon = 0; + appData.mapTargetLat = 0; + appData.mapMoved = 1; } +void moveCenterRelative(float dx, float dy) { + // + // need to make lonlat to screen conversion class - this is just the inverse of the stuff in draw.c, without offsets + // + + float scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height; + + dx = -1.0 * (0.75*(double)appData.screen_width / (double)appData.screen_height) * dx * appData.maxDist / (0.95 * scale_factor * 0.5); + dy = 1.0 * dy * appData.maxDist / (0.95 * scale_factor * 0.5); + + float outLat = dy * (1.0/6371.0) * (180.0f / M_PI); + + float outLon = dx * (1.0/6371.0) * (180.0f / M_PI) / cos(((appData.centerLat)/2.0f) * M_PI / 180.0f); + + //double outLon, outLat; + //latLonFromScreenCoords(&outLat, &outLon, event.tfinger.dx, event.tfinger.dy); + + appData.centerLon += outLon; + appData.centerLat += outLat; + + appData.mapTargetLon = 0; + appData.mapTargetLat = 0; + + appData.mapMoved = 1; +} + +void zoomMapToTarget() { + if(appData.mapTargetMaxDist) { + if(fabs(appData.mapTargetMaxDist - appData.maxDist) > 0.0001) { + appData.maxDist += 0.1 * (appData.mapTargetMaxDist - appData.maxDist); + } else { + appData.mapTargetMaxDist = 0; + } + } +} + +void moveMapToTarget() { + if(appData.mapTargetLon && appData.mapTargetLat) { + if(fabs(appData.mapTargetLon - appData.centerLon) > 0.0001 || fabs(appData.mapTargetLat - appData.centerLat) > 0.0001) { + appData.centerLon += 0.1 * (appData.mapTargetLon- appData.centerLon); + appData.centerLat += 0.1 * (appData.mapTargetLat - appData.centerLat); + + appData.mapMoved = 1; + } else { + appData.mapTargetLon = 0; + appData.mapTargetLat = 0; + } + } +} + void drawMouse() { - if((mstime() - appData.mouseMovedTime) > 1000) { + if(appData.mouseMovedTime == 0 || (mstime() - appData.mouseMovedTime) > 1000) { + appData.mouseMovedTime = 0; return; } @@ -1015,6 +1060,37 @@ void drawMouse() { lineRGBA(appData.renderer, appData.mousex, appData.mousey - 10 * appData.screen_uiscale, appData.mousex, appData.mousey + 10 * appData.screen_uiscale, white.r, white.g, white.b, alpha); } +void registerClick() { + if(appData.tapCount == 1) { + struct planeObj *p = planes; + struct planeObj *selection = NULL; + + while(p) { + if(appData.touchx && appData.touchy) { + if((p->cx - appData.touchx) * (p->cx - appData.touchx) + (p->cy - appData.touchy) * (p->cy - appData.touchy) < 900) { + if(selection) { + if((p->cx - appData.touchx) * (p->cx - appData.touchx) + (p->cy - appData.touchy) * (p->cy - appData.touchy) < + (selection->cx - appData.touchx) * (selection->cx - appData.touchx) + (selection->cy - appData.touchy) * (selection->cy - appData.touchy)) { + selection = p; + } + } else { + selection = p; + } + } + } + + p = p->next; + } + + //if(selectedPlane == NULL) { + selectedPlane = selection; + //} + } else if(appData.tapCount == 2) { + appData.mapTargetMaxDist = 0.25 * appData.maxDist; + animateCenterAbsolute(appData.touchx, appData.touchy); + } +} + // // // @@ -1022,6 +1098,9 @@ void drawMouse() { void draw() { uint64_t drawStartTime = mstime(); + moveMapToTarget(); + zoomMapToTarget(); + updatePlanes(); updateStatus(); @@ -1060,7 +1139,6 @@ void draw() { snprintf(fps,13," %ffps", 1000.0 / (mstime() - appData.lastFrameTime)); drawStringBG(fps, 0,0, appData.mapFont, grey, black); - SDL_RenderPresent(appData.renderer); appData.lastFrameTime = mstime(); diff --git a/init.c b/init.c index 3003d00..ed65386 100644 --- a/init.c +++ b/init.c @@ -43,6 +43,9 @@ void init(char *title) { appData.screen_width, appData.screen_height); appData.mapMoved = 1; + appData.mapTargetLon = 0; + appData.mapTargetLat = 0; + appData.mapTargetMaxDist = 0; selectedPlane = NULL; if(appData.fullscreen) { diff --git a/input.c b/input.c index e75eb98..793220d 100644 --- a/input.c +++ b/input.c @@ -37,42 +37,58 @@ void getInput() break; case SDL_MOUSEWHEEL: - appData.maxDist *= 1.0 + event.wheel.y / 10.0; + appData.mapTargetMaxDist = 0; appData.mapMoved = 1; break; case SDL_MULTIGESTURE: appData.maxDist /=1.0 + 4.0*event.mgesture.dDist; + appData.mapTargetMaxDist = 0; + //moveCenterRelative((appData.screen_width/2) * event.mgesture.x, (appData.screen_height/2) * event.mgesture.y); + //moveCenterRelative(event.mgesture.x, event.mgesture.y); + appData.mapMoved = 1; break; - case SDL_FINGERMOTION:; - moveCenterRelative(appData.screen_width * event.tfinger.dx, appData.screen_height * event.tfinger.dy); - break; + // case SDL_FINGERMOTION:; + // moveCenterRelative(appData.screen_width * event.tfinger.dx, appData.screen_height * event.tfinger.dy); + // break; case SDL_FINGERDOWN: + if(mstime() - appData.touchDownTime > 500) { + appData.tapCount = 0; + } appData.touchDownTime = mstime(); break; - case SDL_FINGERUP: - if(mstime() - appData.touchDownTime < 30) { - appData.touchx = appData.screen_width * event.tfinger.x; - appData.touchy = appData.screen_height * event.tfinger.y; - selectedPlane = NULL; + // case SDL_FINGERUP: + // if(mstime() - appData.touchDownTime < 30) { + // appData.touchx = appData.screen_width * event.tfinger.x; + // appData.touchy = appData.screen_height * event.tfinger.y; + // selectedPlane = NULL; + // //appData.tapCount++; - } else { - appData.touchx = 0; - appData.touchy = 0; - } - break; + // registerClick(); + // } else { + // appData.touchx = 0; + // appData.touchy = 0; + // appData.tapCount = 0; + // } + // break; + + // case SDL_MOUSEBUTTONDOWN:; + // appData.tapCount = 0; + // break; case SDL_MOUSEBUTTONUP:; appData.touchx = event.motion.x; appData.touchy = event.motion.y; - selectedPlane = NULL; + appData.tapCount = event.button.clicks; + + registerClick(); break; - + case SDL_MOUSEMOTION:; appData.mouseMovedTime = mstime(); appData.mousex = event.motion.x; diff --git a/structs.h b/structs.h index bde9e2a..668c4ce 100644 --- a/structs.h +++ b/structs.h @@ -40,11 +40,16 @@ typedef struct AppData uint64_t touchDownTime; int touchx; int touchy; + int tapCount; uint64_t mouseMovedTime; int mousex; int mousey; + float mapTargetMaxDist; + float mapTargetLat; + float mapTargetLon; + int mapMoved; uint64_t lastFrameTime; @@ -129,6 +134,7 @@ void draw(); void latLonFromScreenCoords(float *lat, float *lon, int x, int y); void moveCenterAbsolute(float x, float y); void moveCenterRelative(float dx, float dy); +void registerClick(); //status.c void updateStatus(); diff --git a/view1090.REMOVED.git-id b/view1090.REMOVED.git-id index 2b0acfd..07e3d7e 100644 --- a/view1090.REMOVED.git-id +++ b/view1090.REMOVED.git-id @@ -1 +1 @@ -0bb991221c62367955b3caea2fd131cb374a840c \ No newline at end of file +9a8fdd967629e70f6eb3ebced534ec141239aa05 \ No newline at end of file