Esempio n. 1
0
        public ThingRenderer Bind(Thing t)
        {
            Type binding;

            if (Bindings.TryGetValue(t.GetType(), out binding) == false)
            {
                binding = typeof(ThingRenderer);
            }

            ThingRenderer ret = Activator.CreateInstance(binding) as ThingRenderer;

            ret.Thing = t;
            ret.OnBind();
            return(ret);
        }
Esempio n. 2
0
        private bool SizeAndLocate(ThingRenderer r)
        {
            float wPer = r.Thing.Bounds.Size.W / (float)Scene.Bounds.Size.W;
            float hPer = r.Thing.Bounds.Size.H / (float)Scene.Bounds.Size.H;

            float xPer = r.Thing.Bounds.Location.X / (float)Scene.Bounds.Size.W;
            float yPer = r.Thing.Bounds.Location.Y / (float)Scene.Bounds.Size.H;

            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.Thing.Bounds.W > 0)
            {
                w = 1;
            }

            if (h == 0 && r.Thing.Bounds.H > 0)
            {
                h = 1;
            }

            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);
            }
        }