Cambiado el nombre de la clase LTexture a Texture

This commit is contained in:
2022-10-19 08:56:13 +02:00
parent ddd54fdd3f
commit 8160ddc14a
27 changed files with 64 additions and 62 deletions

View File

@@ -1,7 +1,7 @@
#include "animatedsprite.h"
// Constructor
AnimatedSprite::AnimatedSprite(LTexture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer)
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer)
{
// Copia los punteros
setTexture(texture);

View File

@@ -30,7 +30,7 @@ private:
public:
// Constructor
AnimatedSprite(LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
// Destructor
~AnimatedSprite();

View File

@@ -2,7 +2,7 @@
#include "movingsprite.h"
// Constructor
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer)
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer)
{
// Copia los punteros
this->texture = texture;

View File

@@ -35,7 +35,7 @@ protected:
public:
// Constructor
MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr);
MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
// Destructor
~MovingSprite();

View File

@@ -1,7 +1,7 @@
#include "sprite.h"
// Constructor
Sprite::Sprite(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *renderer)
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer)
{
// Establece la posición X,Y del sprite
this->x = x;
@@ -24,7 +24,7 @@ Sprite::Sprite(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *rend
enabled = true;
}
Sprite::Sprite(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer)
Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer)
{
// Establece la posición X,Y del sprite
x = rect.x;
@@ -149,13 +149,13 @@ void Sprite::setSpriteClip(int x, int y, int w, int h)
}
// Obten el valor de la variable
LTexture *Sprite::getTexture()
Texture *Sprite::getTexture()
{
return texture;
}
// Establece el valor de la variable
void Sprite::setTexture(LTexture *texture)
void Sprite::setTexture(Texture *texture)
{
this->texture = texture;
}

View File

@@ -1,7 +1,7 @@
#pragma once
#include <SDL2/SDL.h>
#include "ltexture.h"
#include "texture.h"
#ifndef SPRITE_H
#define SPRITE_H
@@ -16,15 +16,15 @@ protected:
int h; // Alto del sprite
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
LTexture *texture; // Textura donde estan todos los dibujos del sprite
Texture *texture; // Textura donde estan todos los dibujos del sprite
SDL_Rect spriteClip; // Rectangulo de origen de la textura que se dibujará en pantalla
bool enabled; // Indica si el sprite esta habilitado
public:
// Constructor
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr);
Sprite(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer);
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer);
// Destructor
~Sprite();
@@ -75,10 +75,10 @@ public:
void setSpriteClip(int x, int y, int w, int h);
// Obten el valor de la variable
LTexture *getTexture();
Texture *getTexture();
// Establece el valor de la variable
void setTexture(LTexture *texture);
void setTexture(Texture *texture);
// Establece el valor de la variable
void setRenderer(SDL_Renderer *renderer);

View File

@@ -10,7 +10,7 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
initOffsetFromFile(textFile);
// Crea los objetos
texture = new LTexture(renderer, bitmapFile);
texture = new Texture(renderer, bitmapFile);
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
}

View File

@@ -24,7 +24,7 @@ private:
// Objetos
Sprite *sprite; // Objeto con los graficos para el texto
LTexture *texture; // Textura con los bitmaps del texto
Texture *texture; // Textura con los bitmaps del texto
// Variables
int boxWidth; // Anchura de la caja de cada caracter en el png

View File

@@ -1,10 +1,10 @@
#include "ltexture.h"
#include "texture.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
// Constructor
LTexture::LTexture(SDL_Renderer *renderer, std::string path)
Texture::Texture(SDL_Renderer *renderer, std::string path)
{
// Copia punteros
this->renderer = renderer;
@@ -23,14 +23,14 @@ LTexture::LTexture(SDL_Renderer *renderer, std::string path)
}
// Destructor
LTexture::~LTexture()
Texture::~Texture()
{
// Libera memoria
unload();
}
// Carga una imagen desde un fichero
bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer)
{
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
int req_format = STBI_rgb_alpha;
@@ -98,7 +98,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
}
// Crea una textura en blanco
bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess access)
bool Texture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess access)
{
// Crea una textura sin inicializar
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
@@ -116,7 +116,7 @@ bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Te
}
// Libera la memoria de la textura
void LTexture::unload()
void Texture::unload()
{
// Libera la textura si existe
if (texture != nullptr)
@@ -129,25 +129,25 @@ void LTexture::unload()
}
// Establece el color para la modulacion
void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue)
void Texture::setColor(Uint8 red, Uint8 green, Uint8 blue)
{
SDL_SetTextureColorMod(texture, red, green, blue);
}
// Establece el blending
void LTexture::setBlendMode(SDL_BlendMode blending)
void Texture::setBlendMode(SDL_BlendMode blending)
{
SDL_SetTextureBlendMode(texture, blending);
}
// Establece el alpha para la modulación
void LTexture::setAlpha(Uint8 alpha)
void Texture::setAlpha(Uint8 alpha)
{
SDL_SetTextureAlphaMod(texture, alpha);
}
// Renderiza la textura en un punto específico
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
void Texture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
{
// Establece el destino de renderizado en la pantalla
SDL_Rect renderQuad = {x, y, width, height};
@@ -167,25 +167,25 @@ void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, floa
}
// Establece la textura como objetivo de renderizado
void LTexture::setAsRenderTarget(SDL_Renderer *renderer)
void Texture::setAsRenderTarget(SDL_Renderer *renderer)
{
SDL_SetRenderTarget(renderer, texture);
}
// Obtiene el ancho de la imagen
int LTexture::getWidth()
int Texture::getWidth()
{
return width;
}
// Obtiene el alto de la imagen
int LTexture::getHeight()
int Texture::getHeight()
{
return height;
}
// Recarga la textura
bool LTexture::reLoad()
bool Texture::reLoad()
{
return loadFromFile(path, renderer);
}

View File

@@ -4,25 +4,27 @@
#include <stdio.h>
#include <string>
#ifndef LTEXTURE_H
#define LTEXTURE_H
#ifndef TEXTURE_H
#define TEXTURE_H
// Clase LTexture
class LTexture
class Texture
{
private:
// Objetos y punteros
SDL_Texture *texture; // La textura
SDL_Renderer *renderer; // Renderizador donde dibujar la textura
int width; // Ancho de la imagen
int height; // Alto de la imagen
std::string path; // Ruta de la imagen de la textura
// Variables
int width; // Ancho de la imagen
int height; // Alto de la imagen
std::string path; // Ruta de la imagen de la textura
public:
// Constructor
LTexture(SDL_Renderer *renderer, std::string path = "");
Texture(SDL_Renderer *renderer, std::string path = "");
// Destructor
~LTexture();
~Texture();
// Carga una imagen desde un fichero
bool loadFromFile(std::string path, SDL_Renderer *renderer);

View File

@@ -1,7 +1,7 @@
#pragma once
#include <SDL2/SDL.h>
#include "ltexture.h"
#include "texture.h"
#include <string>
#ifndef UTILS_H