Texto carga lazy.

parent 4a1a360f
Showing with 22 additions and 5 deletions
No preview for this file type
#include "Texto.h"
#include <SDL2/SDL_ttf.h>
#include <stdexcept>
SDL_Texture *Texto::get_textura(SDL_Renderer *renderer) {
if (texture == nullptr) {
......@@ -7,6 +9,16 @@ SDL_Texture *Texto::get_textura(SDL_Renderer *renderer) {
return texture;
}
SDL_Surface *Texto::get_surface() {
if (surface == nullptr) {
surface = TTF_RenderUTF8_Solid(*fuente, text, fg);
if (surface == nullptr) {
throw std::runtime_error(SDL_GetError());
}
}
return surface;
}
void Texto::renderizar(SDL_Renderer *renderer, int x, int y, int tamx, int tamy) {
texture = get_textura(renderer);
......
......@@ -7,15 +7,20 @@
#include <SDL2/SDL_ttf.h>
class Texto {
SDL_Surface *surface;
Fuente fuente;
const char *text;
SDL_Color fg;
SDL_Surface *surface = nullptr;
SDL_Texture *texture = nullptr;
SDL_Texture *get_textura(SDL_Renderer *renderer);
SDL_Surface *get_surface();
public:
Texto(Fuente &fuente, const char *texto, SDL_Color fg) {
surface = TTF_RenderUTF8_Solid(*fuente, texto, fg);
};
Texto(Fuente &fuente, const char *texto, SDL_Color fg) :
fuente(fuente), text(texto), fg(fg) {};
void renderizar(SDL_Renderer *Renderer, int x, int y, int tamx, int tamy);
......
......@@ -10,7 +10,7 @@ objs = $(code_files_in_obj:.cpp=.o)
deps = $(code_files_in_obj:.cpp=.d)
link_flags = -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer
compile_flags = -w $(link_flags)
compile_flags = -w $(link_flags) -g
$(bin): $(objs)
$(CC) $(objs) $(compile_flags) -o $@
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment