private void DrawString(string text, SimpleFont font, DXMediaBrush brush, double pointX, double pointY, DXMediaBrush areaBrush)
        {
            SharpDX.DirectWrite.TextFormat textFormat = font.ToDirectWriteTextFormat();
            SharpDX.DirectWrite.TextLayout textLayout =
                new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory,
                                                   text, textFormat, ChartPanel.X + ChartPanel.W,
                                                   textFormat.FontSize);

            float newW = textLayout.Metrics.Width;
            float newH = textLayout.Metrics.Height;

            SharpDX.Vector2 TextPlotPoint = new System.Windows.Point(pointX - newW, pointY - textLayout.Metrics.Height / 2 - 1).ToVector2();

            SharpDX.RectangleF PLBoundRect = new SharpDX.RectangleF((float)pointX - newW - 4, (float)pointY - textLayout.Metrics.Height / 2 - 1, newW + 6, newH + 2);

            SharpDX.Direct2D1.RoundedRectangle PLRoundedRect = new SharpDX.Direct2D1.RoundedRectangle();

            PLRoundedRect.RadiusX = newW / 4;
            PLRoundedRect.RadiusY = newH / 4;
            PLRoundedRect.Rect    = PLBoundRect;

            RenderTarget.FillRoundedRectangle(PLRoundedRect, areaBrush.DxBrush);

            RenderTarget.DrawTextLayout(TextPlotPoint, textLayout, brush.DxBrush, SharpDX.Direct2D1.DrawTextOptions.NoSnap);

            textLayout.Dispose();
            textLayout = null;
            textFormat.Dispose();
            textFormat = null;
        }
Beispiel #2
0
        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            base.OnRender(chartControl, chartScale);

            InitializeDrawingTools();

            //Calculate where to draw the text.
            //Refer to parent class Lines.cs OnRender method for more information.
            ChartPanel panel          = chartControl.ChartPanels[chartScale.PanelIndex];
            double     strokePixAdj   = ((double)(Stroke.Width % 2)).ApproxCompare(0) == 0 ? 0.5d : 0d;
            Vector     pixelAdjustVec = new Vector(strokePixAdj, strokePixAdj);

            Point endPoint         = EndAnchor.GetPoint(chartControl, panel, chartScale);
            Point endPointAdjusted = endPoint + pixelAdjustVec;

            SharpDX.Vector2 endVec = endPointAdjusted.ToVector2();

            //Calculate the current price.
            string text = (Text != "" ? Text : chartControl.Instrument.MasterInstrument.FormatPrice(chartScale.GetValueByY(endVec.Y), true));

            //Set properties for rectangle to draw the object.
            TextLayout tl = new TextLayout(Core.Globals.DirectWriteFactory, text, cachedTextFormat, ChartPanel.W, ChartPanel.H);

            SharpDX.RectangleF rect = new SharpDX.RectangleF();
            rect.X      = (float)endVec.X;
            rect.Y      = (float)endVec.Y - 6f;
            rect.Width  = (float)-(tl.Metrics.Width);
            rect.Height = (float)-(tl.Metrics.Height);

            //Draw the text.
            using (SharpDX.Direct2D1.Brush myDxBrush = TextColor.ToDxBrush(RenderTarget))
            {
                chartScale.GetValueByY(endVec.Y); RenderTarget.DrawText(string.Format("{0}", text), cachedTextFormat, rect, myDxBrush);
            }
        }
Beispiel #3
0
        // MH:  5-25 Disabled for now, can add option
        // ReSharper disable once UnusedMember.Local
        private void RenderPriceZones(ChartControl chartControl, ChartScale chartScale)
        {
            // add 10 bars of padding so that the drawn region extends past the visual area of the chart
            // but handle possible out of range exception by checking to see we even have enough bars for the padding to begin with
            int startX = chartControl.GetXByBarIndex(ChartBars,
                                                     ChartBars.FromIndex >= 10 ? ChartBars.FromIndex - 10 : ChartBars.FromIndex);
            int sessionBeginX = chartControl.GetXByTime(sessionIterator.ActualSessionBegin);

            if (startX > sessionBeginX)
            {
                return;
            }
            float highPriceY        = chartScale.GetYByValue(trueRangeHigh);
            float highLowDifference = chartScale.GetYByValue(trueRangeLow) - chartScale.GetYByValue(trueRangeHigh);

            SharpDX.RectangleF midZone = new SharpDX.RectangleF(sessionBeginX, highPriceY, startX - sessionBeginX,
                                                                highLowDifference);
            SharpDX.RectangleF lowZone = new SharpDX.RectangleF(sessionBeginX, highPriceY + midZone.Height,
                                                                startX - sessionBeginX, highLowDifference);
            SharpDX.RectangleF highZone = new SharpDX.RectangleF(sessionBeginX, highPriceY - midZone.Height,
                                                                 startX - sessionBeginX, highLowDifference);
            RenderTarget.FillRectangle(lowZone, redBrush.ToDxBrush(RenderTarget));
            RenderTarget.FillRectangle(highZone, greenBrush.ToDxBrush(RenderTarget));
            RenderTarget.FillRectangle(midZone, blueBrush.ToDxBrush(RenderTarget));
        }
        private void drawRow(ChartControl chartControl, ChartScale chartScale, double value, int quantity)
        {
            //Calculate color of this row.
            Brush brushColor = NormalColor;

            if (value <= MaxId + ValueArea && value >= MaxId - ValueArea)
            {
                brushColor = ValueColor;
            }


            //Calculate cell properties
            double y1 = ((chartScale.GetYByValue(value) + chartScale.GetYByValue(value + 1)) / 2) + 1;
            double y2 = ((chartScale.GetYByValue(value) + chartScale.GetYByValue(value - 1)) / 2) - 1;

            SharpDX.RectangleF rect = new SharpDX.RectangleF();
            rect.X      = (float)chartControl.CanvasRight;
            rect.Y      = (float)y1;
            rect.Width  = (float)((chartControl.CanvasLeft - chartControl.CanvasRight) * Math.Log(quantity) / Math.Log(Max));
            rect.Height = (float)Math.Abs(y1 - y2);

            //Draw the row.
            using (SharpDX.Direct2D1.Brush rowBrush = brushColor.ToDxBrush(RenderTarget))
            {
                RenderTarget.FillRectangle(rect, rowBrush);
                //RenderTarget.FillRectangle(rect, rowBrush);
            }

            if (rect.Height > this.MinimumTextHeight)
            {
                RenderTarget.DrawText(string.Format("{0}", quantity), textFormat, rect, TextColor.ToDxBrush(RenderTarget));
            }
        }
Beispiel #5
0
 private void RenderVolumeZones(ChartControl chartControl, ChartScale chartScale)
 {
     foreach (KeyValuePair <double, double> level in VolumeDictionary)
     {
         double price  = level.Key;
         int    volume = (int)level.Value;
         if (price > chartScale.MaxValue + TickSize || price < chartScale.MinValue - (TickSize * 1))
         {
             continue;
         }
         int priceLower = chartScale.GetYByValue(price);
         int priceUpper = chartScale.GetYByValue(price + TickSize);
         int barHeight  = Math.Max(1, Math.Abs(priceUpper - priceLower) - 1);
         maxVolume = Math.Max(volume, maxVolume);
         if (maxVolume < 1)                 // don't divide by zero
         {
             continue;
         }
         int maxWidth            = ((int)maxVolume / 300);
         int barWidth            = volume / maxWidth;
         int barX                = (chartControl.CanvasRight - barWidth);
         int barY                = (priceLower - barHeight);
         SharpDX.RectangleF rect = new SharpDX.RectangleF(barX, barY, barWidth, barHeight);
         RenderTarget.FillRectangle(rect, VolumeZoneBrush(price).ToDxBrush(RenderTarget));
     }
 }
