@@ -16,7 +16,6 @@ namespace ExampleLibrary
1616 using OxyPlot ;
1717 using OxyPlot . Annotations ;
1818 using System . Linq ;
19- using System . Collections . Generic ;
2019
2120 /// <summary>
2221 /// Provides rendering capability examples.
@@ -458,6 +457,59 @@ public static PlotModel DrawTextWithMetrics(string text, string font, double fon
458457 return model ;
459458 }
460459
460+ [ Example ( "Clipping" ) ]
461+ public static PlotModel Clipping ( )
462+ {
463+ var model = new PlotModel ( ) ;
464+ model . Annotations . Add ( new DelegateAnnotation ( rc =>
465+ {
466+ // reset a couple of times without any clipping being set to see that nothing explodes
467+ rc . ResetClip ( ) ;
468+ rc . ResetClip ( ) ;
469+ rc . ResetClip ( ) ;
470+
471+ var p1 = new ScreenPoint ( 150 , 150 ) ;
472+ var clip = 100d ;
473+ var radiusFactor = 1.1 ;
474+ var clipShrink = .15 * clip ;
475+
476+ var rect = new OxyRect ( p1 . X - clip , p1 . Y - clip , clip * 2 , clip * 2 ) ;
477+ rc . DrawRectangle ( rect , OxyColors . Undefined , OxyColors . Red , 1 , EdgeRenderingMode . Automatic ) ;
478+ rc . SetClip ( rect ) ;
479+ rc . DrawCircle ( p1 , clip * radiusFactor , OxyColors . Red , OxyColors . Undefined , 0 , EdgeRenderingMode . Automatic ) ;
480+
481+ clip -= clipShrink ;
482+ rect = new OxyRect ( p1 . X - clip , p1 . Y - clip , clip * 2 , clip * 2 ) ;
483+ rc . DrawRectangle ( rect , OxyColors . Undefined , OxyColors . Green , 1 , EdgeRenderingMode . Automatic ) ;
484+ rc . SetClip ( rect ) ;
485+ rc . DrawCircle ( p1 , clip * radiusFactor , OxyColors . Green , OxyColors . Undefined , 0 , EdgeRenderingMode . Automatic ) ;
486+
487+ clip -= clipShrink ;
488+ rect = new OxyRect ( p1 . X - clip , p1 . Y - clip , clip * 2 , clip * 2 ) ;
489+ rc . DrawRectangle ( rect , OxyColors . Undefined , OxyColors . Blue , 1 , EdgeRenderingMode . Automatic ) ;
490+ rc . SetClip ( rect ) ;
491+ rc . DrawCircle ( p1 , clip * radiusFactor , OxyColors . Blue , OxyColors . Undefined , 0 , EdgeRenderingMode . Automatic ) ;
492+ rc . ResetClip ( ) ;
493+
494+ rc . DrawText ( p1 , "Clipped Circles" , OxyColors . White , fontSize : 12 , horizontalAlignment : HorizontalAlignment . Center , verticalAlignment : VerticalAlignment . Middle ) ;
495+
496+ rc . DrawText ( new ScreenPoint ( p1 . X * 2 , 50 ) , "Not clipped" , OxyColors . Black , fontSize : 40 ) ;
497+
498+ rect = new OxyRect ( p1 . X * 2 + 10 , 100 , 80 , 60 ) ;
499+ rc . DrawRectangle ( rect , OxyColors . Undefined , OxyColors . Black , 1 , EdgeRenderingMode . Automatic ) ;
500+
501+ // set the same clipping a couple of times to see that nothing explodes
502+ rc . SetClip ( rect ) ;
503+ rc . SetClip ( rect ) ;
504+ using ( rc . AutoResetClip ( rect ) )
505+ {
506+ rc . DrawText ( new ScreenPoint ( p1 . X * 2 , 100 ) , "Clipped" , OxyColors . Black , fontSize : 40 ) ;
507+ }
508+ } ) ) ;
509+
510+ return model ;
511+ }
512+
461513 private const double GRID_SIZE = 40 ;
462514 private const double TILE_SIZE = 30 ;
463515 private const int THICKNESS_STEPS = 10 ;
@@ -466,10 +518,6 @@ public static PlotModel DrawTextWithMetrics(string text, string font, double fon
466518 private const double OFFSET_TOP = 20 ;
467519 private static readonly OxyColor FILL_COLOR = OxyColors . LightBlue ;
468520
469- /// <summary>
470- /// Shows capabilities for the MeasureText method.
471- /// </summary>
472- /// <returns>A plot model.</returns>
473521 [ Example ( "Rectangles - EdgeRenderingMode" ) ]
474522 public static PlotModel Rectangles ( )
475523 {
@@ -500,10 +548,6 @@ public static PlotModel Rectangles()
500548 return model ;
501549 }
502550
503- /// <summary>
504- /// Shows capabilities for the MeasureText method.
505- /// </summary>
506- /// <returns>A plot model.</returns>
507551 [ Example ( "Lines - EdgeRenderingMode" ) ]
508552 public static PlotModel Lines ( )
509553 {
@@ -540,10 +584,6 @@ public static PlotModel Lines()
540584 return model ;
541585 }
542586
543- /// <summary>
544- /// Shows capabilities for the MeasureText method.
545- /// </summary>
546- /// <returns>A plot model.</returns>
547587 [ Example ( "Polygons - EdgeRenderingMode" ) ]
548588 public static PlotModel Polygons ( )
549589 {
@@ -582,10 +622,6 @@ public static PlotModel Polygons()
582622 return model ;
583623 }
584624
585- /// <summary>
586- /// Shows capabilities for the MeasureText method.
587- /// </summary>
588- /// <returns>A plot model.</returns>
589625 [ Example ( "Ellipses - EdgeRenderingMode" ) ]
590626 public static PlotModel Ellipses ( )
591627 {
@@ -619,7 +655,7 @@ public static PlotModel Ellipses()
619655 /// <summary>
620656 /// Represents an annotation that renders by a delegate.
621657 /// </summary>
622- private class DelegateAnnotation : Annotation
658+ public class DelegateAnnotation : Annotation
623659 {
624660 /// <summary>
625661 /// Initializes a new instance of the <see cref="DelegateAnnotation"/> class.
0 commit comments