Moved SDL_SetRenderDrawColor wrapper to utils file and added a second overload
Also renamed the function to a more colloquial version.
This commit is contained in:
parent
028b4ee73c
commit
5e35f6dbfe
3 changed files with 26 additions and 14 deletions
|
@ -85,11 +85,6 @@ namespace
|
|||
|
||||
/***** ***** ***** ***** ***** DRAWING PRIMITIVES ***** ***** ***** ***** *****/
|
||||
|
||||
static void set_renderer_color(SDL_Renderer* renderer, color_t color)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a line on a surface.
|
||||
*
|
||||
|
@ -124,7 +119,7 @@ static void draw_line(const int canvas_w,
|
|||
assert(static_cast<int>(y1) < canvas_h);
|
||||
assert(static_cast<int>(y2) < canvas_h);
|
||||
|
||||
set_renderer_color(renderer, color);
|
||||
set_draw_color(renderer, color);
|
||||
|
||||
if(x1 == x2 && y1 == y2) {
|
||||
// Handle single-pixel lines properly
|
||||
|
@ -168,7 +163,7 @@ static void draw_circle(const int canvas_w,
|
|||
if(octants & 0x3c) assert((y_center + radius) < canvas_h);
|
||||
if(octants & 0xc3) assert((y_center - radius) >= 0);
|
||||
|
||||
set_renderer_color(renderer, color);
|
||||
set_draw_color(renderer, color);
|
||||
|
||||
// Algorithm based on
|
||||
// http://de.wikipedia.org/wiki/Rasterung_von_Kreisen#Methode_von_Horn
|
||||
|
@ -235,7 +230,7 @@ static void fill_circle(const int canvas_w,
|
|||
if(octants & 0x3c) assert((y_center + radius) < canvas_h);
|
||||
if(octants & 0xc3) assert((y_center - radius) >= 0);
|
||||
|
||||
set_renderer_color(renderer, color);
|
||||
set_draw_color(renderer, color);
|
||||
|
||||
int d = -static_cast<int>(radius);
|
||||
int x = radius;
|
||||
|
@ -705,7 +700,7 @@ void rectangle_shape::draw(
|
|||
|
||||
// Fill the background, if applicable
|
||||
if(!fill_color.null() && w && h) {
|
||||
set_renderer_color(renderer, fill_color);
|
||||
set_draw_color(renderer, fill_color);
|
||||
|
||||
SDL_Rect area {
|
||||
x + border_thickness_,
|
||||
|
@ -726,7 +721,7 @@ void rectangle_shape::draw(
|
|||
h - (i * 2)
|
||||
};
|
||||
|
||||
set_renderer_color(renderer, border_color_(variables));
|
||||
set_draw_color(renderer, border_color_(variables));
|
||||
|
||||
SDL_RenderDrawRect(renderer, &dimensions);
|
||||
}
|
||||
|
@ -820,7 +815,7 @@ void round_rectangle_shape::draw(
|
|||
|
||||
// Fill the background, if applicable
|
||||
if(!fill_color.null() && w && h) {
|
||||
set_renderer_color(renderer, fill_color);
|
||||
set_draw_color(renderer, fill_color);
|
||||
static const int count = 3;
|
||||
SDL_Rect area[count] {
|
||||
{x + r, y + border_thickness_, w - r * 2, r - border_thickness_ + 1},
|
||||
|
@ -840,7 +835,7 @@ void round_rectangle_shape::draw(
|
|||
|
||||
// Draw the border
|
||||
for(int i = 0; i < border_thickness_; ++i) {
|
||||
set_renderer_color(renderer, border_color);
|
||||
set_draw_color(renderer, border_color);
|
||||
|
||||
SDL_RenderDrawLine(renderer, x + r, y + i, x + w - r, y + i);
|
||||
SDL_RenderDrawLine(renderer, x + r, y + h - i, x + w - r, y + h - i);
|
||||
|
|
|
@ -108,6 +108,22 @@ using render_viewport_setter = render_raii_rect_setter_base<
|
|||
&SDL_RenderSetViewport>;
|
||||
|
||||
|
||||
/**
|
||||
* Set renderer drawing color.
|
||||
*/
|
||||
inline void set_draw_color(SDL_Renderer* renderer, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set renderer drawing color.
|
||||
*/
|
||||
inline void set_draw_color(SDL_Renderer* renderer, color_t color)
|
||||
{
|
||||
set_draw_color(renderer, color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
/*
|
||||
* TEXTURE SETTERS =========================================================================
|
||||
* Need to decide if these need their own file.
|
||||
|
|
|
@ -15,8 +15,9 @@
|
|||
#include "sdl/window.hpp"
|
||||
|
||||
#include "ogl/utils.hpp"
|
||||
#include "sdl/surface.hpp"
|
||||
#include "sdl/exception.hpp"
|
||||
#include "sdl/render_utils.hpp"
|
||||
#include "sdl/surface.hpp"
|
||||
|
||||
namespace sdl
|
||||
{
|
||||
|
@ -122,7 +123,7 @@ void window::full_screen()
|
|||
|
||||
void window::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
||||
{
|
||||
SDL_SetRenderDrawColor(*this, r, g, b, a);
|
||||
set_draw_color(*this, r, g, b, a);
|
||||
if(SDL_RenderClear(*this) != 0) {
|
||||
throw exception("Failed to clear the SDL_Renderer object.",
|
||||
true);
|
||||
|
|
Loading…
Add table
Reference in a new issue