SwitchGame/source/Tool/Common.h

81 lines
1.5 KiB
C
Raw Normal View History

2025-09-15 11:28:54 +08:00
#pragma once
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstddef>
2025-09-19 12:18:57 +08:00
#include <SDL.h>
2025-09-15 11:28:54 +08:00
/// \~chinese
/// @brief 不可拷贝对象
class Noncopyable
{
protected:
Noncopyable() = default;
private:
Noncopyable(const Noncopyable &) = delete;
Noncopyable &operator=(const Noncopyable &) = delete;
};
2025-09-19 12:18:57 +08:00
typedef struct VecPos
{
int x;
int y;
// 构造函数,方便初始化
VecPos(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}
// 定义到 SDL_Point 的转换运算符
operator SDL_Point() const
{
return {x, y}; // 直接返回包含 x、y 的 SDL_Point
}
// 加法运算符重载:两个 VecPos 相加
VecPos operator+(const VecPos &other) const
{
return VecPos(x + other.x, y + other.y);
}
// 减法运算符重载:两个 VecPos 相减
VecPos operator-(const VecPos &other) const
{
return VecPos(x - other.x, y - other.y);
}
// 复合赋值加法:当前对象加上另一个 VecPos
VecPos &operator+=(const VecPos &other)
{
x += other.x;
y += other.y;
return *this;
}
// 复合赋值减法:当前对象减去另一个 VecPos
VecPos &operator-=(const VecPos &other)
{
x -= other.x;
y -= other.y;
return *this;
}
} VecPos;
typedef struct VecFPos
{
float x;
float y;
} VecFPos;
typedef struct VecSize
{
int width;
int height;
} VecSize;