private void DrawItem(MeshItem mesh, Frame frame) { var origin = mesh.FlipX ? new Vector2(frame.Rectangle.Width - frame.Origin.X, frame.Origin.Y) : frame.Origin.ToVector2(); var eff = mesh.FlipX ? SpriteEffects.FlipHorizontally : SpriteEffects.None; //兼容平铺 if (mesh.TileRegion != null) { var region = mesh.TileRegion.Value; for (int y = region.Top; y < region.Bottom; y++) { for (int x = region.Left; x < region.Right; x++) { Vector2 pos = mesh.Position + mesh.TileOffset * new Vector2(x, y); sprite.Draw(frame.Texture, pos, sourceRectangle: frame.AtlasRect, color: new Color(Color.White, frame.A0), origin: origin, effects: eff ); } } } else { sprite.Draw(frame.Texture, mesh.Position, sourceRectangle: frame.AtlasRect, color: new Color(Color.White, frame.A0), origin: origin, effects: eff ); } }
private void DrawItem(MeshItem mesh, Frame frame) { var origin = mesh.FlipX ? new Vector2(frame.Rectangle.Width - frame.Origin.X, frame.Origin.Y) : frame.Origin.ToVector2(); var eff = mesh.FlipX ? SpriteEffects.FlipHorizontally : SpriteEffects.None; var rect = frame.Rectangle; if (mesh.FlipX) { rect.X = -rect.Right; } //兼容平铺 if (mesh.TileRegion != null) { var region = mesh.TileRegion.Value; for (int y = region.Top; y < region.Bottom; y++) { for (int x = region.Left; x < region.Right; x++) { Vector2 pos = mesh.Position + mesh.TileOffset * new Vector2(x, y); if (this.CullingEnabled) { var tileRect = rect; tileRect.Offset(pos); if (!this.IntersectsVP(tileRect)) { continue; } } Prepare(frame.Blend ? ItemType.Sprite_BlendAdditive : ItemType.Sprite); sprite.Draw(frame.Texture, pos, sourceRectangle: frame.AtlasRect, color: new Color(Color.White, frame.A0), origin: origin, effects: eff ); } } } else { rect.Offset(mesh.Position); if (!this.CullingEnabled || this.IntersectsVP(rect)) { Prepare(frame.Blend ? ItemType.Sprite_BlendAdditive : ItemType.Sprite); sprite.Draw(frame.Texture, mesh.Position, sourceRectangle: frame.AtlasRect, color: new Color(Color.White, frame.A0), origin: origin, effects: eff ); } } }
/// <summary> /// Draws the specified texture. /// </summary> /// <param name="texture">The texture.</param> /// <param name="position">The position.</param> /// <param name="renderSize">Size of the render.</param> /// <param name="color">The color.</param> /// <param name="centerOrigin">if set to <c>true</c> [center origin].</param> public override void Draw(TextureBase texture, PointF position, Size renderSize, ColorW color, bool centerOrigin) { testRectangle.X = (int)position.X; testRectangle.Y = (int)position.Y; testRectangle.Width = (int)renderSize.Width; testRectangle.Height = (int)renderSize.Height; if (isClipped && !spriteBatch.GraphicsDevice.ScissorRectangle.Intersects(testRectangle)) { return; } vecColor.PackedValue = color.PackedValue; Texture2D native = texture.GetNativeTexture() as Texture2D; spriteBatch.Draw(native, testRectangle, vecColor); }
private void DrawFrame(RenderEnv env, Vector2 position, Vector2 size) { SpriteBatchEx sprite = env.Sprite; sprite.Draw(this.frame["nw"], position, Color.White); sprite.Draw(this.frame["ne"], position + new Vector2(size.X - 13, 0), Color.White); sprite.Draw(this.frame["sw"], position + new Vector2(0, size.Y - 13), Color.White); sprite.Draw(this.frame["se"], position + new Vector2(size.X - 13, size.Y - 13), Color.White); if (size.X > 26) { sprite.Draw(this.frame["n"], new Rectangle((int)position.X + 13, (int)position.Y, (int)size.X - 26, 13), Color.White); sprite.Draw(this.frame["s"], new Rectangle((int)position.X + 13, (int)(position.Y + size.Y) - 13, (int)size.X - 26, 13), Color.White); } if (size.Y > 26) { sprite.Draw(this.frame["e"], new Rectangle((int)(position.X + size.X) - 13, (int)position.Y + 13, 13, (int)size.Y - 26), Color.White); sprite.Draw(this.frame["w"], new Rectangle((int)position.X, (int)position.Y + 13, 13, (int)size.Y - 26), Color.White); } if (size.X > 26 && size.Y > 26) { sprite.Draw(this.frame["c"], new Rectangle((int)position.X + 13, (int)position.Y + 13, (int)size.X - 26, (int)size.Y - 26), Color.White); } sprite.Draw(this.frame["cover"], position, Color.White); }
public static void DrawNineForm(RenderEnv env, NineFormResource res, Vector2 position, Vector2 size) { SpriteBatchEx sprite = env.Sprite; var blocks = LayoutNinePatch(res, size.ToPoint()); foreach (var block in blocks) { if (block.Texture != null && block.Rectangle.Width > 0 && block.Rectangle.Height > 0) { Rectangle rect = new Rectangle(block.Rectangle.X + (int)position.X, block.Rectangle.Y + (int)position.Y, block.Rectangle.Width, block.Rectangle.Height); sprite.Draw(block.Texture, rect, Color.White); } } }
public static void DrawNineForm(RenderEnv env, NineFormResource res, Vector2 position, Vector2 size) { SpriteBatchEx sprite = env.Sprite; List <RenderBlock> blocks = new List <RenderBlock>(13); //计算框线 int[] x = new int[4] { 0, res.NW.Width, (int)size.X - res.NE.Width, (int)size.X }; int[] y = new int[4] { 0, res.NW.Height, (int)size.Y - res.SW.Height, (int)size.Y }; //绘制左上 blocks.Add(new RenderBlock(res.NW, new Rectangle(x[0], y[0], x[1] - x[0], y[1] - y[0]))); //绘制上 if (res.NW.Height == res.N.Height) { blocks.Add(new RenderBlock(res.N, new Rectangle(x[1], y[0], x[2] - x[1], y[1] - y[0]))); } else if (res.NW.Height > res.N.Height) { int h1 = res.N.Height; blocks.Add(new RenderBlock(res.N, new Rectangle(x[1], y[0], x[2] - x[1], h1))); blocks.Add(new RenderBlock(res.C, new Rectangle(x[1], h1, x[2] - x[1], y[1] - h1))); } //绘制右上 blocks.Add(new RenderBlock(res.NE, new Rectangle(x[2], y[0], x[3] - x[2], y[1] - y[0]))); //绘制左 if (res.NW.Width == res.W.Width) { blocks.Add(new RenderBlock(res.W, new Rectangle(x[0], y[1], x[1] - x[0], y[2] - y[1]))); } else if (res.NW.Width > res.W.Width) { int w1 = res.W.Width; blocks.Add(new RenderBlock(res.W, new Rectangle(x[0], y[1], w1, y[2] - y[1]))); blocks.Add(new RenderBlock(res.C, new Rectangle(w1, y[1], x[1] - w1, y[2] - y[1]))); } //绘制中 blocks.Add(new RenderBlock(res.C, new Rectangle(x[1], y[1], x[2] - x[1], y[2] - y[1]))); //绘制右 if (res.NE.Width == res.E.Width) { blocks.Add(new RenderBlock(res.E, new Rectangle(x[2], y[1], x[3] - x[2], y[2] - y[1]))); } else if (res.NE.Width > res.E.Width) { int w1 = res.E.Width; blocks.Add(new RenderBlock(res.E, new Rectangle(x[3] - w1, y[1], w1, y[2] - y[1]))); blocks.Add(new RenderBlock(res.C, new Rectangle(x[2], y[1], x[3] - x[2] - w1, y[2] - y[1]))); } //绘制左下 blocks.Add(new RenderBlock(res.SW, new Rectangle(x[0], y[2], x[1] - x[0], y[3] - y[2]))); //绘制下 if (res.SW.Height == res.S.Height) { blocks.Add(new RenderBlock(res.S, new Rectangle(x[1], y[2], x[2] - x[1], y[3] - y[2]))); } else if (res.SW.Height > res.S.Height) { int h1 = res.S.Height; blocks.Add(new RenderBlock(res.S, new Rectangle(x[1], y[3] - h1, x[2] - x[1], h1))); blocks.Add(new RenderBlock(res.C, new Rectangle(x[1], y[2], x[2] - x[1], y[3] - y[2] - h1))); } //绘制右下 blocks.Add(new RenderBlock(res.SE, new Rectangle(x[2], y[2], x[3] - x[2], y[3] - y[2]))); //绘制全部 foreach (var block in blocks) { if (block.Texture != null && block.Rectangle.Width > 0 && block.Rectangle.Height > 0) { Rectangle rect = new Rectangle(block.Rectangle.X + (int)position.X, block.Rectangle.Y + (int)position.Y, block.Rectangle.Width, block.Rectangle.Height); sprite.Draw(block.Texture, rect, Color.White); } } }