protected override VisualGroup CreateVisual(IRenderContext context, IStripe stripe) { IRectangle layout = stripe.Layout.ToRectD(); InsetsD stripeInsets; var group = new VisualGroup(); int index; if (stripe is IColumn) { var col = (IColumn)stripe; stripeInsets = new InsetsD(0, col.GetActualInsets().Top, 0, col.GetActualInsets().Bottom); index = col.ParentColumn.ChildColumns.ToList().FindIndex(curr => col == curr); } else { var row = (IRow)stripe; stripeInsets = new InsetsD(row.GetActualInsets().Left, 0, row.GetActualInsets().Right, 0); index = row.ParentRow.ChildRows.ToList().FindIndex((curr) => row == curr); } StripeDescriptor descriptor = index % 2 == 0 ? EvenStripeDescriptor : OddStripeDescriptor; group.Add(new RectangleVisual(layout.X, layout.Y, layout.Width, layout.Height) { Brush = descriptor.BackgroundBrush, Pen = new Pen(descriptor.BorderBrush, descriptor.BorderThickness) }); //Draw the insets if (stripeInsets.Left > 0) { group.Add(new RectangleVisual(layout.X, layout.Y, stripeInsets.Left, layout.Height) { Brush = descriptor.InsetBrush }); } if (stripeInsets.Top > 0) { group.Add(new RectangleVisual(layout.X, layout.Y, layout.Width, stripeInsets.Top) { Brush = descriptor.InsetBrush }); } if (stripeInsets.Right > 0) { group.Add(new RectangleVisual(layout.GetMaxX() - stripeInsets.Right, layout.Y, stripeInsets.Right, layout.Height) { Brush = descriptor.InsetBrush }); } if (stripeInsets.Bottom > 0) { group.Add(new RectangleVisual(layout.X, layout.GetMaxY() - stripeInsets.Bottom, layout.Width, stripeInsets.Bottom) { Brush = descriptor.InsetBrush }); } return(group); }
protected override VisualGroup UpdateVisual(IRenderContext context, VisualGroup group, IStripe stripe) { IRectangle layout = stripe.Layout.ToRectD(); InsetsD stripeInsets; int index; if (stripe is IColumn) { var col = (IColumn)stripe; stripeInsets = new InsetsD(0, col.GetActualInsets().Top, 0, col.GetActualInsets().Bottom); index = col.ParentColumn.ChildColumns.ToList().FindIndex((curr) => col == curr); } else { var row = (IRow)stripe; stripeInsets = new InsetsD(row.GetActualInsets().Left, 0, row.GetActualInsets().Right, 0); index = row.ParentRow.ChildRows.ToList().FindIndex((curr) => row == curr); } StripeDescriptor descriptor = index % 2 == 0 ? EvenStripeDescriptor : OddStripeDescriptor; var rect = (RectangleVisual)group.Children[0]; rect.Rectangle = layout; rect.Brush = descriptor.BackgroundBrush; if (rect.Pen.Brush != descriptor.BorderBrush) { rect.Pen = new Pen(descriptor.BorderBrush, descriptor.BorderThickness); } int count = 1; //Draw the insets if (stripeInsets.Left > 0) { if (count >= group.Children.Count) { group.Add(new RectangleVisual(layout.X, layout.Y, stripeInsets.Left, layout.Height) { Brush = descriptor.InsetBrush }); } else { rect = (RectangleVisual)group.Children[count]; rect.Rectangle = new RectD(layout.X, layout.Y, stripeInsets.Left, layout.Height); } count++; } if (stripeInsets.Top > 0) { if (count >= group.Children.Count) { group.Add(new RectangleVisual(layout.X, layout.Y, layout.Width, stripeInsets.Top) { Brush = descriptor.InsetBrush }); } else { rect = (RectangleVisual)group.Children[count]; rect.Rectangle = new RectD(layout.X, layout.Y, layout.Width, stripeInsets.Top); } count++; } if (stripeInsets.Right > 0) { if (count >= group.Children.Count) { group.Add(new RectangleVisual(layout.GetMaxX() - stripeInsets.Right, layout.Y, stripeInsets.Right, layout.Height) { Brush = descriptor.InsetBrush }); } else { rect = (RectangleVisual)group.Children[count]; rect.Rectangle = new RectD(layout.GetMaxX() - stripeInsets.Right, layout.Y, stripeInsets.Right, layout.Height); } count++; } if (stripeInsets.Bottom > 0) { if (count >= group.Children.Count) { group.Add(new RectangleVisual(layout.X, layout.GetMaxY() - stripeInsets.Bottom, layout.Width, stripeInsets.Bottom) { Brush = descriptor.InsetBrush }); } else { rect = (RectangleVisual)group.Children[count]; rect.Rectangle = new RectD(layout.X, layout.GetMaxY() - stripeInsets.Bottom, layout.Width, stripeInsets.Bottom); } count++; } while (group.Children.Count > count) { group.Children.RemoveAt(group.Children.Count - 1); } return(group); }
public void Paint(IRenderContext context, Graphics graphics) { var node = Stripe; var stripe = node.Lookup <IStripe>(); IRectangle layout = node.Layout.ToRectD(); if (stripe != null) { InsetsD stripeInsets; if (stripe is IColumn) { var col = (IColumn)stripe; stripeInsets = new InsetsD(0, col.GetActualInsets().Top, 0, col.GetActualInsets().Bottom); } else { var row = (IRow)stripe; stripeInsets = new InsetsD(row.GetActualInsets().Left, 0, row.GetActualInsets().Right, 0); } StripeDescriptor descriptor; if (stripe.GetChildStripes().Any()) { //Parent stripe - use the parent descriptor descriptor = ParentDescriptor; } else { int index; if (stripe is IColumn) { var col = (IColumn)stripe; //Get all leaf columns var leafs = col.Table.RootColumn.GetLeaves().ToList(); //Determine the index index = leafs.FindIndex((curr) => col == curr); //Use the correct descriptor descriptor = index % 2 == 0 ? EvenLeafDescriptor : OddLeafDescriptor; } else { var row = (IRow)stripe; var leafs = row.Table.RootRow.GetLeaves().ToList(); index = leafs.FindIndex((curr) => row == curr); descriptor = index % 2 == 0 ? EvenLeafDescriptor : OddLeafDescriptor; } } graphics.FillRectangle(descriptor.BackgroundBrush, new RectangleF((float)layout.X, (float)node.Layout.Y, (float)layout.Width, (float)layout.Height)); //Draw the insets if (stripeInsets.Left > 0) { graphics.FillRectangle(descriptor.InsetBrush, new RectangleF((float)layout.X, (float)node.Layout.Y, (float)stripeInsets.Left, (float)layout.Height)); } if (stripeInsets.Top > 0) { graphics.FillRectangle(descriptor.InsetBrush, new RectangleF((float)layout.X, (float)layout.Y, (float)layout.Width, (float)stripeInsets.Top)); } if (stripeInsets.Right > 0) { graphics.FillRectangle(descriptor.InsetBrush, new RectangleF((float)(layout.GetMaxX() - stripeInsets.Right), (float)layout.Y, (float)stripeInsets.Right, (float)layout.Height)); } if (stripeInsets.Bottom > 0) { graphics.FillRectangle(descriptor.InsetBrush, new RectangleF((float)layout.X, (float)(layout.GetMaxY() - stripeInsets.Bottom), (float)layout.Width, (float)stripeInsets.Bottom)); } graphics.DrawRectangle(new Pen(descriptor.BorderBrush, descriptor.BorderThickness), new Rectangle((int)layout.X, (int)layout.Y, (int)layout.Width, (int)layout.Height)); } }