fixed missing labels

This commit is contained in:
nathan 2021-03-20 10:01:36 -07:00
parent 383081d0de
commit 721b9a4a17
3 changed files with 115 additions and 159 deletions

View file

@ -209,12 +209,50 @@ void AircraftLabel::applyForces() {
// y = p->cy + (int)round(p->oy);
}
// SDL_Color signalToColor(int signal) {
// SDL_Color planeColor;
void AircraftLabel::draw(SDL_Renderer *renderer) {
//don't draw first time
if(x == 0 || y == 0) {
return;
}
// if(signal > 127) {
// signal = 127;
// }
// if(signal < 0) {
// planeColor = setColor(96, 96, 96);
// } else {
// planeColor = setColor(parula[signal][0], parula[signal][1], parula[signal][2]);
// }
// return planeColor;
// }
// void View::drawSignalMarks(Aircraft *p, int x, int y) {
// unsigned char * pSig = p->signalLevel;
// unsigned int signalAverage = (pSig[0] + pSig[1] + pSig[2] + pSig[3] +
// pSig[4] + pSig[5] + pSig[6] + pSig[7] + 3) >> 3;
// SDL_Color barColor = signalToColor(signalAverage);
// Uint8 seenFade;
// if(elapsed(p->msSeen) < 1024) {
// seenFade = (Uint8) (255.0 - elapsed(p->msSeen) / 4.0);
// circleRGBA(renderer, x + mapFontWidth, y - 5, 2 * screen_uiscale, barColor.r, barColor.g, barColor.b, seenFade);
// }
// if(elapsed(p->msSeenLatLon) < 1024) {
// seenFade = (Uint8) (255.0 - elapsed(p->msSeenLatLon) / 4.0);
// hlineRGBA(renderer, x + mapFontWidth + 5 * screen_uiscale, x + mapFontWidth + 9 * screen_uiscale, y - 5, barColor.r, barColor.g, barColor.b, seenFade);
// vlineRGBA(renderer, x + mapFontWidth + 7 * screen_uiscale, y - 2 * screen_uiscale - 5, y + 2 * screen_uiscale - 5, barColor.r, barColor.g, barColor.b, seenFade);
// }
// }
void AircraftLabel::draw(SDL_Renderer *renderer, bool selected) {
// //don't draw first time
// if(x == 0 || y == 0) {
// return;
// }
int totalWidth = 0;
int totalHeight = 0;
@ -245,10 +283,9 @@ void AircraftLabel::draw(SDL_Renderer *renderer) {
drawColor.a = (int) (255.0f * opacity);
//this would need to be set in view (settable label level etc)
// if(p == selectedAircraft) {
// drawColor = style.selectedColor;
// }
if(selected) {
drawColor = style.selectedColor;
}
int tick = 4;
@ -303,15 +340,14 @@ void AircraftLabel::draw(SDL_Renderer *renderer) {
lineRGBA(renderer, x + w, y + h + margin,x + w, y + h + margin - tick, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
}
// if(labelLevel < 2 || p == selectedAircraft) {
//need externally settable label level
if(labelLevel < 2) {
if(labelLevel < 2 || selected) {
// drawSignalMarks(p, x, y);
SDL_Color drawColor = style.labelColor;
drawColor.a = (int) (255.0f * opacity);
flightLabel.setFGColor(drawColor);
flightLabel.setPosition(x,y);
flightLabel.draw(renderer);
// outRect = drawString(flight, x, y, mapBoldFont, drawColor);
outRect = flightLabel.getRect();
@ -321,24 +357,20 @@ void AircraftLabel::draw(SDL_Renderer *renderer) {
}
// if(labelLevel < 1 || p == selectedAircraft) {
if(labelLevel < 1) {
if(labelLevel < 1 || selected) {
SDL_Color drawColor = style.subLabelColor;
drawColor.a = (int) (255.0f * opacity);
// drawStringBG(alt, x, y + currentLine * mapFontHeight, mapFont, style.subLabelColor, style.labelBackground);
// outRect = drawString(alt, x, y + totalHeight, mapFont, drawColor);
altitudeLabel.setFGColor(drawColor);
altitudeLabel.setPosition(x,y + totalHeight);
altitudeLabel.draw(renderer);
outRect = altitudeLabel.getRect();
totalWidth = std::max(totalWidth,outRect.w);
totalHeight += outRect.h;
// drawStringBG(speed, x, y + currentLine * mapFontHeight, mapFont, style.subLabelColor, style.labelBackground);
// outRect = drawString(speed, x, y + totalHeight, mapFont, drawColor);
speedLabel.setFGColor(drawColor);
speedLabel.setPosition(x,y + totalHeight);
speedLabel.draw(renderer);
outRect = speedLabel.getRect();
@ -347,37 +379,6 @@ void AircraftLabel::draw(SDL_Renderer *renderer) {
}
//label debug
// char debug[25] = "";
// snprintf(debug,25,"%1.2f", p->labelLevel);
// drawString(debug, p->x, p->y + totalHeight, mapFont, style.red);
// if(maxCharCount > 1) {
// Sint16 vx[4] = {
// static_cast<Sint16>(p->cx),
// static_cast<Sint16>(p->cx + (p->x - p->cx) / 2),
// static_cast<Sint16>(p->x),
// static_cast<Sint16>(p->x)};
// Sint16 vy[4] = {
// static_cast<Sint16>(p->cy),
// static_cast<Sint16>(p->cy + (p->y - p->cy) / 2),
// static_cast<Sint16>(p->y - mapFontHeight),
// static_cast<Sint16>(p->y)};
// if(p->cy > p->y + currentLine * mapFontHeight) {
// vy[2] = p->y + currentLine * mapFontHeight + mapFontHeight;
// vy[3] = p->y + currentLine * mapFontHeight;
// }
// bezierRGBA(renderer,vx,vy,4,2,style.labelLineColor.r,style.labelLineColor.g,style.labelLineColor.b,SDL_ALPHA_OPAQUE);
// lineRGBA(renderer,p->x,p->y,p->x,p->y+currentLine*mapFontHeight,style.labelLineColor.r,style.labelLineColor.g,style.labelLineColor.b,SDL_ALPHA_OPAQUE);
// }
target_w = totalWidth;
target_h = totalHeight;

View file

@ -15,7 +15,7 @@ class AircraftLabel {
void calculateForces(Aircraft *check_p);
void applyForces();
void draw(SDL_Renderer *renderer);
void draw(SDL_Renderer *renderer, bool selected);
AircraftLabel(Aircraft *p, bool metric, int screen_width, int screen_height, TTF_Font *font);

169
View.cpp
View file

@ -32,9 +32,6 @@
#include "SDL2/SDL2_rotozoom.h"
#include "SDL2/SDL2_gfxPrimitives.h"
//color schemes
#include "parula.h"
#include "View.h"
#include "AircraftLabel.h"
@ -86,22 +83,6 @@ SDL_Color setColor(uint8_t r, uint8_t g, uint8_t b) {
return out;
}
SDL_Color signalToColor(int signal) {
SDL_Color planeColor;
if(signal > 127) {
signal = 127;
}
if(signal < 0) {
planeColor = setColor(96, 96, 96);
} else {
planeColor = setColor(parula[signal][0], parula[signal][1], parula[signal][2]);
}
return planeColor;
}
SDL_Color lerpColor(SDL_Color aColor, SDL_Color bColor, float factor) {
if(factor > 1.0f) {
factor = 1.0f;
@ -119,63 +100,63 @@ SDL_Color lerpColor(SDL_Color aColor, SDL_Color bColor, float factor) {
return out;
}
SDL_Color hsv2SDLColor(float h, float s, float v)
{
float hh, p, q, t, ff;
long i;
SDL_Color out;
// SDL_Color hsv2SDLColor(float h, float s, float v)
// {
// float hh, p, q, t, ff;
// long i;
// SDL_Color out;
if(s <= 0.0) {
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)));
// if(s <= 0.0) {
// 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;
// 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;
}
// 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 View::screenDist(float d) {
float scale_factor = (screen_width > screen_height) ? screen_width : screen_height;
@ -223,6 +204,9 @@ int View::outOfBounds(int x, int y, int left, int top, int right, int bottom) {
}
}
//
// Fonts should probably go in Style
//
TTF_Font* View::loadFont(const char *name, int size)
{
@ -752,8 +736,6 @@ void View::drawGeography() {
currentMaxDist = maxDist;
}
SDL_SetRenderDrawColor(renderer, style.backgroundColor.r, style.backgroundColor.g, style.backgroundColor.b, 255);
SDL_RenderClear(renderer);
@ -811,37 +793,13 @@ void View::drawGeography() {
}
}
void View::drawSignalMarks(Aircraft *p, int x, int y) {
unsigned char * pSig = p->signalLevel;
unsigned int signalAverage = (pSig[0] + pSig[1] + pSig[2] + pSig[3] +
pSig[4] + pSig[5] + pSig[6] + pSig[7] + 3) >> 3;
SDL_Color barColor = signalToColor(signalAverage);
Uint8 seenFade;
if(elapsed(p->msSeen) < 1024) {
seenFade = (Uint8) (255.0 - elapsed(p->msSeen) / 4.0);
circleRGBA(renderer, x + mapFontWidth, y - 5, 2 * screen_uiscale, barColor.r, barColor.g, barColor.b, seenFade);
}
if(elapsed(p->msSeenLatLon) < 1024) {
seenFade = (Uint8) (255.0 - elapsed(p->msSeenLatLon) / 4.0);
hlineRGBA(renderer, x + mapFontWidth + 5 * screen_uiscale, x + mapFontWidth + 9 * screen_uiscale, y - 5, barColor.r, barColor.g, barColor.b, seenFade);
vlineRGBA(renderer, x + mapFontWidth + 7 * screen_uiscale, y - 2 * screen_uiscale - 5, y + 2 * screen_uiscale - 5, barColor.r, barColor.g, barColor.b, seenFade);
}
}
void View::drawPlaneText(Aircraft *p) {
if(!p->label) {
p->label = new AircraftLabel(p,metric,screen_width, screen_height, mapFont);
}
p->label->update();
p->label->draw(renderer);
p->label->draw(renderer, (p == selectedAircraft));
}
float View::resolveLabelConflicts() {
@ -881,7 +839,6 @@ float View::resolveLabelConflicts() {
return maxV;
}
void View::drawPlanes() {
Aircraft *p = appData->aircraftList.head;
SDL_Color planeColor;
@ -998,7 +955,6 @@ void View::animateCenterAbsolute(float x, float y) {
mapMoved = 1;
}
void View::moveCenterAbsolute(float x, float y) {
float scale_factor = (screen_width > screen_height) ? screen_width : screen_height;
@ -1202,13 +1158,12 @@ void View::draw() {
//drawMouse();
drawClick();
if(fps) {
char fps[60] = " ";
snprintf(fps,40," %d lines @ %.1ffps", lineCount, 1000.0 / elapsed(lastFrameTime));
// if(fps) {
// char fps[60] = " ";
// snprintf(fps,40," %d lines @ %.1ffps", lineCount, 1000.0 / elapsed(lastFrameTime));
// drawStringBG(fps, 0,0, mapFont, style.subLabelColor, style.backgroundColor);
}
// }
SDL_RenderPresent(renderer);