-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSurface.cpp
executable file
·66 lines (44 loc) · 1.38 KB
/
Surface.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
64
65
66
#include "Surface.h"
Surface::Surface(){}
SDL_Surface * Surface::onLoad(std::string File){
SDL_Surface * surfTemp = NULL;
SDL_Surface * surfReturn = NULL;
if((surfTemp = SDL_LoadBMP(File.c_str())) == NULL){
return NULL;
}
surfReturn = SDL_DisplayFormat(surfTemp);
SDL_FreeSurface(surfTemp);
return surfReturn;
}
bool Surface::onDraw(SDL_Surface* surfDest, SDL_Surface* surfSrc, int X, int Y) {
if(surfDest == NULL || surfSrc == NULL) {
return false;
}
SDL_Rect destRect;
destRect.x = X;
destRect.y = Y;
SDL_BlitSurface(surfSrc, NULL, surfDest, &destRect);
return true;
}
bool Surface::onDraw(SDL_Surface* surfDest, SDL_Surface* surfSrc, float X, float Y, int X2, int Y2, int W, int H) {
if(surfDest == NULL || surfSrc == NULL) {
return false;
}
SDL_Rect destRect;
destRect.x = X;
destRect.y = Y;
SDL_Rect srcRect;
srcRect.x = X2;
srcRect.y = Y2;
srcRect.w = W;
srcRect.h = H;
SDL_BlitSurface(surfSrc, &srcRect, surfDest, &destRect);
return true;
}
bool Surface::Transparent(SDL_Surface* surfDest, int R, int G, int B) {
if(surfDest == NULL) {
return false;
}
SDL_SetColorKey(surfDest, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(surfDest->format, R, G, B));
return true;
}