Beispiel #6
0
        /// <summary>
        /// Draw the layer.
        /// </summary>
        /// <param name="renderTime">Time since last render.</param>
        /// <remarks>include base.Render(renderTime); in overloads to preserve updating RenderTime field.</remarks>
        public override void Render(RenderTime renderTime)
        {
            base.Render(renderTime);
            if (MM_Repository.OverallDisplay.MapTiles == MM_MapTile.enumMapType.None)
            {
                return;
            }

            var tx = Surface.RenderTarget2D.Transform;

            Surface.RenderTarget2D.Transform = SharpDX.Matrix3x2.Identity;
            BaseMapTileProxy backgroundTile;
            Point            topLeftTile      = MM_Coordinates.XYToTile(Surface.Coordinates.TopLeftXY);
            Point            bottomRightTile  = MM_Coordinates.XYToTile(Surface.Coordinates.BottomRightXY);
            Point            topLeftTileShift = new Point(Surface.Coordinates.TopLeftXY.X % MM_Repository.OverallDisplay.MapTileSize.Width, Surface.Coordinates.TopLeftXY.Y % MM_Repository.OverallDisplay.MapTileSize.Height);
            int extraRadius = 4;

            SharpDX.RectangleF tileSourceRect = new SharpDX.RectangleF(0, 0, MM_Repository.OverallDisplay.MapTileSize.Width, MM_Repository.OverallDisplay.MapTileSize.Height);

            if (MM_Repository.OverallDisplay.MapTiles != MM_MapTile.enumMapType.None)
            {
                int startX = topLeftTile.X - extraRadius;
                int endX   = bottomRightTile.X + extraRadius;
                int startY = topLeftTile.Y - extraRadius;
                int endY   = bottomRightTile.Y + extraRadius;


                foreach (var thisTile in Spiral(topLeftTile, bottomRightTile, extraRadius))
                {
                    TileCoordinates tileCoord = new TileCoordinates(MM_Repository.OverallDisplay.MapTiles, thisTile, (int)Surface.Coordinates.ZoomLevel);
                    if (TryGetTile(tileCoord, out backgroundTile))
                    {
                        if (!backgroundTile.IsReady)
                        {
                            continue;
                        }

                        var targetRect = new SharpDX.RectangleF(((thisTile.X - topLeftTile.X) * MM_Repository.OverallDisplay.MapTileSize.Width) - topLeftTileShift.X, ((thisTile.Y - topLeftTile.Y) * MM_Repository.OverallDisplay.MapTileSize.Height) - topLeftTileShift.Y, MM_Repository.OverallDisplay.MapTileSize.Width, MM_Repository.OverallDisplay.MapTileSize.Height);
                        Surface.RenderTarget2D.DrawBitmap(backgroundTile.Bitmap, targetRect, MM_Repository.OverallDisplay.MapTransparency, BitmapInterpolationMode.NearestNeighbor, tileSourceRect);
                    }
                }

                //for (Point thisTile = new Point(topLeftTile.X - extraRadius, topLeftTile.Y - extraRadius); thisTile.X <= bottomRightTile.X + extraRadius; thisTile.X++, thisTile.Y = topLeftTile.Y)
                //{
                //    for (; thisTile.Y <= bottomRightTile.Y + extraRadius; thisTile.Y++)
                //    {
                //        TileCoordinates tileCoord = new TileCoordinates(MM_Repository.OverallDisplay.MapTiles, thisTile, (int)Surface.Coordinates.ZoomLevel);
                //        if (TryGetTile(tileCoord, out backgroundTile))
                //        {
                //            if (!backgroundTile.IsReady) continue;
                //
                //            var targetRect = new SharpDX.RectangleF(((thisTile.X - topLeftTile.X) * MM_Repository.OverallDisplay.MapTileSize.Width) - topLeftTileShift.X, ((thisTile.Y - topLeftTile.Y) * MM_Repository.OverallDisplay.MapTileSize.Height) - topLeftTileShift.Y, MM_Repository.OverallDisplay.MapTileSize.Width, MM_Repository.OverallDisplay.MapTileSize.Height);
                //            Surface.RenderTarget2D.DrawBitmap(backgroundTile.Bitmap, targetRect, MM_Repository.OverallDisplay.MapTransparency, BitmapInterpolationMode.NearestNeighbor, tileSourceRect);
                //        }
                //    }
                //}
            }

            Surface.RenderTarget2D.Transform = tx;
        }
        static void SHDXOverlay_BeforeDrawingEvent(object sender, ExternalUtilsCSharp.UI.Overlay <SharpDXRenderer, SharpDX.Color, SharpDX.Vector2, TextFormat> .OverlayEventArgs e)
        {
            if (ranksBmp == null)
            {
                System.Drawing.Bitmap bmp = (System.Drawing.Bitmap)Resources.ResourceManager.GetObject("uc_exclusive");
                try
                {
                    ranksBmp = SDXBitmapFromSysBitmap(e.Overlay.Renderer.Device, bmp);
                }
                catch { }
            }
            else
            {
                SharpDX.RectangleF source = new SharpDX.RectangleF(0, 0, ranksBmp.PixelSize.Width, ranksBmp.PixelSize.Height);

                float mul = 1f + 0.2f * (float)Math.Sin(DateTime.Now.TimeOfDay.TotalSeconds * 0.5f);
                SharpDX.RectangleF dest = new SharpDX.RectangleF(e.Overlay.Width / 2f - source.Width / 2f * mul, e.Overlay.Height - source.Height * 2f * mul, source.Width * mul, source.Height * mul);

                e.Overlay.Renderer.Device.DrawBitmap(ranksBmp, dest, 0.9f, BitmapInterpolationMode.Linear, source);
            }

            if (ConfigUtils.GetValue <bool>("aimEnabled") && ConfigUtils.GetValue <bool>("aimDrawFov"))
            {
                float fov = ConfigUtils.GetValue <float>("aimFov");

                SharpDX.Color   foreColor = new SharpDX.Color(0.2f, 0.2f, 0.2f, 0.8f);
                SharpDX.Color   backColor = new SharpDX.Color(0.8f, 0.8f, 0.8f, 0.9f);
                SharpDX.Vector2 size      = new SharpDX.Vector2(e.Overlay.Width / 90f * fov);
                SharpDX.Vector2 center    = new SharpDX.Vector2(e.Overlay.Width / 2f, e.Overlay.Height / 2f);

                e.Overlay.Renderer.DrawEllipse(foreColor, center, size, true, 3f);
                e.Overlay.Renderer.DrawEllipse(backColor, center, size, true);
            }
        }
 public override SharpDX.RectangleF getRenderBounds()
 {
     if (shouldBoundsUpdate)
     {
         shouldBoundsUpdate = false;
         float maxY = Single.MinValue;
         float maxX = Single.MinValue;
         float minY = Single.MaxValue;
         float minX = Single.MaxValue;
         for (int i = 0; i < children.Count; i++)
         {
             SharpDX.RectangleF bounds = children[i].getRenderBounds();
             if (maxY < bounds.Bottom)
             {
                 maxY = bounds.Bottom;
             }
             if (minY > bounds.Top)
             {
                 minY = bounds.Top;
             }
             if (maxX < bounds.Right)
             {
                 maxX = bounds.Right;
             }
             if (minX > bounds.Left)
             {
                 minX = bounds.Left;
             }
         }
         _width      = maxX - minX;
         _height     = maxY - minY;
         boundsCache = new SharpDX.RectangleF(minX, minY, maxX, maxY);
     }
     return(boundsCache);
 }
