From d564a559dcd92339105269c9e8a3e10f4f5fdb12 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Wed, 7 Mar 2018 19:15:08 +0100 Subject: [PATCH] Adds essentially nothing. Some convenience functions. That is all --- CMakeLists.txt | 6 +++++ src/config.h.in | 6 +++++ src/gui.c | 4 ++-- src/main.c | 4 +++- src/texture.c | 60 ++++++++++++++++++++++++++++++++++++++----------- src/texture.h | 13 +++++++++++ 6 files changed, 77 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 060bf42..e4dab5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,12 @@ SET(CMAKE_COLOR_MAKEFILE ON) project(breakhack C) +set(breakhack_GAME_TITLE "BreakHack") +set(breakhack_MAJOR_VERSION 0) +set(breakhack_MINOR_VERSION 1) +set(breakhack_PATCH_VERSION 1) +set(breakhack_RELEASE_TYPE "(early access)") + include(FindLua) include(FindPhysFS) include(cmake/FindSDL2.cmake) diff --git a/src/config.h.in b/src/config.h.in index 83a81a5..83795fc 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -21,4 +21,10 @@ #cmakedefine _WIN32 ${WIN32} +#define GAME_TITLE "@breakhack_GAME_TITLE@" +#define MAJOR_VERSION @breakhack_MAJOR_VERSION@ +#define MINOR_VERSION @breakhack_MINOR_VERSION@ +#define PATCH_VERSION @breakhack_PATCH_VERSION@ +#define RELEASE_TYPE "@breakhack_RELEASE_TYPE@" + #endif // CONFIG_H_ diff --git a/src/gui.c b/src/gui.c index 1543f29..bcc90de 100644 --- a/src/gui.c +++ b/src/gui.c @@ -499,7 +499,7 @@ gui_render_log(Gui *gui, unsigned int width, unsigned int height, Camera *cam) void gui_render_event_message(Gui *gui, Camera *cam) { - static SDL_Color color = { 255, 255, 255, 255 }; + static SDL_Color fg_color = { 255, 255, 255, 255 }; static SDL_Rect box = { 0, 0, 150, 50 }; if (timer_started(gui->event_message_timer) @@ -512,7 +512,7 @@ gui_render_event_message(Gui *gui, Camera *cam) if (event_messages.count > 0) { texture_load_from_text(gui->event_message, event_messages.messages[0], - color, + fg_color, cam->renderer); box.x = (GAME_VIEW_WIDTH/2) - (gui->event_message->dim.width/2); diff --git a/src/main.c b/src/main.c index f910eb9..4090ca8 100644 --- a/src/main.c +++ b/src/main.c @@ -122,7 +122,9 @@ bool initSDL(void) mixer_init(); - gWindow = SDL_CreateWindow("Breakhack", + char title_buffer[100]; + m_sprintf(title_buffer, 100, "%s %d.%d.%d %s", GAME_TITLE, MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, RELEASE_TYPE); + gWindow = SDL_CreateWindow(title_buffer, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (int)(SCREEN_WIDTH * renderScale), diff --git a/src/texture.c b/src/texture.c index 8caa0fd..ca3cd55 100644 --- a/src/texture.c +++ b/src/texture.c @@ -84,20 +84,9 @@ texture_load_font(Texture *t, const char *path, unsigned int size) } } -void -texture_load_from_text(Texture *t, - const char *text, - SDL_Color c, - SDL_Renderer *renderer) +static void +load_from_surface(Texture *t, SDL_Surface *surface, SDL_Renderer *renderer) { - SDL_Surface *surface = TTF_RenderText_Solid( t->font, text, c ); - if (surface == NULL) - { - error("Unable to create texture from rendered text: %s", - IMG_GetError()); - return; - } - if (t->texture) { SDL_DestroyTexture(t->texture); t->texture = NULL; @@ -116,6 +105,51 @@ texture_load_from_text(Texture *t, SDL_FreeSurface(surface); } +void +texture_load_from_text(Texture *t, + const char *text, + SDL_Color c, + SDL_Renderer *renderer) +{ + SDL_Surface *surface = TTF_RenderText_Solid( t->font, text, c ); + if (surface == NULL) + { + error("Unable to create texture from rendered text: %s", + IMG_GetError()); + return; + } + + load_from_surface(t, surface, renderer); +} + +void +texture_load_from_text_shaded(Texture *t, const char * text, SDL_Color fg, SDL_Color bg, SDL_Renderer *renderer) +{ + SDL_Surface *surface = TTF_RenderText_Shaded( t->font, text, fg, bg ); + if (surface == NULL) + { + error("Unable to create texture from rendered text: %s", + IMG_GetError()); + return; + } + + load_from_surface(t, surface, renderer); +} + +void +texture_load_from_text_blended(Texture *t, const char * text, SDL_Color fg, SDL_Renderer *renderer) +{ + SDL_Surface *surface = TTF_RenderText_Blended( t->font, text, fg ); + if (surface == NULL) + { + error("Unable to create texture from rendered text: %s", + IMG_GetError()); + return; + } + + load_from_surface(t, surface, renderer); +} + void texture_render(Texture *texture, SDL_Rect *box, Camera *cam) { diff --git a/src/texture.h b/src/texture.h index 0b431a8..1db0546 100644 --- a/src/texture.h +++ b/src/texture.h @@ -46,6 +46,19 @@ texture_load_from_text(Texture*, SDL_Color, SDL_Renderer*); +void +texture_load_from_text_shaded(Texture*, + const char *text, + SDL_Color, + SDL_Color, + SDL_Renderer*); + +void +texture_load_from_text_blended(Texture*, + const char *text, + SDL_Color, + SDL_Renderer*); + void texture_render(Texture*, SDL_Rect*, Camera*);