private bool SizeAndLocate(SpacialElementRenderer r) { float eW = r.Element.Width; float eH = r.Element.Height; float eL = r.Element.Left; float eT = r.Element.Top; if (eW < .5f && eW > 0) { eL -= .5f; eW = 1; } if (eH < .5f && eH > 0) { eT -= .5f; eH = 1; } float wPer = eW / SpaceTime.Width; float hPer = eH / SpaceTime.Height; float xPer = eL / SpaceTime.Width; float yPer = eT / SpaceTime.Height; int x = Geometry.Round(xPer * (float)Width); int y = Geometry.Round(yPer * (float)Height); int w = Geometry.Round(wPer * (float)Width); int h = Geometry.Round(hPer * (float)Height); r.ZIndex = r.Element.ZIndex; if (x != r.X || y != r.Y || w != r.Width || h != r.Height) { r.Width = w; r.Height = h; #if DEBUG if (float.IsInfinity(x) || float.IsNaN(x) || x >= -100000 == false && x < 100000 == false) { throw new Exception("Out of bounds: " + x + "," + y); } #endif r.X = x; r.Y = y; return(true); } else { return(false); } }
private bool SizeAndLocate(SpacialElementRenderer r) { float wPer = r.Element.Width / SpaceTime.Width; float hPer = r.Element.Height / SpaceTime.Height; float xPer = r.Element.Left / SpaceTime.Width; float yPer = r.Element.Top / SpaceTime.Height; int x = (int)Math.Round(xPer * (float)Width); int y = (int)Math.Round(yPer * (float)Height); int w = (int)Math.Round(wPer * (float)Width); int h = (int)Math.Round(hPer * (float)Height); if (w == 0 && r.Element.Width > 0) { w = 1; } if (h == 0 && r.Element.Height > 0) { h = 1; } r.ZIndex = r.Element.ZIndex; if (x != r.X || y != r.Y || w != r.Width || h != r.Height) { r.Width = w; r.Height = h; #if DEBUG if (float.IsInfinity(x) || float.IsNaN(x) || x >= -100000 == false && x < 100000 == false) { throw new Exception("Out of bounds: " + x + "," + y); } #endif r.X = x; r.Y = y; return(true); } else { return(false); } }
public SpacialElementRenderer Bind(SpacialElement t, SpaceTime spaceTime) { if (t.Renderer != null) { t.Renderer.Element = t; t.Renderer.OnBind(); return(t.Renderer); } Type binding; if (Bindings.TryGetValue(t.GetType(), out binding) == false) { binding = typeof(SpacialElementRenderer); } SpacialElementRenderer ret = Activator.CreateInstance(binding) as SpacialElementRenderer; ret.Element = t; ret.Spacetime = spaceTime; ret.OnBind(); return(ret); }