diff --git a/draw.c b/draw.c index 2b3afb5..1697e0d 100644 --- a/draw.c +++ b/draw.c @@ -918,6 +918,7 @@ void drawPlanes() { appData.mapMoved = 1; } + // this logic should be in input, register a callback for click? float elapsed = mstime() - appData.touchDownTime; int boxSize; @@ -979,6 +980,41 @@ 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; + + 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); + + double 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); + + //double outLon, outLat; + //latLonFromScreenCoords(&outLat, &outLon, event.tfinger.dx, event.tfinger.dy); + + appData.centerLon += outLon; + appData.centerLat += outLat; + + appData.mapMoved = 1; +} + +void drawMouse() { + if((mstime() - appData.mouseMovedTime) > 1000) { + return; + } + + int alpha = (int)(255.0f - 255.0f * (float)(mstime() - appData.mouseMovedTime) / 1000.0f); + + lineRGBA(appData.renderer, appData.mousex - 10 * appData.screen_uiscale, appData.mousey, appData.mousex + 10 * appData.screen_uiscale, appData.mousey, 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); +} + // // // @@ -1018,7 +1054,8 @@ void draw() { drawPlanes(); drawStatus(); - + drawMouse(); + char fps[13] = " "; snprintf(fps,13," %ffps", 1000.0 / (mstime() - appData.lastFrameTime)); drawStringBG(fps, 0,0, appData.mapFont, grey, black); diff --git a/input.c b/input.c index 8539b40..e75eb98 100644 --- a/input.c +++ b/input.c @@ -48,30 +48,9 @@ void getInput() break; case SDL_FINGERMOTION:; - - // - // 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; - - double dx = -1.0 * (0.75*(double)appData.screen_width / (double)appData.screen_height) * appData.screen_width * event.tfinger.dx * appData.maxDist / (0.95 * scale_factor * 0.5); - double dy = 1.0 * appData.screen_height * event.tfinger.dy * appData.maxDist / (0.95 * scale_factor * 0.5); - - double 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); - - //double outLon, outLat; - //latLonFromScreenCoords(&outLat, &outLon, event.tfinger.dx, event.tfinger.dy); - - appData.centerLon += outLon; - appData.centerLat += outLat; - - appData.mapMoved = 1; + moveCenterRelative(appData.screen_width * event.tfinger.dx, appData.screen_height * event.tfinger.dy); break; - case SDL_FINGERDOWN: appData.touchDownTime = mstime(); break; @@ -87,6 +66,22 @@ void getInput() appData.touchy = 0; } break; + + case SDL_MOUSEBUTTONUP:; + appData.touchx = event.motion.x; + appData.touchy = event.motion.y; + selectedPlane = NULL; + break; + + case SDL_MOUSEMOTION:; + appData.mouseMovedTime = mstime(); + appData.mousex = event.motion.x; + appData.mousey = event.motion.y; + + if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) { + moveCenterRelative(event.motion.xrel, event.motion.yrel); + } + break; } } } diff --git a/structs.h b/structs.h index e5335dd..bde9e2a 100644 --- a/structs.h +++ b/structs.h @@ -41,6 +41,10 @@ typedef struct AppData int touchx; int touchy; + uint64_t mouseMovedTime; + int mousex; + int mousey; + int mapMoved; uint64_t lastFrameTime; @@ -123,7 +127,8 @@ void drawList(int top); //draw.c void draw(); void latLonFromScreenCoords(float *lat, float *lon, int x, int y); - +void moveCenterAbsolute(float x, float y); +void moveCenterRelative(float dx, float dy); //status.c void updateStatus(); diff --git a/view1090.REMOVED.git-id b/view1090.REMOVED.git-id index 55b52cd..2b0acfd 100644 --- a/view1090.REMOVED.git-id +++ b/view1090.REMOVED.git-id @@ -1 +1 @@ -07df3964a61c9028e5b598c82409b849e2edc971 \ No newline at end of file +0bb991221c62367955b3caea2fd131cb374a840c \ No newline at end of file