restructured everything
This commit is contained in:
parent
4225a524b9
commit
c66cae17f2
61 changed files with 18406 additions and 1710 deletions
169
include/structures/Color.hpp
Normal file
169
include/structures/Color.hpp
Normal file
|
@ -0,0 +1,169 @@
|
|||
/**
|
||||
* @file Color.hpp
|
||||
* @brief Provides utility for creating and handling colors
|
||||
* @author Lauchmelder23
|
||||
* @date 16.05.2020
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "Util.hpp"
|
||||
|
||||
SDLU_BEGIN
|
||||
/**
|
||||
* @brief A structure holding color data
|
||||
*
|
||||
* This struct allows for the easy passing of color data between
|
||||
* objects or functions. It holds RGBA values and allows for
|
||||
* arithmetical operations.
|
||||
*/
|
||||
struct Color
|
||||
{
|
||||
Uint8 r; ///< Red component
|
||||
Uint8 g; ///< Green component
|
||||
Uint8 b; ///< Blue component
|
||||
Uint8 a; ///< Alpha component
|
||||
|
||||
/**
|
||||
* @brief Default constructor (Black)
|
||||
*/
|
||||
Color();
|
||||
|
||||
/**
|
||||
* @brief Construct color from four 8-Bit integer values
|
||||
*
|
||||
* @param[in] r Red component
|
||||
* @param[in] g Green component
|
||||
* @param[in] b Blue component
|
||||
* @param[in] a Alpha component
|
||||
*/
|
||||
Color(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255);
|
||||
|
||||
/**
|
||||
* @brief Construct color from a 32-Bit integer value
|
||||
*
|
||||
* @param[in] color The color data structured as RGBA
|
||||
*/
|
||||
Color(Uint32 color);
|
||||
|
||||
/**
|
||||
* @brief Returns color data as a 32-Bit integer
|
||||
*
|
||||
* @return A 32-Bit containing the RGBA values
|
||||
*/
|
||||
Uint32 ToInt();
|
||||
|
||||
/**
|
||||
* @brief Generate color from HSV values
|
||||
*
|
||||
* @return An RGBA Color object generated from HSV
|
||||
*/
|
||||
static Color FromHSV(Uint16 h, Uint8 s, Uint8 v);
|
||||
|
||||
|
||||
/////////////////// DEFAULT COLORS ///////////////////
|
||||
|
||||
static const Color Black; ///< Default Color Black (#000000FF)
|
||||
static const Color Red; ///< Default Color Red (#FF0000FF)
|
||||
static const Color Green; ///< Default Color Green (#00FF00FF)
|
||||
static const Color Blue; ///< Default Color Blue (#0000FFFF)
|
||||
static const Color Yellow; ///< Default Color Yellow (#FFFF00FF)
|
||||
static const Color Magenta; ///< Default Color Magenta (#FF00FFFF)
|
||||
static const Color Cyan; ///< Default Color Cyan (#00FFFFFF)
|
||||
static const Color White; ///< Default Color White (#FFFFFFFF)
|
||||
|
||||
static const Color Transparent; ///< Default Color Transparent (#00000000)
|
||||
|
||||
|
||||
/////////////////// OPERATOR OVERLOADS ///////////////////
|
||||
|
||||
/**
|
||||
* @brief Componentwise color addition
|
||||
*
|
||||
* @param[in] left Left operand
|
||||
* @param[in] right Right operand
|
||||
* @return left + right
|
||||
*/
|
||||
friend Color operator+(const Color& left, const Color& right);
|
||||
|
||||
/**
|
||||
* @brief Componentwise color subtraction
|
||||
*
|
||||
* @param[in] left Left operand
|
||||
* @param[in] right Right operand
|
||||
* @return left - right
|
||||
*/
|
||||
friend Color operator-(const Color& left, const Color& right);
|
||||
|
||||
/**
|
||||
* @brief Componentwise color multiplication
|
||||
*
|
||||
* @param[in] left Left operand
|
||||
* @param[in] right Right operand
|
||||
* @return left * right
|
||||
*/
|
||||
friend Color operator*(const Color& left, const Color& right);
|
||||
|
||||
/**
|
||||
* @brief Componentwise color division
|
||||
*
|
||||
* @param[in] left Left operand
|
||||
* @param[in] right Right operand
|
||||
* @return left / right
|
||||
*/
|
||||
friend Color operator/(const Color& left, const Color& right);
|
||||
|
||||
/**
|
||||
* @brief Componentwise color addition
|
||||
*
|
||||
* @param[in] left Left operand
|
||||
* @param[in] right Right operand
|
||||
* @return left += right
|
||||
*/
|
||||
friend Color& operator+=(Color& left, const Color& right);
|
||||
|
||||
/**
|
||||
* @brief Componentwise color subtraction
|
||||
*
|
||||
* @param[in] left Left operand
|
||||
* @param[in] right Right operand
|
||||
* @return left -= right
|
||||
*/
|
||||
friend Color& operator-=(Color& left, const Color& right);
|
||||
|
||||
/**
|
||||
* @brief Componentwise color multiplication
|
||||
*
|
||||
* @param[in] left Left operand
|
||||
* @param[in] right Right operand
|
||||
* @return left *= right
|
||||
*/
|
||||
friend Color& operator*=(Color& left, const Color& right);
|
||||
|
||||
/**
|
||||
* @brief Componentwise color division
|
||||
*
|
||||
* @param[in] left Left operand
|
||||
* @param[in] right Right operand
|
||||
* @return left /= right
|
||||
*/
|
||||
friend Color& operator/=(Color& left, const Color& right);
|
||||
|
||||
/**
|
||||
* @brief Componentwise color comparison
|
||||
*
|
||||
* @param[in] left Left operand
|
||||
* @param[in] right Right operand
|
||||
* @return True if the respective color components are equal, False if not
|
||||
*/
|
||||
friend bool operator==(const Color& left, const Color& right);
|
||||
|
||||
/**
|
||||
* @brief Componentwise color comparison
|
||||
*
|
||||
* @param[in] left Left operand
|
||||
* @param[in] right Right operand
|
||||
* @return False if the respective color components are equal, True if not
|
||||
*/
|
||||
friend bool operator!=(const Color& left, const Color& right);
|
||||
};
|
||||
SDLU_END
|
75
include/structures/Mouse.hpp
Normal file
75
include/structures/Mouse.hpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* @file Mouse.hpp
|
||||
* @brief A static class to provide easy handling of the mouse
|
||||
* @author Lauchmelder23
|
||||
* @date 19.05.2020
|
||||
*/
|
||||
#pragma once
|
||||
#include "structures/Vector2.hpp"
|
||||
#include "graphics/RenderWindow.hpp"
|
||||
|
||||
SDLU_BEGIN
|
||||
/**
|
||||
* @brief A static class that contains/handles data about
|
||||
* mouse position and button states
|
||||
*/
|
||||
class Mouse
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Mouse buttons
|
||||
*/
|
||||
enum class Button {
|
||||
Left = 1,
|
||||
Right = 2,
|
||||
Middle = 3,
|
||||
XButton1 = 4,
|
||||
XButton2 = 5
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Returns the current mouse button state
|
||||
*
|
||||
* @return A 32-bit mask of the current button state
|
||||
*/
|
||||
static Uint32 GetButtonState();
|
||||
|
||||
/**
|
||||
* @brief Checks if a specific button is pressed
|
||||
*
|
||||
* @param[in] button The button to check
|
||||
* @return True if the button is pressed
|
||||
*/
|
||||
static bool IsButtonDown(Button button);
|
||||
|
||||
/**
|
||||
* @brief Gets the absolute position of the mouse
|
||||
*
|
||||
* @return Current mouse position relative to screen
|
||||
*/
|
||||
static Vector2i GetPosition();
|
||||
|
||||
/**
|
||||
* @brief Gets current relative position of the mouse
|
||||
*
|
||||
* @param[in] relativeTo The window the mouse position should be relative to
|
||||
* @return The position of the mouse relative to the top left of the passed window object
|
||||
*/
|
||||
static Vector2i GetPosition(const RenderWindow& relativeTo);
|
||||
|
||||
/**
|
||||
* @brief Sets the absolute position of the mouse
|
||||
*
|
||||
* @param[in] position A 2D vector of the new position
|
||||
*/
|
||||
static void SetPosition(const Vector2i& position);
|
||||
|
||||
/**
|
||||
* @brief Sets current relative position of the mouse
|
||||
*
|
||||
* @param[in] position A 2D vector of the new position
|
||||
* @param[in] relativeTo The window the mouse position should be relative to
|
||||
*/
|
||||
static void SetPosition(const Vector2i& position, const RenderWindow& relativeTo);
|
||||
};
|
||||
SDLU_END
|
154
include/structures/Vector2.hpp
Normal file
154
include/structures/Vector2.hpp
Normal file
|
@ -0,0 +1,154 @@
|
|||
/**
|
||||
* @file Vector2.hpp
|
||||
* @brief Provides a structure for simple vector calculations
|
||||
* @author Lauchmelder23
|
||||
* @date 16.05.2020
|
||||
*/
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
|
||||
#include "Util.hpp"
|
||||
|
||||
SDLU_BEGIN
|
||||
/**
|
||||
* @brief A struct to handle basic 2D vector operations.
|
||||
*
|
||||
* @tparam T The (arithmetical) type of the vector components
|
||||
*/
|
||||
template<
|
||||
typename T,
|
||||
typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type
|
||||
> struct Vector2
|
||||
{
|
||||
T x; ///< x component
|
||||
T y; ///< y component
|
||||
|
||||
//################## CONSTRUCTORS ##################//
|
||||
|
||||
/// Initializes a zero vector
|
||||
Vector2() :
|
||||
x(0), y(0)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
/// Initializes a vector with default values
|
||||
Vector2(T x, T y) :
|
||||
x(x), y(y)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
/// Copies the components of a vector
|
||||
Vector2(const Vector2<T>& other) :
|
||||
x(other.x), y(other.y)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
|
||||
//################## OPERATORS ##################//
|
||||
|
||||
friend Vector2<T> operator-(const Vector2<T>& right)
|
||||
{
|
||||
return Vector2<T>(-right.x, -right.y);
|
||||
}
|
||||
|
||||
friend Vector2<T> operator+(const Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
return Vector2<T>(left.x + right.x, left.y + right.y);
|
||||
}
|
||||
|
||||
friend Vector2<T> operator-(const Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
return left + (-right);
|
||||
}
|
||||
|
||||
friend Vector2<T> operator*(const Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
return Vector2<T>(left.x * right.x, left.y * right.y);
|
||||
}
|
||||
|
||||
friend Vector2<T> operator/(const Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
return Vector2<T>(left.x / right.x, left.y / right.y);
|
||||
}
|
||||
|
||||
friend Vector2<T> operator*(T left, const Vector2<T>& right)
|
||||
{
|
||||
return Vector2<T>(left * right.x, left * right.y);
|
||||
}
|
||||
|
||||
friend Vector2<T> operator*(const Vector2<T>& left, T right)
|
||||
{
|
||||
return right * left;
|
||||
}
|
||||
|
||||
friend Vector2<T> operator/(const Vector2<T>& left, T right)
|
||||
{
|
||||
return Vector2<T>(left.x / right, left.y / right);
|
||||
}
|
||||
|
||||
friend Vector2<T>& operator+=(Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
left.x += right.x;
|
||||
left.y += right.y;
|
||||
return left;
|
||||
}
|
||||
|
||||
friend Vector2<T>& operator-=(Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
left += (-right);
|
||||
return left;
|
||||
}
|
||||
|
||||
friend Vector2<T>& operator*=(Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
left.x *= right.x;
|
||||
left.y *= right.y;
|
||||
return left;
|
||||
}
|
||||
|
||||
friend Vector2<T>& operator/(Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
left.x /= right.x;
|
||||
left.y /= right.y;
|
||||
return left;
|
||||
}
|
||||
|
||||
friend Vector2<T>& operator*=(Vector2<T>& left, T right)
|
||||
{
|
||||
left.x *= right;
|
||||
left.y *= right;
|
||||
return left;
|
||||
}
|
||||
|
||||
friend Vector2<T>& operator/=(Vector2<T>& left, T right)
|
||||
{
|
||||
left.x /= right;
|
||||
left.y /= right;
|
||||
return left;
|
||||
}
|
||||
|
||||
friend bool operator==(const Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
return ((left.x == right.x) && (left.y == right.y));
|
||||
}
|
||||
|
||||
friend bool operator!=(const Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//################## TYPEDEFS ##################//
|
||||
|
||||
typedef Vector2<unsigned int> Vector2u, Vec2u;
|
||||
typedef Vector2<int> Vector2i, Vec2i;
|
||||
typedef Vector2<float> Vector2f, Vec2f;
|
||||
typedef Vector2<double> Vector2d, Vec2d;
|
||||
|
||||
SDLU_END
|
279
include/structures/Window.hpp
Normal file
279
include/structures/Window.hpp
Normal file
|
@ -0,0 +1,279 @@
|
|||
/**
|
||||
* @file Window.hpp
|
||||
* @brief Contains window related objects
|
||||
* @author Lauchmelder23
|
||||
* @date 20.05.20
|
||||
*/
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
#include "Util.hpp"
|
||||
#include "structures/Vector2.hpp"
|
||||
|
||||
struct SDL_Window;
|
||||
union SDL_Event;
|
||||
struct SDL_Surface;
|
||||
struct SDL_Cursor;
|
||||
|
||||
SDLU_BEGIN
|
||||
/**
|
||||
* @brief Stores information about a window. You probably want RenderWindow.
|
||||
*/
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
enum Flags {
|
||||
Fullscreen = ((Uint32)1 << 0),
|
||||
OpenGL = ((Uint32)1 << 1),
|
||||
Shown = ((Uint32)1 << 2),
|
||||
Hidden = ((Uint32)1 << 3),
|
||||
Borderless = ((Uint32)1 << 4),
|
||||
Resizable = ((Uint32)1 << 5),
|
||||
Minimized = ((Uint32)1 << 6),
|
||||
Maximized = ((Uint32)1 << 7),
|
||||
InputGrabbed = ((Uint32)1 << 8),
|
||||
InputFocus = ((Uint32)1 << 9),
|
||||
MouseFocus = ((Uint32)1 << 10),
|
||||
Foregin = ((Uint32)1 << 11),
|
||||
FullscreenDesktop = (Fullscreen | ((Uint32)1 << 12)),
|
||||
};
|
||||
public:
|
||||
/**
|
||||
* @brief Default Constructor. No window is created.
|
||||
*/
|
||||
Window();
|
||||
|
||||
/**
|
||||
* @brief Creates a window with the given parameters
|
||||
*
|
||||
* @param[in] dimension A vector containing the width and height
|
||||
* @param[in] title The title of the create window
|
||||
*/
|
||||
Window(Vector2u dimension, const std::string& title,
|
||||
Uint32 windowFlags);
|
||||
|
||||
Window(const Window& other) = delete;
|
||||
Window(Window&& other) = delete;
|
||||
|
||||
virtual ~Window();
|
||||
|
||||
/**
|
||||
* @brief Creates the window.
|
||||
*
|
||||
* This function creates the SDL_Window object. If
|
||||
* they were already created the function does nothing and returns.
|
||||
* If it fails to create either, an ObjectCreationException is thrown.
|
||||
*
|
||||
* @param[in] dimension A vector containing the width and height
|
||||
* @param[in] title The title of the create window
|
||||
*/
|
||||
void Create(Vector2u dimension, const std::string& title,
|
||||
Uint32 windowFlags);
|
||||
|
||||
/**
|
||||
* @brief Destroys the window.
|
||||
*/
|
||||
void Close();
|
||||
|
||||
/**
|
||||
* @brief Wether or not the window object is created
|
||||
*
|
||||
* @return True if the window is open, False if not
|
||||
*/
|
||||
bool IsOpen() const;
|
||||
|
||||
/**
|
||||
* @brief A non-blocking event polling function
|
||||
*
|
||||
* @param[out] event An object to write the latest event to
|
||||
* @return True if there was an event, False if there wasn't
|
||||
*/
|
||||
bool PollEvent(SDL_Event* event);
|
||||
|
||||
/**
|
||||
* @brief A blocking event polling function
|
||||
*
|
||||
* @param[out] event An object to write the latest event to
|
||||
* @return True if an event was polled
|
||||
*/
|
||||
bool WaitEvent(SDL_Event* event);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns the current position of the window
|
||||
*
|
||||
* @return A vector with the current position relative to the top left corner of the display
|
||||
*/
|
||||
Vector2i GetPosition() const;
|
||||
|
||||
/**
|
||||
* @brief Sets a new window position
|
||||
*
|
||||
* @param[in] position A vector with the new position
|
||||
*/
|
||||
void SetPosition(Vector2i position);
|
||||
|
||||
/**
|
||||
* @brief Sets a new window position
|
||||
*
|
||||
* @param[in] x The new x position
|
||||
* @param[in] y The new y position
|
||||
*/
|
||||
void SetPosition(int x, int y);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets the current window size
|
||||
*
|
||||
* @return A vector with the windows size
|
||||
*/
|
||||
Vector2u GetSize() const;
|
||||
|
||||
/**
|
||||
* @brief Sets a new window size
|
||||
*
|
||||
* @param[in] size A vector with the new size
|
||||
*/
|
||||
void SetSize(Vector2u size);
|
||||
|
||||
/**
|
||||
* @brief Sets a new window size
|
||||
*
|
||||
* @param[in] width The new width of the window
|
||||
* @param[in] height The new height of the window
|
||||
*/
|
||||
void SetSize(unsigned int width, unsigned int height);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets the current window title
|
||||
*
|
||||
* @return The title of the widnow
|
||||
*/
|
||||
std::string GetTitle() const;
|
||||
|
||||
/**
|
||||
* @brief Sets a new window title
|
||||
*
|
||||
* @param[in] title The new window title
|
||||
*/
|
||||
void SetTitle(std::string title);
|
||||
|
||||
/**
|
||||
* @brief Returns a constant pointer to the SDL_Window
|
||||
*
|
||||
* @return A constant pointer to SDL_Window
|
||||
*/
|
||||
SDL_Window* const GetWindow() const;
|
||||
|
||||
/**
|
||||
* @brief Set the windows visibility
|
||||
*
|
||||
* @param[in] visible The new visibility setting
|
||||
*/
|
||||
void SetVisible(bool visible);
|
||||
|
||||
/**
|
||||
* @brief (De)activates VSync !globally!
|
||||
*
|
||||
* @param[in] vsync Wether to enable or disable vsync
|
||||
*/
|
||||
void SetVsync(bool vsync);
|
||||
|
||||
/**
|
||||
* @brief Hides/Shows the mouse cursor inside the windos
|
||||
*
|
||||
* @param[in] visible The new visibility of the cursor
|
||||
*/
|
||||
void SetMouseCursorVisible(bool visible);
|
||||
|
||||
/**
|
||||
* @brief Traps the mouse cursor inside the window
|
||||
*
|
||||
* @param[in] grabbed Wether to (un)trap the cursor
|
||||
*/
|
||||
void SetMouseCursorGrabbed(bool grabbed);
|
||||
|
||||
/**
|
||||
* @brief Sets the window icon to an array of RGBA values
|
||||
*
|
||||
* @param[in] width Width of the icon (in px)
|
||||
* @param[in] height Height of the icon (in px)
|
||||
* @param[in] pixels Array of color data (RGBA as seperate 8-Bit integer values)
|
||||
*/
|
||||
void SetIcon(Uint32 width, Uint32 height, const Uint8* pixels);
|
||||
|
||||
/**
|
||||
* @brief Sets the window icon to an array of RGBA values
|
||||
*
|
||||
* @param[in] width Width of the icon (in px)
|
||||
* @param[in] height Height of the icon (in px)
|
||||
* @param[in] pixels Array of color data (RGBA as one 32-Bit integer value)
|
||||
*/
|
||||
void SetIcon(Uint32 width, Uint32 height, const Uint32* pixels);
|
||||
|
||||
/**
|
||||
* @brief Sets the window icon to a SDL_Surface
|
||||
*
|
||||
* @param[in] icon A SDL_Surface* holding the icon data
|
||||
*/
|
||||
void SetIcon(SDL_Surface* icon);
|
||||
|
||||
/**
|
||||
* @brief Changes the mouse cursor
|
||||
*
|
||||
* @param[in] cursor A pointer to a SDL_Cursor containing cursor data
|
||||
*/
|
||||
void SetMouseCursor(SDL_Cursor* cursor);
|
||||
|
||||
/**
|
||||
* @brief Changes the mouse cursor
|
||||
*
|
||||
* @param[in] surface A pointer to a SDL_Surface containing sprite data
|
||||
* @param[in] clickspot The effective position of the cursor relative to the top left of the sprite
|
||||
*/
|
||||
void SetMouseCursor(SDL_Surface* surface, Vector2u clickspot);
|
||||
|
||||
/**
|
||||
* @brief Changes the mouse cursor
|
||||
*
|
||||
* @param[in] pixels An array of color data (RGBA as seperate 8-bit values)
|
||||
* @param[in] size Size of the cursor
|
||||
* @param[in] clickspot The effective position of the cursor relative to the top left of the sprite
|
||||
*/
|
||||
void SetMouseCursor(const Uint8* pixels, Vector2u size, Vector2u clickspot);
|
||||
|
||||
/**
|
||||
* @brief Changes the mouse cursor
|
||||
*
|
||||
* @param[in] pixels An array of color data (RGBA as one 32-bit value)
|
||||
* @param[in] size Size of the cursor
|
||||
* @param[in] clickspot The effective position of the cursor relative to the top left of the sprite
|
||||
*/
|
||||
void SetMouseCursor(const Uint32* pixels, Vector2u size, Vector2u clickspot);
|
||||
|
||||
protected:
|
||||
SDL_Window* window;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief This function is called after Create() finishes
|
||||
*/
|
||||
virtual void OnCreate();
|
||||
|
||||
/**
|
||||
* @brief This function is called after a SDL_WINDOWEVENT_RESIZED is polled.
|
||||
* (PollEvent() must be called for this to work)
|
||||
*
|
||||
* @return True if the resize event should be popped from the event queue before
|
||||
returning the polled event to the user
|
||||
*/
|
||||
virtual bool OnResize();
|
||||
|
||||
/**
|
||||
* @brief This function is called after Close() finishes.
|
||||
*/
|
||||
virtual void OnClose();
|
||||
};
|
||||
SDLU_END
|
Loading…
Add table
Add a link
Reference in a new issue