From b04d22497f7d88518bf5514c6c58fa8439978e0d Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 29 Mar 2021 21:31:19 +0200 Subject: [PATCH] Added a simple color class. --- 05_sdl_alapok/color.cpp | 18 ++++++++++++++++++ 05_sdl_alapok/color.h | 18 ++++++++++++++++++ 05_sdl_alapok/compile.sh | 3 ++- 05_sdl_alapok/renderer.cpp | 6 +++++- 05_sdl_alapok/renderer.h | 5 ++++- 5 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 05_sdl_alapok/color.cpp create mode 100644 05_sdl_alapok/color.h diff --git a/05_sdl_alapok/color.cpp b/05_sdl_alapok/color.cpp new file mode 100644 index 0000000..24f2cf6 --- /dev/null +++ b/05_sdl_alapok/color.cpp @@ -0,0 +1,18 @@ +#include "color.h" + +Color::Color() { + r = 0; + g = 0; + b = 0; + a = 255; +} + +Color::Color(uint8_t p_r, uint8_t p_g, uint8_t p_b, uint8_t p_a) { + r = p_r; + g = p_g; + b = p_b; + a = p_a; +} + +Color::~Color() { +} \ No newline at end of file diff --git a/05_sdl_alapok/color.h b/05_sdl_alapok/color.h new file mode 100644 index 0000000..98a5f08 --- /dev/null +++ b/05_sdl_alapok/color.h @@ -0,0 +1,18 @@ +#ifndef COLOR_H +#define COLOR_H + +#include + +class Color { +public: + Color(); + Color(uint8_t p_r, uint8_t p_g, uint8_t p_b, uint8_t p_a = 255); + virtual ~Color(); + + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; +}; + +#endif \ No newline at end of file diff --git a/05_sdl_alapok/compile.sh b/05_sdl_alapok/compile.sh index 067b5e9..3985b9b 100755 --- a/05_sdl_alapok/compile.sh +++ b/05_sdl_alapok/compile.sh @@ -16,8 +16,9 @@ fi g++ -Wall -g -c math.cpp -o obj/math.o g++ -Wall -g -c rect2.cpp -o obj/rect2.o +g++ -Wall -g -c color.cpp -o obj/color.o g++ -Wall -g $(sdl2-config --cflags) -c renderer.cpp -o obj/renderer.o g++ -Wall -g $(sdl2-config --cflags) -c main.cpp -o obj/main.o -g++ -o bin/program obj/math.o obj/rect2.o obj/renderer.o obj/main.o $(sdl2-config --libs) +g++ -o bin/program obj/math.o obj/rect2.o obj/color.o obj/renderer.o obj/main.o $(sdl2-config --libs) diff --git a/05_sdl_alapok/renderer.cpp b/05_sdl_alapok/renderer.cpp index 97a9d2d..898425f 100644 --- a/05_sdl_alapok/renderer.cpp +++ b/05_sdl_alapok/renderer.cpp @@ -6,10 +6,14 @@ void Renderer::present() { SDL_RenderPresent(_renderer); } -void Renderer::set_draw_color(Uint8 r, Uint8 g, Uint8 b, Uint8 a) { +void Renderer::set_draw_color(const Uint8 r, const Uint8 g, const Uint8 b, const Uint8 a) { SDL_SetRenderDrawColor(_renderer, r, g, b, a); } +void Renderer::set_draw_color(const Color &color) { + SDL_SetRenderDrawColor(_renderer, color.r, color.g, color.b, color.a); +} + void Renderer::clear() { SDL_RenderClear(_renderer); } diff --git a/05_sdl_alapok/renderer.h b/05_sdl_alapok/renderer.h index 66a1d67..dd81cd9 100644 --- a/05_sdl_alapok/renderer.h +++ b/05_sdl_alapok/renderer.h @@ -2,12 +2,15 @@ #define RENDERER_H #include "rect2.h" +#include "color.h" + #include class Renderer { public: void present(); - void set_draw_color(Uint8 r, Uint8 g, Uint8 b, Uint8 a); + void set_draw_color(const Uint8 r, const Uint8 g, const Uint8 b, const Uint8 a); + void set_draw_color(const Color &color); void clear(); void draw_rect(const SDL_Rect &rect);