public static SharpDX.Vector2[] Vector2EUCtoSDX(MathObjects.Vector2[] vec)
 {
     SharpDX.Vector2[] vecs = new SharpDX.Vector2[vec.Length];
     for (int i = 0; i < vecs.Length; i++)
         vecs[i] = Vector2EUCtoSDX(vec[i]);
     return vecs;
 }
示例#2
0
文件: Camera.cs 项目: TomTer/PoeHud
 public unsafe Vector2 WorldToScreen(Vector3 vec3, EntityWrapper entityWrapper)
 {
     Entity localPlayer = Game.IngameState.Data.LocalPlayer;
     var isplayer = localPlayer.Address == entityWrapper.Address && localPlayer.IsValid;
     var playerMoving = isplayer && localPlayer.GetComponent<Actor>().isMoving;
     float x, y;
     int addr = base.Address + 0xbc;
     fixed (byte* numRef = base.M.ReadBytes(addr, 0x40))
     {
         Matrix4x4 matrix = *(Matrix4x4*)numRef;
         Vector4 cord = *(Vector4*)&vec3;
         cord.W = 1;
         cord = Vector4.Transform(cord, matrix);
         cord = Vector4.Divide(cord, cord.W);
         x = ((cord.X + 1.0f) * 0.5f) * Width;
         y = ((1.0f - cord.Y) * 0.5f) * Height;
     }
     var resultCord = new Vector2(x, y);
     if (playerMoving)
     {
         if (Math.Abs(oldplayerCord.X - resultCord.X) < 40 || (Math.Abs(oldplayerCord.X - resultCord.Y) < 40))
             resultCord = oldplayerCord;
         else
             oldplayerCord = resultCord;
     }
     else if (isplayer)
     {
         oldplayerCord = resultCord;
     }
     return resultCord;
 }
    /// <summary>
    /// A copy of the <see cref="WrapPanel.LayoutLine"/> method, but using the <see cref="ItemProvider"/>
    /// via the <see cref="GetItem"/> method for item retrieval.
    /// </summary>
    protected void LayoutLine(PointF pos, LineMeasurement line)
    {
      float offset = 0;
      for (int i = line.StartIndex; i <= line.EndIndex; i++)
      {
        FrameworkElement layoutChild = GetItem(i, ItemProvider, true);
        SizeF desiredChildSize = layoutChild.DesiredSize;
        SizeF size;
        PointF location;

        if (Orientation == Orientation.Horizontal)
        {
          size = new SizeF(desiredChildSize.Width, line.TotalExtendsInNonOrientationDirection);
          location = new PointF(pos.X + offset, pos.Y);
          ArrangeChildVertical(layoutChild, layoutChild.VerticalAlignment, ref location, ref size);
          offset += desiredChildSize.Width;
        }
        else
        {
          size = new SizeF(line.TotalExtendsInNonOrientationDirection, desiredChildSize.Height);
          location = new PointF(pos.X, pos.Y + offset);
          ArrangeChildHorizontal(layoutChild, layoutChild.HorizontalAlignment, ref location, ref size);
          offset += desiredChildSize.Height;
        }

        layoutChild.Arrange(new RectangleF(location.X, location.Y, size.Width, size.Height));

        _arrangedItems[i] = layoutChild;
      }
    }
示例#4
0
 /// <unmanaged>HRESULT ID2D1CommandSink::DrawGlyphRun([In] D2D_POINT_2F baselineOrigin,[In] const DWRITE_GLYPH_RUN* glyphRun,[In, Optional] const DWRITE_GLYPH_RUN_DESCRIPTION* glyphRunDescription,[In] ID2D1Brush* foregroundBrush,[In] DWRITE_MEASURING_MODE measuringMode)</unmanaged>
 public void DrawGlyphRun(SharpDX.Vector2 baselineOrigin, SharpDX.DirectWrite.GlyphRun glyphRun, SharpDX.DirectWrite.GlyphRunDescription glyphRunDescription, SharpDX.Direct2D1.Brush foregroundBrush, SharpDX.Direct2D1.MeasuringMode measuringMode)
 {
     DrawGlyphRun_(baselineOrigin, glyphRun, glyphRunDescription, foregroundBrush, measuringMode);
 }
示例#5
0
 private unsafe static int DrawLineImpl(IntPtr thisPtr, SharpDX.Vector2 point0, SharpDX.Vector2 point1, IntPtr brush, float strokeWidth, IntPtr strokeStyle)
 {
     try
     {
         var shadow   = ToShadow <CommandSinkShadow>(thisPtr);
         var callback = (CommandSink)shadow.Callback;
         callback.DrawLine(point0, point1, new Brush(brush), strokeWidth, new StrokeStyle(strokeStyle));
     }
     catch (Exception exception)
     {
         return((int)SharpDX.Result.GetResultFromException(exception));
     }
     return(Result.Ok.Code);
 }
示例#6
0
        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            if (Series1 == null)
            {
                return;
            }

            NinjaScriptBase nsb       = AttachedTo.ChartObject as NinjaScriptBase;
            ChartBars       chartBars = (AttachedTo.ChartObject as Gui.NinjaScript.IChartBars).ChartBars;

            if (nsb == null || chartBars == null || Math.Abs(Series1.Count - chartBars.Count) > 1)
            {
                return;
            }

            int startBarIdx;
            int endBarIdx;

            if (chartControl.BarSpacingType == BarSpacingType.TimeBased)
            {
                startBarIdx = chartBars.GetBarIdxByTime(chartControl, StartAnchor.Time);
                endBarIdx   = chartBars.GetBarIdxByTime(chartControl, EndAnchor.Time);
            }
            else
            {
                startBarIdx = StartAnchor.DrawnOnBar - StartAnchor.BarsAgo;
                endBarIdx   = EndAnchor.DrawnOnBar - EndAnchor.BarsAgo;

                if (startBarIdx == endBarIdx)
                {
                    startBarIdx = chartBars.GetBarIdxByTime(chartControl, StartAnchor.Time);
                    endBarIdx   = chartBars.GetBarIdxByTime(chartControl, EndAnchor.Time);
                }
            }

            int startIdx = Math.Min(startBarIdx, endBarIdx);
            int endIdx   = Math.Max(startBarIdx, endBarIdx);

            // Now cap start/end by visibly painted bars!
            // If you dont do this it will absolutely crush performance on larger regions
            int firstVisibleIdx = Math.Max(nsb.BarsRequiredToPlot + Displacement, chartBars.GetBarIdxByTime(chartControl, chartControl.GetTimeByX(0)) - 1);
            int lastVisibleIdx  = Math.Max(chartBars.ToIndex, chartBars.GetBarIdxByTime(chartControl, chartControl.LastTimePainted)) + 1;

            // Update indicies for displacement
            startIdx = Math.Max(0, Math.Max(firstVisibleIdx, startIdx + Displacement));
            endIdx   = Math.Max(0, Math.Min(endIdx + Displacement, lastVisibleIdx));

            // we're completely not visible
            if (startIdx > lastVisibleIdx || endIdx < firstVisibleIdx)
            {
                return;
            }

            /* NOTE: Calling GetValueAt() on an ISeries<double> interface with a concrete
             * type of NinjaScriptBase will get the *bar* value which is not what we want,
             * in this case, default to first values (indicator) series */
            ISeries <double> series1Adjusted = Series1;
            ISeries <double> series2Adjusted = Series2;

            NinjaScriptBase series1NsBase = Series1 as NinjaScriptBase;

            if (series1NsBase != null)
            {
                series1Adjusted = series1NsBase.Value;
            }

            if (series1Adjusted == null)
            {
                return;
            }

            NinjaScriptBase series2NsBase = Series2 as NinjaScriptBase;

            if (series2NsBase != null)
            {
                series2Adjusted = series2NsBase.Value;
            }

            // take care to wind the points correctly so our geometry builds as a solid, not flipped inside out
            SharpDX.Vector2[] points;
            SharpDX.Vector2[] points2 = new SharpDX.Vector2[0];
            int pointIdx  = 0;
            int pointIdx2 = 0;

            if (series2Adjusted == null)
            {
                points = new SharpDX.Vector2[endIdx - startIdx + 1 + 2];
                for (int i = startIdx; i <= endIdx; ++i)
                {
                    if (i < Math.Max(0, Displacement) || i > Math.Max(chartBars.Count - (nsb.Calculate == Calculate.OnBarClose ? 2 : 1) + Displacement, endIdx))
                    {
                        continue;
                    }

                    int    displacedIndex = Math.Min(chartBars.Count - (nsb.Calculate == Calculate.OnBarClose ? 2 : 1), Math.Max(0, i - Displacement));
                    double seriesValue    = series1Adjusted.GetValueAt(displacedIndex);
                    float  y = chartScale.GetYByValue(seriesValue);
                    float  x = chartControl.BarSpacingType == BarSpacingType.TimeBased || chartControl.BarSpacingType == BarSpacingType.EquidistantMulti && i >= chartBars.Count                                                    //i is already displaced
                                                ? chartControl.GetXByTime(chartBars.GetTimeByBarIdx(chartControl, i))
                                                : chartControl.GetXByBarIndex(chartBars, i);

                    double pixXAdjust     = x % 1 != 0 ? 0 : 0.5d;
                    double pixYAdjust     = y % 1 != 0 ? 0 : 0.5d;
                    Vector pixelAdjustVec = new Vector(pixXAdjust, pixYAdjust);

                    Point adjusted = new Point(x, y) + pixelAdjustVec;
                    points[pointIdx] = adjusted.ToVector2();
                    ++pointIdx;
                }

                // cap it end->start
                points[pointIdx].X = chartControl.BarSpacingType == BarSpacingType.TimeBased || chartControl.BarSpacingType == BarSpacingType.EquidistantMulti && endIdx >= chartBars.Count
                                        ? chartControl.GetXByTime(chartBars.GetTimeByBarIdx(chartControl, endIdx))
                                        : chartControl.GetXByBarIndex(chartBars, endIdx);
                points[pointIdx++].Y = chartScale.GetYByValue(Math.Max(chartScale.MinValue, Math.Min(chartScale.MaxValue, Price)));

                points[pointIdx].X = chartControl.BarSpacingType == BarSpacingType.TimeBased || chartControl.BarSpacingType == BarSpacingType.EquidistantMulti && startIdx >= chartBars.Count
                                        ? chartControl.GetXByTime(chartBars.GetTimeByBarIdx(chartControl, startIdx))
                                        : chartControl.GetXByBarIndex(chartBars, startIdx);
                points[pointIdx++].Y = chartScale.GetYByValue(Math.Max(chartScale.MinValue, Math.Min(chartScale.MaxValue, Price)));
            }
            else
            {
                points  = new SharpDX.Vector2[endIdx - startIdx + 1];
                points2 = new SharpDX.Vector2[endIdx - startIdx + 1];
                // fill clockwise from series1, the	counter clockwise for series 2 for correct point poly winding
                for (int i = startIdx; i <= endIdx; ++i)
                {
                    if (i < Math.Max(0, Displacement) || i > Math.Max(chartBars.Count - (nsb.Calculate == Calculate.OnBarClose ? 2 : 1) + Displacement, endIdx))
                    {
                        continue;
                    }

                    int   displacedIndex = Math.Min(chartBars.Count - (nsb.Calculate == Calculate.OnBarClose ? 2 : 1), Math.Max(0, i - Displacement));
                    float x = chartControl.BarSpacingType == BarSpacingType.TimeBased || chartControl.BarSpacingType == BarSpacingType.EquidistantMulti && i >= chartBars.Count                                                     //i is already displaced
                                                ? chartControl.GetXByTime(chartBars.GetTimeByBarIdx(chartControl, i))
                                                : chartControl.GetXByBarIndex(chartBars, i);
                    if (!series1Adjusted.IsValidDataPointAt(displacedIndex))
                    {
                        continue;
                    }
                    double seriesValue = series1Adjusted.GetValueAt(displacedIndex);
                    float  y           = chartScale.GetYByValue(seriesValue);

                    double pixXAdjust = x % 1 != 0 ? 0 : 0.5d;
                    double pixYAdjust = y % 1 != 0 ? 0 : 0.5d;

                    Vector pixelAdjustVec = new Vector(pixXAdjust, pixYAdjust);

                    Point adjusted = new Point(x, y) + pixelAdjustVec;
                    points[pointIdx] = adjusted.ToVector2();
                    ++pointIdx;
                    if (!series2Adjusted.IsValidDataPointAt(displacedIndex))
                    {
                        continue;
                    }
                    seriesValue        = series2Adjusted.GetValueAt(displacedIndex);
                    y                  = chartScale.GetYByValue(seriesValue);
                    pixYAdjust         = y % 1 != 0 ? 0 : 0.5d;
                    pixelAdjustVec     = new Vector(pixXAdjust, pixYAdjust);
                    adjusted           = new Point(x, y) + pixelAdjustVec;
                    points2[pointIdx2] = adjusted.ToVector2();
                    ++pointIdx2;
                }
            }

            if (pointIdx + pointIdx2 > 2)
            {
                RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;

                if (OutlineStroke != null)
                {
                    OutlineStroke.RenderTarget = RenderTarget;
                }

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

                SharpDX.Direct2D1.PathGeometry polyGeo = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFactory);
                SharpDX.Direct2D1.GeometrySink geoSink = polyGeo.Open();
                double pixXAdjust     = points[0].X % 1 != 0 ? 0 : 0.5d;
                double pixYAdjust     = points[0].Y % 1 != 0 ? 0 : 0.5d;
                Vector pixelAdjustVec = new Vector(pixXAdjust, pixYAdjust);
                Point  startPt        = new Point(points[0].X, points[0].Y) + pixelAdjustVec;

                geoSink.BeginFigure(startPt.ToVector2(), SharpDX.Direct2D1.FigureBegin.Filled);
                geoSink.SetFillMode(SharpDX.Direct2D1.FillMode.Winding);

                // NOTE: We skip our first point since that is where the path will start
                for (int i = 1; i < pointIdx; i++)
                {
                    geoSink.AddLine(points[i]);
                }
                for (int i = pointIdx2 - 1; i >= 0; i--)
                {
                    geoSink.AddLine(points2[i]);
                }
                geoSink.EndFigure(SharpDX.Direct2D1.FigureEnd.Closed);
                geoSink.Close();

                SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : areaBrushDevice == null ? null : areaBrushDevice.BrushDX;
                if (tmpBrush != null)
                {
                    RenderTarget.FillGeometry(polyGeo, tmpBrush);
                }

                tmpBrush = IsInHitTest ? chartControl.SelectionBrush : OutlineStroke == null ? null : OutlineStroke.BrushDX;
                if (tmpBrush != null)
                {
                    RenderTarget.DrawGeometry(polyGeo, OutlineStroke.BrushDX, OutlineStroke.Width);
                }

                polyGeo.Dispose();
            }
        }
