all map and drawing is now c++

Former-commit-id: ae9ea92b06a7782e3f12bcf7ebfc6979c7c28cbd
Former-commit-id: 2e197fa5c161f7b44779120e9af25f911e7511bf
This commit is contained in:
nathan 2020-03-18 22:22:59 -07:00
parent 1c75fbc4d8
commit 0a014bdd99
18 changed files with 903 additions and 926 deletions

View file

@ -1,11 +1,11 @@
#include "AircraftData.h"
#include "AppData.h"
//
//carried over from view1090.c
//
int AircraftData::setupConnection(struct client *c) {
int AppData::setupConnection(struct client *c) {
int fd;
// Try to connect to the selected ip address and port. We only support *ONE* input connection which we initiate.here.
@ -37,7 +37,7 @@ int AircraftData::setupConnection(struct client *c) {
//
void AircraftData::initialize() {
void AppData::initialize() {
// Allocate the various buffers used by Modes
if ( NULL == (modes.icao_cache = (uint32_t *) malloc(sizeof(uint32_t) * MODES_ICAO_CACHE_LEN * 2)))
{
@ -53,7 +53,7 @@ void AircraftData::initialize() {
}
void AircraftData::connect() {
void AppData::connect() {
// Try to connect to the selected ip address and port. We only support *ONE* input connection which we initiate.here.
c = (struct client *) malloc(sizeof(*c));
while(1) {
@ -68,13 +68,13 @@ void AircraftData::connect() {
}
void AircraftData::disconnect() {
void AppData::disconnect() {
if (fd != ANET_ERR)
{close(fd);}
}
void AircraftData::update() {
void AppData::update() {
if ((fd == ANET_ERR) || (recv(c->fd, pk_buf, sizeof(pk_buf), MSG_PEEK | MSG_DONTWAIT) == 0)) {
free(c);
usleep(1000000);
@ -87,9 +87,51 @@ void AircraftData::update() {
interactiveRemoveStaleAircrafts(&modes);
aircraftList.update(&modes);
//this can probably be collapsed into somethingelse, came from status.c
updateStatus();
}
AircraftData::AircraftData(){
void AppData::updateStatus() {
// struct aircraft *a = Modes.aircrafts;
numVisiblePlanes = 0;
maxDist = 0;
totalCount = 0;
sigAccumulate = 0.0;
msgRateAccumulate = 0.0;
// PlaneObj *p = appData.planes;
// while(p) {
// unsigned char * pSig = p->signalLevel;
// unsigned int signalAverage = (pSig[0] + pSig[1] + pSig[2] + pSig[3] +
// pSig[4] + pSig[5] + pSig[6] + pSig[7]);
// sigAccumulate += signalAverage;
// if (p->lon && p->lat) {
// numVisiblePlanes++;
// }
// totalCount++;
// msgRateAccumulate += p->messageRate;
// p = p->next;
// }
// Status.msgRate = msgRateAccumulate;
// Status.avgSig = sigAccumulate / (double) totalCount;
// Status.numPlanes = totalCount;
// Status.numVisiblePlanes = numVisiblePlanes;
// Status.maxDist = maxDist;
}
AppData::AppData(){
// Default everything to zero/NULL
memset(&modes, 0, sizeof(Modes));
@ -105,27 +147,4 @@ AircraftData::AircraftData(){
modes.interactive = 0;
modes.quiet = 1;
// Map options
appData.maxDist = 25.0;
appData.centerLon = modes.fUserLon;
appData.centerLat = modes.fUserLat;
// Display options
appData.screen_uiscale = 1;
appData.screen_width = 0;
appData.screen_height = 0;
appData.screen_depth = 32;
appData.fullscreen = 0;
appData.screen_index = 0;
// Initialize status
Status.msgRate = 0;
Status.avgSig = 0;
Status.numPlanes = 0;
Status.numVisiblePlanes = 0;
Status.maxDist = 0;
selectedAircraft = NULL;
}

View file

@ -1,5 +1,5 @@
#ifndef AIRCRAFTDATA_H
#define AIRCRAFTDATA_H
#ifndef APPDATA_H
#define APPDATA_H
#include "dump1090.h"
#include "view1090.h"
@ -7,7 +7,7 @@
#include "AircraftList.h"
class AircraftData {
class AppData {
private:
//from view1090.c
@ -24,13 +24,19 @@ class AircraftData {
void connect();
void disconnect();
void update();
AircraftData();
void updateStatus();
AppData();
AircraftList aircraftList;
Aircraft *selectedAircraft;
Modes modes;
char server[32];
int numVisiblePlanes;
double maxDist;
int totalCount;
double sigAccumulate;
double msgRateAccumulate;
};
#endif

View file

@ -1,4 +1,3 @@
#include "structs.h"
#include "view1090.h"
#include "Input.h"
@ -43,78 +42,76 @@ void Input::getInput()
break;
case SDL_MOUSEWHEEL:
appData.maxDist *= 1.0 + 0.5 * sgn(event.wheel.y);
if(appData.maxDist < 0.001f) {
appData.maxDist = 0.001f;
view->maxDist *= 1.0 + 0.5 * sgn(event.wheel.y);
if(view->maxDist < 0.001f) {
view->maxDist = 0.001f;
}
appData.mapTargetMaxDist = 0;
appData.mapMoved = 1;
view->mapTargetMaxDist = 0;
view->mapMoved = 1;
break;
case SDL_MULTIGESTURE:
appData.maxDist /=1.0 + 4.0*event.mgesture.dDist;
appData.mapTargetMaxDist = 0;
appData.mapMoved = 1;
view->maxDist /=1.0 + 4.0*event.mgesture.dDist;
view->mapTargetMaxDist = 0;
view->mapMoved = 1;
break;
case SDL_FINGERMOTION:;
appData.isDragging = 1;
view->moveCenterRelative( appData.screen_width * event.tfinger.dx, appData.screen_height * event.tfinger.dy);
isDragging = 1;
view->moveCenterRelative( view->screen_width * event.tfinger.dx, view->screen_height * event.tfinger.dy);
break;
case SDL_FINGERDOWN:
if(mstime() - appData.touchDownTime > 500) {
appData.tapCount = 0;
if(mstime() - touchDownTime > 500) {
tapCount = 0;
}
appData.touchDownTime = mstime();
touchDownTime = mstime();
break;
case SDL_FINGERUP:
if(mstime() - appData.touchDownTime < 120) {
appData.touchx = appData.screen_width * event.tfinger.x;
appData.touchy = appData.screen_height * event.tfinger.y;
appData.tapCount++;
appData.isDragging = 0;
view->registerClick();
if(isDragging) {
isDragging = 0;
} else if(mstime() - touchDownTime < 120) {
touchx = view->screen_width * event.tfinger.x;
touchy = view->screen_height * event.tfinger.y;
tapCount++;
view->registerClick(tapCount, touchx, touchy);
} else {
appData.touchx = 0;
appData.touchy = 0;
appData.tapCount = 0;
touchx = 0;
touchy = 0;
tapCount = 0;
}
break;
case SDL_MOUSEBUTTONDOWN:
if(event.button.which != SDL_TOUCH_MOUSEID) {
if(mstime() - appData.touchDownTime > 500) {
appData.tapCount = 0;
if(mstime() - touchDownTime > 500) {
tapCount = 0;
}
appData.touchDownTime = mstime();
touchDownTime = mstime();
}
break;
case SDL_MOUSEBUTTONUP:;
if(event.button.which != SDL_TOUCH_MOUSEID) {
appData.touchx = event.motion.x;
appData.touchy = event.motion.y;
appData.tapCount = event.button.clicks;
appData.isDragging = 0;
touchx = event.motion.x;
touchy = event.motion.y;
tapCount = event.button.clicks;
isDragging = 0;
view->registerClick();
view->registerClick(tapCount, touchx, touchy);
}
break;
case SDL_MOUSEMOTION:;
if(event.motion.which != SDL_TOUCH_MOUSEID) {
appData.mouseMovedTime = mstime();
appData.mousex = event.motion.x;
appData.mousey = event.motion.y;
view->registerMouseMove(event.motion.x, event.motion.y);
if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
appData.isDragging = 1;
isDragging = 1;
view->moveCenterRelative(event.motion.xrel, event.motion.yrel);
}
}
@ -123,6 +120,17 @@ void Input::getInput()
}
}
Input::Input(View *view) {
Input::Input(AppData *appData, View *view) {
this->view = view;
this->appData = appData;
isDragging = 0;
}

11
Input.h
View file

@ -1,7 +1,7 @@
#ifndef INPUT_H
#define INPUT_H
#include "AircraftData.h"
#include "AppData.h"
#include "View.h"
class Input {
@ -9,9 +9,16 @@ public:
void getInput();
//should input know about view?
Input(View *view);
Input(AppData *appData, View *view);
View *view;
AppData *appData;
uint64_t touchDownTime;
int touchx;
int touchy;
int tapCount;
int isDragging;
};
#endif

View file

@ -12,8 +12,8 @@ all: map1090
%.o: %.c %.cpp
$(CC) $(CFLAGS) $(EXTRACFLAGS) -c $<
map1090: map1090.o AircraftData.o AircraftList.o Aircraft.o anet.o interactive.o mode_ac.o mode_s.o net_io.o Input.o View.o font.o init.o mapdata.o status.o parula.o monokai.o
$(CC) -g -o map1090 map1090.o AircraftData.o AircraftList.o Aircraft.o anet.o interactive.o mode_ac.o mode_s.o net_io.o Input.o View.o font.o init.o mapdata.o status.o parula.o monokai.o $(LIBS) $(LDFLAGS)
map1090: map1090.o AppData.o AircraftList.o Aircraft.o anet.o interactive.o mode_ac.o mode_s.o net_io.o Input.o View.o Map.o parula.o monokai.o
$(CC) -g -o map1090 map1090.o AppData.o AircraftList.o Aircraft.o anet.o interactive.o mode_ac.o mode_s.o net_io.o Input.o View.o Map.o parula.o monokai.o $(LIBS) $(LDFLAGS)
clean:
rm -f *.o map1090

View file

@ -1,38 +1,8 @@
#include "dump1090.h"
#include "mapdata.h"
#include "structs.h"
#include <stdbool.h>
#include "Map.h"
#include <stdio.h>
#include <cstdlib>
int mapPoints_count;
float *mapPoints;
void initQuadTree(QuadTree *tree) {
if(tree == NULL) {
return;
}
tree->polygons = NULL;
tree->nw = NULL;
tree->ne = NULL;
tree->sw = NULL;
tree->se = NULL;
}
void initPolygon(Polygon *currentPolygon) {
if(currentPolygon == NULL) {
return;
}
currentPolygon->lat_min = 180.0;
currentPolygon->lon_min = 180.0;
currentPolygon->lat_max = -180.0;
currentPolygon->lon_max = -180.0;
currentPolygon->numPoints = 0;
currentPolygon->points = NULL;
currentPolygon->next = NULL;
}
bool QTInsert(QuadTree *tree, Polygon* polygon) {
bool Map::QTInsert(QuadTree *tree, Polygon *polygon) {
// printf("Inserting %d point poly\n", polygon->numPoints);
if (!(polygon->lat_min >= tree->lat_min &&
@ -45,8 +15,7 @@ bool QTInsert(QuadTree *tree, Polygon* polygon) {
}
if (tree->nw == NULL) {
tree->nw = (QuadTree*)malloc(sizeof(QuadTree));
initQuadTree(tree->nw);
tree->nw = new QuadTree;
tree->nw->lat_min = tree->lat_min;
tree->nw->lat_max = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min);
@ -59,8 +28,7 @@ bool QTInsert(QuadTree *tree, Polygon* polygon) {
}
if (tree->sw == NULL) {
tree->sw = (QuadTree*)malloc(sizeof(QuadTree));
initQuadTree(tree->sw);
tree->sw = new QuadTree;
tree->sw->lat_min = tree->lat_min;
tree->sw->lat_max = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min);
@ -73,8 +41,7 @@ bool QTInsert(QuadTree *tree, Polygon* polygon) {
}
if (tree->ne == NULL) {
tree->ne = (QuadTree*)malloc(sizeof(QuadTree));
initQuadTree(tree->ne);
tree->ne = new QuadTree;
tree->ne->lat_min = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min);
tree->ne->lat_max = tree->lat_max;
@ -87,8 +54,7 @@ bool QTInsert(QuadTree *tree, Polygon* polygon) {
}
if (tree->se == NULL) {
tree->se = (QuadTree*)malloc(sizeof(QuadTree));
initQuadTree(tree->se);
tree->se = new QuadTree;
tree->se->lat_min = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min);
tree->se->lat_max = tree->lat_max;
@ -100,13 +66,50 @@ bool QTInsert(QuadTree *tree, Polygon* polygon) {
return true;
}
polygon->next = tree->polygons;
tree->polygons = polygon;
tree->polygons.push_back(*polygon);
return true;
}
void initMaps() {
std::list<Polygon> Map::getPolysRecursive(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max) {
std::list<Polygon> retPolys;
if(tree == NULL) {
return retPolys;
}
if (tree->lat_min > screen_lat_max || screen_lat_min > tree->lat_max) {
return retPolys;
}
if (tree->lon_min > screen_lon_max || screen_lon_min > tree->lon_max) {
return retPolys;
}
retPolys.splice(retPolys.end(),getPolysRecursive(tree->nw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max));
retPolys.splice(retPolys.end(),getPolysRecursive(tree->sw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max));
retPolys.splice(retPolys.end(),getPolysRecursive(tree->ne, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max));
retPolys.splice(retPolys.end(),getPolysRecursive(tree->se, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max));
float dx, dy;
std::list<Polygon>::iterator currentPolygon;
for (currentPolygon = tree->polygons.begin(); currentPolygon != tree->polygons.end(); ++currentPolygon) {
if(currentPolygon->points.empty()) {
continue;
}
retPolys.push_back(*currentPolygon);
}
}
std::list<Polygon> Map::getPolys(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max) {
return getPolysRecursive(&root, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
};
Map::Map() {
FILE *fileptr;
if(!(fileptr = fopen("mapdata.bin", "rb"))) {
@ -130,48 +133,36 @@ void initMaps() {
// load quad tree
appData.root.lat_min = 180;
appData.root.lon_min = 180;
appData.root.lat_max = -180;
appData.root.lon_max = -180;
appData.root.nw = NULL;
appData.root.ne = NULL;
appData.root.sw = NULL;
appData.root.se = NULL;
for(int i = 0; i < mapPoints_count; i+=2) {
if(mapPoints[i] == 0)
continue;
if(mapPoints[i] < appData.root.lon_min) {
appData.root.lon_min = mapPoints[i];
} else if(mapPoints[i] > appData.root.lon_max) {
appData.root.lon_max = mapPoints[i];
if(mapPoints[i] < root.lon_min) {
root.lon_min = mapPoints[i];
} else if(mapPoints[i] > root.lon_max) {
root.lon_max = mapPoints[i];
}
if(mapPoints[i+1] < appData.root.lat_min) {
appData.root.lat_min = mapPoints[i+1];
} else if(mapPoints[i+1] > appData.root.lat_max) {
appData.root.lat_max = mapPoints[i+1];
if(mapPoints[i+1] < root.lat_min) {
root.lat_min = mapPoints[i+1];
} else if(mapPoints[i+1] > root.lat_max) {
root.lat_max = mapPoints[i+1];
}
}
Polygon *currentPolygon = (Polygon*)malloc(sizeof(Polygon));
initPolygon(currentPolygon);
Polygon *currentPolygon = new Polygon;
for(int i = 0; i < mapPoints_count; i+=2) {
if(mapPoints[i] == 0) {
QTInsert(&appData.root, currentPolygon);
currentPolygon = (Polygon*)malloc(sizeof(Polygon));
initPolygon(currentPolygon);
QTInsert(&root, currentPolygon);
currentPolygon = new Polygon;
continue;
}
currentPolygon->numPoints++;
Point *currentPoint = (Point*)malloc(sizeof(Point));
Point *currentPoint = new Point;
if(mapPoints[i] < currentPolygon->lon_min) {
currentPolygon->lon_min = mapPoints[i];
@ -188,7 +179,6 @@ void initMaps() {
currentPoint->lon = mapPoints[i];
currentPoint->lat = mapPoints[i+1];
currentPoint->next = currentPolygon->points;
currentPolygon->points = currentPoint;
currentPolygon->points.push_back(*currentPoint);
}
}

87
Map.h Normal file
View file

@ -0,0 +1,87 @@
#ifndef MAP_H
#define MAP_H
#include <list>
typedef struct Point{
float lat;
float lon;
} Point;
typedef struct Polygon{
float lat_min;
float lat_max;
float lon_min;
float lon_max;
std::list<Point> points;
int numPoints;
Polygon() {
lat_min = 180.0f;
lon_min = 180.0f;
lat_max = -180.0f;
lon_max = -180.0f;
numPoints = 0;
}
} Polygon;
typedef struct QuadTree{
float lat_min;
float lat_max;
float lon_min;
float lon_max;
std::list<Polygon> polygons;
struct QuadTree *nw;
struct QuadTree *sw;
struct QuadTree *ne;
struct QuadTree *se;
QuadTree() {
lat_min = 180.0f;
lon_min = 180.0f;
lat_max = -180.0f;
lon_max = -180.0f;
nw = NULL;
sw = NULL;
ne = NULL;
se = NULL;
}
~QuadTree() {
if(nw != NULL) {
delete nw;
}
if(sw != NULL) {
delete nw;
}
if(ne != NULL) {
delete nw;
}
if(ne != NULL) {
delete nw;
}
}
} QuadTree;
class Map {
public:
QuadTree root;
bool QTInsert(QuadTree *tree, Polygon *polygon);
std::list<Polygon> getPolysRecursive(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max);
std::list<Polygon> getPolys(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max);
Map();
int mapPoints_count;
float *mapPoints;
};
#endif

775
View.cpp

File diff suppressed because it is too large Load diff

79
View.h
View file

@ -1,12 +1,33 @@
#ifndef VIEW_H
#define VIEW_H
#include "AircraftData.h"
#include "AppData.h"
#include "Map.h"
#include "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h"
class View {
AircraftData *aircraftData;
private:
AppData *appData;
//for cursor drawing
uint64_t mouseMovedTime;
int mousex;
int mousey;
uint64_t clickTime;
int clickx;
int clicky;
TTF_Font* loadFont(char *name, int size);
void closeFont(TTF_Font *font);
void drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color);
void drawStringBG(char * text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor);
void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color color);
void drawStatus();
Aircraft *selectedAircraft;
public:
int screenDist(float d);
void pxFromLonLat(float *dx, float *dy, float lon, float lat);
@ -17,7 +38,7 @@ public:
void drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor);
void drawTrail(Aircraft *p);
void drawScaleBars();
void drawPolys(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max);
void drawPolys(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max);
void drawGeography();
void drawSignalMarks(Aircraft *p, int x, int y);
void drawPlaneText(Aircraft *p);
@ -30,12 +51,60 @@ public:
void zoomMapToTarget();
void moveMapToTarget();
void drawMouse();
void registerClick();
void drawClick();
void registerClick(int tapcount, int x, int y);
void registerMouseMove(int x, int y);
void draw();
View(AircraftData *aircraftData);
void SDL_init();
void font_init();
View(AppData *appData);
~View();
////////////////
bool metric;
float maxDist;
float centerLon;
float centerLat;
float mapTargetMaxDist;
float mapTargetLat;
float mapTargetLon;
int mapMoved;
uint64_t lastFrameTime;
Map map;
int screen_upscale;
int screen_uiscale;
int screen_width;
int screen_height;
int screen_depth;
int fullscreen;
int screen_index;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *mapTexture;
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;
int messageFontHeight;
};
#endif

1
defs.h
View file

@ -4,7 +4,6 @@
#include <unistd.h>
#include "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h"
#include "mapdata.h"
#define ROUND_RADIUS 3 //radius of text box corners

83
font.c
View file

@ -1,83 +0,0 @@
#include "structs.h"
#include "SDL2/SDL2_rotozoom.h"
TTF_Font *loadFont(char *name, int size)
{
TTF_Font *font = TTF_OpenFont(name, size);
if (font == NULL)
{
printf("Failed to open Font %s: %s\n", name, TTF_GetError());
exit(1);
}
return font;
}
void closeFont(TTF_Font *font)
{
if (font != NULL)
{
TTF_CloseFont(font);
}
}
void drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color)
{
if(!strlen(text)) {
return;
}
SDL_Surface *surface;
SDL_Rect dest;
surface = TTF_RenderUTF8_Solid(font, text, color);
if (surface == NULL)
{
printf("Couldn't create String %s: %s\n", text, SDL_GetError());
return;
}
dest.x = x;
dest.y = y;
dest.w = surface->w;
dest.h = surface->h;
SDL_Texture *texture = SDL_CreateTextureFromSurface(appData.renderer, surface);
SDL_RenderCopy(appData.renderer, texture, NULL, &dest);
SDL_DestroyTexture(texture);
SDL_FreeSurface(surface);
}
void drawStringBG(char * text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor) {
if(!strlen(text)) {
return;
}
SDL_Surface *surface;
SDL_Rect dest;
surface = TTF_RenderUTF8_Shaded(font, text, color, bgColor);
if (surface == NULL)
{
printf("Couldn't create String %s: %s\n", text, SDL_GetError());
return;
}
/* Blit the entire surface to the screen */
dest.x = x;
dest.y = y;
dest.w = surface->w;
dest.h = surface->h;
SDL_Texture *texture = SDL_CreateTextureFromSurface(appData.renderer, surface);
SDL_RenderCopy(appData.renderer, texture, NULL, &dest);
SDL_DestroyTexture(texture);
SDL_FreeSurface(surface);
}

102
init.c
View file

@ -1,102 +0,0 @@
#include "dump1090.h"
#include "structs.h"
#include "monokai.h"
void init(char *title) {
// raspberry pi compiler flag enables these options
#ifdef RPI
putenv((char*)"FRAMEBUFFER=/dev/fb1");
putenv((char*)"SDL_FBDEV=/dev/fb1");
#endif
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("Could not initialize SDL: %s\n", SDL_GetError());
exit(1);
}
if (TTF_Init() < 0) {
printf("Couldn't initialize SDL TTF: %s\n", SDL_GetError());
exit(1);
}
SDL_ShowCursor(SDL_DISABLE);
Uint32 flags = 0;
if(appData.fullscreen) {
flags = flags | SDL_WINDOW_FULLSCREEN_DESKTOP;
}
if(appData.screen_width == 0) {
SDL_DisplayMode DM;
SDL_GetCurrentDisplayMode(0, &DM);
appData.screen_width = DM.w;
appData.screen_height= DM.h;
}
appData.window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED_DISPLAY(appData.screen_index), SDL_WINDOWPOS_CENTERED_DISPLAY(appData.screen_index), appData.screen_width, appData.screen_height, flags);
appData.renderer = SDL_CreateRenderer(appData.window, -1, SDL_RENDERER_ACCELERATED);
appData.mapTexture = SDL_CreateTexture(appData.renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_TARGET,
appData.screen_width, appData.screen_height);
appData.mapMoved = 1;
appData.mapTargetLon = 0;
appData.mapTargetLat = 0;
appData.mapTargetMaxDist = 0;
appData.isDragging = 0;
if(appData.fullscreen) {
//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); // make the scaled rendering look smoother.
SDL_RenderSetLogicalSize(appData.renderer, appData.screen_width, appData.screen_height);
}
appData.mapFont = loadFont("font/TerminusTTF-4.46.0.ttf", 12 * appData.screen_uiscale);
appData.mapBoldFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 12 * appData.screen_uiscale);
appData.listFont = loadFont("font/TerminusTTF-4.46.0.ttf", 12 * appData.screen_uiscale);
appData.messageFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 12 * appData.screen_uiscale);
appData.labelFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 12 * appData.screen_uiscale);
appData.mapFontWidth = 5 * appData.screen_uiscale;
appData.mapFontHeight = 12 * appData.screen_uiscale;
appData.messageFontWidth = 6 * appData.screen_uiscale;
appData.messageFontHeight = 12 * appData.screen_uiscale;
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();
}
void cleanup() {
closeFont(appData.mapFont);
closeFont(appData.mapBoldFont);
closeFont(appData.messageFont);
closeFont(appData.labelFont);
closeFont(appData.listFont);
TTF_Quit();
SDL_Quit();
}

View file

@ -1 +1 @@
e54bd400ee152072ad6cade80bc74402d03db46c
eddfb25457316beaa3ba58e14e88f2e187c4acaf

View file

@ -30,7 +30,7 @@
#include "view1090.h"
#include "structs.h"
#include "AircraftData.h"
#include "AppData.h"
#include "View.h"
#include "Input.h"
@ -80,42 +80,43 @@ void showHelp(void) {
//=========================================================================
//
int main(int argc, char **argv) {
int j;
AircraftData aircraftData;
View view(&aircraftData);
Input input(&view);
AppData appData;
View view(&appData);
Input input(&appData,&view);
signal(SIGINT, SIG_DFL); // reset signal handler - bit extra safety
aircraftData.initialize();
appData.initialize();
// Parse the command line options
for (j = 1; j < argc; j++) {
int more = ((j + 1) < argc); // There are more arguments
if (!strcmp(argv[j],"--port") && more) {
aircraftData.modes.net_input_beast_port = atoi(argv[++j]);
appData.modes.net_input_beast_port = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--server") && more) {
std::strcpy(aircraftData.server, argv[++j]);
std::strcpy(appData.server, argv[++j]);
} else if (!strcmp(argv[j],"--lat") && more) {
aircraftData.modes.fUserLat = atof(argv[++j]);
appData.centerLat = aircraftData.modes.fUserLat;
appData.modes.fUserLat = atof(argv[++j]);
view.centerLat = appData.modes.fUserLat;
} else if (!strcmp(argv[j],"--lon") && more) {
aircraftData.modes.fUserLon = atof(argv[++j]);
appData.centerLon = aircraftData.modes.fUserLon;
appData.modes.fUserLon = atof(argv[++j]);
view.centerLon = appData.modes.fUserLon;
} else if (!strcmp(argv[j],"--metric")) {
aircraftData.modes.metric = 1;
view.metric = 1;
} else if (!strcmp(argv[j],"--fullscreen")) {
appData.fullscreen = 1;
view.fullscreen = 1;
} else if (!strcmp(argv[j],"--screenindex")) {
appData.screen_index = atoi(argv[++j]);
view.screen_index = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--uiscale") && more) {
appData.screen_uiscale = atoi(argv[++j]);
view.screen_uiscale = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--screensize") && more) {
appData.screen_width = atoi(argv[++j]);
appData.screen_height = atoi(argv[++j]);
view.screen_width = atoi(argv[++j]);
view.screen_height = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--help")) {
showHelp();
exit(0);
@ -128,22 +129,22 @@ int main(int argc, char **argv) {
int go;
aircraftData.connect();
appData.connect();
init("sdl1090");
atexit(cleanup);
view.SDL_init();
view.font_init();
go = 1;
while (go == 1)
{
input.getInput();
aircraftData.update();
appData.update();
view.draw();
}
aircraftData.disconnect();
appData.disconnect();
return (0);
}

View file

@ -1,36 +0,0 @@
#ifndef MAPPOINTS_H
#define MAPPOINTS_H
typedef struct Point{
float lat;
float lon;
struct Point *next;
} Point;
typedef struct Polygon{
float lat_min;
float lat_max;
float lon_min;
float lon_max;
Point *points;
int numPoints;
struct Polygon *next;
} Polygon;
typedef struct QuadTree{
float lat_min;
float lat_max;
float lon_min;
float lon_max;
Polygon *polygons;
struct QuadTree *nw;
struct QuadTree *sw;
struct QuadTree *ne;
struct QuadTree *se;
} QuadTree;
#endif

152
status.c
View file

@ -1,152 +0,0 @@
#include "dump1090.h"
#include "structs.h"
#include "parula.h"
#include "monokai.h"
#include "SDL2/SDL2_gfxPrimitives.h"
void updateStatus() {
// struct aircraft *a = Modes.aircrafts;
int numVisiblePlanes = 0;
double maxDist = 0;
int totalCount = 0;
double sigAccumulate = 0.0;
double msgRateAccumulate = 0.0;
// PlaneObj *p = appData.planes;
// while(p) {
// unsigned char * pSig = p->signalLevel;
// unsigned int signalAverage = (pSig[0] + pSig[1] + pSig[2] + pSig[3] +
// pSig[4] + pSig[5] + pSig[6] + pSig[7]);
// sigAccumulate += signalAverage;
// if (p->lon && p->lat) {
// numVisiblePlanes++;
// }
// totalCount++;
// msgRateAccumulate += p->messageRate;
// p = p->next;
// }
Status.msgRate = msgRateAccumulate;
Status.avgSig = sigAccumulate / (double) totalCount;
Status.numPlanes = totalCount;
Status.numVisiblePlanes = numVisiblePlanes;
Status.maxDist = maxDist;
}
void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color color) {
int labelWidth = (strlen(label) + ((strlen(label) > 0 ) ? 1 : 0)) * appData.labelFontWidth;
int messageWidth = (strlen(message) + ((strlen(message) > 0 ) ? 1 : 0)) * appData.messageFontWidth;
if(*left + labelWidth + messageWidth + PAD > appData.screen_width) {
*left = PAD;
*top = *top - appData.messageFontHeight - PAD;
}
// filled black background
if(messageWidth) {
roundedBoxRGBA(appData.renderer, *left, *top, *left + labelWidth + messageWidth, *top + appData.messageFontHeight, ROUND_RADIUS, black.r, black.g, black.b, SDL_ALPHA_OPAQUE);
}
// filled label box
if(labelWidth) {
roundedBoxRGBA(appData.renderer, *left, *top, *left + labelWidth, *top + appData.messageFontHeight, ROUND_RADIUS,color.r, color.g, color.b, SDL_ALPHA_OPAQUE);
}
// outline message box
if(messageWidth) {
roundedRectangleRGBA(appData.renderer, *left, *top, *left + labelWidth + messageWidth, *top + appData.messageFontHeight, ROUND_RADIUS,color.r, color.g, color.b, SDL_ALPHA_OPAQUE);
}
drawString(label, *left + appData.labelFontWidth/2, *top, appData.labelFont, black);
//message
drawString(message, *left + labelWidth + appData.messageFontWidth/2, *top, appData.messageFont, color);
*left = *left + labelWidth + messageWidth + PAD;
}
void drawButtonBox(int *left, int *top, char *label, SDL_Color color) {
int labelWidth = (strlen(label) + ((strlen(label) > 0 ) ? 1 : 0)) * appData.labelFontWidth;
//newline if no message or label
if(strlen(label) == 0) {
boxRGBA(appData.renderer, *left, *top, appData.screen_width - PAD, *top + appData.messageFontHeight,0, 0, 0, 0);
*left = PAD;
*top = *top - appData.messageFontHeight - PAD;
return;
}
if(*left + labelWidth + PAD > appData.screen_width) {
*left = PAD;
*top = *top - appData.messageFontHeight - PAD;
}
// outline message box
if(labelWidth) {
roundedRectangleRGBA(appData.renderer, *left, *top , *left + labelWidth - 1, *top + appData.messageFontHeight - 1, ROUND_RADIUS, 255, 255, 255, SDL_ALPHA_OPAQUE);
roundedRectangleRGBA(appData.renderer, *left + 1, *top + 1, *left + labelWidth , *top + appData.messageFontHeight, ROUND_RADIUS, 20, 20, 20, SDL_ALPHA_OPAQUE);
roundedBoxRGBA(appData.renderer, *left + 1, *top + 1, *left + labelWidth - 1, *top + appData.messageFontHeight - 1, ROUND_RADIUS, color.r, color.g, color.b, SDL_ALPHA_OPAQUE);
}
drawString(label, *left + appData.labelFontWidth/2, *top, appData.labelFont, black);
*left = *left + labelWidth + 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(appData.renderer,
*left + appData.messageFontWidth * xList[k],
*top + appData.messageFontHeight * yList[k],
*left + appData.messageFontWidth * xList[k+1],
*top + appData.messageFontHeight * yList[k+1],
lineWidth, grey.r, grey.g, grey.b, SDL_ALPHA_OPAQUE);
}
boxRGBA(appData.renderer, *left, *top + (0.2 + 0.8 * (1.0 - level)) * appData.messageFontHeight, *left + appData.messageFontWidth, *top + appData.messageFontHeight, grey.r, grey.g, grey.b, SDL_ALPHA_OPAQUE);
*left = *left + appData.messageFontWidth;
}
void drawStatus() {
int left = PAD;
int top = appData.screen_height - appData.messageFontHeight - PAD;
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, style.buttonColor);
char strPlaneCount[10] = " ";
snprintf(strPlaneCount, 10,"%d/%d", Status.numVisiblePlanes, Status.numPlanes);
drawStatusBox(&left, &top, "disp", strPlaneCount, style.buttonColor);
char strMsgRate[18] = " ";
snprintf(strMsgRate, 18,"%.0f/s", Status.msgRate);
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, style.buttonColor);
}

View file

@ -3,67 +3,7 @@
#include "defs.h"
#include "AircraftData.h"
typedef struct AppData
{
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *mapTexture;
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;
int messageFontHeight;
// map options
float maxDist;
//display options
int screen_upscale;
int screen_uiscale;
int screen_width;
int screen_height;
int screen_depth;
int fullscreen;
int screen_index;
float centerLon;
float centerLat;
uint64_t touchDownTime;
int touchx;
int touchy;
int tapCount;
int isDragging;
uint64_t mouseMovedTime;
int mousex;
int mousey;
float mapTargetMaxDist;
float mapTargetLat;
float mapTargetLon;
int mapMoved;
QuadTree root;
//PlaneObj *planes;
//PlaneObj *selectedPlane;
uint64_t lastFrameTime;
} AppData;
// #include "AircraftData.h"
struct {
@ -89,7 +29,7 @@ typedef struct Style {
} Style;
// globals
extern AppData appData;
//extern AppData appData;
extern Style style;
// functions
@ -97,24 +37,6 @@ extern Style style;
extern "C" {
#endif
//font.c
TTF_Font *loadFont(char *, int);
void closeFont(TTF_Font *);
void drawString(char *, int, int, TTF_Font *, SDL_Color);
void drawString90(char *, int, int, TTF_Font *, SDL_Color);
void drawStringBG(char *, int, int, TTF_Font *, SDL_Color, SDL_Color);
//init.c
void init(char *);
void cleanup(void);
//mapdata.c
void initMaps();
//list.c
void drawList(int top);
//status.c
void updateStatus();
void drawStatus();

View file

@ -1 +0,0 @@
56c0107a5f8eb9b1a33224437cf439396118c999