From d373baade6b12511ba087d4adfca2b8464e99c6e Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 10 Oct 2017 15:56:05 -0500 Subject: [PATCH] labeling updates, placeholder battery indicator Former-commit-id: d1e81f2e82cbbee968d9c54cdedc5e2fabba2937 Former-commit-id: ac2a078be1f5c4797824be34c85eaf9b4db7d08f --- sdl1090/defs.h | 1 + sdl1090/init.c | 30 ++++++++++------ sdl1090/interactive.c | 5 +++ sdl1090/maps.c | 61 ++++++++++++++++++--------------- sdl1090/status.c | 47 +++++++++++++++---------- sdl1090/structs.h | 5 ++- sdl1090/view1090.REMOVED.git-id | 2 +- 7 files changed, 93 insertions(+), 58 deletions(-) diff --git a/sdl1090/defs.h b/sdl1090/defs.h index 9474c32..60cff8e 100644 --- a/sdl1090/defs.h +++ b/sdl1090/defs.h @@ -14,6 +14,7 @@ #define SCREEN_HEIGHT 480 #define UPSCALE 1 +#define SCALE 1 #define LOGMAXDIST 1000.0 #define MAXDIST 50.0 diff --git a/sdl1090/init.c b/sdl1090/init.c index 3644276..b4543b6 100644 --- a/sdl1090/init.c +++ b/sdl1090/init.c @@ -25,7 +25,6 @@ void init(char *title) putenv((char*)"SDL_FBDEV=/dev/fb1"); #endif - mouseSetup(); /* Initialise SDL */ @@ -75,21 +74,26 @@ void init(char *title) exit(1); } + mouseSetup(); + /* Load the font */ - game.font = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 12); + game.mapFont = loadFont("font/TerminusTTF-4.46.0.ttf", 12 * SCALE); + game.mapBoldFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 12 * SCALE); - game.listFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 18); + game.listFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 18 * SCALE); - game.messageFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 34); - game.labelFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 16); + game.messageFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 34 * SCALE); + game.labelFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 16 * SCALE); + game.mapFontWidth = 5 * SCALE; + game.mapFontHeight = 12 * SCALE; - game.messageFontWidth = 17; - game.messageFontHeight = 34; + game.messageFontWidth = 17 * SCALE; + game.messageFontHeight = 34 * SCALE; - game.labelFontWidth = 5; - game.labelFontHeight = 10; + game.labelFontWidth = 5 * SCALE; + game.labelFontHeight = 10 * SCALE; /* Set the screen title */ @@ -102,8 +106,12 @@ void cleanup() { /* Close the font */ - closeFont(game.font); - + closeFont(game.mapFont); + closeFont(game.mapBoldFont); + closeFont(game.messageFont); + closeFont(game.labelFont); + closeFont(game.listFont); + /* Close SDL_TTF */ TTF_Quit(); diff --git a/sdl1090/interactive.c b/sdl1090/interactive.c index e27e31d..653a706 100644 --- a/sdl1090/interactive.c +++ b/sdl1090/interactive.c @@ -299,6 +299,11 @@ struct aircraft *interactiveReceiveData(struct modesMessage *mm) { a->prev_seen = a->seen; } + //strip trailing spaces + for(int i = 0; i<8; i++) { + a->flight[i] = (a->flight[i] == 32) ? 0 : a->flight[i]; + } + a->signalLevel[a->messages & 7] = mm->signalLevel;// replace the 8th oldest signal strength a->seen = time(NULL); a->timestamp = mm->timestampMsg; diff --git a/sdl1090/maps.c b/sdl1090/maps.c index 69ad43a..d0fe068 100644 --- a/sdl1090/maps.c +++ b/sdl1090/maps.c @@ -67,20 +67,16 @@ int outOfBounds(int x, int y) { } } -void drawPlaneHeading(double dx, double dy, double heading, int signal, char *flight) +void drawPlaneHeading(int x, int y, double heading, SDL_Color planeColor) { - int x, y; - screenCoords(&x, &y, dx, dy); - if(outOfBounds(x,y)) { return; } - SDL_Color planeColor = signalToColor(signal); - - double body = 8.0; - double wing = 6.0; - double tail = 3.0; + double body = 8.0 * SCALE; + double wing = 6.0 * SCALE; + double tail = 3.0 * SCALE; + double bodyWidth = 2.0 * SCALE; double vec[3]; vec[0] = sin(heading * M_PI / 180); @@ -106,9 +102,9 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl aatrigonRGBA(game.screen, x + round(-wing*.35*out[0]), y + round(-wing*.35*out[1]), x + round(wing*.35*out[0]), y + round(wing*.35*out[1]), x1, y1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); aacircleRGBA(game.screen, x2,y2,1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); } else { - thickLineRGBA(game.screen,x,y,x2,y2,2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); + thickLineRGBA(game.screen,x,y,x2,y2,bodyWidth,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); filledTrigonRGBA(game.screen, x + round(-wing*.35*out[0]), y + round(-wing*.35*out[1]), x + round(wing*.35*out[0]), y + round(wing*.35*out[1]), x1, y1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); - filledCircleRGBA(game.screen, x2,y2,1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); + filledCircleRGBA(game.screen, x2,y2,SCALE,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); } //wing @@ -134,22 +130,14 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl } else { filledTrigonRGBA (game.screen, x1, y1, x2, y2, x+round(-body*.5*vec[0]), y+round(-body*.5*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); } - - drawString(flight, x + 10, y + 10, game.font, planeColor); } -void drawPlane(double dx, double dy, int signal) +void drawPlane(int x, int y, SDL_Color planeColor) { - - int x, y; - screenCoords(&x, &y, dx, dy); - if(outOfBounds(x,y)) { return; } - SDL_Color planeColor = signalToColor(signal); - int length = 3.0; rectangleRGBA (game.screen, x - length, y - length, x+length, y + length, planeColor.r, planeColor.g, planeColor.b, SDL_ALPHA_OPAQUE); @@ -202,7 +190,7 @@ void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) { aalineRGBA(game.screen, prevX, prevY, currentX, currentY,colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE); } else { //thickLineRGBA(game.screen, prevX, prevY, currentX, currentY, 2, colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE); - thickLineRGBA(game.screen, prevX, prevY, currentX, currentY, 2, colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE); + thickLineRGBA(game.screen, prevX, prevY, currentX, currentY, 2 * SCALE, colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE); } } } @@ -227,9 +215,9 @@ void drawGrid() circleRGBA (game.screen, Modes.screen_width>>1, Modes.screen_height * CENTEROFFSET, p100km, pink.r, pink.g, pink.b, 127); } - drawString("1km", (Modes.screen_width>>1) + (0.707 * p1km) + 5, (Modes.screen_height * CENTEROFFSET) + (0.707 * p1km) + 5, game.font, pink); - drawString("10km", (Modes.screen_width>>1) + (0.707 * p10km) + 5, (Modes.screen_height * CENTEROFFSET) + (0.707 * p10km) + 5, game.font, pink); - drawString("100km", (Modes.screen_width>>1) + (0.707 * p100km) + 5, (Modes.screen_height * CENTEROFFSET) + (0.707 * p100km) + 5, game.font, pink); + drawString("1km", (Modes.screen_width>>1) + (0.707 * p1km) + 5, (Modes.screen_height * CENTEROFFSET) + (0.707 * p1km) + 5, game.mapFont, pink); + drawString("10km", (Modes.screen_width>>1) + (0.707 * p10km) + 5, (Modes.screen_height * CENTEROFFSET) + (0.707 * p10km) + 5, game.mapFont, pink); + drawString("100km", (Modes.screen_width>>1) + (0.707 * p100km) + 5, (Modes.screen_height * CENTEROFFSET) + (0.707 * p100km) + 5, game.mapFont, pink); } void drawGeography() { @@ -255,7 +243,7 @@ void drawGeography() { if(AA) { aalineRGBA(game.screen, x1, y1, x2, y2,purple.r,purple.g,purple.b, (alpha < 0) ? 0 : (uint8_t) alpha); } else { - lineRGBA(game.screen, x1, y1, x2, y2,purple.r,purple.g,purple.b, (alpha < 0) ? 0 : (uint8_t) alpha); + thickLineRGBA(game.screen, x1, y1, x2, y2, SCALE, purple.r,purple.g,purple.b, (alpha < 0) ? 0 : (uint8_t) alpha); } } } @@ -285,10 +273,29 @@ void drawMap(void) { colorIdx = signalAverage; } + SDL_Color planeColor = signalToColor(colorIdx); + int x, y; + screenCoords(&x, &y, a->dx, a->dy); + if(MODES_ACFLAGS_HEADING_VALID) { - drawPlaneHeading(a->dx, a->dy,a->track, colorIdx, a->flight); + drawPlaneHeading(x, y,a->track, planeColor); + + //char flight[11] = " "; + //snprintf(flight,11," %s ", a->flight); + //drawStringBG(flight, x, y + game.mapFontHeight, game.mapBoldFont, black, planeColor); + drawStringBG(a->flight, x + 5, y + game.mapFontHeight, game.mapBoldFont, white, black); + + char alt[10] = " "; + snprintf(alt,10,"%dm", a->altitude); + drawStringBG(alt, x + 5, y + 2*game.mapFontHeight, game.mapFont, grey, black); + + char speed[10] = " "; + snprintf(speed,10,"%dkm/h", a->speed); + drawStringBG(speed, x + 5, y + 3*game.mapFontHeight, game.mapFont, grey, black); + + lineRGBA(game.screen, x, y, x, y + 4*game.mapFontHeight, grey.r, grey.g, grey.b, SDL_ALPHA_OPAQUE); } else { - drawPlane(a->dx, a->dy, colorIdx); + drawPlane(x, y, planeColor); } } } diff --git a/sdl1090/status.c b/sdl1090/status.c index 83da594..8ffb0a3 100644 --- a/sdl1090/status.c +++ b/sdl1090/status.c @@ -108,6 +108,28 @@ void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color co *left = *left + labelWidth + messageWidth + PAD; } + +void drawBattery(int *left, int *top, double level) { + int lineWidth = 1; + + int pointCount = 9; + float xList[9] = {0.0, 0.25, 0.25, 0.75, 0.75, 1.0, 1.0, 0.0, 0.0}; + float yList[9] = {0.2, 0.2, 0.0, 0.0, 0.2, 0.2, 1.0, 1.0, 0.2}; + + for(int k = 0; k < pointCount - 1; k++) { + thickLineRGBA(game.screen, + *left + game.messageFontWidth * xList[k], + *top + game.messageFontHeight * yList[k], + *left + game.messageFontWidth * xList[k+1], + *top + game.messageFontHeight * yList[k+1], + lineWidth, grey.r, grey.g, grey.b, SDL_ALPHA_OPAQUE); + } + + boxRGBA(game.screen, *left, *top + (0.2 + 0.8 * (1.0 - level)) * game.messageFontHeight, *left + game.messageFontWidth, *top + game.messageFontHeight, grey.r, grey.g, grey.b, SDL_ALPHA_OPAQUE); + + *left = *left + game.messageFontWidth; +} + void drawStatus() { int left = PAD; @@ -117,6 +139,8 @@ void drawStatus() { snprintf(strLoc, 20, "%3.3fN %3.3f%c", Modes.fUserLat, fabs(Modes.fUserLon),(Modes.fUserLon > 0) ? 'E' : 'W'); drawStatusBox(&left, &top, "GPS", strLoc, pink); + drawBattery(&left, &top, 0.85); + char strPlaneCount[10] = " "; snprintf(strPlaneCount, 10,"%d/%d", Status.numVisiblePlanes, Status.numPlanes); drawStatusBox(&left, &top, "disp", strPlaneCount, yellow); @@ -136,24 +160,11 @@ void drawStatus() { drawStatusBox(&left, &top, "||||", "MENU", grey); if(Status.closeCall != NULL) { - // if no flight id, "near" box goes on first line - if(!strlen(Status.closeCall->flight)) { - drawStatusBox(&left, &top, "near", "", red); - } - - char strSpeed[8] = " "; - snprintf(strSpeed, 8, "%.0fkm/h", Status.closeCall->speed * 1.852); - drawStatusBox(&left, &top, "vel", strSpeed, white); - - char strAlt[8] = " "; - snprintf(strAlt, 8, "%.0fm", Status.closeCall->altitude / 3.2828); - drawStatusBox(&left, &top, "alt", strAlt, white); - - drawStatusBox(&left, &top, "", "", black); //this is effectively a newline - - if(strlen(Status.closeCall->flight)) { - drawStatusBox(&left, &top, "near", "", red); - drawStatusBox(&left, &top, "id", Status.closeCall->flight, white); + drawStatusBox(&left, &top, "", "", black); //this is effectively a newline + if(strlen(Status.closeCall->flight)) { + drawStatusBox(&left, &top, "near", Status.closeCall->flight, white); + } else { + drawStatusBox(&left, &top, "near", "", white); } } } diff --git a/sdl1090/structs.h b/sdl1090/structs.h index 6861c45..c9dd678 100644 --- a/sdl1090/structs.h +++ b/sdl1090/structs.h @@ -8,12 +8,15 @@ typedef struct Game SDL_Surface *screen; SDL_Surface *bigScreen; - TTF_Font *font; + TTF_Font *mapFont; + TTF_Font *mapBoldFont; TTF_Font *listFont; TTF_Font *messageFont; TTF_Font *labelFont; + int mapFontWidth; + int mapFontHeight; int labelFontWidth; int labelFontHeight; int messageFontWidth; diff --git a/sdl1090/view1090.REMOVED.git-id b/sdl1090/view1090.REMOVED.git-id index a366532..16ee10d 100644 --- a/sdl1090/view1090.REMOVED.git-id +++ b/sdl1090/view1090.REMOVED.git-id @@ -1 +1 @@ -d5ebf86bb1a0e40d3ca3749d31c89c02dbc12fc6 \ No newline at end of file +6d9c5442d0ddf630e47b4e32c4f9ea2b5ebf4d91 \ No newline at end of file