90 lines
2.5 KiB
C++
90 lines
2.5 KiB
C++
#ifndef Box_h_
|
|
#define Box_h_
|
|
|
|
#include <iostream>
|
|
#include <algorithm>
|
|
|
|
#include "SDL.h"
|
|
|
|
#define GLM_ENABLE_EXPERIMENTAL
|
|
#include "glm/common.hpp"
|
|
#include "glm/vec2.hpp"
|
|
|
|
class Segment;
|
|
|
|
class Box : public SDL_FRect
|
|
{
|
|
|
|
public:
|
|
|
|
Box(const glm::vec2& = {0, 0}, const glm::vec2& = {0, 0});
|
|
Box(const SDL_Rect&);
|
|
float get_x() const;
|
|
float get_y() const;
|
|
float get_w() const;
|
|
float get_h() const;
|
|
void set_x(float);
|
|
void set_y(float);
|
|
void set_w(float);
|
|
void set_h(float);
|
|
glm::vec2 get_size() const;
|
|
void set_size(const glm::vec2&, bool = false);
|
|
float get_area() const;
|
|
float get_top() const;
|
|
float get_right() const;
|
|
float get_bottom() const;
|
|
float get_left() const;
|
|
float get_center_x() const;
|
|
float get_center_y() const;
|
|
void set_top(float, bool=false);
|
|
void drag_top(float);
|
|
void set_right(float, bool=false);
|
|
void drag_right(float);
|
|
void set_bottom(float, bool=false);
|
|
void drag_bottom(float);
|
|
void set_left(float, bool=false);
|
|
void drag_left(float);
|
|
void set_center_x(float);
|
|
void set_center_y(float);
|
|
glm::vec2 get_nw() const;
|
|
glm::vec2 get_north() const;
|
|
glm::vec2 get_ne() const;
|
|
glm::vec2 get_east() const;
|
|
glm::vec2 get_se() const;
|
|
glm::vec2 get_south() const;
|
|
glm::vec2 get_sw() const;
|
|
glm::vec2 get_west() const;
|
|
glm::vec2 get_center() const;
|
|
void set_nw(const glm::vec2&);
|
|
void set_north(const glm::vec2&);
|
|
void set_ne(const glm::vec2&);
|
|
void set_east(const glm::vec2&);
|
|
void set_se(const glm::vec2&);
|
|
void set_south(const glm::vec2&);
|
|
void set_sw(const glm::vec2&);
|
|
void set_west(const glm::vec2&);
|
|
void set_center(const glm::vec2&);
|
|
operator SDL_Rect() const;
|
|
void clear();
|
|
void scale(glm::vec2, bool = false);
|
|
void scale(float, bool = false);
|
|
void expand(glm::vec2, bool = false);
|
|
void expand(float, bool = false);
|
|
void move(const glm::vec2&);
|
|
Box stamp(const glm::vec2&) const;
|
|
bool fits(const Box&) const;
|
|
void crop(const Box&);
|
|
bool collide(const glm::vec2&) const;
|
|
bool collide(const Segment&, glm::vec2* = nullptr) const;
|
|
bool collide(const Segment&, glm::vec2&) const;
|
|
bool collide(const Box&, Box* = nullptr) const;
|
|
bool collide(const Box&, Box&) const;
|
|
virtual std::string get_class_name() const { return "Box"; }
|
|
std::ostream& to_string (std::ostream&) const;
|
|
|
|
};
|
|
|
|
std::ostream& operator<<(std::ostream&, const Box&);
|
|
|
|
#endif
|