Added a simple color class.

This commit is contained in:
Relintai 2021-03-29 21:31:19 +02:00
parent ac2a6000bc
commit b04d22497f
5 changed files with 47 additions and 3 deletions

18
05_sdl_alapok/color.cpp Normal file
View File

@ -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() {
}

18
05_sdl_alapok/color.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef COLOR_H
#define COLOR_H
#include <inttypes.h>
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

View File

@ -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)

View File

@ -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);
}

View File

@ -2,12 +2,15 @@
#define RENDERER_H
#include "rect2.h"
#include "color.h"
#include <SDL.h>
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);