public override void Draw(Graphics g) { base.Draw(g); PointF[] ps = ToPoints(); if (ShadowWidth > 0) { PointF[] pss = (PointF[])ps.Clone(); OffsetPoint(pss, ShadowWidth, ShadowWidth); g.FillPolygon(new SolidBrush(Color.FromArgb(64, Color.Black)), pss); } if (BackBrush.Color != Color.Empty) { g.FillPolygon(BackBrush.GetBrush(GetMaxRect()), ps); } if (LinePen.Color != Color.Empty) { g.DrawLines(LinePen.GetPen(), ps); } TextRenderingHint trh = g.TextRenderingHint; g.TextRenderingHint = TextRenderingHint.AntiAlias; LabelFont.DrawString(NewText, g, Rect); g.TextRenderingHint = trh; }
public void Dispose() { if (BackBrush != null) { BackBrush.Dispose(); } if (FontBrush != null) { FontBrush.Dispose(); } if (Icon != null) { Icon.Dispose(); } }
protected override void OnBarUpdate() { // check conditions for trade if (CurrentBar < BarsRequiredToTrade) { return; } if (isUpTrend()) { BackBrush = Brushes.Lime; Brush newBrush = BackBrush.Clone(); newBrush.Opacity = 0.25; newBrush.Freeze(); BackBrush = newBrush; } else if (isDownTrend()) { BackBrush = Brushes.HotPink; Brush newBrush = BackBrush.Clone(); newBrush.Opacity = 0.25; newBrush.Freeze(); BackBrush = newBrush; } if ((Position.MarketPosition == MarketPosition.Flat) && isUpTrend() && TradeLong) { var stopLoss = (Close[0] - dc.Lower[0]) * RiskFactor; var stopPrice = Close[0] - stopLoss; var limitPrice = Close[0] + stopLoss; EnterLong(10000, "Long"); ExitLongLimit(5000, limitPrice, "L-EX1", "Long"); ExitLongStopMarket(stopPrice, "L-SL", "Long"); } if ((Position.MarketPosition == MarketPosition.Long) && isDownTrend()) { ExitLong("Long"); } }
private void VideoNewFrame(object sender, NewFrameEventArgs e) { var nf = NewFrame; var f = e.Frame; if (_requestedToStop || nf == null || f == null) { return; } if (_lastframeEvent > DateTime.MinValue) { if ((Helper.Now < _nextFrameTarget)) { return; } CalculateFramerates(); } _lastframeEvent = Helper.Now; if (_updateResources) { _updateResources = false; DrawFont.Dispose(); DrawFont = null; ForeBrush.Dispose(); ForeBrush = null; BackBrush.Dispose(); BackBrush = null; SetMaskImage(); RotateFlipType rft; if (Enum.TryParse(CW.Camobject.rotateMode, out rft)) { RotateFlipType = rft; } else { RotateFlipType = RotateFlipType.RotateNoneFlipNone; } } Bitmap bmOrig = null; bool bMotion = false; lock (_sync) { try { bmOrig = ResizeBmOrig(f); if (RotateFlipType != RotateFlipType.RotateNoneFlipNone) { bmOrig.RotateFlip(RotateFlipType); } _width = bmOrig.Width; _height = bmOrig.Height; if (ZPoint == Point.Empty) { ZPoint = new Point(bmOrig.Width / 2, bmOrig.Height / 2); } if (CW.NeedMotionZones) { CW.NeedMotionZones = !SetMotionZones(CW.Camobject.detector.motionzones); } if (Mask != null) { ApplyMask(bmOrig); } if (CW.Camobject.alerts.active && Plugin != null && Alarm != null) { bmOrig = RunPlugin(bmOrig); } var bmd = bmOrig.LockBits(new Rectangle(0, 0, bmOrig.Width, bmOrig.Height), ImageLockMode.ReadWrite, bmOrig.PixelFormat); //this converts the image into a windows displayable image so do it regardless using (var lfu = new UnmanagedImage(bmd)) { if (_motionDetector != null) { bMotion = ApplyMotionDetector(lfu); } else { MotionDetected = false; } if (CW.Camobject.settings.FishEyeCorrect) { _feCorrect.Correct(lfu, CW.Camobject.settings.FishEyeFocalLengthPX, CW.Camobject.settings.FishEyeLimit, CW.Camobject.settings.FishEyeScale, ZPoint.X, ZPoint.Y); } if (ZFactor > 1) { var f1 = new ResizeNearestNeighbor(lfu.Width, lfu.Height); var f2 = new Crop(ViewRectangle); try { using (var imgTemp = f2.Apply(lfu)) { f1.Apply(imgTemp, lfu); } } catch (Exception ex) { ErrorHandler?.Invoke(ex.Message); } } } bmOrig.UnlockBits(bmd); PiP(bmOrig); AddTimestamp(bmOrig); } catch (UnsupportedImageFormatException ex) { CW.VideoSourceErrorState = true; CW.VideoSourceErrorMessage = ex.Message; bmOrig?.Dispose(); return; } catch (Exception ex) { bmOrig?.Dispose(); ErrorHandler?.Invoke(ex.Message); return; } if (MotionDetector != null && !CW.Calibrating && MotionDetector.MotionProcessingAlgorithm is BlobCountingObjectsProcessing && !CW.PTZNavigate && CW.Camobject.settings.ptzautotrack) { try { ProcessAutoTracking(); } catch (Exception ex) { ErrorHandler?.Invoke(ex.Message); } } } if (!_requestedToStop) { nf.Invoke(this, new NewFrameEventArgs(bmOrig)); } if (bMotion) { TriggerDetect(this); } }
public override void Draw(Graphics g) { base.Draw(g); PointF P = ToPointF(ControlPoints[0]); SizeF sf = g.MeasureString(Text, TextFont, 1000, format); RectangleF Rect = new RectangleF(P.X, P.Y, sf.Width + 4, sf.Height + 4); ArrayList al = new ArrayList(); al.Add(new PointF(Rect.Left, Rect.Top + RoundWidth)); al.Add(new PointF(Rect.Left + RoundWidth, Rect.Top)); al.Add(new PointF(Rect.Right - RoundWidth, Rect.Top)); al.Add(new PointF(Rect.Right, Rect.Top + RoundWidth)); al.Add(new PointF(Rect.Right, Rect.Bottom - RoundWidth)); al.Add(new PointF(Rect.Right - RoundWidth, Rect.Bottom)); al.Add(new PointF(Rect.Left + RoundWidth, Rect.Bottom)); al.Add(new PointF(Rect.Left, Rect.Bottom - RoundWidth)); al.Add(al[0]); if (StickHeight > 0) { float OffsetX = 0; float OffsetY = 0; int Index = 1; switch (StickAlignment) { case StickAlignment.LeftTop: OffsetX = StickHeight; OffsetY = StickHeight; break; case StickAlignment.LeftCenter: break; case StickAlignment.LeftBottom: OffsetX = StickHeight; OffsetY = -Rect.Height - StickHeight; Index = 7; break; case StickAlignment.CenterTop: break; case StickAlignment.CenterCenter: break; case StickAlignment.CenterBottom: break; case StickAlignment.RightTop: OffsetX = -Rect.Width - StickHeight; OffsetY = StickHeight; Index = 3; break; case StickAlignment.RightCenter: break; case StickAlignment.RightBottom: OffsetX = -Rect.Width - StickHeight; OffsetY = -Rect.Height - StickHeight; Index = 5; break; } al = OffsetPoint(al, OffsetX, OffsetY); al.Insert(Index, P); Rect.Offset(OffsetX, OffsetY); } PointF[] ps = (PointF[])al.ToArray(typeof(PointF)); if (ShadowWidth > 0) { PointF[] pss = (PointF[])ps.Clone(); OffsetPoint(pss, ShadowWidth, ShadowWidth); g.FillPolygon(new SolidBrush(Color.FromArgb(64, Color.Black)), pss); } if (BackBrush.Color != Color.Empty) { g.FillPolygon(BackBrush.GetBrush(GetMaxRect()), ps); } if (LinePen.Color != Color.Empty) { g.DrawLines(LinePen.GetPen(), ps); } TextRenderingHint trh = g.TextRenderingHint; g.TextRenderingHint = TextRenderingHint.AntiAlias; g.DrawString(Text, TextFont, TextBrush.GetBrush(), Rect, format); g.TextRenderingHint = trh; }