]> git.localhorst.tv Git - l2e.git/commitdiff
added texture class
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 21 Oct 2012 14:06:12 +0000 (16:06 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 21 Oct 2012 14:06:12 +0000 (16:06 +0200)
Debug/src/graphics/subdir.mk
Release/src/graphics/subdir.mk
src/graphics/Texture.cpp [new file with mode: 0644]
src/graphics/Texture.h [new file with mode: 0644]
src/graphics/fwd.h

index 23f43a82fecf4bc4a8e1a778685e2f12532953a6..2c416978245b6d4a2c96000691af0c87d4037022 100644 (file)
@@ -13,7 +13,8 @@ CPP_SRCS += \
 ../src/graphics/Gauge.cpp \
 ../src/graphics/Menu.cpp \
 ../src/graphics/SimpleAnimation.cpp \
-../src/graphics/Sprite.cpp 
+../src/graphics/Sprite.cpp \
+../src/graphics/Texture.cpp 
 
 OBJS += \
 ./src/graphics/Animation.o \
@@ -25,7 +26,8 @@ OBJS += \
 ./src/graphics/Gauge.o \
 ./src/graphics/Menu.o \
 ./src/graphics/SimpleAnimation.o \
-./src/graphics/Sprite.o 
+./src/graphics/Sprite.o \
+./src/graphics/Texture.o 
 
 CPP_DEPS += \
 ./src/graphics/Animation.d \
@@ -37,7 +39,8 @@ CPP_DEPS += \
 ./src/graphics/Gauge.d \
 ./src/graphics/Menu.d \
 ./src/graphics/SimpleAnimation.d \
-./src/graphics/Sprite.d 
+./src/graphics/Sprite.d \
+./src/graphics/Texture.d 
 
 
 # Each subdirectory must supply rules for building sources it contributes
index c020692572cd22254b2cc66ce9aead1a1774d47c..347deaebc8b2c84b054f012f3ebaa29de99d237a 100644 (file)
@@ -13,7 +13,8 @@ CPP_SRCS += \
 ../src/graphics/Gauge.cpp \
 ../src/graphics/Menu.cpp \
 ../src/graphics/SimpleAnimation.cpp \
-../src/graphics/Sprite.cpp 
+../src/graphics/Sprite.cpp \
+../src/graphics/Texture.cpp 
 
 OBJS += \
 ./src/graphics/Animation.o \
@@ -25,7 +26,8 @@ OBJS += \
 ./src/graphics/Gauge.o \
 ./src/graphics/Menu.o \
 ./src/graphics/SimpleAnimation.o \
-./src/graphics/Sprite.o 
+./src/graphics/Sprite.o \
+./src/graphics/Texture.o 
 
 CPP_DEPS += \
 ./src/graphics/Animation.d \
@@ -37,7 +39,8 @@ CPP_DEPS += \
 ./src/graphics/Gauge.d \
 ./src/graphics/Menu.d \
 ./src/graphics/SimpleAnimation.d \
-./src/graphics/Sprite.d 
+./src/graphics/Sprite.d \
+./src/graphics/Texture.d 
 
 
 # Each subdirectory must supply rules for building sources it contributes
diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp
new file mode 100644 (file)
index 0000000..6fc8f0e
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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);
+               }
+       }
+}
+
+}
diff --git a/src/graphics/Texture.h b/src/graphics/Texture.h
new file mode 100644 (file)
index 0000000..3b6357e
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Texture.h
+ *
+ *  Created on: Oct 21, 2012
+ *      Author: holy
+ */
+
+#ifndef GRAPHICS_TEXTURE_H_
+#define GRAPHICS_TEXTURE_H_
+
+#include "../geometry/Vector.h"
+
+#include <SDL.h>
+
+namespace graphics {
+
+class Texture {
+
+public:
+       Texture();
+       ~Texture();
+
+public:
+       void Render(SDL_Surface *dest, const geometry::Vector<int> &from, const geometry::Vector<int> &to) const;
+
+public:
+       void SetSurface(SDL_Surface *s) { surface = s; }
+       void SetOffset(const geometry::Vector<int> &o) { offset = o; }
+       void SetSize(const geometry::Vector<int> &s) { size = s; }
+
+private:
+       SDL_Surface *surface;
+       geometry::Vector<int> offset;
+       geometry::Vector<int> size;
+
+};
+
+}
+
+#endif /* GRAPHICS_TEXTURE_H_ */
index 31dbf27f8bace3d9fc9815a83aa1b245969e079a..961890b3471981b6237744f42bd6c231bdc0900e 100644 (file)
@@ -24,6 +24,7 @@ class Menu;
 struct MenuProperties;
 class SimpleAnimation;
 class Sprite;
+class Texture;
 
 }