diff options
| author | Alejandro W. Sior <aho@sior.be> | 2023-02-02 12:21:19 +0100 |
|---|---|---|
| committer | Alejandro W. Sior <aho@sior.be> | 2023-02-02 12:21:19 +0100 |
| commit | a628daf4c738734d775634f20635e80669606b67 (patch) | |
| tree | 4ca76adf7825a123b8bb87e1979e87f3c2972966 | |
| parent | 1c5acb13bb8ad5a0e62c7abf313fc02c9890fd00 (diff) | |
| -rw-r--r-- | chisel/box.cpp | 12 | ||||
| -rw-r--r-- | chisel/box.hpp | 4 | ||||
| -rw-r--r-- | chisel/button.cpp | 14 | ||||
| -rw-r--r-- | chisel/button.hpp | 2 | ||||
| -rw-r--r-- | chisel/color.hpp | 9 | ||||
| -rw-r--r-- | chisel/sdl_window.cpp | 4 | ||||
| -rw-r--r-- | chisel/sdl_window.hpp | 2 |
7 files changed, 32 insertions, 15 deletions
diff --git a/chisel/box.cpp b/chisel/box.cpp index e8e3207..b0d11c5 100644 --- a/chisel/box.cpp +++ b/chisel/box.cpp @@ -23,10 +23,16 @@ namespace chisel { } void Box::draw() { - fill_rect(0, 0, width, height, width % 256, height % 256, (width + height) % 256); + Color color = { + width % 256, + height % 256, + (width + height) % 256 + }; + + fill_rect(0, 0, width, height, color); } - void Box::fill_rect(int x0, int y0, int w, int h, int r, int g, int b) { + void Box::fill_rect(int x0, int y0, int w, int h, Color color) { if (!parent) return; @@ -39,7 +45,7 @@ namespace chisel { if (y0 + h >= height) h = height - x0; - parent->fill_rect(x + x0, y + y0, w, h, r, g, b); + parent->fill_rect(x + x0, y + y0, w, h, color); } void Box::add_child(Box *child) { diff --git a/chisel/box.hpp b/chisel/box.hpp index f879584..6095133 100644 --- a/chisel/box.hpp +++ b/chisel/box.hpp @@ -1,7 +1,9 @@ #pragma once #include <socket/socket.hpp> + #include "attribute.hpp" +#include "color.hpp" #include <string> #include <vector> @@ -52,7 +54,7 @@ namespace chisel { void damage(); virtual void draw(); - virtual void fill_rect(int x0, int y0, int w, int h, int r, int g, int b); + virtual void fill_rect(int x0, int y0, int w, int h, Color color); void add_child(Box *child); diff --git a/chisel/button.cpp b/chisel/button.cpp index 0bf7425..c98d52a 100644 --- a/chisel/button.cpp +++ b/chisel/button.cpp @@ -7,9 +7,9 @@ namespace chisel { on_mouse_button_down.connect(this, &Button::press); on_mouse_button_up.connect(this, &Button::depress); pressed = false; - r = 255; - g = 255; - b = 255; + color.r = 255; + color.g = 255; + color.b = 255; } Button::~Button() {} @@ -31,12 +31,12 @@ namespace chisel { void Button::draw() { if (pressed) - r = g = b = 0; + color.r = color.g = color.b = 0; else if (hovered) - r = g = b = 255/2; + color.r = color.g = color.b = 255/2; else - r = g = b = 255; + color.r = color.g = color.b = 255; - fill_rect(0, 0, width, height, r, g, b); + fill_rect(0, 0, width, height, color); } } diff --git a/chisel/button.hpp b/chisel/button.hpp index 477d013..c710817 100644 --- a/chisel/button.hpp +++ b/chisel/button.hpp @@ -8,7 +8,7 @@ namespace chisel { Button(); virtual ~Button(); - int r, g, b; + Color color; bool pressed; void hover(int x, int y); diff --git a/chisel/color.hpp b/chisel/color.hpp new file mode 100644 index 0000000..4eceb6d --- /dev/null +++ b/chisel/color.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace chisel { + struct Color { + int r; + int g; + int b; + }; +} diff --git a/chisel/sdl_window.cpp b/chisel/sdl_window.cpp index 216becb..a0071f4 100644 --- a/chisel/sdl_window.cpp +++ b/chisel/sdl_window.cpp @@ -129,13 +129,13 @@ namespace chisel { SDL_RenderClear(sdl_renderer); } - void SDLWindow::fill_rect(int x0, int y0, int w, int h, int r, int g, int b) { + void SDLWindow::fill_rect(int x0, int y0, int w, int h, Color color) { SDL_Rect rect; rect.x = x0; rect.y = y0; rect.w = w; rect.h = h; - SDL_SetRenderDrawColor(sdl_renderer, r, g, b, 0xFF); + SDL_SetRenderDrawColor(sdl_renderer, color.r, color.g, color.b, 0xFF); SDL_RenderFillRect(sdl_renderer, &rect); } } diff --git a/chisel/sdl_window.hpp b/chisel/sdl_window.hpp index 36a83cf..c2f0f65 100644 --- a/chisel/sdl_window.hpp +++ b/chisel/sdl_window.hpp @@ -27,6 +27,6 @@ namespace chisel { // Implements Box void draw() override; - void fill_rect(int x0, int y0, int w, int h, int r, int g, int b) override; + void fill_rect(int x0, int y0, int w, int h, Color color) override; }; } |
