labeling updates, placeholder battery indicator

Former-commit-id: bff0f6c851c23cab84690fb0fa599f7a14718ed4
Former-commit-id: 9b81f580a60bde5b9279591b6f1818d574dae5f8
This commit is contained in:
Nathan 2017-10-10 15:56:05 -05:00
parent c87d2b8c13
commit 314a210201
7 changed files with 93 additions and 58 deletions

View file

@ -14,6 +14,7 @@
#define SCREEN_HEIGHT 480 #define SCREEN_HEIGHT 480
#define UPSCALE 1 #define UPSCALE 1
#define SCALE 1
#define LOGMAXDIST 1000.0 #define LOGMAXDIST 1000.0
#define MAXDIST 50.0 #define MAXDIST 50.0

View file

@ -25,7 +25,6 @@ void init(char *title)
putenv((char*)"SDL_FBDEV=/dev/fb1"); putenv((char*)"SDL_FBDEV=/dev/fb1");
#endif #endif
mouseSetup();
/* Initialise SDL */ /* Initialise SDL */
@ -75,21 +74,26 @@ void init(char *title)
exit(1); exit(1);
} }
mouseSetup();
/* Load the font */ /* 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.messageFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 34 * SCALE);
game.labelFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 16); game.labelFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 16 * SCALE);
game.mapFontWidth = 5 * SCALE;
game.mapFontHeight = 12 * SCALE;
game.messageFontWidth = 17; game.messageFontWidth = 17 * SCALE;
game.messageFontHeight = 34; game.messageFontHeight = 34 * SCALE;
game.labelFontWidth = 5; game.labelFontWidth = 5 * SCALE;
game.labelFontHeight = 10; game.labelFontHeight = 10 * SCALE;
/* Set the screen title */ /* Set the screen title */
@ -102,8 +106,12 @@ void cleanup()
{ {
/* Close the font */ /* Close the font */
closeFont(game.font); closeFont(game.mapFont);
closeFont(game.mapBoldFont);
closeFont(game.messageFont);
closeFont(game.labelFont);
closeFont(game.listFont);
/* Close SDL_TTF */ /* Close SDL_TTF */
TTF_Quit(); TTF_Quit();

View file

@ -299,6 +299,11 @@ struct aircraft *interactiveReceiveData(struct modesMessage *mm) {
a->prev_seen = a->seen; 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->signalLevel[a->messages & 7] = mm->signalLevel;// replace the 8th oldest signal strength
a->seen = time(NULL); a->seen = time(NULL);
a->timestamp = mm->timestampMsg; a->timestamp = mm->timestampMsg;

View file

@ -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)) { if(outOfBounds(x,y)) {
return; return;
} }
SDL_Color planeColor = signalToColor(signal); double body = 8.0 * SCALE;
double wing = 6.0 * SCALE;
double body = 8.0; double tail = 3.0 * SCALE;
double wing = 6.0; double bodyWidth = 2.0 * SCALE;
double tail = 3.0;
double vec[3]; double vec[3];
vec[0] = sin(heading * M_PI / 180); 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); 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); aacircleRGBA(game.screen, x2,y2,1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
} else { } 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); 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 //wing
@ -134,22 +130,14 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl
} else { } 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); 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)) { if(outOfBounds(x,y)) {
return; return;
} }
SDL_Color planeColor = signalToColor(signal);
int length = 3.0; int length = 3.0;
rectangleRGBA (game.screen, x - length, y - length, x+length, y + length, planeColor.r, planeColor.g, planeColor.b, SDL_ALPHA_OPAQUE); 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); aalineRGBA(game.screen, prevX, prevY, currentX, currentY,colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE);
} else { } 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, 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); 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("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.font, 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.font, pink); drawString("100km", (Modes.screen_width>>1) + (0.707 * p100km) + 5, (Modes.screen_height * CENTEROFFSET) + (0.707 * p100km) + 5, game.mapFont, pink);
} }
void drawGeography() { void drawGeography() {
@ -255,7 +243,7 @@ void drawGeography() {
if(AA) { if(AA) {
aalineRGBA(game.screen, x1, y1, x2, y2,purple.r,purple.g,purple.b, (alpha < 0) ? 0 : (uint8_t) alpha); aalineRGBA(game.screen, x1, y1, x2, y2,purple.r,purple.g,purple.b, (alpha < 0) ? 0 : (uint8_t) alpha);
} else { } 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; colorIdx = signalAverage;
} }
SDL_Color planeColor = signalToColor(colorIdx);
int x, y;
screenCoords(&x, &y, a->dx, a->dy);
if(MODES_ACFLAGS_HEADING_VALID) { 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 { } else {
drawPlane(a->dx, a->dy, colorIdx); drawPlane(x, y, planeColor);
} }
} }
} }

View file

@ -108,6 +108,28 @@ void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color co
*left = *left + labelWidth + messageWidth + PAD; *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() { void drawStatus() {
int left = PAD; 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'); snprintf(strLoc, 20, "%3.3fN %3.3f%c", Modes.fUserLat, fabs(Modes.fUserLon),(Modes.fUserLon > 0) ? 'E' : 'W');
drawStatusBox(&left, &top, "GPS", strLoc, pink); drawStatusBox(&left, &top, "GPS", strLoc, pink);
drawBattery(&left, &top, 0.85);
char strPlaneCount[10] = " "; char strPlaneCount[10] = " ";
snprintf(strPlaneCount, 10,"%d/%d", Status.numVisiblePlanes, Status.numPlanes); snprintf(strPlaneCount, 10,"%d/%d", Status.numVisiblePlanes, Status.numPlanes);
drawStatusBox(&left, &top, "disp", strPlaneCount, yellow); drawStatusBox(&left, &top, "disp", strPlaneCount, yellow);
@ -136,24 +160,11 @@ void drawStatus() {
drawStatusBox(&left, &top, "||||", "MENU", grey); drawStatusBox(&left, &top, "||||", "MENU", grey);
if(Status.closeCall != NULL) { if(Status.closeCall != NULL) {
// if no flight id, "near" box goes on first line drawStatusBox(&left, &top, "", "", black); //this is effectively a newline
if(!strlen(Status.closeCall->flight)) { if(strlen(Status.closeCall->flight)) {
drawStatusBox(&left, &top, "near", "", red); drawStatusBox(&left, &top, "near", Status.closeCall->flight, white);
} } else {
drawStatusBox(&left, &top, "near", "", white);
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);
} }
} }
} }

View file

@ -8,12 +8,15 @@ typedef struct Game
SDL_Surface *screen; SDL_Surface *screen;
SDL_Surface *bigScreen; SDL_Surface *bigScreen;
TTF_Font *font; TTF_Font *mapFont;
TTF_Font *mapBoldFont;
TTF_Font *listFont; TTF_Font *listFont;
TTF_Font *messageFont; TTF_Font *messageFont;
TTF_Font *labelFont; TTF_Font *labelFont;
int mapFontWidth;
int mapFontHeight;
int labelFontWidth; int labelFontWidth;
int labelFontHeight; int labelFontHeight;
int messageFontWidth; int messageFontWidth;

View file

@ -1 +1 @@
d5ebf86bb1a0e40d3ca3749d31c89c02dbc12fc6 6d9c5442d0ddf630e47b4e32c4f9ea2b5ebf4d91