Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1.  
  2. public static SharpDX.Direct2D1.LinearGradientBrush BrushToGradient(SharpDX.Direct2D1.RenderTarget renderTarget, Brush brush1, double transparency1, Brush brush2, double transparency2, float x1, float y1, float x2, float y2)
  3. {
  4. SharpDX.Direct2D1.Brush DXbrush1=null;
  5. SharpDX.Direct2D1.Brush DXbrush2 = null;
  6. SharpDX.Direct2D1.LinearGradientBrush linearGradientBrush = null;
  7. SharpDX.Direct2D1.GradientStopCollection gradientStopCollection = null;
  8. try
  9. {
  10. DXbrush1 = brush1.ToDxBrush(renderTarget);
  11. DXbrush2 = brush2.ToDxBrush(renderTarget);
  12. SharpDX.Direct2D1.SolidColorBrush dxbrush1a = (SharpDX.Direct2D1.SolidColorBrush)DXbrush1;
  13. SharpDX.Direct2D1.SolidColorBrush dxbrush2a = (SharpDX.Direct2D1.SolidColorBrush)DXbrush2;
  14. SharpDX.Color highCol = (SharpDX.Color)dxbrush1a.Color; highCol.A = (byte)(transparency1 / 100 * 255); //opacity should be 1-100
  15. SharpDX.Color lowCol = (SharpDX.Color)dxbrush2a.Color; lowCol.A = (byte)(transparency2 / 100 * 255);
  16. DXbrush1.Dispose();
  17. DXbrush2.Dispose();
  18. dxbrush1a.Dispose();
  19. dxbrush2a.Dispose();
  20. //this method ----> new SharpDX.Color4(col.R, col.G, col.B, col.A / 255); --- faults absolutely !!!
  21. gradientStopCollection = new SharpDX.Direct2D1.GradientStopCollection(renderTarget, new SharpDX.Direct2D1.GradientStop[]
  22. {
  23. new SharpDX.Direct2D1.GradientStop() { Color = highCol, Position = 0},
  24. new SharpDX.Direct2D1.GradientStop() { Color = lowCol, Position = 1}
  25. });
  26. linearGradientBrush = new SharpDX.Direct2D1.LinearGradientBrush(renderTarget,
  27. new SharpDX.Direct2D1.LinearGradientBrushProperties()
  28. {
  29. StartPoint = new SharpDX.Vector2(x1, y1),
  30. EndPoint = new SharpDX.Vector2(x2, y2),
  31. },
  32. gradientStopCollection
  33. );
  34. gradientStopCollection.Dispose();
  35. return linearGradientBrush;
  36. }
  37. catch { }
  38. finally
  39. {
  40. if (DXbrush1 !=null) DXbrush1.Dispose();
  41. if (DXbrush2 != null) DXbrush2.Dispose();
  42. //if (linearGradientBrush != null) linearGradientBrush.Dispose();
  43. if (gradientStopCollection != null) gradientStopCollection.Dispose();
  44. }
  45. return null;
  46. }
  47.  
  48. public static void fillGeometry(SharpDX.Direct2D1.RenderTarget renderTarget, SharpDX.Direct2D1.Brush dxBrush, SharpDX.Vector2 startvector, SharpDX.Vector2[] vectors)
  49. {
  50. SharpDX.Direct2D1.PathGeometry geo1 = null;
  51. SharpDX.Direct2D1.GeometrySink sink1 =null;
  52. try {
  53. geo1 = new SharpDX.Direct2D1.PathGeometry(NinjaTrader.Core.Globals.D2DFactory);
  54. sink1 = geo1.Open();
  55. sink1.BeginFigure(startvector, SharpDX.Direct2D1.FigureBegin.Filled);
  56. sink1.AddLines(vectors);
  57. sink1.EndFigure(SharpDX.Direct2D1.FigureEnd.Closed);
  58. sink1.Close();
  59. //RenderTarget.DrawGeometry(geo1, brush);
  60. renderTarget.FillGeometry(geo1, dxBrush);
  61. }
  62. catch { }
  63. finally
  64. {
  65. if (geo1 !=null) geo1.Dispose();
  66. if (sink1 !=null) sink1.Dispose();
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement