summaryrefslogtreecommitdiff
path: root/src/string.c
blob: ce93e88ff6a42a7cc0f1b30a7775da90fdf98594 (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
32
33
34
35
36
37
/*
** string.c for  in /home/gayot_o/prog/lib/sdl-digit
** 
** Made by olivier gayot
** Login   <gayot_o@epitech.net>
** 
** Started on  Mon Apr 23 11:08:25 2012 olivier gayot
** Last update Mon Apr 23 11:08:25 2012 olivier gayot
*/

#include	<string.h>
#include	"sdl_digit.h"

void		draw_string(SDL_Surface *surf, SDL_Rect *rect, const char *str, Uint32 color, int size) {
  SDL_Rect	rect_;

  rect_.x = (rect) ? rect->x : 0;
  rect_.y = (rect) ? rect->y : 0;
  while (*str) {
    if (draw_digit(surf, &rect_, size, color, *str))
      rect_.x += size * 150. / 100.;
    ++str;
  }
}

SDL_Surface	*new_string(const char *str, Uint32 color, int size)
{
  SDL_Surface	*surf;
  int		w;
  int		h;

  w = (size * 150. / 100.) * strlen(str);;
  h = (size * 2) + (size / 5);
  surf = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h, 32, 0, 0, 0, 0);
  draw_string(surf, NULL, str, color, size);
  return (surf);
}