double click zoom, other tap cleanup
Former-commit-id: 0f130dbbdc9ea3f519912785beb2ccc6345f5a3f Former-commit-id: d6e0e41a4e1b355449f3312201ab79977c256071
This commit is contained in:
parent
a4718f8d93
commit
06276d33c2
160
draw.c
160
draw.c
|
@ -841,42 +841,24 @@ void drawPlanes() {
|
||||||
|
|
||||||
// draw all trails first so they don't cover up planes and text
|
// draw all trails first so they don't cover up planes and text
|
||||||
// also find closest plane to selection point
|
// also find closest plane to selection point
|
||||||
|
|
||||||
struct planeObj *selection = NULL;
|
|
||||||
|
|
||||||
while(p) {
|
while(p) {
|
||||||
if ((now - p->seen) < Modes.interactive_display_ttl) {
|
if ((now - p->seen) < Modes.interactive_display_ttl) {
|
||||||
drawTrail(p->oldLon, p->oldLat, p->oldHeading, p->oldSeen, p->oldIdx);
|
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;
|
p = p->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(selectedPlane == NULL) {
|
if(selectedPlane) {
|
||||||
selectedPlane = selection;
|
appData.mapTargetLon = selectedPlane->lon;
|
||||||
|
appData.mapTargetLat = selectedPlane->lat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
p = planes;
|
p = planes;
|
||||||
|
|
||||||
while(p) {
|
while(p) {
|
||||||
if ((now - p->seen) < Modes.interactive_display_ttl) {
|
if ((now - p->seen) < Modes.interactive_display_ttl) {
|
||||||
if (p->lon && p->lat) {
|
if (p->lon && p->lat) {
|
||||||
|
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
float dx, dy;
|
float dx, dy;
|
||||||
|
@ -910,14 +892,6 @@ void drawPlanes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(p == selectedPlane) {
|
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?
|
// this logic should be in input, register a callback for click?
|
||||||
float elapsed = mstime() - appData.touchDownTime;
|
float elapsed = mstime() - appData.touchDownTime;
|
||||||
|
|
||||||
|
@ -980,20 +954,37 @@ void drawPlanes() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveCenterAbsolute(float x, float y);
|
void animateCenterAbsolute(float x, float y) {
|
||||||
void moveCenterRelative(float dx, float dy) {
|
float scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height;
|
||||||
//
|
|
||||||
// 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;
|
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);
|
||||||
|
|
||||||
dx = -1.0 * (0.75*(double)appData.screen_width / (double)appData.screen_height) * dx * appData.maxDist / (0.95 * scale_factor * 0.5);
|
float outLat = dy * (1.0/6371.0) * (180.0f / M_PI);
|
||||||
dy = 1.0 * dy * appData.maxDist / (0.95 * scale_factor * 0.5);
|
|
||||||
|
|
||||||
double 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 = 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;
|
//double outLon, outLat;
|
||||||
//latLonFromScreenCoords(&outLat, &outLon, event.tfinger.dx, event.tfinger.dy);
|
//latLonFromScreenCoords(&outLat, &outLon, event.tfinger.dx, event.tfinger.dy);
|
||||||
|
@ -1001,11 +992,65 @@ void moveCenterRelative(float dx, float dy) {
|
||||||
appData.centerLon += outLon;
|
appData.centerLon += outLon;
|
||||||
appData.centerLat += outLat;
|
appData.centerLat += outLat;
|
||||||
|
|
||||||
|
appData.mapTargetLon = 0;
|
||||||
|
appData.mapTargetLat = 0;
|
||||||
|
|
||||||
appData.mapMoved = 1;
|
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() {
|
void drawMouse() {
|
||||||
if((mstime() - appData.mouseMovedTime) > 1000) {
|
if(appData.mouseMovedTime == 0 || (mstime() - appData.mouseMovedTime) > 1000) {
|
||||||
|
appData.mouseMovedTime = 0;
|
||||||
return;
|
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);
|
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() {
|
void draw() {
|
||||||
uint64_t drawStartTime = mstime();
|
uint64_t drawStartTime = mstime();
|
||||||
|
|
||||||
|
moveMapToTarget();
|
||||||
|
zoomMapToTarget();
|
||||||
|
|
||||||
updatePlanes();
|
updatePlanes();
|
||||||
|
|
||||||
updateStatus();
|
updateStatus();
|
||||||
|
@ -1060,7 +1139,6 @@ void draw() {
|
||||||
snprintf(fps,13," %ffps", 1000.0 / (mstime() - appData.lastFrameTime));
|
snprintf(fps,13," %ffps", 1000.0 / (mstime() - appData.lastFrameTime));
|
||||||
drawStringBG(fps, 0,0, appData.mapFont, grey, black);
|
drawStringBG(fps, 0,0, appData.mapFont, grey, black);
|
||||||
|
|
||||||
|
|
||||||
SDL_RenderPresent(appData.renderer);
|
SDL_RenderPresent(appData.renderer);
|
||||||
|
|
||||||
appData.lastFrameTime = mstime();
|
appData.lastFrameTime = mstime();
|
||||||
|
|
3
init.c
3
init.c
|
@ -43,6 +43,9 @@ void init(char *title) {
|
||||||
appData.screen_width, appData.screen_height);
|
appData.screen_width, appData.screen_height);
|
||||||
|
|
||||||
appData.mapMoved = 1;
|
appData.mapMoved = 1;
|
||||||
|
appData.mapTargetLon = 0;
|
||||||
|
appData.mapTargetLat = 0;
|
||||||
|
appData.mapTargetMaxDist = 0;
|
||||||
selectedPlane = NULL;
|
selectedPlane = NULL;
|
||||||
|
|
||||||
if(appData.fullscreen) {
|
if(appData.fullscreen) {
|
||||||
|
|
46
input.c
46
input.c
|
@ -37,40 +37,56 @@ void getInput()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
|
|
||||||
appData.maxDist *= 1.0 + event.wheel.y / 10.0;
|
appData.maxDist *= 1.0 + event.wheel.y / 10.0;
|
||||||
|
appData.mapTargetMaxDist = 0;
|
||||||
appData.mapMoved = 1;
|
appData.mapMoved = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MULTIGESTURE:
|
case SDL_MULTIGESTURE:
|
||||||
appData.maxDist /=1.0 + 4.0*event.mgesture.dDist;
|
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;
|
appData.mapMoved = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_FINGERMOTION:;
|
// case SDL_FINGERMOTION:;
|
||||||
moveCenterRelative(appData.screen_width * event.tfinger.dx, appData.screen_height * event.tfinger.dy);
|
// moveCenterRelative(appData.screen_width * event.tfinger.dx, appData.screen_height * event.tfinger.dy);
|
||||||
break;
|
// break;
|
||||||
|
|
||||||
case SDL_FINGERDOWN:
|
case SDL_FINGERDOWN:
|
||||||
|
if(mstime() - appData.touchDownTime > 500) {
|
||||||
|
appData.tapCount = 0;
|
||||||
|
}
|
||||||
appData.touchDownTime = mstime();
|
appData.touchDownTime = mstime();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_FINGERUP:
|
// case SDL_FINGERUP:
|
||||||
if(mstime() - appData.touchDownTime < 30) {
|
// if(mstime() - appData.touchDownTime < 30) {
|
||||||
appData.touchx = appData.screen_width * event.tfinger.x;
|
// appData.touchx = appData.screen_width * event.tfinger.x;
|
||||||
appData.touchy = appData.screen_height * event.tfinger.y;
|
// appData.touchy = appData.screen_height * event.tfinger.y;
|
||||||
selectedPlane = NULL;
|
// selectedPlane = NULL;
|
||||||
|
// //appData.tapCount++;
|
||||||
|
|
||||||
} else {
|
// registerClick();
|
||||||
appData.touchx = 0;
|
// } else {
|
||||||
appData.touchy = 0;
|
// appData.touchx = 0;
|
||||||
}
|
// appData.touchy = 0;
|
||||||
break;
|
// appData.tapCount = 0;
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case SDL_MOUSEBUTTONDOWN:;
|
||||||
|
// appData.tapCount = 0;
|
||||||
|
// break;
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONUP:;
|
case SDL_MOUSEBUTTONUP:;
|
||||||
appData.touchx = event.motion.x;
|
appData.touchx = event.motion.x;
|
||||||
appData.touchy = event.motion.y;
|
appData.touchy = event.motion.y;
|
||||||
selectedPlane = NULL;
|
appData.tapCount = event.button.clicks;
|
||||||
|
|
||||||
|
registerClick();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEMOTION:;
|
case SDL_MOUSEMOTION:;
|
||||||
|
|
|
@ -40,11 +40,16 @@ typedef struct AppData
|
||||||
uint64_t touchDownTime;
|
uint64_t touchDownTime;
|
||||||
int touchx;
|
int touchx;
|
||||||
int touchy;
|
int touchy;
|
||||||
|
int tapCount;
|
||||||
|
|
||||||
uint64_t mouseMovedTime;
|
uint64_t mouseMovedTime;
|
||||||
int mousex;
|
int mousex;
|
||||||
int mousey;
|
int mousey;
|
||||||
|
|
||||||
|
float mapTargetMaxDist;
|
||||||
|
float mapTargetLat;
|
||||||
|
float mapTargetLon;
|
||||||
|
|
||||||
int mapMoved;
|
int mapMoved;
|
||||||
|
|
||||||
uint64_t lastFrameTime;
|
uint64_t lastFrameTime;
|
||||||
|
@ -129,6 +134,7 @@ void draw();
|
||||||
void latLonFromScreenCoords(float *lat, float *lon, int x, int y);
|
void latLonFromScreenCoords(float *lat, float *lon, int x, int y);
|
||||||
void moveCenterAbsolute(float x, float y);
|
void moveCenterAbsolute(float x, float y);
|
||||||
void moveCenterRelative(float dx, float dy);
|
void moveCenterRelative(float dx, float dy);
|
||||||
|
void registerClick();
|
||||||
|
|
||||||
//status.c
|
//status.c
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0bb991221c62367955b3caea2fd131cb374a840c
|
9a8fdd967629e70f6eb3ebced534ec141239aa05
|
Loading…
Reference in a new issue