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
32
33
34
35
36
37
38
39
40
|
#include "game_utils.h"
/**
* This file, as the rest of the project is under MIT license.
* see http://opensource.org/licenses/MIT
*
* Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2013
*/
SDL_Color game_color_set_draw_color (SDL_Renderer * renderer,
const SDL_Color color) {
SDL_Color nc = color;
SDL_Color oc = {0,0,0,0}; /* Save the old colour */
int ret = SDL_GetRenderDrawColor (renderer, &oc.r, &oc.g, &oc.b, &oc.a);
if (ret < 0) {
fprintf(stderr, "Couldn't get Colour: %s\n", SDL_GetError());
}
ret = SDL_SetRenderDrawColor (renderer, nc.r, nc.g, nc.b, nc.a);
if (ret < 0) {
fprintf(stderr, "Couldn't set Colour: %s\n", SDL_GetError());
}
return oc;
}
SDL_Color game_color_create_color (int r, int g, int b, int a) {
return (SDL_Color) {.r = r, .g = g, .b = b, .a = a};
}
SDL_Rect game_rect_create_rect (int x, int y, int h, int w) {
return (SDL_Rect) {.x = x, .y = y, .h = h, .w = w};
}
SDL_Rect * game_rect_new (int x, int y, int h, int w) {
SDL_Rect * self = malloc (sizeof(SDL_Rect));
self->x = x;
self->y = y;
self->w = w;
self->h = h;
return self;
}
|