public override void Construct() { if (ItemSource == null) { ItemSource = new List <Widget>(); } if (Border == "tray-border") { // This is a hack. InteriorMargin = new Margin(0, 0, 0, 0); if (Corners.HasFlag(Scale9Corners.Top)) { InteriorMargin.Top = 12; } if (Corners.HasFlag(Scale9Corners.Bottom)) { InteriorMargin.Bottom = 12; } if (Corners.HasFlag(Scale9Corners.Left)) { InteriorMargin.Left = 16; } if (Corners.HasFlag(Scale9Corners.Right)) { InteriorMargin.Right = 16; } } Padding = new Margin(0, 0, 0, 0); ResetItemsFromSource(); }
/// <summary> /// Create a mesh for a scale9 background. This assumed the tilesheet is 3*3 and positions the /// corners without scalling, scales the edges on one axis only, and fills the middle with the /// center tile. /// </summary> /// <param name="Rect"></param> /// <param name="Tiles"></param> /// <param name="Corners"></param> /// <returns></returns> public MeshPart Scale9Part( Rectangle Rect, ITileSheet Tiles, Scale9Corners Corners = Scale9Corners.All) { var rects = new Rectangle[9]; var margin = new Margin(0, 0, 0, 0); if (Corners.HasFlag(Scale9Corners.Left)) { margin.Left = Tiles.TileWidth; } if (Corners.HasFlag(Scale9Corners.Right)) { margin.Right = Tiles.TileWidth; } if (Corners.HasFlag(Scale9Corners.Top)) { margin.Top = Tiles.TileHeight; } if (Corners.HasFlag(Scale9Corners.Bottom)) { margin.Bottom = Tiles.TileHeight; } rects[0] = new Rectangle(Rect.Left, Rect.Top, margin.Left, margin.Top); rects[1] = new Rectangle(Rect.Left + margin.Left, Rect.Top, Rect.Width - margin.Left - margin.Right, margin.Top); rects[2] = new Rectangle(Rect.Right - margin.Right, Rect.Top, margin.Right, margin.Top); rects[3] = new Rectangle(Rect.Left, Rect.Top + margin.Top, margin.Left, Rect.Height - margin.Top - margin.Bottom); rects[4] = new Rectangle(Rect.Left + margin.Left, Rect.Top + margin.Top, Rect.Width - margin.Left - margin.Right, Rect.Height - margin.Top - margin.Bottom); rects[5] = new Rectangle(Rect.Right - margin.Right, Rect.Top + margin.Top, margin.Right, Rect.Height - margin.Top - margin.Bottom); rects[6] = new Rectangle(Rect.Left, Rect.Bottom - margin.Bottom, margin.Left, margin.Bottom); rects[7] = new Rectangle(Rect.Left + margin.Left, Rect.Bottom - margin.Bottom, Rect.Width - margin.Left - margin.Right, margin.Bottom); rects[8] = new Rectangle(Rect.Right - margin.Right, Rect.Bottom - margin.Bottom, margin.Right, margin.Bottom); var result = new MeshPart { VertexOffset = this.VertexCount, Mesh = this }; for (var i = 0; i < 9; ++i) { if (rects[i].Width != 0 && rects[i].Height != 0) { if (Tiles.RepeatWhenUsedAsBorder) { TiledSpritePart(rects[i], Tiles, i); } else { FittedSpritePart(rects[i], Tiles, i); } } } result.VertexCount = this.VertexCount - result.VertexOffset; return(result); }
public override void Construct() { InteriorMargin = new Margin(0, 0, 0, 0); if (Corners.HasFlag(Scale9Corners.Top)) { InteriorMargin.Top = 12; } if (Corners.HasFlag(Scale9Corners.Bottom)) { InteriorMargin.Bottom = 12; } if (Corners.HasFlag(Scale9Corners.Left)) { InteriorMargin.Left = 16; } if (Corners.HasFlag(Scale9Corners.Right)) { InteriorMargin.Right = 16; } Padding = new Margin(0, 0, 0, 0); }
public override void Construct() { if (ItemSource == null) { ItemSource = new List <Widget>(); } InteriorMargin = new Margin(0, 0, 0, 0); if (Corners.HasFlag(Scale9Corners.Top)) { InteriorMargin.Top = 12; } if (Corners.HasFlag(Scale9Corners.Bottom)) { InteriorMargin.Bottom = 12; } if (Corners.HasFlag(Scale9Corners.Left)) { InteriorMargin.Left = 16; } if (Corners.HasFlag(Scale9Corners.Right)) { InteriorMargin.Right = 16; } Padding = new Margin(0, 0, 0, 0); // Calculate perfect size. Margins + item sizes + padding. MaximumSize.X = InteriorMargin.Left + InteriorMargin.Right + (SizeToGrid.X * ItemSize.X) + ((SizeToGrid.X - 1) * ItemSpacing.X); MaximumSize.Y = InteriorMargin.Top + InteriorMargin.Bottom + (SizeToGrid.Y * ItemSize.Y) + ((SizeToGrid.Y - 1) * ItemSpacing.Y); MinimumSize = MaximumSize; Rect.Width = MinimumSize.X; Rect.Height = MinimumSize.Y; foreach (var item in ItemSource) { AddChild(item); } }
/// <summary> /// Create a mesh for a scale9 background. This assumed the tilesheet is 3*3 and positions the /// corners without scalling, scales the edges on one axis only, and fills the middle with the /// center tile. /// </summary> /// <param name="Rect"></param> /// <param name="Tiles"></param> /// <param name="Corners"></param> /// <returns></returns> public static Mesh CreateScale9Background( Rectangle Rect, ITileSheet Tiles, Scale9Corners Corners = Scale9Corners.All) { var rects = new Rectangle[9]; var margin = new Margin(0, 0, 0, 0); if (Corners.HasFlag(Scale9Corners.Left)) { margin.Left = Tiles.TileWidth; } if (Corners.HasFlag(Scale9Corners.Right)) { margin.Right = Tiles.TileWidth; } if (Corners.HasFlag(Scale9Corners.Top)) { margin.Top = Tiles.TileHeight; } if (Corners.HasFlag(Scale9Corners.Bottom)) { margin.Bottom = Tiles.TileHeight; } rects[0] = new Rectangle(Rect.Left, Rect.Top, margin.Left, margin.Top); rects[1] = new Rectangle(Rect.Left + margin.Left, Rect.Top, Rect.Width - margin.Left - margin.Right, margin.Top); rects[2] = new Rectangle(Rect.Right - margin.Right, Rect.Top, margin.Right, margin.Top); rects[3] = new Rectangle(Rect.Left, Rect.Top + margin.Top, margin.Left, Rect.Height - margin.Top - margin.Bottom); rects[4] = new Rectangle(Rect.Left + margin.Left, Rect.Top + margin.Top, Rect.Width - margin.Left - margin.Right, Rect.Height - margin.Top - margin.Bottom); rects[5] = new Rectangle(Rect.Right - margin.Right, Rect.Top + margin.Top, margin.Right, Rect.Height - margin.Top - margin.Bottom); rects[6] = new Rectangle(Rect.Left, Rect.Bottom - margin.Bottom, margin.Left, margin.Bottom); rects[7] = new Rectangle(Rect.Left + margin.Left, Rect.Bottom - margin.Bottom, Rect.Width - margin.Left - margin.Right, margin.Bottom); rects[8] = new Rectangle(Rect.Right - margin.Right, Rect.Bottom - margin.Bottom, margin.Right, margin.Bottom); var result = new List <Mesh>(); for (var i = 0; i < 9; ++i) { if (rects[i].Width != 0 && rects[i].Height != 0) { if (Tiles.RepeatWhenUsedAsBorder) { result.Add(TiledSprite(rects[i], Tiles, i)); } else { result.Add(FittedSprite(rects[i], Tiles, i)); } } } return(Merge(result.ToArray())); }
public override void Construct() { if (ItemSource == null) { ItemSource = new List <Widget>(); } if (Border == "tray-border") { // This is a hack. InteriorMargin = new Margin(0, 0, 0, 0); if (Corners.HasFlag(Scale9Corners.Top)) { InteriorMargin.Top = 12; } if (Corners.HasFlag(Scale9Corners.Bottom)) { InteriorMargin.Bottom = 12; } if (Corners.HasFlag(Scale9Corners.Left)) { InteriorMargin.Left = 16; } if (Corners.HasFlag(Scale9Corners.Right)) { InteriorMargin.Right = 16; } } Padding = new Margin(0, 0, 0, 0); //if (SizeToGrid.X > 1) //{ // SizeToGrid.X = Math.Min(SizeToGrid.X, WidthLimit/ItemSize.X); // int numRows = (int)Math.Ceiling((float)(ItemSource.Count())/(float)(SizeToGrid.X)); // SizeToGrid.Y = Math.Max(numRows, 1); //} // Calculate perfect size. Margins + item sizes + padding. MaximumSize.X = InteriorMargin.Left + InteriorMargin.Right + (SizeToGrid.X * ItemSize.X) + ((SizeToGrid.X - 1) * ItemSpacing.X); MaximumSize.Y = InteriorMargin.Top + InteriorMargin.Bottom + (SizeToGrid.Y * ItemSize.Y) + ((SizeToGrid.Y - 1) * ItemSpacing.Y); MinimumSize = MaximumSize; Rect.Width = MinimumSize.X; Rect.Height = MinimumSize.Y; AddChild(new FramedIcon { OnClick = (sender, args) => { IconOffset -= 1; LayoutIcons(); }, Icon = null, Text = "<<", Font = "font16", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, EnabledTextColor = Vector4.One, }); AddChild(new FramedIcon { OnClick = (sender, args) => { IconOffset += 1; LayoutIcons(); }, Icon = null, Text = ">>", Font = "font16", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, EnabledTextColor = Vector4.One, }); var items = ItemSource.ToList(); foreach (var item in items) { AddChild(item); } }