summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-07-12 23:46:08 +0200
committerkdx <kikoodx@paranoici.org>2023-07-12 23:46:08 +0200
commitcdfa78a8bc48b4170bc161564b27fa23b352db21 (patch)
tree26e456f96082f753d742b6d42cf337d00c183ff0
parent0c9eaf7c92b25d8e7e17dbe34a5a218287a57417 (diff)
downloadfld-cdfa78a8bc48b4170bc161564b27fa23b352db21.tar.gz
drawRectangle
-rw-r--r--demo.cpp4
-rw-r--r--src/FLD.hpp10
-rw-r--r--src/drawRectangle.cpp16
3 files changed, 29 insertions, 1 deletions
diff --git a/demo.cpp b/demo.cpp
index 5ed0da6..0d6f15b 100644
--- a/demo.cpp
+++ b/demo.cpp
@@ -6,8 +6,10 @@ main_loop(FLD& fld, [[maybe_unused]] void *udata)
if (fld.drawBegin())
return 1;
- fld.drawSetColor(fld.tick%3 == 0, fld.tick%3 == 1, fld.tick%3 == 2);
+ fld.drawSetColor(0, 0, 0);
fld.drawClear();
+ fld.drawSetColor(1, 1, 1);
+ fld.drawRectangle({ 16, 32, 64, 32 });
if (fld.drawEnd())
return 1;
diff --git a/src/FLD.hpp b/src/FLD.hpp
index 3c4fb01..e08d9e6 100644
--- a/src/FLD.hpp
+++ b/src/FLD.hpp
@@ -23,6 +23,14 @@ public:
float b = -1.0f;
float a = -1.0f;
};
+ struct Rectangle {
+ int x;
+ int y;
+ int w;
+ int h;
+ bool center = false;
+ bool fill = false;
+ };
const Config config;
READONLY(SDL_Window *, window, nullptr);
@@ -43,6 +51,8 @@ public:
Error drawSetColor(float r, float g, float b, float a=-1);
Error drawSetColor(const Color& c);
Error drawClear() const;
+
+ Error drawRectangle(const Rectangle& rect) const;
private:
bool shouldQuit = false;
struct {
diff --git a/src/drawRectangle.cpp b/src/drawRectangle.cpp
new file mode 100644
index 0000000..fb21be9
--- /dev/null
+++ b/src/drawRectangle.cpp
@@ -0,0 +1,16 @@
+#include "FLD.hpp"
+
+FLD::Error
+FLD::drawRectangle(const Rectangle &rect) const
+{
+ const SDL_Rect srect {
+ .x = rect.x - rect.center * (rect.w / 2),
+ .y = rect.y - rect.center * (rect.h / 2),
+ .w = rect.w,
+ .h = rect.h
+ };
+ const auto fun = rect.fill ? SDL_RenderFillRect : SDL_RenderDrawRect;
+ if (fun(_renderer, &srect) < 0)
+ return sdlError();
+ return 0;
+}