protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { base.OnRender(chartControl, chartScale); if (ChartBars == null) { return; } // Set AntiAlias mode for smoothing SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode; RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; // Draw Price Line DrawLine(PriceLineBrush, chartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex - PriceLineLength), chartScale.GetYByValue(Close.GetValueAt(CurrentBar)), ChartPanel.W, chartScale.GetYByValue(Close.GetValueAt(CurrentBar)), PriceLineWidth, PriceLineStyle); // Draw label DrawString(Close.GetValueAt(CurrentBar).ToString() + " = Last Price -- ", Font, PriceTextBrush, chartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex - PriceLineLength), chartScale.GetYByValue(Close.GetValueAt(CurrentBar)), PriceAreaBrush); //Reset AntiAlias mode RenderTarget.AntialiasMode = oldAntialiasMode; }
private unsafe static int SetAntialiasModeImpl(IntPtr thisPtr, SharpDX.Direct2D1.AntialiasMode antialiasMode) { try { var shadow = ToShadow <CommandSinkShadow>(thisPtr); var callback = (CommandSink)shadow.Callback; callback.AntialiasMode = antialiasMode; } catch (Exception exception) { return((int)SharpDX.Result.GetResultFromException(exception)); } return(Result.Ok.Code); }
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { // Call base.OnRender() to ensure plots get rendered appropriately. base.OnRender(chartControl, chartScale); if (Bars == null || ChartControl == null) { return; } // Set AntiAlias mode for smoothing SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode; RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; // Limit Custom Rendering to ChartBarsd.FromIndex and ChartBars.ToIndex for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++) { // Reference Series objects with GetValueAt(idx). Only check FromIndex bar so we don't draw lines for multiple bars. if (DrawSeries.GetValueAt(idx) && idx == ChartBars.FromIndex) { // Line 1 DrawLine("BrushToUse", ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartPanel.H, BrushToUseWidth, DashStyleHelper.Solid); // Line 2 DrawLine("BrushToUse", ChartPanel.X - 20, ChartPanel.Y, ChartPanel.W - 20, ChartPanel.H, BrushToUseWidth, DashStyleHelper.Dash); // Line 3 DrawLine("BrushToUse", ChartPanel.X - 40, ChartPanel.Y, ChartPanel.W - 40, ChartPanel.H, BrushToUseWidth, DashStyleHelper.DashDot); } } //Reset AntiAlias mode RenderTarget.AntialiasMode = oldAntialiasMode; }
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { // Call base OnRender() method to paint defined Plots. base.OnRender(chartControl, chartScale); // Store previous AA mode SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode; RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; // Draw Region between SenkouSpanA and SenkouSpanB DrawRegionBetweenSeries(chartScale, SenkouSpanA, SenkouSpanB, "CloudAreaColorUp", "CloudAreaColorDown", CloudDisplacement); // Reset AA mode. RenderTarget.AntialiasMode = oldAntialiasMode; }
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { // Call base OnRender() method to paint defined Plots. base.OnRender(chartControl, chartScale); // Store previous AA mode SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode; RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; // Create Linear Graient Brush Properties SharpDX.Direct2D1.RadialGradientBrushProperties rgbProps = new SharpDX.Direct2D1.RadialGradientBrushProperties(); rgbProps.Center = new SharpDX.Vector2(ChartPanel.W / 2, ChartPanel.H / 2); rgbProps.RadiusX = ChartPanel.W / 2; rgbProps.RadiusY = ChartPanel.W / 2; // Create Gradient Stop1 for the Gradient Stop Collection SharpDX.Direct2D1.GradientStop stop1; stop1.Color = SharpDX.Color.DarkSalmon; stop1.Position = 0; // Create Gradient Stop2 for the Gradient Stop Collection SharpDX.Direct2D1.GradientStop stop2; stop2.Color = SharpDX.Color.DarkGreen; stop2.Position = 1; // Create GradientStop array for GradientStopCollection SharpDX.Direct2D1.GradientStop[] rgbStops = new SharpDX.Direct2D1.GradientStop[] { stop1, stop2 }; // Make our GradientStopCollection SharpDX.Direct2D1.GradientStopCollection rgbSGC = new SharpDX.Direct2D1.GradientStopCollection(RenderTarget, rgbStops); // Finally, create the LinearGradientBrush SharpDX.Direct2D1.RadialGradientBrush rgBrush = new SharpDX.Direct2D1.RadialGradientBrush(RenderTarget, rgbProps, rgbSGC); // Render Draw Method here RenderTarget.FillEllipse(new SharpDX.Direct2D1.Ellipse(new SharpDX.Vector2(ChartPanel.W / 2, ChartPanel.H / 2), ChartPanel.W / 2, ChartPanel.H / 2), rgBrush); // This exmaple describes implementation in OnRender(), for more effieceny, dipose and recreate class level RenderTarget dependant objects in OnRederTargetStateChange() rgbSGC.Dispose(); rgBrush.Dispose(); // Reset AA mode. RenderTarget.AntialiasMode = oldAntialiasMode; }
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { if (!IsVisible) { return; } if (!IsInHitTest && lastBarNum > 0) { // start point is 10 bars back and 5 ticks up from 2nd to last bar and price startPoint = new Point(ChartControl.GetXByBarIndex(ChartBars, (lastBarNum - 10)), chartScale.GetYByValue(lastPrice + 5 * TickSize)); // end point is 2nd to last bar and 5 ticks down from price endPoint = new Point(ChartControl.GetXByBarIndex(ChartBars, (lastBarNum)), chartScale.GetYByValue(lastPrice - 5 * TickSize)); SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode; RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; RenderTarget.DrawLine(startPoint.ToVector2(), endPoint.ToVector2(), brushDx, 15); RenderTarget.AntialiasMode = oldAntialiasMode; } base.OnRender(chartControl, chartScale); }
private unsafe static int PushAxisAlignedClipImpl(IntPtr thisPtr, IntPtr clipRect, SharpDX.Direct2D1.AntialiasMode antialiasMode) { try { var shadow = ToShadow <CommandSinkShadow>(thisPtr); var callback = (CommandSink)shadow.Callback; callback.PushAxisAlignedClip(*(RawRectangleF *)clipRect, antialiasMode); } catch (Exception exception) { return((int)SharpDX.Result.GetResultFromException(exception)); } return(Result.Ok.Code); }
// drawZones // private void drawZones(ChartControl chartControl, ChartScale chartScale) { if (hideActiveZones && hideBrokenZones) { return; } if (Zones.Count == 0) { return; } SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode; RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.Aliased; SharpDX.Direct2D1.Brush demandBrush = demandColor.ToDxBrush(RenderTarget); SharpDX.Direct2D1.Brush supplyBrush = supplyColor.ToDxBrush(RenderTarget); int x1 = 0; int x2 = 0; int y1 = 0; int y2 = 0; int wd = (int)(chartControl.BarWidth / 2.0) + (int)(chartControl.BarMarginLeft / 2.0); for (int i = 0; i < Zones.Count; i++) { if (Zones[i].a == true && hideActiveZones) { continue; } if (Zones[i].a == false && hideBrokenZones) { continue; } if (barIndex == 0) { x1 = ChartControl.GetXByBarIndex(ChartBars, Zones[i].b); x2 = (Zones[i].a == false) ? ChartControl.GetXByBarIndex(ChartBars, Zones[i].e) : (int)(ChartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex) + wd); x2 = (Zones[i].a == true && extendZones) ? chartControl.CanvasRight: x2; } else { x1 = ChartControl.GetXByBarIndex(ChartBars, findBar(Zones[i])); //x1 = ChartControl.GetXByBarIndex(ChartBars, BarsArray[0].GetBar(BarsArray[1].GetTime(Zones[i].b))); x2 = (Zones[i].a == false) ? ChartControl.GetXByBarIndex(ChartBars, ChartBars.GetBarIdxByTime(chartControl, BarsArray[1].GetTime(Zones[i].e))) : (int)(ChartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex) + wd); x2 = (Zones[i].a == true && extendZones) ? chartControl.CanvasRight: x2; } if (x2 < x1) { continue; } y1 = chartScale.GetYByValue(Zones[i].h); y2 = chartScale.GetYByValue(Zones[i].l); // area SharpDX.RectangleF rect = new SharpDX.RectangleF(); rect.X = (float)x1; rect.Y = (float)y1; rect.Width = (float)Math.Abs(x2 - x1); rect.Height = (float)Math.Abs(y1 - y2) - 1; if (Zones[i].a == true) { demandBrush.Opacity = activeAreaOpacity; supplyBrush.Opacity = activeAreaOpacity; } else { demandBrush.Opacity = brokenAreaOpacity; supplyBrush.Opacity = brokenAreaOpacity; } if (Zones[i].t == "d") { RenderTarget.FillRectangle(rect, demandBrush); } if (Zones[i].t == "s") { RenderTarget.FillRectangle(rect, supplyBrush); } // line one if (Zones[i].a == true) { demandBrush.Opacity = activeLineOpacity; supplyBrush.Opacity = activeLineOpacity; } else { demandBrush.Opacity = brokenLineOpacity; supplyBrush.Opacity = brokenLineOpacity; } SharpDX.Vector2 pOne = new SharpDX.Vector2(); SharpDX.Vector2 pTwo = new SharpDX.Vector2(); pOne.X = (float)x1; pOne.Y = (float)y1; pTwo.X = (float)x2; pTwo.Y = (float)y1; if (Zones[i].t == "d") { RenderTarget.DrawLine(pOne, pTwo, demandBrush, lineWidth); } if (Zones[i].t == "s") { RenderTarget.DrawLine(pOne, pTwo, supplyBrush, lineWidth); } // line two pOne.X = (float)x1; pOne.Y = (float)y2; pTwo.X = (float)x2; pTwo.Y = (float)y2; if (Zones[i].t == "d") { RenderTarget.DrawLine(pOne, pTwo, demandBrush, lineWidth); } if (Zones[i].t == "s") { RenderTarget.DrawLine(pOne, pTwo, supplyBrush, lineWidth); } } RenderTarget.AntialiasMode = oldAntialiasMode; // --- demandBrush.Dispose(); supplyBrush.Dispose(); }
/// <unmanaged>HRESULT ID2D1CommandSink::PushAxisAlignedClip([In] const D2D_RECT_F* clipRect,[In] D2D1_ANTIALIAS_MODE antialiasMode)</unmanaged> public void PushAxisAlignedClip(SharpDX.RectangleF clipRect, SharpDX.Direct2D1.AntialiasMode antialiasMode) { PushAxisAlignedClip_(clipRect, antialiasMode); }
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { bool overlay = false; // Call base.OnRender() to ensure plots get rendered appropriately. base.OnRender(chartControl, chartScale); if (Bars == null || ChartControl == null) { return; } // Set AntiAlias mode for smoothing SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode; RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; // Check if we are in hit test for chartScale lines to ignore mouse clicks on these drawings if (!IsInHitTest) { double top = Instrument.MasterInstrument.RoundToTickSize(chartScale.GetValueByY(ChartPanel.Y)); double bot = Instrument.MasterInstrument.RoundToTickSize(chartScale.GetValueByY(ChartPanel.H)); double lastPos = chartScale.GetYByValue(bot - 2 * TickSize); int j = 0; // Loop through each tick level to draw lines with alternating DashStyles for (double i = bot - TickSize; i <= top; i += TickSize) { // This check makes sure lines have a distance greater than 1 pixel. if (lastPos - chartScale.GetYByValue(i) > 1) { // Iterate our DashStyle type ++j; // Draw our alternating tick lines DXH.DrawLine(RenderTarget, "LineBrush", ChartPanel.X, chartScale.GetYByValue(i), ChartPanel.W, chartScale.GetYByValue(i), LineBrushWidth, (DashStyleHelper)(j % 4)); lastPos = chartScale.GetYByValue(i); } } } // Limit Custom Rendering to ChartBars.FromIndex and ChartBars.ToIndex // Each index can be used for rendering per bar for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++) { // Reference Series objects with GetValueAt(idx) for each up bar marked in our "DrawSeries". // It is best to determine what should be rendered outside of OnRender() as much as possible to reduce repeated calculations in OnRender(). if (DrawSeries.GetValueAt(idx)) { // Set a bool for overlay drawing to be done last overlay = true; // DXMBrush Dictionary Reference for up bars DXH.DrawLine(RenderTarget, "LineBrush", ChartControl.GetXByBarIndex(ChartBars, idx) - 0.5, chartScale.GetYByValue(Close.GetValueAt(idx)) - 0.5, ChartControl.GetXByBarIndex(ChartBars, idx) - 0.5, chartScale.GetYByValue(Open.GetValueAt(idx)) - 0.5, (float)ChartControl.BarWidth * 2, DashStyleHelper.Solid); } // Demonstrate DrawText using DXMediaBrush DXH.DrawText(RenderTarget, idx.ToString(), new SimpleFont("Arial", 10), chartControl.GetXByBarIndex(ChartBars, idx), chartScale.GetYByValue(High.GetValueAt(idx) + 3 * TickSize), idx.ToString().Length *10, 10, DXMBrush); // Demonstrate DrawText Layout using DXMediaBrush DXH.DrawTextLayout(RenderTarget, ChartPanel, chartControl.GetXByBarIndex(ChartBars, idx), chartScale.GetYByValue(Low.GetValueAt(idx) - 3 * TickSize), idx.ToString(), new SimpleFont("Arial", 10), DXMBrush); // Demonstrate FillEllipse using DXMediaBrush Dictionary reference DXH.FillEllipse(RenderTarget, chartControl.GetXByBarIndex(ChartBars, idx), chartScale.GetYByValue((High.GetValueAt(idx) + 5 * TickSize)), (float)chartControl.BarWidth * 2, (float)chartControl.BarWidth * 2, "EllipseBrush"); // Demonstrate DrawEllipse using DXMediaBrush Dictionary reference DXH.DrawEllipse(RenderTarget, chartControl.GetXByBarIndex(ChartBars, idx), chartScale.GetYByValue(Low.GetValueAt(idx) - 5 * TickSize), (float)chartControl.BarWidth * 2, (float)chartControl.BarWidth * 2, "EllipseBrush", 2, DashStyleHelper.Dash); } // Draw items that should be overlayed once after all other drawing so the overlay remains on top and ignore mouse clicks if (overlay && !IsInHitTest) { // Draw some images DXH.DrawBitmap(RenderTarget, Image1Path, ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartPanel.H, Image1Opacity); DXH.DrawBitmap(RenderTarget, Image2Path, ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartPanel.H, Image2Opacity); // Draw a filled rectangle and a rectangle border DXH.FillRectangle(RenderTarget, ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartPanel.H, "RectBrush"); DXH.DrawRectangle(RenderTarget, ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartPanel.H, "RectBorderBrush", 10, DashStyleHelper.Dash); // Draw a filled rounded rectangle and a rounded rectangle border DXH.FillRoundedRectangle(RenderTarget, ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartPanel.H, ChartPanel.W / 2, ChartPanel.H / 2, "RoundedRectBrush"); DXH.DrawRoundedRectangle(RenderTarget, ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartPanel.H, ChartPanel.W / 2, ChartPanel.H / 2, "RoundedRectBorderBrush", 10, DashStyleHelper.Dash); // Line 1 DXMediaBrush Dictionary Reference DXH.DrawLine(RenderTarget, "LineBrush", ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartPanel.H, LineBrushWidth, DashStyleHelper.Solid); // Line 2 DXMediaBrush reference DXH.DrawLine(RenderTarget, DXMBrush, ChartPanel.X - 20, ChartPanel.Y, ChartPanel.W - 20, ChartPanel.H, LineBrushWidth, DashStyleHelper.Dash); // Line 3 DXMediaBrush.DxBrush reference from DXMediaBrush DXH.DrawLine(RenderTarget, DXMBrush.DxBrush, ChartPanel.X - 40, ChartPanel.Y, ChartPanel.W - 40, ChartPanel.H, LineBrushWidth, DashStyleHelper.DashDot); // Line 4 Windows Media Brush reference from DXMediaBrush DXH.DrawLine(RenderTarget, DXMBrush.MediaBrush, ChartPanel.X - 60, ChartPanel.Y, ChartPanel.W - 60, ChartPanel.H, LineBrushWidth, DashStyleHelper.DashDotDot); // Line 5 Windows Media Brush reference from User Defined Brush (Media Brushes must be cloned and refrozen for opacity to have effect) DXH.DrawLine(RenderTarget, LineBrush, ChartPanel.X - 80, ChartPanel.Y, ChartPanel.W - 80, ChartPanel.H, LineBrushWidth, DashStyleHelper.Solid); } //Reset AntiAlias mode RenderTarget.AntialiasMode = oldAntialiasMode; }
public override void OnRender(ChartControl chartControl, ChartScale chartScale) { try { if (model != null) { SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode; RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; ChartPanel panel = chartControl.ChartPanels[chartScale.PanelIndex]; Point startPoint = StartAnchor.GetPoint(chartControl, panel, chartScale); // align to full pixel to avoid unneeded aliasing double strokePixAdj = ((double)(1 % 2)).ApproxCompare(0) == 0 ? 0.5d : 0d; Vector pixelAdjustVec = new Vector(strokePixAdj, strokePixAdj); Point endPoint = EndAnchor.GetPoint(chartControl, panel, chartScale); // convert our start / end pixel points to directx 2d vectors Point startPointAdjusted = startPoint + pixelAdjustVec; Point endPointAdjusted = endPoint + pixelAdjustVec; SharpDX.Vector2 startVec = startPointAdjusted.ToVector2(); SharpDX.Vector2 endVec = endPointAdjusted.ToVector2(); //SharpDX.Direct2D1.Brush tmpBrush = chartControl.SelectionBrush; SharpDX.Vector2 tmpVect = startVec - endVec; brush0DX = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Black); brush0DX.Opacity = (float)0.01; brush1DX = model.Input_ProfileRange_Border_Color.ToDxBrush(RenderTarget); brush2DX = model.Input_ProfileRange_Inside_Color.ToDxBrush(RenderTarget); brush2DX.Opacity = model.Profile_Opacity / (float)100d; brush3DX = model.Input_ProfileRange_POC_Color.ToDxBrush(RenderTarget); brush3DX.Opacity = model.Profile_Opacity / (float)100d; brush4DX = model.Range_Profile_Text_Color.ToDxBrush(RenderTarget); brush4DX.Opacity = model.Profile_Text_Opacity / (float)100d; brush5DX = model.Input_ProfileRange_Inside_Bid_Color.ToDxBrush(RenderTarget); brush5DX.Opacity = model.Profile_Opacity / (float)100d; brush6DX = model.Input_ProfileRange_Inside_Ask_Color.ToDxBrush(RenderTarget); brush6DX.Opacity = model.Profile_Opacity / (float)100d; brush7DX = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.WhiteSmoke); brush8DX = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Gray); brush9DX = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Gray); brush9DX.Opacity = (float)0.5; brush10DX = model.Input_ProfileRange_POC_Color.ToDxBrush(RenderTarget); brush10DX.Opacity = model.Profile_Text_Opacity / (float)100d; // if a plain ol' line, then we're all done // if we're an arrow line, make sure to draw the actual line. for extended lines, only a single // line to extended points is drawn below, to avoid unneeded multiple DrawLine calls //RenderTarget.DrawLine(startVec, endVec, model.Input_ProfileRange_Inside_Color.ToDxBrush(RenderTarget), 2); RenderTarget.DrawRectangle(new SharpDX.RectangleF(endVec.X, endVec.Y, tmpVect.X, tmpVect.Y), brush1DX, (float)1); RenderTarget.FillRectangle(new SharpDX.RectangleF(endVec.X, endVec.Y, tmpVect.X, tmpVect.Y), brush0DX); //int firstindex = ((int)model.parent.ChartControl.GetSlotIndexByTime(StartAnchor.Time)); //int lastIndex = ((int)model.parent.ChartControl.GetSlotIndexByTime(EndAnchor.Time)); int firstindex = model.parent.ChartBars.GetBarIdxByTime(chartControl, StartAnchor.Time); //Edited by PD int lastIndex = model.parent.ChartBars.GetBarIdxByTime(chartControl, EndAnchor.Time); //Edited by PD Model.HistogrammClass profile = new Model.HistogrammClass(); int count = 0; IEnumerable <Model.Bar> bars; if (firstindex <= lastIndex) { bars = model.GetBarRange(firstindex, lastIndex); } else { bars = model.GetBarRange(lastIndex, firstindex); } int leftPosition = 0; int topPosition = 0; if (startVec.X < endVec.X) { leftPosition = (int)startVec.X; } else { leftPosition = (int)endVec.X; } if (startVec.Y < endVec.Y) { topPosition = (int)startVec.Y; } else { topPosition = (int)endVec.Y; } foreach (Model.Bar bar in bars) { IEnumerable <KeyValuePair <double, Model.Claster> > clasters; if (StartAnchor.Price >= EndAnchor.Price) { clasters = bar.ListOfClasters.Where(c => c.Key <= StartAnchor.Price && c.Key >= EndAnchor.Price); } else { clasters = bar.ListOfClasters.Where(c => c.Key >= StartAnchor.Price && c.Key <= EndAnchor.Price); } foreach (KeyValuePair <double, Model.Claster> claster in clasters) { profile.AddPrintToHistogramm(claster.Key, claster.Value.Volume_Ask_sum, PrintType.ASK); profile.AddPrintToHistogramm(claster.Key, claster.Value.Volume_Bid_sum, PrintType.BID); } } //textToRender+=" : "+profile.ListOfCurrentBar.Count.ToString(); Dictionary <double, int> deltaProfile = new Dictionary <double, int>(); double maxDeltaPrice = int.MinValue; int prevdelta = 0; int volumeSum = 0; foreach (KeyValuePair <double, Model.CurrentClaster> claster in profile.ListOfCurrentBar) { volumeSum += claster.Value.Volume_sum; int delta = Math.Abs(claster.Value.Volume_Bid_sum - claster.Value.Volume_Ask_sum); deltaProfile.Add(claster.Key, delta); if (prevdelta <= delta) { prevdelta = delta; maxDeltaPrice = claster.Key; } } SharpDX.DirectWrite.TextFormat Claster_textFormat = chartControl.Properties.LabelFont.ToDirectWriteTextFormat(); Claster_textFormat.ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Center; int vol1 = ProfileType != 1 ? (int)Math.Abs(tmpVect.X) : (int)Math.Abs(tmpVect.X / 2); float fontSize1 = Math.Max(7, Math.Min(vol1 / 2, Math.Min(14, model.Claster_Height - 1))); SharpDX.DirectWrite.TextFormat Claster_textFormatEach = new SharpDX.DirectWrite.TextFormat(Core.Globals.DirectWriteFactory, "Arial", SharpDX.DirectWrite.FontWeight.Normal, SharpDX.DirectWrite.FontStyle.Normal, fontSize1); Claster_textFormatEach.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading; Claster_textFormatEach.ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Center; Claster_textFormatEach.WordWrapping = SharpDX.DirectWrite.WordWrapping.NoWrap; if (ProfileType == 1 || ProfileType == 0) { foreach (KeyValuePair <double, Model.CurrentClaster> claster in profile.ListOfCurrentBar) { int Y_histogramm = chartScale.GetYByValue(claster.Key) - model.Claster_Height / 2; int vol = claster.Value.Volume_sum * (int)Math.Abs(tmpVect.X) / profile.ListOfCurrentBar[profile.pocPrice].Volume_sum; if (ProfileType == 0) { if (claster.Key == profile.pocPrice) { if (ExtendedLine) { vol = (int)ChartPanel.MaxWidth - Math.Abs(leftPosition); } RenderTarget.FillRectangle(new SharpDX.RectangleF(leftPosition, Y_histogramm, vol, model.Claster_Height), brush3DX); int text_Y = chartScale.GetYByValue(profile.pocPrice) - model.Claster_Height / 2; int text_width = profile.pocPrice.ToString().Length *7; RenderTarget.DrawText(profile.pocPrice.ToString(), Claster_textFormat, new SharpDX.RectangleF(leftPosition - text_width, text_Y, text_width, model.Claster_Height), brush10DX); //RenderTarget.DrawRectangle(new SharpDX.RectangleF(leftPosition-text_width, text_Y,text_width ,model.Claster_Height), Brushes.Red.ToDxBrush(RenderTarget), 1f); // } else { RenderTarget.FillRectangle(new SharpDX.RectangleF(leftPosition, Y_histogramm, vol, model.Claster_Height), brush2DX); } if (model.Range_Profile_Text_OnOff && vol1 > 10 && model.Claster_Height > 5) { SharpDX.RectangleF rectText = new SharpDX.RectangleF(leftPosition + 2, Y_histogramm, vol1, model.Claster_Height); //RenderTarget.DrawRectangle(rectText, model.Range_Profile_Text_Color.ToDxBrush(RenderTarget), 1f); RenderTarget.DrawText(claster.Value.Volume_sum.ToString(), Claster_textFormatEach, rectText, brush4DX); } } if (ProfileType == 1) { int vol_bid = claster.Value.Volume_Bid_sum * vol / claster.Value.Volume_sum; RenderTarget.FillRectangle(new SharpDX.RectangleF(leftPosition, Y_histogramm, vol_bid, model.Claster_Height), brush5DX); RenderTarget.FillRectangle(new SharpDX.RectangleF(leftPosition + vol_bid, Y_histogramm, vol - vol_bid, model.Claster_Height), brush6DX); if (claster.Key == profile.pocPrice && ExtendedLine) { RenderTarget.FillRectangle(new SharpDX.RectangleF(leftPosition + vol, Y_histogramm, (int)ChartPanel.MaxWidth - Math.Abs(leftPosition + vol), model.Claster_Height), brush3DX); } if (claster.Key == profile.pocPrice) { int text_Y = chartScale.GetYByValue(profile.pocPrice) - model.Claster_Height / 2; int text_width = profile.pocPrice.ToString().Length *7; RenderTarget.DrawText(profile.pocPrice.ToString(), Claster_textFormat, new SharpDX.RectangleF(leftPosition - text_width, text_Y, text_width, model.Claster_Height), brush10DX); //RenderTarget.DrawRectangle(new SharpDX.RectangleF(leftPosition-text_width, text_Y,text_width ,model.Claster_Height), Brushes.Red.ToDxBrush(RenderTarget), 1f); } if (model.Range_Profile_Text_OnOff && vol1 > 10 && model.Claster_Height > 5) { SharpDX.RectangleF rectText = new SharpDX.RectangleF(leftPosition + 2, Y_histogramm, vol1, model.Claster_Height); //RenderTarget.DrawRectangle(rectText, model.Range_Profile_Text_Color.ToDxBrush(RenderTarget), 1f); RenderTarget.DrawText(claster.Value.Volume_Bid_sum.ToString() + " x " + claster.Value.Volume_Ask_sum.ToString(), Claster_textFormatEach, rectText, brush4DX); } } } } if (ProfileType == 2) { foreach (KeyValuePair <double, int> claster in deltaProfile) { int Y_histogramm = chartScale.GetYByValue(claster.Key) - model.Claster_Height / 2; int vol_delta = claster.Value * (int)Math.Abs(tmpVect.X) / (int)prevdelta; if (profile.ListOfCurrentBar[claster.Key].Volume_Bid_sum == profile.ListOfCurrentBar[claster.Key].Volume_Ask_sum) { vol_delta = 0; } else if (profile.ListOfCurrentBar[claster.Key].Volume_Bid_sum > profile.ListOfCurrentBar[claster.Key].Volume_Ask_sum) { RenderTarget.FillRectangle(new SharpDX.RectangleF(leftPosition, Y_histogramm, vol_delta, model.Claster_Height), brush5DX); } else if (profile.ListOfCurrentBar[claster.Key].Volume_Bid_sum < profile.ListOfCurrentBar[claster.Key].Volume_Ask_sum) { RenderTarget.FillRectangle(new SharpDX.RectangleF(leftPosition, Y_histogramm, vol_delta, model.Claster_Height), brush6DX); } if (model.Range_Profile_Text_OnOff && vol1 > 10 && model.Claster_Height > 5) { SharpDX.RectangleF rectText = new SharpDX.RectangleF(leftPosition + 2, Y_histogramm, vol1, model.Claster_Height); //RenderTarget.DrawRectangle(rectText, model.Range_Profile_Text_Color.ToDxBrush(RenderTarget), 1f); RenderTarget.DrawText((profile.ListOfCurrentBar[claster.Key].Volume_Ask_sum - profile.ListOfCurrentBar[claster.Key].Volume_Bid_sum).ToString(), Claster_textFormatEach, rectText, brush4DX); } } int text_Y = chartScale.GetYByValue(maxDeltaPrice) - model.Claster_Height / 2; int text_width = maxDeltaPrice.ToString().Length *7; RenderTarget.DrawText(maxDeltaPrice.ToString(), Claster_textFormat, new SharpDX.RectangleF(leftPosition - text_width, text_Y, text_width, model.Claster_Height), brush10DX); } RenderTarget.DrawText("Σ " + volumeSum.ToString(), Claster_textFormat, new SharpDX.RectangleF(leftPosition, topPosition + Math.Abs(tmpVect.Y) + 3, volumeSum.ToString().Length *8 + 10, 10), brush10DX); if (Claster_textFormat != null) { Claster_textFormat.Dispose(); } if (Claster_textFormatEach != null) { Claster_textFormatEach.Dispose(); } if (IsSelected) { SharpDX.Vector2 tempVector1 = new Point(leftPosition + 2, topPosition + 2 - 20).ToVector2(); SharpDX.Vector2 tempVector2 = new Point(leftPosition - 2 + 15, topPosition - 2 - 20 + 15).ToVector2(); RenderTarget.DrawLine(tempVector1, tempVector2, brush8DX, 2); tempVector1.X += 11; tempVector2.X -= 11; RenderTarget.DrawLine(tempVector1, tempVector2, brush8DX, 2); RenderTarget.DrawRectangle(new SharpDX.RectangleF(leftPosition, topPosition - 20, 15, 15), brush8DX, (float)1); RenderTarget.DrawRectangle(new SharpDX.RectangleF(leftPosition + 20, topPosition - 20, 15, 15), brush8DX, (float)1); string str = ""; switch (ProfileType) { case 0: str = "V"; break; case 1: str = "P"; break; case 2: str = "D"; break; } SharpDX.DirectWrite.Factory fontFactory = new SharpDX.DirectWrite.Factory(); SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(fontFactory, "Segoe UI", 15); RenderTarget.DrawText(str, textFormat, new SharpDX.RectangleF(leftPosition + 23, topPosition - 23, 15, 15), brush7DX); fontFactory.Dispose(); textFormat.Dispose(); if (ExtendedLine) { RenderTarget.FillRectangle(new SharpDX.RectangleF(leftPosition + 42, topPosition - 18, 11, 11), brush9DX); } RenderTarget.DrawRectangle(new SharpDX.RectangleF(leftPosition + 40, topPosition - 20, 15, 15), brush8DX, (float)1); } RenderTarget.AntialiasMode = oldAntialiasMode; if (brush0DX != null) { brush0DX.Dispose(); } if (brush1DX != null) { brush1DX.Dispose(); } if (brush2DX != null) { brush2DX.Dispose(); } if (brush3DX != null) { brush3DX.Dispose(); } if (brush4DX != null) { brush4DX.Dispose(); } if (brush5DX != null) { brush5DX.Dispose(); } if (brush6DX != null) { brush6DX.Dispose(); } if (brush7DX != null) { brush7DX.Dispose(); } if (brush8DX != null) { brush8DX.Dispose(); } if (brush9DX != null) { brush9DX.Dispose(); } if (brush10DX != null) { brush10DX.Dispose(); } } } catch (Exception ex) { Print("Range Profile2 OnRender 663: " + ex); } return; }
public override void OnRender(ChartControl chartControl, ChartScale chartScale) { try { if (!model.parent.Input_TickAggregator_OnOff) { Dispose(); return; } if (model != null) { SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode; RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; ChartPanel panel = chartControl.ChartPanels[chartScale.PanelIndex]; Point startPoint = StartAnchor.GetPoint(chartControl, panel, chartScale); // align to full pixel to avoid unneeded aliasing double strokePixAdj = ((double)(1 % 2)).ApproxCompare(0) == 0 ? 0.5d : 0d; Vector pixelAdjustVec = new Vector(strokePixAdj, strokePixAdj); //Point endPoint = EndAnchor.GetPoint(chartControl, panel, chartScale); // convert our start / end pixel points to directx 2d vectors Point startPointAdjusted = startPoint + pixelAdjustVec; SharpDX.Vector2 startVec = startPointAdjusted.ToVector2(); // if a plain ol' line, then we're all done // if we're an arrow line, make sure to draw the actual line. for extended lines, only a single // line to extended points is drawn below, to avoid unneeded multiple DrawLine calls // RenderTarget.DrawLine(startVec, endVec, tmpBrush, LineStroke.Width, LineStroke.StrokeStyle); brush0DX = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.WhiteSmoke); brush1DX = model.parent.Input_TickAggregator_AskColor.ToDxBrush(RenderTarget); brush1DX.Opacity = (float)0.3; brush2DX = model.parent.Input_TickAggregator_BidColor.ToDxBrush(RenderTarget); brush2DX.Opacity = (float)0.3; brush3DX = model.parent.Input_TickAggregator_AskColor.ToDxBrush(RenderTarget); brush4DX = model.parent.Input_TickAggregator_BidColor.ToDxBrush(RenderTarget); brush5DX = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Black); brush5DX.Opacity = (float)0.01; brush6DX = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.White); brush6DX.Opacity = (float)0.3; brush7DX = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.White); SharpDX.Direct2D1.Ellipse el = new SharpDX.Direct2D1.Ellipse(startVec, Radius, Radius); int Position_Y1 = chartScale.GetYByValue(TickAggregatorData.TopPrice) - model.Claster_Height / 2; int Position_Y2 = chartScale.GetYByValue(TickAggregatorData.LowPrice); int Delta_Y = Position_Y2 - Position_Y1 + model.Claster_Height / 2; if (Delta_Y < 1) { Delta_Y = model.Claster_Height; } int max = model.parent.Input_TickAggregator_Distance; int Position_X1 = chartControl.GetXByTime(TickAggregatorData.Time); int Delta_X = TickAggregatorData.Volume * max / model.MaxTickAggregatorVolume; int Delta_X_Ask = TickAggregatorData.Volume_Ask * Delta_X / 100; int Delta_X_Bid = Delta_X - Delta_X_Ask; if (IsSelected) { SharpDX.DirectWrite.TextFormat Claster_textFormat = chartControl.Properties.LabelFont.ToDirectWriteTextFormat(); string str = "Volume: " + TickAggregatorData.Volume.ToString() + " ="; //+" - "+TickAggregatorData.Volume_Ask.ToString()+" - "+TickAggregatorData.Volume_Bid.ToString(); //string str =""; bool tmpFirst = true; foreach (Model.Print p in TickAggregatorData.PrintList) { if (p.Volume >= model.parent.Input_TickAggregator_TickShow) { if (tmpFirst) { str += " " + p.Volume; tmpFirst = false; } else { str += " + " + p.Volume; } } else { break; } } string str1 = "Time: " + TickAggregatorData.Time.ToLongTimeString() + " MaxPrice: " + TickAggregatorData.TopPrice.ToString() + " MinPrice: " + TickAggregatorData.LowPrice.ToString() + " Ask: " + TickAggregatorData.Volume_Ask.ToString() + "% Bid:" + TickAggregatorData.Volume_Bid.ToString() + "% Delta: " + TickAggregatorData.Volume_Delta.ToString() + "%"; if (model.parent.Input_TickAggregator_Standart) { RenderTarget.DrawText(str1, Claster_textFormat, new SharpDX.RectangleF(startVec.X + 5, startVec.Y - Radius - 23, str1.Length * 8, 10), brush0DX); RenderTarget.DrawText(str, Claster_textFormat, new SharpDX.RectangleF(startVec.X + 5, startVec.Y - Radius - 12, str.Length * 8, 10), brush0DX); } else { RenderTarget.DrawText(str1, Claster_textFormat, new SharpDX.RectangleF(startVec.X + 5, Position_Y1 - 23, str1.Length * 8, 10), brush0DX); RenderTarget.DrawText(str, Claster_textFormat, new SharpDX.RectangleF(startVec.X + 5, Position_Y1 - 12, str.Length * 8, 10), brush0DX); } Claster_textFormat.Dispose(); } if (model.parent.Input_TickAggregator_Standart) { if (TickAggregatorData.Volume_Ask > TickAggregatorData.Volume_Bid) { RenderTarget.DrawEllipse(el, brush3DX); if (IsSelected) { RenderTarget.FillEllipse(el, brush1DX); } } else if (TickAggregatorData.Volume_Ask < TickAggregatorData.Volume_Bid) { RenderTarget.DrawEllipse(el, brush4DX); if (IsSelected) { RenderTarget.FillEllipse(el, brush2DX); } } else if (TickAggregatorData.Volume_Ask == TickAggregatorData.Volume_Bid) { RenderTarget.DrawEllipse(el, brush7DX); if (IsSelected) { RenderTarget.FillEllipse(el, brush6DX); } } if (!IsSelected) { RenderTarget.FillEllipse(el, brush5DX); } } else { RenderTarget.FillRectangle(new SharpDX.RectangleF(Position_X1, Position_Y1, Delta_X_Ask, Delta_Y), brush1DX); RenderTarget.FillRectangle(new SharpDX.RectangleF(Position_X1 + Delta_X_Ask, Position_Y1, Delta_X_Bid, Delta_Y), brush2DX); } RenderTarget.AntialiasMode = oldAntialiasMode; if (brush0DX != null) { brush0DX.Dispose(); } if (brush1DX != null) { brush1DX.Dispose(); } if (brush2DX != null) { brush2DX.Dispose(); } if (brush3DX != null) { brush3DX.Dispose(); } if (brush4DX != null) { brush4DX.Dispose(); } if (brush5DX != null) { brush5DX.Dispose(); } if (brush6DX != null) { brush6DX.Dispose(); } if (brush7DX != null) { brush7DX.Dispose(); } } } catch (Exception ex) { Print("MR CustomEllipse 417: " + ex); } return; }