示例#7
0
 /// <summary>
 /// Issue an order for the player(me) act on.
 /// </summary>
 /// <param name="issuedOrder"></param>
 /// <param name="positionOrdered"></param>
 public static void IssueOrder(OrderType issuedOrder, SharpDX.Vector2 positionOrdered)
 {
     EngineManager.IssueOrder((EngineManager.OrderType)issuedOrder, positionOrdered);
 }
示例#8
0
        private SharpDX.Vector2 CalculateUV(float x, float y)
        {
            SharpDX.Vector2 uv = SharpDX.Vector2.Zero;

            if (this.textureWidth != 1 || this.textureHeight != 1)
            {
                uv = new SharpDX.Vector2(x / (float)this.textureWidth, y / (float)this.textureHeight);
            }

            return uv;
        }
示例#9
0
 public static System.Numerics.Vector2 ToNVector2(this SharpDX.Vector2 v)
 {
     return(new System.Numerics.Vector2(v.X, v.Y));
 }
示例#10
0
 /// <summary>
 /// No documentation.
 /// </summary>
 /// <param name="effect">No documentation.</param>
 /// <param name="targetOffset">No documentation.</param>
 /// <param name="interpolationMode">No documentation.</param>
 /// <param name="compositeMode">No documentation.</param>
 /// <unmanaged>void ID2D1DeviceContext::DrawImage([In] ID2D1Image* image,[In, Optional] const D2D_POINT_2F* targetOffset,[In, Optional] const D2D_RECT_F* imageRectangle,[In] D2D1_INTERPOLATION_MODE interpolationMode,[In] D2D1_COMPOSITE_MODE compositeMode)</unmanaged>
 public void DrawImage(SharpDX.Direct2D1.Effect effect, SharpDX.Vector2 targetOffset, SharpDX.Direct2D1.InterpolationMode interpolationMode = InterpolationMode.Linear, SharpDX.Direct2D1.CompositeMode compositeMode = CompositeMode.SourceOver)
 {
     using (var output = effect.Output)
         DrawImage(output, targetOffset, null, interpolationMode, compositeMode);
 }
示例#11
0
        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;
        }
示例#12
0
    protected override void ArrangeOverride()
    {
      base.ArrangeOverride();
      ColumnDefinitions.SetAvailableSize(ActualWidth);
      RowDefinitions.SetAvailableSize(ActualHeight);

      foreach (FrameworkElement child in GetVisibleChildren())
      {
        int col = GetColumn(child);
        int row = GetRow(child);
        if (col >= ColumnDefinitions.Count) col = ColumnDefinitions.Count - 1;
        if (col < 0) col = 0;
        if (row >= RowDefinitions.Count) row = RowDefinitions.Count - 1;
        if (row < 0) row = 0;

        PointF position = new PointF(
            (float) ColumnDefinitions.GetOffset(col) + _innerRect.Location.X, 
            (float) RowDefinitions.GetOffset(row) + _innerRect.Location.Y);

        SizeF childSize = new SizeF(
            (float) ColumnDefinitions.GetLength(col, GetColumnSpan(child)),
            (float) RowDefinitions.GetLength(row, GetRowSpan(child)));

        ArrangeChild(child, child.HorizontalAlignment, child.VerticalAlignment, ref position, ref childSize);
        child.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize));
      }
    }
示例#13
0
 public override bool HitTest(SharpDX.Vector2 vec)
 {
     return(base.HitTest(vec + new SharpDX.Vector2(normal.Width / 2, normal.Height / 2)));
 }
示例#14
0
        private static void OnDraw(EventArgs args)
        {
            if (Menu.Item("drawQ").GetValue<bool>())
            {
                Render.Circle.DrawCircle(Player.Position, Q.Range, Menu.Item("drawQColor").GetValue<Color>(), 3);
            }
            if (Menu.Item("drawE").GetValue<bool>())
            {
                Render.Circle.DrawCircle(Player.Position, E.Range, Menu.Item("drawEColor").GetValue<Color>(), 3);
            }
            if (Menu.Item("drawEMax").GetValue<bool>())
            {
                Render.Circle.DrawCircle(Player.Position, E.Range+E.Range, Menu.Item("drawEMaxColor").GetValue<Color>(), 3);
            }
            if (Menu.Item("drawRr").GetValue<bool>())
            {
                Render.Circle.DrawCircle(Player.Position, R.Range, Menu.Item("drawRrColor").GetValue<Color>(), 3);
            }
            if (Menu.Item("drawMinionQCombo").GetValue<bool>() && SelectedTarget.IsValidTarget())
            {
                if (Player.Distance(SelectedTarget) <= R.Range + Q.Range)
                {
                    RRectangle.Draw(Menu.Item("drawMinionQComboColor").GetValue<Color>(), 3);
                }
            }
            if (hitchanceR != "" && Menu.Item("drawRHitChance").GetValue<bool>())
            {
                Drawing.DrawText((float)Menu.Item("drawRHitChanceX").GetValue<Slider>().Value, (float)Menu.Item("drawRHitChanceY").GetValue<Slider>().Value, Menu.Item("drawRHitChanceColor").GetValue<Color>(), "Hitchance: " + hitchanceR);
            }
            if (debugText != "")
            {
                Drawing.DrawText(400, 600, Color.DarkTurquoise, "Debug: " + debugText);
            }
            if (debugText2 != "")
            {
                Drawing.DrawText(400, 800, Color.DarkTurquoise, "Debug: " + debugText2);
            }
            if (Menu.Item("drawR").GetValue<bool>() && SelectedTarget.IsValidTarget())
            {
                Render.Circle.DrawCircle(R.GetPrediction(SelectedTarget, false, Player.Distance(SelectedTarget.Position)).CastPosition.Extend(Player.Position, -(600)), 250, Menu.Item("drawRColor").GetValue<Color>());
            }
            if (Menu.Item("drawComboDamage").GetValue<bool>()) 
            {
                foreach (var unit in HeroManager.Enemies.Where(u => u.IsValidTarget() && u.IsHPBarRendered))
                {
                    // Instantiate the delegate.
                    var damage = TotalComboDamage(unit);
                    if(damage <= 0)
                    {
                        continue;
                    }
                    var damagePercentage = ((unit.Health - damage) > 0 ? (unit.Health - damage) : 0) / unit.MaxHealth;
                    var currentHealthPercentage = unit.Health / unit.MaxHealth;

                    // Calculate start and end point of the bar indicator
                    var startPoint = new SharpDX.Vector2((int)(unit.HPBarPosition.X + BarOffset.X + damagePercentage * 104), (int)(unit.HPBarPosition.Y + BarOffset.Y) - 5);
                    var endPoint = new SharpDX.Vector2((int)(unit.HPBarPosition.X + BarOffset.X + currentHealthPercentage * 104) + 1, (int)(unit.HPBarPosition.Y + BarOffset.Y) - 5);

                    Color bar = Menu.Item("ComboDamageColor").GetValue<Color>();
                    // Draw the line
                    Drawing.DrawLine(startPoint, endPoint, 9, bar);
                }
            }
        }
示例#15
0
 public static System.Windows.Point Convert(SharpDX.Vector2 pos)
 {
     return(new System.Windows.Point(pos.X, pos.Y));
 }
示例#16
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();
        }
示例#17
0
 /// <summary>
 /// No documentation.
 /// </summary>
 /// <param name="image">No documentation.</param>
 /// <param name="targetOffset">No documentation.</param>
 /// <param name="interpolationMode">No documentation.</param>
 /// <param name="compositeMode">No documentation.</param>
 /// <unmanaged>void ID2D1DeviceContext::DrawImage([In] ID2D1Image* image,[In, Optional] const D2D_POINT_2F* targetOffset,[In, Optional] const D2D_RECT_F* imageRectangle,[In] D2D1_INTERPOLATION_MODE interpolationMode,[In] D2D1_COMPOSITE_MODE compositeMode)</unmanaged>
 public void DrawImage(SharpDX.Direct2D1.Image image, SharpDX.Vector2 targetOffset, SharpDX.Direct2D1.InterpolationMode interpolationMode = InterpolationMode.Linear, SharpDX.Direct2D1.CompositeMode compositeMode = CompositeMode.SourceOver)
 {
     DrawImage(image, targetOffset, null, interpolationMode, compositeMode);
 }
