4 * Created on: Aug 7, 2012
10 #include "../loader/TypeDescription.h"
12 using geometry::Vector;
13 using loader::FieldDescription;
14 using loader::TypeDescription;
18 // TODO: maybe create a cache for frames?
19 void Frame::Draw(SDL_Surface *dest, const Vector<int> &position, int width, int height) const {
22 rect.x = position.X();
23 rect.y = position.Y();
26 SDL_FillRect(dest, &rect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
31 srcRect.x = offset.X();
32 srcRect.y = offset.Y();
33 srcRect.w = BorderWidth();
34 srcRect.h = BorderHeight();
36 destRect.x = position.X();
37 destRect.y = position.Y();
38 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
41 srcRect.x += BorderWidth();
42 srcRect.w = RepeatWidth();
43 destRect.x += BorderWidth();
44 int fullRepeatWidth(width - (2 * BorderWidth()));
46 while (repeatCursor < fullRepeatWidth) {
47 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
48 destRect.x += RepeatWidth();
49 repeatCursor += RepeatWidth();
53 srcRect.x += RepeatWidth();
54 srcRect.w = BorderWidth();
55 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
58 destRect.y += BorderHeight();
59 int fullRepeatHeight(height - (2 * BorderHeight()));
61 while (hRepeatCursor < fullRepeatHeight) {
64 srcRect.x = offset.X();
65 srcRect.y = offset.Y() + BorderHeight();
66 srcRect.w = BorderWidth();
67 srcRect.h = RepeatHeight();
68 destRect.x = position.X();
69 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
73 srcRect.x += BorderWidth();
74 srcRect.w = RepeatWidth();
75 destRect.x += BorderWidth();
76 while (repeatCursor < fullRepeatWidth) {
77 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
78 destRect.x += RepeatWidth();
79 repeatCursor += RepeatWidth();
83 srcRect.x += RepeatWidth();
84 srcRect.w = BorderWidth();
85 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
87 destRect.y += RepeatHeight();
88 hRepeatCursor += RepeatHeight();
92 srcRect.x = offset.X();
93 srcRect.y = offset.Y() + BorderHeight() + RepeatHeight();
94 srcRect.w = BorderWidth();
95 srcRect.h = BorderHeight();
96 destRect.x = position.X();
97 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
100 srcRect.x += BorderWidth();
101 srcRect.w = RepeatWidth();
102 destRect.x += BorderWidth();
104 while (repeatCursor < fullRepeatWidth) {
105 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
106 destRect.x += RepeatWidth();
107 repeatCursor += RepeatWidth();
109 if (fullRepeatWidth < fullRepeatWidth) {
110 srcRect.w = fullRepeatWidth - fullRepeatWidth;
111 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
112 destRect.x += fullRepeatWidth - fullRepeatWidth;
115 // bottom-right corner
116 srcRect.x += RepeatWidth();
117 srcRect.w = BorderWidth();
118 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
122 void Frame::CreateTypeDescription() {
125 int imageId(TypeDescription::GetTypeId("Image"));
126 int vectorId(TypeDescription::GetTypeId("Vector"));
128 TypeDescription &td(TypeDescription::CreateOrGet("Frame"));
129 td.SetConstructor(&Construct);
130 td.SetSize(sizeof(Frame));
132 td.AddField("image", FieldDescription(((char *)&f.surface) - ((char *)&f), imageId, true));
133 td.AddField("border", FieldDescription(((char *)&f.borderSize) - ((char *)&f), vectorId, false));
134 td.AddField("repeat", FieldDescription(((char *)&f.repeatSize) - ((char *)&f), vectorId, false));
135 td.AddField("offset", FieldDescription(((char *)&f.offset) - ((char *)&f), vectorId, false));
138 void Frame::Construct(void *data) {