-
Notifications
You must be signed in to change notification settings - Fork 2
/
SDL_util.cpp
63 lines (48 loc) · 1.56 KB
/
SDL_util.cpp
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
62
63
#include "SDL_util.h"
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
SDL_Color SDL_RGB(int r, int g, int b)
{
SDL_Color color = {r,g,b,0};
return color;
}
SDL_Surface* LoadSurface(const char* filename)
{
SDL_Surface *temp, *surface;
temp = IMG_Load(filename);
if(temp == NULL)
return NULL;
surface = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
return surface;
}
int Blit(SDL_Surface* src, int fromX, int fromY, int width, int height,
SDL_Surface* dst, int toX, int toY)
{
SDL_Rect srcRect = {fromX, fromY, width, height};
SDL_Rect dstRect = { toX, toY, width, height};
return SDL_BlitSurface(src, &srcRect, dst, &dstRect);
}
void DrawText(const char* text, TTF_Font* font, SDL_Surface* dest, int x, int y, SDL_Color color)
{
if(strlen(text)<=0)
return;
SDL_Surface* output = TTF_RenderText_Solid(font, text, color);
Blit(output, 0, 0, output->w, output->h, dest, x, y);
SDL_FreeSurface(output);
}
void DrawText(const char* text, TTF_Font* font, SDL_Surface* dest, int x, int y, int r, int g, int b)
{
SDL_Color color = {r,g,b,0};
DrawText(text, font, dest, x, y, color);
}
int FillRectangle(SDL_Surface* dest, int x, int y, int w, int h, SDL_Color color)
{
return FillRectangle(dest, x, y, w, h, color.r, color.g, color.b);
}
int FillRectangle(SDL_Surface* dest, int x, int y, int w, int h, int r, int g, int b)
{
SDL_Rect rect = {x,y,w,h};
return SDL_FillRect(dest, &rect, SDL_MapRGBA(dest->format,r,g,b,0));
}