From 561d55ff4d63d207895f127a2db5afb47007299a Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Tue, 4 Aug 2009 19:07:12 +0000 Subject: Added Surface methods centerOnX() and centerOnY(). svn-id: r43051 --- engines/draci/surface.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'engines/draci/surface.cpp') diff --git a/engines/draci/surface.cpp b/engines/draci/surface.cpp index 636ec0c4ac..e5fb18dda0 100644 --- a/engines/draci/surface.cpp +++ b/engines/draci/surface.cpp @@ -118,7 +118,7 @@ void Surface::setTransparentColour(uint colour) { } /** - * @ brief Fills the surface with the specified colour + * @brief Fills the surface with the specified colour */ void Surface::fill(uint colour) { byte *ptr = (byte *)getBasePtr(0, 0); @@ -126,4 +126,46 @@ void Surface::fill(uint colour) { memset(ptr, colour, w * h); } +/** + * @brief Calculates horizontal center of an object + * + * @param x The x coordinate of the center + * @param width The width of the object to be centered (in pixels) + * + * @return The centered x coordinate + */ +uint Surface::centerOnX(uint x, uint width) { + + int newX = x - width / 2; + + if (newX < 0) + newX = 0; + + if (newX + width >= (uint)w - 1) + newX = (w - 1) - width; + + return newX; +} + +/** + * @brief Calculates vertical center of an object + * + * @param y The y coordinate of the center + * @param height The height of the object to be centered (in pixels) + * + * @return The centered y coordinate + */ +uint Surface::centerOnY(uint y, uint height) { + + int newY = y - height / 2; + + if (newY < 0) + newY = 0; + + if (newY + height >= (uint)h - 1) + newY = (h - 1) - height; + + return newY; +} + } // End of namespace Draci -- cgit v1.2.3