private static List <DisplayCommand> BuildDisplayList(Layout.LayoutBox layoutRoot) { var list = new List <DisplayCommand>(); RenderLayoutBox(list, layoutRoot); return(list); }
private static void RenderLayoutBox(List <DisplayCommand> list, Layout.LayoutBox layoutBox) { RenderBackground(list, layoutBox); RenderBorders(list, layoutBox); foreach (var child in layoutBox.Children) { RenderLayoutBox(list, child); } }
private static Css.Color GetColor(Layout.LayoutBox layoutBox, string name) { if (layoutBox.BoxType is Layout.AnonymousBlock) { return(null); } var color = layoutBox.BoxType.StyledNode.GetValue(name) as Css.ColorValue; return(color?.Value); }
public static Canvas Paint(Layout.LayoutBox layoutRoot, Layout.Rect bounds) { var displayList = BuildDisplayList(layoutRoot); var canvas = new Canvas((int)bounds.Width, (int)bounds.Height); foreach (var item in displayList) { canvas.PaintItem(item); } return(canvas); }
private static void RenderBorders(List <DisplayCommand> list, Layout.LayoutBox layoutBox) { var color = GetColor(layoutBox, "border-color"); if (color == null) { return; } var borderBox = layoutBox.Dimensions.BorderBox(); var rect = new Layout.Rect() { X = borderBox.X , Y = borderBox.Y , Width = layoutBox.Dimensions.Border.Left , Height = borderBox.Height }; list.Add(new SolidColor(color, rect)); rect = new Layout.Rect() { X = borderBox.X + borderBox.Width - layoutBox.Dimensions.Border.Right , Y = borderBox.Y , Width = layoutBox.Dimensions.Border.Right , Height = borderBox.Height }; list.Add(new SolidColor(color, rect)); rect = new Layout.Rect() { X = borderBox.X , Y = borderBox.Y , Width = borderBox.Width , Height = layoutBox.Dimensions.Border.Top }; list.Add(new SolidColor(color, rect)); rect = new Layout.Rect() { X = borderBox.X , Y = borderBox.Y + borderBox.Height - layoutBox.Dimensions.Border.Bottom , Width = borderBox.Width , Height = layoutBox.Dimensions.Border.Bottom }; list.Add(new SolidColor(color, rect)); }
private static void RenderBackground(List <DisplayCommand> list, Layout.LayoutBox layoutBox) { var color = GetColor(layoutBox, "background"); list.Add(new SolidColor(color, layoutBox.Dimensions.BorderBox())); }