]> git.localhorst.tv Git - l2e.git/blobdiff - src/sdl/utility.cpp
added some graphics primitive functions
[l2e.git] / src / sdl / utility.cpp
diff --git a/src/sdl/utility.cpp b/src/sdl/utility.cpp
new file mode 100644 (file)
index 0000000..101c3ee
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+  * utility.cpp
+ *
+ *  Created on: Oct 6, 2012
+ *      Author: holy
+ */
+
+#include "utility.h"
+
+#include <cmath>
+
+using geometry::Vector;
+
+namespace sdl {
+
+void HorizontalLine(SDL_Surface *dst, const Vector<int> &position, unsigned int length, Uint32 color) {
+       SDL_Rect destRect;
+       destRect.x = position.X();
+       destRect.y = position.Y();
+       destRect.w = length;
+       destRect.h = 1;
+       SDL_FillRect(dst, &destRect, color);
+}
+
+void VerticalLine(SDL_Surface *dst, const geometry::Vector<int> &position, unsigned int length, Uint32 color) {
+       SDL_Rect destRect;
+       destRect.x = position.X();
+       destRect.y = position.Y();
+       destRect.w = 1;
+       destRect.h = length;
+       SDL_FillRect(dst, &destRect, color);
+}
+
+
+void OutlineRect(SDL_Surface *dst, const Vector<int> &from, const Vector<int> &to, Uint32 color) {
+       SDL_Rect destRect;
+       destRect.x = std::min(from.X(), to.X());
+       destRect.y = std::min(from.Y(), to.Y());
+       destRect.w = std::abs(from.X() - to.X());
+       destRect.h = std::abs(from.Y() - to.Y());
+       OutlineRect(dst, &destRect, color);
+}
+
+void OutlineRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color) {
+       SDL_Rect destRect;
+       destRect.x = dstrect->x;
+       destRect.y = dstrect->y;
+       destRect.w = dstrect->w;
+       destRect.h = 1;
+       SDL_FillRect(dst, &destRect, color);
+       destRect.y += dstrect->h - 1;
+       SDL_FillRect(dst, &destRect, color);
+       destRect.y = dstrect->y;
+       destRect.w = 1;
+       destRect.h = dstrect->h;
+       SDL_FillRect(dst, &destRect, color);
+       destRect.x += dstrect->w - 1;
+       SDL_FillRect(dst, &destRect, color);
+}
+
+}