diff --git a/AppData.cpp b/AppData.cpp index 61eb889..0bfda44 100644 --- a/AppData.cpp +++ b/AppData.cpp @@ -59,7 +59,8 @@ void AppData::update() { fd = setupConnection(c); return; } - modesReadFromClient(&modes, c,"",decodeBinMessage); + char empty; + modesReadFromClient(&modes, c, &empty,decodeBinMessage); interactiveRemoveStaleAircrafts(&modes); diff --git a/View.cpp b/View.cpp index 5b2ed64..56df496 100644 --- a/View.cpp +++ b/View.cpp @@ -195,7 +195,7 @@ int View::outOfBounds(int x, int y) { // Font stuff // -TTF_Font* View::loadFont(char *name, int size) +TTF_Font* View::loadFont(const char *name, int size) { TTF_Font *font = TTF_OpenFont(name, size); @@ -304,20 +304,20 @@ void View::font_init() { style.buttonColor = lightblue; } -void View::drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color) +void View::drawString(std::string text, int x, int y, TTF_Font *font, SDL_Color color) { - if(!strlen(text)) { + if(!text.length()) { return; } SDL_Surface *surface; SDL_Rect dest; - surface = TTF_RenderUTF8_Solid(font, text, color); + surface = TTF_RenderUTF8_Solid(font, text.c_str(), color); if (surface == NULL) { - printf("Couldn't create String %s: %s\n", text, SDL_GetError()); + printf("Couldn't create String %s: %s\n", text.c_str(), SDL_GetError()); return; } @@ -333,19 +333,19 @@ void View::drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color SDL_FreeSurface(surface); } -void View::drawStringBG(char * text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor) { - if(!strlen(text)) { +void View::drawStringBG(std::string text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor) { + if(!text.length()) { return; } SDL_Surface *surface; SDL_Rect dest; - surface = TTF_RenderUTF8_Shaded(font, text, color, bgColor); + surface = TTF_RenderUTF8_Shaded(font, text.c_str(), color, bgColor); if (surface == NULL) { - printf("Couldn't create String %s: %s\n", text, SDL_GetError()); + printf("Couldn't create String %s: %s\n", text.c_str(), SDL_GetError()); return; } @@ -365,9 +365,9 @@ void View::drawStringBG(char * text, int x, int y, TTF_Font *font, SDL_Color col // Status boxes // -void View::drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color color) { - int labelWidth = (strlen(label) + ((strlen(label) > 0 ) ? 1 : 0)) * labelFontWidth; - int messageWidth = (strlen(message) + ((strlen(message) > 0 ) ? 1 : 0)) * messageFontWidth; +void View::drawStatusBox(int *left, int *top, std::string label, std::string message, SDL_Color color) { + int labelWidth = (label.length() + ((label.length() > 0 ) ? 1 : 0)) * labelFontWidth; + int messageWidth = (message.length() + ((message.length() > 0 ) ? 1 : 0)) * messageFontWidth; if(*left + labelWidth + messageWidth + PAD > screen_width) { *left = PAD; @@ -821,8 +821,17 @@ void View::drawPlaneText(Aircraft *p) { if(maxCharCount > 1) { - 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 - mapFontHeight, p->y}; + Sint16 vx[4] = { + static_cast(p->cx), + static_cast(p->cx + (p->x - p->cx) / 2), + static_cast(p->x), + static_cast(p->x)}; + + Sint16 vy[4] = { + static_cast(p->cy), + static_cast(p->cy + (p->y - p->cy) / 2), + static_cast(p->y - mapFontHeight), + static_cast(p->y)}; if(p->cy > p->y + currentLine * mapFontHeight) { vy[2] = p->y + currentLine * mapFontHeight + mapFontHeight; diff --git a/View.h b/View.h index b7b060e..31875f4 100644 --- a/View.h +++ b/View.h @@ -6,6 +6,7 @@ #include "SDL2/SDL.h" #include "SDL2/SDL_ttf.h" #include +#include //defs - should all move to config file setup #define ROUND_RADIUS 3 //radius of text box corners @@ -68,11 +69,11 @@ class View { float dx_mult; float dy_mult; - TTF_Font* loadFont(char *name, int size); + TTF_Font* loadFont(const char *name, int size); void closeFont(TTF_Font *font); - void drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color); - void drawStringBG(char * text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor); - void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color color); + void drawString(std::string text, int x, int y, TTF_Font *font, SDL_Color color); + void drawStringBG(std::string text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor); + void drawStatusBox(int *left, int *top, std::string label, std::string message, SDL_Color color); void drawStatus(); Aircraft *selectedAircraft; @@ -131,7 +132,7 @@ class View { int mapMoved; int mapRedraw; int mapAnimating; - + float currentLon; float currentLat; std::chrono::high_resolution_clock::time_point lastFrameTime;