fixed heading, added heading history, switched list mode to overlay (in progress)

Former-commit-id: 0f107d8c372c5a2540f04b315ec9f947ff496fd1
Former-commit-id: 68382a78fc5e92438b70877a3f4497b3404498e9
This commit is contained in:
nathan 2019-09-08 14:29:21 -05:00
parent 4acb3633e8
commit 0507fc179b
34 changed files with 145 additions and 50 deletions

View file

@ -18,4 +18,6 @@
#define AA 0 #define AA 0
#define MAGMA 0 #define MAGMA 0
#define ROUND_RADIUS 3

View file

@ -26,11 +26,10 @@ void draw() {
SDL_RenderClear(game.renderer); SDL_RenderClear(game.renderer);
if (Modes.map) { drawMap();
drawMap(); drawStatus();
drawStatus(); if(!Modes.map) {
} else { drawList(0);
drawList(10,0);
} }
SDL_RenderPresent(game.renderer); SDL_RenderPresent(game.renderer);

View file

@ -230,7 +230,7 @@ struct aircraft {
uint64_t even_cprtime; uint64_t even_cprtime;
double lat, lon; // Coordinated obtained from CPR encoded data double lat, lon; // Coordinated obtained from CPR encoded data
double dx, dy; // distance in km double dx, dy; // distance in km
double oldDx[MODES_INTERACTIVE_TRAIL_LENGTH], oldDy[MODES_INTERACTIVE_TRAIL_LENGTH]; // position history double oldDx[MODES_INTERACTIVE_TRAIL_LENGTH], oldDy[MODES_INTERACTIVE_TRAIL_LENGTH], oldHeading[MODES_INTERACTIVE_TRAIL_LENGTH]; // position history
time_t oldSeen[MODES_INTERACTIVE_TRAIL_LENGTH];// position time time_t oldSeen[MODES_INTERACTIVE_TRAIL_LENGTH];// position time
uint8_t oldIdx; // index for ring buffer uint8_t oldIdx; // index for ring buffer
uint64_t created; uint64_t created;

View file

@ -0,0 +1 @@
091001c845fa041bb58677bdb97edc546a43b72d

View file

@ -0,0 +1 @@
248a001641f39a4ad8b75387b889698120fd4983

View file

@ -0,0 +1 @@
130bb4a9cecd7210769427502b3ee33cdb097341

View file

@ -0,0 +1 @@
2a1ec89b5722143dfbdee504bbddab3a48b7bdd6

View file

@ -0,0 +1 @@
672aac709f31f3596fe66420cbc409122c8cb706

View file

@ -0,0 +1 @@
f20e8486e0becccceddade23c1f89d5336aebc49

View file

@ -0,0 +1 @@
11cbae78cf937af2f5c0236b8f86cad443162a2f

View file

@ -0,0 +1 @@
e8aa21e61df3e92fb290abc35215afdfe9a6db0a

View file

@ -0,0 +1 @@
bca6a642079482aab1d8d68488c6302c9e0e284d

View file

@ -0,0 +1 @@
5aeb931af933ee4dd2557a465ecadf908dc53978

View file

@ -0,0 +1 @@
22983e3d94e5c6e9c3f85f2bb6aff805b31657d0

View file

@ -0,0 +1 @@
66c93d8a95903ec73a80ea4f49811d23525ed967

View file

@ -0,0 +1 @@
d07ca5d41b3a257274f42c5fe0b402a672ea612a

View file

@ -0,0 +1 @@
db3b7b20ab68a2010a29158ad5a86a1fff1f86e5

View file

@ -0,0 +1 @@
6963c72346edf4b03a76271242ca933ac9afb750

View file

@ -0,0 +1 @@
0368d2bbae0b02dfeeb66950db2f79109714756e

View file

@ -0,0 +1 @@
f159709859ade068ba25e93720a5c8abc2fd20ce

View file

@ -0,0 +1 @@
53c606887962f52031d77dd4fe9c1ce85ce0783e

View file

@ -0,0 +1 @@
e52ba0d0e32c0a8a9de183dc11352f59c754c764

View file

@ -0,0 +1 @@
f279c6703790767cc5efae5941913527c039cb0b

View file

@ -0,0 +1 @@
653a1008f0ee073bafcd84e21bddd930e03579b1

View file

@ -0,0 +1 @@
d206e1de86a19ab735257abba83e25bd1d296ebb

View file

@ -0,0 +1 @@
9fe3e4aecd84c498563c3af03fe7050924915f60

View file

@ -56,7 +56,7 @@ void init(char *title) {
game.mapFont = loadFont("font/TerminusTTF-4.46.0.ttf", 12 * Modes.screen_uiscale); game.mapFont = loadFont("font/TerminusTTF-4.46.0.ttf", 12 * Modes.screen_uiscale);
game.mapBoldFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 12 * Modes.screen_uiscale); game.mapBoldFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 12 * Modes.screen_uiscale);
game.listFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 18 * Modes.screen_uiscale); game.listFont = loadFont("font/TerminusTTF-4.46.0.ttf", 12 * Modes.screen_uiscale);
game.messageFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 12 * Modes.screen_uiscale); game.messageFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 12 * Modes.screen_uiscale);
game.labelFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 12 * Modes.screen_uiscale); game.labelFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 12 * Modes.screen_uiscale);

