Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- {
- SharpDX.Direct2D1.Brush DXbrush1=null;
- SharpDX.Direct2D1.Brush DXbrush2 = null;
- SharpDX.Direct2D1.LinearGradientBrush linearGradientBrush = null;
- SharpDX.Direct2D1.GradientStopCollection gradientStopCollection = null;
- try
- {
- DXbrush1 = brush1.ToDxBrush(renderTarget);
- DXbrush2 = brush2.ToDxBrush(renderTarget);
- SharpDX.Direct2D1.SolidColorBrush dxbrush1a = (SharpDX.Direct2D1.SolidColorBrush)DXbrush1;
- SharpDX.Direct2D1.SolidColorBrush dxbrush2a = (SharpDX.Direct2D1.SolidColorBrush)DXbrush2;
- SharpDX.Color highCol = (SharpDX.Color)dxbrush1a.Color; highCol.A = (byte)(transparency1 / 100 * 255); //opacity should be 1-100
- SharpDX.Color lowCol = (SharpDX.Color)dxbrush2a.Color; lowCol.A = (byte)(transparency2 / 100 * 255);
- DXbrush1.Dispose();
- DXbrush2.Dispose();
- dxbrush1a.Dispose();
- dxbrush2a.Dispose();
- //this method ----> new SharpDX.Color4(col.R, col.G, col.B, col.A / 255); --- faults absolutely !!!
- gradientStopCollection = new SharpDX.Direct2D1.GradientStopCollection(renderTarget, new SharpDX.Direct2D1.GradientStop[]
- {
- new SharpDX.Direct2D1.GradientStop() { Color = highCol, Position = 0},
- new SharpDX.Direct2D1.GradientStop() { Color = lowCol, Position = 1}
- });
- linearGradientBrush = new SharpDX.Direct2D1.LinearGradientBrush(renderTarget,
- new SharpDX.Direct2D1.LinearGradientBrushProperties()
- {
- StartPoint = new SharpDX.Vector2(x1, y1),
- EndPoint = new SharpDX.Vector2(x2, y2),
- },
- gradientStopCollection
- );
- gradientStopCollection.Dispose();
- return linearGradientBrush;
- }
- catch { }
- finally
- {
- if (DXbrush1 !=null) DXbrush1.Dispose();
- if (DXbrush2 != null) DXbrush2.Dispose();
- //if (linearGradientBrush != null) linearGradientBrush.Dispose();
- if (gradientStopCollection != null) gradientStopCollection.Dispose();
- }
- return null;
- }
- public static void fillGeometry(SharpDX.Direct2D1.RenderTarget renderTarget, SharpDX.Direct2D1.Brush dxBrush, SharpDX.Vector2 startvector, SharpDX.Vector2[] vectors)
- {
- SharpDX.Direct2D1.PathGeometry geo1 = null;
- SharpDX.Direct2D1.GeometrySink sink1 =null;
- try {
- geo1 = new SharpDX.Direct2D1.PathGeometry(NinjaTrader.Core.Globals.D2DFactory);
- sink1 = geo1.Open();
- sink1.BeginFigure(startvector, SharpDX.Direct2D1.FigureBegin.Filled);
- sink1.AddLines(vectors);
- sink1.EndFigure(SharpDX.Direct2D1.FigureEnd.Closed);
- sink1.Close();
- //RenderTarget.DrawGeometry(geo1, brush);
- renderTarget.FillGeometry(geo1, dxBrush);
- }
- catch { }
- finally
- {
- if (geo1 !=null) geo1.Dispose();
- if (sink1 !=null) sink1.Dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement