diff --git a/defs.h b/defs.h index f89b6f1..abdf5b9 100644 --- a/defs.h +++ b/defs.h @@ -6,11 +6,6 @@ #include "SDL2/SDL_ttf.h" #include "mapdata.h" -#define SCREEN_WIDTH 320 -#define SCREEN_HEIGHT 480 - -#define UISCALE 1 - #define ROUND_RADIUS 3 //radius of text box corners #define CENTEROFFSET .375 //vertical offset for middle of screen @@ -20,4 +15,6 @@ #define DISPLAY_ACTIVE 30 #define TRAIL_TTL_STEP 2 -#define FRAMETIME 33 \ No newline at end of file +#define FRAMETIME 33 + +#define PAD 5 diff --git a/draw.c b/draw.c index f0aaf92..bebe530 100644 --- a/draw.c +++ b/draw.c @@ -48,6 +48,64 @@ SDL_Color signalToColor(int signal) { return planeColor; } +SDL_Color hsv2SDLColor(double h, double s, double v) +{ + double hh, p, q, t, ff; + long i; + SDL_Color out; + + if(s <= 0.0) { // < is bogus, just shuts up warnings + out.r = (uint8_t)v; + out.g = (uint8_t)v; + out.b = (uint8_t)v; + return out; + } + hh = h; + if(hh >= 360.0) hh = 0.0; + hh /= 60.0; + i = (long)hh; + ff = hh - i; + p = v * (1.0 - s); + q = v * (1.0 - (s * ff)); + t = v * (1.0 - (s * (1.0 - ff))); + + switch(i) { + case 0: + out.r = (uint8_t)v; + out.g = (uint8_t)t; + out.b = (uint8_t)p; + break; + case 1: + out.r = (uint8_t)q; + out.g = (uint8_t)v; + out.b = (uint8_t)p; + break; + case 2: + out.r = (uint8_t)p; + out.g = (uint8_t)v; + out.b = (uint8_t)t; + break; + + case 3: + out.r = (uint8_t)p; + out.g = (uint8_t)q; + out.b = (uint8_t)v; + break; + case 4: + out.r = (uint8_t)t; + out.g = (uint8_t)p; + out.b = (uint8_t)v; + break; + case 5: + default: + out.r = (uint8_t)v; + out.g = (uint8_t)p; + out.b = (uint8_t)q; + break; + } + return out; +} + int screenDist(double d) { double scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height; @@ -276,7 +334,7 @@ void drawTrail(double *oldDx, double *oldDy, double *oldHeading, time_t * oldSee x2 = currentX + round(cross_size*vec[0]); y2 = currentY + round(cross_size*vec[1]); - lineRGBA(appData.renderer,x1,y1,x2,y2,colorVal,colorVal,colorVal,127); + thickLineRGBA(appData.renderer,x1,y1,x2,y2,appData.screen_uiscale,colorVal,colorVal,colorVal,127); //side cross x1 = currentX + round(-cross_size*out[0]); @@ -284,7 +342,7 @@ void drawTrail(double *oldDx, double *oldDy, double *oldHeading, time_t * oldSee x2 = currentX + round(cross_size*out[0]); y2 = currentY + round(cross_size*out[1]); - lineRGBA(appData.renderer,x1,y1,x2,y2,colorVal,colorVal,colorVal,127); + thickLineRGBA(appData.renderer,x1,y1,x2,y2,appData.screen_uiscale,colorVal,colorVal,colorVal,127); } } @@ -306,11 +364,32 @@ void drawGrid() void drawGeography() { int x1, y1, x2, y2; - for(int i=1; imsSeen) / 4.0); - circleRGBA(appData.renderer, x, y - 5, 2 * appData.screen_uiscale, barColor.r, barColor.g, barColor.b, seenFade); + circleRGBA(appData.renderer, x + appData.mapFontWidth, y - 5, 2 * appData.screen_uiscale, barColor.r, barColor.g, barColor.b, seenFade); seenFade = (Uint8) (255.0 - (mstime() - p->msSeenLatLon) / 4.0); - hlineRGBA(appData.renderer, x + 5 * appData.screen_uiscale, x + 9 * appData.screen_uiscale, y - 5, barColor.r, barColor.g, barColor.b, seenFade); - vlineRGBA(appData.renderer, x + 7 * appData.screen_uiscale, y - 2 * appData.screen_uiscale - 5, y + 2 * appData.screen_uiscale - 5, barColor.r, barColor.g, barColor.b, seenFade); + hlineRGBA(appData.renderer, x + appData.mapFontWidth + 5 * appData.screen_uiscale, x + appData.mapFontWidth + 9 * appData.screen_uiscale, y - 5, barColor.r, barColor.g, barColor.b, seenFade); + vlineRGBA(appData.renderer, x + appData.mapFontWidth + 7 * appData.screen_uiscale, y - 2 * appData.screen_uiscale - 5, y + 2 * appData.screen_uiscale - 5, barColor.r, barColor.g, barColor.b, seenFade); } void drawPlaneText(struct planeObj *p) { - - drawSignalMarks(p, p->x, p->y); - - int maxCharCount; + int maxCharCount = 0; int currentCharCount; int currentLine = 0; - char flight[10] = " "; - maxCharCount = snprintf(flight,10,"%s", p->flight); + if(p->pressure * appData.screen_width< 0.4f) { + drawSignalMarks(p, p->x, p->y); + + char flight[10] = " "; + maxCharCount = snprintf(flight,10," %s", p->flight); + + if(maxCharCount > 0) { + drawStringBG(flight, p->x, p->y, appData.mapBoldFont, white, black); + //roundedRectangleRGBA(appData.renderer, p->x, p->y, p->x + maxCharCount * appData.mapFontWidth, p->y + appData.mapFontHeight, ROUND_RADIUS, white.r, white.g, white.b, SDL_ALPHA_OPAQUE); + //drawString(flight, p->x, p->y, appData.mapBoldFont, white); + currentLine++; + } + } + + if(p->pressure * appData.screen_width < 0.2f) { + char alt[10] = " "; + if (Modes.metric) { + currentCharCount = snprintf(alt,10," %dm", (int) (p->altitude / 3.2828)); + } else { + currentCharCount = snprintf(alt,10," %d'", p->altitude); + } + + if(currentCharCount > 0) { + drawStringBG(alt, p->x, p->y + currentLine * appData.mapFontHeight, appData.mapFont, grey, black); + currentLine++; + } + + if(currentCharCount > maxCharCount) { + maxCharCount = currentCharCount; + } + + char speed[10] = " "; + if (Modes.metric) { + currentCharCount = snprintf(speed,10," %dkm/h", (int) (p->speed * 1.852)); + } else { + currentCharCount = snprintf(speed,10," %dmph", p->speed); + } + + if(currentCharCount > 0) { + drawStringBG(speed, p->x, p->y + currentLine * appData.mapFontHeight, appData.mapFont, grey, black); + currentLine++; + } + + if(currentCharCount > maxCharCount) { + maxCharCount = currentCharCount; + } + } if(maxCharCount > 0) { - drawStringBG(flight, p->x, p->y, appData.mapBoldFont, white, black); - currentLine++; + + Sint16 vx[4] = {p->cx, p->cx + (p->x - p->cx) / 2, p->x, p->x}; + Sint16 vy[4] = {p->cy, p->cy + (p->y - p->cy) / 2, p->y - appData.mapFontHeight, p->y}; + + if(p->cy > p->y + currentLine * appData.mapFontHeight) { + vy[2] = p->y + currentLine * appData.mapFontHeight + appData.mapFontHeight; + vy[3] = p->y + currentLine * appData.mapFontHeight; + } + + bezierRGBA(appData.renderer,vx,vy,4,2,200,200,200,SDL_ALPHA_OPAQUE); + + + thickLineRGBA(appData.renderer,p->x,p->y,p->x,p->y+currentLine*appData.mapFontHeight,appData.screen_uiscale,200,200,200,SDL_ALPHA_OPAQUE); } - - char alt[10] = " "; - if (Modes.metric) { - currentCharCount = snprintf(alt,10,"%dm", (int) (p->altitude / 3.2828)); - } else { - currentCharCount = snprintf(alt,10,"%d'", p->altitude); - } - - if(currentCharCount > 0) { - drawStringBG(alt, p->x, p->y + currentLine * appData.mapFontHeight, appData.mapFont, grey, black); - currentLine++; - } - - if(currentCharCount > maxCharCount) { - maxCharCount = currentCharCount; - } - - char speed[10] = " "; - if (Modes.metric) { - currentCharCount = snprintf(speed,10,"%dkm/h", (int) (p->speed * 1.852)); - } else { - currentCharCount = snprintf(speed,10,"%dmph", p->speed); - } - - if(currentCharCount > 0) { - drawStringBG(speed, p->x, p->y + currentLine * appData.mapFontHeight, appData.mapFont, grey, black); - currentLine++; - } - - if(currentCharCount > maxCharCount) { - maxCharCount = currentCharCount; - } - + p->w = maxCharCount * appData.mapFontWidth; p->h = currentLine * appData.mapFontHeight; } @@ -444,12 +544,12 @@ void resolveLabelConflicts() { //apply damping - p->ddox -= 0.7f * p->dox; - p->ddoy -= 0.7f * p->doy; + p->ddox -= 0.07f * p->dox; + p->ddoy -= 0.07f * p->doy; //spring back to origin - p->ddox -= 0.05f * p->ox; - p->ddoy -= 0.05f * p->oy; + p->ddox -= 0.005f * p->ox; + p->ddoy -= 0.005f * p->oy; // // //screen edge @@ -469,9 +569,10 @@ void resolveLabelConflicts() { p->oy -= (float)(p_bottom - (appData.screen_height - 10 * appData.screen_uiscale)); } + p->pressure = 0; + //check against other labels - while(check_p) { if(check_p->addr != p->addr) { @@ -480,6 +581,10 @@ void resolveLabelConflicts() { int check_top = check_p->y - 5 * appData.screen_uiscale; int check_bottom = check_p->y + check_p->h + 5 * appData.screen_uiscale; + + p->pressure += 1.0f / ((check_p->cx - p->cx) * (check_p->cx - p->cx) + (check_p->cy - p->cy) * (check_p->cy - p->cy)); + + //if(check_left > (p_right + 10) || check_right < (p_left - 10)) { if(check_left > p_right || check_right < p_left) { check_p = check_p -> next; @@ -494,23 +599,23 @@ void resolveLabelConflicts() { //left collision if(check_left > p_left && check_left < p_right) { - check_p->ddox -= 0.1f * (float)(check_left - p_right); + check_p->ddox -= 0.01f * (float)(check_left - p_right); } //right collision if(check_right > p_left && check_right < p_right) { - check_p->ddox -= 0.1f * (float)(check_right - p_left); + check_p->ddox -= 0.01f * (float)(check_right - p_left); } //top collision if(check_top > p_top && check_top < p_bottom) { - check_p->ddoy -= 0.1f * (float)(check_top - p_bottom); + check_p->ddoy -= 0.01f * (float)(check_top - p_bottom); } //bottom collision if(check_bottom > p_top && check_bottom < p_bottom) { - check_p->ddoy -= 0.1f * (float)(check_bottom - p_top); - } + check_p->ddoy -= 0.01f * (float)(check_bottom - p_top); + } } check_p = check_p -> next; } @@ -543,22 +648,22 @@ void resolveLabelConflicts() { //left collision if(check_left > p_left && check_left < p_right) { - check_p->ddox -= 0.1f * (float)(check_left - p_right); + check_p->ddox -= 0.04f * (float)(check_left - p_right); } //right collision if(check_right > p_left && check_right < p_right) { - check_p->ddox -= 0.1f * (float)(check_right - p_left); + check_p->ddox -= 0.04f * (float)(check_right - p_left); } //top collision if(check_top > p_top && check_top < p_bottom) { - check_p->ddoy -= 0.1f * (float)(check_top - p_bottom); + check_p->ddoy -= 0.04f * (float)(check_top - p_bottom); } //bottom collision if(check_bottom > p_top && check_bottom < p_bottom) { - check_p->ddoy -= 0.1f * (float)(check_bottom - p_top); + check_p->ddoy -= 0.04f * (float)(check_bottom - p_top); } check_p = check_p -> next; @@ -617,9 +722,9 @@ void drawMap() { drawGrid(); - //for(int i = 0; i < 2; i++) { + for(int i = 0; i < 4; i++) { resolveLabelConflicts(); - //} + } //draw all trails first so they don't cover up planes and text @@ -648,6 +753,10 @@ void drawMap() { planeColor = grey; } else { planeColor = white; + //srand(p->addr); + // planeColor = hsv2SDLColor(255.0 * (double)rand()/(double)RAND_MAX, 255.0, 200.0); + //planeColor = signalToColor((int)(255.0f * (float)rand()/(float)RAND_MAX)); + //fprintf("%d %d %d\n", planeColor.r, planeColor.g, planeColor.b); } if(p->created == 0) { @@ -679,17 +788,17 @@ void drawMap() { if(outOfBounds(x,y)) { drawPlaneOffMap(x, y, &(p->cx), &(p->cy), planeColor); - thickLineRGBA(appData.renderer, p->cx, p->cy, p->x+(p->w>>2), p->y, appData.screen_uiscale, 200,200,200,SDL_ALPHA_OPAQUE); + + //lineRGBA(appData.renderer, p->cx, p->cy, p->x+(p->w/2), p->y, 200,200,200,SDL_ALPHA_OPAQUE); + } else { drawPlaneHeading(usex, usey, p->track, planeColor); p->cx = usex;// + 5; p->cy = usey;// + 10 * appData.screen_uiscale; - - if(p->cx != 0 && p->cy != 0 && p->x != 0 && p->y != 0) { - - thickLineRGBA(appData.renderer, usex, usey, p->x+(p->w>>2), p->y, appData.screen_uiscale, 200,200,200, SDL_ALPHA_OPAQUE); - } + + //lineRGBA(appData.renderer, usex, usey, p->x+(p->w/2), p->y, 200,200,200, SDL_ALPHA_OPAQUE); + } diff --git a/draw.o.REMOVED.git-id b/draw.o.REMOVED.git-id index 8d1d3a5..7c1526e 100644 --- a/draw.o.REMOVED.git-id +++ b/draw.o.REMOVED.git-id @@ -1 +1 @@ -a17d06a73e34e6e65d1ff9ed411da79667154ca6 \ No newline at end of file +5bec8587fd94772a4061e38543ad9846ffb0fc11 \ No newline at end of file diff --git a/font.o b/font.o index 120e521..1b9094e 100644 Binary files a/font.o and b/font.o differ diff --git a/init.c b/init.c index 0ad39f3..46d5643 100644 --- a/init.c +++ b/init.c @@ -27,6 +27,13 @@ void init(char *title) { 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_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, appData.screen_width, appData.screen_height, flags); appData.renderer = SDL_CreateRenderer(appData.window, -1, 0); appData.texture = SDL_CreateTexture(appData.renderer, @@ -35,7 +42,7 @@ void init(char *title) { appData.screen_width, appData.screen_height); if(appData.fullscreen) { - //SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); // make the scaled rendering look smoother. + //\SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); // make the scaled rendering look smoother. SDL_RenderSetLogicalSize(appData.renderer, appData.screen_width, appData.screen_height); } diff --git a/init.o b/init.o index c075893..60eada6 100644 Binary files a/init.o and b/init.o differ diff --git a/input.o.REMOVED.git-id b/input.o.REMOVED.git-id index 8dccc44..5a96a3c 100644 --- a/input.o.REMOVED.git-id +++ b/input.o.REMOVED.git-id @@ -1 +1 @@ -2305764a62eb8dd80a5f71e908a04bfaa9bc3cc9 \ No newline at end of file +b7c0644a5ba34c2548772d880bce685146ce9e95 \ No newline at end of file diff --git a/list.o b/list.o index cdfa683..a8039d4 100644 Binary files a/list.o and b/list.o differ diff --git a/monokai.o b/monokai.o index 06326c5..8a20179 100644 Binary files a/monokai.o and b/monokai.o differ diff --git a/planeObj.o b/planeObj.o index 46f2380..e2a0fd7 100644 Binary files a/planeObj.o and b/planeObj.o differ diff --git a/status.c b/status.c index f9e09bb..852c8f0 100644 --- a/status.c +++ b/status.c @@ -4,8 +4,6 @@ #include "monokai.h" #include "SDL2/SDL2_gfxPrimitives.h" -#define PAD 5 - void updateStatus() { // struct aircraft *a = Modes.aircrafts; @@ -102,12 +100,12 @@ void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color co int messageWidth = (strlen(message) + ((strlen(message) > 0 ) ? 1 : 0)) * appData.messageFontWidth; //newline if no message or label - if(strlen(label) == 0 && strlen(message) == 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(strlen(label) == 0 && strlen(message) == 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 + messageWidth + PAD > appData.screen_width) { // if(*left + PAD < appData.screen_width) { @@ -200,8 +198,8 @@ void drawBattery(int *left, int *top, double level) { void drawStatus() { - int left = PAD + 2 * appData.messageFontHeight ; - int top = appData.screen_height - 2 * appData.messageFontHeight - PAD; + 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'); diff --git a/status.o.REMOVED.git-id b/status.o.REMOVED.git-id index 8c415a8..e8a5452 100644 --- a/status.o.REMOVED.git-id +++ b/status.o.REMOVED.git-id @@ -1 +1 @@ -30a2da16b88ee34ce3413fff471b01c956184f32 \ No newline at end of file +90ec17d3fd60fd6950fbb50080a31747734eec21 \ No newline at end of file diff --git a/structs.h b/structs.h index a1fe80b..5e64226 100644 --- a/structs.h +++ b/structs.h @@ -77,7 +77,7 @@ struct planeObj { int x, y, cx, cy, w, h; float ox, oy, dox, doy, ddox, ddoy; - + float pressure; }; struct planeObj *planes; diff --git a/view1090.REMOVED.git-id b/view1090.REMOVED.git-id index 5c9e4c9..fbe62e2 100644 --- a/view1090.REMOVED.git-id +++ b/view1090.REMOVED.git-id @@ -1 +1 @@ -8994067f92a4d800070c11716a732a5636bb6e5b \ No newline at end of file +2e266c7f3d943cd7251613fc0eddc9208d5bb05a \ No newline at end of file diff --git a/view1090.c b/view1090.c index 413353a..71b5780 100644 --- a/view1090.c +++ b/view1090.c @@ -71,9 +71,9 @@ void view1090InitConfig(void) { appData.centerLat = Modes.fUserLat; // Display options - appData.screen_uiscale = UISCALE; - appData.screen_width = SCREEN_WIDTH; - appData.screen_height = SCREEN_HEIGHT; + appData.screen_uiscale = 1; + appData.screen_width = 0; + appData.screen_height = 0; appData.screen_depth = 32; appData.fullscreen = 0; diff --git a/view1090.o.REMOVED.git-id b/view1090.o.REMOVED.git-id index 05895e4..8adde1b 100644 --- a/view1090.o.REMOVED.git-id +++ b/view1090.o.REMOVED.git-id @@ -1 +1 @@ -a549061b45cd62ae3ca46ebf3b8e29c4956b9641 \ No newline at end of file +547bceb30b8891c365837c7f01eac3b9c227fa8e \ No newline at end of file