trananh1992 / rokon

Automatically exported from code.google.com/p/rokon
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

[PATCH] Enhancement to provide abstraction for detecting visible scene size regardless of whether a window is used #153

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
As per DrawableObject#isOnScreen(), it seems that the visible screen size may 
be determined either by RokonActivity or by a window variable in the Scene 
object. Here is a patch to abstract away the difference.

It adds four new methods to Scene, getWidth(), getHeight(), getX(), and getY(), 
which can be used to determine the visible Scene area regardless of whether a 
window is used.

--- a/src/com/stickycoding/rokon/Scene.java
+++ b/src/com/stickycoding/rokon/Scene.java
@@ -1020,5 +1020,55 @@ public abstract class Scene {
        RokonActivity.toastHandler.sendEmptyMessage(0);
    }

+
+    /**
+     * Returns the effective visible width of the scene. If the scene
+     * uses a window, then it returns the window's height; otherwise,
+     * returns the width of the RokonActivity.
+     *
+     */
+    public float getWidth() {
+        if(window == null)
+            return RokonActivity.gameWidth;
+        else
+            return window.width;
+    }
+
+    /**
+     * Returns the effective visible height of the scene. If the scene
+     * uses a window, then it returns the window's height; otherwise,
+     * returns the height of the RokonActivity.
+     *
+     */
+    public float getHeight() {
+        if(window == null)
+            return RokonActivity.gameHeight;
+        else
+            return window.height;
+    }
+
+    /**
+     * Returns the x value of the scene's left edge.
+     * If the scene uses a window, returns getWindow().getX().
+     * Otherwise, returns 0.
+     */
+    public float getX() {
+        if(window == null)
+            return 0;
+        else
+            return window.getX();
+    }
+
+    /**
+     * Returns the x value of the scene's top edge.
+     * If the scene uses a window, returns getWindow().getY().
+     * Otherwise, returns 0.
+     */
+    public float getY() {
+        if(window == null)
+            return 0;
+        else
+            return window.getY();
+    }

 }

Original issue reported on code.google.com by pjleg...@gmail.com on 30 Aug 2010 at 8:33