From 293c7d2a6d72c3b8f7215b8167073b70cbdd6c0b Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 6 Mar 2020 20:51:47 -0800 Subject: [PATCH] swapping out color names in preparation for styles Former-commit-id: 4ffc36aa3a42586e1a7d4a17a5946175e23c3cb3 Former-commit-id: 93bbe2405261c2b98ba36a1548ec1993cdbf0538 --- draw.c | 46 +++++++++++++++++++++++++---------------- init.c | 17 +++++++++++++++ input.c | 31 ++++----------------------- run_view1090.sh | 2 +- status.c | 9 ++++---- structs.h | 16 ++++++++++++++ view1090.REMOVED.git-id | 2 +- 7 files changed, 72 insertions(+), 51 deletions(-) diff --git a/draw.c b/draw.c index 4456e1a..158b422 100644 --- a/draw.c +++ b/draw.c @@ -21,6 +21,20 @@ float sign(float x) { return (x > 0) - (x < 0); } +float clamp(float in, float min, float max) { + float out = in; + + if(in < min) { + out = min; + } + + if(in > max) { + out = max; + } + + return out; +} + void CROSSVP(float *v, float *u, float *w) { v[0] = u[1]*w[2] - u[2]*(w)[1]; @@ -314,11 +328,7 @@ void drawTrail(float *oldDx, float *oldDy, float *oldHeading, time_t * oldSeen, float age = pow(1.0 - (float)(now - oldSeen[currentIdx]) / TRAIL_TTL, 2.2); - if(age < 0) { - age = 0; - } - - uint8_t colorVal = (uint8_t)floor(255.0 * age); + uint8_t colorVal = (uint8_t)floor(255.0 * clamp(age,0,1)); thickLineRGBA(appData.renderer, prevX, prevY, currentX, currentY, 2 * appData.screen_uiscale, colorVal, colorVal, colorVal, 64); @@ -332,7 +342,7 @@ void drawTrail(float *oldDx, float *oldDy, float *oldHeading, time_t * oldSeen, //tick marks age = 1.0 - (float) 4.0 * (now - oldSeen[currentIdx]) / TRAIL_TTL; - colorVal = (uint8_t)floor(255.0 * age); + colorVal = (uint8_t)floor(255.0 * clamp(age,0,1)); float vec[3]; vec[0] = sin(oldHeading[currentIdx] * M_PI / 180); @@ -345,7 +355,6 @@ void drawTrail(float *oldDx, float *oldDy, float *oldHeading, time_t * oldSeen, CROSSVP(out,vec,up); - int x1, y1, x2, y2; int cross_size = 5 * appData.screen_uiscale; @@ -375,10 +384,10 @@ void drawScaleBars() char scaleLabel[13] = ""; - lineRGBA(appData.renderer,10,10,10,10*appData.screen_uiscale,pink.r, pink.g, pink.b, 255); + lineRGBA(appData.renderer,10,10,10,10*appData.screen_uiscale,style.scaleBarColor.r, style.scaleBarColor.g, style.scaleBarColor.b, 255); while(scaleBarDist < appData.screen_width) { - lineRGBA(appData.renderer,10+scaleBarDist,8,10+scaleBarDist,16*appData.screen_uiscale,pink.r, pink.g, pink.b, 255); + lineRGBA(appData.renderer,10+scaleBarDist,8,10+scaleBarDist,16*appData.screen_uiscale,style.scaleBarColor.r, style.scaleBarColor.g, style.scaleBarColor.b, 255); if (Modes.metric) { snprintf(scaleLabel,13,"%dkm", (int)pow(10,scalePower)); @@ -386,7 +395,7 @@ void drawScaleBars() snprintf(scaleLabel,13,"%dmi", (int)pow(10,scalePower)); } - drawString(scaleLabel, 10+scaleBarDist, 15*appData.screen_uiscale, appData.mapFont, pink); + drawString(scaleLabel, 10+scaleBarDist, 15*appData.screen_uiscale, appData.mapFont, style.scaleBarColor); scalePower++; scaleBarDist = screenDist((float)pow(10,scalePower)); @@ -395,7 +404,7 @@ void drawScaleBars() scalePower--; scaleBarDist = screenDist((float)pow(10,scalePower)); - lineRGBA(appData.renderer,10,10+5*appData.screen_uiscale,10+scaleBarDist,10+5*appData.screen_uiscale,pink.r, pink.g, pink.b, 255); + lineRGBA(appData.renderer,10,10+5*appData.screen_uiscale,10+scaleBarDist,10+5*appData.screen_uiscale, style.scaleBarColor.r, style.scaleBarColor.g, style. scaleBarColor.b, 255); } void drawPolys(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max) { @@ -460,7 +469,7 @@ void drawPolys(QuadTree *tree, float screen_lat_min, float screen_lat_max, float float factor = 1.0 - (d1+d2) / (3* appData.maxDist * appData.maxDist); - SDL_Color lineColor = lerpColor(purple, blue, factor); + SDL_Color lineColor = lerpColor(style.mapOuterColor, style.mapInnerColor, factor); lineRGBA(appData.renderer, x1, y1, x2, y2, lineColor.r, lineColor.g, lineColor.b, 255); @@ -913,9 +922,9 @@ void drawPlanes() { lineRGBA(appData.renderer, usex - boxSize, usey + boxSize, usex - boxSize/2, usey + boxSize, pink.r, pink.g, pink.b, 255); lineRGBA(appData.renderer, usex - boxSize, usey + boxSize, usex - boxSize, usey + boxSize/2, pink.r, pink.g, pink.b, 255); - planeColor = lerpColor(pink, grey, (now - p->seen) / (float) DISPLAY_ACTIVE); + planeColor = lerpColor(style.selectedColor, style.planeGoneColor, (now - p->seen) / (float) DISPLAY_ACTIVE); } else { - planeColor = lerpColor(green, grey, (now - p->seen) / (float) DISPLAY_ACTIVE); + planeColor = lerpColor(style.planeColor, style.planeGoneColor, (now - p->seen) / (float) DISPLAY_ACTIVE); } if(outOfBounds(x,y)) { @@ -1061,7 +1070,7 @@ void drawMouse() { } void registerClick() { - if(appData.tapCount == 1) { + if(appData.tapCount == 1 && appData.isDragging == 0) { struct planeObj *p = planes; struct planeObj *selection = NULL; @@ -1108,7 +1117,8 @@ void draw() { if(appData.mapMoved) { SDL_SetRenderTarget(appData.renderer, appData.mapTexture); - SDL_SetRenderDrawColor(appData.renderer, 0, 0, 0, 0); + SDL_SetRenderDrawColor(appData.renderer, style.backgroundColor.r, style.backgroundColor.g, style.backgroundColor.b, 255); + SDL_RenderClear(appData.renderer); drawGeography(); @@ -1125,7 +1135,7 @@ void draw() { } //SDL_SetRenderDrawColor( appData.renderer, 0, 15, 30, 0); - SDL_SetRenderDrawColor(appData.renderer, 0, 0, 0, 0); + SDL_SetRenderDrawColor(appData.renderer, style.backgroundColor.r, style.backgroundColor.g, style.backgroundColor.b, 255); SDL_RenderClear(appData.renderer); @@ -1136,7 +1146,7 @@ void draw() { drawMouse(); char fps[13] = " "; - snprintf(fps,13," %ffps", 1000.0 / (mstime() - appData.lastFrameTime)); + snprintf(fps,13," %.1ffps", 1000.0 / (mstime() - appData.lastFrameTime)); drawStringBG(fps, 0,0, appData.mapFont, grey, black); SDL_RenderPresent(appData.renderer); diff --git a/init.c b/init.c index ed65386..dd4e08d 100644 --- a/init.c +++ b/init.c @@ -1,5 +1,6 @@ #include "dump1090.h" #include "structs.h" +#include "monokai.h" void init(char *title) { @@ -46,6 +47,7 @@ void init(char *title) { appData.mapTargetLon = 0; appData.mapTargetLat = 0; appData.mapTargetMaxDist = 0; + appData.isDragging = 0; selectedPlane = NULL; if(appData.fullscreen) { @@ -70,6 +72,21 @@ void init(char *title) { appData.labelFontWidth = 6 * appData.screen_uiscale; appData.labelFontHeight = 12 * appData.screen_uiscale; + SDL_Color bgcolor = {10,20,30,255}; + SDL_Color greenblue = {236,192,68,255}; + SDL_Color lightblue = {211,208,203,255}; + SDL_Color mediumblue ={110,136,152,255}; + SDL_Color darkblue = {46,82,102,255}; + + style.backgroundColor = bgcolor; + style.selectedColor = pink; + style.planeColor = greenblue; + style.planeGoneColor = grey; + style.mapInnerColor = mediumblue; + style.mapOuterColor = darkblue; + style.scaleBarColor = lightGrey; + style.buttonColor = lightblue; + initMaps(); } diff --git a/input.c b/input.c index 793220d..7489e64 100644 --- a/input.c +++ b/input.c @@ -45,48 +45,24 @@ void getInput() 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_FINGERDOWN: + case SDL_MOUSEBUTTONDOWN: 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; - // //appData.tapCount++; - - // 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; appData.tapCount = event.button.clicks; registerClick(); + + appData.isDragging = 0; break; case SDL_MOUSEMOTION:; @@ -95,6 +71,7 @@ void getInput() appData.mousey = event.motion.y; if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) { + appData.isDragging = 1; moveCenterRelative(event.motion.xrel, event.motion.yrel); } break; diff --git a/run_view1090.sh b/run_view1090.sh index 47cff53..85ed8e4 100755 --- a/run_view1090.sh +++ b/run_view1090.sh @@ -1,2 +1,2 @@ #!/bin/bash -./view1090 --screensize 640 480 --fullscreen --server adsb --lat 47.6 --lon -122.3 +./view1090 --screensize 640 360 --fullscreen --server adsb --lat 47.6 --lon -122.3 diff --git a/status.c b/status.c index 1d52d81..a53e1ea 100644 --- a/status.c +++ b/status.c @@ -175,17 +175,18 @@ void drawStatus() { char strLoc[20] = " "; snprintf(strLoc, 20, "%3.3fN %3.3f%c", appData.centerLat, fabs(appData.centerLon),(appData.centerLon > 0) ? 'E' : 'W'); - drawStatusBox(&left, &top, "loc", strLoc, pink); + drawStatusBox(&left, &top, "loc", strLoc, style.buttonColor); char strPlaneCount[10] = " "; snprintf(strPlaneCount, 10,"%d/%d", Status.numVisiblePlanes, Status.numPlanes); - drawStatusBox(&left, &top, "disp", strPlaneCount, yellow); + drawStatusBox(&left, &top, "disp", strPlaneCount, style.buttonColor); char strMsgRate[18] = " "; snprintf(strMsgRate, 18,"%.0f/s", Status.msgRate); - drawStatusBox(&left, &top, "rate", strMsgRate, orange); + drawStatusBox(&left, &top, "rate", strMsgRate, style.buttonColor); char strSig[18] = " "; snprintf(strSig, 18, "%.0f%%", 100.0 * Status.avgSig / 1024.0); - drawStatusBox(&left, &top, "sAvg", strSig, green); + drawStatusBox(&left, &top, "sAvg", strSig, style.buttonColor); + } diff --git a/structs.h b/structs.h index 668c4ce..bb51410 100644 --- a/structs.h +++ b/structs.h @@ -41,6 +41,7 @@ typedef struct AppData int touchx; int touchy; int tapCount; + int isDragging; uint64_t mouseMovedTime; int mousex; @@ -106,6 +107,21 @@ struct { double maxDist; struct aircraft *closeCall; } Status; +typedef struct Style { + SDL_Color backgroundColor; + + SDL_Color selectedColor; + SDL_Color planeColor; + SDL_Color planeGoneColor; + + SDL_Color mapInnerColor; + SDL_Color mapOuterColor; + SDL_Color scaleBarColor; + + SDL_Color buttonColor; +} Style; + +Style style; // functions diff --git a/view1090.REMOVED.git-id b/view1090.REMOVED.git-id index 07e3d7e..17c1af3 100644 --- a/view1090.REMOVED.git-id +++ b/view1090.REMOVED.git-id @@ -1 +1 @@ -9a8fdd967629e70f6eb3ebced534ec141239aa05 \ No newline at end of file +b7d48859caf08d954d9a9d596481d36962f33b98 \ No newline at end of file