示例#18
0
        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            if (firstTime && DrawingState == DrawingState.Normal)
            {
                firstTime = false;
                Cbi.License.Log("Path");
            }

            RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;
            Stroke outlineStroke = OutlineStroke;

            outlineStroke.RenderTarget = RenderTarget;
            ChartPanel chartPanel      = chartControl.ChartPanels[PanelIndex];
            double     strokePixAdjust = outlineStroke.Width % 2 == 0 ? 0.5d : 0d;
            Vector     pixelAdjustVec  = new Vector(strokePixAdjust, strokePixAdjust);

            SharpDX.Direct2D1.PathGeometry polyGeo  = CreatePathGeometry(chartControl, chartPanel, chartScale, strokePixAdjust);
            SharpDX.Direct2D1.Brush        tmpBrush = IsInHitTest ? chartControl.SelectionBrush : outlineStroke.BrushDX;

            RenderTarget.DrawGeometry(polyGeo, tmpBrush, outlineStroke.Width, outlineStroke.StrokeStyle);
            polyGeo.Dispose();

            if (PathBegin == PathToolCapMode.Arrow || PathEnd == PathToolCapMode.Arrow)
            {
                Point[] points = GetPathAnchorPoints(chartControl, chartScale);

                if (points.Length > 1)
                {
                    if (arrowPathGeometry == null)
                    {
                        arrowPathGeometry = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFactory);
                        SharpDX.Direct2D1.GeometrySink geometrySink = arrowPathGeometry.Open();
                        float           arrowWidth = 6f;
                        SharpDX.Vector2 top        = new SharpDX.Vector2(0, outlineStroke.Width * 0.5f);

                        geometrySink.BeginFigure(top, SharpDX.Direct2D1.FigureBegin.Filled);
                        geometrySink.AddLine(new SharpDX.Vector2(arrowWidth, -arrowWidth));
                        geometrySink.AddLine(new SharpDX.Vector2(-arrowWidth, -arrowWidth));
                        geometrySink.AddLine(top);                        // cap off figure
                        geometrySink.EndFigure(SharpDX.Direct2D1.FigureEnd.Closed);
                        geometrySink.Close();
                    }

                    if (PathBegin == PathToolCapMode.Arrow)
                    {
                        Vector lineVector = points[0] - points[1];

                        lineVector.Normalize();

                        Point             pointAdjusted    = points[0] + pixelAdjustVec;
                        SharpDX.Vector2   pointVec         = pointAdjusted.ToVector2();
                        float             vectorAngle      = -(float)Math.Atan2(lineVector.X, lineVector.Y);
                        Vector            adjustVector     = lineVector * 5;
                        SharpDX.Vector2   arrowPointVec    = new SharpDX.Vector2((float)(pointVec.X + adjustVector.X), (float)(pointVec.Y + adjustVector.Y));
                        SharpDX.Matrix3x2 transformMatrix2 = SharpDX.Matrix3x2.Rotation(vectorAngle, SharpDX.Vector2.Zero) * SharpDX.Matrix3x2.Scaling((float)Math.Max(1.0f, outlineStroke.Width * .45) + 0.25f) * SharpDX.Matrix3x2.Translation(arrowPointVec);
                        RenderTarget.Transform = transformMatrix2;

                        RenderTarget.FillGeometry(arrowPathGeometry, tmpBrush);
                        RenderTarget.Transform = SharpDX.Matrix3x2.Identity;
                    }

                    if (PathEnd == PathToolCapMode.Arrow)
                    {
                        Vector lineVector = points[points.Length - 1] - points[points.Length - 2];

                        lineVector.Normalize();

                        Point             pointAdjusted    = points[points.Length - 1] + pixelAdjustVec;
                        SharpDX.Vector2   pointVec         = pointAdjusted.ToVector2();
                        float             vectorAngle      = -(float)Math.Atan2(lineVector.X, lineVector.Y);
                        Vector            adjustVector     = lineVector * 5;
                        SharpDX.Vector2   arrowPointVec    = new SharpDX.Vector2((float)(pointVec.X + adjustVector.X), (float)(pointVec.Y + adjustVector.Y));
                        SharpDX.Matrix3x2 transformMatrix2 = SharpDX.Matrix3x2.Rotation(vectorAngle, SharpDX.Vector2.Zero) * SharpDX.Matrix3x2.Scaling((float)Math.Max(1.0f, outlineStroke.Width * .45) + 0.25f) * SharpDX.Matrix3x2.Translation(arrowPointVec);
                        RenderTarget.Transform = transformMatrix2;

                        RenderTarget.FillGeometry(arrowPathGeometry, tmpBrush);

                        RenderTarget.Transform = SharpDX.Matrix3x2.Identity;
                    }
                }
            }

            if (ShowCount)
            {
                SimpleFont wpfFont = chartControl.Properties.LabelFont ?? new SimpleFont();
                SharpDX.DirectWrite.TextFormat textFormat = wpfFont.ToDirectWriteTextFormat();
                textFormat.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading;
                textFormat.WordWrapping  = SharpDX.DirectWrite.WordWrapping.NoWrap;

                for (int i = 1; i < ChartAnchors.Count; i++)
                {
                    Point p  = ChartAnchors[i - 1].GetPoint(chartControl, chartPanel, chartScale);
                    Point p1 = ChartAnchors[i].GetPoint(chartControl, chartPanel, chartScale);

                    if (i + 1 < ChartAnchors.Count)
                    {
                        Point  p2 = ChartAnchors[i + 1].GetPoint(chartControl, chartPanel, chartScale);
                        Vector v1 = p - p1;

                        v1.Normalize();

                        Vector v2 = p2 - p1;

                        v2.Normalize();

                        Vector vector = v1 + v2;

                        vector.Normalize();

                        SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout(Core.Globals.DirectWriteFactory, i.ToString(), textFormat, 250, textFormat.FontSize);
                        Point textPoint = p1 - vector * textFormat.FontSize;
                        textPoint.X -= textLayout.Metrics.Width / 2f;
                        textPoint.Y -= textLayout.Metrics.Height / 2f;

                        RenderTarget.DrawTextLayout((textPoint + pixelAdjustVec).ToVector2(), textLayout, outlineStroke.BrushDX, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
                        textLayout.Dispose();
                    }
                    else
                    {
                        SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout(Core.Globals.DirectWriteFactory, i.ToString(), textFormat, 250, textFormat.FontSize);
                        Vector vector = (p - p1);

                        vector.Normalize();

                        Point textPoint = p1 - vector * textFormat.FontSize;
                        textPoint.X -= textLayout.Metrics.Width / 2f;
                        textPoint.Y -= textLayout.Metrics.Height / 2f;

                        RenderTarget.DrawTextLayout((textPoint + pixelAdjustVec).ToVector2(), textLayout, outlineStroke.BrushDX, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
                        textLayout.Dispose();
                    }
                }

                textFormat.Dispose();
            }
        }
示例#19
0
        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            if (Anchors.All(a => a.IsEditing))
            {
                return;
            }

            RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;

            ChartPanel chartPanel           = chartControl.ChartPanels[PanelIndex];
            Point      anchorStartPoint     = StartAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point      anchorEndPoint       = EndAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point      anchorExtensionPoint = ExtensionAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point      midPointExtension    = new Point((anchorExtensionPoint.X + anchorEndPoint.X) / 2, (anchorExtensionPoint.Y + anchorEndPoint.Y) / 2);

            if (CalculationMethod == AndrewsPitchforkCalculationMethod.Schiff)
            {
                anchorStartPoint = new Point(anchorStartPoint.X, (anchorStartPoint.Y + anchorEndPoint.Y) / 2);
            }
            else if (CalculationMethod == AndrewsPitchforkCalculationMethod.ModifiedSchiff)
            {
                anchorStartPoint = new Point((anchorEndPoint.X + anchorStartPoint.X) / 2, (anchorEndPoint.Y + anchorStartPoint.Y) / 2);
            }

            AnchorLineStroke.RenderTarget      = RenderTarget;
            RetracementLineStroke.RenderTarget = RenderTarget;

            // Align to full pixel to avoid unneeded aliasing
            double strokePixAdj   = AnchorLineStroke.Width % 2 == 0 ? 0.5d : 0d;
            Vector pixelAdjustVec = new Vector(strokePixAdj, strokePixAdj);

            SharpDX.Vector2         startVec = (anchorStartPoint + pixelAdjustVec).ToVector2();
            SharpDX.Vector2         endVec   = (anchorEndPoint + pixelAdjustVec).ToVector2();
            SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : AnchorLineStroke.BrushDX;

            SharpDX.Vector2 startOriginVec = (StartAnchor.GetPoint(chartControl, chartPanel, chartScale) + pixelAdjustVec).ToVector2();

            RenderTarget.DrawLine(startOriginVec, endVec, tmpBrush, AnchorLineStroke.Width, AnchorLineStroke.StrokeStyle);

            // Is second anchor set yet? Check both so we correctly re-draw during extension anchor editing
            if (ExtensionAnchor.IsEditing && EndAnchor.IsEditing)
            {
                return;
            }

            SharpDX.Vector2 extVector = anchorExtensionPoint.ToVector2();
            tmpBrush = IsInHitTest ? chartControl.SelectionBrush : RetracementLineStroke.BrushDX;
            RenderTarget.DrawLine(endVec, extVector, tmpBrush, RetracementLineStroke.Width, RetracementLineStroke.StrokeStyle);

            // If we're doing a hit test pass, don't draw price levels at all, we dont want those to count for
            // hit testing
            if (IsInHitTest || PriceLevels == null || !PriceLevels.Any())
            {
                return;
            }

            SetAllPriceLevelsRenderTarget();

            // Calculate total y range for % calculation on each level
            double totalPriceRange = EndAnchor.Price - ExtensionAnchor.Price;
            double startPrice      = ExtensionAnchor.Price;
            float  minLevelY       = float.MaxValue;
            float  maxLevelY       = float.MinValue;

            // Store values to use in correct render order
            Point  lastEndPoint   = new Point(0, 0);
            Point  lastStartPoint = new Point(0, 0);
            Stroke lastStroke     = null;
            List <Tuple <PriceLevel, Point> > textPoints = new List <Tuple <PriceLevel, Point> >();

            foreach (PriceLevel priceLevel in PriceLevels.Where(pl => pl.IsVisible && pl.Stroke != null).OrderBy(pl => pl.Value))
            {
                double levelPrice = (startPrice + ((priceLevel.Value / 100) * totalPriceRange));
                float  pixelY     = chartScale.GetYByValue(levelPrice);
                float  pixelX     = anchorExtensionPoint.X > anchorEndPoint.X ?
                                    priceLevel.Value >= 0 ? (float)(anchorExtensionPoint.X - (Math.Abs((anchorEndPoint.X - anchorExtensionPoint.X) * (priceLevel.Value / 100)))) : (float)(anchorExtensionPoint.X + ((anchorEndPoint.X - anchorExtensionPoint.X) * (priceLevel.Value / 100))):
                                    priceLevel.Value >= 0 ? (float)(anchorExtensionPoint.X + ((anchorEndPoint.X - anchorExtensionPoint.X) * (priceLevel.Value / 100))) : (float)(anchorExtensionPoint.X - (Math.Abs((anchorEndPoint.X - anchorExtensionPoint.X) * (priceLevel.Value / 100))));
                Point startPoint    = new Point(pixelX, pixelY);
                Point endPoint      = new Point(startPoint.X + (midPointExtension.X - anchorStartPoint.X), startPoint.Y + (midPointExtension.Y - anchorStartPoint.Y));
                Point maxLevelPoint = GetExtendedPoint(startPoint, endPoint);
                if (priceLevel.Value == 50)
                {
                    RenderTarget.DrawLine(startVec, maxLevelPoint.ToVector2(), priceLevel.Stroke.BrushDX, priceLevel.Stroke.Width, priceLevel.Stroke.StrokeStyle);
                }
                else
                {
                    RenderTarget.DrawLine(startPoint.ToVector2(), maxLevelPoint.ToVector2(), priceLevel.Stroke.BrushDX, priceLevel.Stroke.Width, priceLevel.Stroke.StrokeStyle);
                }

                if (lastStroke == null)
                {
                    lastStroke = new Stroke();
                }
                else
                {
                    SharpDX.Direct2D1.PathGeometry lineGeometry = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFactory);
                    SharpDX.Direct2D1.GeometrySink sink         = lineGeometry.Open();
                    sink.BeginFigure(lastEndPoint.ToVector2(), SharpDX.Direct2D1.FigureBegin.Filled);
                    // Does the fill color need to fill a corner?  Check and add a point
                    if (lastEndPoint.Y != maxLevelPoint.Y && lastEndPoint.X != maxLevelPoint.X)
                    {
                        double boundaryX;
                        double boundaryY;

                        if (lastEndPoint.Y <= ChartPanel.Y || lastEndPoint.Y >= ChartPanel.Y + ChartPanel.H)
                        {
                            boundaryY = lastEndPoint.Y;
                            boundaryX = maxLevelPoint.X;
                        }
                        else
                        {
                            boundaryY = maxLevelPoint.Y;
                            boundaryX = lastEndPoint.X;
                        }
                        sink.AddLine(new SharpDX.Vector2((float)boundaryX, (float)boundaryY));
                    }
                    sink.AddLine(maxLevelPoint.ToVector2());
                    sink.AddLine(startPoint.ToVector2());
                    sink.AddLine(lastStartPoint.ToVector2());
                    sink.EndFigure(SharpDX.Direct2D1.FigureEnd.Closed);
                    sink.Close();
                    RenderTarget.FillGeometry(lineGeometry, lastStroke.BrushDX);
                    lineGeometry.Dispose();
                }

                if (IsTextDisplayed)
                {
                    textPoints.Add(new Tuple <PriceLevel, Point>(priceLevel, maxLevelPoint));
                }

                priceLevel.Stroke.CopyTo(lastStroke);
                lastStroke.Opacity = PriceLevelOpacity;
                lastStartPoint     = startPoint;
                lastEndPoint       = maxLevelPoint;
                minLevelY          = Math.Min(pixelY, minLevelY);
                maxLevelY          = Math.Max(pixelY, maxLevelY);
            }

            // Render text last so it's on top of the price level colors
            if (IsTextDisplayed)
            {
                foreach (Tuple <PriceLevel, Point> textPoint in textPoints)
                {
                    DrawPriceLevelText(0, 0, textPoint.Item2, textPoint.Item1, chartPanel);
                }
            }
        }
示例#20
0
        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;
        }
