mouse click and drag added
Former-commit-id: aee18213d280783da1b761e5b7ec7c01a53ac0d1 Former-commit-id: f15d983599f1f7e3b82b5642395f1914ae75d2f2
This commit is contained in:
parent
3398748007
commit
a4718f8d93
37
draw.c
37
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,6 +1054,7 @@ void draw() {
|
|||
|
||||
drawPlanes();
|
||||
drawStatus();
|
||||
drawMouse();
|
||||
|
||||
char fps[13] = " ";
|
||||
snprintf(fps,13," %ffps", 1000.0 / (mstime() - appData.lastFrameTime));
|
||||
|
|
39
input.c
39
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -1 +1 @@
|
|||
07df3964a61c9028e5b598c82409b849e2edc971
|
||||
0bb991221c62367955b3caea2fd131cb374a840c
|
Loading…
Reference in a new issue