+/*
+ * Texture.cpp
+ *
+ * Created on: Oct 21, 2012
+ * Author: holy
+ */
+
+#include "Texture.h"
+
+#include "../sdl/utility.h"
+
+using geometry::Vector;
+
+namespace graphics {
+
+Texture::Texture()
+: surface(0) {
+
+}
+
+Texture::~Texture() {
+
+}
+
+
+void Texture::Render(SDL_Surface *dest, const Vector<int> &from, const Vector<int> &to) const {
+ SDL_Rect destRect;
+ destRect.x = from.X();
+ destRect.y = from.Y();
+ if (!surface || size == Vector<int>()) {
+ destRect.w = to.X() - from.X();
+ destRect.h = to.Y() - from.Y();
+ SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+ return;
+ }
+
+ SDL_Rect srcRect;
+ srcRect.x = offset.X();
+ srcRect.y = offset.Y();
+
+ for (destRect.y = from.Y(); destRect.y < to.Y(); destRect.y += size.Y()) {
+ srcRect.h = size.Y();
+ destRect.h = size.Y();
+ if (destRect.y + destRect.h > to.Y()) {
+ srcRect.h = to.Y() - destRect.y;
+ destRect.h = to.Y() - destRect.y;
+ }
+ for (destRect.x = from.X(); destRect.x < to.X(); destRect.x += size.X()) {
+ srcRect.w = size.X();
+ destRect.w = size.X();
+ if (destRect.x + destRect.w > to.X()) {
+ srcRect.w = to.X() - destRect.x;
+ destRect.w = to.X() - destRect.x;
+ }
+ SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+ }
+ }
+}
+
+}