restructured everything
This commit is contained in:
parent
4225a524b9
commit
c66cae17f2
61 changed files with 18406 additions and 1710 deletions
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
|
45
src/graphics/drawable/shapes/Rectangle.cpp
Normal file
45
src/graphics/drawable/shapes/Rectangle.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <graphics/drawable/shapes/Rectangle.hpp>
|
||||
#include <graphics/RenderTarget.hpp>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
namespace sdlu
|
||||
{
|
||||
Rectangle::Rectangle() :
|
||||
Shape()
|
||||
{
|
||||
}
|
||||
|
||||
Rectangle::Rectangle(const Vector2f& position, const Vector2f& size) :
|
||||
Shape()
|
||||
{
|
||||
this->position = position;
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
Vector2f Rectangle::GetSize()
|
||||
{
|
||||
return this->size;
|
||||
}
|
||||
|
||||
void Rectangle::SetSize(const Vector2f& size)
|
||||
{
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
void Rectangle::SetSize(float x, float y)
|
||||
{
|
||||
this->size = Vector2f(x, y);
|
||||
}
|
||||
|
||||
void Rectangle::Draw(SDL_Renderer* const renderer) const
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_Rect rect;
|
||||
rect.x = position.x;
|
||||
rect.y = position.y;
|
||||
rect.w = size.x;
|
||||
rect.h = size.y;
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
}
|
23
src/graphics/drawable/shapes/Shape.cpp
Normal file
23
src/graphics/drawable/shapes/Shape.cpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include <graphics/drawable/shapes/Shape.hpp>
|
||||
|
||||
namespace sdlu
|
||||
{
|
||||
Shape::~Shape()
|
||||
{
|
||||
}
|
||||
|
||||
void Shape::SetColor(const Color& color)
|
||||
{
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
Color Shape::GetColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
Shape::Shape() :
|
||||
Drawable(), Transformable()
|
||||
{
|
||||
}
|
||||
}
|
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…
Add table
Add a link
Reference in a new issue