Beispiel #9
0
        private void DrawText(ChartControl chartControl)
        {
            if (Font == null || string.IsNullOrEmpty(DisplayText))
            {
                return;
            }

            Rect outLineRect = GetCurrentRect(layoutRect, outlinePadding);                                                    // this will add padding to layoutRect for us

            SharpDX.RectangleF outlineRectDx = new SharpDX.RectangleF((float)outLineRect.X, (float)outLineRect.Y, (float)outLineRect.Width, (float)outLineRect.Height);

            textBrushDevice.RenderTarget = RenderTarget;
            areaBrushDevice.RenderTarget = RenderTarget;
            OutlineStroke.RenderTarget   = RenderTarget;

            SharpDX.Direct2D1.Brush tmpBrush;
            if (AreaBrush != null)
            {
                SolidColorBrush tmpOb = areaBrushDevice.Brush as SolidColorBrush;
                SolidColorBrush tmpNb = AreaBrush                     as SolidColorBrush;
                // if brush not set, set brush. else if brush set and changed, change brush. if not SolidColorBrush always change brush
                if (tmpNb == null || tmpOb == null || tmpOb.Color != tmpNb.Color || Math.Abs(tmpOb.Opacity - tmpNb.Opacity) > 0.1)
                {
                    Brush brushCopy = AreaBrush.Clone();
                    brushCopy.Opacity     = areaOpacity / 100d;
                    areaBrushDevice.Brush = brushCopy;
                }
                areaBrushDevice.RenderTarget = RenderTarget;
                tmpBrush = IsInHitTest ? chartControl.SelectionBrush : areaBrushDevice.BrushDX;
                RenderTarget.FillRectangle(outlineRectDx, tmpBrush);
            }
            else
            {
                areaBrushDevice.RenderTarget = null;
            }

            if (OutlineStroke.StrokeStyle != null && (OutlineStroke.Brush != null || !OutlineStroke.Brush.IsTransparent()))
            {
                tmpBrush = IsInHitTest ? chartControl.SelectionBrush : OutlineStroke.BrushDX;
                if (tmpBrush != null)
                {
                    RenderTarget.DrawRectangle(outlineRectDx, tmpBrush, OutlineStroke.Width, OutlineStroke.StrokeStyle);
                }
            }

            textBrushDevice.RenderTarget = RenderTarget;

            SolidColorBrush tmpOtb = textBrushDevice.Brush  as SolidColorBrush;
            SolidColorBrush tmpNtb = TextBrush                              as SolidColorBrush;

            // if brush not set, set brush. else if brush set and changed, change brush. if not SolidColorBrush always change brush
            if (tmpNtb == null || tmpOtb == null || tmpOtb.Color != tmpNtb.Color || Math.Abs(tmpOtb.Opacity - tmpNtb.Opacity) > 0.1)
            {
                textBrushDevice.Brush = TextBrush;
            }
            // when drawing the actual text layout, add padding again, we dont want text right on the edges of our outline rect
            tmpBrush = IsInHitTest ? chartControl.SelectionBrush : textBrushDevice.BrushDX;
            RenderTarget.DrawTextLayout(new SharpDX.Vector2(outlineRectDx.X + outlinePadding, outlineRectDx.Y + outlinePadding),
                                        cachedTextLayout, tmpBrush, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
        }
Beispiel #10
0
        private bool CheckAdvansedFilter(int currentTab, RectangleF position, Entity itemClass)
        {
            foreach (var item in _filterItems)
            {
                if (!itemClass.Path.Contains(item.Type))
                {
                    continue;
                }
                var modsComponent = itemClass.GetComponent <Mods>();
                if (item.ItemRarity < 4 && modsComponent != null && modsComponent.ItemRarity != (ItemRarity)item.ItemRarity)
                {
                    return(false);
                }
                if (item.Tab != currentTab)
                {
                    return(true);
                }
                if (!CheckIngoredCell(position))
                {
                    continue;
                }
                position.X += GameController.Window.GetWindowRectangle().X;
                position.Y += GameController.Window.GetWindowRectangle().Y;
                MouseClickCtrl(position.Center);
                return(true);
            }

            return(false);
        }
Beispiel #11
0
        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            LineColor.RenderTarget = RenderTarget;

            // first of all, turn on anti-aliasing to smooth out our line
            RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;

            ChartPanel panel = chartControl.ChartPanels[chartScale.PanelIndex];

            // draw a line from start measure point to end measure point.
            Point lineStartPoint = StartAnchor.GetPoint(chartControl, panel, chartScale);
            Point lineEndPoint   = EndAnchor.GetPoint(chartControl, panel, chartScale);

            // align to full pixel to avoid unneeded aliasing
            double strokePixAdjust    = (LineColor.Width % 2).ApproxCompare(0) == 0 ? 0.5d : 0d;
            Vector strokePixAdjustVec = new Vector(strokePixAdjust, strokePixAdjust);

            SharpDX.Vector2         endVec   = (lineEndPoint + strokePixAdjustVec).ToVector2();
            SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : LineColor.BrushDX;
            RenderTarget.DrawLine((lineStartPoint + strokePixAdjustVec).ToVector2(), endVec, tmpBrush, LineColor.Width, LineColor.StrokeStyle);

            if (ShouldDrawText)
            {
                UpdateTextLayout(chartControl, ChartPanel, chartScale);
                textDeviceBrush.RenderTarget = RenderTarget;
                // Text rec uses same settings as mini data box
                textBackgroundDeviceBrush.Brush        = Application.Current.FindResource("ChartControl.DataBoxBackground") as Brush;
                textBackgroundDeviceBrush.RenderTarget = RenderTarget;

                Brush  borderBrush       = Application.Current.FindResource("BorderThinBrush") as Brush;
                object thicknessResource = Application.Current.FindResource("BorderThinThickness");
                double thickness         = thicknessResource as double? ?? 1;
                Stroke textBorderStroke  = new Stroke(borderBrush ?? LineColor.Brush, DashStyleHelper.Solid, Convert.ToSingle(thickness))
                {
                    RenderTarget = RenderTarget
                };

                Point           textEndPoint = TextAnchor.GetPoint(chartControl, panel, chartScale);
                SharpDX.Vector2 textEndVec   = (textEndPoint + strokePixAdjustVec).ToVector2();

                RenderTarget.DrawLine(endVec, textEndVec, LineColor.BrushDX, LineColor.Width, LineColor.StrokeStyle);

                float rectPixAdjust     = (float)(strokePixAdjust / 2f);
                SharpDX.RectangleF rect = new SharpDX.RectangleF((float)(textEndPoint.X - textLayout.MaxWidth - textMargin + rectPixAdjust),
                                                                 (float)(textEndPoint.Y - textLayout.MaxHeight - textMargin + rectPixAdjust),
                                                                 textLayout.MaxWidth + textMargin * 2f, textLayout.MaxHeight + textMargin);

                if (textBackgroundDeviceBrush.BrushDX != null && !IsInHitTest)
                {
                    RenderTarget.FillRectangle(rect, textBackgroundDeviceBrush.BrushDX);
                }
                RenderTarget.DrawRectangle(rect, textBorderStroke.BrushDX, textBorderStroke.Width, textBorderStroke.StrokeStyle);

                if (textDeviceBrush.BrushDX != null && !IsInHitTest)
                {
                    RenderTarget.DrawTextLayout(new SharpDX.Vector2((float)(rect.X + textMargin + strokePixAdjust), (float)(rect.Y + textMargin + strokePixAdjust)), textLayout, textDeviceBrush.BrushDX);
                }
            }
        }
