/+junk/c_sdl_joypad

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil
 * vi: set shiftwidth=2 tabstop=2 expandtab:
 * :indentSize=2:tabSize=2:noTabs=true:
 */

#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> 2014
 */

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

void print_error (const char * str, ... ) {
  fprintf (stderr,
"============================================================================\n"
  );
  
  va_list args;
  va_start (args, str);
  vfprintf (stderr, str, args);
  va_end (args);
  
  fprintf (stderr,
"\n"
"============================================================================\n"
  );
}