From: Daniel Karbach Date: Sat, 6 Oct 2012 21:01:03 +0000 (+0200) Subject: added some graphics primitive functions X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=3b5b2b79db22ef40c031d791a976310ea49e0d8e;p=l2e.git added some graphics primitive functions --- diff --git a/Debug/src/sdl/subdir.mk b/Debug/src/sdl/subdir.mk index 4a12c4d..43bc0e6 100644 --- a/Debug/src/sdl/subdir.mk +++ b/Debug/src/sdl/subdir.mk @@ -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/Release/src/sdl/subdir.mk b/Release/src/sdl/subdir.mk index c3a1775..eb0681e 100644 --- a/Release/src/sdl/subdir.mk +++ b/Release/src/sdl/subdir.mk @@ -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 index 0000000..101c3ee --- /dev/null +++ b/src/sdl/utility.cpp @@ -0,0 +1,61 @@ +/* + * utility.cpp + * + * Created on: Oct 6, 2012 + * Author: holy + */ + +#include "utility.h" + +#include + +using geometry::Vector; + +namespace sdl { + +void HorizontalLine(SDL_Surface *dst, const Vector &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 &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 &from, const Vector &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 index 0000000..d63c78f --- /dev/null +++ b/src/sdl/utility.h @@ -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 + +namespace sdl { + +void HorizontalLine(SDL_Surface *dst, const geometry::Vector &position, unsigned int length, Uint32 color); +void VerticalLine(SDL_Surface *dst, const geometry::Vector &position, unsigned int length, Uint32 color); + +void OutlineRect(SDL_Surface *dst, const geometry::Vector &from, const geometry::Vector &to, Uint32 color); +void OutlineRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color); + +} + +#endif /* SDL_UTILITY_H_ */