]> git.localhorst.tv Git - l2e.git/commitdiff
added some graphics primitive functions
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 6 Oct 2012 21:01:03 +0000 (23:01 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 6 Oct 2012 21:01:03 +0000 (23:01 +0200)
Debug/src/sdl/subdir.mk
Release/src/sdl/subdir.mk
src/sdl/utility.cpp [new file with mode: 0644]
src/sdl/utility.h [new file with mode: 0644]

index 4a12c4d34911a6c7b2fa5c9d45beb9df5a813e0e..43bc0e66c3c41a333b378b084068331216ac4d1f 100644 (file)
@@ -6,17 +6,20 @@
 CPP_SRCS += \
 ../src/sdl/InitImage.cpp \
 ../src/sdl/InitSDL.cpp \
-../src/sdl/InitScreen.cpp 
+../src/sdl/InitScreen.cpp \
+../src/sdl/utility.cpp 
 
 OBJS += \
 ./src/sdl/InitImage.o \
 ./src/sdl/InitSDL.o \
-./src/sdl/InitScreen.o 
+./src/sdl/InitScreen.o \
+./src/sdl/utility.o 
 
 CPP_DEPS += \
 ./src/sdl/InitImage.d \
 ./src/sdl/InitSDL.d \
-./src/sdl/InitScreen.d 
+./src/sdl/InitScreen.d \
+./src/sdl/utility.d 
 
 
 # Each subdirectory must supply rules for building sources it contributes
index c3a1775023a1956bd116107b861fa899f525e408..eb0681e4e1f16393c6f67695ff74d651f97903c2 100644 (file)
@@ -6,17 +6,20 @@
 CPP_SRCS += \
 ../src/sdl/InitImage.cpp \
 ../src/sdl/InitSDL.cpp \
-../src/sdl/InitScreen.cpp 
+../src/sdl/InitScreen.cpp \
+../src/sdl/utility.cpp 
 
 OBJS += \
 ./src/sdl/InitImage.o \
 ./src/sdl/InitSDL.o \
-./src/sdl/InitScreen.o 
+./src/sdl/InitScreen.o \
+./src/sdl/utility.o 
 
 CPP_DEPS += \
 ./src/sdl/InitImage.d \
 ./src/sdl/InitSDL.d \
-./src/sdl/InitScreen.d 
+./src/sdl/InitScreen.d \
+./src/sdl/utility.d 
 
 
 # Each subdirectory must supply rules for building sources it contributes
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);
+}
+
+}
diff --git a/src/sdl/utility.h b/src/sdl/utility.h
new file mode 100644 (file)
index 0000000..d63c78f
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * utility.h
+ *
+ *  Created on: Oct 6, 2012
+ *      Author: holy
+ */
+
+#ifndef SDL_UTILITY_H_
+#define SDL_UTILITY_H_
+
+#include "../geometry/Vector.h"
+#include <SDL.h>
+
+namespace sdl {
+
+void HorizontalLine(SDL_Surface *dst, const geometry::Vector<int> &position, unsigned int length, Uint32 color);
+void VerticalLine(SDL_Surface *dst, const geometry::Vector<int> &position, unsigned int length, Uint32 color);
+
+void OutlineRect(SDL_Surface *dst, const geometry::Vector<int> &from, const geometry::Vector<int> &to, Uint32 color);
+void OutlineRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
+
+}
+
+#endif /* SDL_UTILITY_H_ */