restructured everything

This commit is contained in:
Robert 2021-04-23 15:08:51 +02:00
parent 4225a524b9
commit c66cae17f2
61 changed files with 18406 additions and 1710 deletions

View file

@ -0,0 +1,4 @@
#pragma once
#include "RenderWindow.hpp"
#include "drawable/shapes/Rectangle.hpp"

View file

@ -0,0 +1,79 @@
/**
* @file RenderTarget
* @brief Contains rendering related objects
* @author Lauchmelder23
* @date 20.05.2020
*/
#pragma once
#include <chrono>
#include "structures/Color.hpp"
#include "graphics/drawable/Drawable.hpp"
struct SDL_Window;
struct SDL_Surface;
SDLU_BEGIN
/**
* @brief Acts as a wrapper for SDL_Renderer*. You can't (and shouldn't)
* instantiate this, but rather derive from it.
*/
class RenderTarget
{
public:
virtual ~RenderTarget();
/**
* @brief Clears the display
*
* @param[in] color The color to clear the display with
*/
void Clear(const Color& color = Color::Black);
/**
* @brief Draws a sdlu::Drawable to the SDL_Renderer
*
* @param[in] drawable A reference to a derived class of Drawable
*/
void Draw(const Drawable& drawable);
/**
* @brief Display the current state of the renderer to the screen
*/
void Display();
/**
* @brief Sets a maximum framerate on the display function
*
* If the maximum framerate is not 0, SDL_Delay() will be called
* after each Display() to ensure that the time between displays
* is not shorter than the framerate limit.
*
* @param[in] max The new maximum framerate
*/
void SetMaxFramerate(Uint32 max);
protected:
/**
* @brief Create Renderer and bind it to a window
*
* @param[in] target The SDL_Window to bind to
*/
RenderTarget(SDL_Window* target);
/**
* @brief Create Renderer and bind it to a texture
*
* @param[in] target The SDL_Surface to bind to
*/
RenderTarget(SDL_Surface* target);
protected:
SDL_Renderer* renderer; ///< The renderer object
private:
Uint32 m_oFramerate; ///< The current maximum framerate of the window (0 = unlimited)
std::chrono::steady_clock::time_point m_oTimeSinceLastDisplay; ///< The timepoint at which Display() was last called
};
SDLU_END

View file

@ -0,0 +1,69 @@
/**
* @file RenderWindow.hpp
* @brief A wrapper around SDL_Window and SDL_Renderer
* @author Lauchmelder23
* @date 16.05.2020
*/
#pragma once
#include <string>
#include <chrono>
#include "structures/Vector2.hpp"
#include "structures/Color.hpp"
#include "structures/Window.hpp"
#include "graphics/RenderTarget.hpp"
SDLU_BEGIN
// TODO: Probably break up into sdlu::Window and sdlu::Renderer
// to avoid passing around the Renderer when only the Window is
// needed. (See Mouse::GetPosition for example)
/**
* @brief A class that handles window related functionality
*
* A class that combines the SDL_Window and SDL_Renderer and
* behaves similar to the sf::RenderWindow from SFML. It provides
* utility and wrappers for common operations on those objects.
*/
class RenderWindow : public Window, public RenderTarget
{
public:
/**
* @brief Default Constructor. No window or renderer is created.
*/
RenderWindow();
/**
* @brief Creates a window and renderer with the given parameters
*
* @param[in] dimension A vector containing the width and height
* @param[in] title The title of the create window
*/
RenderWindow(Vector2u dimension, const std::string& title,
Uint32 windowFlags = Window::Flags::Shown);
RenderWindow(const RenderWindow& other) = delete;
RenderWindow(const RenderWindow&& other) = delete;
virtual ~RenderWindow();
protected:
/**
* @brief Function called after Window creation
*/
virtual void OnCreate();
/**
* @brief Function called after resize event
*
* @return True if the resize event should not be returned via
* PollEvent()
*/
virtual bool OnResize();
/**
* @brief Function called after closing the window
*/
virtual void OnClose();
};
SDLU_END

View file

@ -0,0 +1,30 @@
/**
* @file Drawable.hpp
* @brief The base class of everything renderable by RenderTarget
* @author Lauchmelder23
* @date 20.05.2020
*/
#pragma once
#include "Util.hpp"
struct SDL_Renderer;
SDLU_BEGIN
/**
* @brief Everything that can be rendered derives from this class.
*/
class Drawable
{
public:
Drawable(const Drawable& other) = delete;
Drawable(Drawable&& other) = delete;
Drawable& operator=(const Drawable& other) = delete;
friend class RenderTarget;
protected:
Drawable() { }
virtual void Draw(SDL_Renderer* const target) const = 0;
};
SDLU_END

View file