Beispiel #12
0
        protected GraphicsPath CalculateTransformedPath(GraphicsPath path, SharpDX.RectangleF baseRect)
        {
            GraphicsPath result = path;

            using (Matrix m = new Matrix())
            {
                RectangleF bounds = result.GetBounds();
                _fillDisabled = bounds.Width < StrokeThickness || bounds.Height < StrokeThickness;
                if (Width > 0)
                {
                    baseRect.Width = (float)Width;
                }
                if (Height > 0)
                {
                    baseRect.Height = (float)Height;
                }
                float scaleW;
                float scaleH;
                if (Stretch == Stretch.Fill)
                {
                    scaleW = baseRect.Width / bounds.Width;
                    scaleH = baseRect.Height / bounds.Height;
                    m.Translate(-bounds.X, -bounds.Y, MatrixOrder.Append);
                }
                else if (Stretch == Stretch.Uniform)
                {
                    scaleW = Math.Min(baseRect.Width / bounds.Width, baseRect.Height / bounds.Height);
                    scaleH = scaleW;
                    m.Translate(-bounds.X, -bounds.Y, MatrixOrder.Append);
                }
                else if (Stretch == Stretch.UniformToFill)
                {
                    scaleW = Math.Max(baseRect.Width / bounds.Width, baseRect.Height / bounds.Height);
                    scaleH = scaleW;
                    m.Translate(-bounds.X, -bounds.Y, MatrixOrder.Append);
                }
                else
                {
                    // Stretch == Stretch.None
                    scaleW = 1;
                    scaleH = 1;
                }
                // In case bounds.Width or bounds.Height or baseRect.Width or baseRect.Height were 0
                if (scaleW == 0 || float.IsNaN(scaleW) || float.IsInfinity(scaleW))
                {
                    scaleW = 1;
                }
                if (scaleH == 0 || float.IsNaN(scaleH) || float.IsInfinity(scaleH))
                {
                    scaleH = 1;
                }
                m.Scale(scaleW, scaleH, MatrixOrder.Append);

                m.Translate(baseRect.X, baseRect.Y, MatrixOrder.Append);
                result.Transform(m);
                result.Flatten();
            }
            return(result);
        }
Beispiel #13
0
 public bool Intersects(SharpDX.RectangleF rect)
 {
     var testRect = new SharpDX.RectangleF(Owner.Transform.Translation.X - OriginX, Owner.Transform.Translation.Y - OriginY, BaseWidth, BaseHeight);
     bool contains = false;
     rect.Contains(ref testRect, out contains);
     bool intersects = rect.Intersects(testRect);
     return contains || intersects;
 }
Beispiel #14
0
        public bool Intersects(SharpDX.RectangleF rect)
        {
            var  testRect = new SharpDX.RectangleF(Owner.Transform.Translation.X - OriginX, Owner.Transform.Translation.Y - OriginY, BaseWidth, BaseHeight);
            bool contains = false;

            rect.Contains(ref testRect, out contains);
            bool intersects = rect.Intersects(testRect);

            return(contains || intersects);
        }
        public RectangleF DrawBoxOnMap(SharpDX.Vector2 screenPos, float size, Color color)
        {
            var sizeScaled = size * _scale;
            var rectangleF = new RectangleF(screenPos.X - sizeScaled / 2, screenPos.Y - sizeScaled / 2, sizeScaled, sizeScaled);

            _graphics.DrawBox(
                rectangleF,
                color);
            return(rectangleF);
        }
Beispiel #16
0
        /// <summary>
        ///     Draws a plugin image to screen.
        /// </summary>
        /// <param name="rec"></param>
        /// <param name="fileName">The full path including file, fx. C:\\image\\Carl.png</param>
        /// <returns></returns>
        private bool DrawImage(string fileName, RectangleF rec)
        {
            try
            {
                //Graphics.DrawPluginImage(fileName, rec);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
        private float DrawItemBar(ISnoItem[] itemsToDisplay, float barY)
        {
            var uiInv = Hud.Inventory.InventoryMainUiElement;

            var rect = new SharpDX.RectangleF(uiInv.Rectangle.Left - 1, barY, uiInv.Rectangle.Width + 2, _materialBackgroundImage.Height * uiInv.Rectangle.Width / _materialBackgroundImage.Width);

            _materialBackgroundImage.Draw(rect.X, rect.Y, rect.Width, rect.Height);

            var itemCountList = new int[itemsToDisplay.Length];

            foreach (var item in Hud.Inventory.GetItemsInStash())
            {
                for (int j = 0; j < itemsToDisplay.Length; j++)
                {
                    if (item.SnoItem == itemsToDisplay[j])
                    {
                        itemCountList[j] += (int)item.Quantity;
                    }
                }
            }

            foreach (var item in Hud.Inventory.GetItemsInInventory())
            {
                for (int j = 0; j < itemsToDisplay.Length; j++)
                {
                    if (item.SnoItem == itemsToDisplay[j])
                    {
                        itemCountList[j] += (int)item.Quantity;
                    }
                }
            }

            var w = rect.Width / (itemsToDisplay.Length + 1);
            var h = rect.Height * 0.85f;
            var y = rect.Top + (rect.Height - h) / 2;

            for (int i = 0; i < itemsToDisplay.Length; i++)
            {
                var snoItem = itemsToDisplay[i];
                var texture = Hud.Texture.GetItemTexture(snoItem);
                if (texture != null)
                {
                    var x = w / 2 + rect.Left + i * w;
                    texture.Draw(x + w - h, y, h, h, 1);
                    var layout = MaterialCountFont.GetTextLayout(ValueToString(itemCountList[i], ValueFormat.NormalNumberNoDecimal));
                    MaterialCountFont.DrawText(layout, x + w - h * 1.2f - layout.Metrics.Width, y + (h - layout.Metrics.Height) / 2);
                }
            }

            return(rect.Height);
        }
Beispiel #18
0
        private bool CheckIngoredCell(RectangleF position)
        {
            var   invPoint = _inventoryZone;
            float wCell    = invPoint.Width / 12;
            float hCell    = invPoint.Height / 5;
            int   x        = (int)((1f + position.X - invPoint.X) / wCell);
            int   y        = (int)((1f + position.Y - invPoint.Y) / hCell);

            if (x < 0 || y < 0 || x > 13 || y > 6)
            {
                return(false);
            }
            return(_invArr[y, x] == 0);
        }
        public bool isButtonPressed(SharpDX.RectangleF buttonRect)
        {
            if (Control.MouseButtons == MouseButtons.Left)
            {
                var prevMousePos = Mouse.GetCursorPosition();

                if (buttonRect.Contains(Mouse.GetCursorPosition() - windowOffset))
                {
                    return(true);
                }

                Mouse.moveMouse(prevMousePos);
            }

            return(false);
        }
Beispiel #20
0
        private void DrawString(string text, SimpleFont font, string brushName, double pointX, double pointY, string areaBrushName)
        {
            SharpDX.DirectWrite.TextFormat textFormat = font.ToDirectWriteTextFormat();
            SharpDX.Vector2 TextPlotPoint             = new System.Windows.Point(pointX, pointY).ToVector2();
            SharpDX.DirectWrite.TextLayout textLayout =
                new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory,
                                                   text, textFormat, ChartPanel.X + ChartPanel.W,
                                                   textFormat.FontSize);

            float newW = textLayout.Metrics.Width;
            float newH = textLayout.Metrics.Height;

            SharpDX.RectangleF PLBoundRect = new SharpDX.RectangleF((float)pointX + 2, (float)pointY, newW + 5, newH + 2);
            RenderTarget.FillRectangle(PLBoundRect, dxmBrushes[areaBrushName].DxBrush);

            RenderTarget.DrawTextLayout(TextPlotPoint, textLayout, dxmBrushes[brushName].DxBrush, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
            textLayout.Dispose();
            textFormat.Dispose();
        }
Beispiel #21
0
        private RectSide LineIntersectsRect(Point p1, Point p2, SharpDX.RectangleF r)
        {
            if (LineIntersectsLine(p1, p2, new Point(r.X, r.Y), new Point(r.X + r.Width, r.Y)) && p1.Y > r.Y)
            {
                return(RectSide.Top);
            }
            if (LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y), new Point(r.X + r.Width, r.Y + r.Height)) && p1.X < r.X + r.Width)
            {
                return(RectSide.Right);
            }
            if (LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y + r.Height), new Point(r.X, r.Y + r.Height)) && p1.Y < r.Y + r.Height)
            {
                return(RectSide.Bottom);
            }
            if (LineIntersectsLine(p1, p2, new Point(r.X, r.Y + r.Height), new Point(r.X, r.Y)))
            {
                return(RectSide.Left);
            }

            return(RectSide.None);
        }
