diff options
author | Denis Kasak | 2009-08-04 19:07:12 +0000 |
---|---|---|
committer | Denis Kasak | 2009-08-04 19:07:12 +0000 |
commit | 561d55ff4d63d207895f127a2db5afb47007299a (patch) | |
tree | 0f7901ffcae9c89be9b5af9ba6f77b1064f6780f /engines/draci | |
parent | 41d7590835cbee3c0befe41031e08f4ded969dc9 (diff) | |
download | scummvm-rg350-561d55ff4d63d207895f127a2db5afb47007299a.tar.gz scummvm-rg350-561d55ff4d63d207895f127a2db5afb47007299a.tar.bz2 scummvm-rg350-561d55ff4d63d207895f127a2db5afb47007299a.zip |
Added Surface methods centerOnX() and centerOnY().
svn-id: r43051
Diffstat (limited to 'engines/draci')
-rw-r--r-- | engines/draci/surface.cpp | 44 | ||||
-rw-r--r-- | engines/draci/surface.h | 2 |
2 files changed, 45 insertions, 1 deletions
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 diff --git a/engines/draci/surface.h b/engines/draci/surface.h index db564ec2e5..1c7022ceff 100644 --- a/engines/draci/surface.h +++ b/engines/draci/surface.h @@ -45,6 +45,8 @@ public: uint getTransparentColour(); void setTransparentColour(uint colour); void fill(uint colour); + uint centerOnY(uint y, uint height); + uint centerOnX(uint x, uint width); private: /** The current transparent colour of the surface. See getTransparentColour() and |