Nuevo Drawable.
Cambiamos un poco la arquitectura del Drawable. Parece que todo funciona sin necesidad de tocar nada.
This commit is contained in:
@@ -48,7 +48,7 @@ namespace UE
|
||||
* @param i : �ndice del rect.
|
||||
* @return El SDL_Rect* solicitado (o el por defecto en caso de error).
|
||||
*/
|
||||
SDL_Rect* GetTextureRect(int i);
|
||||
SDL_Rect* GetTextureRect(int i); // -> Devolver un SDL_Rect, el Ptr ocupa incluso más.
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "Drawable.h"
|
||||
|
||||
#include "Assets/Texture.h"
|
||||
#include "Logging/Logger.h"
|
||||
|
||||
namespace UE
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,27 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "Interfaces/Transformable.h"
|
||||
|
||||
#include <SDL_rect.h>
|
||||
|
||||
namespace UE
|
||||
{
|
||||
class Renderer;
|
||||
class Texture;
|
||||
|
||||
class Drawable
|
||||
/*
|
||||
* Clase base para renderizar objetos en el mundo.
|
||||
* El renderer extrae los datos necesarios de esta clase para renderizar el objeto.
|
||||
*/
|
||||
class Drawable : public Transformable
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
Drawable() {}
|
||||
virtual ~Drawable() {};
|
||||
|
||||
~Drawable() {}
|
||||
|
||||
//Get-Set del renderLayer.
|
||||
inline void SetLayer(int newLayer) { _renderLayer = newLayer; }
|
||||
inline int GetLayer() { return _renderLayer; }
|
||||
|
||||
public:
|
||||
virtual void Draw(Renderer* renderer) = 0;
|
||||
|
||||
//¿Añadir funciones para cambiar las variables? ¿Al menos, para actualizar el actualRect de alguna forma?
|
||||
|
||||
|
||||
protected:
|
||||
//renderLayer usada en el renderer como "profundidad".
|
||||
int _renderLayer = 0;
|
||||
};
|
||||
|
||||
//Esto permite acceder a este método desde el Renderer, pero no será accesible desde fuera.
|
||||
// de esta forma, me aseguro que ocurren las dos etapas del rendering.
|
||||
friend class Renderer;
|
||||
|
||||
/*
|
||||
* Esta función ha de ser sobrecargada por los Drawables.
|
||||
* Sirve para actualizar la información que hay en el drawable para hacer el rendering.
|
||||
* Constituye la primera parte del draw. En la que se actualizan los datos del Drawable.
|
||||
* La segunda parte, ocurre en el renderer, que extraerá los datos del Drawable.
|
||||
*/
|
||||
virtual void Draw(Renderer* renderer) = 0;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//Ptr a la textura y los datos que está utilizando.
|
||||
UE::Texture* _tx = nullptr;
|
||||
|
||||
//Sección de la textura que se utilizará.
|
||||
SDL_Rect _txRect;
|
||||
|
||||
//UE::Texture contiene una lista de rects, con esto, podemos seleccionar el rect que queramos.
|
||||
//Pero es redundante con _txRect y para que sea seguro habría que encapsular todo.
|
||||
//¿Es necesario que esté aquí? ¿Puedo simplemente tenerlo en aquellos Drawables en que lo necesite (animated ones)?
|
||||
int _txRectID = 0;
|
||||
|
||||
//Indica en qué layer del renderer está el objeto (z order).
|
||||
int _renderLayer = 0;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace UE
|
||||
{
|
||||
class Renderer;
|
||||
|
||||
class Sprite : public Drawable, public Transformable
|
||||
class Sprite : public Drawable
|
||||
{
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace UE
|
||||
|
||||
typedef glm::tvec4<int> UE_Color;
|
||||
|
||||
class TextBox : public Drawable, public Transformable
|
||||
class TextBox : public Drawable
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "Transformable.h"
|
||||
|
||||
#include "Logging/Logger.h"
|
||||
|
||||
#include <SDL_rect.h>
|
||||
|
||||
|
||||
namespace UE
|
||||
{
|
||||
|
||||
void Transformable::SetPosition(float x, float y)
|
||||
{
|
||||
_pos.x = x;
|
||||
_pos.y = y;
|
||||
}
|
||||
|
||||
void Transformable::SetPosition(glm::vec<2, float> newPosition)
|
||||
{
|
||||
_pos = newPosition;
|
||||
}
|
||||
|
||||
void Transformable::SetSize(float x, float y)
|
||||
{
|
||||
_size.x = x;
|
||||
_size.y = y;
|
||||
}
|
||||
|
||||
void Transformable::SetSize(glm::vec<2, float> newSize)
|
||||
{
|
||||
_size = newSize;
|
||||
}
|
||||
|
||||
void Transformable::Move(float x, float y)
|
||||
{
|
||||
_pos.x += x;
|
||||
_pos.y += y;
|
||||
}
|
||||
|
||||
void Transformable::Resize(float x, float y)
|
||||
{
|
||||
_size.x += x;
|
||||
_size.y += y;
|
||||
}
|
||||
|
||||
SDL_Rect Transformable::GetRect()
|
||||
{
|
||||
SDL_Rect rect = { _pos.x, _pos.y, _size.x, _size.y };
|
||||
return rect;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
|
||||
struct SDL_Rect;
|
||||
|
||||
namespace UE
|
||||
{
|
||||
/*
|
||||
Clase que contiene lo necesario para crear un objeto con posici�n en el espacio y modificarlo.
|
||||
Almacena una posición y un tamaño.
|
||||
Utilizado para representar objetos en algún espacio.
|
||||
*/
|
||||
class Transformable
|
||||
{
|
||||
@@ -20,13 +21,32 @@ namespace UE
|
||||
//-----------
|
||||
|
||||
|
||||
//Modifica la posici�n del Objeto.
|
||||
inline void SetPosition(float x, float y) { _pos = glm::vec<2, float>(x, y); }
|
||||
inline void SetPosition(glm::vec<2, float> newPosition) { _pos = newPosition; }
|
||||
/*
|
||||
* Establece una nueva posición para el objeto.
|
||||
* Dados dos floats como nueva posición.
|
||||
*/
|
||||
void SetPosition(float x, float y);
|
||||
|
||||
/*
|
||||
* Establece una nueva posición para el objeto.
|
||||
* Dado un vector como nueva posición.
|
||||
*/
|
||||
void SetPosition(glm::vec<2, float> newPosition);
|
||||
|
||||
|
||||
/*
|
||||
* Establece un nuevo tamaño para el objeto (En principio, en pixeles).
|
||||
* Dados dos floats como nuevo tamaño.
|
||||
*/
|
||||
void SetSize(float x, float y);
|
||||
|
||||
/*
|
||||
* Establece un nuevo tamaño para el objeto (En principio, en pixeles).
|
||||
* Dado un vector como nuevo tamaño.
|
||||
*/
|
||||
void SetSize(glm::vec<2, float> newSize);
|
||||
|
||||
|
||||
//Modifica la escala de Objeto.
|
||||
inline void SetSize(float x, float y) { _size = glm::vec<2, float>(x, y); }
|
||||
inline void SetSize(glm::vec<2, float> newSize) { _size = newSize; }
|
||||
|
||||
//-----------
|
||||
//- Getters -
|
||||
@@ -36,9 +56,28 @@ namespace UE
|
||||
inline glm::vec2 GetSize() { return _size; }
|
||||
|
||||
|
||||
//-----------
|
||||
//- Methods -
|
||||
//-----------
|
||||
|
||||
/*
|
||||
* Mueve el objeto el offset indicado.
|
||||
*/
|
||||
void Move(float x, float y);
|
||||
|
||||
/*
|
||||
* Cambia el tamaño la cantidad indicada.
|
||||
*/
|
||||
void Resize(float x, float y);
|
||||
|
||||
/*
|
||||
* Devuelve el rect que representa/ocupa el objeto.
|
||||
*/
|
||||
SDL_Rect GetRect();
|
||||
|
||||
|
||||
protected:
|
||||
//Se almacena la posici�n y el tama�o del objeto. Con esto se puede crear un SDL_Rect.
|
||||
//Almacenamos la posición y el tamaño del objeto. Esto representa un SDL_Rect.
|
||||
glm::vec<2, float> _pos;
|
||||
glm::vec<2, float> _size;
|
||||
};
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "Scenes/MainScene.hpp"
|
||||
#include "Scenes/TestScene2.hpp"
|
||||
|
||||
|
||||
static bool _quit = false;
|
||||
|
||||
int Init();
|
||||
|
||||
Reference in New Issue
Block a user