示例#21
0
//		enum PositionDX {
//			Left, Center, Right;
//		}

        private void drawHistogram(List <double> list, string position, string title)
        {
            if (list.Count < 2)
            {
                return;
            }

            SharpDX.Vector2 startPoint;
            SharpDX.Vector2 endPoint;
            float           leadingSpace = 30.0f;

            //Print(ChartPanel.W);
            if (position == "Center")
            {
                leadingSpace = ChartPanel.W / 2;
            }
            if (position == "Right")
            {
                leadingSpace = ChartPanel.W - (ChartPanel.W / 4);
            }

            float halfHeight = ChartPanel.H / 4;
            float maxWidth   = ChartPanel.W / 8;

            Dictionary <double, double> Profile = listIntoSortedDict(list: list);
            var           mode    = Profile.OrderByDescending(x => x.Value).FirstOrDefault().Key;
            List <double> arr     = iBRanges;
            int           avg     = Convert.ToInt32(arr.Average());
            double        stdDev  = StandardDeviation(values: arr);
            double        stDevLo = mode - stdDev;

            if (stDevLo < 3)
            {
                stDevLo = 3;
            }
            double stDevHi = mode + stdDev;

            if (!IsInHitTest)
            {
                SharpDX.Direct2D1.Brush areaBrushDx;
                areaBrushDx = areaBrush.ToDxBrush(RenderTarget);
                SharpDX.Direct2D1.SolidColorBrush pocBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Red);
                SharpDX.Direct2D1.SolidColorBrush avgBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Goldenrod);
                SharpDX.Direct2D1.SolidColorBrush volBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Gray);

                int spacer = 20;

                float divisor = maxWidth / (float)Profile.Values.Max();

                textFormat = new TextFormat(Globals.DirectWriteFactory, "Arial", SharpDX.DirectWrite.FontWeight.Light,
                                            SharpDX.DirectWrite.FontStyle.Normal, SharpDX.DirectWrite.FontStretch.Normal, textSize)
                {
                    TextAlignment = SharpDX.DirectWrite.TextAlignment.Trailing,   //TextAlignment.Leading,
                    WordWrapping  = WordWrapping.NoWrap
                };

                textFormatSmaller = new TextFormat(Globals.DirectWriteFactory, "Arial", SharpDX.DirectWrite.FontWeight.Light,
                                                   SharpDX.DirectWrite.FontStyle.Normal, SharpDX.DirectWrite.FontStretch.Normal, textSize)
                {
                    TextAlignment = SharpDX.DirectWrite.TextAlignment.Trailing,   //TextAlignment.Leading,
                    WordWrapping  = WordWrapping.NoWrap
                };

                SharpDX.Direct2D1.Brush textBrushDx;
                textBrushDx = textBrush.ToDxBrush(RenderTarget);

                string unicodeString = "today";


                foreach (KeyValuePair <double, double> row in Profile)
                {
                    //Print(row.Value);
                    float rowSize = (float)row.Value * divisor;
                    spacer    += 15;
                    startPoint = new SharpDX.Vector2(ChartPanel.X + leadingSpace, halfHeight + spacer);
                    endPoint   = new SharpDX.Vector2(ChartPanel.X + rowSize + leadingSpace, halfHeight + spacer);

                    if (row.Key == mode)
                    {
                        areaBrushDx = pocBrush;
                    }
                    else if (row.Key == avg)
                    {
                        areaBrushDx = avgBrush;
                    }
                    else if (row.Key < stDevLo || row.Key > stDevHi)
                    {
                        areaBrushDx = volBrush;
                    }
                    else
                    {
                        areaBrushDx = areaBrush.ToDxBrush(RenderTarget);
                    }

                    drawRow(startPoint: startPoint, endPoint: endPoint, areaBrushDx: areaBrushDx);


                    // recurrence text
                    if ((int)row.Key == (int)ibRange)
                    {
                        float textStartPos      = (float)startPoint.Y - 10f;
                        float endPointIB        = 35f + (float)ibRange;
                        SharpDX.RectangleF rect = new SharpDX.RectangleF(0f, textStartPos, endPoint.X + endPointIB, 10f);
                        RenderTarget.DrawText("today", textFormatSmaller, rect, areaBrushDx);
                    }

                    if (row.Key == mode)
                    {
                        float commonBuffer = 40f;
                        if ((int)row.Key == (int)ibRange)
                        {
                            commonBuffer += 40f;
                        }
                        float textStartPos      = (float)startPoint.Y - 10f;
                        SharpDX.RectangleF rect = new SharpDX.RectangleF(0f, textStartPos, endPoint.X + commonBuffer, 10f);
                        RenderTarget.DrawText("poc", textFormatSmaller, rect, areaBrushDx);
                    }

                    if (row.Key == avg)
                    {
                        float commonBuffer = 40f;
                        if ((int)row.Key == (int)ibRange)
                        {
                            commonBuffer += 40f;
                        }
                        if ((int)row.Key == (int)mode)
                        {
                            commonBuffer += 40f;
                        }
                        float textStartPos      = (float)startPoint.Y - 10f;
                        SharpDX.RectangleF rect = new SharpDX.RectangleF(0f, textStartPos, endPoint.X + commonBuffer, 10f);
                        RenderTarget.DrawText("avg", textFormatSmaller, rect, areaBrushDx);
                    }

                    // value text
                    float textStartPos2      = (float)startPoint.Y - 10f;
                    SharpDX.RectangleF rect2 = new SharpDX.RectangleF(0f, textStartPos2, leadingSpace - 5f, 10f);
                    RenderTarget.DrawText(string.Format("{0}", row.Key), textFormat, rect2, areaBrushDx);
                }

                // end text
                //areaBrushDx = areaBrush.ToDxBrush(RenderTarget);
                SharpDX.RectangleF rect3 = new SharpDX.RectangleF(0f, halfHeight + spacer + 15f, 245, 10f);
                RenderTarget.DrawText(dayCount + " day " + title + " distribution", textFormat, rect3, areaBrushDx);

                areaBrushDx.Dispose();
                textBrushDx.Dispose();
                pocBrush.Dispose();
                avgBrush.Dispose();
                volBrush.Dispose();
            }
        }
 public static MathObjects.Vector2 Vector2SDXtoEUC(this SharpDX.Vector2 vec)
 {
     return(new MathObjects.Vector2(vec.X, vec.Y));
 }
示例#23
0
 private void drawRow(SharpDX.Vector2 startPoint, SharpDX.Vector2 endPoint, SharpDX.Direct2D1.Brush areaBrushDx)
 {
     RenderTarget.DrawLine(startPoint, endPoint, areaBrushDx, 10);
 }
示例#24
0
 public static double DistanceSquared(SharpDX.Vector2 v1, SharpDX.Vector2 v2)
 {
     return(Math.Pow(v1.X - v2.X, 2) + Math.Pow(v1.Y - v2.Y, 2));
 }
示例#25
0
    protected override void ArrangeOverride()
    {
      base.ArrangeOverride();
      float offsetTop = 0.0f;
      float offsetLeft = 0.0f;
      float offsetRight = 0.0f;
      float offsetBottom = 0.0f;
      SizeF availableSize = new SizeF(_innerRect.Width, _innerRect.Height);

      int count = 0;
      // Area allocated to child
      SizeF childArea;

      IList<FrameworkElement> visibleChildren = GetVisibleChildren();
      foreach (FrameworkElement child in visibleChildren)
      {
        count++;
        //Trace.WriteLine(String.Format("DockPanel:arrange {0} {1}", count, child.Name));

        // Size of the child
        SizeF childSize = child.DesiredSize;

        switch (GetDock(child))
        {
          case Dock.Top:
            {
              PointF location = new PointF(offsetLeft, offsetTop);
              location.X += ActualPosition.X;
              location.Y += ActualPosition.Y;

              // Allocate area to child
              if (count == visibleChildren.Count && LastChildFill)
                childArea = new SizeF(availableSize.Width, availableSize.Height);
              else
                childArea = new SizeF(availableSize.Width, childSize.Height);

              // Position the child within the child area
              ArrangeChildHorizontal(child, child.HorizontalAlignment, ref location, ref childArea);
              child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea));

              offsetTop += childArea.Height;
              availableSize.Height -= childArea.Height;
            }
            break;
          case Dock.Bottom:
            {
              PointF location;
              if (count == visibleChildren.Count && LastChildFill)
                location = new PointF(offsetLeft, _innerRect.Height - (offsetBottom + availableSize.Height));
              else
                location = new PointF(offsetLeft, _innerRect.Height - (offsetBottom + childSize.Height));

              location.X += ActualPosition.X;
              location.Y += ActualPosition.Y;

              // Allocate area to child
              if (count == visibleChildren.Count && LastChildFill)
                childArea = new SizeF(availableSize.Width, availableSize.Height);
              else
                childArea = new SizeF(availableSize.Width, childSize.Height);

              // Position the child within the child area
              ArrangeChildHorizontal(child, child.HorizontalAlignment, ref location, ref childArea);
              child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea));

              offsetBottom += childArea.Height;
              availableSize.Height -= childArea.Height;
            }
            break;
          case Dock.Left:
            {
              PointF location = new PointF(offsetLeft, offsetTop);
              location.X += ActualPosition.X;
              location.Y += ActualPosition.Y;

              // Allocate area to child
              if (count == visibleChildren.Count && LastChildFill)
                childArea = new SizeF(availableSize.Width, availableSize.Height);
              else
                childArea = new SizeF(childSize.Width, availableSize.Height);

              // Position the child within the child area
              ArrangeChildVertical(child, child.VerticalAlignment, ref location, ref childArea);
              child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea));

              offsetLeft += childArea.Width;
              availableSize.Width -= childArea.Width;
            }
            break;
          case Dock.Right:
            {
              PointF location;
              if (count == visibleChildren.Count && LastChildFill)
                location = new PointF(_innerRect.Width - (offsetRight + availableSize.Width), offsetTop);
              else
                location = new PointF(_innerRect.Width - (offsetRight + childSize.Width), offsetTop);
              location.X += ActualPosition.X;
              location.Y += ActualPosition.Y;

              // Allocate area to child
              if (count == visibleChildren.Count && LastChildFill)
                childArea = new SizeF(availableSize.Width,availableSize.Height);
              else
                childArea = new SizeF(childSize.Width,availableSize.Height);

              // Position the child within the child area
              ArrangeChildVertical(child, child.VerticalAlignment, ref location, ref childArea);
              child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea));

              offsetRight += childArea.Width;
              availableSize.Width -= childArea.Width;
            }
            break;
          default: // Dock.Center
            {
              PointF location = new PointF(offsetLeft, offsetTop);
              location.X += ActualPosition.X;
              location.Y += ActualPosition.Y;
              childSize = new SizeF(availableSize.Width, availableSize.Height);
              if (count == visibleChildren.Count && LastChildFill)
                child.Arrange(SharpDXExtensions.CreateRectangleF(location, childSize));
              else
              {
                ArrangeChild(child, child.HorizontalAlignment, child.VerticalAlignment, ref location, ref childSize);
                child.Arrange(SharpDXExtensions.CreateRectangleF(location, childSize));
              }

              // Do not remove child size from a border offset or from size - the child will
              // stay in the "empty space" without taking place from the border layouting variables
            }
            break;
        }
      }
    }
