Guest User

RenderTools usage

a guest
Jun 21st, 2012
2,047
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var renderTools = new RenderTools();
  2.  
  3. // Register gradient brush
  4. renderTools.RegisterTool<Tuple<Color, Color>, Brush>(tuple =>
  5.     new LinearGradientBrush
  6.     {
  7.         GradientStops = new GradientStopCollection(new []
  8.             {
  9.                 new GradientStop(tuple.Item1, 0),
  10.                 new GradientStop(tuple.Item2, 1)
  11.             })
  12.     });
  13.  
  14. // Register solid pen.
  15. renderTools.RegisterTool<Tuple<Brush, double>, Pen>(tuple => new Pen(tuple.Item1, tuple.Item2));
  16.  
  17. // Register pen with dashstyle support.
  18. renderTools.RegisterTool<Tuple<Brush, double, DashStyle>, Pen>(tuple => new Pen(tuple.Item1, tuple.Item2) { DashStyle = tuple.Item3 });
  19.  
  20. var brush1 = renderTools.GetTool<Brush>(new Tuple<Color, Color>(Colors.Red, Colors.Yellow));
  21. var brush2 = renderTools.GetTool<Brush>(new Tuple<Color, Color>(Colors.Red, Colors.Yellow));
  22. Console.WriteLine(Object.ReferenceEquals(brush1, brush2));
  23.  
  24. var pen1 = renderTools.GetTool<Pen>(new Tuple<Brush, double>(Brushes.Red, 5));
  25. var pen2 = renderTools.GetTool<Pen>(new Tuple<Brush, double>(Brushes.Red, 5));
  26. Console.WriteLine(Object.ReferenceEquals(pen1, pen2));
  27.  
  28. var pen3 = renderTools.GetTool<Pen>(new Tuple<Brush, double, DashStyle>(Brushes.Blue, 2, DashStyles.DashDotDot));
  29. var pen4 = renderTools.GetTool<Pen>(new Tuple<Brush, double, DashStyle>(Brushes.Blue, 2, DashStyles.DashDotDot));
  30. Console.WriteLine(Object.ReferenceEquals(pen3, pen4));
RAW Paste Data