2020-06-27 17:47:14 -04:00
|
|
|
#ifndef Box_h_
|
|
|
|
#define Box_h_
|
|
|
|
|
|
|
|
#include <iostream>
|
2020-08-09 16:32:32 -04:00
|
|
|
#include <algorithm>
|
2021-08-14 19:53:39 -04:00
|
|
|
#include <stdexcept>
|
2020-06-27 17:47:14 -04:00
|
|
|
|
2020-09-05 19:40:59 -04:00
|
|
|
#include "SDL.h"
|
2020-06-27 17:47:14 -04:00
|
|
|
|
|
|
|
#define GLM_ENABLE_EXPERIMENTAL
|
|
|
|
#include "glm/common.hpp"
|
|
|
|
#include "glm/vec2.hpp"
|
|
|
|
|
2021-06-26 20:25:03 -04:00
|
|
|
class Segment;
|
2020-08-09 16:32:32 -04:00
|
|
|
|
2021-06-26 20:25:03 -04:00
|
|
|
class Box : public SDL_FRect
|
2020-06-27 17:47:14 -04:00
|
|
|
{
|
2020-08-22 20:06:06 -04:00
|
|
|
|
2021-06-26 20:25:03 -04:00
|
|
|
public:
|
|
|
|
|
2020-07-25 17:55:27 -04:00
|
|
|
Box(const glm::vec2& = {0, 0}, const glm::vec2& = {0, 0});
|
2020-09-12 20:29:26 -04:00
|
|
|
Box(const SDL_Rect&);
|
2021-08-14 19:53:39 -04:00
|
|
|
float width() const;
|
|
|
|
void width(float);
|
|
|
|
float height() const;
|
|
|
|
void height(float);
|
|
|
|
glm::vec2 size() const;
|
|
|
|
void size(const glm::vec2&, bool = false);
|
2021-07-21 02:08:45 -04:00
|
|
|
float aspect() const;
|
2021-08-14 19:53:39 -04:00
|
|
|
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);
|
2020-09-12 20:29:26 -04:00
|
|
|
void drag_top(float);
|
2021-08-14 19:53:39 -04:00
|
|
|
void right(float, bool = false);
|
2020-08-06 18:54:50 -04:00
|
|
|
void drag_right(float);
|
2021-08-14 19:53:39 -04:00
|
|
|
void bottom(float, bool = false);
|
2020-09-12 20:29:26 -04:00
|
|
|
void drag_bottom(float);
|
2021-08-14 19:53:39 -04:00
|
|
|
void left(float, bool = false);
|
2020-08-06 18:54:50 -04:00
|
|
|
void drag_left(float);
|
2021-08-14 19:53:39 -04:00
|
|
|
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&);
|
2020-08-22 20:06:06 -04:00
|
|
|
operator SDL_Rect() const;
|
2020-07-25 17:55:27 -04:00
|
|
|
void clear();
|
2020-08-29 23:49:45 -04:00
|
|
|
void scale(glm::vec2, bool = false);
|
2020-07-31 12:10:21 -04:00
|
|
|
void scale(float, bool = false);
|
2020-09-02 23:32:01 -04:00
|
|
|
void expand(glm::vec2, bool = false);
|
|
|
|
void expand(float, bool = false);
|
2020-07-17 22:58:23 -04:00
|
|
|
void move(const glm::vec2&);
|
2020-09-06 03:02:02 -04:00
|
|
|
Box stamp(const glm::vec2&) const;
|
2020-09-12 20:29:26 -04:00
|
|
|
bool fits(const Box&) const;
|
|
|
|
void crop(const Box&);
|
2020-08-09 16:32:32 -04:00
|
|
|
bool collide(const glm::vec2&) const;
|
2020-08-26 16:43:43 -04:00
|
|
|
bool collide(const Segment&, glm::vec2* = nullptr) const;
|
2020-08-09 16:32:32 -04:00
|
|
|
bool collide(const Segment&, glm::vec2&) const;
|
2020-08-26 16:43:43 -04:00
|
|
|
bool collide(const Box&, Box* = nullptr) const;
|
2020-08-09 16:32:32 -04:00
|
|
|
bool collide(const Box&, Box&) const;
|
2021-08-14 19:53:39 -04:00
|
|
|
virtual std::string class_name() const { return "Box"; }
|
|
|
|
std::string string() const;
|
2020-06-27 17:47:14 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-07-17 22:58:23 -04:00
|
|
|
std::ostream& operator<<(std::ostream&, const Box&);
|
2020-06-27 17:47:14 -04:00
|
|
|
|
|
|
|
#endif
|