Posant make_uniques, s'ha quedat tot enmerdat per culpa d'un struct

This commit is contained in:
2024-10-08 13:53:24 +02:00
parent 9d41d14d68
commit 06a4f439c1
11 changed files with 157 additions and 304 deletions

View File

@@ -95,15 +95,15 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
}
// Crea los objetos
texture = new Texture(renderer, bitmapFile);
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture);
texture = std::make_unique<Texture>(renderer, bitmapFile);
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight}, texture.get());
// Inicializa variables
fixedWidth = false;
}
// Constructor
Text::Text(std::string textFile, Texture *texture, SDL_Renderer *renderer)
Text::Text(std::string textFile, Texture *texture)
{
// Carga los offsets desde el fichero
textFile_t tf = LoadTextFile(textFile);
@@ -119,15 +119,14 @@ Text::Text(std::string textFile, Texture *texture, SDL_Renderer *renderer)
}
// Crea los objetos
this->texture = nullptr;
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture);
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight});
// Inicializa variables
fixedWidth = false;
}
// Constructor
Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer)
Text::Text(textFile_t *textFile, Texture *texture)
{
// Inicializa variables desde la estructura
boxHeight = textFile->boxHeight;
@@ -140,23 +139,12 @@ Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer)
}
// Crea los objetos
this->texture = nullptr;
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture);
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight});
// Inicializa variables
fixedWidth = false;
}
// Destructor
Text::~Text()
{
delete sprite;
if (texture != nullptr)
{
delete texture;
}
}
// Escribe texto en pantalla
void Text::write(int x, int y, std::string text, int kerning, int lenght)
{
@@ -259,7 +247,7 @@ int Text::lenght(std::string text, int kerning)
}
// Devuelve el valor de la variable
int Text::getCharacterSize()
int Text::getCharacterSize() const
{
return boxWidth;
}