[Scummvm-cvs-logs] SF.net SVN: scummvm:[43051] scummvm/branches/gsoc2009-draci/engines/draci

dkasak13 at users.sourceforge.net dkasak13 at users.sourceforge.net
Tue Aug 4 21:07:12 CEST 2009


Revision: 43051
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43051&view=rev
Author:   dkasak13
Date:     2009-08-04 19:07:12 +0000 (Tue, 04 Aug 2009)

Log Message:
-----------
Added Surface methods centerOnX() and centerOnY().

Modified Paths:
--------------
    scummvm/branches/gsoc2009-draci/engines/draci/surface.cpp
    scummvm/branches/gsoc2009-draci/engines/draci/surface.h

Modified: scummvm/branches/gsoc2009-draci/engines/draci/surface.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/surface.cpp	2009-08-04 18:24:39 UTC (rev 43050)
+++ scummvm/branches/gsoc2009-draci/engines/draci/surface.cpp	2009-08-04 19:07:12 UTC (rev 43051)
@@ -118,7 +118,7 @@
 }
 
 /**
- * @ 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 @@
 	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

Modified: scummvm/branches/gsoc2009-draci/engines/draci/surface.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/surface.h	2009-08-04 18:24:39 UTC (rev 43050)
+++ scummvm/branches/gsoc2009-draci/engines/draci/surface.h	2009-08-04 19:07:12 UTC (rev 43051)
@@ -45,6 +45,8 @@
 	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


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list