bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape
1
by Gustav Hartvigsson
Initial code. |
1 |
#include "game_utils.h" |
2 |
||
7
by Gustav Hartvigsson
* Added licensing information to the files. |
3 |
/**
|
4 |
* This file, as the rest of the project is under MIT license.
|
|
5 |
* see http://opensource.org/licenses/MIT
|
|
6 |
*
|
|
8
by Gustav Hartvigsson
* added and changed little in the files Lincening information. |
7 |
* Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
8 |
*/
|
9 |
||
1
by Gustav Hartvigsson
Initial code. |
10 |
SDL_Color game_color_set_draw_color (SDL_Renderer * renderer, |
11 |
const SDL_Color color) { |
|
12 |
SDL_Color nc = color; |
|
13 |
SDL_Color oc = {0,0,0,0}; /* Save the old colour */ |
|
14 |
int ret = SDL_GetRenderDrawColor (renderer, &oc.r, &oc.g, &oc.b, &oc.a); |
|
15 |
if (ret < 0) { |
|
16 |
fprintf(stderr, "Couldn't get Colour: %s\n", SDL_GetError()); |
|
17 |
} |
|
18 |
ret = SDL_SetRenderDrawColor (renderer, nc.r, nc.g, nc.b, nc.a); |
|
19 |
if (ret < 0) { |
|
20 |
fprintf(stderr, "Couldn't set Colour: %s\n", SDL_GetError()); |
|
21 |
} |
|
22 |
return oc; |
|
23 |
}
|
|
24 |
||
25 |
SDL_Color game_color_create_color (int r, int g, int b, int a) { |
|
26 |
return (SDL_Color) {.r = r, .g = g, .b = b, .a = a}; |
|
27 |
}
|
|
28 |
||
29 |
SDL_Rect game_rect_create_rect (int x, int y, int h, int w) { |
|
30 |
return (SDL_Rect) {.x = x, .y = y, .h = h, .w = w}; |
|
31 |
}
|
|
32 |
||
33 |
SDL_Rect * game_rect_new (int x, int y, int h, int w) { |
|
34 |
SDL_Rect * self = malloc (sizeof(SDL_Rect)); |
|
35 |
self->x = x; |
|
36 |
self->y = y; |
|
37 |
self->w = w; |
|
38 |
self->h = h; |
|
39 |
return self; |
|
40 |
}
|
|
10
by Gustav Hartvigsson
created a generic error print function that should print nice looking |
41 |
|
42 |
void print_error (const char * str, ... ) { |
|
43 |
fprintf (stderr, |
|
44 |
"============================================================================\n" |
|
45 |
); |
|
46 |
|
|
47 |
va_list args; |
|
15
by Gustav Hartvigsson
* moved the files to ./src/ |
48 |
va_start (args, str); |
10
by Gustav Hartvigsson
created a generic error print function that should print nice looking |
49 |
vfprintf (stderr, str, args); |
50 |
va_end (args); |
|
51 |
|
|
52 |
fprintf (stderr, |
|
53 |
"\n" |
|
54 |
"============================================================================\n" |
|
55 |
); |
|
56 |
}
|