aboutsummaryrefslogtreecommitdiff
path: root/src/sdl/color.c
blob: cb94095ceaad9d4d8875b293617613a35f73ea53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdbool.h>
#include "color.h"
#include "util.h"

static const SDL_Color
PALETTE[] = {
  { .r = 0x00, .g = 0x00, .b = 0x00, .a = 0xFF }, // COLOR_BG
  { .r = 0x00, .g = 0xFF, .b = 0x00, .a = 0xFF }, // COLOR_BG_WON
  { .r = 0x66, .g = 0x66, .b = 0x66, .a = 0xFF }, // COLOR_WALL
  { .r = 0x00, .g = 0xFF, .b = 0x00, .a = 0xFF }, // COLOR_GOAL
  { .r = 0xFF, .g = 0x00, .b = 0x00, .a = 0xFF }, // COLOR_HOME
  { .r = 0xFF, .g = 0xFF, .b = 0x00, .a = 0xFF }, // COLOR_HOME_GOAL
  { .r = 0x00, .g = 0x00, .b = 0xFF, .a = 0xFF }, // COLOR_BOX
  { .r = 0x00, .g = 0xFF, .b = 0xFF, .a = 0xFF }, // COLOR_BOX_GOAL
  { 0, 0, 0, 0 },                                 // COLOR_LAST
};

void
set_color(
  SDL_Renderer * const renderer,
  const color_t ofs
) {
  if (ofs >= COLOR_LAST) {
    die("set_color(): invalid color");
  }

  const SDL_Color c = PALETTE[ofs];
  if (SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, c.a)) {
    die("SDL_SetRenderDrawColor(): %s", SDL_GetError());
  }
}