restructured everything
This commit is contained in:
parent
4225a524b9
commit
c66cae17f2
0
.gitmodules
vendored
0
.gitmodules
vendored
|
@ -2,12 +2,35 @@ cmake_minimum_required(VERSION 3.8)
|
||||||
|
|
||||||
project(sdlu)
|
project(sdlu)
|
||||||
|
|
||||||
if(NOT ENABLE_EXAMPLE)
|
find_package(SDL2 CONFIG REQUIRED)
|
||||||
set(ENABLE_EXAMPLE CACHE BOOL OFF)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_subdirectory(3rdparty/SDL)
|
option(BUILD_EXAMPLES "Builds the example projects" ON)
|
||||||
add_subdirectory(SDLU)
|
|
||||||
if(ENABLE_EXAMPLE)
|
add_subdirectory(lib/sdl2_gfx)
|
||||||
add_subdirectory(SDLU_Example)
|
|
||||||
|
file(GLOB_RECURSE sdlu_includes
|
||||||
|
"include/*.hpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE sdlu_sources
|
||||||
|
"src/*.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(sdlu
|
||||||
|
${sdlu_includes} ${sdlu_sources}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(sdlu PUBLIC
|
||||||
|
"include"
|
||||||
|
SDL2::SDL2
|
||||||
|
sdl2_gfx
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(sdlu PUBLIC
|
||||||
|
sdl2_gfx
|
||||||
|
SDL2::SDL2 SDL2::SDL2main
|
||||||
|
)
|
||||||
|
|
||||||
|
if(BUILD_EXAMPLES)
|
||||||
|
add_subdirectory(examples)
|
||||||
endif()
|
endif()
|
|
@ -1,23 +0,0 @@
|
||||||
set(PNAME SDLU)
|
|
||||||
|
|
||||||
add_library(${PNAME}
|
|
||||||
alibi.cpp SDLU.hpp Util.hpp
|
|
||||||
"structures/Color.cpp" "structures/Mouse.cpp" "structures/Window.cpp" "graphics/RenderTarget.cpp" "graphics/drawable/Transformable.cpp" "graphics/drawable/shapes/Rectangle.cpp")
|
|
||||||
|
|
||||||
set_property(TARGET ${PNAME} PROPERTY CXX_STANDARD 17)
|
|
||||||
|
|
||||||
target_include_directories(${PNAME} PRIVATE
|
|
||||||
${PROJECT_SOURCE_DIR}/3rdparty/SDL/include
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(${PNAME}
|
|
||||||
SDL2
|
|
||||||
)
|
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
||||||
target_link_libraries(${PNAME} m)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_subdirectory(structures)
|
|
||||||
add_subdirectory(graphics)
|
|
|
@ -1,7 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "graphics/Graphics.hpp"
|
|
||||||
|
|
||||||
#include "structures/Mouse.hpp"
|
|
||||||
|
|
||||||
#include "exceptions/Exceptions.hpp"
|
|
|
@ -1 +0,0 @@
|
||||||
// CMake needs a .cpp file to build
|
|
|
@ -1,12 +0,0 @@
|
||||||
/**
|
|
||||||
* @file Exceptions.hpp
|
|
||||||
* @brief Provides utility and includes all exceptions
|
|
||||||
* @author Lauchmelder23
|
|
||||||
* @date 16.05.2020
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "ObjectCreationException.hpp"
|
|
||||||
|
|
||||||
#define THROW_IF( condition, exception ) ( condition ? throw exception : false)
|
|
||||||
#define THROW_IF_NOT( condition, exception ) ( THROW_IF(!condition, exception) )
|
|
|
@ -1,31 +0,0 @@
|
||||||
/**
|
|
||||||
* @file ObjectCreationException.hpp
|
|
||||||
* @brief An exception object to handle failed object creations
|
|
||||||
* @author Lauchmelder23
|
|
||||||
* @date 16.05.2020
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
#include <exception>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
class ObjectCreationException :
|
|
||||||
virtual public std::exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ObjectCreationException(std::string description) :
|
|
||||||
m_pDescription(description)
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const char* what() const throw()
|
|
||||||
{
|
|
||||||
return m_pDescription.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string m_pDescription;
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
target_sources(${PNAME} PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Graphics.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/RenderWindow.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/RenderWindow.cpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/RenderTarget.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/RenderTarget.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_subdirectory(drawable)
|
|
|
@ -1,86 +0,0 @@
|
||||||
#include "RenderTarget.hpp"
|
|
||||||
|
|
||||||
#include <Util.hpp>
|
|
||||||
#include <exceptions/Exceptions.hpp>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
Uint32 RenderTarget::m_uRenderers = -1;
|
|
||||||
|
|
||||||
RenderTarget::~RenderTarget()
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(renderer);
|
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderTarget::Clear(const Color& color)
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(renderer);
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderTarget::Draw(const Drawable& drawable)
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(renderer);
|
|
||||||
|
|
||||||
drawable.Draw(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderTarget::Display()
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(renderer);
|
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
|
|
||||||
if (m_oFramerate != 0)
|
|
||||||
{
|
|
||||||
Uint64 diff = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
||||||
std::chrono::steady_clock::now() - m_oTimeSinceLastDisplay).count();
|
|
||||||
|
|
||||||
if (diff < 1000 / m_oFramerate)
|
|
||||||
{
|
|
||||||
SDL_Delay(static_cast<Uint32>(1000 / m_oFramerate - diff));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_oTimeSinceLastDisplay = std::chrono::steady_clock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderTarget::SetMaxFramerate(Uint32 max)
|
|
||||||
{
|
|
||||||
m_oFramerate = max;
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderTarget::RenderTarget(SDL_Window* target) :
|
|
||||||
renderer(nullptr), m_oFramerate(0)
|
|
||||||
{
|
|
||||||
RETURN_IF_NOT_NULLPTR(renderer);
|
|
||||||
renderer = SDL_CreateRenderer(target, m_uRenderers, SDL_RENDERER_ACCELERATED);
|
|
||||||
|
|
||||||
THROW_IF(IS_NULLPTR(renderer),
|
|
||||||
sdlu::ObjectCreationException("Failed to create SDL_Renderer* from SDL_Window*: "
|
|
||||||
+ std::string(SDL_GetError())));
|
|
||||||
m_uRenderers++;
|
|
||||||
|
|
||||||
m_oTimeSinceLastDisplay = std::chrono::steady_clock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderTarget::RenderTarget(SDL_Surface* target) :
|
|
||||||
renderer(nullptr), m_oFramerate(0)
|
|
||||||
{
|
|
||||||
m_oFramerate = 0;
|
|
||||||
|
|
||||||
RETURN_IF_NOT_NULLPTR(renderer);
|
|
||||||
renderer = SDL_CreateSoftwareRenderer(target);
|
|
||||||
|
|
||||||
THROW_IF(IS_NULLPTR(renderer),
|
|
||||||
sdlu::ObjectCreationException("Failed to create SDL_Renderer* from SDL_Surface*: "
|
|
||||||
+ std::string(SDL_GetError())));
|
|
||||||
m_uRenderers++;
|
|
||||||
|
|
||||||
m_oTimeSinceLastDisplay = std::chrono::steady_clock::now();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,81 +0,0 @@
|
||||||
/**
|
|
||||||
* @file RenderTarget
|
|
||||||
* @brief Contains rendering related objects
|
|
||||||
* @author Lauchmelder23
|
|
||||||
* @date 20.05.2020
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
#include <SDL.h>
|
|
||||||
|
|
||||||
#include <structures/Color.hpp>
|
|
||||||
#include <graphics/drawable/Drawable.hpp>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @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
|
|
||||||
|
|
||||||
static Uint32 m_uRenderers; ///< The number of renderers instantiated so far
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
#include "RenderWindow.hpp"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#include <exceptions/Exceptions.hpp>
|
|
||||||
#include <Util.hpp>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
RenderWindow::RenderWindow() :
|
|
||||||
Window(), RenderTarget(window)
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderWindow::RenderWindow(Vector2u dimension, const std::string& title,
|
|
||||||
Uint32 windowFlags) :
|
|
||||||
Window(dimension, title, windowFlags), RenderTarget(window)
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderWindow::~RenderWindow()
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderWindow::OnCreate()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderWindow::OnResize()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderWindow::OnClose()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
/**
|
|
||||||
* @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 <SDL.h>
|
|
||||||
|
|
||||||
#include <structures/Vector2.hpp>
|
|
||||||
#include <structures/Color.hpp>
|
|
||||||
#include <structures/Window.hpp>
|
|
||||||
#include <graphics/RenderTarget.hpp>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
// 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 = SDL_WINDOW_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();
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
target_sources(${PNAME} PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Drawable.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Transformable.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Transformable.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_subdirectory( shapes )
|
|
|
@ -1,29 +0,0 @@
|
||||||
/**
|
|
||||||
* @file Drawable.hpp
|
|
||||||
* @brief The base class of everything renderable by RenderTarget
|
|
||||||
* @author Lauchmelder23
|
|
||||||
* @date 20.05.2020
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL.h>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @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;
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
#include "Transformable.hpp"
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
Transformable::Transformable() :
|
|
||||||
position(0, 0), origin(0, 0),
|
|
||||||
scale(1.f, 1.f), rotation(0.f)
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
Transformable::~Transformable()
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2f Transformable::GetPosition()
|
|
||||||
{
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::SetPosition(const Vector2f& position)
|
|
||||||
{
|
|
||||||
this->position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::SetPosition(float x, float y)
|
|
||||||
{
|
|
||||||
position = Vector2f(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::Move(const Vector2f& position)
|
|
||||||
{
|
|
||||||
this->position += position;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::Move(float x, float y)
|
|
||||||
{
|
|
||||||
position += Vector2f(x, y);
|
|
||||||
}
|
|
||||||
Vector2f Transformable::GetOrigin()
|
|
||||||
{
|
|
||||||
return origin;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::SetOrigin(const Vector2f& origin)
|
|
||||||
{
|
|
||||||
this->origin = origin;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::SetOrigin(float x, float y)
|
|
||||||
{
|
|
||||||
origin = Vector2f(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2f Transformable::GetScale()
|
|
||||||
{
|
|
||||||
return scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::SetScale(const Vector2f& scale)
|
|
||||||
{
|
|
||||||
this->scale = scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::SetScale(float x, float y)
|
|
||||||
{
|
|
||||||
scale = Vector2f(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::Scale(const Vector2f& scale)
|
|
||||||
{
|
|
||||||
this->scale += scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::Scale(float x, float y)
|
|
||||||
{
|
|
||||||
scale += Vector2f(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
float Transformable::GetRotation()
|
|
||||||
{
|
|
||||||
return rotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::SetRotation(float angle)
|
|
||||||
{
|
|
||||||
rotation = angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Transformable::Rotate(float angle)
|
|
||||||
{
|
|
||||||
rotation += angle;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,158 +0,0 @@
|
||||||
/**
|
|
||||||
* @file Transformable.hpp
|
|
||||||
* @brief Contains information for transformable objects
|
|
||||||
* @author Lauchmelder23
|
|
||||||
* @date 23.05.2020
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <structures/Vector2.hpp>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @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)
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
target_sources(${PNAME} PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Shape.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Shape.cpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Rectangle.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Rectangle.cpp
|
|
||||||
)
|
|
|
@ -1,46 +0,0 @@
|
||||||
/**
|
|
||||||
* @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>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @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;
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
target_sources(${PNAME} PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Vector2.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Color.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Color.cpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Mouse.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Mouse.cpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Window.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Window.cpp
|
|
||||||
)
|
|
|
@ -1,163 +0,0 @@
|
||||||
#include "Color.hpp"
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
const Color Color::Black = Color(0, 0, 0);
|
|
||||||
const Color Color::Red = Color(255, 0, 0);
|
|
||||||
const Color Color::Green = Color(0, 255, 0);
|
|
||||||
const Color Color::Blue = Color(0, 0, 255);
|
|
||||||
const Color Color::Yellow = Color(255, 255, 0);
|
|
||||||
const Color Color::Magenta = Color(255, 0, 255);
|
|
||||||
const Color Color::Cyan = Color(0, 255, 255);
|
|
||||||
const Color Color::White = Color(255, 255, 255);
|
|
||||||
|
|
||||||
const Color Color::Transparent = Color(0, 0, 0, 0);
|
|
||||||
|
|
||||||
Color::Color() :
|
|
||||||
r(0), g(0), b(0), a(0)
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
Color::Color(Uint8 r, Uint8 g, Uint8 b, Uint8 a) :
|
|
||||||
r(r), g(g), b(b), a(a)
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
Color::Color(Uint32 color) :
|
|
||||||
r((color & 0xFF000000) >> 24),
|
|
||||||
g((color & 0x00FF0000) >> 16),
|
|
||||||
b((color & 0x0000FF00) >> 8),
|
|
||||||
a((color & 0x000000FF))
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint32 Color::ToInt()
|
|
||||||
{
|
|
||||||
Uint32 color = 0;
|
|
||||||
color |= r << 24;
|
|
||||||
color |= g << 16;
|
|
||||||
color |= b << 8;
|
|
||||||
color |= a;
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color Color::FromHSV(Uint16 h, Uint8 s, Uint8 v)
|
|
||||||
{
|
|
||||||
// Normalize parameters
|
|
||||||
// H : [0, 360)
|
|
||||||
// S : [0, 1]
|
|
||||||
// V : [0, 1]
|
|
||||||
h -= std::floor(h / 360) * 360;
|
|
||||||
s = (s > 1) ? 1 : s;
|
|
||||||
v = (v > 1) ? 1 : v;
|
|
||||||
|
|
||||||
// Convert to RGBA
|
|
||||||
Uint16 H = std::floor(h / 60.f);
|
|
||||||
float f = (h / 60.f) - H;
|
|
||||||
|
|
||||||
Uint8 p = static_cast<Uint8>((v * (1 - s)) * 255);
|
|
||||||
Uint8 q = static_cast<Uint8>((v * (1 - s * f)) * 255);
|
|
||||||
Uint8 t = static_cast<Uint8>((v * (1 - s * (1 - f))) * 255);
|
|
||||||
v *= 255;
|
|
||||||
|
|
||||||
Color output;
|
|
||||||
switch (H)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
case 6:
|
|
||||||
output = Color(v, t, p);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
output = Color(q, v, p);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
output = Color(p, v, t);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
output = Color(p, q, v);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
output = Color(t, p, v);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
output = Color(v, p, q);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color operator+(const Color& left, const Color& right)
|
|
||||||
{
|
|
||||||
return Color((UINT8_MAX - left.r) < right.r ? 255 : left.r + right.r,
|
|
||||||
(UINT8_MAX - left.g) < right.g ? 255 : left.g + right.g,
|
|
||||||
(UINT8_MAX - left.b) < right.b ? 255 : left.b + right.b,
|
|
||||||
(UINT8_MAX - left.a) < right.a ? 255 : left.a + right.a);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color operator-(const Color& left, const Color& right)
|
|
||||||
{
|
|
||||||
return Color(left.r < right.r ? 0 : left.r - right.r,
|
|
||||||
left.g < right.g ? 0 : left.g - right.g,
|
|
||||||
left.b < right.b ? 0 : left.b - right.b,
|
|
||||||
left.a < right.a ? 0 : left.a - right.a);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color operator*(const Color& left, const Color& right)
|
|
||||||
{
|
|
||||||
return Color((UINT8_MAX / left.r) < right.r ? 255 : left.r * right.r,
|
|
||||||
(UINT8_MAX / left.g) < right.g ? 255 : left.g * right.g,
|
|
||||||
(UINT8_MAX / left.b) < right.b ? 255 : left.b * right.b,
|
|
||||||
(UINT8_MAX / left.a) < right.a ? 255 : left.a * right.a);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color operator/(const Color& left, const Color& right)
|
|
||||||
{
|
|
||||||
return Color(left.r / right.r,
|
|
||||||
left.g / right.g,
|
|
||||||
left.b / right.b,
|
|
||||||
left.a / right.a);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color& operator+=(Color& left, const Color& right)
|
|
||||||
{
|
|
||||||
left = left + right;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color& operator-=(Color& left, const Color& right)
|
|
||||||
{
|
|
||||||
left = left - right;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color& operator*=(Color& left, const Color& right)
|
|
||||||
{
|
|
||||||
left = left * right;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color& operator/=(Color& left, const Color& right)
|
|
||||||
{
|
|
||||||
left = left / right;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const Color& left, const Color& right)
|
|
||||||
{
|
|
||||||
return ((left.r == right.r) && (left.g == right.g) && (left.b == right.b) && (left.a == right.a));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const Color& left, const Color& right)
|
|
||||||
{
|
|
||||||
return !(left == right);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
#include "Mouse.hpp"
|
|
||||||
|
|
||||||
#include <SDL_mouse.h>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
Uint32 Mouse::GetButtonState()
|
|
||||||
{
|
|
||||||
return SDL_GetMouseState(NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Mouse::IsButtonDown(Button button)
|
|
||||||
{
|
|
||||||
return (GetButtonState() & SDL_BUTTON(button));
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2i Mouse::GetPosition()
|
|
||||||
{
|
|
||||||
int x = 0, y = 0;
|
|
||||||
SDL_GetGlobalMouseState(&x, &y);
|
|
||||||
return Vector2i(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2i Mouse::GetPosition(const RenderWindow& relativeTo)
|
|
||||||
{
|
|
||||||
return GetPosition() - relativeTo.GetPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mouse::SetPosition(const Vector2i& position)
|
|
||||||
{
|
|
||||||
SDL_WarpMouseGlobal(position.x, position.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mouse::SetPosition(const Vector2i& position, const RenderWindow& relativeTo)
|
|
||||||
{
|
|
||||||
SDL_WarpMouseInWindow(relativeTo.GetWindow(), position.x, position.y);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,77 +0,0 @@
|
||||||
/**
|
|
||||||
* @file Mouse.hpp
|
|
||||||
* @brief A static class to provide easy handling of the mouse
|
|
||||||
* @author Lauchmelder23
|
|
||||||
* @date 19.05.2020
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
#include <SDL_mouse.h>
|
|
||||||
#include <structures/Vector2.hpp>
|
|
||||||
#include <graphics/RenderWindow.hpp>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @brief A static class that contains/handles data about
|
|
||||||
* mouse position and button states
|
|
||||||
*/
|
|
||||||
class Mouse
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Mouse buttons
|
|
||||||
*/
|
|
||||||
enum Button {
|
|
||||||
Left = SDL_BUTTON_LEFT,
|
|
||||||
Right = SDL_BUTTON_RIGHT,
|
|
||||||
Middle = SDL_BUTTON_MIDDLE,
|
|
||||||
XButton1 = SDL_BUTTON_X1,
|
|
||||||
XButton2 = SDL_BUTTON_X2
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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);
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,152 +0,0 @@
|
||||||
/**
|
|
||||||
* @file Vector2.hpp
|
|
||||||
* @brief Provides a structure for simple vector calculations
|
|
||||||
* @author Lauchmelder23
|
|
||||||
* @date 16.05.2020
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
#include <type_traits>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @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;
|
|
||||||
}
|
|
|
@ -1,253 +0,0 @@
|
||||||
#include "Window.hpp"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#include <exceptions/Exceptions.hpp>
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
Window::Window() :
|
|
||||||
window(nullptr)
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
Window::Window(Vector2u dimension, const std::string& title, Uint32 windowFlags) :
|
|
||||||
Window()
|
|
||||||
{
|
|
||||||
Create(dimension, title, windowFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
Window::~Window()
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::Create(Vector2u dimension, const std::string& title, Uint32 windowFlags)
|
|
||||||
{
|
|
||||||
// Don't create a window when it already exists
|
|
||||||
RETURN_IF_NOT_NULLPTR(window);
|
|
||||||
|
|
||||||
window = SDL_CreateWindow(title.c_str(),
|
|
||||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
|
||||||
dimension.x, dimension.y,
|
|
||||||
windowFlags);
|
|
||||||
|
|
||||||
THROW_IF(IS_NULLPTR(window),
|
|
||||||
ObjectCreationException("Failed to create SDL_Window. \nSDL_GetError(): " + std::string(SDL_GetError())));
|
|
||||||
|
|
||||||
OnCreate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::Close()
|
|
||||||
{
|
|
||||||
// Don't destroy a window that doesn't exist
|
|
||||||
RETURN_IF_NULLPTR(window);
|
|
||||||
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
window = nullptr;
|
|
||||||
|
|
||||||
OnClose();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Window::IsOpen() const
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(window, false);
|
|
||||||
return (!SDL_GetWindowID(window) ? false : true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Window::PollEvent(SDL_Event* event)
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(window, false);
|
|
||||||
// Handle events before the user in case a derived
|
|
||||||
// class decides to block the event.
|
|
||||||
while (SDL_PollEvent(event))
|
|
||||||
{
|
|
||||||
switch (event->window.event)
|
|
||||||
{
|
|
||||||
case SDL_WINDOWEVENT_RESIZED: if (!OnResize()) return true; break;
|
|
||||||
default: return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event = NULL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Window::WaitEvent(SDL_Event* event)
|
|
||||||
{
|
|
||||||
while (!PollEvent(event)) continue;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2i Window::GetPosition() const
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(window, Vector2i());
|
|
||||||
|
|
||||||
int x = 0, y = 0;
|
|
||||||
SDL_GetWindowPosition(window, &x, &y);
|
|
||||||
return Vector2i(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetPosition(Vector2i position)
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(window);
|
|
||||||
|
|
||||||
SDL_SetWindowPosition(window, position.x, position.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetPosition(int x, int y)
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(window);
|
|
||||||
|
|
||||||
SDL_SetWindowPosition(window, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2u Window::GetSize() const
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(window, Vector2u());
|
|
||||||
|
|
||||||
int x = 0, y = 0;
|
|
||||||
SDL_GetWindowSize(window, &x, &y);
|
|
||||||
return Vector2u(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetSize(Vector2u size)
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(window);
|
|
||||||
|
|
||||||
SDL_SetWindowSize(window, size.x, size.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetSize(unsigned int width, unsigned int height)
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(window);
|
|
||||||
|
|
||||||
SDL_SetWindowSize(window, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Window::GetTitle() const
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(window, "");
|
|
||||||
|
|
||||||
return SDL_GetWindowTitle(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetTitle(std::string title)
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(window);
|
|
||||||
|
|
||||||
SDL_SetWindowTitle(window, title.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Window* const Window::GetWindow() const
|
|
||||||
{
|
|
||||||
return window;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetVisible(bool visible)
|
|
||||||
{
|
|
||||||
RETURN_IF_NULLPTR(window);
|
|
||||||
if (visible)
|
|
||||||
SDL_ShowWindow(window);
|
|
||||||
else
|
|
||||||
SDL_HideWindow(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetVsync(bool vsync)
|
|
||||||
{
|
|
||||||
// SDL actually doesn't allow you to change the VSync
|
|
||||||
// flag of a Renderer after it's been created. This
|
|
||||||
// Changes it globally for all other windows
|
|
||||||
SDL_GL_SetSwapInterval(vsync);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetMouseCursorVisible(bool visible)
|
|
||||||
{
|
|
||||||
SDL_ShowCursor(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetMouseCursorGrabbed(bool grabbed)
|
|
||||||
{
|
|
||||||
SDL_SetWindowGrab(window, grabbed ? SDL_TRUE : SDL_FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetIcon(Uint32 width, Uint32 height, const Uint8* pixels)
|
|
||||||
{
|
|
||||||
size_t size = static_cast<size_t>(width) * static_cast<size_t>(height) * 4;
|
|
||||||
void* _pixels = malloc(size);
|
|
||||||
memcpy(_pixels, pixels, size);
|
|
||||||
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
|
|
||||||
width, height, 32, 32 * width,
|
|
||||||
SDL_PIXELFORMAT_RGBA8888);
|
|
||||||
|
|
||||||
SDL_SetWindowIcon(window, surface);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetIcon(Uint32 width, Uint32 height, const Uint32* pixels)
|
|
||||||
{
|
|
||||||
size_t size = static_cast<size_t>(width) * static_cast<size_t>(height) * 4;
|
|
||||||
void* _pixels = malloc(size);
|
|
||||||
memcpy(_pixels, pixels, size);
|
|
||||||
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
|
|
||||||
width, height, 32, 4 * width,
|
|
||||||
SDL_PIXELFORMAT_RGBA8888);
|
|
||||||
|
|
||||||
SDL_SetWindowIcon(window, surface);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetIcon(SDL_Surface* icon)
|
|
||||||
{
|
|
||||||
SDL_SetWindowIcon(window, icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetMouseCursor(SDL_Cursor* cursor)
|
|
||||||
{
|
|
||||||
SDL_SetCursor(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetMouseCursor(SDL_SystemCursor cursor)
|
|
||||||
{
|
|
||||||
SDL_Cursor* _cursor = SDL_CreateSystemCursor(cursor);
|
|
||||||
SDL_SetCursor(_cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetMouseCursor(SDL_Surface* surface, Vector2u clickspot)
|
|
||||||
{
|
|
||||||
SDL_Cursor* _cursor = SDL_CreateColorCursor(surface, clickspot.x, clickspot.y);
|
|
||||||
SDL_SetCursor(_cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetMouseCursor(const Uint8* pixels, Vector2u size, Vector2u clickspot)
|
|
||||||
{
|
|
||||||
size_t _size = static_cast<size_t>(size.x) * static_cast<size_t>(size.y) * 4;
|
|
||||||
void* _pixels = malloc(_size);
|
|
||||||
memcpy(_pixels, pixels, _size);
|
|
||||||
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
|
|
||||||
size.x, size.y, 32, 8 * size.x, SDL_PIXELFORMAT_RGBA8888);
|
|
||||||
this->SetMouseCursor(surface, clickspot);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::SetMouseCursor(const Uint32* pixels, Vector2u size, Vector2u clickspot)
|
|
||||||
{
|
|
||||||
size_t _size = static_cast<size_t>(size.x) * static_cast<size_t>(size.y) * 4;
|
|
||||||
void* _pixels = malloc(_size);
|
|
||||||
memcpy(_pixels, pixels, _size);
|
|
||||||
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
|
|
||||||
size.x, size.y, 32, 8 * size.x, SDL_PIXELFORMAT_RGBA32);
|
|
||||||
this->SetMouseCursor(surface, clickspot);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::OnCreate()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Window::OnResize()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::OnClose()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,269 +0,0 @@
|
||||||
/**
|
|
||||||
* @file Window.hpp
|
|
||||||
* @brief Contains window related objects
|
|
||||||
* @author Lauchmelder23
|
|
||||||
* @date 20.05.20
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
#include <SDL.h>
|
|
||||||
|
|
||||||
#include <Util.hpp>
|
|
||||||
#include <structures/Vector2.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sdlu
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @brief Stores information about a window. You probably want RenderWindow.
|
|
||||||
*/
|
|
||||||
class Window
|
|
||||||
{
|
|
||||||
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] cursor An enum for a system cursor
|
|
||||||
*/
|
|
||||||
void SetMouseCursor(SDL_SystemCursor 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();
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
set(PNAME sdlu_example)
|
|
||||||
|
|
||||||
add_executable(${PNAME}
|
|
||||||
main.cpp header.hpp
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(${PNAME} PRIVATE
|
|
||||||
${PROJECT_SOURCE_DIR}/SDLU
|
|
||||||
${PROJECT_SOURCE_DIR}/3rdparty/SDL/include
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(${PNAME}
|
|
||||||
SDLU
|
|
||||||
SDL2
|
|
||||||
SDL2main
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_command(TARGET ${PNAME}
|
|
||||||
POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:SDL2> $<TARGET_FILE_DIR:sdlu_example>
|
|
||||||
)
|
|
15
examples/CMakeLists.txt
Normal file
15
examples/CMakeLists.txt
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
add_executable(sdlu_example
|
||||||
|
main.cpp header.hpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(sdlu_example PUBLIC
|
||||||
|
sdlu
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(sdlu_example
|
||||||
|
sdlu
|
||||||
|
)
|
||||||
|
|
||||||
|
# add_custom_command(TARGET sdlu_example POST_BUILD
|
||||||
|
# COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:SDL2> $<TARGET_FILE_DIR:sdlu_example>
|
||||||
|
# )
|
|
@ -1,7 +1,6 @@
|
||||||
#include <SDLU.hpp>
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "SDLU.hpp"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <SDLU.hpp>
|
||||||
|
|
||||||
class MyWindow :
|
class MyWindow :
|
||||||
public sdlu::RenderWindow
|
public sdlu::RenderWindow
|
||||||
|
@ -9,7 +8,7 @@ class MyWindow :
|
||||||
public:
|
public:
|
||||||
MyWindow(Uint32 width, Uint32 height, const char* title) :
|
MyWindow(Uint32 width, Uint32 height, const char* title) :
|
||||||
RenderWindow(sdlu::Vector2u(width, height), title,
|
RenderWindow(sdlu::Vector2u(width, height), title,
|
||||||
SDL_WINDOW_RESIZABLE)
|
32)
|
||||||
{
|
{
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
|
@ -1,11 +1,13 @@
|
||||||
#include "header.hpp"
|
#include "header.hpp"
|
||||||
|
|
||||||
|
#include <SDL_events.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
sdlu::Initialize();
|
||||||
|
|
||||||
Uint32* icon_data = new Uint32[64 * 64];
|
Uint32* icon_data = new Uint32[64 * 64];
|
||||||
for (int y = 0; y < 64; y++)
|
for (int y = 0; y < 64; y++)
|
||||||
|
@ -22,10 +24,10 @@ int main(int argc, char** argv)
|
||||||
Uint64 diff = 1;
|
Uint64 diff = 1;
|
||||||
|
|
||||||
MyWindow window(800, 800, "Test");
|
MyWindow window(800, 800, "Test");
|
||||||
SDL_SetWindowTitle(window.GetWindow(), "New Title");
|
window.SetTitle("New Title");
|
||||||
|
|
||||||
window.SetIcon(64, 64, icon_data);
|
window.SetIcon(64, 64, icon_data);
|
||||||
window.SetMouseCursor(SDL_SYSTEM_CURSOR_CROSSHAIR);
|
// window.SetMouseCursor(SDL_SYSTEM_CURSOR_CROSSHAIR);
|
||||||
window.SetMaxFramerate(144);
|
window.SetMaxFramerate(144);
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
@ -73,7 +75,6 @@ int main(int argc, char** argv)
|
||||||
start = std::chrono::steady_clock::now();
|
start = std::chrono::steady_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Quit();
|
sdlu::Quit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
10
include/SDLU.hpp
Normal file
10
include/SDLU.hpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <graphics/Graphics.hpp>
|
||||||
|
#include <structures/Mouse.hpp>
|
||||||
|
|
||||||
|
namespace sdlu {
|
||||||
|
// TODO: Eventually we should initialize things once the object gets created
|
||||||
|
extern int Initialize();
|
||||||
|
extern void Quit();
|
||||||
|
}
|
|
@ -24,4 +24,10 @@ typedef uint32_t Uint32;
|
||||||
typedef int32_t Int32;
|
typedef int32_t Int32;
|
||||||
|
|
||||||
typedef uint64_t Uint64;
|
typedef uint64_t Uint64;
|
||||||
typedef int64_t Int64;
|
typedef int64_t Int64;
|
||||||
|
|
||||||
|
#define THROW_IF( condition, exception ) ( condition ? throw exception : false)
|
||||||
|
#define THROW_IF_NOT( condition, exception ) ( THROW_IF(!condition, exception) )
|
||||||
|
|
||||||
|
#define SDLU_BEGIN namespace sdlu {
|
||||||
|
#define SDLU_END }
|
79
include/graphics/RenderTarget.hpp
Normal file
79
include/graphics/RenderTarget.hpp
Normal 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
|
69
include/graphics/RenderWindow.hpp
Normal file
69
include/graphics/RenderWindow.hpp
Normal 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
|
30
include/graphics/drawable/Drawable.hpp
Normal file
30
include/graphics/drawable/Drawable.hpp
Normal 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
|
157
include/graphics/drawable/Transformable.hpp
Normal file
157
include/graphics/drawable/Transformable.hpp
Normal 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
|
|
@ -8,8 +8,6 @@
|
||||||
|
|
||||||
#include "Shape.hpp"
|
#include "Shape.hpp"
|
||||||
|
|
||||||
#include <SDL.h>
|
|
||||||
|
|
||||||
namespace sdlu
|
namespace sdlu
|
||||||
{
|
{
|
||||||
class Rectangle :
|
class Rectangle :
|
45
include/graphics/drawable/shapes/Shape.hpp
Normal file
45
include/graphics/drawable/shapes/Shape.hpp
Normal 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
|
|
@ -6,10 +6,9 @@
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Util.hpp>
|
#include "Util.hpp"
|
||||||
|
|
||||||
namespace sdlu
|
SDLU_BEGIN
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @brief A structure holding color data
|
* @brief A structure holding color data
|
||||||
*
|
*
|
||||||
|
@ -167,4 +166,4 @@ namespace sdlu
|
||||||
*/
|
*/
|
||||||
friend bool operator!=(const Color& left, const Color& right);
|
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
|
20
lib/sdl2_gfx/CMakeLists.txt
Normal file
20
lib/sdl2_gfx/CMakeLists.txt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
file(GLOB_RECURSE sdl2gfx_includes
|
||||||
|
"include/*.h"
|
||||||
|
)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE sdl2gfx_sources
|
||||||
|
"src/*.c"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(sdl2_gfx
|
||||||
|
${sdl2gfx_includes} ${sdl2gfx_sources}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(sdl2_gfx PUBLIC
|
||||||
|
SDL2
|
||||||
|
"include"
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(sdl2_gfx PUBLIC
|
||||||
|
SDL2::SDL2
|
||||||
|
)
|
100
lib/sdl2_gfx/include/SDL2_framerate.h
Normal file
100
lib/sdl2_gfx/include/SDL2_framerate.h
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
SDL2_framerate.h: framerate manager
|
||||||
|
|
||||||
|
Copyright (C) 2012-2014 Andreas Schiffler
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
|
||||||
|
Andreas Schiffler -- aschiffler at ferzkopp dot net
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SDL2_framerate_h
|
||||||
|
#define _SDL2_framerate_h
|
||||||
|
|
||||||
|
/* Set up for C function definitions, even when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* --- */
|
||||||
|
|
||||||
|
#include "SDL.h"
|
||||||
|
|
||||||
|
/* --------- Definitions */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Highest possible rate supported by framerate controller in Hz (1/s).
|
||||||
|
*/
|
||||||
|
#define FPS_UPPER_LIMIT 200
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Lowest possible rate supported by framerate controller in Hz (1/s).
|
||||||
|
*/
|
||||||
|
#define FPS_LOWER_LIMIT 1
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Default rate of framerate controller in Hz (1/s).
|
||||||
|
*/
|
||||||
|
#define FPS_DEFAULT 30
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Structure holding the state and timing information of the framerate controller.
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
Uint32 framecount;
|
||||||
|
float rateticks;
|
||||||
|
Uint32 baseticks;
|
||||||
|
Uint32 lastticks;
|
||||||
|
Uint32 rate;
|
||||||
|
} FPSmanager;
|
||||||
|
|
||||||
|
/* ---- Function Prototypes */
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
|
||||||
|
# define SDL2_FRAMERATE_SCOPE __declspec(dllexport)
|
||||||
|
# else
|
||||||
|
# ifdef LIBSDL2_GFX_DLL_IMPORT
|
||||||
|
# define SDL2_FRAMERATE_SCOPE __declspec(dllimport)
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#ifndef SDL2_FRAMERATE_SCOPE
|
||||||
|
# define SDL2_FRAMERATE_SCOPE extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Functions return 0 or value for sucess and -1 for error */
|
||||||
|
|
||||||
|
SDL2_FRAMERATE_SCOPE void SDL_initFramerate(FPSmanager * manager);
|
||||||
|
SDL2_FRAMERATE_SCOPE int SDL_setFramerate(FPSmanager * manager, Uint32 rate);
|
||||||
|
SDL2_FRAMERATE_SCOPE int SDL_getFramerate(FPSmanager * manager);
|
||||||
|
SDL2_FRAMERATE_SCOPE int SDL_getFramecount(FPSmanager * manager);
|
||||||
|
SDL2_FRAMERATE_SCOPE Uint32 SDL_framerateDelay(FPSmanager * manager);
|
||||||
|
|
||||||
|
/* --- */
|
||||||
|
|
||||||
|
/* Ends C function definitions when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _SDL2_framerate_h */
|
241
lib/sdl2_gfx/include/SDL2_gfxPrimitives.h
Normal file
241
lib/sdl2_gfx/include/SDL2_gfxPrimitives.h
Normal file
|
@ -0,0 +1,241 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
SDL2_gfxPrimitives.h: graphics primitives for SDL
|
||||||
|
|
||||||
|
Copyright (C) 2012-2014 Andreas Schiffler
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
|
||||||
|
Andreas Schiffler -- aschiffler at ferzkopp dot net
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SDL2_gfxPrimitives_h
|
||||||
|
#define _SDL2_gfxPrimitives_h
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.1415926535897932384626433832795
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "SDL.h"
|
||||||
|
|
||||||
|
/* Set up for C function definitions, even when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ----- Versioning */
|
||||||
|
|
||||||
|
#define SDL2_GFXPRIMITIVES_MAJOR 1
|
||||||
|
#define SDL2_GFXPRIMITIVES_MINOR 0
|
||||||
|
#define SDL2_GFXPRIMITIVES_MICRO 3
|
||||||
|
|
||||||
|
|
||||||
|
/* ---- Function Prototypes */
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
|
||||||
|
# define SDL2_GFXPRIMITIVES_SCOPE __declspec(dllexport)
|
||||||
|
# else
|
||||||
|
# ifdef LIBSDL2_GFX_DLL_IMPORT
|
||||||
|
# define SDL2_GFXPRIMITIVES_SCOPE __declspec(dllimport)
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#ifndef SDL2_GFXPRIMITIVES_SCOPE
|
||||||
|
# define SDL2_GFXPRIMITIVES_SCOPE extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Note: all ___Color routines expect the color to be in format 0xRRGGBBAA */
|
||||||
|
|
||||||
|
/* Pixel */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int pixelColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int pixelRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Horizontal line */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int hlineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int hlineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Vertical line */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int vlineColor(SDL_Renderer * renderer, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int vlineRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y1, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Rectangle */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int rectangleColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int rectangleRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
|
||||||
|
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Rounded-Corner Rectangle */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int roundedRectangleColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int roundedRectangleRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
|
||||||
|
Sint16 x2, Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Filled rectangle (Box) */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int boxColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int boxRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2,
|
||||||
|
Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Rounded-Corner Filled rectangle (Box) */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int roundedBoxColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int roundedBoxRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2,
|
||||||
|
Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Line */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int lineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int lineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
|
||||||
|
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* AA Line */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int aalineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int aalineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
|
||||||
|
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Thick Line */
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int thickLineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
|
||||||
|
Uint8 width, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int thickLineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
|
||||||
|
Uint8 width, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Circle */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int circleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int circleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Arc */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int arcColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int arcRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end,
|
||||||
|
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* AA Circle */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int aacircleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int aacircleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
|
||||||
|
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Filled Circle */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int filledCircleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int filledCircleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
|
||||||
|
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Ellipse */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int ellipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int ellipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
|
||||||
|
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* AA Ellipse */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int aaellipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int aaellipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
|
||||||
|
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Filled Ellipse */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int filledEllipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int filledEllipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
|
||||||
|
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Pie */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int pieColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
|
||||||
|
Sint16 start, Sint16 end, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int pieRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
|
||||||
|
Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Filled Pie */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int filledPieColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
|
||||||
|
Sint16 start, Sint16 end, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int filledPieRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
|
||||||
|
Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Trigon */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int trigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int trigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
|
||||||
|
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* AA-Trigon */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int aatrigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int aatrigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
|
||||||
|
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Filled Trigon */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int filledTrigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int filledTrigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
|
||||||
|
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Polygon */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int polygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int polygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy,
|
||||||
|
int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* AA-Polygon */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int aapolygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int aapolygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy,
|
||||||
|
int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Filled Polygon */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int filledPolygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int filledPolygonRGBA(SDL_Renderer * renderer, const Sint16 * vx,
|
||||||
|
const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Textured Polygon */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int texturedPolygon(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, SDL_Surface * texture,int texture_dx,int texture_dy);
|
||||||
|
|
||||||
|
/* Bezier */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int bezierColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, int s, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int bezierRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy,
|
||||||
|
int n, int s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Characters/Strings */
|
||||||
|
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE void gfxPrimitivesSetFont(const void *fontdata, Uint32 cw, Uint32 ch);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE void gfxPrimitivesSetFontRotation(Uint32 rotation);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int characterColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, char c, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int characterRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, char c, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int stringColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, const char *s, Uint32 color);
|
||||||
|
SDL2_GFXPRIMITIVES_SCOPE int stringRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, const char *s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Ends C function definitions when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _SDL2_gfxPrimitives_h */
|
3106
lib/sdl2_gfx/include/SDL2_gfxPrimitives_font.h
Normal file
3106
lib/sdl2_gfx/include/SDL2_gfxPrimitives_font.h
Normal file
File diff suppressed because it is too large
Load diff
166
lib/sdl2_gfx/include/SDL2_imageFilter.h
Normal file
166
lib/sdl2_gfx/include/SDL2_imageFilter.h
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
SDL2_imageFilter.h: byte-image "filter" routines
|
||||||
|
|
||||||
|
Copyright (C) 2012-2014 Andreas Schiffler
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
|
||||||
|
Andreas Schiffler -- aschiffler at ferzkopp dot net
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SDL2_imageFilter_h
|
||||||
|
#define _SDL2_imageFilter_h
|
||||||
|
|
||||||
|
/* Set up for C function definitions, even when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ---- Function Prototypes */
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
|
||||||
|
# define SDL2_IMAGEFILTER_SCOPE __declspec(dllexport)
|
||||||
|
# else
|
||||||
|
# ifdef LIBSDL2_GFX_DLL_IMPORT
|
||||||
|
# define SDL2_IMAGEFILTER_SCOPE __declspec(dllimport)
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#ifndef SDL2_IMAGEFILTER_SCOPE
|
||||||
|
# define SDL2_IMAGEFILTER_SCOPE extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Comments: */
|
||||||
|
/* 1.) MMX functions work best if all data blocks are aligned on a 32 bytes boundary. */
|
||||||
|
/* 2.) Data that is not within an 8 byte boundary is processed using the C routine. */
|
||||||
|
/* 3.) Convolution routines do not have C routines at this time. */
|
||||||
|
|
||||||
|
// Detect MMX capability in CPU
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMMXdetect(void);
|
||||||
|
|
||||||
|
// Force use of MMX off (or turn possible use back on)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE void SDL_imageFilterMMXoff(void);
|
||||||
|
SDL2_IMAGEFILTER_SCOPE void SDL_imageFilterMMXon(void);
|
||||||
|
|
||||||
|
//
|
||||||
|
// All routines return:
|
||||||
|
// 0 OK
|
||||||
|
// -1 Error (internal error, parameter error)
|
||||||
|
//
|
||||||
|
|
||||||
|
// SDL_imageFilterAdd: D = saturation255(S1 + S2)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterAdd(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterMean: D = S1/2 + S2/2
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMean(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterSub: D = saturation0(S1 - S2)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterSub(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterAbsDiff: D = | S1 - S2 |
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterAbsDiff(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterMult: D = saturation(S1 * S2)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMult(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterMultNor: D = S1 * S2 (non-MMX)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMultNor(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterMultDivby2: D = saturation255(S1/2 * S2)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMultDivby2(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest,
|
||||||
|
unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterMultDivby4: D = saturation255(S1/2 * S2/2)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMultDivby4(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest,
|
||||||
|
unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterBitAnd: D = S1 & S2
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterBitAnd(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterBitOr: D = S1 | S2
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterBitOr(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterDiv: D = S1 / S2 (non-MMX)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterDiv(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterBitNegation: D = !S
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterBitNegation(unsigned char *Src1, unsigned char *Dest, unsigned int length);
|
||||||
|
|
||||||
|
// SDL_imageFilterAddByte: D = saturation255(S + C)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterAddByte(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char C);
|
||||||
|
|
||||||
|
// SDL_imageFilterAddUint: D = saturation255(S + (uint)C)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterAddUint(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned int C);
|
||||||
|
|
||||||
|
// SDL_imageFilterAddByteToHalf: D = saturation255(S/2 + C)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterAddByteToHalf(unsigned char *Src1, unsigned char *Dest, unsigned int length,
|
||||||
|
unsigned char C);
|
||||||
|
|
||||||
|
// SDL_imageFilterSubByte: D = saturation0(S - C)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterSubByte(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char C);
|
||||||
|
|
||||||
|
// SDL_imageFilterSubUint: D = saturation0(S - (uint)C)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterSubUint(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned int C);
|
||||||
|
|
||||||
|
// SDL_imageFilterShiftRight: D = saturation0(S >> N)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftRight(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char N);
|
||||||
|
|
||||||
|
// SDL_imageFilterShiftRightUint: D = saturation0((uint)S >> N)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftRightUint(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char N);
|
||||||
|
|
||||||
|
// SDL_imageFilterMultByByte: D = saturation255(S * C)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMultByByte(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char C);
|
||||||
|
|
||||||
|
// SDL_imageFilterShiftRightAndMultByByte: D = saturation255((S >> N) * C)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftRightAndMultByByte(unsigned char *Src1, unsigned char *Dest, unsigned int length,
|
||||||
|
unsigned char N, unsigned char C);
|
||||||
|
|
||||||
|
// SDL_imageFilterShiftLeftByte: D = (S << N)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftLeftByte(unsigned char *Src1, unsigned char *Dest, unsigned int length,
|
||||||
|
unsigned char N);
|
||||||
|
|
||||||
|
// SDL_imageFilterShiftLeftUint: D = ((uint)S << N)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftLeftUint(unsigned char *Src1, unsigned char *Dest, unsigned int length,
|
||||||
|
unsigned char N);
|
||||||
|
|
||||||
|
// SDL_imageFilterShiftLeft: D = saturation255(S << N)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftLeft(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char N);
|
||||||
|
|
||||||
|
// SDL_imageFilterBinarizeUsingThreshold: D = S >= T ? 255:0
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterBinarizeUsingThreshold(unsigned char *Src1, unsigned char *Dest, unsigned int length,
|
||||||
|
unsigned char T);
|
||||||
|
|
||||||
|
// SDL_imageFilterClipToRange: D = (S >= Tmin) & (S <= Tmax) 255:0
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterClipToRange(unsigned char *Src1, unsigned char *Dest, unsigned int length,
|
||||||
|
unsigned char Tmin, unsigned char Tmax);
|
||||||
|
|
||||||
|
// SDL_imageFilterNormalizeLinear: D = saturation255((Nmax - Nmin)/(Cmax - Cmin)*(S - Cmin) + Nmin)
|
||||||
|
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterNormalizeLinear(unsigned char *Src, unsigned char *Dest, unsigned int length, int Cmin,
|
||||||
|
int Cmax, int Nmin, int Nmax);
|
||||||
|
|
||||||
|
/* Ends C function definitions when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _SDL_imageFilter_h */
|
123
lib/sdl2_gfx/include/SDL2_rotozoom.h
Normal file
123
lib/sdl2_gfx/include/SDL2_rotozoom.h
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
SDL2_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces
|
||||||
|
|
||||||
|
Copyright (C) 2012-2014 Andreas Schiffler
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
|
||||||
|
Andreas Schiffler -- aschiffler at ferzkopp dot net
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SDL2_rotozoom_h
|
||||||
|
#define _SDL2_rotozoom_h
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/* Set up for C function definitions, even when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.1415926535897932384626433832795
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "SDL.h"
|
||||||
|
|
||||||
|
/* ---- Defines */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Disable anti-aliasing (no smoothing).
|
||||||
|
*/
|
||||||
|
#define SMOOTHING_OFF 0
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Enable anti-aliasing (smoothing).
|
||||||
|
*/
|
||||||
|
#define SMOOTHING_ON 1
|
||||||
|
|
||||||
|
/* ---- Function Prototypes */
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
|
||||||
|
# define SDL2_ROTOZOOM_SCOPE __declspec(dllexport)
|
||||||
|
# else
|
||||||
|
# ifdef LIBSDL2_GFX_DLL_IMPORT
|
||||||
|
# define SDL2_ROTOZOOM_SCOPE __declspec(dllimport)
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#ifndef SDL2_ROTOZOOM_SCOPE
|
||||||
|
# define SDL2_ROTOZOOM_SCOPE extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Rotozoom functions
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
SDL2_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth);
|
||||||
|
|
||||||
|
SDL2_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurfaceXY
|
||||||
|
(SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth);
|
||||||
|
|
||||||
|
|
||||||
|
SDL2_ROTOZOOM_SCOPE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth,
|
||||||
|
int *dstheight);
|
||||||
|
|
||||||
|
SDL2_ROTOZOOM_SCOPE void rotozoomSurfaceSizeXY
|
||||||
|
(int width, int height, double angle, double zoomx, double zoomy,
|
||||||
|
int *dstwidth, int *dstheight);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Zooming functions
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
SDL2_ROTOZOOM_SCOPE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
|
||||||
|
|
||||||
|
SDL2_ROTOZOOM_SCOPE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Shrinking functions
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
SDL2_ROTOZOOM_SCOPE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Specialized rotation functions
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
SDL2_ROTOZOOM_SCOPE SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns);
|
||||||
|
|
||||||
|
/* Ends C function definitions when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _SDL2_rotozoom_h */
|
189
lib/sdl2_gfx/src/SDL2_framerate.c
Normal file
189
lib/sdl2_gfx/src/SDL2_framerate.c
Normal file
|
@ -0,0 +1,189 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
SDL2_framerate.c: framerate manager
|
||||||
|
|
||||||
|
Copyright (C) 2012-2014 Andreas Schiffler
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
|
||||||
|
Andreas Schiffler -- aschiffler at ferzkopp dot net
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SDL2_framerate.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Internal wrapper to SDL_GetTicks that ensures a non-zero return value.
|
||||||
|
|
||||||
|
\return The tick count.
|
||||||
|
*/
|
||||||
|
Uint32 _getTicks()
|
||||||
|
{
|
||||||
|
Uint32 ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Since baseticks!=0 is used to track initialization
|
||||||
|
* we need to ensure that the tick count is always >0
|
||||||
|
* since SDL_GetTicks may not have incremented yet and
|
||||||
|
* return 0 depending on the timing of the calls.
|
||||||
|
*/
|
||||||
|
if (ticks == 0) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return ticks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Initialize the framerate manager.
|
||||||
|
|
||||||
|
Initialize the framerate manager, set default framerate of 30Hz and
|
||||||
|
reset delay interpolation.
|
||||||
|
|
||||||
|
\param manager Pointer to the framerate manager.
|
||||||
|
*/
|
||||||
|
void SDL_initFramerate(FPSmanager * manager)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Store some sane values
|
||||||
|
*/
|
||||||
|
manager->framecount = 0;
|
||||||
|
manager->rate = FPS_DEFAULT;
|
||||||
|
manager->rateticks = (1000.0f / (float) FPS_DEFAULT);
|
||||||
|
manager->baseticks = _getTicks();
|
||||||
|
manager->lastticks = manager->baseticks;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Set the framerate in Hz
|
||||||
|
|
||||||
|
Sets a new framerate for the manager and reset delay interpolation.
|
||||||
|
Rate values must be between FPS_LOWER_LIMIT and FPS_UPPER_LIMIT inclusive to be accepted.
|
||||||
|
|
||||||
|
\param manager Pointer to the framerate manager.
|
||||||
|
\param rate The new framerate in Hz (frames per second).
|
||||||
|
|
||||||
|
\return 0 for sucess and -1 for error.
|
||||||
|
*/
|
||||||
|
int SDL_setFramerate(FPSmanager * manager, Uint32 rate)
|
||||||
|
{
|
||||||
|
if ((rate >= FPS_LOWER_LIMIT) && (rate <= FPS_UPPER_LIMIT)) {
|
||||||
|
manager->framecount = 0;
|
||||||
|
manager->rate = rate;
|
||||||
|
manager->rateticks = (1000.0f / (float) rate);
|
||||||
|
return (0);
|
||||||
|
} else {
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Return the current target framerate in Hz
|
||||||
|
|
||||||
|
Get the currently set framerate of the manager.
|
||||||
|
|
||||||
|
\param manager Pointer to the framerate manager.
|
||||||
|
|
||||||
|
\return Current framerate in Hz or -1 for error.
|
||||||
|
*/
|
||||||
|
int SDL_getFramerate(FPSmanager * manager)
|
||||||
|
{
|
||||||
|
if (manager == NULL) {
|
||||||
|
return (-1);
|
||||||
|
} else {
|
||||||
|
return ((int)manager->rate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Return the current framecount.
|
||||||
|
|
||||||
|
Get the current framecount from the framerate manager.
|
||||||
|
A frame is counted each time SDL_framerateDelay is called.
|
||||||
|
|
||||||
|
\param manager Pointer to the framerate manager.
|
||||||
|
|
||||||
|
\return Current frame count or -1 for error.
|
||||||
|
*/
|
||||||
|
int SDL_getFramecount(FPSmanager * manager)
|
||||||
|
{
|
||||||
|
if (manager == NULL) {
|
||||||
|
return (-1);
|
||||||
|
} else {
|
||||||
|
return ((int)manager->framecount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Delay execution to maintain a constant framerate and calculate fps.
|
||||||
|
|
||||||
|
Generate a delay to accomodate currently set framerate. Call once in the
|
||||||
|
graphics/rendering loop. If the computer cannot keep up with the rate (i.e.
|
||||||
|
drawing too slow), the delay is zero and the delay interpolation is reset.
|
||||||
|
|
||||||
|
\param manager Pointer to the framerate manager.
|
||||||
|
|
||||||
|
\return The time that passed since the last call to the function in ms. May return 0.
|
||||||
|
*/
|
||||||
|
Uint32 SDL_framerateDelay(FPSmanager * manager)
|
||||||
|
{
|
||||||
|
Uint32 current_ticks;
|
||||||
|
Uint32 target_ticks;
|
||||||
|
Uint32 the_delay;
|
||||||
|
Uint32 time_passed = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* No manager, no delay
|
||||||
|
*/
|
||||||
|
if (manager == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize uninitialized manager
|
||||||
|
*/
|
||||||
|
if (manager->baseticks == 0) {
|
||||||
|
SDL_initFramerate(manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Next frame
|
||||||
|
*/
|
||||||
|
manager->framecount++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get/calc ticks
|
||||||
|
*/
|
||||||
|
current_ticks = _getTicks();
|
||||||
|
time_passed = current_ticks - manager->lastticks;
|
||||||
|
manager->lastticks = current_ticks;
|
||||||
|
target_ticks = manager->baseticks + (Uint32) ((float) manager->framecount * manager->rateticks);
|
||||||
|
|
||||||
|
if (current_ticks <= target_ticks) {
|
||||||
|
the_delay = target_ticks - current_ticks;
|
||||||
|
SDL_Delay(the_delay);
|
||||||
|
} else {
|
||||||
|
manager->framecount = 0;
|
||||||
|
manager->baseticks = _getTicks();
|
||||||
|
}
|
||||||
|
|
||||||
|
return time_passed;
|
||||||
|
}
|
3790
lib/sdl2_gfx/src/SDL2_gfxPrimitives.c
Normal file
3790
lib/sdl2_gfx/src/SDL2_gfxPrimitives.c
Normal file
File diff suppressed because it is too large
Load diff
7371
lib/sdl2_gfx/src/SDL2_imageFilter.c
Normal file
7371
lib/sdl2_gfx/src/SDL2_imageFilter.c
Normal file
File diff suppressed because it is too large
Load diff
1663
lib/sdl2_gfx/src/SDL2_rotozoom.c
Normal file
1663
lib/sdl2_gfx/src/SDL2_rotozoom.c
Normal file
File diff suppressed because it is too large
Load diff
18
src/SDLU.cpp
Normal file
18
src/SDLU.cpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#include "SDLU.hpp"
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include "Util.hpp"
|
||||||
|
|
||||||
|
SDLU_BEGIN
|
||||||
|
|
||||||
|
int Initialize() {
|
||||||
|
return SDL_Init(SDL_INIT_EVERYTHING);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Quit() {
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_CommonEvent c;
|
||||||
|
|
||||||
|
SDLU_END
|
79
src/graphics/RenderTarget.cpp
Normal file
79
src/graphics/RenderTarget.cpp
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
#include "graphics/RenderTarget.hpp"
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <Util.hpp>
|
||||||
|
|
||||||
|
SDLU_BEGIN
|
||||||
|
RenderTarget::~RenderTarget()
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(renderer);
|
||||||
|
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderTarget::Clear(const Color& color)
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(renderer);
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderTarget::Draw(const Drawable& drawable)
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(renderer);
|
||||||
|
|
||||||
|
drawable.Draw(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderTarget::Display()
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(renderer);
|
||||||
|
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
|
if (m_oFramerate != 0)
|
||||||
|
{
|
||||||
|
Uint64 diff = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
std::chrono::steady_clock::now() - m_oTimeSinceLastDisplay).count();
|
||||||
|
|
||||||
|
if (diff < 1000 / m_oFramerate)
|
||||||
|
{
|
||||||
|
SDL_Delay(static_cast<Uint32>(1000 / m_oFramerate - diff));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_oTimeSinceLastDisplay = std::chrono::steady_clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderTarget::SetMaxFramerate(Uint32 max)
|
||||||
|
{
|
||||||
|
m_oFramerate = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderTarget::RenderTarget(SDL_Window* target) :
|
||||||
|
renderer(nullptr), m_oFramerate(0)
|
||||||
|
{
|
||||||
|
RETURN_IF_NOT_NULLPTR(renderer);
|
||||||
|
renderer = SDL_CreateRenderer(target, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
|
||||||
|
THROW_IF(IS_NULLPTR(renderer),
|
||||||
|
std::runtime_error("Failed to create SDL_Renderer* from SDL_Window*: " + std::string(SDL_GetError())));
|
||||||
|
|
||||||
|
m_oTimeSinceLastDisplay = std::chrono::steady_clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderTarget::RenderTarget(SDL_Surface* target) :
|
||||||
|
renderer(nullptr), m_oFramerate(0)
|
||||||
|
{
|
||||||
|
m_oFramerate = 0;
|
||||||
|
|
||||||
|
RETURN_IF_NOT_NULLPTR(renderer);
|
||||||
|
renderer = SDL_CreateSoftwareRenderer(target);
|
||||||
|
|
||||||
|
THROW_IF(IS_NULLPTR(renderer),
|
||||||
|
std::runtime_error("Failed to create SDL_Renderer* from SDL_Surface*: " + std::string(SDL_GetError())));
|
||||||
|
|
||||||
|
m_oTimeSinceLastDisplay = std::chrono::steady_clock::now();
|
||||||
|
}
|
||||||
|
SDLU_END
|
37
src/graphics/RenderWindow.cpp
Normal file
37
src/graphics/RenderWindow.cpp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#include "graphics/RenderWindow.hpp"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <Util.hpp>
|
||||||
|
|
||||||
|
SDLU_BEGIN
|
||||||
|
RenderWindow::RenderWindow() :
|
||||||
|
Window(), RenderTarget(window)
|
||||||
|
{
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderWindow::RenderWindow(Vector2u dimension, const std::string& title,
|
||||||
|
Uint32 windowFlags) :
|
||||||
|
Window(dimension, title, windowFlags), RenderTarget(window)
|
||||||
|
{
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderWindow::~RenderWindow()
|
||||||
|
{
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderWindow::OnCreate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderWindow::OnResize()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderWindow::OnClose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
SDLU_END
|
94
src/graphics/drawable/Transformable.cpp
Normal file
94
src/graphics/drawable/Transformable.cpp
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
#include "graphics/drawable/Transformable.hpp"
|
||||||
|
|
||||||
|
SDLU_BEGIN
|
||||||
|
Transformable::Transformable() :
|
||||||
|
position(0, 0), origin(0, 0),
|
||||||
|
scale(1.f, 1.f), rotation(0.f)
|
||||||
|
{
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable::~Transformable()
|
||||||
|
{
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2f Transformable::GetPosition()
|
||||||
|
{
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::SetPosition(const Vector2f& position)
|
||||||
|
{
|
||||||
|
this->position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::SetPosition(float x, float y)
|
||||||
|
{
|
||||||
|
position = Vector2f(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::Move(const Vector2f& position)
|
||||||
|
{
|
||||||
|
this->position += position;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::Move(float x, float y)
|
||||||
|
{
|
||||||
|
position += Vector2f(x, y);
|
||||||
|
}
|
||||||
|
Vector2f Transformable::GetOrigin()
|
||||||
|
{
|
||||||
|
return origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::SetOrigin(const Vector2f& origin)
|
||||||
|
{
|
||||||
|
this->origin = origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::SetOrigin(float x, float y)
|
||||||
|
{
|
||||||
|
origin = Vector2f(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2f Transformable::GetScale()
|
||||||
|
{
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::SetScale(const Vector2f& scale)
|
||||||
|
{
|
||||||
|
this->scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::SetScale(float x, float y)
|
||||||
|
{
|
||||||
|
scale = Vector2f(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::Scale(const Vector2f& scale)
|
||||||
|
{
|
||||||
|
this->scale += scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::Scale(float x, float y)
|
||||||
|
{
|
||||||
|
scale += Vector2f(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
float Transformable::GetRotation()
|
||||||
|
{
|
||||||
|
return rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::SetRotation(float angle)
|
||||||
|
{
|
||||||
|
rotation = angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transformable::Rotate(float angle)
|
||||||
|
{
|
||||||
|
rotation += angle;
|
||||||
|
}
|
||||||
|
SDLU_END
|
|
@ -1,7 +1,8 @@
|
||||||
#include "Rectangle.hpp"
|
#include <graphics/drawable/shapes/Rectangle.hpp>
|
||||||
|
|
||||||
#include <graphics/RenderTarget.hpp>
|
#include <graphics/RenderTarget.hpp>
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
namespace sdlu
|
namespace sdlu
|
||||||
{
|
{
|
||||||
Rectangle::Rectangle() :
|
Rectangle::Rectangle() :
|
|
@ -1,4 +1,4 @@
|
||||||
#include "Shape.hpp"
|
#include <graphics/drawable/shapes/Shape.hpp>
|
||||||
|
|
||||||
namespace sdlu
|
namespace sdlu
|
||||||
{
|
{
|
162
src/structures/Color.cpp
Normal file
162
src/structures/Color.cpp
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
#include "structures/Color.hpp"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
SDLU_BEGIN
|
||||||
|
const Color Color::Black = Color(0, 0, 0);
|
||||||
|
const Color Color::Red = Color(255, 0, 0);
|
||||||
|
const Color Color::Green = Color(0, 255, 0);
|
||||||
|
const Color Color::Blue = Color(0, 0, 255);
|
||||||
|
const Color Color::Yellow = Color(255, 255, 0);
|
||||||
|
const Color Color::Magenta = Color(255, 0, 255);
|
||||||
|
const Color Color::Cyan = Color(0, 255, 255);
|
||||||
|
const Color Color::White = Color(255, 255, 255);
|
||||||
|
|
||||||
|
const Color Color::Transparent = Color(0, 0, 0, 0);
|
||||||
|
|
||||||
|
Color::Color() :
|
||||||
|
r(0), g(0), b(0), a(0)
|
||||||
|
{
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
Color::Color(Uint8 r, Uint8 g, Uint8 b, Uint8 a) :
|
||||||
|
r(r), g(g), b(b), a(a)
|
||||||
|
{
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
Color::Color(Uint32 color) :
|
||||||
|
r((color & 0xFF000000) >> 24),
|
||||||
|
g((color & 0x00FF0000) >> 16),
|
||||||
|
b((color & 0x0000FF00) >> 8),
|
||||||
|
a((color & 0x000000FF))
|
||||||
|
{
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint32 Color::ToInt()
|
||||||
|
{
|
||||||
|
Uint32 color = 0;
|
||||||
|
color |= r << 24;
|
||||||
|
color |= g << 16;
|
||||||
|
color |= b << 8;
|
||||||
|
color |= a;
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color Color::FromHSV(Uint16 h, Uint8 s, Uint8 v)
|
||||||
|
{
|
||||||
|
// Normalize parameters
|
||||||
|
// H : [0, 360)
|
||||||
|
// S : [0, 1]
|
||||||
|
// V : [0, 1]
|
||||||
|
h -= std::floor(h / 360) * 360;
|
||||||
|
s = (s > 1) ? 1 : s;
|
||||||
|
v = (v > 1) ? 1 : v;
|
||||||
|
|
||||||
|
// Convert to RGBA
|
||||||
|
Uint16 H = std::floor(h / 60.f);
|
||||||
|
float f = (h / 60.f) - H;
|
||||||
|
|
||||||
|
Uint8 p = static_cast<Uint8>((v * (1 - s)) * 255);
|
||||||
|
Uint8 q = static_cast<Uint8>((v * (1 - s * f)) * 255);
|
||||||
|
Uint8 t = static_cast<Uint8>((v * (1 - s * (1 - f))) * 255);
|
||||||
|
v *= 255;
|
||||||
|
|
||||||
|
Color output;
|
||||||
|
switch (H)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
case 6:
|
||||||
|
output = Color(v, t, p);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
output = Color(q, v, p);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
output = Color(p, v, t);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
output = Color(p, q, v);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
output = Color(t, p, v);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
output = Color(v, p, q);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color operator+(const Color& left, const Color& right)
|
||||||
|
{
|
||||||
|
return Color((UINT8_MAX - left.r) < right.r ? 255 : left.r + right.r,
|
||||||
|
(UINT8_MAX - left.g) < right.g ? 255 : left.g + right.g,
|
||||||
|
(UINT8_MAX - left.b) < right.b ? 255 : left.b + right.b,
|
||||||
|
(UINT8_MAX - left.a) < right.a ? 255 : left.a + right.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
Color operator-(const Color& left, const Color& right)
|
||||||
|
{
|
||||||
|
return Color(left.r < right.r ? 0 : left.r - right.r,
|
||||||
|
left.g < right.g ? 0 : left.g - right.g,
|
||||||
|
left.b < right.b ? 0 : left.b - right.b,
|
||||||
|
left.a < right.a ? 0 : left.a - right.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
Color operator*(const Color& left, const Color& right)
|
||||||
|
{
|
||||||
|
return Color((UINT8_MAX / left.r) < right.r ? 255 : left.r * right.r,
|
||||||
|
(UINT8_MAX / left.g) < right.g ? 255 : left.g * right.g,
|
||||||
|
(UINT8_MAX / left.b) < right.b ? 255 : left.b * right.b,
|
||||||
|
(UINT8_MAX / left.a) < right.a ? 255 : left.a * right.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
Color operator/(const Color& left, const Color& right)
|
||||||
|
{
|
||||||
|
return Color(left.r / right.r,
|
||||||
|
left.g / right.g,
|
||||||
|
left.b / right.b,
|
||||||
|
left.a / right.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
Color& operator+=(Color& left, const Color& right)
|
||||||
|
{
|
||||||
|
left = left + right;
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color& operator-=(Color& left, const Color& right)
|
||||||
|
{
|
||||||
|
left = left - right;
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color& operator*=(Color& left, const Color& right)
|
||||||
|
{
|
||||||
|
left = left * right;
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color& operator/=(Color& left, const Color& right)
|
||||||
|
{
|
||||||
|
left = left / right;
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Color& left, const Color& right)
|
||||||
|
{
|
||||||
|
return ((left.r == right.r) && (left.g == right.g) && (left.b == right.b) && (left.a == right.a));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Color& left, const Color& right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
|
SDLU_END
|
37
src/structures/Mouse.cpp
Normal file
37
src/structures/Mouse.cpp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#include <structures/Mouse.hpp>
|
||||||
|
|
||||||
|
#include <SDL_mouse.h>
|
||||||
|
|
||||||
|
SDLU_BEGIN
|
||||||
|
Uint32 Mouse::GetButtonState()
|
||||||
|
{
|
||||||
|
return SDL_GetMouseState(NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Mouse::IsButtonDown(Button button)
|
||||||
|
{
|
||||||
|
return (GetButtonState() & SDL_BUTTON(static_cast<int>(button)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2i Mouse::GetPosition()
|
||||||
|
{
|
||||||
|
int x = 0, y = 0;
|
||||||
|
SDL_GetGlobalMouseState(&x, &y);
|
||||||
|
return Vector2i(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2i Mouse::GetPosition(const RenderWindow& relativeTo)
|
||||||
|
{
|
||||||
|
return GetPosition() - relativeTo.GetPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mouse::SetPosition(const Vector2i& position)
|
||||||
|
{
|
||||||
|
SDL_WarpMouseGlobal(position.x, position.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mouse::SetPosition(const Vector2i& position, const RenderWindow& relativeTo)
|
||||||
|
{
|
||||||
|
SDL_WarpMouseInWindow(relativeTo.GetWindow(), position.x, position.y);
|
||||||
|
}
|
||||||
|
SDLU_END
|
245
src/structures/Window.cpp
Normal file
245
src/structures/Window.cpp
Normal file
|
@ -0,0 +1,245 @@
|
||||||
|
#include "structures/Window.hpp"
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
SDLU_BEGIN
|
||||||
|
Window::Window() :
|
||||||
|
window(nullptr)
|
||||||
|
{
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
Window::Window(Vector2u dimension, const std::string& title, Uint32 windowFlags) :
|
||||||
|
Window()
|
||||||
|
{
|
||||||
|
Create(dimension, title, windowFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
Window::~Window()
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::Create(Vector2u dimension, const std::string& title, Uint32 windowFlags)
|
||||||
|
{
|
||||||
|
// Don't create a window when it already exists
|
||||||
|
RETURN_IF_NOT_NULLPTR(window);
|
||||||
|
|
||||||
|
window = SDL_CreateWindow(title.c_str(),
|
||||||
|
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||||
|
dimension.x, dimension.y,
|
||||||
|
windowFlags);
|
||||||
|
|
||||||
|
THROW_IF(IS_NULLPTR(window),
|
||||||
|
std::runtime_error("Failed to create SDL_Window. \nSDL_GetError(): " + std::string(SDL_GetError())));
|
||||||
|
|
||||||
|
OnCreate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::Close()
|
||||||
|
{
|
||||||
|
// Don't destroy a window that doesn't exist
|
||||||
|
RETURN_IF_NULLPTR(window);
|
||||||
|
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
window = nullptr;
|
||||||
|
|
||||||
|
OnClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Window::IsOpen() const
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(window, false);
|
||||||
|
return (!SDL_GetWindowID(window) ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Window::PollEvent(SDL_Event* event)
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(window, false);
|
||||||
|
// Handle events before the user in case a derived
|
||||||
|
// class decides to block the event.
|
||||||
|
while (SDL_PollEvent(event))
|
||||||
|
{
|
||||||
|
switch (event->window.event)
|
||||||
|
{
|
||||||
|
case SDL_WINDOWEVENT_RESIZED: if (!OnResize()) return true; break;
|
||||||
|
default: return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Window::WaitEvent(SDL_Event* event)
|
||||||
|
{
|
||||||
|
while (!PollEvent(event)) continue;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2i Window::GetPosition() const
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(window, Vector2i());
|
||||||
|
|
||||||
|
int x = 0, y = 0;
|
||||||
|
SDL_GetWindowPosition(window, &x, &y);
|
||||||
|
return Vector2i(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetPosition(Vector2i position)
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(window);
|
||||||
|
|
||||||
|
SDL_SetWindowPosition(window, position.x, position.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(window);
|
||||||
|
|
||||||
|
SDL_SetWindowPosition(window, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2u Window::GetSize() const
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(window, Vector2u());
|
||||||
|
|
||||||
|
int x = 0, y = 0;
|
||||||
|
SDL_GetWindowSize(window, &x, &y);
|
||||||
|
return Vector2u(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetSize(Vector2u size)
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(window);
|
||||||
|
|
||||||
|
SDL_SetWindowSize(window, size.x, size.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetSize(unsigned int width, unsigned int height)
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(window);
|
||||||
|
|
||||||
|
SDL_SetWindowSize(window, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Window::GetTitle() const
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(window, "");
|
||||||
|
|
||||||
|
return SDL_GetWindowTitle(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetTitle(std::string title)
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(window);
|
||||||
|
|
||||||
|
SDL_SetWindowTitle(window, title.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Window* const Window::GetWindow() const
|
||||||
|
{
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetVisible(bool visible)
|
||||||
|
{
|
||||||
|
RETURN_IF_NULLPTR(window);
|
||||||
|
if (visible)
|
||||||
|
SDL_ShowWindow(window);
|
||||||
|
else
|
||||||
|
SDL_HideWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetVsync(bool vsync)
|
||||||
|
{
|
||||||
|
// SDL actually doesn't allow you to change the VSync
|
||||||
|
// flag of a Renderer after it's been created. This
|
||||||
|
// Changes it globally for all other windows
|
||||||
|
SDL_GL_SetSwapInterval(vsync);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetMouseCursorVisible(bool visible)
|
||||||
|
{
|
||||||
|
SDL_ShowCursor(visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetMouseCursorGrabbed(bool grabbed)
|
||||||
|
{
|
||||||
|
SDL_SetWindowGrab(window, grabbed ? SDL_TRUE : SDL_FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetIcon(Uint32 width, Uint32 height, const Uint8* pixels)
|
||||||
|
{
|
||||||
|
size_t size = static_cast<size_t>(width) * static_cast<size_t>(height) * 4;
|
||||||
|
void* _pixels = malloc(size);
|
||||||
|
memcpy(_pixels, pixels, size);
|
||||||
|
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
|
||||||
|
width, height, 32, 32 * width,
|
||||||
|
SDL_PIXELFORMAT_RGBA8888);
|
||||||
|
|
||||||
|
SDL_SetWindowIcon(window, surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetIcon(Uint32 width, Uint32 height, const Uint32* pixels)
|
||||||
|
{
|
||||||
|
size_t size = static_cast<size_t>(width) * static_cast<size_t>(height) * 4;
|
||||||
|
void* _pixels = malloc(size);
|
||||||
|
memcpy(_pixels, pixels, size);
|
||||||
|
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
|
||||||
|
width, height, 32, 4 * width,
|
||||||
|
SDL_PIXELFORMAT_RGBA8888);
|
||||||
|
|
||||||
|
SDL_SetWindowIcon(window, surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetIcon(SDL_Surface* icon)
|
||||||
|
{
|
||||||
|
SDL_SetWindowIcon(window, icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetMouseCursor(SDL_Cursor* cursor)
|
||||||
|
{
|
||||||
|
SDL_SetCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetMouseCursor(SDL_Surface* surface, Vector2u clickspot)
|
||||||
|
{
|
||||||
|
SDL_Cursor* _cursor = SDL_CreateColorCursor(surface, clickspot.x, clickspot.y);
|
||||||
|
SDL_SetCursor(_cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetMouseCursor(const Uint8* pixels, Vector2u size, Vector2u clickspot)
|
||||||
|
{
|
||||||
|
size_t _size = static_cast<size_t>(size.x) * static_cast<size_t>(size.y) * 4;
|
||||||
|
void* _pixels = malloc(_size);
|
||||||
|
memcpy(_pixels, pixels, _size);
|
||||||
|
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
|
||||||
|
size.x, size.y, 32, 8 * size.x, SDL_PIXELFORMAT_RGBA8888);
|
||||||
|
this->SetMouseCursor(surface, clickspot);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::SetMouseCursor(const Uint32* pixels, Vector2u size, Vector2u clickspot)
|
||||||
|
{
|
||||||
|
size_t _size = static_cast<size_t>(size.x) * static_cast<size_t>(size.y) * 4;
|
||||||
|
void* _pixels = malloc(_size);
|
||||||
|
memcpy(_pixels, pixels, _size);
|
||||||
|
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
|
||||||
|
size.x, size.y, 32, 8 * size.x, SDL_PIXELFORMAT_RGBA32);
|
||||||
|
this->SetMouseCursor(surface, clickspot);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::OnCreate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Window::OnResize()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::OnClose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
SDLU_END
|
Loading…
Reference in a new issue