115 lines
3.2 KiB
C++
115 lines
3.2 KiB
C++
/* /\ +--------------------------------------------------------------+
|
|
____/ \____ /| - zlib/MIT/Unlicenced game framework licensed to freely use, |
|
|
\ / / | copy, and modify without restriction |
|
|
+--\ ^__^ /--+ | |
|
|
| ~/ \~ | | - originally created at [http://nugget.fun] |
|
|
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
|
|
| SPACE ~~~~~ | /
|
|
| ~~~~~~~ BOX |/
|
|
+-------------*/
|
|
|
|
#ifndef SB_BOX_H_
|
|
#define SB_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
|
|
{
|
|
|
|
private:
|
|
|
|
bool invert_y_state = false;
|
|
|
|
public:
|
|
|
|
Box(const glm::vec2& = {0, 0}, const glm::vec2& = {0, 0}, bool = false);
|
|
Box(float, float, float, float, bool = false);
|
|
Box(const SDL_Rect&, bool = false);
|
|
void invert_y(bool);
|
|
bool inverted_y() const;
|
|
float width() const;
|
|
void width(float);
|
|
float height() const;
|
|
void height(float);
|
|
glm::vec2 size() const;
|
|
void size(const glm::vec2&, bool = false);
|
|
|
|
/* If the flag is not set, this will return width divided by height. Otherwise, it will check which side is longer and return the longer side
|
|
* divided by the shorter side. */
|
|
float aspect(bool = false) 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;
|
|
|
|
};
|
|
|
|
namespace std
|
|
{
|
|
std::ostream& operator<<(std::ostream&, const Box&);
|
|
}
|
|
|
|
#include "extension.hpp"
|
|
#include "Segment.hpp"
|
|
|
|
#endif
|