diff options
author | kdx <kikoodx@paranoici.org> | 2023-07-15 08:15:29 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-07-15 08:15:29 +0200 |
commit | 859465d61e214fce4a84021c91635e297e187a0a (patch) | |
tree | 41fc6375be7adb5b360a68341bc75c6cd0e6786d | |
parent | f1a32aad576fb6b5bae80a391b28de445cfa24aa (diff) | |
download | fld-859465d61e214fce4a84021c91635e297e187a0a.tar.gz |
overload cringe
-rw-r--r-- | demo.cpp | 6 | ||||
-rw-r--r-- | src/FLD.hpp | 18 | ||||
-rw-r--r-- | src/drawLine.cpp | 10 | ||||
-rw-r--r-- | src/drawPoint.cpp | 10 | ||||
-rw-r--r-- | src/drawSetColor.cpp | 16 |
5 files changed, 20 insertions, 40 deletions
@@ -8,10 +8,10 @@ main_loop(FLD& fld, [[maybe_unused]] void *udata) if (fld.drawBegin()) return 1; - fld.drawSetColor(0, 0, 0); - + fld.drawSetColor(FLD::BLACK); fld.drawClear(); - fld.drawSetColor(1, 1, 1); + + fld.drawSetColor(FLD::WHITE); fld.drawRectangle({ 16, 32, 64, 32 }); if (fld.drawEnd()) diff --git a/src/FLD.hpp b/src/FLD.hpp index 584c418..391e18a 100644 --- a/src/FLD.hpp +++ b/src/FLD.hpp @@ -38,6 +38,14 @@ public: FILL = 1, CENTER = 2, }; + static constexpr Color BLACK {0.0f, 0.0f, 0.0f, -1.0f}; + static constexpr Color RED {1.0f, 0.0f, 0.0f, -1.0f}; + static constexpr Color GREEN {0.0f, 1.0f, 0.0f, -1.0f}; + static constexpr Color BLUE {0.0f, 0.0f, 1.0f, -1.0f}; + static constexpr Color YELLOW {1.0f, 1.0f, 0.0f, -1.0f}; + static constexpr Color PURPLE {1.0f, 0.0f, 1.0f, -1.0f}; + static constexpr Color CYAN {0.0f, 1.0f, 1.0f, -1.0f}; + static constexpr Color WHITE {1.0f, 1.0f, 1.0f, -1.0f}; const Config config; READONLY(SDL_Window *, window, nullptr); @@ -52,24 +60,14 @@ public: [[nodiscard]] Error init(); [[nodiscard]] Error init(MainLoop main_loop, void *udata=nullptr); - void run(MainLoop main_loop, void *udata = nullptr); [[nodiscard]] Error drawBegin() const; - [[nodiscard]] Error drawEnd(); - - Error drawSetColor(float r, float g, float b, float a=-1); Error drawSetColor(const Color& c); - Error drawClear() const; - - Error drawPoint(int x, int y) const; Error drawPoint(const Point& p) const; - - Error drawLine(int x0, int y0, int x1, int y1) const; Error drawLine(const Point& p0, const Point& p1) const; - Error drawRectangle(const Rectangle& rect, unsigned flags=NONE) const; private: bool shouldQuit = false; diff --git a/src/drawLine.cpp b/src/drawLine.cpp index 0c7e64d..eb03f90 100644 --- a/src/drawLine.cpp +++ b/src/drawLine.cpp @@ -1,15 +1,9 @@ #include "FLD.hpp" FLD::Error -FLD::drawLine(int x0, int y0, int x1, int y1) const +FLD::drawLine(const Point& p0, const Point& p1) const { - if (SDL_RenderDrawLine(_renderer, x0, y0, x1, y1) < 0) + if (SDL_RenderDrawLine(_renderer, p0.x, p0.y, p1.x, p1.y) < 0) return sdlError(); return 0; } - -FLD::Error -FLD::drawLine(const Point& p0, const Point& p1) const -{ - return drawLine(p0.x, p0.y, p1.x, p1.y); -} diff --git a/src/drawPoint.cpp b/src/drawPoint.cpp index fb24155..f2e3cee 100644 --- a/src/drawPoint.cpp +++ b/src/drawPoint.cpp @@ -1,15 +1,9 @@ #include "FLD.hpp" FLD::Error -FLD::drawPoint(int x, int y) const +FLD::drawPoint(const Point& p) const { - if (SDL_RenderDrawPoint(_renderer, x, y) < 0) + if (SDL_RenderDrawPoint(_renderer, p.x, p.y) < 0) return sdlError(); return 0; } - -FLD::Error -FLD::drawPoint(const Point& p) const -{ - return drawPoint(p.x, p.y); -} diff --git a/src/drawSetColor.cpp b/src/drawSetColor.cpp index eb14f13..2dd5bc4 100644 --- a/src/drawSetColor.cpp +++ b/src/drawSetColor.cpp @@ -2,12 +2,12 @@ #include <SDL2/SDL_render.h> FLD::Error -FLD::drawSetColor(float r, float g, float b, float a) +FLD::drawSetColor(const Color& c) { - 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 (c.r >= 0) _drawColor.r = c.r; + if (c.g >= 0) _drawColor.g = c.g; + if (c.b >= 0) _drawColor.b = c.b; + if (c.a >= 0) _drawColor.a = c.a; if (SDL_SetRenderDrawColor(_renderer, static_cast<Uint8>(_drawColor.r * 0xff), static_cast<Uint8>(_drawColor.g * 0xff), @@ -16,9 +16,3 @@ FLD::drawSetColor(float r, float g, float b, float a) sdlError(); return 0; } - -FLD::Error -FLD::drawSetColor(const Color& c) -{ - return drawSetColor(c.r, c.g, c.b, c.a); -} |