View file

@ -67,11 +67,11 @@ void getInput()
// //
// need to make lonlat to screen conversion class - this is just the inverse of the stuff in draw.c, without offsets // need to make lonlat to screen conversion class - this is just the inverse of the stuff in draw.c, without offsets
// //
double scale_factor = (Modes.screen_width > Modes.screen_height) ? Modes.screen_width : Modes.screen_height; double scale_factor = (Modes.screen_width > Modes.screen_height) ? Modes.screen_width : Modes.screen_height;
double dx = -1.0 * (0.75*(double)Modes.screen_width / (double)Modes.screen_height) * Modes.screen_width * event.tfinger.dx * Modes.maxDist / (0.95 * scale_factor * 0.5); double dx = -1.0 * (0.75*(double)Modes.screen_width / (double)Modes.screen_height) * Modes.screen_width * event.tfinger.dx * Modes.maxDist / (0.95 * scale_factor * 0.5);
double dy = -1.0 * Modes.screen_height * event.tfinger.dy * Modes.maxDist / (0.95 * scale_factor * 0.5); double dy = 1.0 * Modes.screen_height * event.tfinger.dy * Modes.maxDist / (0.95 * scale_factor * 0.5);
double outLat = dy * (1.0/6371.0) * (180.0f / M_PI); double outLat = dy * (1.0/6371.0) * (180.0f / M_PI);

View file

@ -144,6 +144,7 @@ struct aircraft *interactiveCreateAircraft(struct modesMessage *mm) {
a->oldIdx = 0; a->oldIdx = 0;
memset(a->oldDx, 0, sizeof(a->oldDx)); memset(a->oldDx, 0, sizeof(a->oldDx));
memset(a->oldDy, 0, sizeof(a->oldDy)); memset(a->oldDy, 0, sizeof(a->oldDy));
memset(a->oldHeading, 0, sizeof(a->oldHeading));
memset(a->signalLevel, mm->signalLevel, 8); // First time, initialise everything memset(a->signalLevel, mm->signalLevel, 8); // First time, initialise everything
// to the first signal strength // to the first signal strength
@ -411,6 +412,8 @@ struct aircraft *interactiveReceiveData(struct modesMessage *mm) {
a->oldDx[a->oldIdx] = a->dx; a->oldDx[a->oldIdx] = a->dx;
a->oldDy[a->oldIdx] = a->dy; a->oldDy[a->oldIdx] = a->dy;
a->oldHeading[a->oldIdx] = a->track;
a->oldSeen[a->oldIdx] = a->seen; a->oldSeen[a->oldIdx] = a->seen;
} }
} }

View file

