188 lines
2.4 KiB
C++
188 lines
2.4 KiB
C++
#include "Box.hpp"
|
|
|
|
Box::Box(glm::vec2 nw, glm::vec2 size)
|
|
{
|
|
set_nw(nw);
|
|
set_size(size);
|
|
}
|
|
|
|
float Box::get_x()
|
|
{
|
|
return rect.x;
|
|
}
|
|
|
|
float Box::get_y()
|
|
{
|
|
return rect.y;
|
|
}
|
|
|
|
float Box::get_w()
|
|
{
|
|
return rect.w;
|
|
}
|
|
|
|
float Box::get_h()
|
|
{
|
|
return rect.h;
|
|
}
|
|
|
|
void Box::set_x(float x)
|
|
{
|
|
rect.x = x;
|
|
}
|
|
|
|
void Box::set_y(float y)
|
|
{
|
|
rect.y = y;
|
|
}
|
|
|
|
void Box::set_w(float w)
|
|
{
|
|
rect.w = w;
|
|
}
|
|
|
|
void Box::set_h(float h)
|
|
{
|
|
rect.h = h;
|
|
}
|
|
|
|
glm::vec2 Box::get_size()
|
|
{
|
|
return glm::vec2(get_w(), get_h());
|
|
}
|
|
|
|
void Box::set_size(glm::vec2 size)
|
|
{
|
|
set_w(size.x);
|
|
set_h(size.y);
|
|
}
|
|
|
|
float Box::get_top()
|
|
{
|
|
return get_y();
|
|
}
|
|
|
|
float Box::get_right()
|
|
{
|
|
return get_x() + get_w();
|
|
}
|
|
|
|
float Box::get_bottom()
|
|
{
|
|
return get_y() + get_h();
|
|
}
|
|
|
|
float Box::get_left()
|
|
{
|
|
return get_x();
|
|
}
|
|
|
|
void Box::set_top(float top)
|
|
{
|
|
set_y(top);
|
|
}
|
|
|
|
void Box::set_right(float right)
|
|
{
|
|
move(glm::vec2(right - get_right(), 0));
|
|
}
|
|
|
|
void Box::set_bottom(float bottom)
|
|
{
|
|
move(glm::vec2(0, bottom - get_bottom()));
|
|
}
|
|
|
|
void Box::set_left(float left)
|
|
{
|
|
set_x(left);
|
|
}
|
|
|
|
glm::vec2 Box::get_nw()
|
|
{
|
|
return glm::vec2(get_x(), get_y());
|
|
}
|
|
|
|
glm::vec2 Box::get_north()
|
|
{
|
|
return glm::vec2(get_x() + get_w() / 2, get_y());
|
|
}
|
|
|
|
glm::vec2 Box::get_east()
|
|
{
|
|
return glm::vec2(get_right(), get_y() + get_h() / 2);
|
|
}
|
|
|
|
glm::vec2 Box::get_south()
|
|
{
|
|
return glm::vec2(get_x() + get_w() / 2, get_bottom());
|
|
}
|
|
|
|
glm::vec2 Box::get_west()
|
|
{
|
|
return glm::vec2(get_x(), get_y() + get_h() / 2);
|
|
}
|
|
|
|
glm::vec2 Box::get_center()
|
|
{
|
|
return glm::vec2(get_x() + get_w() / 2, get_y() + get_h() / 2);
|
|
}
|
|
|
|
void Box::set_nw(glm::vec2 nw)
|
|
{
|
|
set_x(nw.x);
|
|
set_y(nw.y);
|
|
}
|
|
|
|
void Box::set_north(glm::vec2 n)
|
|
{
|
|
move(n - get_north());
|
|
}
|
|
|
|
void Box::set_east(glm::vec2 e)
|
|
{
|
|
move(e - get_east());
|
|
}
|
|
|
|
void Box::set_south(glm::vec2 s)
|
|
{
|
|
move(s - get_south());
|
|
}
|
|
|
|
void Box::set_west(glm::vec2 w)
|
|
{
|
|
move(w - get_west());
|
|
}
|
|
|
|
void Box::set_center(glm::vec2 center)
|
|
{
|
|
move(center - get_center());
|
|
}
|
|
|
|
SDL_FRect* Box::get_rect()
|
|
{
|
|
return ▭
|
|
}
|
|
|
|
void Box::zero()
|
|
{
|
|
set_nw(glm::vec2(0, 0));
|
|
set_size(glm::vec2(0, 0));
|
|
}
|
|
|
|
void Box::move(glm::vec2 delta)
|
|
{
|
|
set_x(get_x() + delta.x);
|
|
set_y(get_y() + delta.y);
|
|
}
|
|
|
|
std::ostream& Box::to_string (std::ostream& out) const
|
|
{
|
|
out << "{(" << rect.x << ", " << rect.y << "), (" << rect.w << ", " << rect.h << ")}";
|
|
return out;
|
|
}
|
|
|
|
std::ostream& operator<< (std::ostream& out, const Box& box)
|
|
{
|
|
return box.to_string(out);
|
|
}
|