From 3282ab0cd838ab7e070021cd2a537d78e60d263a Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 28 Dec 2017 21:52:04 +0100 Subject: Imported sources files into the Git Signed-off-by: Olivier Gayot --- src/string.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/string.c (limited to 'src/string.c') diff --git a/src/string.c b/src/string.c new file mode 100644 index 0000000..ce93e88 --- /dev/null +++ b/src/string.c @@ -0,0 +1,37 @@ +/* +** string.c for in /home/gayot_o/prog/lib/sdl-digit +** +** Made by olivier gayot +** Login +** +** Started on Mon Apr 23 11:08:25 2012 olivier gayot +** Last update Mon Apr 23 11:08:25 2012 olivier gayot +*/ + +#include +#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); +} -- cgit v1.2.3