From 13fe2176ff029c4e1086b6071dfb6f4f2ee77fa4 Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Sat, 30 Nov 2024 15:44:33 +0100 Subject: [PATCH] Add jngl::Rect::drawBoundingBox --- src/jngl/Rect.cpp | 30 ++++++++++++++++++++++++++++++ src/jngl/Rect.hpp | 14 +++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/jngl/Rect.cpp diff --git a/src/jngl/Rect.cpp b/src/jngl/Rect.cpp new file mode 100644 index 00000000..6be90f60 --- /dev/null +++ b/src/jngl/Rect.cpp @@ -0,0 +1,30 @@ +// Copyright 2024 Jan Niklas Hasse +// For conditions of distribution and use, see copyright notice in LICENSE.txt +#include "Rect.hpp" + +#include "Rgba.hpp" +#include "shapes.hpp" + +namespace jngl { + +double Rect::getX() const { + return pos.x; +} + +double Rect::getY() const { + return pos.y; +} + +double Rect::getWidth() const { + return size.x; +} + +double Rect::getHeight() const { + return size.y; +} + +void Rect::drawBoundingBox(Mat3 modelview) const { + jngl::drawRect(modelview.translate(pos), size, 0xff0000aa_rgba); +} + +} // namespace jngl diff --git a/src/jngl/Rect.hpp b/src/jngl/Rect.hpp index fe2d2e2b..798bd6a0 100644 --- a/src/jngl/Rect.hpp +++ b/src/jngl/Rect.hpp @@ -4,19 +4,23 @@ /// @file #pragma once +#include "Mat3.hpp" #include "Vec2.hpp" namespace jngl { /// Simple struct for a rectangle, can be use with jngl::contains struct Rect { - double getX() const { return pos.x; } - double getY() const { return pos.y; } - double getWidth() const { return size.x; } - double getHeight() const { return size.y; } + double getX() const; + double getY() const; + double getWidth() const; + double getHeight() const; + + /// Draws a red box around the rectangle + void drawBoundingBox(Mat3 modelview) const; Vec2 pos; - Vec2 size; + Vec2 size; }; } // namespace jngl