示例#26
0
        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;

            ChartPanel panel       = chartControl.ChartPanels[PanelIndex];
            Point      anchorPoint = Anchor.GetPoint(chartControl, panel, chartScale);

            Point lastEndPoint = new Point(0, 0);

            SharpDX.Direct2D1.Brush lastBrush = null;
            foreach (GannAngle gannAngle in GannAngles.Where(ga => ga.IsVisible && ga.Stroke != null).OrderBy(ga => (ga.RatioX / ga.RatioY)))
            {
                gannAngle.Stroke.RenderTarget = RenderTarget;

                double dx               = gannAngle.RatioX * chartControl.Properties.BarDistance;
                double dVal             = gannAngle.RatioY * PointsPerBar;                                //NT7, just multiple directly this is price not pixels //chartScale.GetPixelsForDistance(gannAngle.RatioY * PointsPerBar);
                Vector gannDataVector   = GetGannStepDataVector(dx, dVal);
                Point  extendedEndPoint = CalculateExtendedDataPoint(panel, chartScale, Convert.ToInt32(anchorPoint.X), Anchor.Price, gannDataVector);

                // align to full pixel to avoid unneeded aliasing
                double strokePixAdj   = ((double)(gannAngle.Stroke.Width % 2)).ApproxCompare(0) == 0 ? 0.5d : 0d;
                Vector pixelAdjustVec = new Vector(0, strokePixAdj);

                SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : gannAngle.Stroke.BrushDX;
                RenderTarget.DrawLine((anchorPoint + pixelAdjustVec).ToVector2(), (extendedEndPoint + pixelAdjustVec).ToVector2(), tmpBrush, gannAngle.Stroke.Width, gannAngle.Stroke.StrokeStyle);

                if (lastBrush != null)
                {
                    float oldOpacity = lastBrush.Opacity;
                    lastBrush.Opacity = PriceLevelOpacity / 100f;

                    // create geometry
                    SharpDX.Direct2D1.PathGeometry lineGeometry = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFactory);
                    SharpDX.Direct2D1.GeometrySink sink         = lineGeometry.Open();
                    sink.BeginFigure(lastEndPoint.ToVector2(), SharpDX.Direct2D1.FigureBegin.Filled);
                    // Does the fill color need to fill a corner?  Check and add a point
                    if (Math.Abs(lastEndPoint.Y - extendedEndPoint.Y) > 0.1 && Math.Abs(lastEndPoint.X - extendedEndPoint.X) > 0.1)
                    {
                        double boundaryX;
                        double boundaryY;

                        if (lastEndPoint.Y <= ChartPanel.Y || lastEndPoint.Y >= ChartPanel.Y + ChartPanel.H)
                        {
                            if (FanDirection == GannFanDirection.UpLeft || FanDirection == GannFanDirection.UpRight)
                            {
                                boundaryY = extendedEndPoint.Y;
                                boundaryX = lastEndPoint.X;
                            }
                            else
                            {
                                boundaryY = lastEndPoint.Y;
                                boundaryX = extendedEndPoint.X;
                            }
                        }
                        else
                        {
                            if (FanDirection == GannFanDirection.UpLeft || FanDirection == GannFanDirection.UpRight)
                            {
                                boundaryY = lastEndPoint.Y;
                                boundaryX = extendedEndPoint.X;
                            }
                            else
                            {
                                boundaryY = extendedEndPoint.Y;
                                boundaryX = lastEndPoint.X;
                            }
                        }
                        sink.AddLine(new SharpDX.Vector2((float)boundaryX, (float)boundaryY));
                    }

                    sink.AddLine(extendedEndPoint.ToVector2());
                    sink.AddLine((anchorPoint + pixelAdjustVec).ToVector2());
                    sink.AddLine((lastEndPoint).ToVector2());
                    sink.EndFigure(SharpDX.Direct2D1.FigureEnd.Closed);
                    sink.Close();
                    RenderTarget.FillGeometry(lineGeometry, lastBrush);
                    lineGeometry.Dispose();

                    lastBrush.Opacity = oldOpacity;
                }
                lastEndPoint = extendedEndPoint + pixelAdjustVec;
                lastBrush    = tmpBrush;
            }

            if (!IsTextDisplayed || IsInHitTest)
            {
                return;
            }

            foreach (GannAngle gannAngle in GannAngles.Where(ga => ga.IsVisible && ga.Stroke != null).OrderBy(ga => (ga.RatioX / ga.RatioY)))
            {
                gannAngle.Stroke.RenderTarget = RenderTarget;
                double dx               = gannAngle.RatioX * chartControl.Properties.BarDistance;
                double dVal             = gannAngle.RatioY * PointsPerBar;                                //NT7, just multiple directly this is price not pixels //chartScale.GetPixelsForDistance(gannAngle.RatioY * PointsPerBar);
                Vector gannDataVector   = GetGannStepDataVector(dx, dVal);
                Point  extendedEndPoint = CalculateExtendedDataPoint(panel, chartScale, Convert.ToInt32(anchorPoint.X), Anchor.Price, gannDataVector);

                if (!IsTextDisplayed || IsInHitTest)
                {
                    continue;
                }

                SimpleFont wpfFont = chartControl.Properties.LabelFont ?? new SimpleFont();
                SharpDX.DirectWrite.TextFormat textFormat = wpfFont.ToDirectWriteTextFormat();
                textFormat.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading;
                textFormat.WordWrapping  = SharpDX.DirectWrite.WordWrapping.NoWrap;
                SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout(Core.Globals.DirectWriteFactory, gannAngle.Name, textFormat, 100, textFormat.FontSize);

                // once text is laid out, update used width to calcuated space required
                float fontHeight = textLayout.Metrics.Height;

                Point textEndPoint = new Point(extendedEndPoint.X, extendedEndPoint.Y);

                if (textEndPoint.X > panel.X + panel.W - textLayout.Metrics.Width)
                {
                    textEndPoint.X  = panel.X + panel.W - textLayout.Metrics.Width;
                    textEndPoint.Y += textLayout.Metrics.Width;
                }

                if (gannDataVector.Y > 0)
                {
                    if (textEndPoint.Y < panel.Y + (fontHeight * 0.5))
                    {
                        textEndPoint.Y = panel.Y + (fontHeight * 0.5);
                    }
                }
                else
                {
                    if (textEndPoint.Y > panel.Y + panel.H - (fontHeight * 1.5))
                    {
                        textEndPoint.Y = panel.Y + panel.H - (fontHeight * 1.5);
                    }
                }

                float?marginResource = Application.Current.FindResource("FontModalTitleMargin") as float?;
                float margin         = 2f + (marginResource.HasValue ? marginResource.Value : 3f);
                // Allow for changes in X position based on whether text is aligned to left or right edge of screen
                float marginX = FanDirection == GannFanDirection.DownLeft || FanDirection == GannFanDirection.UpLeft ? margin : -2 * margin;

                SharpDX.Vector2   endVec          = new SharpDX.Vector2((float)textEndPoint.X, (float)textEndPoint.Y);
                SharpDX.Matrix3x2 transformMatrix = SharpDX.Matrix3x2.Translation(endVec);

                RenderTarget.Transform = transformMatrix;

                RenderTarget.DrawTextLayout(new SharpDX.Vector2(marginX + margin, margin), textLayout, gannAngle.Stroke.BrushDX, SharpDX.Direct2D1.DrawTextOptions.NoSnap);

                RenderTarget.Transform = SharpDX.Matrix3x2.Identity;
                textFormat.Dispose();
                textLayout.Dispose();
            }
        }
示例#27
0
 public OnpuObject(PPDDevice device, PPDFramework.Resource.ResourceManager resourceManager, PathObject filename, float x, float y, bool center)
     : base(device, resourceManager, filename, center)
 {
     Position = new SharpDX.Vector2(x, y);
 }
示例#28
0
 /// <unmanaged>HRESULT ID2D1CommandSink::DrawLine([In] D2D_POINT_2F point0,[In] D2D_POINT_2F point1,[In] ID2D1Brush* brush,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged>
 public void DrawLine(SharpDX.Vector2 point0, SharpDX.Vector2 point1, SharpDX.Direct2D1.Brush brush, float strokeWidth, SharpDX.Direct2D1.StrokeStyle strokeStyle)
 {
     DrawLine_(point0, point1, brush, strokeWidth, strokeStyle);
 }
