|
|
|
@ -3,7 +3,7 @@
|
|
|
|
|
#include "engine/TextureLoader.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TextLabel createTextLabel(const char text[], const SDL_Point* pos, const SDL_Color* color, TTF_Font* font, SDL_Renderer* renderer) {
|
|
|
|
|
TextLabel createTextLabel(const char text[], const SDL_Point* pos, const SDL_Color* color, TTF_Font* font, SDL_Renderer* renderer, const POSITIONX_TYPE posXType, const POSITIONY_TYPE posYType) {
|
|
|
|
|
TextLabel label = {
|
|
|
|
|
.color = *color,
|
|
|
|
|
.texture = NULL
|
|
|
|
@ -11,7 +11,7 @@ TextLabel createTextLabel(const char text[], const SDL_Point* pos, const SDL_Col
|
|
|
|
|
|
|
|
|
|
label.text = (char*) malloc(sizeof(char)*strlen(text));
|
|
|
|
|
strcpy(label.text, text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
SDL_Surface* surface = TTF_RenderText_Solid(font, label.text, label.color);
|
|
|
|
|
|
|
|
|
@ -28,12 +28,39 @@ TextLabel createTextLabel(const char text[], const SDL_Point* pos, const SDL_Col
|
|
|
|
|
SDL_FreeSurface(surface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
label.textZone.x = pos->x;
|
|
|
|
|
label.textZone.y = pos->y;
|
|
|
|
|
label.textZone.w = calculateStringPixelLenght(font, label.text);
|
|
|
|
|
label.textZone.h = TTF_FontHeight(font);
|
|
|
|
|
|
|
|
|
|
switch (posXType)
|
|
|
|
|
{
|
|
|
|
|
case POSX_LEFT:
|
|
|
|
|
label.textZone.x = pos->x;
|
|
|
|
|
break;
|
|
|
|
|
case POSX_CENTER:
|
|
|
|
|
label.textZone.x = pos->x-label.textZone.w/2;
|
|
|
|
|
break;
|
|
|
|
|
case POSX_RIGHT:
|
|
|
|
|
label.textZone.x = pos->x-label.textZone.w;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (posYType)
|
|
|
|
|
{
|
|
|
|
|
case POSY_TOP:
|
|
|
|
|
label.textZone.y = pos->y;
|
|
|
|
|
break;
|
|
|
|
|
case POSY_CENTER:
|
|
|
|
|
label.textZone.y = pos->y-label.textZone.h/2;
|
|
|
|
|
break;
|
|
|
|
|
case POSY_BOTTOM:
|
|
|
|
|
label.textZone.y = pos->y-label.textZone.h;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|