4 * Created on: Aug 7, 2012
10 using geometry::Vector;
14 // TODO: maybe create a cache for frames?
15 void Frame::Draw(SDL_Surface *dest, const Vector<int> &position, int width, int height) const {
18 rect.x = position.X();
19 rect.y = position.Y();
22 SDL_FillRect(dest, &rect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
27 srcRect.x = offset.X();
28 srcRect.y = offset.Y();
29 srcRect.w = BorderWidth();
30 srcRect.h = BorderHeight();
32 destRect.x = position.X();
33 destRect.y = position.Y();
34 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
37 srcRect.x += BorderWidth();
38 srcRect.w = RepeatWidth();
39 destRect.x += BorderWidth();
40 int fullRepeatWidth(width - (2 * BorderWidth()));
42 while (repeatCursor < fullRepeatWidth) {
43 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
44 destRect.x += RepeatWidth();
45 repeatCursor += RepeatWidth();
49 srcRect.x += RepeatWidth();
50 srcRect.w = BorderWidth();
51 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
54 destRect.y += BorderHeight();
55 int fullRepeatHeight(height - (2 * BorderHeight()));
57 while (hRepeatCursor < fullRepeatHeight) {
60 srcRect.x = offset.X();
61 srcRect.y = offset.Y() + BorderHeight();
62 srcRect.w = BorderWidth();
63 srcRect.h = RepeatHeight();
64 destRect.x = position.X();
65 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
69 srcRect.x += BorderWidth();
70 srcRect.w = RepeatWidth();
71 destRect.x += BorderWidth();
72 while (repeatCursor < fullRepeatWidth) {
73 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
74 destRect.x += RepeatWidth();
75 repeatCursor += RepeatWidth();
79 srcRect.x += RepeatWidth();
80 srcRect.w = BorderWidth();
81 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
83 destRect.y += RepeatHeight();
84 hRepeatCursor += RepeatHeight();
88 srcRect.x = offset.X();
89 srcRect.y = offset.Y() + BorderHeight() + RepeatHeight();
90 srcRect.w = BorderWidth();
91 srcRect.h = BorderHeight();
92 destRect.x = position.X();
93 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
96 srcRect.x += BorderWidth();
97 srcRect.w = RepeatWidth();
98 destRect.x += BorderWidth();
100 while (repeatCursor < fullRepeatWidth) {
101 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
102 destRect.x += RepeatWidth();
103 repeatCursor += RepeatWidth();
105 if (fullRepeatWidth < fullRepeatWidth) {
106 srcRect.w = fullRepeatWidth - fullRepeatWidth;
107 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
108 destRect.x += fullRepeatWidth - fullRepeatWidth;
111 // bottom-right corner
112 srcRect.x += RepeatWidth();
113 srcRect.w = BorderWidth();
114 SDL_BlitSurface(surface, &srcRect, dest, &destRect);