示例#29
0
        protected override void ArrangeChildren()
        {
            bool fireScrolled = false;

            lock (Children.SyncRoot)
            {
                if (ItemProvider == null)
                {
                    base.ArrangeChildren();
                    return;
                }

                _totalHeight = 0;
                _totalWidth  = 0;
                int numItems = ItemProvider.NumItems;
                if (numItems > 0)
                {
                    PointF actualPosition = ActualPosition;
                    SizeF  actualSize     = new SizeF((float)ActualWidth, (float)ActualHeight);

                    // For Orientation == vertical, this is ActualHeight, for horizontal it is ActualWidth
                    float actualExtendsInOrientationDirection = GetExtendsInOrientationDirection(Orientation, actualSize);
                    // For Orientation == vertical, this is ActualWidth, for horizontal it is ActualHeight
                    float actualExtendsInNonOrientationDirection = GetExtendsInNonOrientationDirection(Orientation, actualSize);
                    // Hint: We cannot skip the arrangement of lines above _actualFirstVisibleLineIndex or below _actualLastVisibleLineIndex
                    // because the rendering and focus system also needs the bounds of the currently invisible children
                    float startPosition = 0;
                    // If set to true, we'll check available space from the last to first visible child.
                    // That is necessary if we want to scroll a specific child to the last visible position.
                    bool invertLayouting = false;
                    lock (_renderLock)
                        if (_pendingScrollIndex.HasValue)
                        {
                            fireScrolled = true;
                            int pendingSI = _pendingScrollIndex.Value;
                            if (_scrollToFirst)
                            {
                                _actualFirstVisibleLineIndex = pendingSI;
                            }
                            else
                            {
                                _actualLastVisibleLineIndex = pendingSI;
                                invertLayouting             = true;
                            }
                            _pendingScrollIndex = null;
                        }

                    int itemsPerLine = 0;
                    // if we haven't arranged any lines previously - items per line can't be calculated yet, but is not needed
                    if (_firstArrangedLineIndex >= 0)
                    {
                        // to calculate the starting index of elements for a line we assume that every line (until the last) has the same number of items
                        itemsPerLine = _arrangedLines[_firstArrangedLineIndex].EndIndex - _arrangedLines[_firstArrangedLineIndex].StartIndex + 1;
                        _assumedLineExtendsInNonOrientationDirection = _arrangedLines[_firstArrangedLineIndex].TotalExtendsInNonOrientationDirection;
                    }

                    // scrolling may have set an invalid index for the first visible line
                    if (_actualFirstVisibleLineIndex < 0)
                    {
                        _actualFirstVisibleLineIndex = 0;
                    }
                    if (itemsPerLine > 0)
                    {
                        int linesPerPage = (int)Math.Floor(actualExtendsInNonOrientationDirection / _assumedLineExtendsInNonOrientationDirection);
                        int maxLineIndex = (int)Math.Ceiling((float)numItems / itemsPerLine);
                        if (_actualFirstVisibleLineIndex > maxLineIndex - linesPerPage)
                        {
                            _actualFirstVisibleLineIndex = Math.Max(maxLineIndex - linesPerPage, 0);
                        }
                    }

                    // clear values from previous arrange
                    _arrangedItems = new FrameworkElement[numItems];
                    _arrangedLines.Clear();
                    _firstArrangedLineIndex = 0;
                    _lastArrangedLineIndex  = 0;

                    // 1) Calculate scroll indices
                    if (_doScroll)
                    { // Calculate last visible child
                        float spaceLeft = actualExtendsInNonOrientationDirection;
                        if (invertLayouting)
                        {
                            if (_actualLastVisibleLineIndex == int.MaxValue) // when scroll to last item (END) was requested
                            {
                                _actualLastVisibleLineIndex = (int)Math.Ceiling((float)numItems / itemsPerLine) - 1;
                            }
                            _actualFirstVisibleLineIndex = _actualLastVisibleLineIndex + 1;
                            int currentLineIndex = _actualLastVisibleLineIndex;
                            _lastArrangedLineIndex = currentLineIndex;
                            while (_arrangedLines.Count <= currentLineIndex)
                            {
                                _arrangedLines.Add(new LineMeasurement());                                // add "unarranged lines" up to the last visible
                            }
                            int itemIndex             = currentLineIndex * itemsPerLine;
                            int additionalLinesBefore = 0;
                            while (currentLineIndex >= 0 && additionalLinesBefore < NUM_ADD_MORE_FOCUS_LINES)
                            {
                                LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false);
                                _arrangedLines[currentLineIndex] = line;

                                _firstArrangedLineIndex = currentLineIndex;

                                currentLineIndex--;
                                itemIndex = line.StartIndex - itemsPerLine;

                                spaceLeft -= line.TotalExtendsInNonOrientationDirection;
                                if (spaceLeft + DELTA_DOUBLE < 0)
                                {
                                    additionalLinesBefore++;
                                }
                                else
                                {
                                    _actualFirstVisibleLineIndex--;
                                }
                            }
                            // now add NUM_ADD_MORE_FOCUS_LINES after last visible
                            itemIndex = _arrangedLines[_lastArrangedLineIndex].EndIndex + 1;
                            int additionalLinesAfterwards = 0;
                            while (itemIndex < numItems && additionalLinesAfterwards < NUM_ADD_MORE_FOCUS_LINES)
                            {
                                LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false);
                                _arrangedLines.Add(line);
                                _lastArrangedLineIndex = _arrangedLines.Count - 1;
                                itemIndex = line.EndIndex + 1;
                                additionalLinesAfterwards++;
                            }
                        }
                        else
                        {
                            _actualLastVisibleLineIndex = _actualFirstVisibleLineIndex - 1;
                            _firstArrangedLineIndex     = Math.Max(_actualFirstVisibleLineIndex - NUM_ADD_MORE_FOCUS_LINES, 0);
                            int currentLineIndex = _firstArrangedLineIndex;
                            // add "unarranges lines" up until where we start
                            while (_arrangedLines.Count < currentLineIndex)
                            {
                                _arrangedLines.Add(new LineMeasurement());
                            }
                            int itemIndex = currentLineIndex * itemsPerLine;
                            int additionalLinesAfterwards = 0;
                            while (itemIndex < numItems && additionalLinesAfterwards < NUM_ADD_MORE_FOCUS_LINES)
                            {
                                LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false);
                                _arrangedLines.Add(line);

                                _lastArrangedLineIndex = currentLineIndex;

                                currentLineIndex++;
                                itemIndex = line.EndIndex + 1;

                                if (currentLineIndex > _actualFirstVisibleLineIndex)
                                {
                                    spaceLeft -= line.TotalExtendsInNonOrientationDirection;
                                    if (spaceLeft + DELTA_DOUBLE < 0)
                                    {
                                        additionalLinesAfterwards++;
                                    }
                                    else
                                    {
                                        _actualLastVisibleLineIndex++;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        _actualFirstVisibleLineIndex = 0;
                        _actualLastVisibleLineIndex  = _arrangedLines.Count - 1;
                    }

                    // now we know items per line for sure so just calculate it
                    itemsPerLine = _arrangedLines[_firstArrangedLineIndex].EndIndex - _arrangedLines[_firstArrangedLineIndex].StartIndex + 1;
                    _assumedLineExtendsInNonOrientationDirection = _arrangedLines[_firstArrangedLineIndex].TotalExtendsInNonOrientationDirection;

                    // 2) Calculate start position (so the first visible line starts at 0)
                    startPosition -= (_actualFirstVisibleLineIndex - _firstArrangedLineIndex) * _assumedLineExtendsInNonOrientationDirection;

                    // 3) Arrange children
                    if (Orientation == Orientation.Vertical)
                    {
                        _totalHeight = actualExtendsInOrientationDirection;
                    }
                    else
                    {
                        _totalWidth = actualExtendsInOrientationDirection;
                    }
                    PointF position = Orientation == Orientation.Vertical ?
                                      new PointF(actualPosition.X + startPosition, actualPosition.Y) :
                                      new PointF(actualPosition.X, actualPosition.Y + startPosition);
                    foreach (LineMeasurement line in _arrangedLines.Skip(_firstArrangedLineIndex).Take(_lastArrangedLineIndex - _firstArrangedLineIndex + 1))
                    {
                        LayoutLine(position, line);

                        startPosition += line.TotalExtendsInNonOrientationDirection;
                        if (Orientation == Orientation.Vertical)
                        {
                            position = new PointF(actualPosition.X + startPosition, actualPosition.Y);
                        }
                        else
                        {
                            position = new PointF(actualPosition.X, actualPosition.Y + startPosition);
                        }
                    }

                    // estimate the desired size
                    var estimatedExtendsInNonOrientationDirection = (float)Math.Ceiling((float)numItems / itemsPerLine) * _assumedLineExtendsInNonOrientationDirection;
                    if (Orientation == Orientation.Horizontal)
                    {
                        _totalHeight = estimatedExtendsInNonOrientationDirection;
                    }
                    else
                    {
                        _totalWidth = estimatedExtendsInNonOrientationDirection;
                    }

                    // keep one more item, because we did use it in CalcLine (and need always one more to find the last item not fitting on the line)
                    // -> if we dont, it will always be newlyCreated and we keep calling Arrange since the new item recursively sets the parent invalid
                    _itemProvider.Keep(_arrangedLines[_firstArrangedLineIndex].StartIndex, _arrangedLines[_lastArrangedLineIndex].EndIndex + 1);
                }
                else
                {
                    _actualFirstVisibleLineIndex = 0;
                    _actualLastVisibleLineIndex  = -1;
                }
            }
            if (fireScrolled)
            {
                InvokeScrolled();
            }
        }
    protected override void ArrangeChildren()
    {
      bool fireScrolled = false;
      lock (Children.SyncRoot)
      {
        if (ItemProvider == null)
        {
          base.ArrangeChildren();
          return;
        }

        _totalHeight = 0;
        _totalWidth = 0;
        int numItems = ItemProvider.NumItems;
        if (numItems > 0)
        {
          PointF actualPosition = ActualPosition;
          SizeF actualSize = new SizeF((float)ActualWidth, (float)ActualHeight);

          // For Orientation == vertical, this is ActualHeight, for horizontal it is ActualWidth
          float actualExtendsInOrientationDirection = GetExtendsInOrientationDirection(Orientation, actualSize);
          // For Orientation == vertical, this is ActualWidth, for horizontal it is ActualHeight
          float actualExtendsInNonOrientationDirection = GetExtendsInNonOrientationDirection(Orientation, actualSize);
          // Hint: We cannot skip the arrangement of lines above _actualFirstVisibleLineIndex or below _actualLastVisibleLineIndex
          // because the rendering and focus system also needs the bounds of the currently invisible children
          float startPosition = 0;
          // If set to true, we'll check available space from the last to first visible child.
          // That is necessary if we want to scroll a specific child to the last visible position.
          bool invertLayouting = false;
          lock (_renderLock)
            if (_pendingScrollIndex.HasValue)
            {
              fireScrolled = true;
              int pendingSI = _pendingScrollIndex.Value;
              if (_scrollToFirst)
                _actualFirstVisibleLineIndex = pendingSI;
              else
              {
                _actualLastVisibleLineIndex = pendingSI;
                invertLayouting = true;
              }
              _pendingScrollIndex = null;
            }

          int itemsPerLine = 0;
          // if we haven't arranged any lines previously - items per line can't be calculated yet, but is not needed
          if (_firstArrangedLineIndex >= 0)
          {
            // to calculate the starting index of elements for a line we assume that every line (until the last) has the same number of items
            itemsPerLine = _arrangedLines[_firstArrangedLineIndex].EndIndex - _arrangedLines[_firstArrangedLineIndex].StartIndex + 1;
            _assumedLineExtendsInNonOrientationDirection = _arrangedLines[_firstArrangedLineIndex].TotalExtendsInNonOrientationDirection;
          }

          // scrolling may have set an invalid index for the first visible line
          if (_actualFirstVisibleLineIndex < 0) _actualFirstVisibleLineIndex = 0;
          if (itemsPerLine > 0)
          {
            int linesPerPage = (int)Math.Floor(actualExtendsInNonOrientationDirection / _assumedLineExtendsInNonOrientationDirection);
            int maxLineIndex = (int)Math.Ceiling((float)numItems / itemsPerLine);
            if (_actualFirstVisibleLineIndex > maxLineIndex - linesPerPage)
            {
              _actualFirstVisibleLineIndex = Math.Max(maxLineIndex - linesPerPage, 0);
            }
          }

          // clear values from previous arrange
          _arrangedItems = new FrameworkElement[numItems];
          _arrangedLines.Clear();
          _firstArrangedLineIndex = 0;
          _lastArrangedLineIndex = 0;

          // 1) Calculate scroll indices
          if (_doScroll)
          { // Calculate last visible child
            float spaceLeft = actualExtendsInNonOrientationDirection;
            if (invertLayouting)
            {
              if (_actualLastVisibleLineIndex == int.MaxValue) // when scroll to last item (END) was requested
                _actualLastVisibleLineIndex = (int)Math.Ceiling((float)numItems / itemsPerLine) - 1;
              _actualFirstVisibleLineIndex = _actualLastVisibleLineIndex + 1;
              int currentLineIndex = _actualLastVisibleLineIndex;
              _lastArrangedLineIndex = currentLineIndex;
              while (_arrangedLines.Count <= currentLineIndex) _arrangedLines.Add(new LineMeasurement()); // add "unarranged lines" up to the last visible
              int itemIndex = currentLineIndex * itemsPerLine;
              int additionalLinesBefore = 0;
              while (currentLineIndex >= 0 && additionalLinesBefore < NUM_ADD_MORE_FOCUS_LINES)
              {
                LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false);
                _arrangedLines[currentLineIndex] = line;

                _firstArrangedLineIndex = currentLineIndex;

                currentLineIndex--;
                itemIndex = line.StartIndex - itemsPerLine;

                spaceLeft -= line.TotalExtendsInNonOrientationDirection;
                if (spaceLeft + DELTA_DOUBLE < 0)
                  additionalLinesBefore++;
                else
                  _actualFirstVisibleLineIndex--;
              }
              // now add NUM_ADD_MORE_FOCUS_LINES after last visible
              itemIndex = _arrangedLines[_lastArrangedLineIndex].EndIndex + 1;
              int additionalLinesAfterwards = 0;
              while (itemIndex < numItems && additionalLinesAfterwards < NUM_ADD_MORE_FOCUS_LINES)
              {
                LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false);
                _arrangedLines.Add(line);
                _lastArrangedLineIndex = _arrangedLines.Count - 1;
                itemIndex = line.EndIndex + 1;
                additionalLinesAfterwards++;
              }
            }
            else
            {
              _actualLastVisibleLineIndex = _actualFirstVisibleLineIndex - 1;
              _firstArrangedLineIndex = Math.Max(_actualFirstVisibleLineIndex - NUM_ADD_MORE_FOCUS_LINES, 0);
              int currentLineIndex = _firstArrangedLineIndex;
              // add "unarranges lines" up until where we start
              while (_arrangedLines.Count < currentLineIndex) _arrangedLines.Add(new LineMeasurement());
              int itemIndex = currentLineIndex * itemsPerLine;
              int additionalLinesAfterwards = 0;
              while (itemIndex < numItems && additionalLinesAfterwards < NUM_ADD_MORE_FOCUS_LINES)
              {
                LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false);
                _arrangedLines.Add(line);

                _lastArrangedLineIndex = currentLineIndex;

                currentLineIndex++;
                itemIndex = line.EndIndex + 1;

                if (currentLineIndex > _actualFirstVisibleLineIndex)
                {
                  spaceLeft -= line.TotalExtendsInNonOrientationDirection;
                  if (spaceLeft + DELTA_DOUBLE < 0)
                    additionalLinesAfterwards++;
                  else
                    _actualLastVisibleLineIndex++;
                }
              }
            }
          }
          else
          {
            _actualFirstVisibleLineIndex = 0;
            _actualLastVisibleLineIndex = _arrangedLines.Count - 1;
          }

          // now we know items per line for sure so just calculate it
          itemsPerLine = _arrangedLines[_firstArrangedLineIndex].EndIndex - _arrangedLines[_firstArrangedLineIndex].StartIndex + 1;
          _assumedLineExtendsInNonOrientationDirection = _arrangedLines[_firstArrangedLineIndex].TotalExtendsInNonOrientationDirection;

          // 2) Calculate start position (so the first visible line starts at 0)
          startPosition -= (_actualFirstVisibleLineIndex - _firstArrangedLineIndex) * _assumedLineExtendsInNonOrientationDirection;

          // 3) Arrange children
          if (Orientation == Orientation.Vertical)
            _totalHeight = actualExtendsInOrientationDirection;
          else
            _totalWidth = actualExtendsInOrientationDirection;
          PointF position = Orientation == Orientation.Vertical ?
              new PointF(actualPosition.X + startPosition, actualPosition.Y) :
              new PointF(actualPosition.X, actualPosition.Y + startPosition);
          foreach (LineMeasurement line in _arrangedLines.Skip(_firstArrangedLineIndex).Take(_lastArrangedLineIndex - _firstArrangedLineIndex + 1))
          {
            LayoutLine(position, line);

            startPosition += line.TotalExtendsInNonOrientationDirection;
            if (Orientation == Orientation.Vertical)
              position = new PointF(actualPosition.X + startPosition, actualPosition.Y);
            else
              position = new PointF(actualPosition.X, actualPosition.Y + startPosition);
          }

          // estimate the desired size
          var estimatedExtendsInNonOrientationDirection = (float)Math.Ceiling((float)numItems / itemsPerLine) * _assumedLineExtendsInNonOrientationDirection;
          if (Orientation == Orientation.Horizontal)
            _totalHeight = estimatedExtendsInNonOrientationDirection;
          else
            _totalWidth = estimatedExtendsInNonOrientationDirection;

          // keep one more item, because we did use it in CalcLine (and need always one more to find the last item not fitting on the line)
          // -> if we dont, it will always be newlyCreated and we keep calling Arrange since the new item recursively sets the parent invalid
          _itemProvider.Keep(_arrangedLines[_firstArrangedLineIndex].StartIndex, _arrangedLines[_lastArrangedLineIndex].EndIndex + 1);
        }
        else
        {
          _actualFirstVisibleLineIndex = 0;
          _actualLastVisibleLineIndex = -1;
        }
      }
      if (fireScrolled)
        InvokeScrolled();
    }
示例#31
0
 public static Vector2 ToSystem(this SharpDX.Vector2 vec) => new Vector2(vec.X, vec.Y);
示例#32
0
        /// <summary>
        /// Converts screen coordinates to in-world coordinates via raycasting.
        /// </summary>
        /// <param name="screenPos">Screen coordinates.</param>
        /// <param name="worldPos">Converted coordinates.</param>
        /// <param name="rayDistance">How far to search for a collision.</param>
        /// <returns>True if successful. On false, worldPos's contents are undefined.</returns>
        public bool ScreenToWorld(SharpDX.Vector2 screenPos, out SharpDX.Vector3 worldPos, float rayDistance = 100000.0f)
        {
            // The game is only visible in the main viewport, so if the cursor is outside
            // of the game window, do not bother calculating anything
            var windowPos  = ImGuiHelpers.MainViewport.Pos;
            var windowSize = ImGuiHelpers.MainViewport.Size;

            if (screenPos.X < windowPos.X || screenPos.X > windowPos.X + windowSize.X ||
                screenPos.Y < windowPos.Y || screenPos.Y > windowPos.Y + windowSize.Y)
            {
                worldPos = default;
                return(false);
            }

            // Get base object with matrices
            var matrixSingleton = this.getMatrixSingleton();

            // Read current ViewProjectionMatrix plus game window size
            var   viewProjectionMatrix = default(SharpDX.Matrix);
            float width, height;

            unsafe
            {
                var rawMatrix = (float *)(matrixSingleton + 0x1b4).ToPointer();

                for (var i = 0; i < 16; i++, rawMatrix++)
                {
                    viewProjectionMatrix[i] = *rawMatrix;
                }

                width  = *rawMatrix;
                height = *(rawMatrix + 1);
            }

            viewProjectionMatrix.Invert();

            var localScreenPos = new SharpDX.Vector2(screenPos.X - windowPos.X, screenPos.Y - windowPos.Y);
            var screenPos3D    = new SharpDX.Vector3
            {
                X = (localScreenPos.X / width * 2.0f) - 1.0f,
                Y = -((localScreenPos.Y / height * 2.0f) - 1.0f),
                Z = 0,
            };

            SharpDX.Vector3.TransformCoordinate(ref screenPos3D, ref viewProjectionMatrix, out var camPos);

            screenPos3D.Z = 1;
            SharpDX.Vector3.TransformCoordinate(ref screenPos3D, ref viewProjectionMatrix, out var camPosOne);

            var clipPos = camPosOne - camPos;

            clipPos.Normalize();

            bool isSuccess;

            unsafe
            {
                var camPosArray  = camPos.ToArray();
                var clipPosArray = clipPos.ToArray();

                // This array is larger than necessary because it contains more info than we currently use
                var worldPosArray = stackalloc float[32];

                // Theory: this is some kind of flag on what type of things the ray collides with
                var unknown = stackalloc int[3]
                {
                    0x4000,
                    0x4000,
                    0x0,
                };

                fixed(float *pCamPos = camPosArray)
                {
                    fixed(float *pClipPos = clipPosArray)
                    {
                        isSuccess = this.screenToWorldNative(pCamPos, pClipPos, rayDistance, worldPosArray, unknown);
                    }
                }

                worldPos = new SharpDX.Vector3
                {
                    X = worldPosArray[0],
                    Y = worldPosArray[1],
                    Z = worldPosArray[2],
                };
            }

            return(isSuccess);
        }
