Actualizada la libreria text.h a la última versión

This commit is contained in:
2022-08-08 18:37:42 +02:00
parent 2b2b822540
commit 386039336e
5 changed files with 169 additions and 303 deletions

View File

@@ -1,58 +1,66 @@
#pragma once
#include "sprite.h"
#include "utils.h"
#ifndef TEXT_H
#define TEXT_H
#define TXT_COLOR 1
#define TXT_SHADOW 2
#define TXT_CENTER 4
#define TXT_STROKE 8
// Clase texto. Pinta texto en pantalla a partir de un bitmap
class Text
{
private:
Sprite *mSprite; // Objeto con los graficos para el texto
struct Offset
{
int x;
int y;
Uint8 w;
};
Offset mOffset[128]; // Vector con las posiciones y ancho de cada letra
Uint8 mBoxWidth; // Anchura de la caja de cada caracter en el png
Uint8 mBoxHeight; // Altura de la caja de cada caracter en el png
std::string mFile; // Fichero con los descriptores de la fuente
// Inicializa el vector de offsets desde un fichero
void initOffsetFromFile();
public:
// Constructor
Text();
Text(std::string file, LTexture *texture, SDL_Renderer *renderer);
// Destructor
~Text();
// Inicializador
void init(LTexture *texture, SDL_Renderer *renderer, Uint8 height);
void init();
/**
* \brief Escribe texto en pantalla
*
* \param x Posición en el eje X donde empezar a escribir el texto
* \param y Posición en el eje Y donde empezar a escribir el texto
* \param string Texto para escribir
* \param kerning Espacio de separación entre letras
* \param lenght Longitud de la cadena de texto a escribir
*/
void write(int x, int y, std::string text, Sint8 kerning = 0, Uint8 lenght = 0);
// Escribe el texto en pantalla
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);
// Escribe el texto con colores
void writeColored(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B);
void writeColored(int x, int y, std::string text, color_t color, int kerning = 1, int lenght = -1);
// Escribe el texto con sombra
void writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance = 1, int kerning = 1, int lenght = -1);
// Escribe el texto centrado en un punto x y con kerning
void writeCentered(int x, int y, std::string text, int kerning);
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
// Escribe texto con extras
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = {255, 255, 255}, Uint8 shadowDistance = 1, color_t shadowColor = {0, 0, 0}, int lenght = -1);
// Obtiene la longitud en pixels de una cadena
Uint16 lenght(std::string text, int kerning);
Uint16 lenght(std::string text, int kerning = 1);
// Obtiene el valor de la variable
Uint8 getType();
// Establece el valor de la variable
void setType(Uint8 type);
// Obtiene el valor de la variable
Uint8 getHeight();
// Establece el valor de la variable
void setHeight(Uint8 size);
private:
Sprite *mSprite; // Objeto con los graficos para el texto
SDL_Rect mOffset[255]; // Vector con las posiciones y ancho de cada letra
Uint8 mHeight; // Altura del texto
// Devuelve el valor de la variable
Uint8 getCharacterWidth();
};
#endif