Beispiel #22
0
        private float DrawItemBar(ISnoItem[] itemsToDisplay, float barY)
        {
            var uiInv = Hud.Inventory.InventoryMainUiElement;

            var rect = new SharpDX.RectangleF(uiInv.Rectangle.Left - 1, barY, uiInv.Rectangle.Width + 2, _materialBackgroundImage.Height * uiInv.Rectangle.Width / _materialBackgroundImage.Width);

            _materialBackgroundImage.Draw(rect.X, rect.Y, rect.Width, rect.Height);

            var itemCountList = new long[itemsToDisplay.Length];

            for (int j = 0; j < itemsToDisplay.Length; j++)
            {
                itemCountList[j] = GetItemCount(itemsToDisplay[j]);
            }

            var w = rect.Width / (itemsToDisplay.Length + 1);
            var h = rect.Height * 0.85f;
            var y = rect.Top + (rect.Height - h) / 2;

            for (int i = 0; i < itemsToDisplay.Length; i++)
            {
                var snoItem = itemsToDisplay[i];
                var texture = Hud.Texture.GetItemTexture(snoItem);
                if (texture != null)
                {
                    var x = w / 2 + rect.Left + i * w;
                    texture.Draw(x + w - h, y, h, h, 1);
                    var layout = MaterialCountFont.GetTextLayout(ValueToString(itemCountList[i], ValueFormat.NormalNumberNoDecimal));
                    MaterialCountFont.DrawText(layout, x + w - h * 1.2f - layout.Metrics.Width, y + (h - layout.Metrics.Height) / 2);

                    if (Hud.Window.CursorInsideRect(x + w - h * 1.2f - layout.Metrics.Width, y, h * 1.2f + layout.Metrics.Width, h))
                    {
                        Hud.Render.SetHint(snoItem.NameLocalized);
                    }
                }
            }

            return(rect.Height);
        }
        public void Draw(RectangleF windowDrawFrame)
        {
            var bmSizeWidth  = _bmSize.Width;
            var bmSizeHeight = _bmSize.Height;

            var scaleX = windowDrawFrame.Width / bmSizeWidth;
            var scaleY = windowDrawFrame.Height / bmSizeHeight;

            _scale = Math.Min(scaleX, scaleY);

            var width  = bmSizeWidth * _scale;
            var height = bmSizeHeight * _scale;

            _imageDrawFrame = new RectangleF(windowDrawFrame.X, windowDrawFrame.Y, width, height);

            const int lines = 42;
            var       stepY = _imageDrawFrame.Height / lines;

            for (var i = 1; i < lines; i++)
            {
                var drawPosY = _imageDrawFrame.Y + i * stepY;
                _graphics.DrawLine(new Vector2(_imageDrawFrame.X, drawPosY),
                                   new Vector2(_imageDrawFrame.Right, drawPosY), 1, Color.Gray);
            }


            var stepX = _imageDrawFrame.Width / lines;

            for (var i = 1; i < lines; i++)
            {
                var drawPosX = _imageDrawFrame.X + i * stepX;
                _graphics.DrawLine(new Vector2(drawPosX, _imageDrawFrame.Y),
                                   new Vector2(drawPosX, _imageDrawFrame.Bottom), 1, Color.Gray);
            }

            _graphics.DrawImage(Path.GetFileName(_bgImg), _imageDrawFrame, Color.White);
        }
Beispiel #24
0
        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            for (int index = ChartBars.FromIndex; index <= ChartBars.ToIndex; index++)
            {
                // gets the pixel coordinate of the bar index passed to the method - X axis
                float xStart = chartControl.GetXByBarIndex(ChartBars, index);

                // gets the pixel coordinate of the price value passed to the method - Y axis
                float yStart = chartScale.GetYByValue(High.GetValueAt(index) + 2 * TickSize);

                float width = (float)chartControl.BarWidth * 4;


                // construct the rectangleF struct to describe the position and size the drawing
                SharpDX.RectangleF rect = new SharpDX.RectangleF(xStart, yStart, width, width);

                //				// define the brush used in the rectangle
                SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Blue);

                SharpDX.Direct2D1.SolidColorBrush outlineBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Black);


                // The RenderTarget consists of two commands related to Rectangles.
                // The FillRectangle() method is used to "Paint" the area of a Rectangle
                // execute the render target fill rectangle with desired values
                RenderTarget.FillRectangle(rect, customDXBrush);

                // and DrawRectangle() is used to "Paint" the outline of a Rectangle
                RenderTarget.DrawRectangle(rect, outlineBrush, 2);                 //Added WH 6/5/2017

                // always dispose of a brush when finished
                customDXBrush.Dispose();
                outlineBrush.Dispose();
            }

            base.OnRender(chartControl, chartScale);
        }