示例#33
0
 public void Draw(Drawing.IDrawingContext dc, SharpDX.Vector2 where, int strokeWidth = 1)
 {
     _rectangle.Location = where;
     dc.DrawRectangle(this._rectangle, where);
 }
示例#34
0
        internal static void AtoB(this Spell spell, Obj_AI_Base T, float Drag = 700f) //Coded By RL244 AtoB Drag 기본값 700f는 빅토르를 위한 것임.
        {
            if (T != null)
            {
                var TH = T as AIHeroClient;
                var TM = T as Obj_AI_Minion;
                if (TH != null)
                {
                    var             TH2      = HeroManager.Enemies.Where(x => x != TH && Func.CanHit(spell, x, Drag)).FirstOrDefault();
                    var             THdelay  = (Player.Distance(TH.ServerPosition) > spell.Range ? (Player.Distance(TH.ServerPosition) - spell.Range) / spell.Speed : 100f / spell.Speed);
                    var             pred     = Prediction.GetPrediction(TH, THdelay + spell.Delay);
                    var             TH2delay = (TH2 != null ? (Player.Distance(TH.ServerPosition) > spell.Range ? (Player.Distance(TH2.ServerPosition) - spell.Range) / spell.Speed : TH2.ServerPosition.Distance(TH.ServerPosition) / spell.Speed) : 0f);
                    var             TH2pred  = (TH2 != null ? Prediction.GetPrediction(TH2, TH2delay + spell.Delay) : null);
                    SharpDX.Vector2 castVec  = (pred.UnitPosition.To2D() + TH.ServerPosition.To2D()) / 2;
                    SharpDX.Vector2 castVec2 = Player.ServerPosition.To2D() +
                                               SharpDX.Vector2.Normalize(pred.UnitPosition.To2D() - Player.Position.To2D()) * (spell.Range);
                    SharpDX.Vector2 castVec3 = TH.ServerPosition.To2D() -
                                               SharpDX.Vector2.Normalize(pred.UnitPosition.To2D() - Player.Position.To2D()) * (100f);
                    SharpDX.Vector2 EditedVec = pred.UnitPosition.To2D() -
                                                SharpDX.Vector2.Normalize(pred.UnitPosition.To2D() - TH.ServerPosition.To2D()) * (spell.Width * 2 / 5);
                    SharpDX.Vector2 EditedCV2Vec = Player.ServerPosition.To2D() +
                                                   SharpDX.Vector2.Normalize(EditedVec - Player.Position.To2D()) * (spell.Range);

                    if (pred.Hitchance >= MenuProvider.Champion.Misc.SelectedHitchance)
                    {
                        if (TH.Distance(Player.ServerPosition) >= spell.Range)
                        {
                            if (Func.CanHit(spell, TH, Drag) && (pred.UnitPosition.Distance(TH.ServerPosition) <= spell.Width / 2 || TH.MoveSpeed * THdelay <= spell.Width / 2)) //if(Func.CanHit(spell,TH,Drag) && TH2 != null && TH2pred.Hitchance >= MenuProvider.Champion.Misc.SelectedHitchance)//별로 좋은 생각이 더 안나고 피곤해서 걍관둠.
                            {
                                spell.Cast(EditedCV2Vec, TH.ServerPosition.To2D());                                                                                              //별로 좋은 생각이 더 안나고 피곤해서 걍관둠.
                            }
                            else if (Func.CanHit(spell, TH, Drag) && pred.UnitPosition.Distance(TH.ServerPosition) < 350)
                            {
                                if (pred.UnitPosition.Distance(Player.ServerPosition) > spell.Range)
                                {
                                    spell.Cast(castVec2, EditedVec);//pred.UnitPosition.To2D());
                                }
                            }
                        }
                        else
                        {
                            if (TH2 == null || !Func.CanHit(spell, TH2, Drag))
                            {
                                if (castVec3.Distance(Player.ServerPosition) < TH.ServerPosition.Distance(Player.ServerPosition))
                                {
                                    spell.Cast(castVec3, TH.ServerPosition.To2D());
                                }
                                else
                                {
                                    spell.Cast(TH.ServerPosition.To2D(), castVec3);
                                }
                            }
                            else if (TH2 != null && Func.CanHit(spell, TH2, Drag) && TH2pred.Hitchance >= MenuProvider.Champion.Misc.SelectedHitchance)
                            {
                                SharpDX.Vector2 castVec4 = TH.ServerPosition.To2D() -
                                                           SharpDX.Vector2.Normalize(TH2pred.UnitPosition.To2D() - TH.ServerPosition.To2D()) * (80f);
                                if (castVec4.Distance(Player.ServerPosition) < TH2pred.UnitPosition.Distance(Player.ServerPosition))
                                {
                                    spell.Cast(castVec4, TH2pred.UnitPosition.To2D());
                                }
                                else
                                {
                                    spell.Cast(TH2pred.UnitPosition.To2D(), castVec4);
                                }
                            }
                        }
                    }
                }
                if (TM != null)
                {
                    var Minions = ObjectManager.Get <Obj_AI_Minion>().Where(m => m.IsValidTarget(spell.Range + Drag) && m.Team != ObjectManager.Player.Team).Cast <Obj_AI_Base>().ToList();
                    if (Minions.Count > 0)
                    { //으....
                        //MinionManager.GetMinions(spell.Range+Drag, MinionTypes.All, MinionTeam.NotAlly);
                        var FM  = Minions.OrderBy(o => o.Distance(Player.ServerPosition)).FirstOrDefault().ServerPosition;
                        var FFM = Minions.OrderBy(o => o.Distance(Player.ServerPosition)).Reverse().FirstOrDefault().ServerPosition;
                        var P   = MinionManager.GetMinionsPredictedPositions(Minions, spell.Delay, spell.Width, spell.Speed, FM, Drag, true, SkillshotType.SkillshotLine);
                        var PP  = MinionManager.GetBestLineFarmLocation(P, spell.Width, spell.Range + Drag);
                        if (FM != null && FM.Distance(Player.ServerPosition) <= spell.Range) // && PP.MinionsHit >= Math.Min(Minions.Count,6))
                                                                                             //spell.Cast(FM.To2D(),PP.Position);
                        {
                            spell.Cast(FM.To2D(), FFM.To2D());
                        }
                    }
                }
            }
            if (Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.LaneClear)
            {
                var Minions = ObjectManager.Get <Obj_AI_Minion>().Where(m => m.IsValidTarget(spell.Range + Drag) && m.Team != ObjectManager.Player.Team).Cast <Obj_AI_Base>().ToList();
                if (Minions.Count > 0)
                {
                    //MinionManager.GetMinions(spell.Range+Drag, MinionTypes.All, MinionTeam.NotAlly);
                    var FM  = Minions.OrderBy(o => o.Distance(Player.ServerPosition)).FirstOrDefault().ServerPosition;
                    var FFM = Minions.OrderBy(o => o.Distance(Player.ServerPosition)).Reverse().FirstOrDefault().ServerPosition;
                    var P   = MinionManager.GetMinionsPredictedPositions(Minions, spell.Delay, spell.Width, spell.Speed, FM, Drag, true, SkillshotType.SkillshotLine);
                    var PP  = MinionManager.GetBestLineFarmLocation(P, spell.Width, spell.Range + Drag);
                    if (FM != null && FM.Distance(Player.ServerPosition) <= spell.Range)// && PP.MinionsHit >= Math.Min(Minions.Count,6))
                    //spell.Cast(FM.To2D(),PP.Position);
                    {
                        spell.Cast(FM.To2D(), FFM.To2D());
                    }
                }
            }
        }
示例#35
0
 public override bool Contains(SharpDX.Vector2 cursorLocation)
 {
     return(BoundingRectangle.Contains(cursorLocation));
 }
示例#36
0
        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            if (!IsVisible)
            {
                return;
            }
            if (Anchors.All(a => a.IsEditing))
            {
                return;
            }

            // this will be true right away to fix a restoral issue, so check if we really want to set reward
            if (needsRatioUpdate && DrawTarget)
            {
                SetReward();
            }

            ChartPanel chartPanel  = chartControl.ChartPanels[PanelIndex];
            Point      entryPoint  = EntryAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point      stopPoint   = RiskAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point      targetPoint = RewardAnchor.GetPoint(chartControl, chartPanel, chartScale);

            AnchorLineStroke.RenderTarget = RenderTarget;
            EntryLineStroke.RenderTarget  = RenderTarget;
            StopLineStroke.RenderTarget   = RenderTarget;

            // first of all, turn on anti-aliasing to smooth out our line
            RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;
            RenderTarget.DrawLine(entryPoint.ToVector2(), stopPoint.ToVector2(), AnchorLineStroke.BrushDX, AnchorLineStroke.Width, AnchorLineStroke.StrokeStyle);

            double anchorMinX = DrawTarget ? new[] { entryPoint.X, stopPoint.X, targetPoint.X }.Min() : new[] { entryPoint.X, stopPoint.X }.Min();
            double anchorMaxX = DrawTarget ? new[] { entryPoint.X, stopPoint.X, targetPoint.X }.Max() : new[] { entryPoint.X, stopPoint.X }.Max();
            double lineStartX = IsExtendedLinesLeft ? chartPanel.X : anchorMinX;
            double lineEndX   = IsExtendedLinesRight ? chartPanel.X + chartPanel.W : anchorMaxX;

            SharpDX.Vector2 entryStartVector = new SharpDX.Vector2((float)lineStartX, (float)entryPoint.Y);
            SharpDX.Vector2 entryEndVector   = new SharpDX.Vector2((float)lineEndX, (float)entryPoint.Y);
            SharpDX.Vector2 stopStartVector  = new SharpDX.Vector2((float)lineStartX, (float)stopPoint.Y);
            SharpDX.Vector2 stopEndVector    = new SharpDX.Vector2((float)lineEndX, (float)stopPoint.Y);

            // don't try and draw the target stuff until we have calculated the target
            SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : AnchorLineStroke.BrushDX;
            if (DrawTarget)
            {
                AnchorLineStroke.RenderTarget = RenderTarget;
                RenderTarget.DrawLine(entryPoint.ToVector2(), targetPoint.ToVector2(), tmpBrush, AnchorLineStroke.Width, AnchorLineStroke.StrokeStyle);

                TargetLineStroke.RenderTarget = RenderTarget;
                SharpDX.Vector2 targetStartVector = new SharpDX.Vector2((float)lineStartX, (float)targetPoint.Y);
                SharpDX.Vector2 targetEndVector   = new SharpDX.Vector2((float)lineEndX, (float)targetPoint.Y);

                tmpBrush = IsInHitTest ? chartControl.SelectionBrush : TargetLineStroke.BrushDX;
                RenderTarget.DrawLine(targetStartVector, targetEndVector, tmpBrush, TargetLineStroke.Width, TargetLineStroke.StrokeStyle);
                DrawPriceText(RewardAnchor, targetPoint, targetPrice, chartControl, chartPanel, chartScale);
            }

            tmpBrush = IsInHitTest ? chartControl.SelectionBrush : EntryLineStroke.BrushDX;
            RenderTarget.DrawLine(entryStartVector, entryEndVector, tmpBrush, EntryLineStroke.Width, EntryLineStroke.StrokeStyle);
            DrawPriceText(EntryAnchor, entryPoint, entryPrice, chartControl, chartPanel, chartScale);

            tmpBrush = IsInHitTest ? chartControl.SelectionBrush : StopLineStroke.BrushDX;
            RenderTarget.DrawLine(stopStartVector, stopEndVector, tmpBrush, StopLineStroke.Width, StopLineStroke.StrokeStyle);
            DrawPriceText(RiskAnchor, stopPoint, stopPrice, chartControl, chartPanel, chartScale);
        }
