diff options
author | kdx <kikoodx@paranoici.org> | 2023-07-12 17:12:24 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-07-12 17:12:24 +0200 |
commit | 046ae7f2b4e24b55969f521235f237e46d3832cc (patch) | |
tree | 86df28d9e81519c4dd4441e79aaf3126ad6ece7c | |
parent | 2a4c2abab474d0e7ed5f427f23baf9c08719ebb2 (diff) | |
download | fld-046ae7f2b4e24b55969f521235f237e46d3832cc.tar.gz |
drawSetColor
-rw-r--r-- | src/FLD.hpp | 14 | ||||
-rw-r--r-- | src/drawSetColor.cpp | 24 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/FLD.hpp b/src/FLD.hpp index c404996..c00866f 100644 --- a/src/FLD.hpp +++ b/src/FLD.hpp @@ -6,6 +6,8 @@ class FLD { public: + using Error = int; + using MainLoop = int (*)(FLD& fld, void *udata); struct Config { int width = 640; int height = 480; @@ -15,16 +17,20 @@ public: bool hide_cursor = true; std::string title = "FLD project"; }; + struct Color { + float r = -1.0f; + float g = -1.0f; + float b = -1.0f; + float a = -1.0f; + }; const Config config; READONLY(SDL_Window *, window, nullptr); READONLY(SDL_Renderer *, renderer, nullptr); READONLY(SDL_Texture *, target, nullptr); READONLY(unsigned long, tick, 0); + READONLY(Color, drawColor, Color({0, 0, 0, 1})); public: - using Error = int; - using MainLoop = int (*)(FLD& fld, void *udata); - FLD(const Config& config); FLD(const Config&& config); ~FLD(); @@ -34,6 +40,8 @@ public: [[nodiscard]] Error drawBegin() const; [[nodiscard]] Error drawEnd(); + [[nodiscard]] Error drawSetColor(float r, float g, float b, float a=-1); + [[nodiscard]] Error drawSetColor(const Color& c); private: bool shouldQuit = false; struct { diff --git a/src/drawSetColor.cpp b/src/drawSetColor.cpp new file mode 100644 index 0000000..1c63aed --- /dev/null +++ b/src/drawSetColor.cpp @@ -0,0 +1,24 @@ +#include "FLD.hpp" +#include <SDL2/SDL_render.h> + +FLD::Error +FLD::drawSetColor(float r, float g, float b, float a) +{ + if (r >= 0) _drawColor.r = r; + if (g >= 0) _drawColor.g = g; + if (b >= 0) _drawColor.b = b; + if (a >= 0) _drawColor.a = a; + if (SDL_SetRenderDrawColor(_renderer, + static_cast<int>(_drawColor.r * 0xff), + static_cast<int>(_drawColor.g * 0xff), + static_cast<int>(_drawColor.b * 0xff), + static_cast<int>(_drawColor.a * 0xff) < 0)) + sdlError(); + return 0; +} + +FLD::Error +FLD::drawSetColor(const Color& c) +{ + return drawSetColor(c.r, c.g, c.b, c.a); +} |