Beispiel #25
0
        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            if (IsInHitTest)
            {
                return;
            }

            int    lastBar   = ChartBars.ToIndex;
            int    firstBar  = ChartBars.FromIndex;
            double highPrice = 0;
            double lowPrice  = double.MaxValue;

            SharpDX.Direct2D1.Brush brushDown = BarDownBrush.ToDxBrush(RenderTarget);
            SharpDX.Direct2D1.Brush lineBrush = LineBrush.ToDxBrush(RenderTarget);
            SharpDX.Direct2D1.Brush brushUp   = BarUpBrush.ToDxBrush(RenderTarget);
            brushDown.Opacity = (float)(Opacity / 100.0);
            brushUp.Opacity   = (float)(Opacity / 100.0);

            for (int idx = firstBar; idx <= lastBar && idx >= 0; idx++)
            {
                highPrice = Math.Max(highPrice, Bars.GetHigh(idx));
                lowPrice  = Math.Min(lowPrice, Bars.GetLow(idx));
            }

            int    volumeBarCount = BarCount;
            double priceRange     = highPrice - lowPrice;
            double priceBoxSize   = priceRange / volumeBarCount;
            double volumeMax      = 0;

            // Pass 1: Fill all VolumeInfo structures with appropriate data
            for (int i = 0; i < volumeBarCount; i++)
            {
                double priceUpper = lowPrice + priceBoxSize * (i + 1);
                double priceLower = lowPrice + priceBoxSize * i;

                double priceVolumeUp   = 0;
                double priceVolumeDown = 0;

                for (int idx = firstBar; idx <= lastBar; idx++)
                {
                    double checkPrice;

                    PriceSeries series = (Inputs[0] as PriceSeries);

                    switch (series.PriceType)
                    {
                    case PriceType.Open:            checkPrice = Bars.GetOpen(idx); break;

                    case PriceType.Close:           checkPrice = Bars.GetClose(idx); break;

                    case PriceType.High:            checkPrice = Bars.GetHigh(idx); break;

                    case PriceType.Low:                     checkPrice = Bars.GetLow(idx); break;

                    case PriceType.Median:          checkPrice = (Bars.GetHigh(idx) + Bars.GetLow(idx)) / 2; break;

                    case PriceType.Typical:         checkPrice = (Bars.GetHigh(idx) + Bars.GetLow(idx) + Bars.GetClose(idx)) / 3; break;

                    case PriceType.Weighted:        checkPrice = (Bars.GetHigh(idx) + Bars.GetLow(idx) + 2 * Bars.GetClose(idx)) / 4; break;

                    default:                                        checkPrice = Bars.GetClose(idx); break;
                    }

                    if (checkPrice >= priceLower && checkPrice < priceUpper)
                    {
                        if (Bars.GetOpen(idx) < Bars.GetClose(idx))
                        {
                            priceVolumeUp += Bars.GetVolume(idx);
                        }
                        else
                        {
                            priceVolumeDown += Bars.GetVolume(idx);
                        }
                    }
                }

                volumeInfo[i].up    = priceVolumeUp;
                volumeInfo[i].down  = priceVolumeDown;
                volumeInfo[i].total = priceVolumeUp + priceVolumeDown;

                volumeMax = Math.Max(volumeMax, volumeInfo[i].total);
            }

            // Pass 2: Paint the volume bars
            for (int i = 0; i < Math.Min(volumeBarCount, lastBar - firstBar + 1); i++)
            {
                double priceUpper   = lowPrice + priceBoxSize * (i + 1);
                double priceLower   = lowPrice + priceBoxSize * i;
                int    yUpper       = Convert.ToInt32(chartScale.GetYByValue(priceUpper)) + BarSpacing;
                int    yLower       = Convert.ToInt32(chartScale.GetYByValue(priceLower));
                int    barWidthUp   = (int)((chartScale.Height / 2) * (volumeInfo[i].up / volumeMax));
                int    barWidthDown = (int)((chartScale.Height / 2) * (volumeInfo[i].down / volumeMax));

                SharpDX.RectangleF rect = new SharpDX.RectangleF(ChartPanel.X, yUpper, barWidthUp, Math.Abs(yUpper - yLower));
                RenderTarget.FillRectangle(rect, brushUp);
                RenderTarget.DrawRectangle(rect, brushUp);

                SharpDX.RectangleF rect2 = new SharpDX.RectangleF(ChartPanel.X + barWidthUp, yUpper, barWidthDown, Math.Abs(yUpper - yLower));
                RenderTarget.DrawRectangle(rect2, brushDown);
                RenderTarget.FillRectangle(rect2, brushDown);

                if (DrawLines)
                {
                    RenderTarget.DrawLine(new SharpDX.Vector2(ChartPanel.X, yLower), new SharpDX.Vector2(ChartPanel.X + ChartPanel.W, yLower), lineBrush);
                    if (i == volumeBarCount - 1)
                    {
                        RenderTarget.DrawLine(new SharpDX.Vector2(ChartPanel.X, yUpper), new SharpDX.Vector2(ChartPanel.X + ChartPanel.W, yUpper), lineBrush);
                    }
                }
            }

            lineBrush.Dispose();
            brushDown.Dispose();
            brushUp.Dispose();
        }
        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            //Allow user to change ZOrder when manually drawn on chart
            if (!hasSetZOrder && !StartAnchor.IsNinjaScriptDrawn)
            {
                ZOrderType   = DrawingToolZOrder.Normal;
                ZOrder       = ChartPanel.ChartObjects.Min(z => z.ZOrder) - 1;
                hasSetZOrder = true;
            }
            RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;
            OutlineStroke.RenderTarget = RenderTarget;
            ChartPanel chartPanel = chartControl.ChartPanels[PanelIndex];

            // recenter region anchors to always be onscreen/centered
            double middleX = chartPanel.X + chartPanel.W / 2d;
            double middleY = chartPanel.Y + chartPanel.H / 2d;

            if (Mode == RegionHighlightMode.Price)
            {
                StartAnchor.UpdateXFromPoint(new Point(middleX, 0), chartControl, chartScale);
                EndAnchor.UpdateXFromPoint(new Point(middleX, 0), chartControl, chartScale);
            }
            else
            {
                StartAnchor.UpdateYFromDevicePoint(new Point(0, middleY), chartScale);
                EndAnchor.UpdateYFromDevicePoint(new Point(0, middleY), chartScale);
            }

            Point  startPoint = StartAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point  endPoint   = EndAnchor.GetPoint(chartControl, chartPanel, chartScale);
            double width      = endPoint.X - startPoint.X;

            AnchorLineStroke.RenderTarget = RenderTarget;
            OutlineStroke.RenderTarget    = RenderTarget;

            if (!IsInHitTest && AreaBrush != null)
            {
                if (areaBrushDevice.Brush == null)
                {
                    Brush brushCopy = areaBrush.Clone();
                    brushCopy.Opacity     = areaOpacity / 100d;
                    areaBrushDevice.Brush = brushCopy;
                }
                areaBrushDevice.RenderTarget = RenderTarget;
            }
            else
            {
                areaBrushDevice.RenderTarget = null;
                areaBrushDevice.Brush        = null;
            }

            // align to full pixel to avoid unneeded aliasing
            float strokePixAdjust = Math.Abs(OutlineStroke.Width % 2d).ApproxCompare(0) == 0 ? 0.5f : 0f;

            SharpDX.RectangleF rect = Mode == RegionHighlightMode.Time ?
                                      new SharpDX.RectangleF((float)startPoint.X + strokePixAdjust, ChartPanel.Y - OutlineStroke.Width + strokePixAdjust,
                                                             (float)width, chartPanel.Y + chartPanel.H + OutlineStroke.Width * 2) :
                                      new SharpDX.RectangleF(chartPanel.X - OutlineStroke.Width + strokePixAdjust, (float)startPoint.Y + strokePixAdjust,
                                                             chartPanel.X + chartPanel.W + OutlineStroke.Width * 2, (float)(endPoint.Y - startPoint.Y));

            if (!IsInHitTest && areaBrushDevice.BrushDX != null)
            {
                RenderTarget.FillRectangle(rect, areaBrushDevice.BrushDX);
            }

            SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : OutlineStroke.BrushDX;
            RenderTarget.DrawRectangle(rect, tmpBrush, OutlineStroke.Width, OutlineStroke.StrokeStyle);

            if (IsSelected)
            {
                tmpBrush = IsInHitTest ? chartControl.SelectionBrush : AnchorLineStroke.BrushDX;
                RenderTarget.DrawLine(startPoint.ToVector2(), endPoint.ToVector2(), tmpBrush, AnchorLineStroke.Width, AnchorLineStroke.StrokeStyle);
            }
        }