示例#37
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="renderTarget"></param>
        /// <param name="unitList"></param>
        private void drawUnits(WindowRenderTarget renderTarget, List <MapUnit> unitList)
        {
            for (int i = 0; i < unitList.Count; i++)
            {
                MapUnit mapUnit = unitList[i];

                SharpDX.Vector2 position = new SharpDX.Vector2(X[mapUnit.Position.X], Y[mapUnit.Position.Y]);
                float           radius   = Math.Max(X.Prop(mapUnit.Radius), 0.01f);

                switch (mapUnit)
                {
                case AIBaseMapUnit aiBaseMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.AIBase, position, radius);

                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.White, position, X.Prop(mapUnit.Radius - 3f));
                    break;

                case AIDroneMapUnit aiDroneMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.AIDrone, position, radius);

                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.White, position, X.Prop(mapUnit.Radius - 3f));
                    break;

                case AIPlatformMapUnit aiPlatformMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.AIPlatform, position, radius);

                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.White, position, X.Prop(mapUnit.Radius - 2f));
                    break;

                case AIProbeMapUnit aiProbeMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.AIProbe, position, radius);

                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.White, position, X.Prop(mapUnit.Radius - 2f));
                    break;

                case AIShipMapUnit aiShipMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.AIShip, position, radius);

                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.White, position, X.Prop(mapUnit.Radius - 2f));
                    break;

                case AsteroidMapUnit asteroidMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Asteroid, position, radius);
                    break;

                case BlackHoleMapUnit blackHoleMapUnit:
                    for (int c = 0; c < blackHoleMapUnit.GravityWellInfos.Length; c++)
                    {
                        Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.BlueViolet, position, X.Prop(blackHoleMapUnit.GravityWellInfos[c].Radius), 1f, dashedStrokeStyle);
                    }

                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.BlackHole, position, radius);
                    break;

                case BuoyMapUnit buoyMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Buoy, position, radius);
                    break;

                case CloakPowerUpMapUnit cloakPowerUpMapUnit:
                    Primitives.Circle.Fill(renderTarget, Brushes.SolidColorBrushes.CloakPowerUp, position, radius);
                    break;

                case DoubleDamagePowerUpMapUnit doubleDamagePowerUpMapUnit:
                    Primitives.Circle.Fill(renderTarget, Brushes.SolidColorBrushes.DoubleDamagePowerUp, position, radius);
                    break;

                case EnergyPowerUpMapUnit energyPowerUpMapUnit:
                    Primitives.Circle.Fill(renderTarget, Brushes.SolidColorBrushes.EnergyPowerUp, position, radius);
                    break;

                case ExplosionMapUnit explosionMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Explosion, position, radius);
                    break;

                case GateMapUnit gateMapUnit:
                    if (gateMapUnit.Switched)
                    {
                        Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Red, position, radius);
                    }
                    else
                    {
                        Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Green, position, radius, 1f, dashedStrokeStyle);
                    }
                    break;

                case HastePowerUpMapUnit hastePowerUpMapUnit:
                    Primitives.Circle.Fill(renderTarget, Brushes.SolidColorBrushes.HastePowerUp, position, radius);
                    break;

                case HullPowerUpMapUnit hullPowerUpMapUnit:
                    Primitives.Circle.Fill(renderTarget, Brushes.SolidColorBrushes.HullPowerUp, position, radius);
                    break;

                case IonsPowerUpMapUnit ionsPowerUpMapUnit:
                    Primitives.Circle.Fill(renderTarget, Brushes.SolidColorBrushes.IonsPowerUp, position, radius);
                    break;

                case MeteoroidMapUnit meteoroidMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Meteoroid, position, radius);
                    break;

                case MissionTargetMapUnit missionTargetMapUnit:

                    SolidColorBrush solidColorBrush;
                    if (missionTargetMapUnit.Team == null || missionTargetMapUnit.Team.Name == "None")
                    {
                        solidColorBrush = missionTargetMapUnit.IsHit ? Brushes.SolidColorBrushes.LimeGreen : Brushes.SolidColorBrushes.Red;
                    }
                    else
                    {
                        solidColorBrush = Brushes.SolidColorBrushes.TeamColors[missionTargetMapUnit.Team.Name];
                    }

                    Primitives.Circle.Draw(renderTarget, solidColorBrush, position, radius);
                    Primitives.Circle.Draw(renderTarget, solidColorBrush, position, X.Prop(mapUnit.Radius + 3f));

                    if (missionTargetMapUnit.DominationRadius > 0f)
                    {
                        if (missionTargetMapUnit.Team == null)
                        {
                            Primitives.Circle.Draw(renderTarget,
                                                   Brushes.SolidColorBrushes.GreenYellow,
                                                   position,
                                                   X.Prop(missionTargetMapUnit.DominationRadius));
                        }
                        else
                        {
                            Primitives.Circle.Draw(renderTarget,
                                                   Brushes.SolidColorBrushes.TeamColors[missionTargetMapUnit.Team.Name],
                                                   position,
                                                   X.Prop(missionTargetMapUnit.DominationRadius), X.Prop(4f));
                        }

                        if (missionTargetMapUnit.DominatingTeam != null)
                        {
                            Primitives.Circle.Draw(renderTarget,
                                                   Brushes.SolidColorBrushes.TeamColors[missionTargetMapUnit.DominatingTeam.Name],
                                                   position,
                                                   X.Prop(missionTargetMapUnit.DominationRadius - 10f),
                                                   X.Prop(8f),
                                                   dashedStrokeStyle);
                        }
                    }
                    else
                    {
                        renderTarget.DrawText(
                            missionTargetMapUnit.Name + " (#" + missionTargetMapUnit.SequenceNumber + ")",
                            missionTargetTextFormat,
                            new SharpDX.Mathematics.Interop.RawRectangleF(position.X, position.Y - X.Prop(20f), position.X + 100f, position.Y + 40f),
                            Brushes.SolidColorBrushes.MissionTarget,
                            DrawTextOptions.NoSnap);

                        foreach (Flattiverse.Vector tempHint in missionTargetMapUnit.Hints)
                        {
                            Flattiverse.Vector hint = tempHint * 20f;

                            renderTarget.DrawLine(
                                new SharpDX.Mathematics.Interop.RawVector2(position.X, position.Y),
                                new SharpDX.Mathematics.Interop.RawVector2(position.X + hint.X, position.Y + hint.Y),
                                Brushes.SolidColorBrushes.White, 2f, dashedStrokeStyle);
                        }
                    }
                    break;

                case MoonMapUnit moonMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Moon, position, radius);
                    break;

                case NebulaMapUnit nebulaMapUnit:
                    // TODO: Nebula color handling
                    break;

                case ParticlesPowerUpMapUnit particlesPowerUpMapUnit:
                    Primitives.Circle.Fill(renderTarget, Brushes.SolidColorBrushes.ParticlesPowerUp, position, radius);
                    break;

                case PixelMapUnit pixelMapUnit:
                    // Skip this for now
                    // Unused anyway
                    break;

                case PlanetMapUnit planetMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Planet, position, radius);
                    break;

                // TODO: Same handling as playership needed
                case PlayerBaseMapUnit playerBaseMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.DarkGreen, position, radius);
                    break;

                case PlayerDroneMapUnit playerDroneMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.DarkGreen, position, radius);
                    break;

                case PlayerPlatformMapUnit playerPlatformMapUnit:
                    break;

                case PlayerProbeMapUnit playerProbeMapUnit:
                    break;

                case PlayerShipMapUnit playerShipMapUnit:
                    float penThicknessBars = 2f;

                    using (SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout(parent.DirectWriteFactory, playerShipMapUnit.Name, missionTargetTextFormat, 100f, 20f))
                    {
                        float halfWidth = textLayout.Metrics.Width / 2f;
                        renderTarget.DrawTextLayout(new SharpDX.Mathematics.Interop.RawVector2(position.X - halfWidth, position.Y + radius + Y.Prop(penThicknessBars + 2f)),
                                                    textLayout,
                                                    Brushes.SolidColorBrushes.TeamColors[playerShipMapUnit.TeamName], SharpDX.Direct2D1.DrawTextOptions.NoSnap);
                    }

                    if (playerShipMapUnit.Hull > 0f)
                    {
                        Primitives.Arc.Draw(renderTarget,
                                            Brushes.SolidColorBrushes.OrangeRed,
                                            position,
                                            radius - X.Prop(penThicknessBars),
                                            270f,
                                            360f * playerShipMapUnit.Hull,
                                            X.Prop(penThicknessBars));
                    }

                    if (playerShipMapUnit.Shield > 0.01f)
                    {
                        Primitives.Arc.Draw(renderTarget,
                                            Brushes.SolidColorBrushes.CadetBlue,
                                            position,
                                            radius - X.Prop(penThicknessBars * 3f),
                                            270f,
                                            360f * playerShipMapUnit.Shield,
                                            X.Prop(penThicknessBars));
                    }

                    if (playerShipMapUnit.IsOwnShip)
                    {
                        Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.LightBlue, position, radius);

                        if (currentShip.Name == playerShipMapUnit.Name)
                        {
                            Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Red, position, X.Prop(currentShip.MaxShootRadius));
                        }

                        #region Health, Energy, Shield

                        if (playerShipMapUnit.Energy > 0f)
                        {
                            Primitives.Arc.Draw(renderTarget,
                                                Brushes.SolidColorBrushes.BlueViolet,
                                                position,
                                                radius - X.Prop(penThicknessBars * 2f),
                                                270f,
                                                360f * playerShipMapUnit.Energy,
                                                X.Prop(penThicknessBars));
                        }

                        float weaponLoadPercentage = playerShipMapUnit.CurrentShots / playerShipMapUnit.MaxShots;

                        weaponLoadPercentage = weaponLoadPercentage < 0.01f ? 0.0f : weaponLoadPercentage;

                        if (weaponLoadPercentage > 0f)
                        {
                            Primitives.Arc.Draw(renderTarget,
                                                Brushes.SolidColorBrushes.LightGoldenrodYellow,
                                                position,
                                                radius + X.Prop(penThicknessBars),
                                                270f,
                                                360f * weaponLoadPercentage,
                                                X.Prop(penThicknessBars));
                        }
                        #endregion
                    }
                    else
                    {
                        Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.IndianRed, position, radius);
                    }
                    break;

                case QuadDamagePowerUpMapUnit quadDamagePowerUpMapUnit:
                    Primitives.Circle.Fill(renderTarget, Brushes.SolidColorBrushes.QuadDamagePowerUp, position, radius);
                    break;

                case ShieldPowerUpMapUnit shieldPowerUpMapUnit:
                    Primitives.Circle.Fill(renderTarget, Brushes.SolidColorBrushes.ShieldPowerUp, position, radius);
                    break;

                case ShotMapUnit shotMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Shot, position, radius);
                    break;

                case ShotProductionPowerUpMapUnit shotProductionPowerUpMapUnit:
                    Primitives.Circle.Fill(renderTarget, Brushes.SolidColorBrushes.ShotProductionPowerUp, position, radius);
                    break;

                case SpaceJellyFishMapUnit spaceJellyFishMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.SpaceJellyFish, position, radius);
                    break;

                case SpaceJellyFishSlimeMapUnit spaceJellyFishSlimeMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.SpaceJellyFishSlime, position, radius, 1f, dashedStrokeStyle);
                    break;

                case StormCommencingWhirlMapUnit stormCommencingWhirlMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.StormCommencingWhirl, position, radius, 1f, dashedStrokeStyle);
                    break;

                case StormMapUnit stormMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Storm, position, radius);
                    break;

                case StormWhirlMapUnit stormWhirlMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.StormWhirl, position, radius);
                    break;

                case SunMapUnit sunMapUnit:
                    for (int c = 0; c < sunMapUnit.CoronaInfos.Length; c++)
                    {
                        Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.LightYellow, position, X.Prop(sunMapUnit.CoronaInfos[c].Radius), 1f, dashedStrokeStyle);
                    }

                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Sun, position, radius);
                    break;

                case SwitchMapUnit switchMapUnit:
                    if (switchMapUnit.Switched)
                    {
                        Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Red, position, radius);
                    }
                    else
                    {
                        Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Green, position, radius, 1f, dashedStrokeStyle);
                    }
                    break;

                case TotalRefreshPowerUpMapUnit totalRefreshPowerUpMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.TotalRefreshPowerUp, position, radius);
                    break;

                case UnknownMapUnit unknownMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.Unknown, position, radius);
                    break;

                case WormHoleMapUnit wormHoleMapUnit:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.WormHole, position, radius);
                    break;

                default:
                    Primitives.Circle.Draw(renderTarget, Brushes.SolidColorBrushes.White, position, radius);
                    break;
                }
            }
        }
示例#38
0
 public override bool HitTest(SharpDX.Vector2 vec)
 {
     return(base.HitTest(vec + new SharpDX.Vector2(this[1].Width / 2, this[1].Height / 2)));
 }
示例#39
0
 private void getVector2(List<Vector2> point2d_array)
 {
     var vec2 = new Vector2();
     vec2.X = float.Parse(Tokens[1]);
     vec2.X = float.Parse(Tokens[2]);
     point2d_array.Add(vec2);
 }