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>
|
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&);
|
2020-07-13 00:53:12 -04:00
|
|
|
float get_x() const;
|
|
|
|
float get_y() const;
|
|
|
|
float get_w() const;
|
|
|
|
float get_h() const;
|
2020-06-27 17:47:14 -04:00
|
|
|
void set_x(float);
|
|
|
|
void set_y(float);
|
|
|
|
void set_w(float);
|
|
|
|
void set_h(float);
|
2020-07-13 00:53:12 -04:00
|
|
|
glm::vec2 get_size() const;
|
2020-07-31 12:10:21 -04:00
|
|
|
void set_size(const glm::vec2&, bool = false);
|
2020-08-06 18:54:50 -04:00
|
|
|
float get_area() const;
|
2020-07-13 00:53:12 -04:00
|
|
|
float get_top() const;
|
|
|
|
float get_right() const;
|
|
|
|
float get_bottom() const;
|
|
|
|
float get_left() const;
|
2020-08-06 18:54:50 -04:00
|
|
|
float get_center_x() const;
|
|
|
|
float get_center_y() const;
|
2020-09-12 20:29:26 -04:00
|
|
|
void set_top(float, bool=false);
|
|
|
|
void drag_top(float);
|
2020-08-06 18:54:50 -04:00
|
|
|
void set_right(float, bool=false);
|
|
|
|
void drag_right(float);
|
2020-09-12 20:29:26 -04:00
|
|
|
void set_bottom(float, bool=false);
|
|
|
|
void drag_bottom(float);
|
2020-08-06 18:54:50 -04:00
|
|
|
void set_left(float, bool=false);
|
|
|
|
void drag_left(float);
|
|
|
|
void set_center_x(float);
|
|
|
|
void set_center_y(float);
|
2020-07-13 00:53:12 -04:00
|
|
|
glm::vec2 get_nw() const;
|
|
|
|
glm::vec2 get_north() const;
|
2020-07-19 15:43:47 -04:00
|
|
|
glm::vec2 get_ne() const;
|
2020-07-13 00:53:12 -04:00
|
|
|
glm::vec2 get_east() const;
|
2020-08-06 18:54:50 -04:00
|
|
|
glm::vec2 get_se() const;
|
2020-07-13 00:53:12 -04:00
|
|
|
glm::vec2 get_south() const;
|
2020-08-06 18:54:50 -04:00
|
|
|
glm::vec2 get_sw() const;
|
2020-07-13 00:53:12 -04:00
|
|
|
glm::vec2 get_west() const;
|
|
|
|
glm::vec2 get_center() const;
|
2020-07-17 22:58:23 -04:00
|
|
|
void set_nw(const glm::vec2&);
|
|
|
|
void set_north(const glm::vec2&);
|
2020-07-19 15:43:47 -04:00
|
|
|
void set_ne(const glm::vec2&);
|
2020-07-17 22:58:23 -04:00
|
|
|
void set_east(const glm::vec2&);
|
2020-08-06 18:54:50 -04:00
|
|
|
void set_se(const glm::vec2&);
|
2020-07-17 22:58:23 -04:00
|
|
|
void set_south(const glm::vec2&);
|
2020-09-12 20:29:26 -04:00
|
|
|
void set_sw(const glm::vec2&);
|
2020-07-17 22:58:23 -04:00
|
|
|
void set_west(const glm::vec2&);
|
|
|
|
void set_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-06-24 17:40:30 -04:00
|
|
|
virtual std::string get_class_name() const { return "Box"; }
|
2020-06-27 17:47:14 -04:00
|
|
|
std::ostream& to_string (std::ostream&) const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-07-17 22:58:23 -04:00
|
|
|
std::ostream& operator<<(std::ostream&, const Box&);
|
2020-06-27 17:47:14 -04:00
|
|
|
|
|
|
|
#endif
|