Beispiel #27
0
 protected GraphicsPath CreateRectanglePath(RectangleF rect)
 {
   return GraphicsPathHelper.CreateRoundedRectPath(rect, (float) RadiusX, (float) RadiusY);
 }
        public override void PaintWorld(WorldLayer layer)
        {
            if (layer != WorldLayer.Ground)
            {
                return;
            }

            var groundRect          = Hud.Window.GroundRectangle;
            var padding             = Hud.Window.Size.Height * Padding;
            var screenBorderPadding = Hud.Window.Size.Height * ScreenBorderPadding;

            foreach (var kvp in _registeredLabels)
            {
                var coord = kvp.Key;
                var list  = kvp.Value;

                var tw   = 0.0f;
                var sc   = coord.ToScreenCoordinate(true, true);
                var maxH = 0.0f;

                foreach (var regLabel in list)
                {
                    var layout = regLabel.Decorator.TextFont.GetTextLayout(regLabel.Text);
                    var w      = layout.Metrics.Width + padding * 6;
                    tw += w;
                    if (layout.Metrics.Height > maxH)
                    {
                        maxH = layout.Metrics.Height;
                    }
                }

                var forceOnScreen = list.Any(regLabel => regLabel.Decorator.ForceOnScreen);

                var x = sc.X - tw / 2;
                if (forceOnScreen)
                {
                    x = Math.Max(screenBorderPadding, Math.Min(x, groundRect.Width - screenBorderPadding - tw));
                }

                foreach (var regLabel in list)
                {
                    var layout = regLabel.Decorator.TextFont.GetTextLayout(regLabel.Text);
                    var w      = layout.Metrics.Width + padding * 6;
                    var h      = layout.Metrics.Height + padding * 2;

                    var y = regLabel.Decorator.CenterBaseLine ? sc.Y - layout.Metrics.Height / 2 : sc.Y + (maxH - layout.Metrics.Height) / 2;

                    if (forceOnScreen)
                    {
                        y = Math.Max(screenBorderPadding, Math.Min(y, groundRect.Bottom - screenBorderPadding - h));
                    }

                    var rect = new SharpDX.RectangleF(x + regLabel.Decorator.OffsetX, y + regLabel.Decorator.OffsetY - padding, w, h);

                    if (regLabel.Decorator.BackgroundTexture1 != null)
                    {
                        regLabel.Decorator.BackgroundTexture1.Draw(rect, regLabel.Decorator.BackgroundTextureOpacity1);
                    }

                    if (regLabel.Decorator.BackgroundTexture2 != null)
                    {
                        regLabel.Decorator.BackgroundTexture2.Draw(rect, regLabel.Decorator.BackgroundTextureOpacity2);
                    }

                    if (regLabel.Decorator.BackgroundBrush != null)
                    {
                        regLabel.Decorator.BackgroundBrush.DrawRectangle(rect);
                    }

                    regLabel.Decorator.TextFont.DrawText(layout, x + regLabel.Decorator.OffsetX + padding * 3, y + regLabel.Decorator.OffsetY);

                    if (regLabel.Decorator.BorderBrush != null)
                    {
                        regLabel.Decorator.BorderBrush.DrawRectangle(rect);
                    }

                    x += w;
                }
            }

            _registeredLabels.Clear();
        }
Beispiel #29
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RenderForm form = new RenderForm("Kinect simple pilot sample");

            RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport);
            RenderContext context = new RenderContext(device);
            DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle);

            //Allow to draw using direct2d on top of swapchain
            var context2d = new SharpDX.Direct2D1.DeviceContext(swapChain.Texture.QueryInterface<SharpDX.DXGI.Surface>());
            //Call release on texture since queryinterface does an addref
            Marshal.Release(swapChain.Texture.NativePointer);

            var textFormat = new SharpDX.DirectWrite.TextFormat(device.DWriteFactory, "Arial", 16.0f);

            var blackBrush = new SharpDX.Direct2D1.SolidColorBrush(context2d, SharpDX.Color.Black);
            var whiteBrush = new SharpDX.Direct2D1.SolidColorBrush(context2d, SharpDX.Color.White);

            KinectSensor sensor = KinectSensor.GetDefault();
            sensor.Open();

            bool doQuit = false;

            KinectSensorColorRGBAFrameProvider provider = new KinectSensorColorRGBAFrameProvider(sensor);
            DynamicColorRGBATextureProcessor colorProcessor = new DynamicColorRGBATextureProcessor(provider, device);

            KinectPilotProcessor pilot = KinectPilotProcessor.Default;

            KinectSensorBodyFrameProvider bodyFrameProvider = new KinectSensorBodyFrameProvider(sensor);
            bodyFrameProvider.FrameReceived += (sender, args) =>
            {
                var body = args.FrameData.TrackedOnly().ClosestBodies().FirstOrDefault();
                if (body != null)
                {
                    pilot.Process(body.GetJointTable());
                }
            };

            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } };

            RenderLoop.Run(form, () =>
            {
                if (doQuit)
                {
                    form.Dispose();
                    return;
                }

                colorProcessor.Update(context);

                context.RenderTargetStack.Push(swapChain);

                device.Primitives.ApplyFullTri(context, colorProcessor.Texture.ShaderView);
                device.Primitives.FullScreenTriangle.Draw(context);
                context.RenderTargetStack.Pop();

                context2d.BeginDraw();

                var rect = new SharpDX.RectangleF(0, 0, 200, 130);
                context2d.FillRectangle(rect, blackBrush);
                context2d.DrawText("Elevation: " + pilot.Elevation, textFormat, rect, whiteBrush);
                rect.Top += 30;
                context2d.DrawText("Steering Y: " + pilot.SteeringY, textFormat, rect, whiteBrush);
                rect.Top += 30;
                context2d.DrawText("Steering Z: " + pilot.SterringZ, textFormat, rect, whiteBrush);
                rect.Top += 30;
                context2d.DrawText("Push: " + pilot.Push, textFormat, rect, whiteBrush);
                context2d.EndDraw();

                swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
            });

            swapChain.Dispose();
            context.Dispose();
            device.Dispose();

            colorProcessor.Dispose();
            provider.Dispose();

            sensor.Close();
        }
