Ejemplo n.º 1
0
        /// <summary>
        /// Get the render mesh to draw this widget.
        /// </summary>
        /// <returns></returns>
        public Mesh GetRenderMesh(int Invalidation)
        {
            if (Hidden)
            {
                return(Mesh.EmptyMesh());
            }

            if (Debugger.Switches.ABTestSwitch)
            {
                var r = new Mesh[1 + Children.Count];
                r[0] = Redraw();
                for (var i = 0; i < Children.Count; ++i)
                {
                    r[i + 1] = Children[i].GetRenderMesh(Invalidation);
                }
                return(Mesh.Merge(r));
            }

            if (CachedRenderMesh == null || Invalidation > RenderMeshInvalidation)
            {
                var r = new Mesh[1 + Children.Count];
                r[0] = Redraw();
                for (var i = 0; i < Children.Count; ++i)
                {
                    r[i + 1] = Children[i].GetRenderMesh(Invalidation);
                }
                CachedRenderMesh       = Mesh.Merge(r); // This is the heart of the in-place mesh generation... can't kill merge yet!
                RenderMeshInvalidation = Invalidation;
            }

            return(CachedRenderMesh);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create the rendering mesh for this widget.
        /// </summary>
        /// <returns></returns>
        protected virtual Mesh Redraw()
        {
            if (Hidden)
            {
                throw new InvalidOperationException();
            }

            if (Transparent || Root == null)
            {
                return(Mesh.EmptyMesh());
            }

            var result = new List <Mesh>();

            if (Background != null)
            {
                if (Rotation != 0.0)
                {
                    result.Add(Mesh.Quad()
                               .Scale(Rect.Width, Rect.Height)
                               .Transform(Rect.X, Rect.Y, Rect.Width, Rect.Height, Rotation)
                               .Colorize(BackgroundColor)
                               .Texture(Root.GetTileSheet(Background.Sheet).TileMatrix(Background.Tile)));
                }
                else
                {
                    result.Add(Mesh.Quad()
                               .Scale(Rect.Width, Rect.Height)
                               .Translate(Rect.X, Rect.Y)
                               .Colorize(BackgroundColor)
                               .Texture(Root.GetTileSheet(Background.Sheet).TileMatrix(Background.Tile)));
                }
            }

            if (!String.IsNullOrEmpty(Border))
            {
                //Create a 'scale 9' background
                result.Add(
                    Mesh.CreateScale9Background(Rect, Root.GetTileSheet(Border))
                    .Colorize(BackgroundColor));
            }

            // Add text label
            if (!String.IsNullOrEmpty(Text))
            {
                GetTextMesh(result);
            }

            return(Mesh.Merge(result.ToArray()));
        }
Ejemplo n.º 3
0
        public Mesh ForceRenderMeshUpdate()
        {
            if (Hidden)
            {
                return(Mesh.EmptyMesh());
            }

            var r = new Mesh[1 + Children.Count];

            r[0] = Redraw();
            for (var i = 0; i < Children.Count; ++i)
            {
                r[i + 1] = Children[i].ForceRenderMeshUpdate();
            }
            CachedRenderMesh = Mesh.Merge(r);
            return(CachedRenderMesh);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get the render mesh to draw this widget.
        /// </summary>
        /// <returns></returns>
        public Mesh GetRenderMesh()
        {
            if (Hidden)
            {
                return(Mesh.EmptyMesh());
            }

            if (CachedRenderMesh == null)
            {
                var r = new Mesh[1 + Children.Count];
                r[0] = Redraw();
                for (var i = 0; i < Children.Count; ++i)
                {
                    r[i + 1] = Children[i].GetRenderMesh();
                }
                CachedRenderMesh = Mesh.Merge(r);
            }

            return(CachedRenderMesh);
        }
        // Tiles a sprite across a rect. Expensive!
        public static Mesh TiledSprite(Rectangle Rect, ITileSheet Tiles, int Tile)
        {
            var meshes = new List <Mesh>();
            var pos    = new Point(Rect.X, Rect.Y);

            while (pos.X < Rect.Right)
            {
                while (pos.Y < Rect.Bottom)
                {
                    var quad = Mesh.Quad();
                    var size = new Point(Tiles.TileWidth, Tiles.TileHeight);

                    // Adjust texture coordinates if needed.
                    if (pos.Y + Tiles.TileHeight > Rect.Bottom)
                    {
                        size.Y = Rect.Bottom - pos.Y;
                        var ratio = (float)(size.Y) / (float)Tiles.TileHeight;
                        quad.MorphEx(v => { v.TextureCoordinate.Y *= ratio; return(v); });
                    }

                    if (pos.X + Tiles.TileWidth > Rect.Right)
                    {
                        size.X = Rect.Right - pos.X;
                        var ratio = (float)(size.X) / (float)Tiles.TileWidth;
                        quad.MorphEx(v => { v.TextureCoordinate.X *= ratio; return(v); });
                    }

                    quad.Scale(size.X, size.Y)
                    .Translate(pos.X, pos.Y)
                    .Texture(Tiles.TileMatrix(Tile));

                    meshes.Add(quad);

                    pos.Y += Tiles.TileHeight;
                }
                pos.Y  = Rect.Y;
                pos.X += Tiles.TileWidth;
            }

            return(Mesh.Merge(meshes.ToArray()));
        }