set invert Y to default for Box class, add support for any size GLM vector to JSON library
This commit is contained in:
parent
12e5a15d1c
commit
3db0a3bd32
10
src/Box.hpp
10
src/Box.hpp
|
@ -35,20 +35,20 @@ class Box : public SDL_FRect
|
|||
|
||||
private:
|
||||
|
||||
bool invert_y_state = false;
|
||||
bool invert_y_state = true;
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* Construct a Box object by giving a corner coordinate (top left if Y-axis is not inverted, bottom left otherwise) and
|
||||
* size (as width, height). The invert_y argument indicates that the Y-coordinate increases from the bottom of the screen
|
||||
* to the top rather than the default case where it increases from the top to the bottom.
|
||||
* to the top (like in OpenGL) rather than from the top to the bottom (like in Pygame).
|
||||
*
|
||||
* @param corner top left coordinate in the x, y axis
|
||||
* @param size size of the box in width and height
|
||||
* @param invert_y if true, y-coordinates increase as they move up on the screen, rather than decrease
|
||||
*/
|
||||
Box(const glm::vec2& corner = {0, 0}, const glm::vec2& size = {0, 0}, bool invert_y = false);
|
||||
Box(const glm::vec2& corner = {0.0f, 0.0f}, const glm::vec2& size = {0.0f, 0.0f}, bool invert_y = true);
|
||||
|
||||
/*!
|
||||
* Construct a Box object lfrom float arguments: x, y, width, height. If invert_y is set, the Y-axis increases from bottom to
|
||||
|
@ -62,7 +62,7 @@ public:
|
|||
* @param height size of the y-dimension
|
||||
* @param invert_y if true, y-coordinates increase as they move up on the screen, rather than decrease
|
||||
*/
|
||||
Box(float x, float y, float width, float height, bool invert_y = false);
|
||||
Box(float x, float y, float width, float height, bool invert_y = true);
|
||||
|
||||
/*!
|
||||
* Construct a ::Box object by passing an SDL_Rect struct, which is of the form {x, y, w, h} and limited to int arguments.
|
||||
|
@ -70,7 +70,7 @@ public:
|
|||
* @param rect see SDL's rect documentation http://doc.here/sdlwiki/SDL_FRect.html
|
||||
* @param invert_y if true, y-coordinates increase as they move up on the screen, rather than decrease
|
||||
*/
|
||||
Box(const SDL_Rect& rect, bool invert_y = false);
|
||||
Box(const SDL_Rect& rect, bool invert_y = true);
|
||||
|
||||
void invert_y(bool);
|
||||
bool inverted_y() const;
|
||||
|
|
|
@ -170,20 +170,34 @@ public:
|
|||
|
||||
};
|
||||
|
||||
/* Extend GLM so nlohmann::json can read and write glm::vec2 */
|
||||
/* Extend GLM so nlohmann::json can read and write glm::vec */
|
||||
namespace glm
|
||||
{
|
||||
template <typename T>
|
||||
void to_json(nlohmann::json& j, const vec<2, T, defaultp>& v)
|
||||
template <length_t dimensions, typename VectorType, qualifier qualifier>
|
||||
void to_json(nlohmann::json& j, const vec<dimensions, VectorType, qualifier>& v)
|
||||
{
|
||||
j = nlohmann::json{v.x, v.y};
|
||||
if constexpr (dimensions == 2) {
|
||||
j = nlohmann::json{v.x, v.y};
|
||||
}
|
||||
else if constexpr (dimensions == 3) {
|
||||
j = nlohmann::json{v.x, v.y, v.z};
|
||||
}
|
||||
else if constexpr (dimensions == 4) {
|
||||
j = nlohmann::json{v.x, v.y, v.z, v.w};
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void from_json(const nlohmann::json& j, vec<2, T, defaultp>& v)
|
||||
template <length_t dimensions, typename VectorType, qualifier qualifier>
|
||||
void from_json(const nlohmann::json& j, vec<dimensions, VectorType, qualifier>& v)
|
||||
{
|
||||
j.at(0).get_to(v.x);
|
||||
j.at(1).get_to(v.y);
|
||||
if constexpr (dimensions > 2) {
|
||||
j.at(2).get_to(v.z);
|
||||
}
|
||||
if constexpr (dimensions > 3) {
|
||||
j.at(3).get_to(v.w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue