From 4e886547268583ef1d8a415d9f7f959ce76ffcbc Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 5 Aug 2012 17:45:49 +0200 Subject: [PATCH] added Point class --- Debug/makefile | 1 + Debug/sources.mk | 1 + Debug/src/geometry/subdir.mk | 24 ++++++++++++++++++++++++ Release/makefile | 1 + Release/sources.mk | 1 + Release/src/geometry/subdir.mk | 24 ++++++++++++++++++++++++ src/geometry/Point.cpp | 12 ++++++++++++ src/geometry/Point.h | 31 +++++++++++++++++++++++++++++++ src/graphics/Sprite.cpp | 8 +++++--- src/graphics/Sprite.h | 4 +++- 10 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 Debug/src/geometry/subdir.mk create mode 100644 Release/src/geometry/subdir.mk create mode 100644 src/geometry/Point.cpp create mode 100644 src/geometry/Point.h diff --git a/Debug/makefile b/Debug/makefile index 507437a..48bc75f 100644 --- a/Debug/makefile +++ b/Debug/makefile @@ -10,6 +10,7 @@ RM := rm -rf -include sources.mk -include src/sdl/subdir.mk -include src/graphics/subdir.mk +-include src/geometry/subdir.mk -include src/battle/subdir.mk -include src/app/subdir.mk -include src/subdir.mk diff --git a/Debug/sources.mk b/Debug/sources.mk index 0fdadd3..41a8dd3 100644 --- a/Debug/sources.mk +++ b/Debug/sources.mk @@ -26,6 +26,7 @@ SUBDIRS := \ src/sdl \ src \ src/graphics \ +src/geometry \ src/battle \ src/app \ diff --git a/Debug/src/geometry/subdir.mk b/Debug/src/geometry/subdir.mk new file mode 100644 index 0000000..3173086 --- /dev/null +++ b/Debug/src/geometry/subdir.mk @@ -0,0 +1,24 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables +CPP_SRCS += \ +../src/geometry/Point.cpp + +OBJS += \ +./src/geometry/Point.o + +CPP_DEPS += \ +./src/geometry/Point.d + + +# Each subdirectory must supply rules for building sources it contributes +src/geometry/%.o: ../src/geometry/%.cpp + @echo 'Building file: $<' + @echo 'Invoking: GCC C++ Compiler' + g++ -I/usr/include/SDL -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + + diff --git a/Release/makefile b/Release/makefile index 507437a..48bc75f 100644 --- a/Release/makefile +++ b/Release/makefile @@ -10,6 +10,7 @@ RM := rm -rf -include sources.mk -include src/sdl/subdir.mk -include src/graphics/subdir.mk +-include src/geometry/subdir.mk -include src/battle/subdir.mk -include src/app/subdir.mk -include src/subdir.mk diff --git a/Release/sources.mk b/Release/sources.mk index 0fdadd3..41a8dd3 100644 --- a/Release/sources.mk +++ b/Release/sources.mk @@ -26,6 +26,7 @@ SUBDIRS := \ src/sdl \ src \ src/graphics \ +src/geometry \ src/battle \ src/app \ diff --git a/Release/src/geometry/subdir.mk b/Release/src/geometry/subdir.mk new file mode 100644 index 0000000..3ddc804 --- /dev/null +++ b/Release/src/geometry/subdir.mk @@ -0,0 +1,24 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables +CPP_SRCS += \ +../src/geometry/Point.cpp + +OBJS += \ +./src/geometry/Point.o + +CPP_DEPS += \ +./src/geometry/Point.d + + +# Each subdirectory must supply rules for building sources it contributes +src/geometry/%.o: ../src/geometry/%.cpp + @echo 'Building file: $<' + @echo 'Invoking: GCC C++ Compiler' + g++ -I/usr/include/SDL -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + + diff --git a/src/geometry/Point.cpp b/src/geometry/Point.cpp new file mode 100644 index 0000000..a3bb3a2 --- /dev/null +++ b/src/geometry/Point.cpp @@ -0,0 +1,12 @@ +/* + * Point.cpp + * + * Created on: Aug 5, 2012 + * Author: holy + */ + +#include "Point.h" + +namespace geometry { + +} /* namespace geometry */ diff --git a/src/geometry/Point.h b/src/geometry/Point.h new file mode 100644 index 0000000..9d4bd85 --- /dev/null +++ b/src/geometry/Point.h @@ -0,0 +1,31 @@ +/* + * Point.h + * + * Created on: Aug 5, 2012 + * Author: holy + */ + +#ifndef GEOMETRY_POINT_H_ +#define GEOMETRY_POINT_H_ + +namespace geometry { + +template +class Point { + +public: + Point() : x(0), y(0) { } + Point(T x, T y) : x(x), y(y) { } + +public: + T X() const { return x; } + T Y() const { return y; } + +private: + T x, y; + +}; + +} + +#endif /* GEOMETRY_POINT_H_ */ diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp index 67deeef..afd6209 100644 --- a/src/graphics/Sprite.cpp +++ b/src/graphics/Sprite.cpp @@ -7,16 +7,18 @@ #include "Sprite.h" +using geometry::Point; + namespace graphics { -void Sprite::Draw(SDL_Surface *dest, int x, int y, int col, int row) const { +void Sprite::Draw(SDL_Surface *dest, Point position, int col, int row) const { SDL_Rect srcRect, destRect; srcRect.x = col * Width(); srcRect.y = row * Height(); srcRect.w = Width(); srcRect.h = Height(); - destRect.x = x; - destRect.y = y; + destRect.x = position.X(); + destRect.y = position.Y(); destRect.w = Width(); destRect.h = Height(); SDL_BlitSurface(surface, &srcRect, dest, &destRect); diff --git a/src/graphics/Sprite.h b/src/graphics/Sprite.h index 5710ee5..c81ed01 100644 --- a/src/graphics/Sprite.h +++ b/src/graphics/Sprite.h @@ -8,6 +8,8 @@ #ifndef GRAPHICS_SPRITE_H_ #define GRAPHICS_SPRITE_H_ +#include "../geometry/Point.h" + #include namespace graphics { @@ -21,7 +23,7 @@ public: public: int Width() const { return width; } int Height() const { return height; } - void Draw(SDL_Surface *dest, int x, int y, int col = 0, int row = 0) const; + void Draw(SDL_Surface *dest, geometry::Point position, int col = 0, int row = 0) const; private: SDL_Surface *surface; -- 2.39.2