@ -0,0 +1,157 @@
/**
* @file Transformable.hpp
* @brief Contains information for transformable objects
* @author Lauchmelder23
* @date 23.05.2020
*/
#pragma once
#include "structures/Vector2.hpp"
SDLU_BEGIN
/**
* @brief A class that stores locational information
*
* Stores position, rotation, scale and the origin of an
* object, and provides functions to get/set those values.
* "Origin" is the offset between the position and the top-left
* corner of the object.
*/
class Transformable
{
public:
/**
* @brief Default constructur
*/
Transformable();
/**
* @brief Deconstructor
*/
virtual ~Transformable();
/**
* @brief Returns the position of the object
*
* @return A 2D vector of the position
*/
Vector2f GetPosition();
/**
* @brief Sets a new position
*
* @param[in] position A 2D vector with the new position
*/
void SetPosition(const Vector2f& position);
/**
* @brief Sets a new position
*
* @param[in] x The new x position
* @param[in] y The new y position
*/
void SetPosition(float x, float y);
/**
* @brief Adds to the current position
*
* @param[in] position A 2D movement vector
*/
void Move(const Vector2f& position);
/**
* @brief Adds to the current position
*
* @param[in] x The offset in x direction
* @param[in] y The offset in y direction
*/
void Move(float x, float y);
/**
* @brief Gets the current local origin
*
* @return A 2D vector with the offset
*/
Vector2f GetOrigin();
/**
* @brief Sets a new local origin
*
* @param[in] origin A 2D vector with the new origin
*/
void SetOrigin(const Vector2f& origin);
/**
* @brief Sets a new local origin
*
* @param[in] x The new x component of the origin
* @param[in] y The new y component of the origin
*/
void SetOrigin(float x, float y);
/**
* @brief Gets the current scale of the object
*
* @return A 2D vector with the scale in x- and y-direction
*/
Vector2f GetScale();
/**
* @brief Sets a new scale
*
* @param[in] scale A 2D vector with the new scale
*/
void SetScale(const Vector2f& scale);
/**
* @brief Sets a new scale
*
* @param[in] x The new scale in x direction
* @param[in] y The new scale in y direction
*/
void SetScale(float x, float y);
/**
* @brief Scales the object by some amount
*
* @param[in] scale The amount to scale by in x- and y-direction
*/
void Scale(const Vector2f& scale);
/**
* @brief Scales the object by some amount
*
* @param[in] x The amount to scale by in x direction
* @param[in] y The amount to scale by in y direction
*/
void Scale(float x, float y);
/**
* @brief Gets the current rotation
*
* @return The rotation in degrees
*/
float GetRotation();
/**
* @brief Sets a new rotation
*
* @param[in] angle The new rotation in degrees
*/
void SetRotation(float angle);
/**
* @brief Rotates by some amount
*
* @param[in] angle The angle to rotate by in degrees
*/
void Rotate(float angle);
protected:
Vector2f position; ///< Position of the object
Vector2f origin; ///< Offset of the top-left corner from the position
Vector2f scale; ///< Scale of the object
float rotation; ///< Rotation of the object (in degrees)
};
SDLU_END

View file

@ -0,0 +1,62 @@
/**
* @file Rectangle.hpp
* @brief The primitive Rectangle shape
* @author Lauchmelder23
* @date 23.05.2020
*/
#pragma once
#include "Shape.hpp"
namespace sdlu
{
class Rectangle :
public Shape
{
public:
/**
* @brief Default constructor
*/
Rectangle();
/**
* @brief Constructor with default parameters
*
* @param[in] position A 2D position vector
* @param[in] size A 2D size vector
*/
Rectangle(const Vector2f& position, const Vector2f& size);
/**
* @brief Gets the size of the rectangle
*
* @return A 2D vector with the size information
*/
Vector2f GetSize();
/**
* @brief Sets a new size for the rectangle
*
* @param[in] size A 2D vector with the size information
*/
void SetSize(const Vector2f& size);
/**
* @brief Sets a new size for the rectangle
*
* @param[in] x The new size in x direction
* @param[in] y The new size in y direction
*/
void SetSize(float x, float y);
/**
* @brief Draws the Rectangle to the target
*
* @param[in] target The RenderTarget to draw to
*/
virtual void Draw(SDL_Renderer* const target) const override;
private:
Vector2f size; ///< Size of the rectangle
};
}

View file

@ -0,0 +1,45 @@
/**
* @file Shape.hpp
* @brief The base class for all native SDLU shapes
* @author Lauchmelder23
* @date 23.05.2020
*/
#pragma once
#include "graphics/drawable/Drawable.hpp"
#include "graphics/drawable/Transformable.hpp"
#include "structures/Color.hpp"
SDLU_BEGIN
/**
* @brief The non-instantiable base class for all SDLU shapes
*/
class Shape :
public Drawable, public Transformable
{
public:
/**
* @brief Deconstructor
*/
virtual ~Shape();
/**
* @brief Sets the color of the shape
*/
void SetColor(const Color& color);
/**
* @brief Gets the color of the shape
*/
Color GetColor();
protected:
/**
* @brief Default constructor
*/
Shape();
protected:
Color color;
};
SDLU_END