protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);

            dc.DrawRectangle(Background, null, ContentBounds);

            dc.DrawRectangle(VisualBrush, null, ContentBounds);

            if (ViewportRect.IntersectsWith(new Rect(RenderSize)))
            {
                // draw shadow rectangles over the non-viewport regions
                Rect r1 = new Rect(new Point(0, 0), new Size(RenderSize.Width, Math.Max(0, ViewportRect.Top)));
                Rect r2 = new Rect(new Point(0, ViewportRect.Top),
                                   new Size(Math.Max(0, ViewportRect.Left), ViewportRect.Height));
                Rect r3 = new Rect(new Point(ViewportRect.Right, ViewportRect.Top),
                                   new Size(Math.Max(0, RenderSize.Width - ViewportRect.Right), ViewportRect.Height));
                Rect r4 = new Rect(new Point(0, ViewportRect.Bottom),
                                   new Size(RenderSize.Width, Math.Max(0, RenderSize.Height - ViewportRect.Bottom)));
                dc.DrawRectangle(ShadowBrush, null, r1);
                dc.DrawRectangle(ShadowBrush, null, r2);
                dc.DrawRectangle(ShadowBrush, null, r3);
                dc.DrawRectangle(ShadowBrush, null, r4);

                // draw the rectangle around the viewport region
                dc.DrawRectangle(ViewportBrush, ViewportPen, ViewportRect);
            }
            else
            {
                // if no part of the Rect is visible, just draw a
                // shadow over the entire content bounds
                dc.DrawRectangle(ShadowBrush, null, new Rect(RenderSize));
            }
        }
예제 #2
0
 public ViewportRect Clamp(ViewportRect bounds)
 {
     return(new ViewportRect()
     {
         startX = Math.Max(bounds.startX, startX),
         startY = Math.Max(bounds.startY, startY),
         endX = Math.Min(bounds.endX, endX),
         endY = Math.Min(bounds.endY, endY)
     });
 }
예제 #3
0
 public static bool IsInScreen(Rectangle rect)
 {
     return(ViewportRect.Intersects(rect));
 }