trying 90 degree lables

Former-commit-id: 416a4800a52e43f2583252650e6345f88fa7f988
Former-commit-id: 5efa8306924bca3a336db7412480ee40b3876dbc
This commit is contained in:
Nathan 2017-10-06 11:34:36 -05:00
parent 374f2bc972
commit aff3e48bbc
5 changed files with 90 additions and 31 deletions

View file

@ -1,4 +1,5 @@
#include "font.h" #include "font.h"
#include "SDL/SDL_rotozoom.h"
TTF_Font *loadFont(char *name, int size) 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); 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) { void drawStringBG(char * text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor) {
if(!strlen(text)) { if(!strlen(text)) {
return; return;

View file

@ -82,8 +82,15 @@ void init(char *title)
game.listFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 18); game.listFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 18);
game.fontWidth = 10; game.messageFont = loadFont("font/TerminusTTF-Bold-4.46.0.ttf", 34);
game.fontHeight = 20; 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 */ /* Set the screen title */

View file

@ -65,32 +65,42 @@ void updateStatus() {
} }
void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color color) { void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color color) {
int labelWidth = (strlen(label) + 2) * game.fontWidth; int labelWidth = ((strlen(label) > 0 ) ? 1.5 : 0) * game.labelFontHeight;
int messageWidth = (strlen(message) + ((strlen(message) > 0) ? 2 : 0)) * game.fontWidth; int messageWidth = (strlen(message) + ((strlen(message) > 0 ) ? 1 : 0)) * game.messageFontWidth;
if(strlen(label) == 0 && strlen(message) == 0) { 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); boxRGBA(game.screen, *left, *top, Modes.screen_width - PAD, *top + game.messageFontHeight, darkGrey.r, darkGrey.g, darkGrey.b, SDL_ALPHA_OPAQUE);
return; return;
} }
if(*left + labelWidth + messageWidth + PAD > Modes.screen_width) { 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; *left = PAD;
*top = *top - game.fontHeight - PAD; *top = *top - game.messageFontHeight - PAD;
} }
// filled black background
if(messageWidth) { 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) { 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); // label
drawString(message, *left + labelWidth + game.fontWidth, *top, game.listFont, color); 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; *left = *left + labelWidth + messageWidth + PAD;
} }
@ -98,30 +108,29 @@ void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color co
void drawStatus() { void drawStatus() {
int left = PAD; 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] = " "; char strPlaneCount[10] = " ";
snprintf(strPlaneCount, 10,"%d/%d", Status.numVisiblePlanes, Status.numPlanes); snprintf(strPlaneCount, 10,"%d/%d", Status.numVisiblePlanes, Status.numPlanes);
drawStatusBox(&left, &top, "disp", strPlaneCount, yellow); drawStatusBox(&left, &top, "disp", strPlaneCount, yellow);
char strDMax[18] = " "; char strDMax[5] = " ";
snprintf(strDMax, 18, "%.1fkm", Status.maxDist); snprintf(strDMax, 5, "%.0fkm", Status.maxDist);
drawStatusBox(&left, &top, "maxDist", strDMax, blue); drawStatusBox(&left, &top, "mDst", strDMax, blue);
char strMsgRate[18] = " "; char strMsgRate[18] = " ";
snprintf(strMsgRate, 18,"%.0f msg/s", Status.msgRate); snprintf(strMsgRate, 18,"%.0f/s", Status.msgRate);
drawStatusBox(&left, &top, "rate", strMsgRate, pink); drawStatusBox(&left, &top, "rate", strMsgRate, orange);
char strSig[18] = " "; char strSig[18] = " ";
snprintf(strSig, 18, "%.0f%%", 100.0 * Status.avgSig / 1024.0); snprintf(strSig, 18, "%.0f%%", 100.0 * Status.avgSig / 1024.0);
drawStatusBox(&left, &top, "sigAvg", strSig, green); drawStatusBox(&left, &top, "sAvg", 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);
if(Status.closeCall != NULL) { if(Status.closeCall != NULL) {
char strSpeed[8] = " "; char strSpeed[8] = " ";
@ -132,7 +141,7 @@ void drawStatus() {
snprintf(strAlt, 8, "%.0fm", Status.closeCall->altitude / 3.2828); snprintf(strAlt, 8, "%.0fm", Status.closeCall->altitude / 3.2828);
drawStatusBox(&left, &top, "alt", strAlt, white); drawStatusBox(&left, &top, "alt", strAlt, white);
drawStatusBox(&left, &top, "nearby", "", red); drawStatusBox(&left, &top, "near", "", red);
if(strlen(Status.closeCall->flight)) { if(strlen(Status.closeCall->flight)) {
drawStatusBox(&left, &top, "id", Status.closeCall->flight, white); drawStatusBox(&left, &top, "id", Status.closeCall->flight, white);

View file

@ -10,8 +10,14 @@ typedef struct Game
TTF_Font *font; TTF_Font *font;
TTF_Font *listFont; TTF_Font *listFont;
int fontWidth;
int fontHeight; TTF_Font *messageFont;
TTF_Font *labelFont;
int labelFontWidth;
int labelFontHeight;
int messageFontWidth;
int messageFontHeight;
} Game; } Game;
Game game; Game game;
@ -22,6 +28,7 @@ Game game;
TTF_Font *loadFont(char *, int); TTF_Font *loadFont(char *, int);
void closeFont(TTF_Font *); void closeFont(TTF_Font *);
void drawString(char *, int, int, TTF_Font *, SDL_Color); 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); void drawStringBG(char *, int, int, TTF_Font *, SDL_Color, SDL_Color);
//init.c //init.c

View file

@ -1 +1 @@
b7315d268ac28e2a67d8925acc46b6c0ada7c1c8 b528f90e4ca7c8e232740b358694dd53c9c0a3cf