Beispiel #30
0
        private void DrawTextBox(bool Snap, string displayText, double x, double y, SharpDX.Direct2D1.Brush brush, SharpDX.Direct2D1.Brush bgBrush, Stroke stroke, float rotate)
        {
            const int padding = 4;

            // Text has changed, need to update cached TextLayout
            if (displayText != lastText)
            {
                needsLayoutUpdate = true;
            }
            lastText = displayText;

            // Update cachedTextLayout
            if (needsLayoutUpdate || cachedTextLayout == null)
            {
                SharpDX.DirectWrite.TextFormat textFormat = Font.ToDirectWriteTextFormat();
                cachedTextLayout = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory,
                                                                      displayText, textFormat, ChartPanel.X + ChartPanel.W,
                                                                      textFormat.FontSize);
                textFormat.Dispose();
                needsLayoutUpdate = false;
            }

            // Snap TextBox coordinates to ChartPanel when out of bounds
            if (Snap)
            {
                if (rotate == 1.5708f)
                {
                    y = Math.Max(ChartPanel.Y + cachedTextLayout.Metrics.Width + 2 * padding, y);
                }
                else
                {
                    y = Math.Min(ChartPanel.H - padding, y);
                    y = Math.Max(ChartPanel.Y + cachedTextLayout.Metrics.Height + padding, y);
                    x = Math.Max(ChartPanel.X + cachedTextLayout.Metrics.Width + 2 * padding, x);
                }
            }

            // Apply rotation
            RenderTarget.Transform = SharpDX.Matrix3x2.Rotation(rotate, new SharpDX.Vector2((float)x, (float)y));

            // Add padding to TextPlotPoint
            SharpDX.Vector2 TextPlotPoint = new System.Windows.Point(x - cachedTextLayout.Metrics.Width - padding / 2, y - cachedTextLayout.Metrics.Height).ToVector2();

            // Draw the TextBox
            if (displayText.Length > 0)
            {
                SharpDX.RectangleF PLBoundRect = new SharpDX.RectangleF((float)x - cachedTextLayout.Metrics.Width - padding, (float)y - cachedTextLayout.Metrics.Height - padding / 2, cachedTextLayout.Metrics.Width + padding, cachedTextLayout.Metrics.Height + padding);
                SharpDX.Direct2D1.RoundedRectangle PLRoundedRect = new SharpDX.Direct2D1.RoundedRectangle()
                {
                    Rect = PLBoundRect, RadiusX = cachedTextLayout.FontSize / 4, RadiusY = cachedTextLayout.FontSize / 4
                };
                RenderTarget.FillRoundedRectangle(PLRoundedRect, bgBrush);
                RenderTarget.DrawRoundedRectangle(PLRoundedRect, stroke.BrushDX, stroke.Width, stroke.StrokeStyle);

                // Draw the TextLayout
                RenderTarget.DrawTextLayout(TextPlotPoint, cachedTextLayout, brush, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
            }

            // Restore rotation
            RenderTarget.Transform = SharpDX.Matrix3x2.Identity;
        }
Beispiel #31
0
 protected GraphicsPath CreateRectanglePath(RectangleF rect)
 {
     return(GraphicsPathHelper.CreateRoundedRectPath(rect, (float)RadiusX, (float)RadiusY));
 }
Beispiel #32
0
        // 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();
        }
Beispiel #33
0
        public override void GetTexture(SharpDX.Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out SharpDX.RectangleF textureSubRectangle)
        {
            if (_synchronizedTexture == null)
            {
                _synchronizedTexture = _host.CreateSynchronizedTexture(_controller.GetTexture());
            }

            // Set output parameters.
            _textureSubRectangle.Left   = 0.0f;
            _textureSubRectangle.Top    = 0.0f;
            _textureSubRectangle.Right  = surfaceSize.Width;
            _textureSubRectangle.Bottom = surfaceSize.Height;


            //HOW DO YOU DO A Microsoft::WRL::ComPtr<T>   CopyTo ?????
            //m_synchronizedTexture.CopyTo(synchronizedTexture);
            synchronizedTexture = _synchronizedTexture;

            textureSubRectangle = _textureSubRectangle;

            //something is going wrong here as the second time thru the BeginDraw consumes
            //the call and controlnever returns back to this method, thus GetTexture
            //(the call after begindraw) never fires again... ??????
            synchronizedTexture.BeginDraw();

            _controller.GetTexture(surfaceSize, synchronizedTexture, textureSubRectangle);

            synchronizedTexture.EndDraw();
        }
    public override void AlignedPanelAddPotentialFocusNeighbors(RectangleF? startingRect, ICollection<FrameworkElement> outElements,
        bool linesBeforeAndAfter)
    {
      if (ItemProvider == null)
      {
        base.AlignedPanelAddPotentialFocusNeighbors(startingRect, outElements, linesBeforeAndAfter);
        return;
      }
      if (!IsVisible)
        return;
      if (Focusable)
        outElements.Add(this);

      IList<FrameworkElement> arrangedItemsCopy;
      lock (Children.SyncRoot)
      {
        arrangedItemsCopy = new List<FrameworkElement>(_arrangedItems.Skip(_arrangedLines[0].StartIndex).Take(_arrangedLines[_arrangedLines.Count - 1].EndIndex + 1));
      }
      int numLinesBeforeAndAfter = linesBeforeAndAfter ? NUM_ADD_MORE_FOCUS_LINES : 0;
      AddFocusedElementRange(arrangedItemsCopy, startingRect, _actualFirstVisibleLineIndex, _actualLastVisibleLineIndex,
          numLinesBeforeAndAfter, numLinesBeforeAndAfter, outElements);
    }
    protected override void MakeChildVisible(UIElement element, ref RectangleF elementBounds)
    {
      IItemProvider itemProvider = ItemProvider;
      if (itemProvider == null)
      {
        base.MakeChildVisible(element, ref elementBounds);
        return;
      }

      if (_doScroll)
      {
        int lineIndex = 0;

        IList<FrameworkElement> arrangedItemsCopy;
        lock (Children.SyncRoot)
        {
          arrangedItemsCopy = new List<FrameworkElement>(_arrangedItems);
        }
        IList<LineMeasurement> lines = new List<LineMeasurement>(_arrangedLines);
        foreach (LineMeasurement line in lines)
        {
          for (int childIndex = line.StartIndex; childIndex <= line.EndIndex; childIndex++)
          {
            FrameworkElement currentChild = arrangedItemsCopy[childIndex];
            if (InVisualPath(currentChild, element))
            {
              int oldFirstVisibleLine = _actualFirstVisibleLineIndex;
              int oldLastVisibleLine = _actualLastVisibleLineIndex;
              bool first;
              if (lineIndex < oldFirstVisibleLine)
                first = true;
              else if (lineIndex <= oldLastVisibleLine)
                // Already visible
                break;
              else
                first = false;
              SetScrollIndex(lineIndex, first);
              // Adjust the scrolled element's bounds; Calculate the difference between positions of childen at old/new child indices
              float extendsInOrientationDirection = SumActualLineExtendsInNonOrientationDirection(lines,
                  first ? oldFirstVisibleLine : oldLastVisibleLine, lineIndex);
              if (Orientation == Orientation.Horizontal)
                elementBounds.X -= extendsInOrientationDirection;
              else
                elementBounds.Y -= extendsInOrientationDirection;
              break;
            }
          }
          lineIndex++;
        }
      }
    }