public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info) { Update(info.EllapsedTime, info.ButtonState); Color color = ColorFromState * info.Opacity * Opacity; Texture2D image = _image; if (image != null) { float scale = _scale.Value(true); if (scale == 0) { scale = Math.Min(info.Target.Width / (float)image.Width, info.Target.Height / (float)image.Height); scale = Math.Min(1, scale); } Rectangle textureSrc = new Rectangle(0, 0, image.Width, image.Height); int width = (int)(scale * image.Width); int height = (int)(scale * image.Height); Rectangle target = _margin.ComputeRect(info.Target); switch (_horizontalAlignment) { case HorizontalContentAlignment.Center: target.X = target.Center.X - width / 2; break; case HorizontalContentAlignment.Right: target.X = target.Right - width; break; } switch (_verticalAlignment) { case VerticalContentAlignment.Center: target.Y = target.Center.Y - height / 2; break; case VerticalContentAlignment.Bottom: target.Y = target.Bottom - height; break; } target.Width = width; target.Height = height; drawBatch.DrawImage(image, target, textureSrc, color); } }
public override void Draw(AdvancedDrawBatch batch, Point startPosition, Vector2 position, float scale) { int size = UnitToPixels(scale); int unitSize = UnitToPixels(1); Rectangle target = new Rectangle(0, 0, size, size); position = position.TrimToIntValues() * size; SamplerState oldSamplerState = batch.SamplerState; batch.SamplerState = SamplerState.PointClamp; TiledLayer layer = Document.Current.SelectedLayer.Layer as TiledLayer; if (layer != null) { int maxX = _tiles.GetLength(0); int maxY = _tiles.GetLength(1); int targetX = (int)(position.X / size); int targetY = (int)(position.Y / size); maxX = Math.Min(layer.Width - targetX, maxX); maxY = Math.Min(layer.Height - targetY, maxY); position.X -= startPosition.X; position.Y -= startPosition.Y; for (int idxX = 0; idxX < maxX; ++idxX) { target.X = (int)(idxX * size + position.X); for (int idxY = 0; idxY < maxY; ++idxY) { target.Y = (int)(idxY * size + position.Y); ushort tile = _tiles[idxX, idxY]; Point src = new Point(tile & 0xff, (tile >> 8) & 0xff); Rectangle source = new Rectangle(src.X * unitSize, src.Y * unitSize, unitSize - 1, unitSize - 1); batch.DrawImage(_tileset, target, source, Color.White * 0.5f); } } } batch.SamplerState = oldSamplerState; }
void DrawTiles(ref UiViewDrawParameters parameters, TiledLayer layer) { Rectangle bounds = ScreenBounds; AdvancedDrawBatch batch = parameters.DrawBatch; SamplerState oldSamplerState = batch.SamplerState; batch.SamplerState = SamplerState.PointClamp; int width = layer.Width; int height = layer.Height; float zoom = (float)_zoom.Value / 100f; int unitSize = Tools.Tool.UnitToPixels(zoom); int tileSize = Tools.Tool.UnitToPixels(1); Rectangle target = new Rectangle(bounds.X - CurrentPosition.X, bounds.Y - CurrentPosition.Y, unitSize, unitSize); Rectangle source = new Rectangle(0, 0, tileSize - 1, tileSize - 1); Texture2D tileset = CurrentTemplate.Instance.Tileset(layer.Tileset).Item2; int startY = target.Y; int maxY = 0; ushort[,] tiles = layer.Content; for (int idxX = 0; idxX < width; ++idxX) { target.Y = startY; if (target.Right >= bounds.X && target.X <= bounds.Right) { for (int idxY = 0; idxY < height; ++idxY) { if (target.Bottom >= bounds.Y && target.Y <= bounds.Bottom) { ushort tile = tiles[idxX, idxY]; if (tile != 0xffff) { source.X = (tile & 0xff) * tileSize; source.Y = ((tile >> 8) & 0xff) * tileSize; batch.DrawImage(tileset, target, source, Color.White * 0.5f); } } target.Y += unitSize; maxY = Math.Max(target.Y, maxY); } } target.X += unitSize; } Color color = Color.White * 0.25f; batch.DrawLine(new Point(target.X, bounds.Top), new Point(target.X, maxY), color); batch.DrawLine(new Point(bounds.Left, maxY), new Point(target.X, maxY), color); batch.SamplerState = oldSamplerState; }
public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info) { Update(info.EllapsedTime, info.ButtonState); if (info.Icon == null) { return; } float scale = (float)UiUnit.Unit * _scale; float scaleX = scale; float scaleY = scale; Rectangle target = info.Target; Texture2D image = info.Icon; Rectangle bounds = _margin.ComputeRect(target); switch (_stretch) { case Stretch.Uniform: scaleX = scaleY = Math.Min((float)target.Width / (float)image.Width, (float)target.Height / (float)image.Height); break; case Stretch.UniformToFill: scaleX = scaleY = Math.Max((float)target.Width / (float)image.Width, (float)target.Height / (float)image.Height); break; case Stretch.Fill: scaleX = (float)target.Width / (float)image.Width; scaleY = (float)target.Height / (float)image.Height; break; } Color color = ColorFromState * info.Opacity * Opacity; Rectangle source = new Rectangle(0, 0, info.Icon.Width, info.Icon.Height); Vector2 size = new Vector2(source.Width * scaleX, source.Height * scaleY); target.Width = (int)size.X; target.Height = (int)size.Y; switch (_horzAlign) { case HorizontalContentAlignment.Center: case HorizontalContentAlignment.Auto: target.X = bounds.Center.X - target.Width / 2; break; case HorizontalContentAlignment.Left: target.X = bounds.X; break; case HorizontalContentAlignment.Right: target.X = bounds.Right - target.Width; break; } switch (_vertAlign) { case VerticalContentAlignment.Center: case VerticalContentAlignment.Auto: target.Y = bounds.Center.Y - target.Height / 2; break; case VerticalContentAlignment.Top: target.Y = bounds.Y; break; case VerticalContentAlignment.Bottom: target.Y = bounds.Bottom - target.Height; break; } drawBatch.DrawImage(info.Icon, target, source, color); }