@ -4,7 +4,7 @@
#include "monokai.h" #include "monokai.h"
#include "SDL2/SDL2_gfxPrimitives.h" #include "SDL2/SDL2_gfxPrimitives.h"
void drawList(int rows, int top) { void drawList(int top) {
struct aircraft *a = Modes.aircrafts; struct aircraft *a = Modes.aircrafts;
time_t now = time(NULL); time_t now = time(NULL);
int count = 0; int count = 0;
@ -13,7 +13,9 @@ void drawList(int rows, int top) {
progress = spinner[time(NULL)%4]; progress = spinner[time(NULL)%4];
drawStringBG(" Flight Alt(m) km/h D(km) H S ", 0, top, game.listFont, black, white); drawStringBG(" Flight Alt(m) km/h D(km) H S ", 0, top, game.mapBoldFont, black, (SDL_Color){255,255,255,64});
top = top + game.mapFontHeight;
// int xstride = 10; // int xstride = 10;
// for(int i = 0; i < 320 / xstride; i++) { // for(int i = 0; i < 320 / xstride; i++) {
@ -26,7 +28,12 @@ void drawList(int rows, int top) {
// } // }
int numNoDir = 0; int numNoDir = 0;
while(a && (count < rows)) { while(a) {
if(top > Modes.screen_height) {
return;
}
if ((now - a->seen) < Modes.interactive_display_ttl) if ((now - a->seen) < Modes.interactive_display_ttl)
{ {
int msgs = a->messages; int msgs = a->messages;
@ -123,25 +130,18 @@ void drawList(int rows, int top) {
if ((now - a->seen) > 30 ) { if ((now - a->seen) > 30 ) {
drawString(a->flight, 0, top + (count + 1) * 20, game.listFont, (SDL_Color){96,96,96,255}); drawString(a->flight, 0, top, game.listFont, (SDL_Color){96,96,96,255});
// printf("\x1B[1;30m%-8s%5s %4s %5s %c%c %d",
// a->flight,
// strFl,
// strGs,
// strD,
// cLat, cLon,
// (int)((float)signalAverage/25.0f));
} else { } else {
drawString(a->flight, 10, top + (count + 1) * 20, game.listFont, pink); drawString(a->flight, 10, top, game.listFont, pink);
drawString(strFl, 90, top + (count + 1) * 20, game.listFont, orange); drawString(strFl, 90, top, game.listFont, orange);
drawString(strGs, 160, top + (count + 1) * 20, game.listFont, green); drawString(strGs, 160, top, game.listFont, green);
drawString(strD, 210, top + (count + 1) * 20, game.listFont, blue); drawString(strD, 210, top, game.listFont, blue);
drawString(strDir, 270, top + (count + 1) * 20, game.listFont, yellow); drawString(strDir, 270, top, game.listFont, yellow);
// drawString(strS, 290, (count + 1) * 20, game.listFont, (SDL_Color){255,9,96,255}); // drawString(strS, 290, (count + 1) * 20, game.listFont, (SDL_Color){255,9,96,255});
@ -153,6 +153,7 @@ void drawList(int rows, int top) {
// cLat, cLon, // cLat, cLon,
// (int)((float)signalAverage/25.0f)); // (int)((float)signalAverage/25.0f));
} }
top = top + game.mapFontHeight;
count++; count++;
} else { } else {
numNoDir++; numNoDir++;

View file

@ -78,7 +78,7 @@ void pxFromLonLat(double *dx, double *dy, double lon, double lat) {
void screenCoords(int *outX, int *outY, double dx, double dy) { void screenCoords(int *outX, int *outY, double dx, double dy) {
*outX = (Modes.screen_width>>1) + ((dx>0) ? 1 : -1) * screenDist(dx); *outX = (Modes.screen_width>>1) + ((dx>0) ? 1 : -1) * screenDist(dx);
*outY = (Modes.screen_height * CENTEROFFSET) + ((dy>0) ? 1 : -1) * screenDist(dy); *outY = (Modes.screen_height * CENTEROFFSET) + ((dy>0) ? -1 : 1) * screenDist(dy);
} }
int outOfBounds(int x, int y) { int outOfBounds(int x, int y) {
@ -156,7 +156,7 @@ void drawPlaneHeading(int x, int y, double heading, SDL_Color planeColor)
double vec[3]; double vec[3];
vec[0] = sin(heading * M_PI / 180); vec[0] = sin(heading * M_PI / 180);
vec[1] = cos(heading * M_PI / 180); vec[1] = -cos(heading * M_PI / 180);
vec[2] = 0; vec[2] = 0;
double up[] = {0,0,1}; double up[] = {0,0,1};
@ -221,7 +221,7 @@ void drawPlane(int x, int y, SDL_Color planeColor)
} }
void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) { void drawTrail(double *oldDx, double *oldDy, double *oldHeading, time_t * oldSeen, int idx) {
int currentIdx, prevIdx; int currentIdx, prevIdx;
@ -273,8 +273,42 @@ void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) {
aalineRGBA(game.renderer, prevX, prevY, currentX, currentY,colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE); aalineRGBA(game.renderer, prevX, prevY, currentX, currentY,colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE);
} else { } else {
//thickLineRGBA(game.renderer, prevX, prevY, currentX, currentY, 2, colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE); //thickLineRGBA(game.renderer, prevX, prevY, currentX, currentY, 2, colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE);
thickLineRGBA(game.renderer, prevX, prevY, currentX, currentY, 2 * Modes.screen_uiscale, colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE); thickLineRGBA(game.renderer, prevX, prevY, currentX, currentY, 4 * Modes.screen_uiscale, colorVal, colorVal, colorVal, 127);
} }
//tick marks
double vec[3];
vec[0] = sin(oldHeading[currentIdx] * M_PI / 180);
vec[1] = -cos(oldHeading[currentIdx] * M_PI / 180);
vec[2] = 0;
double up[] = {0,0,1};
double out[3];
CROSSVP(out,vec,up);
int x1, y1, x2, y2;
int cross_size = 8 * Modes.screen_uiscale;
//forward cross
x1 = currentX + round(-cross_size*vec[0]);
y1 = currentY + round(-cross_size*vec[1]);
x2 = currentX + round(cross_size*vec[0]);
y2 = currentY + round(cross_size*vec[1]);
lineRGBA(game.renderer,x1,y1,x2,y2,colorVal,colorVal,colorVal,127);
//side cross
x1 = currentX + round(-cross_size*out[0]);
y1 = currentY + round(-cross_size*out[1]);
x2 = currentX + round(cross_size*out[0]);
y2 = currentY + round(cross_size*out[1]);
lineRGBA(game.renderer,x1,y1,x2,y2,colorVal,colorVal,colorVal,127);
} }
} }
@ -284,8 +318,8 @@ void drawGrid()
int p10km = screenDist(10.0); int p10km = screenDist(10.0);
int p100km = screenDist(100.0); int p100km = screenDist(100.0);
hlineRGBA (game.renderer, (Modes.screen_width>>1) - p100km, (Modes.screen_width>>1) + p100km, Modes.screen_height * CENTEROFFSET, grey.r, grey.g, grey.b, SDL_ALPHA_OPAQUE); //hlineRGBA (game.renderer, (Modes.screen_width>>1) - p100km, (Modes.screen_width>>1) + p100km, Modes.screen_height * CENTEROFFSET, grey.r, grey.g, grey.b, SDL_ALPHA_OPAQUE);
vlineRGBA (game.renderer, Modes.screen_width>>1, (Modes.screen_height * CENTEROFFSET) - p100km, (Modes.screen_height * CENTEROFFSET) + p100km, grey.r, grey.g, grey.b, SDL_ALPHA_OPAQUE); //vlineRGBA (game.renderer, Modes.screen_width>>1, (Modes.screen_height * CENTEROFFSET) - p100km, (Modes.screen_height * CENTEROFFSET) + p100km, grey.r, grey.g, grey.b, SDL_ALPHA_OPAQUE);
if(AA) { if(AA) {
aacircleRGBA (game.renderer, Modes.screen_width>>1, Modes.screen_height>>1, p1km, pink.r, pink.g, pink.b, 255); aacircleRGBA (game.renderer, Modes.screen_width>>1, Modes.screen_height>>1, p1km, pink.r, pink.g, pink.b, 255);
@ -368,7 +402,7 @@ void drawMap(void) {
drawGeography(); drawGeography();
//drawGrid(); drawGrid();
while(a) { while(a) {
if ((now - a->seen) < Modes.interactive_display_ttl) { if ((now - a->seen) < Modes.interactive_display_ttl) {
@ -378,7 +412,7 @@ void drawMap(void) {
unsigned int signalAverage = (pSig[0] + pSig[1] + pSig[2] + pSig[3] + unsigned int signalAverage = (pSig[0] + pSig[1] + pSig[2] + pSig[3] +
pSig[4] + pSig[5] + pSig[6] + pSig[7] + 3) >> 3; pSig[4] + pSig[5] + pSig[6] + pSig[7] + 3) >> 3;
drawTrail(a->oldDx, a->oldDy, a->oldSeen, a->oldIdx); drawTrail(a->oldDx, a->oldDy, a->oldHeading, a->oldSeen, a->oldIdx);
int colorIdx; int colorIdx;
if((int)(now - a->seen) > MODES_INTERACTIVE_DISPLAY_ACTIVE) { if((int)(now - a->seen) > MODES_INTERACTIVE_DISPLAY_ACTIVE) {

View file

@ -87,17 +87,17 @@ void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color co
// filled black background // filled black background
if(messageWidth) { if(messageWidth) {
boxRGBA(game.renderer, *left, *top, *left + labelWidth + messageWidth, *top + game.messageFontHeight, black.r, black.g, black.b, SDL_ALPHA_OPAQUE); roundedBoxRGBA(game.renderer, *left, *top, *left + labelWidth + messageWidth, *top + game.messageFontHeight, ROUND_RADIUS, black.r, black.g, black.b, SDL_ALPHA_OPAQUE);
} }
// filled label box // filled label box
if(labelWidth) { if(labelWidth) {
boxRGBA(game.renderer, *left, *top, *left + labelWidth, *top + game.messageFontHeight, color.r, color.g, color.b, SDL_ALPHA_OPAQUE); roundedBoxRGBA(game.renderer, *left, *top, *left + labelWidth, *top + game.messageFontHeight, ROUND_RADIUS,color.r, color.g, color.b, SDL_ALPHA_OPAQUE);
} }
// outline message box // outline message box
if(messageWidth) { if(messageWidth) {
rectangleRGBA(game.renderer, *left, *top, *left + labelWidth + messageWidth, *top + game.messageFontHeight, color.r, color.g, color.b, SDL_ALPHA_OPAQUE); roundedRectangleRGBA(game.renderer, *left, *top, *left + labelWidth + messageWidth, *top + game.messageFontHeight, ROUND_RADIUS,color.r, color.g, color.b, SDL_ALPHA_OPAQUE);
} }
// label // label
@ -112,6 +112,39 @@ void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color co
} }
void drawButtonBox(int *left, int *top, char *label, SDL_Color color) {
int labelWidth = (strlen(label) + ((strlen(label) > 0 ) ? 1 : 0)) * game.labelFontWidth;
//newline if no message or label
if(strlen(label) == 0) {
boxRGBA(game.renderer, *left, *top, Modes.screen_width - PAD, *top + game.messageFontHeight,0, 0, 0, 0);
*left = PAD;
*top = *top - game.messageFontHeight - PAD;
return;
}
if(*left + labelWidth + PAD > Modes.screen_width) {
*left = PAD;
*top = *top - game.messageFontHeight - PAD;
}
// outline message box
if(labelWidth) {
roundedRectangleRGBA(game.renderer, *left, *top , *left + labelWidth - 1, *top + game.messageFontHeight - 1, ROUND_RADIUS, 255, 255, 255, SDL_ALPHA_OPAQUE);
roundedRectangleRGBA(game.renderer, *left + 1, *top + 1, *left + labelWidth , *top + game.messageFontHeight, ROUND_RADIUS, 20, 20, 20, SDL_ALPHA_OPAQUE);
roundedBoxRGBA(game.renderer, *left + 1, *top + 1, *left + labelWidth - 1, *top + game.messageFontHeight - 1, ROUND_RADIUS, color.r, color.g, color.b, SDL_ALPHA_OPAQUE);
}
drawString(label, *left + game.labelFontWidth/2, *top, game.labelFont, black);
*left = *left + labelWidth + PAD;
}
void drawBattery(int *left, int *top, double level) { void drawBattery(int *left, int *top, double level) {
int lineWidth = 1; int lineWidth = 1;
@ -135,8 +168,8 @@ void drawBattery(int *left, int *top, double level) {
void drawStatus() { void drawStatus() {
int left = PAD; int left = PAD + 2 * game.messageFontHeight ;
int top = Modes.screen_height - game.messageFontHeight - PAD; int top = Modes.screen_height - 2 * game.messageFontHeight - PAD;
char strLoc[20] = " "; char strLoc[20] = " ";
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');
@ -162,12 +195,12 @@ void drawStatus() {
// drawStatusBox(&left, &top, "||||", "MENU", grey); // drawStatusBox(&left, &top, "||||", "MENU", grey);
if(Status.closeCall != NULL) { // if(Status.closeCall != NULL) {
drawStatusBox(&left, &top, "", "", black); //this is effectively a newline // drawStatusBox(&left, &top, "", "", black); //this is effectively a newline
if(strlen(Status.closeCall->flight)) { // if(strlen(Status.closeCall->flight)) {
drawStatusBox(&left, &top, "near", Status.closeCall->flight, white); // drawStatusBox(&left, &top, "near", Status.closeCall->flight, white);
} else { // } else {
drawStatusBox(&left, &top, "near", "", white); // drawStatusBox(&left, &top, "near", "", white);
} // }
} // }
} }

View file

@ -46,7 +46,7 @@ void getInput(void);
void initMaps(); void initMaps();
//list.c //list.c
void drawList(int rows, int top); void drawList(int top);
//draw.c //draw.c
void draw(); void draw();

View file

@ -1 +1 @@
2056de76ba9dff16057865185ffa2eb99617235e 03ce37e44e1175c6d216ace0dc15712026569f3f