Files
2026-05-13 19:48:22 +00:00

67 lines
2.4 KiB
C++

#pragma once
/// @file Rect.hpp
/// For complete documentation, see src/Rect.cpp
#include <SDL3/SDL_rect.h>
namespace hdk::sdl {
class FRect;
class Rect : public SDL_Rect {
public:
using SDL_Rect::SDL_Rect;
Rect()
: SDL_Rect { 0, 0, 0, 0 } { }
Rect(SDL_Rect another)
: SDL_Rect { another.x, another.y, another.w, another.h } { }
Rect(SDL_FRect another)
: SDL_Rect { static_cast<int>(another.x), static_cast<int>(another.y), static_cast<int>(another.w),
static_cast<int>(another.h) } { }
Rect(FRect another);
Rect& scale(float scaleX, float scaleY) {
x = static_cast<int>(x * scaleX);
y = static_cast<int>(y * scaleY);
w = static_cast<int>(w * scaleX);
h = static_cast<int>(h * scaleY);
return *this;
}
Rect& scale(float scale) { return this->scale(scale, scale); }
Rect& operator*=(float scale) { return this->scale(scale); }
operator SDL_FRect() const {
return SDL_FRect { static_cast<float>(x), static_cast<float>(y), static_cast<float>(w), static_cast<float>(h) };
}
};
class FRect : public SDL_FRect {
public:
using SDL_FRect::SDL_FRect;
FRect()
: SDL_FRect { 0.0f, 0.0f, 0.0f, 0.0f } { }
FRect(SDL_FRect another)
: SDL_FRect { another.x, another.y, another.w, another.h } { }
FRect(SDL_Rect another)
: SDL_FRect { static_cast<float>(another.x), static_cast<float>(another.y), static_cast<float>(another.w),
static_cast<float>(another.h) } { }
FRect(Rect another)
: SDL_FRect { static_cast<float>(another.x), static_cast<float>(another.y), static_cast<float>(another.w),
static_cast<float>(another.h) } { }
FRect& scale(float scaleX, float scaleY) {
x = x * scaleX;
y = y * scaleY;
w = w * scaleX;
h = h * scaleY;
return *this;
}
FRect& scale(float scale) { return this->scale(scale, scale); }
FRect& operator*=(float scale) { return this->scale(scale); }
operator SDL_Rect() const {
return SDL_Rect { static_cast<int>(x), static_cast<int>(y), static_cast<int>(w), static_cast<int>(h) };
}
};
inline Rect::Rect(FRect another)
: SDL_Rect { static_cast<int>(another.x), static_cast<int>(another.y), static_cast<int>(another.w),
static_cast<int>(another.h) } { }
}