From 1d47f59ae54da8dbed0bb8d5b0c22e85f1510807 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Fri, 11 Dec 2015 19:26:08 -0500 Subject: [PATCH] lib/gamnit: fix offsets in textures to be lazy MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/gamnit/textures.nit | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/gamnit/textures.nit b/lib/gamnit/textures.nit index 04efeb1..ee66213 100644 --- a/lib/gamnit/textures.nit +++ b/lib/gamnit/textures.nit @@ -62,29 +62,15 @@ abstract class Texture # Prepare a subtexture from this texture fun subtexture(left, top, width, height: Numeric): GamnitSubtexture do - # We want only floats - left = left.to_f - top = top.to_f - width = width.to_f - height = height.to_f - # Setup the subtexture - var subtex = new GamnitSubtexture(root) - subtex.width = width - subtex.height = height - - subtex.offset_left = offset_left + left / root.width - subtex.offset_top = offset_top + top / root.height - subtex.offset_right = offset_left + width / root.width - subtex.offset_bottom = offset_top + height / root.height - + var subtex = new GamnitSubtexture(root, self, left.to_f, top.to_f, width.to_f, height.to_f) return subtex end - private fun offset_left: Float do return 0.0 - private fun offset_top: Float do return 0.0 - private fun offset_right: Float do return 1.0 - private fun offset_bottom: Float do return 1.0 + fun offset_left: Float do return 0.0 + fun offset_top: Float do return 0.0 + fun offset_right: Float do return 1.0 + fun offset_bottom: Float do return 1.0 end # Texture with its own pixels @@ -167,12 +153,27 @@ class GamnitSubtexture redef var root + # Parent texture, from which this texture was created + var parent: Texture + + # Left border of this texture compared to `parent` + var left: Float + + # Top border of this texture compared to `parent` + var top: Float + + private fun set_wh(width, height: Float) + is autoinit do + self.width = width + self.height = height + end + redef fun load(force) do root.load(force) - redef var offset_left = 0.0 - redef var offset_top = 0.0 - redef var offset_right = 1.0 - redef var offset_bottom = 1.0 + redef var offset_left = parent.offset_left + left / root.width is lazy + redef var offset_top = parent.offset_top + top / root.height is lazy + redef var offset_right = offset_left + width / root.width is lazy + redef var offset_bottom = offset_top + height / root.height is lazy end redef class Sys -- 1.7.9.5