2021-11-09 23:30:27 -05:00
|
|
|
/* /\ +--------------------------------------------------------------+
|
|
|
|
____/ \____ /| - zlib/MIT/Unlicenced game framework licensed to freely use, |
|
2021-11-19 14:13:37 -05:00
|
|
|
\ / / | copy, and modify without restriction |
|
2021-11-09 23:30:27 -05:00
|
|
|
+--\ ^__^ /--+ | |
|
|
|
|
| ~/ \~ | | - originally created at [http://nugget.fun] |
|
|
|
|
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
|
|
|
|
| SPACE ~~~~~ | /
|
|
|
|
| ~~~~~~~ BOX |/
|
|
|
|
+-------------*/
|
|
|
|
|
2022-06-16 16:45:41 -04:00
|
|
|
#ifndef SB_BOX_H_
|
|
|
|
#define SB_BOX_H_
|
2020-06-27 17:47:14 -04:00
|
|
|
|
|
|
|
#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-09-06 22:11:56 -04:00
|
|
|
private:
|
|
|
|
|
2021-11-13 14:49:56 -05:00
|
|
|
bool invert_y_state = false;
|
2021-09-06 22:11:56 -04:00
|
|
|
|
2021-06-26 20:25:03 -04:00
|
|
|
public:
|
|
|
|
|
2021-09-06 22:11:56 -04:00
|
|
|
Box(const glm::vec2& = {0, 0}, const glm::vec2& = {0, 0}, bool = false);
|
2021-11-13 14:49:56 -05:00
|
|
|
Box(float, float, float, float, bool = false);
|
2021-09-06 22:11:56 -04:00
|
|
|
Box(const SDL_Rect&, bool = false);
|
2021-11-13 14:49:56 -05:00
|
|
|
void invert_y(bool);
|
|
|
|
bool inverted_y() const;
|
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);
|
2022-06-16 16:45:41 -04:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
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
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-10-22 15:06:05 -04:00
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
std::ostream& operator<<(std::ostream&, const Box&);
|
|
|
|
}
|
2020-06-27 17:47:14 -04:00
|
|
|
|
2021-11-09 23:30:27 -05:00
|
|
|
#include "extension.hpp"
|
|
|
|
#include "Segment.hpp"
|
|
|
|
|
2020-06-27 17:47:14 -04:00
|
|
|
#endif
|