spacebox/src/Box.cpp

198 lines
2.7 KiB
C++

#include "Box.hpp"
Box::Box(glm::vec2 nw, glm::vec2 size)
{
set_nw(nw);
set_size(size);
}
float Box::get_x() const
{
return rect.x;
}
float Box::get_y() const
{
return rect.y;
}
float Box::get_w() const
{
return rect.w;
}
float Box::get_h() const
{
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() const
{
return glm::vec2(get_w(), get_h());
}
void Box::set_size(const glm::vec2& size)
{
set_w(size.x);
set_h(size.y);
}
float Box::get_top() const
{
return get_y();
}
float Box::get_right() const
{
return get_x() + get_w();
}
float Box::get_bottom() const
{
return get_y() + get_h();
}
float Box::get_left() const
{
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() const
{
return glm::vec2(get_x(), get_y());
}
glm::vec2 Box::get_north() const
{
return glm::vec2(get_x() + get_w() / 2, get_y());
}
glm::vec2 Box::get_ne() const
{
return glm::vec2(get_right(), get_y());
}
glm::vec2 Box::get_east() const
{
return glm::vec2(get_right(), get_y() + get_h() / 2);
}
glm::vec2 Box::get_south() const
{
return glm::vec2(get_x() + get_w() / 2, get_bottom());
}
glm::vec2 Box::get_west() const
{
return glm::vec2(get_x(), get_y() + get_h() / 2);
}
glm::vec2 Box::get_center() const
{
return glm::vec2(get_x() + get_w() / 2, get_y() + get_h() / 2);
}
void Box::set_nw(const glm::vec2& nw)
{
set_x(nw.x);
set_y(nw.y);
}
void Box::set_north(const glm::vec2& n)
{
move(n - get_north());
}
void Box::set_ne(const glm::vec2& ne)
{
move(ne - get_ne());
}
void Box::set_east(const glm::vec2& e)
{
move(e - get_east());
}
void Box::set_south(const glm::vec2& s)
{
move(s - get_south());
}
void Box::set_west(const glm::vec2& w)
{
move(w - get_west());
}
void Box::set_center(const 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(const 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);
}