88 lines
2.2 KiB
C++
88 lines
2.2 KiB
C++
#ifndef Box_h_
|
|
#define Box_h_
|
|
|
|
#include <iostream>
|
|
#include <algorithm>
|
|
#include <stdexcept>
|
|
|
|
#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 width() const;
|
|
void width(float);
|
|
float height() const;
|
|
void height(float);
|
|
glm::vec2 size() const;
|
|
void size(const glm::vec2&, bool = false);
|
|
float aspect() const;
|
|
float area() const;
|
|
float top() const;
|
|
float right() const;
|
|
float bottom() const;
|
|
float left() const;
|
|
float cx() const;
|
|
float cy() const;
|
|
void top(float, bool = false);
|
|
void drag_top(float);
|
|
void right(float, bool = false);
|
|
void drag_right(float);
|
|
void bottom(float, bool = false);
|
|
void drag_bottom(float);
|
|
void left(float, bool = false);
|
|
void drag_left(float);
|
|
void cx(float);
|
|
void cy(float);
|
|
glm::vec2 nw() const;
|
|
glm::vec2 north() const;
|
|
glm::vec2 ne() const;
|
|
glm::vec2 east() const;
|
|
glm::vec2 se() const;
|
|
glm::vec2 south() const;
|
|
glm::vec2 sw() const;
|
|
glm::vec2 west() const;
|
|
glm::vec2 center() const;
|
|
void nw(const glm::vec2&);
|
|
void north(const glm::vec2&);
|
|
void ne(const glm::vec2&);
|
|
void east(const glm::vec2&);
|
|
void se(const glm::vec2&);
|
|
void south(const glm::vec2&);
|
|
void sw(const glm::vec2&);
|
|
void west(const glm::vec2&);
|
|
void 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 class_name() const { return "Box"; }
|
|
std::string string() const;
|
|
|
|
};
|
|
|
|
std::ostream& operator<<(std::ostream&, const Box&);
|
|
|
|
#endif
|