]> git.localhorst.tv Git - gworm.git/blobdiff - src/graphics/Texture.h
added texture support
[gworm.git] / src / graphics / Texture.h
diff --git a/src/graphics/Texture.h b/src/graphics/Texture.h
new file mode 100644 (file)
index 0000000..a4985bc
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef GWORM_TEXTURE_H_
+#define GWORM_TEXTURE_H_
+
+#include "Color.h"
+#include "Rect.h"
+#include "Vector.h"
+
+#include <algorithm>
+#include <SDL.h>
+
+
+namespace gworm {
+
+class Texture {
+
+public:
+       Texture();
+       ~Texture();
+
+       Texture(Texture &&);
+       Texture &operator =(Texture &&);
+
+       Texture(const Texture &) = delete;
+       Texture &operator =(const Texture &) = delete;
+
+       Texture(SDL_Renderer *, Uint32 format, int use, Vector<int> size);
+
+       void Swap(Texture &);
+
+public:
+       Vector<int> Size() const { return size; }
+
+       /// stretch this texture to completely fill given render target
+       void Fill(SDL_Renderer *);
+       /// copy entire texture as is to given coordinates
+       void Copy(SDL_Renderer *, Vector<int> to);
+       /// copy entire texture stretched to given rect
+       void Copy(SDL_Renderer *, Rect<int> to);
+
+       /// set all color values
+       /// given array must hold at least Size().x * Size().y values
+       void SetColors(const Color *);
+
+private:
+       SDL_Texture *tex;
+       Uint32 format;
+       Vector<int> size;
+
+};
+
+}
+
+
+namespace std {
+
+template<>
+inline void swap<gworm::Texture>(gworm::Texture &lhs, gworm::Texture &rhs) {
+       lhs.Swap(rhs);
+}
+
+}
+
+#endif