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); // y = p->cy + (int)round(p->oy);
} }
// SDL_Color signalToColor(int signal) {
// SDL_Color planeColor;
void AircraftLabel::draw(SDL_Renderer *renderer) { // if(signal > 127) {
//don't draw first time // signal = 127;
if(x == 0 || y == 0) { // }
return;
} // 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 totalWidth = 0;
int totalHeight = 0; int totalHeight = 0;
@ -245,10 +283,9 @@ void AircraftLabel::draw(SDL_Renderer *renderer) {
drawColor.a = (int) (255.0f * opacity); drawColor.a = (int) (255.0f * opacity);
//this would need to be set in view (settable label level etc) if(selected) {
// if(p == selectedAircraft) { drawColor = style.selectedColor;
// drawColor = style.selectedColor; }
// }
int tick = 4; 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); 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) { if(labelLevel < 2 || selected) {
//need externally settable label level
if(labelLevel < 2) {
// drawSignalMarks(p, x, y); // drawSignalMarks(p, x, y);
SDL_Color drawColor = style.labelColor; SDL_Color drawColor = style.labelColor;
drawColor.a = (int) (255.0f * opacity); drawColor.a = (int) (255.0f * opacity);
flightLabel.setFGColor(drawColor); flightLabel.setFGColor(drawColor);
flightLabel.setPosition(x,y);
flightLabel.draw(renderer); flightLabel.draw(renderer);
// outRect = drawString(flight, x, y, mapBoldFont, drawColor); // outRect = drawString(flight, x, y, mapBoldFont, drawColor);
outRect = flightLabel.getRect(); outRect = flightLabel.getRect();
@ -321,24 +357,20 @@ void AircraftLabel::draw(SDL_Renderer *renderer) {
} }
// if(labelLevel < 1 || p == selectedAircraft) { if(labelLevel < 1 || selected) {
if(labelLevel < 1) {
SDL_Color drawColor = style.subLabelColor; SDL_Color drawColor = style.subLabelColor;
drawColor.a = (int) (255.0f * opacity); 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.setFGColor(drawColor);
altitudeLabel.setPosition(x,y + totalHeight);
altitudeLabel.draw(renderer); altitudeLabel.draw(renderer);
outRect = altitudeLabel.getRect(); outRect = altitudeLabel.getRect();
totalWidth = std::max(totalWidth,outRect.w); totalWidth = std::max(totalWidth,outRect.w);
totalHeight += outRect.h; 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.setFGColor(drawColor);
speedLabel.setPosition(x,y + totalHeight);
speedLabel.draw(renderer); speedLabel.draw(renderer);
outRect = speedLabel.getRect(); 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_w = totalWidth;
target_h = totalHeight; target_h = totalHeight;

View file

@ -15,7 +15,7 @@ class AircraftLabel {
void calculateForces(Aircraft *check_p); void calculateForces(Aircraft *check_p);
void applyForces(); 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); AircraftLabel(Aircraft *p, bool metric, int screen_width, int screen_height, TTF_Font *font);

171
View.cpp
View file

@ -32,9 +32,6 @@
#include "SDL2/SDL2_rotozoom.h" #include "SDL2/SDL2_rotozoom.h"
#include "SDL2/SDL2_gfxPrimitives.h" #include "SDL2/SDL2_gfxPrimitives.h"
//color schemes
#include "parula.h"
#include "View.h" #include "View.h"
#include "AircraftLabel.h" #include "AircraftLabel.h"
@ -86,22 +83,6 @@ SDL_Color setColor(uint8_t r, uint8_t g, uint8_t b) {
return out; 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) { SDL_Color lerpColor(SDL_Color aColor, SDL_Color bColor, float factor) {
if(factor > 1.0f) { if(factor > 1.0f) {
factor = 1.0f; factor = 1.0f;
@ -119,63 +100,63 @@ SDL_Color lerpColor(SDL_Color aColor, SDL_Color bColor, float factor) {
return out; return out;
} }
SDL_Color hsv2SDLColor(float h, float s, float v) // SDL_Color hsv2SDLColor(float h, float s, float v)
{ // {
float hh, p, q, t, ff; // float hh, p, q, t, ff;
long i; // long i;
SDL_Color out; // SDL_Color out;
if(s <= 0.0) { // if(s <= 0.0) {
out.r = (uint8_t)v; // out.r = (uint8_t)v;
out.g = (uint8_t)v; // out.g = (uint8_t)v;
out.b = (uint8_t)v; // out.b = (uint8_t)v;
return out; // return out;
} // }
hh = h; // hh = h;
if(hh >= 360.0) hh = 0.0; // if(hh >= 360.0) hh = 0.0;
hh /= 60.0; // hh /= 60.0;
i = (long)hh; // i = (long)hh;
ff = hh - i; // ff = hh - i;
p = v * (1.0 - s); // p = v * (1.0 - s);
q = v * (1.0 - (s * ff)); // q = v * (1.0 - (s * ff));
t = v * (1.0 - (s * (1.0 - ff))); // t = v * (1.0 - (s * (1.0 - ff)));
switch(i) { // switch(i) {
case 0: // case 0:
out.r = (uint8_t)v; // out.r = (uint8_t)v;
out.g = (uint8_t)t; // out.g = (uint8_t)t;
out.b = (uint8_t)p; // out.b = (uint8_t)p;
break; // break;
case 1: // case 1:
out.r = (uint8_t)q; // out.r = (uint8_t)q;
out.g = (uint8_t)v; // out.g = (uint8_t)v;
out.b = (uint8_t)p; // out.b = (uint8_t)p;
break; // break;
case 2: // case 2:
out.r = (uint8_t)p; // out.r = (uint8_t)p;
out.g = (uint8_t)v; // out.g = (uint8_t)v;
out.b = (uint8_t)t; // out.b = (uint8_t)t;
break; // break;
case 3: // case 3:
out.r = (uint8_t)p; // out.r = (uint8_t)p;
out.g = (uint8_t)q; // out.g = (uint8_t)q;
out.b = (uint8_t)v; // out.b = (uint8_t)v;
break; // break;
case 4: // case 4:
out.r = (uint8_t)t; // out.r = (uint8_t)t;
out.g = (uint8_t)p; // out.g = (uint8_t)p;
out.b = (uint8_t)v; // out.b = (uint8_t)v;
break; // break;
case 5: // case 5:
default: // default:
out.r = (uint8_t)v; // out.r = (uint8_t)v;
out.g = (uint8_t)p; // out.g = (uint8_t)p;
out.b = (uint8_t)q; // out.b = (uint8_t)q;
break; // break;
} // }
return out; // return out;
} // }
int View::screenDist(float d) { int View::screenDist(float d) {
float scale_factor = (screen_width > screen_height) ? screen_width : screen_height; 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) TTF_Font* View::loadFont(const char *name, int size)
{ {
@ -752,8 +736,6 @@ void View::drawGeography() {
currentMaxDist = maxDist; currentMaxDist = maxDist;
} }
SDL_SetRenderDrawColor(renderer, style.backgroundColor.r, style.backgroundColor.g, style.backgroundColor.b, 255); SDL_SetRenderDrawColor(renderer, style.backgroundColor.r, style.backgroundColor.g, style.backgroundColor.b, 255);
SDL_RenderClear(renderer); 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) { void View::drawPlaneText(Aircraft *p) {
if(!p->label) { if(!p->label) {
p->label = new AircraftLabel(p,metric,screen_width, screen_height, mapFont); p->label = new AircraftLabel(p,metric,screen_width, screen_height, mapFont);
} }
p->label->update(); p->label->update();
p->label->draw(renderer); p->label->draw(renderer, (p == selectedAircraft));
} }
float View::resolveLabelConflicts() { float View::resolveLabelConflicts() {
@ -881,7 +839,6 @@ float View::resolveLabelConflicts() {
return maxV; return maxV;
} }
void View::drawPlanes() { void View::drawPlanes() {
Aircraft *p = appData->aircraftList.head; Aircraft *p = appData->aircraftList.head;
SDL_Color planeColor; SDL_Color planeColor;
@ -998,7 +955,6 @@ void View::animateCenterAbsolute(float x, float y) {
mapMoved = 1; mapMoved = 1;
} }
void View::moveCenterAbsolute(float x, float y) { void View::moveCenterAbsolute(float x, float y) {
float scale_factor = (screen_width > screen_height) ? screen_width : screen_height; float scale_factor = (screen_width > screen_height) ? screen_width : screen_height;
@ -1202,13 +1158,12 @@ void View::draw() {
//drawMouse(); //drawMouse();
drawClick(); drawClick();
if(fps) { // if(fps) {
char fps[60] = " "; // char fps[60] = " ";
snprintf(fps,40," %d lines @ %.1ffps", lineCount, 1000.0 / elapsed(lastFrameTime)); // snprintf(fps,40," %d lines @ %.1ffps", lineCount, 1000.0 / elapsed(lastFrameTime));
// drawStringBG(fps, 0,0, mapFont, style.subLabelColor, style.backgroundColor);
//drawStringBG(fps, 0,0, mapFont, style.subLabelColor, style.backgroundColor); // }
}
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);