From aff3e48bbc3bffa63c7f405c2c0e37c5ea474cb2 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 6 Oct 2017 11:34:36 -0500 Subject: [PATCH] trying 90 degree lables Former-commit-id: 416a4800a52e43f2583252650e6345f88fa7f988 Former-commit-id: 5efa8306924bca3a336db7412480ee40b3876dbc --- sdl1090/font.c | 36 +++++++++++++++++++ sdl1090/init.c | 11 ++++-- sdl1090/status.c | 61 +++++++++++++++++++-------------- sdl1090/structs.h | 11 ++++-- sdl1090/view1090.REMOVED.git-id | 2 +- 5 files changed, 90 insertions(+), 31 deletions(-) diff --git a/sdl1090/font.c b/sdl1090/font.c index b03b11b..e356218 100755 --- a/sdl1090/font.c +++ b/sdl1090/font.c @@ -1,4 +1,5 @@ #include "font.h" +#include "SDL/SDL_rotozoom.h" TTF_Font *loadFont(char *name, int size) { @@ -58,6 +59,41 @@ void drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color) SDL_FreeSurface(surface); } +void drawString90(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_Blended(font, text, color); + + 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_Surface *temp = rotateSurface90Degrees(surface,1); + + SDL_BlitSurface(temp, NULL, game.screen, &dest); + + /* Free the generated string image */ + + SDL_FreeSurface(surface); + SDL_FreeSurface(temp); +} + void drawStringBG(char * text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor) { if(!strlen(text)) { return; diff --git a/sdl1090/init.c b/sdl1090/init.c index b7ef594..07c7df0 100644 --- a/sdl1090/init.c +++ b/sdl1090/init.c @@ -82,8 +82,15 @@ void init(char *title) game.listFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 18); - game.fontWidth = 10; - game.fontHeight = 20; + game.messageFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 34); + game.labelFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 16); + + + game.messageFontWidth = 17; + game.messageFontHeight = 34; + + game.labelFontWidth = 5; + game.labelFontHeight = 10; /* Set the screen title */ diff --git a/sdl1090/status.c b/sdl1090/status.c index c639474..1ec2c6c 100644 --- a/sdl1090/status.c +++ b/sdl1090/status.c @@ -65,32 +65,42 @@ void updateStatus() { } void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color color) { - int labelWidth = (strlen(label) + 2) * game.fontWidth; - int messageWidth = (strlen(message) + ((strlen(message) > 0) ? 2 : 0)) * game.fontWidth; + int labelWidth = ((strlen(label) > 0 ) ? 1.5 : 0) * game.labelFontHeight; + int messageWidth = (strlen(message) + ((strlen(message) > 0 ) ? 1 : 0)) * game.messageFontWidth; - if(strlen(label) == 0 && strlen(message) == 0) { - boxRGBA(game.screen, *left, *top, Modes.screen_width - PAD, *top + game.fontHeight, darkGrey.r, darkGrey.g, darkGrey.b, SDL_ALPHA_OPAQUE); + if(strlen(label) == 0 && strlen(message) == 0 ) { + boxRGBA(game.screen, *left, *top, Modes.screen_width - PAD, *top + game.messageFontHeight, darkGrey.r, darkGrey.g, darkGrey.b, SDL_ALPHA_OPAQUE); return; } if(*left + labelWidth + messageWidth + PAD > Modes.screen_width) { - boxRGBA(game.screen, *left, *top, Modes.screen_width - PAD, *top + game.fontHeight, darkGrey.r, darkGrey.g, darkGrey.b, SDL_ALPHA_OPAQUE); + if(*left + PAD < Modes.screen_width) { + boxRGBA(game.screen, *left, *top, Modes.screen_width - PAD, *top + game.messageFontHeight, darkGrey.r, darkGrey.g, darkGrey.b, SDL_ALPHA_OPAQUE); + } *left = PAD; - *top = *top - game.fontHeight - PAD; + *top = *top - game.messageFontHeight - PAD; } + // filled black background if(messageWidth) { - boxRGBA(game.screen, *left, *top, *left + labelWidth + messageWidth, *top + game.fontHeight, black.r, black.g, black.b, SDL_ALPHA_OPAQUE); + boxRGBA(game.screen, *left, *top, *left + labelWidth + messageWidth, *top + game.messageFontHeight, black.r, black.g, black.b, SDL_ALPHA_OPAQUE); } - boxRGBA(game.screen, *left, *top, *left + labelWidth, *top + game.fontHeight, color.r, color.g, color.b, SDL_ALPHA_OPAQUE); + // filled label box + if(labelWidth) { + boxRGBA(game.screen, *left, *top, *left + labelWidth, *top + game.messageFontHeight, color.r, color.g, color.b, SDL_ALPHA_OPAQUE); + } + // outline message box if(messageWidth) { - rectangleRGBA(game.screen, *left, *top, *left + labelWidth + messageWidth, *top + game.fontHeight, color.r, color.g, color.b, SDL_ALPHA_OPAQUE); + rectangleRGBA(game.screen, *left, *top, *left + labelWidth + messageWidth, *top + game.messageFontHeight, color.r, color.g, color.b, SDL_ALPHA_OPAQUE); } - drawString(label, *left + game.fontWidth, *top, game.listFont, black); - drawString(message, *left + labelWidth + game.fontWidth, *top, game.listFont, color); + // label + drawString90(label, *left, *top + game.labelFontWidth/2, game.labelFont, black); + + //message + drawString(message, *left + labelWidth + game.messageFontWidth/2, *top, game.messageFont, color); *left = *left + labelWidth + messageWidth + PAD; } @@ -98,30 +108,29 @@ void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color co void drawStatus() { int left = PAD; - int top = Modes.screen_height - game.fontHeight - PAD; + int top = Modes.screen_height - game.messageFontHeight - PAD; + +// drawStatusBox(&left, &top, "", "MENU", white); + + char strLoc[20] = " "; + snprintf(strLoc, 20, "%3.3fN %3.3f%c", Modes.fUserLat, fabs(Modes.fUserLon),(Modes.fUserLon > 0) ? 'E' : 'W'); + drawStatusBox(&left, &top, "GPS", strLoc, pink); char strPlaneCount[10] = " "; snprintf(strPlaneCount, 10,"%d/%d", Status.numVisiblePlanes, Status.numPlanes); drawStatusBox(&left, &top, "disp", strPlaneCount, yellow); - char strDMax[18] = " "; - snprintf(strDMax, 18, "%.1fkm", Status.maxDist); - drawStatusBox(&left, &top, "maxDist", strDMax, blue); + char strDMax[5] = " "; + snprintf(strDMax, 5, "%.0fkm", Status.maxDist); + drawStatusBox(&left, &top, "mDst", strDMax, blue); char strMsgRate[18] = " "; - snprintf(strMsgRate, 18,"%.0f msg/s", Status.msgRate); - drawStatusBox(&left, &top, "rate", strMsgRate, pink); + snprintf(strMsgRate, 18,"%.0f/s", Status.msgRate); + drawStatusBox(&left, &top, "rate", strMsgRate, orange); char strSig[18] = " "; snprintf(strSig, 18, "%.0f%%", 100.0 * Status.avgSig / 1024.0); - drawStatusBox(&left, &top, "sigAvg", strSig, green); - - drawStatusBox(&left, &top, "GPS", "", purple); - - char strLoc[20] = " "; - snprintf(strLoc, 20, "%3.3fN %3.3f%c", Modes.fUserLat, fabs(Modes.fUserLon),(Modes.fUserLon > 0) ? 'E' : 'W'); - - drawStatusBox(&left, &top, "pos", strLoc, orange); + drawStatusBox(&left, &top, "sAvg", strSig, green); if(Status.closeCall != NULL) { char strSpeed[8] = " "; @@ -132,7 +141,7 @@ void drawStatus() { snprintf(strAlt, 8, "%.0fm", Status.closeCall->altitude / 3.2828); drawStatusBox(&left, &top, "alt", strAlt, white); - drawStatusBox(&left, &top, "nearby", "", red); + drawStatusBox(&left, &top, "near", "", red); if(strlen(Status.closeCall->flight)) { drawStatusBox(&left, &top, "id", Status.closeCall->flight, white); diff --git a/sdl1090/structs.h b/sdl1090/structs.h index cc148d6..6861c45 100644 --- a/sdl1090/structs.h +++ b/sdl1090/structs.h @@ -10,8 +10,14 @@ typedef struct Game TTF_Font *font; TTF_Font *listFont; - int fontWidth; - int fontHeight; + + TTF_Font *messageFont; + TTF_Font *labelFont; + + int labelFontWidth; + int labelFontHeight; + int messageFontWidth; + int messageFontHeight; } Game; Game game; @@ -22,6 +28,7 @@ Game game; 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 diff --git a/sdl1090/view1090.REMOVED.git-id b/sdl1090/view1090.REMOVED.git-id index 50e1fab..d89480c 100644 --- a/sdl1090/view1090.REMOVED.git-id +++ b/sdl1090/view1090.REMOVED.git-id @@ -1 +1 @@ -b7315d268ac28e2a67d8925acc46b6c0ada7c1c8 \ No newline at end of file +b528f90e4ca7c8e232740b358694dd53c9c0a3cf \ No newline at end of file