Example #1
0
        internal static void LCast(this Spell spell, AIBaseClient target, HitChance SelectedHitchance, float alpha = 0f, float colmini = float.MaxValue, bool HeroOnly = false, float BombRadius = 0f) //for Linar spells  사용예시 AIO_Func.LCast(Q,Qtarget,50,0)
        {                                                                                                                                                                                              //        AIO_Func.LCast(E,Etarget,Menu.Item("Misc.Etg").GetValue<Slider>().Value,float.MaxValue); <- 이런식으로 사용.
            if (spell.Type == SkillshotType.Line)
            {
                if (spell != null && target != null)
                {
                    var pred      = SpellPrediction.GetPrediction(target, spell.Delay, spell.Width / 2, spell.Speed); //spell.Width/2
                    var collision = spell.GetCollision(Player.PreviousPosition.ToVector2(), new List <Vector2> {
                        pred.CastPosition.ToVector2()
                    });
                    //var minioncol = collision.Where(x => !(x is Obj_AI_Hero)).Count(x => x.IsMinion);
                    var             minioncol = collision.Count(x => (HeroOnly == false ? x.IsMinion : (x is AIHeroClient)));
                    SharpDX.Vector2 EditedVec = pred.UnitPosition.ToVector2() -
                                                SharpDX.Vector2.Normalize(pred.UnitPosition.ToVector2() - target.PreviousPosition.ToVector2()) * (spell.Width * 2 / 5);
                    SharpDX.Vector2 EditedVec2 = (pred.UnitPosition.ToVector2() + target.PreviousPosition.ToVector2()) / 2;

                    var collision2 = spell.GetCollision(Player.PreviousPosition.ToVector2(), new List <Vector2> {
                        EditedVec
                    });
                    var minioncol2 = collision2.Count(x => (HeroOnly == false ? x.IsMinion : (x is AIHeroClient)));
                    var collision3 = spell.GetCollision(Player.PreviousPosition.ToVector2(), new List <Vector2> {
                        EditedVec2
                    });
                    var minioncol3 = collision3.Count(x => (HeroOnly == false ? x.IsMinion : (x is AIHeroClient)));
                    if (pred.Hitchance >= SelectedHitchance)
                    {
                        if (target.IsValidTarget(spell.Range - target.MoveSpeed * (spell.Delay + Player.Distance(target.PreviousPosition) / spell.Speed) + alpha) && minioncol2 <= colmini && pred.UnitPosition.Distance(target.PreviousPosition) > spell.Width)
                        {
                            spell.Cast(EditedVec);
                        }
                        else if (target.IsValidTarget(spell.Range - target.MoveSpeed * (spell.Delay + Player.Distance(target.PreviousPosition) / spell.Speed) + alpha) && minioncol3 <= colmini && pred.UnitPosition.Distance(target.PreviousPosition) > spell.Width / 2)
                        {
                            spell.Cast(EditedVec2);
                        }
                        else if (target.IsValidTarget(spell.Range - target.MoveSpeed * (spell.Delay + Player.Distance(target.PreviousPosition) / spell.Speed) + alpha) && minioncol <= colmini)
                        {
                            spell.Cast(pred.CastPosition);
                        }
                        else if (false == spell.Collision && colmini < 1 && minioncol >= 1)
                        {
                            var FirstMinion = collision.OrderBy(o => o.Distance(Player.PreviousPosition)).FirstOrDefault();
                            if (FirstMinion.PreviousPosition.Distance(pred.UnitPosition) <= BombRadius / 4)
                            {
                                spell.Cast(pred.CastPosition);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        protected override void ArrangeOverride()
        {
            PointF oldPosition = ActualPosition;
            double oldWidth    = ActualWidth;
            double oldHeight   = ActualHeight;

            base.ArrangeOverride();
            if (ActualWidth != 0 && ActualHeight != 0 &&
                (ActualWidth != oldWidth || ActualHeight != oldHeight || oldPosition != ActualPosition))
            {
                _performLayout = true;
            }
            ArrangeTemplateControl();
        }
        public override void Update(double secondsElapsed, InputUtilities keyUtils, SharpDX.Vector2 cursorPoint, bool checkMouse = false)
        {
            base.Update(secondsElapsed, keyUtils, cursorPoint, checkMouse);
            if (this.Visible)
            {
                this.ContentLayout.ApplyLayout(this);
                float width = 0, height = 0;
                Control <SharpDXRenderer, Color, Vector2, TextFormat> lastControl = null;

                for (int i = 0; i < this.ChildControls.Count; i++)
                {
                    var control = this.ChildControls[i];
                    if (!control.Visible)
                    {
                        continue;
                    }

                    lastControl = control;
                    if (this.DynamicWidth)
                    {
                        if (control.Width + control.MarginLeft + control.MarginRight > width)
                        {
                            width = control.Width + control.MarginLeft + control.MarginRight;
                        }
                    }
                }

                if (this.DynamicHeight)
                {
                    if (ChildControls.Count(x => x.Visible) > 0)
                    {
                        height = ChildControls.Where(x => x.Visible).Max(x => x.Y + x.Height);
                    }
                }
                //if (lastControl != null)
                //    height = lastControl.Y + lastControl.Height + lastControl.MarginBottom;
                if (this.DynamicWidth)
                {
                    this.Width = width + this.MarginLeft + this.MarginRight;
                }
                if (this.DynamicHeight)
                {
                    this.Height = height + this.MarginBottom;
                }
            }
            else
            {
                this.Height = 0;
            }
        }
Example #4
0
        protected override void ArrangeOverride()
        {
            base.ArrangeOverride();
            FrameworkElement content = Content;

            if (content != null)
            {
                PointF position      = new PointF(_innerRect.X, _innerRect.Y);
                SizeF  availableSize = CalculateInnerDesiredSize(_innerRect.Size);
                ArrangeChild(content, content.HorizontalAlignment, content.VerticalAlignment, ref position, ref availableSize);
                RectangleF childRect = SharpDXExtensions.CreateRectangleF(position, availableSize);
                content.Arrange(childRect);
            }
        }
Example #5
0
        /// <summary>
        /// Function to convert a 2D vector value from texel coordinates to pixel space.
        /// </summary>
        /// <param name="texelVector">The texel size to convert.</param>
        /// <param name="mipLevel">[Optional] The mip level to use.</param>
        /// <returns>A 2D vector containing the pixel space coordinates.</returns>
        /// <remarks>
        /// <para>
        /// If specified, the <paramref name="mipLevel"/> only applies to the <see cref="MipSlice"/> and <see cref="MipCount"/> for this view, it will be constrained if it falls outside of that range.
        /// Because of this, the coordinates returned may not be the exact size of the texture bound to the view at mip level 0. If the <paramref name="mipLevel"/> is omitted, then the first mip level
        /// for the underlying <see cref="Texture"/> is used.
        /// </para>
        /// </remarks>
        public DX.Vector2 ToPixel(DX.Vector2 texelVector, int?mipLevel = null)
        {
            float width  = Texture.Width;
            float height = Texture.Height;

            if (mipLevel == null)
            {
                return(new DX.Vector2(texelVector.X * width, texelVector.Y * height));
            }

            width  = GetMipWidth(mipLevel.Value);
            height = GetMipHeight(mipLevel.Value);

            return(new DX.Vector2(texelVector.X * width, texelVector.Y * height));
        }
Example #6
0
        /// <summary>Initializes a new instance of the <see cref="T:Gorgon.Editor.SpriteEditor.SpriteContentRenderer"/> class.</summary>
        /// <param name="sprite">The sprite view model.</param>
        /// <param name="graphics">The graphics interface for the application.</param>
        /// <param name="swapChain">The swap chain for the render area.</param>
        /// <param name="renderer">The 2D renderer for the application.</param>
        /// <param name="anchorEditor">The editor for the anchor position.</param>
        /// <param name="initialZoom">The initial zoom scale value.</param>
        public SpriteAnchorRenderer(ISpriteContent sprite, GorgonGraphics graphics, GorgonSwapChain swapChain, Gorgon2D renderer, IAnchorEditService anchorEditor, float initialZoom)
            : base(sprite, graphics, swapChain, renderer, initialZoom)
        {
            _anchorEdit = anchorEditor;

            _anchorEdit.PointToClient   = r => ToClient(r);
            _anchorEdit.PointFromClient = p =>
            {
                DX.Vector2 pos = FromClient(p);
                return(new DX.Vector2((int)pos.X, (int)pos.Y));
            };

            _anchorEdit.AnchorChanged += AnchorEdit_AnchorChanged;
            _anchorEdit.BoundsChanged += AnchorEdit_BoundsChanged;
        }
        public static Vector2 RotatePoint(Vector2 pointToRotate, Vector2 centerPoint, float angleInDegrees)
        {
            var angleInRadians = angleInDegrees * (Math.PI / 180);
            var cosTheta       = Math.Cos(angleInRadians);
            var sinTheta       = Math.Sin(angleInRadians);
            //var tanTheta = Math.Tan(angleInRadians);

            var newX = (cosTheta * (pointToRotate.X - centerPoint.X) - sinTheta * (pointToRotate.Y - centerPoint.Y) + centerPoint.X);
            var newY = (sinTheta * (pointToRotate.X - centerPoint.X) + cosTheta * (pointToRotate.Y - centerPoint.Y) + centerPoint.Y);
            //var newZ = (tanTheta * (pointToRotate.Z - centerPoint.Z) + cosTheta * (pointToRotate.Y - centerPoint.Y) + centerPoint.Z);

            Vector2 newPos = new Vector2((float)newX, (float)newY);

            return(newPos);
        }
Example #8
0
 private void RenderText(float textX, float textY, string text, Brush brush)
 {
     if (ChartControl == null)
     {
         return;
     }
     using (SharpDX.DirectWrite.TextFormat textFormat = ChartControl.Properties.LabelFont.ToDirectWriteTextFormat())
     {
         using (SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout(Core.Globals.DirectWriteFactory, text, textFormat, ChartPanel.W, 8f))
         {
             SharpDX.Vector2 origin = new SharpDX.Vector2(textX, textY - (float)(textLayout.Metrics.Height) / 2);                       // bump above copyright
             RenderTarget.DrawTextLayout(origin, textLayout, brush.ToDxBrush(RenderTarget));
         }
     }
 }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Plane" /> class.
        /// </summary>
        /// <param name="graphics">The graphics interface used to create the buffers for this object.</param>
        /// <param name="inputLayout">The input layout for the vertices in this mesh.</param>
        /// <param name="size">The width and height of the plane.</param>
        /// <param name="textureCoordinates">Texture coordinates.</param>
        public Plane(GorgonGraphics graphics, GorgonInputLayout inputLayout, DX.Vector2 size, DX.RectangleF textureCoordinates)
            : base(inputLayout)
        {
            Size = size;

            // Create our vertices.
            Vertices = new[]
            {
                new BoingerVertex(new DX.Vector3(-size.X, size.Y, 0.0f), textureCoordinates.Location),
                new BoingerVertex(new DX.Vector3(size.X, size.Y, 0.0f), new DX.Vector2(textureCoordinates.Right, textureCoordinates.Top)),
                new BoingerVertex(new DX.Vector3(-size.X, -size.Y, 0.0f), new DX.Vector2(textureCoordinates.Left, textureCoordinates.Bottom)),
                new BoingerVertex(new DX.Vector3(size.X, -size.Y, 0.0f), new DX.Vector2(textureCoordinates.Right, textureCoordinates.Bottom))
            };

            // Create our indices.
            Indices = new ushort[]
            {
                0,
                1,
                2,
                2,
                1,
                3
            };

            // Copy the above vertex/index data into a vertex and index buffer so we can render our plane.
            using (var vertexPtr = GorgonNativeBuffer <BoingerVertex> .Pin(Vertices))
                using (var indexPtr = GorgonNativeBuffer <ushort> .Pin(Indices))
                {
                    VertexBufferBindings[0] = GorgonVertexBufferBinding.CreateVertexBuffer(graphics,
                                                                                           new GorgonVertexBufferInfo("Plane Vertex Buffer")
                    {
                        SizeInBytes =
                            Vertices.Length * BoingerVertex.Size,
                        Usage = ResourceUsage.Immutable
                    },
                                                                                           vertexPtr);

                    IndexBuffer = new GorgonIndexBuffer(graphics,
                                                        new GorgonIndexBufferInfo("Plane Index Buffer")
                    {
                        Usage           = ResourceUsage.Immutable,
                        IndexCount      = Indices.Length,
                        Use16BitIndices = true
                    },
                                                        indexPtr);
                }
        }
Example #10
0
        /// <summary>Function called to render the sprite data.</summary>
        /// <returns>The presentation interval to use when rendering.</returns>
        protected override int OnRender()
        {
            var spriteRegion = SpriteContent.Texture.ToPixel(SpriteContent.TextureCoordinates).ToRectangleF();
            var imageRegion  = new DX.RectangleF(0, 0, SpriteContent.Texture.Width, SpriteContent.Texture.Height);

            RenderSpriteTextureWithoutSprite(imageRegion, spriteRegion);

            SwapChain.RenderTargetView.Clear(BackgroundColor);

            Renderer.Begin();

            if (IsAnimating)
            {
                // Draw the pattern layer.
                Renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, SwapChain.Width, SwapChain.Height),
                                             new GorgonColor(GorgonColor.White, (0.5f - TextureAlpha.Min(0.5f).Max(0)) * 2),
                                             BackgroundPattern,
                                             new DX.RectangleF(0, 0, SwapChain.Width / BackgroundPattern.Width, SwapChain.Height / BackgroundPattern.Height));

                RenderRect(imageRegion, new GorgonColor(GorgonColor.White, TextureAlpha * 2), BackgroundPattern, new DX.RectangleF(0, 0, (imageRegion.Width * ZoomScaleValue) / BackgroundPattern.Width, (imageRegion.Height * ZoomScaleValue) / BackgroundPattern.Height));
                RenderRect(spriteRegion, GorgonColor.White, BackgroundPattern, new DX.RectangleF(0, 0, (spriteRegion.Width * ZoomScaleValue) / BackgroundPattern.Width, (spriteRegion.Height * ZoomScaleValue) / BackgroundPattern.Height));
            }
            else
            {
                // Draw the pattern layer.
                RenderRect(imageRegion, GorgonColor.White, BackgroundPattern, new DX.RectangleF(0, 0, (imageRegion.Width * ZoomScaleValue) / BackgroundPattern.Width, (imageRegion.Height * ZoomScaleValue) / BackgroundPattern.Height));
            }

            // Draw the image buffer layer.
            Renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, SwapChain.Width, SwapChain.Height), new GorgonColor(GorgonColor.White, TextureAlpha), ImageBufferTexture, new DX.RectangleF(0, 0, 1, 1));

            // Draw the sprite layer.
            Renderer.DrawSprite(_workingSprite);

            // Draw an indicator for the anchor.
            DX.Vector2 anchorPos = ToClient(new DX.Vector2(SpriteContent.Anchor.X * spriteRegion.Width + spriteRegion.Left,
                                                           SpriteContent.Anchor.Y * spriteRegion.Height + spriteRegion.Top)).Truncate();

            Renderer.DrawEllipse(new DX.RectangleF(anchorPos.X - 4, anchorPos.Y - 4, 8, 8), GorgonColor.Black);
            Renderer.DrawEllipse(new DX.RectangleF(anchorPos.X - 3, anchorPos.Y - 3, 6, 6), GorgonColor.White);

            // We convert to integer first so we can clip the decimal places.
            _marchAnts.Draw(Renderer.MeasureSprite(_workingSprite).Truncate());

            Renderer.End();

            return(1);
        }
Example #11
0
        public static async Task <bool> MoveToPosWithNavMeshAsync(SharpDX.Vector3 vecDest, int NearDistance = 50)
        {
            if (Nav.D3.Navmesh.Current == null)
            {
                Nav.D3.Navmesh.Create(Enigma.D3.Engine.Current, new Nav.ExploreEngine.Nearest());
            }

            var localAcd = ActorCommonDataHelper.GetLocalAcd();
            var distance = vecDest.Distance(); // (Math.Pow(localAcd.x0D0_WorldPosX - vecDest.X, 2) + Math.Pow(localAcd.x0D4_WorldPosY - vecDest.Y, 2));

            var minDistanceReached = distance;
            var dtDistanceReached  = DateTime.Now;

            DateTime dtTimeout = DateTime.Now;

            while (distance > NearDistance)
            {
                if (DateTime.Now > dtTimeout.AddSeconds(30) || DateTime.Now > dtDistanceReached.AddSeconds(10))
                {
                    return(false);
                }

                SharpDX.Vector2 curVector  = localAcd.ToSharpDXVector2(); // new SharpDX.Vector2(localAcd.x0D0_WorldPosX, localAcd.x0D4_WorldPosY);
                SharpDX.Vector2 destVector = new SharpDX.Vector2(vecDest.X, vecDest.Y);

                // Update current player position.
                Nav.D3.Navmesh.Current.Navigator.CurrentPos = localAcd.ToNavVec3(); // new Nav.Vec3(localAcd.x0D0_WorldPosX, localAcd.x0D4_WorldPosY, localAcd.x0D8_WorldPosZ);

                // Update destination. You can keep setting the same value there is internal check if destination has actually changed.
                // This destination overrides any internal destinations (including exploration). When You just want to explore You do
                // not need to set any destination. It will be set automatically.
                Nav.D3.Navmesh.Current.Navigator.Destination = new Nav.Vec3(vecDest.X, vecDest.Y, vecDest.Z);

                // Get current destination.
                Nav.Vec3 goToPosition = Nav.D3.Navmesh.Current.Navigator.GoToPosition;
                while (goToPosition.IsEmpty)
                {
                    await Task.Delay(10);
                }

                SharpDX.Vector3 goToPositionVector = new SharpDX.Vector3(goToPosition.X, goToPosition.Y, goToPosition.Z);
                await MoveToPosAsync(goToPositionVector);
            }

            return(true);
        }
        protected virtual void ArrangeTemplateControl()
        {
            FrameworkElement templateControl = _templateControl;

            if (templateControl == null)
            {
                return;
            }
            PointF position      = new PointF(_innerRect.X, _innerRect.Y);
            SizeF  availableSize = new SizeF(_innerRect.Width, _innerRect.Height);

            ArrangeChild(templateControl, HorizontalContentAlignment, VerticalContentAlignment,
                         ref position, ref availableSize);
            RectangleF childRect = SharpDXExtensions.CreateRectangleF(position, availableSize);

            templateControl.Arrange(childRect);
        }
Example #13
0
        /// <summary>Function called to render the sprite data.</summary>
        /// <returns>The presentation interval to use when rendering.</returns>
        protected override int OnRender()
        {
            var   clientSize = new DX.Size2F(SwapChain.Width, SwapChain.Height);
            float newSize    = clientSize.Width < clientSize.Height ? clientSize.Width : clientSize.Height;
            var   size       = new DX.Size2F(newSize.Min(_noImage.Width), newSize.Min(_noImage.Width));
            var   halfClient = new DX.Size2F(clientSize.Width / 2.0f, clientSize.Height / 2.0f);
            var   pos        = new DX.Vector2((int)(halfClient.Width - size.Width / 2.0f), (int)(halfClient.Height - size.Height / 2.0f));

            Graphics.SetRenderTarget(SwapChain.RenderTargetView);
            SwapChain.RenderTargetView.Clear(BackgroundColor);

            Renderer.Begin();
            Renderer.DrawFilledRectangle(new DX.RectangleF(pos.X, pos.Y, size.Width, size.Height), GorgonColor.White, _noImage, new DX.RectangleF(0, 0, 1, 1));
            Renderer.End();

            return(1);
        }
Example #14
0
        /// <summary>
        /// Handles the MouseUp event of the Window control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
        private static void Window_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            if (_dragButton != null)
            {
                var dragPosition = new DX.RectangleF(e.X - _dragOffset.X, e.Y - _dragOffset.Y, _dragButton.Bounds.Width, _dragButton.Bounds.Height);
                int index        = -1;
                for (int i = 0; i < _buttons.Length; ++i)
                {
                    Button overButton = _buttons[i];

                    if (!overButton.Bounds.Intersects(dragPosition))
                    {
                        continue;
                    }

                    index = i;
                    break;
                }

                _compositor.MovePass(_dragButton.Pass.Name, index != -1 ? index : _buttons.Length);

                _dragButton.IsDragging = false;
                _dragButton            = null;
                _dragOffset            = DX.Vector2.Zero;
                _dragStart             = DX.Vector2.Zero;

                LayoutGUI();
                return;
            }

            for (int i = 0; i < _buttons.Length; ++i)
            {
                Button button = _buttons[i];
                if (!button.Bounds.Contains(e.X, e.Y))
                {
                    continue;
                }

                button.PerformClick();
            }
        }
Example #15
0
        /// <summary>
        /// Handles the MouseMove event of the Window control.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
        private static void Window_MouseMove(object sender, MouseEventArgs e)
        {
            bool targetAcquired = false;

            for (int i = 0; i < _buttons.Length; ++i)
            {
                Button button = _buttons[i];
                button.State = ButtonState.Normal;

                if ((_dragButton == null) && (!button.Bounds.Contains(e.X, e.Y)))
                {
                    continue;
                }

                if (_dragButton != null)
                {
                    var dragPosition = new DX.RectangleF(e.X - _dragOffset.X, e.Y - _dragOffset.Y, _dragButton.Bounds.Width, _dragButton.Bounds.Height);

                    if ((!button.Bounds.Intersects(dragPosition)) || (targetAcquired))
                    {
                        continue;
                    }

                    targetAcquired = true;
                }

                button.State = ButtonState.Hovered;

                if ((e.Button != MouseButtons.Left) || (_dragButton != null))
                {
                    continue;
                }

                DX.Vector2 diff = new DX.Vector2(e.X, e.Y) - _dragStart;

                if ((diff.X.Abs() < 5) && (diff.Y.Abs() < 5))
                {
                    continue;
                }

                _dragOffset       = new DX.Vector2(_dragStart.X - button.Bounds.Left, _dragStart.Y - button.Bounds.Top);
                button.IsDragging = true;
                _dragButton       = button;
            }
        }
Example #16
0
        private float EdgeDf(SharpDX.Vector2 g, float a)
        {
            float df;

            if ((g.X == 0) || (g.Y == 0))
            {
                // Either A) gu or gv are zero, or B) both
                df = 0.5f - a; // Linear approximation is A) correct or B) a fair guess
            }
            else
            {
                float gradientLength = (float)Math.Sqrt(g.X * g.X + g.Y * g.Y);
                if (gradientLength > 0.0)
                {
                    g.X = g.X / gradientLength;
                    g.Y = g.Y / gradientLength;
                }

                g.X = Math.Abs(g.X);
                g.Y = Math.Abs(g.Y);
                if (g.X < g.Y)
                {
                    Utilities.Swap(ref g.X, ref g.Y);
                }

                float a1 = 0.5f * g.Y / g.X;
                if (a < a1)
                {
                    // 0 <= a < a1
                    df = 0.5f * (g.X + g.Y) - (float)Math.Sqrt(2.0f * g.X * g.Y * a);
                }
                else if (a < (1.0 - a1))
                {
                    // a1 <= a <= 1-a1
                    df = (0.5f - a) * g.X;
                }
                else
                {
                    // 1-a1 < a <= 1
                    df = -0.5f * (g.X + g.Y) + (float)Math.Sqrt(2.0f * g.X * g.Y * (1.0f - a));
                }
            }

            return(df);
        }
Example #17
0
        public static void TestEnterBloodAqua()
        {
            var        gameWindowRect = GameController.Window.GetWindowRectangle();
            int        latency        = (int)GameController.IngameState.CurLatency;
            RectangleF waypointRect   = new RectangleF();

            foreach (var itemOnGround in GameController.Game.IngameState.IngameUi.ItemsOnGroundLabels)
            {
                if (itemOnGround.Label != null && itemOnGround.Label.ChildCount > 0)
                {
                    if (itemOnGround?.Label?.GetChildAtIndex(0)?.Text?.ToLower().Contains("waypoint") == true)
                    {
                        waypointRect = itemOnGround.Label.GetClientRectCache;
                        break;
                    }
                }
            }
            Mouse.SetCursorPosAndLeftOrRightClick(waypointRect, latency, randomClick: true);
            while (GameController.IngameState.IngameUi.WorldMapPart2.IsVisible == false)
            {
                Thread.Sleep(50);
            }
            Thread.Sleep(200);
            Mouse.SetCursorPosAndLeftOrRightClick(GameController.IngameState.IngameUi.WorldMapAct9Rect.GetClientRectCache, latency, randomClick: true);
            Thread.Sleep(300);
            Mouse.SetCursorPosAndLeftOrRightClick(GameController.IngameState.IngameUi.WorldMapPart2.GetClientRectCache, latency, randomClick: true);

            Thread.Sleep(200);
            var wp = GameController.IngameState.IngameUi.WorldMapBloodAquaductsWaypoint;

            // I only have topleft of the waypoint.
            // Add an offset
            SharpDX.Vector2 mapWaypointOffset = new SharpDX.Vector2(25, 25);
            var             clickPoint        = gameWindowRect.TopLeft + wp.GetClientRectCache.TopLeft + mapWaypointOffset;

            Input.KeyDown(Keys.LControlKey);
            Mouse.SetCursorPosAndLeftOrRightClick(clickPoint, latency);
            Input.KeyUp(Keys.LControlKey);

            Thread.Sleep(500);
            // Press new button


            Mouse.SetCursorPosAndLeftOrRightClick(WillBot.Me.AreaInstanceNewButton.GetClientRectCache, latency, randomClick: true);
        }
Example #18
0
        public void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle)
        {
            SetOffset(true);
            PointF start;
            var    arc    = CreateArc(x, y, width, height, startAngle, sweepAngle, out start);
            var    path   = new sd.PathGeometry(SDFactory.D2D1Factory);
            var    sink   = path.Open();
            var    center = new s.Vector2(x + width / 2, y + height / 2);

            sink.BeginFigure(center, sd.FigureBegin.Filled);
            sink.AddLine(start.ToDx());
            sink.AddArc(arc);
            sink.AddLine(center);
            sink.EndFigure(sd.FigureEnd.Open);
            sink.Close();
            sink.Dispose();
            Control.FillGeometry(path, brush.ToDx(Control));
        }
Example #19
0
        /// <summary>
        /// Function to draw the balls without any effects.
        /// </summary>
        private static void DrawNoBlur()
        {
            // Draw balls.
            for (int i = 0; i < _ballCount; i++)
            {
                Ball ball = _ballList[i];

                _ball.Angle    = ball.Rotation;
                _ball.Position = ball.Position;
                _ball.Color    = new GorgonColor(ball.Color, ball.Opacity);
                _ball.Scale    = new DX.Vector2(ball.Scale, ball.Scale);

                DX.Vector2 offset = ball.Checkered ? new DX.Vector2(0.5f, 0) : new DX.Vector2(0, 0.5f);
                _ball.TextureRegion = new DX.RectangleF(offset.X, offset.Y, _ball.TextureRegion.Width, _ball.TextureRegion.Height);

                _2D.DrawSprite(_ball);
            }
        }
Example #20
0
        protected override void ArrangeOverride()
        {
            base.ArrangeOverride();
            float x = _innerRect.Location.X;
            float y = _innerRect.Location.Y;

            foreach (FrameworkElement child in GetVisibleChildren())
            {
                // Get the coordinates relative to the canvas area.
                PointF location = new PointF(GetLeft(child, false) + x, GetTop(child, false) + y);

                // Get the child size
                SizeF childSize = child.DesiredSize;

                // Arrange the child
                child.Arrange(SharpDXExtensions.CreateRectangleF(location, childSize));
            }
        }
Example #21
0
        /// Item's World To Screen Function
        /// </summary>
        /// <param name="viewMatrix"></param>
        /// <param name="pos"></param>
        /// <param name="screen"></param>
        /// <param name="distance"></param>
        /// <param name="windowWidth"></param>
        /// <param name="windowHeight"></param>
        /// <returns></returns>
        public static bool WorldToScreenItem(D3DMatrix viewMatrix, ShpVector3 pos, out ShpVector2 screen, out int distance, int windowWidth, int windowHeight)
        {
            screen = new ShpVector2();
            float screenW = (viewMatrix._14 * pos.X) + (viewMatrix._24 * pos.Y) + (viewMatrix._34 * pos.Z + viewMatrix._44);

            distance = (int)(screenW / 100);
            if (screenW < 0.0001f)
            {
                return(false);
            }
            screenW = 1 / screenW;
            float sightX = (windowWidth / 2);
            float sightY = (windowHeight / 2);

            screen.X = sightX + (viewMatrix._11 * pos.X + viewMatrix._21 * pos.Y + viewMatrix._31 * pos.Z + viewMatrix._41) * screenW * sightX;
            screen.Y = sightY - (viewMatrix._12 * pos.X + viewMatrix._22 * pos.Y + viewMatrix._32 * pos.Z + viewMatrix._42) * screenW * sightY;
            return(!float.IsNaN(screen.X) && !float.IsNaN(screen.Y));
        }
        /// <summary>Function called when a mouse button is released.</summary>
        /// <param name="position">The position of the mouse cursor.</param>
        /// <param name="buttons">The button(s) released.</param>
        /// <param name="image">The current image.</param>
        protected override void OnMouseUp(DX.Vector2 position, MouseButtons buttons, IImageContent image)
        {
            if (buttons != MouseButtons.Left)
            {
                return;
            }

            int cubeGroup = (image.CurrentArrayIndex / 6) * 6;

            for (int i = 0; i < _cubeImageBounds.Length; ++i)
            {
                if (_cubeImageBounds[i].Contains(position))
                {
                    image.CurrentArrayIndex = cubeGroup + i;
                    return;
                }
            }
        }
Example #23
0
        void TickLogic()
        {
            ingameStateIngameUi = GameController.Game.IngameState.IngameUi;

            if (ingameStateIngameUi.Map.SmallMiniMap.IsVisibleLocal)
            {
                var mapRect = ingameStateIngameUi.Map.SmallMiniMap.GetClientRectCache;
                screentCenterCache = new Vector2(mapRect.X + mapRect.Width / 2, mapRect.Y + mapRect.Height / 2);
                largeMap           = false;
            }
            else if (ingameStateIngameUi.Map.LargeMap.IsVisibleLocal)
            {
                screentCenterCache = screenCenter;
                largeMap           = true;
            }

            k     = camera.Width < 1024f ? 1120f : 1024f;
            scale = k / camera.Height * camera.Width * 3f / 4f / mapWindow.LargeMapZoom;
        }
Example #24
0
        public static async Task<bool> MoveToPosWithNavMeshAsync(SharpDX.Vector3 vecDest, int NearDistance = 50)
        {
            if (Nav.D3.Navmesh.Current == null)
                Nav.D3.Navmesh.Create(Enigma.D3.Engine.Current, new Nav.ExploreEngine.Nearest());

            var localAcd = ActorCommonDataHelper.GetLocalAcd();
            var distance = vecDest.Distance(); // (Math.Pow(localAcd.x0D0_WorldPosX - vecDest.X, 2) + Math.Pow(localAcd.x0D4_WorldPosY - vecDest.Y, 2));

            var minDistanceReached = distance;
            var dtDistanceReached = DateTime.Now;

            DateTime dtTimeout = DateTime.Now;
            while (distance > NearDistance)
            {
                if (DateTime.Now > dtTimeout.AddSeconds(30) || DateTime.Now > dtDistanceReached.AddSeconds(10))
                    return false;

                SharpDX.Vector2 curVector = localAcd.ToSharpDXVector2(); // new SharpDX.Vector2(localAcd.x0D0_WorldPosX, localAcd.x0D4_WorldPosY);
                SharpDX.Vector2 destVector = new SharpDX.Vector2(vecDest.X, vecDest.Y);

                // Update current player position.
                Nav.D3.Navmesh.Current.Navigator.CurrentPos = localAcd.ToNavVec3(); // new Nav.Vec3(localAcd.x0D0_WorldPosX, localAcd.x0D4_WorldPosY, localAcd.x0D8_WorldPosZ);

                // Update destination. You can keep setting the same value there is internal check if destination has actually changed. 
                // This destination overrides any internal destinations (including exploration). When You just want to explore You do 
                // not need to set any destination. It will be set automatically.
                Nav.D3.Navmesh.Current.Navigator.Destination = new Nav.Vec3(vecDest.X, vecDest.Y, vecDest.Z);

                // Get current destination.
                Nav.Vec3 goToPosition = Nav.D3.Navmesh.Current.Navigator.GoToPosition;
                while (goToPosition.IsEmpty)
                    await Task.Delay(10);

                SharpDX.Vector3 goToPositionVector = new SharpDX.Vector3(goToPosition.X, goToPosition.Y, goToPosition.Z);
                await MoveToPosAsync(goToPositionVector);



            }

            return true;
        }
Example #25
0
 private void DrawEntity(WindowRenderTarget device, ProtoBuf.Entity localPlay, ProtoBuf.Entity entity, SharpDX.Vector2 screenMid, SharpDX.Color color)
 {
     if (entity != null)
     {
         SharpDX.Vector2 pointToRotate = SharpDX.Vector2.op_UnaryPlus(new SharpDX.Vector2(entity.baseEntity.pos.x, entity.baseEntity.pos.z));
         pointToRotate.X = localPlay.baseEntity.pos.x - entity.baseEntity.pos.x;
         pointToRotate.Y = localPlay.baseEntity.pos.z - entity.baseEntity.pos.z;
         if (pointToRotate.Length() <= 149f)
         {
             if (pointToRotate.Length() > 150f)
             {
                 pointToRotate.Normalize();
                 pointToRotate = (SharpDX.Vector2)(pointToRotate * 150f);
             }
             pointToRotate += screenMid;
             pointToRotate  = RotatePoint(pointToRotate, screenMid, localPlayer.baseEntity.rot.y);
             this.FillEllipse(device, new SharpDX.Color(0xff, 0xff, 0xff, color.A), pointToRotate.X + 1.5f, pointToRotate.Y + 1.5f, 6f, 6f, true);
             this.FillEllipse(device, color, pointToRotate.X + 1f, pointToRotate.Y + 1f, 4f, 4f, true);
         }
     }
 }
Example #26
0
        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);
        }
Example #27
0
        public static async Task <bool> MoveToPosAsync(SharpDX.Vector3 vecDest, int NearDistance = 50)
        {
            var localAcd = ActorCommonDataHelper.GetLocalAcd();
            var distance = (Math.Pow(localAcd.x0D0_WorldPosX - vecDest.X, 2) + Math.Pow(localAcd.x0D4_WorldPosY - vecDest.Y, 2));

            var minDistanceReached = distance;
            var dtDistanceReached  = DateTime.Now;

            DateTime dtTimeout = DateTime.Now;

            while (distance > NearDistance)
            {
                if (DateTime.Now > dtTimeout.AddSeconds(30) || DateTime.Now > dtDistanceReached.AddSeconds(10))
                {
                    return(false);
                }

                SharpDX.Vector2 curVector  = new SharpDX.Vector2(localAcd.x0D0_WorldPosX, localAcd.x0D4_WorldPosY);
                SharpDX.Vector2 destVector = new SharpDX.Vector2(vecDest.X, vecDest.Y);

                distance = (Math.Pow(localAcd.x0D0_WorldPosX - vecDest.X, 2) + Math.Pow(localAcd.x0D4_WorldPosY - vecDest.Y, 2));
                var minExtendValue = Math.Min(10f, float.Parse(distance.ToString(), CultureInfo.InvariantCulture.NumberFormat));

                var vecNormalized = curVector.Extend(destVector, minExtendValue).To3D();

                System.Drawing.Point screenPoint = D3ToScreen.FromD3toScreenCoords(vecNormalized);

                MouseEvents.RightClick(screenPoint.X, screenPoint.Y);
                await Task.Delay(new Random().Next(100, 250));

                if (distance < minDistanceReached)
                {
                    minDistanceReached = distance;
                    dtDistanceReached  = DateTime.Now;
                }
            }

            return(true);
        }
Example #28
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));
            }
        }
Example #29
0
        /// <summary>
        /// Function to draw the selection region.
        /// </summary>
        /// <param name="region">The region to draw.</param>
        public void Draw(DX.RectangleF region)
        {
            GorgonTexture2DView texture = _selectionTexture.Value;

            Debug.Assert(texture != null, "No texture was found for the selection rectangle.");

            _renderer.DrawFilledRectangle(region,
                                          Color,
                                          texture,
                                          texture.ToTexel(new DX.Rectangle((int)_selectionTextureOffset.X,
                                                                           (int)_selectionTextureOffset.Y,
                                                                           (int)region.Width, (int)region.Height)));

            _renderer.DrawRectangle(region, BorderColor);

            _selectionTextureOffset = new DX.Vector2(_selectionTextureOffset.X - (GorgonTiming.Delta * Speed.X), _selectionTextureOffset.Y - (GorgonTiming.Delta * Speed.Y));

            float regionMin = region.Width.Max(region.Height) * 2;

            if (_selectionTextureOffset.X < -regionMin)
            {
                _selectionTextureOffset = new DX.Vector2(-(regionMin + _selectionTextureOffset.X), _selectionTextureOffset.Y);
            }

            if (_selectionTextureOffset.Y < -regionMin)
            {
                _selectionTextureOffset = new DX.Vector2(_selectionTextureOffset.X, -(regionMin + _selectionTextureOffset.Y));
            }

            if (_selectionTextureOffset.X > regionMin)
            {
                _selectionTextureOffset = new DX.Vector2((_selectionTextureOffset.X - regionMin), _selectionTextureOffset.Y);
            }

            if (_selectionTextureOffset.Y > regionMin)
            {
                _selectionTextureOffset = new DX.Vector2(_selectionTextureOffset.X, (_selectionTextureOffset.Y - regionMin));
            }
        }
Example #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Plane" /> class.
        /// </summary>
        /// <param name="graphics">The graphics interface to use.</param>
        /// <param name="size">The width and height of the plane.</param>
        /// <param name="textureCoordinates">The texture coordinates to apply to the plane.</param>
        /// <param name="angle">The initial orientation, in degrees.</param>
        /// <param name="columns">The number of columns to subdivide by.</param>
        /// <param name="rows">The number of rows to subdivide by.</param>
        public Plane(GorgonGraphics graphics, DX.Vector2 size, RectangleF textureCoordinates, DX.Vector3 angle, int columns = 1, int rows = 1)
            : base(graphics)
        {
            PrimitiveType = PrimitiveType.TriangleStrip;
            VertexCount   = (columns + 1) * (rows + 1);
            IndexCount    = ((columns * rows) * 6) + (rows - 1);
            TriangleCount = (IndexCount - (rows - 1)) / 3;

            DX.Quaternion.RotationYawPitchRoll(angle.Y.ToRadians(), angle.X.ToRadians(), angle.Z.ToRadians(), out DX.Quaternion orientation);
            DX.Matrix.RotationQuaternion(ref orientation, out _orientation);

            using (var vertexData = new GorgonNativeBuffer <Vertex3D>(VertexCount))
                using (var indexData = new GorgonNativeBuffer <int>(IndexCount))
                {
                    GetVertices(vertexData, size, textureCoordinates, columns, rows);
                    GetIndices(indexData, columns, rows);

                    CalculateTangents(vertexData, indexData);

                    VertexBuffer = new GorgonVertexBuffer(graphics,
                                                          new GorgonVertexBufferInfo("PlaneVB")
                    {
                        Usage       = ResourceUsage.Immutable,
                        SizeInBytes = vertexData.SizeInBytes
                    },
                                                          vertexData.Cast <byte>());

                    IndexBuffer = new GorgonIndexBuffer(graphics,
                                                        new GorgonIndexBufferInfo
                    {
                        Usage           = ResourceUsage.Immutable,
                        Use16BitIndices = false,
                        IndexCount      = IndexCount
                    },
                                                        indexData);
                }
        }
Example #31
0
        /// <summary>
        /// Function to update the working sprite data from the sprite content.
        /// </summary>
        private void UpdateWorkingSprite()
        {
            if (_workingSprite == null)
            {
                return;
            }

            _workingSprite.Texture           = SpriteContent?.Texture;
            _workingSprite.TextureArrayIndex = TextureArrayIndex;

            if (SpriteContent?.Texture == null)
            {
                return;
            }

            var spriteRegion = SpriteContent.Texture.ToPixel(SpriteContent.TextureCoordinates).ToRectangleF();

            DX.Vector2 scaledSpritePosition = ToClient(spriteRegion.TopLeft).Truncate();

            _workingSprite.TextureRegion = SpriteContent.TextureCoordinates;
            _workingSprite.Size          = spriteRegion.Size;
            _workingSprite.Position      = scaledSpritePosition;
            _workingSprite.Scale         = new DX.Vector2(ZoomScaleValue);
        }
Example #32
0
        public static async Task<bool> MoveToPosAsync(SharpDX.Vector3 vecDest, int NearDistance = 50)
        {
            var localAcd = ActorCommonDataHelper.GetLocalAcd();
            var distance = (Math.Pow(localAcd.x0D0_WorldPosX - vecDest.X, 2) + Math.Pow(localAcd.x0D4_WorldPosY - vecDest.Y, 2));

            var minDistanceReached = distance;
            var dtDistanceReached = DateTime.Now;

            DateTime dtTimeout = DateTime.Now;
            while (distance > NearDistance)
            {
                if (DateTime.Now > dtTimeout.AddSeconds(30) || DateTime.Now > dtDistanceReached.AddSeconds(10))
                    return false;

                SharpDX.Vector2 curVector = new SharpDX.Vector2(localAcd.x0D0_WorldPosX, localAcd.x0D4_WorldPosY);
                SharpDX.Vector2 destVector = new SharpDX.Vector2(vecDest.X, vecDest.Y);

                distance = (Math.Pow(localAcd.x0D0_WorldPosX - vecDest.X, 2) + Math.Pow(localAcd.x0D4_WorldPosY - vecDest.Y, 2));
                var minExtendValue = Math.Min(10f, float.Parse(distance.ToString(), CultureInfo.InvariantCulture.NumberFormat));

                var vecNormalized = curVector.Extend(destVector, minExtendValue).To3D(); 

                System.Drawing.Point screenPoint = D3ToScreen.FromD3toScreenCoords(vecNormalized);

                MouseEvents.RightClick(screenPoint.X, screenPoint.Y);
                await Task.Delay(new Random().Next(100, 250));

                if (distance < minDistanceReached)
                {
                    minDistanceReached = distance;
                    dtDistanceReached = DateTime.Now;
                }
            }

            return true;
        }
Example #33
0
    protected virtual void ArrangeChildren()
    {
      bool fireScrolled = false;
      _totalHeight = 0;
      _totalWidth = 0;
      IList<FrameworkElement> visibleChildren = GetVisibleChildren();
      int numVisibleChildren = visibleChildren.Count;
      if (numVisibleChildren > 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 children above _actualFirstVisibleChildIndex or below _actualLastVisibleChildIndex
        // 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)
              _actualFirstVisibleChildIndex = pendingSI;
            else
            {
              _actualLastVisibleChildIndex = pendingSI;
              invertLayouting = true;
            }
            _pendingScrollIndex = null;
          }

        // 1) Calculate scroll indices
        if (_doScroll)
        { // Calculate last visible child
          float spaceLeft = actualExtendsInOrientationDirection;
          if (invertLayouting)
          {
            CalcHelper.Bound(ref _actualLastVisibleChildIndex, 0, numVisibleChildren - 1);
            _actualFirstVisibleChildIndex = _actualLastVisibleChildIndex + 1;
            while (_actualFirstVisibleChildIndex > 0)
            {
              FrameworkElement child = visibleChildren[_actualFirstVisibleChildIndex - 1];
              spaceLeft -= GetExtendsInOrientationDirection(Orientation, child.DesiredSize);
              if (spaceLeft + DELTA_DOUBLE < 0)
                break; // Found item which is not visible any more
              _actualFirstVisibleChildIndex--;
            }
            if (_actualFirstVisibleChildIndex > _actualLastVisibleChildIndex)
              // Happens if the item at _actualFirstVisibleChildIndex is bigger than the available space
              _actualFirstVisibleChildIndex = _actualLastVisibleChildIndex;
            if (spaceLeft > 0)
            { // Correct the last scroll index to fill the available space
              while (_actualLastVisibleChildIndex < numVisibleChildren - 1)
              {
                FrameworkElement child = visibleChildren[_actualLastVisibleChildIndex + 1];
                spaceLeft -= GetExtendsInOrientationDirection(Orientation, child.DesiredSize);
                if (spaceLeft + DELTA_DOUBLE < 0)
                  break; // Found item which is not visible any more
                _actualLastVisibleChildIndex++;
              }
            }
          }
          else
          {
            CalcHelper.Bound(ref _actualFirstVisibleChildIndex, 0, numVisibleChildren - 1);
            _actualLastVisibleChildIndex = _actualFirstVisibleChildIndex - 1;
            while (_actualLastVisibleChildIndex < numVisibleChildren - 1)
            {
              FrameworkElement child = visibleChildren[_actualLastVisibleChildIndex + 1];
              spaceLeft -= GetExtendsInOrientationDirection(Orientation, child.DesiredSize);
              if (spaceLeft + DELTA_DOUBLE < 0)
                break; // Found item which is not visible any more
              _actualLastVisibleChildIndex++;
            }
            if (_actualLastVisibleChildIndex < _actualFirstVisibleChildIndex)
              // Happens if the item at _actualFirstVisibleChildIndex is bigger than the available space
              _actualLastVisibleChildIndex = _actualFirstVisibleChildIndex;
            if (spaceLeft > 0)
            { // Correct the first scroll index to fill the available space
              while (_actualFirstVisibleChildIndex > 0)
              {
                FrameworkElement child = visibleChildren[_actualFirstVisibleChildIndex - 1];
                spaceLeft -= GetExtendsInOrientationDirection(Orientation, child.DesiredSize);
                if (spaceLeft + DELTA_DOUBLE < 0)
                  break; // Found item which is not visible any more
                _actualFirstVisibleChildIndex--;
              }
            }
          }
        }
        else
        {
          _actualFirstVisibleChildIndex = 0;
          _actualLastVisibleChildIndex = numVisibleChildren - 1;
        }

        // 2) Calculate start position
        for (int i = 0; i < _actualFirstVisibleChildIndex; i++)
        {
          FrameworkElement child = visibleChildren[i];
          startPosition -= GetExtendsInOrientationDirection(Orientation, child.DesiredSize);
        }

        // 3) Arrange children
        if (Orientation == Orientation.Vertical)
          _totalWidth = actualExtendsInNonOrientationDirection;
        else
          _totalHeight = actualExtendsInNonOrientationDirection;
        foreach (FrameworkElement child in visibleChildren)
        {
          SizeF childSize = child.DesiredSize;
          // For Orientation == vertical, this is childSize.Height, for horizontal it is childSize.Width
          float desiredExtendsInOrientationDirection = GetExtendsInOrientationDirection(Orientation, childSize);
          if (Orientation == Orientation.Vertical)
          {
            PointF position = new PointF(actualPosition.X, actualPosition.Y + startPosition);

            childSize.Width = actualExtendsInNonOrientationDirection;

            ArrangeChildHorizontal(child, child.HorizontalAlignment, ref position, ref childSize);
            child.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize));
            _totalHeight += desiredExtendsInOrientationDirection;

            startPosition += desiredExtendsInOrientationDirection;
          }
          else
          {
            PointF position = new PointF(actualPosition.X + startPosition, actualPosition.Y);

            childSize.Height = actualExtendsInNonOrientationDirection;

            ArrangeChildVertical(child, child.VerticalAlignment, ref position, ref childSize);
            child.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize));
            _totalWidth += desiredExtendsInOrientationDirection;

            startPosition += desiredExtendsInOrientationDirection;
          }
        }
        // 4) Add size gap for the last item if we use logical scrolling. If we scroll to the bottom/to the right, there might be a gap from the last item
        //    to the end of the area. We need to add that gap to make the scroll bars show the correct size.
        if (_doScroll)
        {
          float spaceLeft = actualExtendsInOrientationDirection;
          for (int i = _actualFirstVisibleChildIndex; i <= _actualFirstVisibleChildIndex; i++)
          {
            FrameworkElement child = visibleChildren[i];
            float childSize = GetExtendsInOrientationDirection(Orientation, child.DesiredSize);
            if (childSize < spaceLeft + DELTA_DOUBLE)
              spaceLeft -= childSize;
            else
            {
              if (Orientation == Orientation.Vertical)
                _totalHeight += spaceLeft;
              else
                _totalWidth += spaceLeft;
              break;
            }
          }
        }
      }
      else
      {
        _actualFirstVisibleChildIndex = 0;
        _actualLastVisibleChildIndex = -1;
      }
      if (fireScrolled)
        InvokeScrolled();
    }
Example #34
0
    protected override void ArrangeOverride()
    {
      base.ArrangeOverride();

      IList<FrameworkElement> visibleChildren = GetVisibleChildren();
      int visibleChildrenCount = visibleChildren.Count;

      if (_doScroll)
        CalculateDesiredSize(new SizeF((float) ActualWidth, (float) ActualHeight), false, out _actualColumnWidth, out _actualRowHeight);
      else
      {
        _actualColumnWidth = (float) (ActualWidth/_actualColumns);
        _actualRowHeight = (float) (ActualHeight/_actualRows);
      }

      _actualNumVisibleCols = (int) (ActualWidth/_actualColumnWidth);
      _actualNumVisibleRows = (int) (ActualHeight/_actualRowHeight);

      if (_doScroll)
      {
        int maxScrollIndexX = Math.Max(_actualColumns - _actualNumVisibleCols, 0);
        int maxScrollIndexY = Math.Max(_actualRows - _actualNumVisibleRows, 0);

        if (_scrollIndexX > maxScrollIndexX)
          _scrollIndexX = maxScrollIndexX;
        if (_scrollIndexY > maxScrollIndexY)
          _scrollIndexY = maxScrollIndexY;
      }
      else
      {
        _scrollIndexX = 0;
        _scrollIndexY = 0;
      }

      // Hint: We cannot skip the arrangement of children above _scrollOffset or below the last visible child
      // because the rendering and focus system also needs the bounds of the currently invisible children
      for (int i = 0; i < visibleChildrenCount; i++)
      {
        FrameworkElement child = visibleChildren[i];
        SizeF childSize = new SizeF(_actualColumnWidth, _actualRowHeight);
        PointF position = new PointF(
            ActualPosition.X + (i % _actualColumns - _scrollIndexX)*_actualColumnWidth,
            ActualPosition.Y + (i / _actualColumns - _scrollIndexY)*_actualRowHeight);

        ArrangeChild(child, child.HorizontalAlignment, child.VerticalAlignment, ref position, ref childSize);
        child.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize));
      }
    }
 protected override void ArrangeOverride()
 {
   base.ArrangeOverride();
   FrameworkElement content = Content;
   if (content != null)
   {
     PointF position = new PointF(_innerRect.X, _innerRect.Y);
     SizeF availableSize = CalculateInnerDesiredSize(_innerRect.Size);
     ArrangeChild(content, content.HorizontalAlignment, content.VerticalAlignment, ref position, ref availableSize);
     RectangleF childRect = SharpDXExtensions.CreateRectangleF(position, availableSize);
     content.Arrange(childRect);
   }
 }
Example #36
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));
      }
    }
    protected override void ArrangeChildren()
    {
      bool fireScrolled = false;
      lock (Children.SyncRoot)
      {
        _arrangedItemsStartIndex = -1;
        IItemProvider itemProvider = ItemProvider;
        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);
          // 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;

          //Percentage of child size to offset child positions
          float physicalOffset = _actualPhysicalOffset;

          if (_pendingScrollIndex.HasValue)
          {
            fireScrolled = true;
            int pendingSI = _pendingScrollIndex.Value;
            physicalOffset = _actualPhysicalOffset = _pendingPhysicalOffset;
            CalcHelper.Bound(ref pendingSI, 0, numItems - 1);
            if (_scrollToFirst)
              _actualFirstVisibleChildIndex = pendingSI;
            else
            {
              _actualLastVisibleChildIndex = pendingSI;
              //If we have an offset then there will be part of an additional item visible
              if (physicalOffset != 0)
                _actualLastVisibleChildIndex++;
              invertLayouting = true;
            }
            _pendingScrollIndex = null;
          }

          // 1) Calculate scroll indices
          if (_doScroll)
          {
            float spaceLeft = actualExtendsInOrientationDirection;
            //Allow space for partially visible items at top and bottom
            if (physicalOffset != 0)
              spaceLeft += _averageItemSize;
            if (invertLayouting)
            {
              CalcHelper.Bound(ref _actualLastVisibleChildIndex, 0, numItems - 1);
              _actualFirstVisibleChildIndex = _actualLastVisibleChildIndex + 1;
              int ct = MAX_NUM_VISIBLE_ITEMS;
              while (_actualFirstVisibleChildIndex > 0)
              {
                FrameworkElement item = GetItem(_actualFirstVisibleChildIndex - 1, itemProvider, true);
                if (item == null || !item.IsVisible)
                  continue;
                if (ct-- == 0)
                  break;
                spaceLeft -= GetExtendsInOrientationDirection(Orientation, item.DesiredSize);
                if (spaceLeft + DELTA_DOUBLE < 0)
                  break; // Found item which is not visible any more
                _actualFirstVisibleChildIndex--;
              }
              if (_actualFirstVisibleChildIndex > _actualLastVisibleChildIndex)
                // Happens if the item at _actualFirstVisibleChildIndex is bigger than the available space
                _actualFirstVisibleChildIndex = _actualLastVisibleChildIndex;
              if (spaceLeft > 0)
              { // Correct the last scroll index to fill the available space
                while (_actualLastVisibleChildIndex < numItems - 1)
                {
                  FrameworkElement item = GetItem(_actualLastVisibleChildIndex + 1, itemProvider, true);
                  if (item == null || !item.IsVisible)
                    continue;
                  if (ct-- == 0)
                    break;
                  spaceLeft -= GetExtendsInOrientationDirection(Orientation, item.DesiredSize);
                  if (spaceLeft + DELTA_DOUBLE < 0)
                    break; // Found item which is not visible any more
                  _actualLastVisibleChildIndex++;
                }
              }
            }
            else
            {
              CalcHelper.Bound(ref _actualFirstVisibleChildIndex, 0, numItems - 1);
              _actualLastVisibleChildIndex = _actualFirstVisibleChildIndex - 1;
              int ct = MAX_NUM_VISIBLE_ITEMS;
              while (_actualLastVisibleChildIndex < numItems - 1)
              {
                FrameworkElement item = GetItem(_actualLastVisibleChildIndex + 1, itemProvider, true);
                if (item == null || !item.IsVisible)
                  continue;
                if (ct-- == 0)
                  break;
                spaceLeft -= GetExtendsInOrientationDirection(Orientation, item.DesiredSize);
                if (spaceLeft + DELTA_DOUBLE < 0)
                  break; // Found item which is not visible any more
                _actualLastVisibleChildIndex++;
              }
              if (_actualLastVisibleChildIndex < _actualFirstVisibleChildIndex)
                // Happens if the item at _actualFirstVisibleChildIndex is bigger than the available space
                _actualLastVisibleChildIndex = _actualFirstVisibleChildIndex;
              if (spaceLeft > 0)
              { // Correct the first scroll index to fill the available space
                while (_actualFirstVisibleChildIndex > 0)
                {
                  FrameworkElement item = GetItem(_actualFirstVisibleChildIndex - 1, itemProvider, true);
                  if (item == null || !item.IsVisible)
                    continue;
                  if (ct-- == 0)
                    break;
                  spaceLeft -= GetExtendsInOrientationDirection(Orientation, item.DesiredSize);
                  if (spaceLeft + DELTA_DOUBLE < 0)
                    break; // Found item which is not visible any more
                  _actualFirstVisibleChildIndex--;
                }
              }
            }
          }
          else
          {
            _actualFirstVisibleChildIndex = 0;
            _actualLastVisibleChildIndex = numItems - 1;
          }

          // 2) Arrange children
          if (Orientation == Orientation.Vertical)
            _totalWidth = actualExtendsInNonOrientationDirection;
          else
            _totalHeight = actualExtendsInNonOrientationDirection;
          _arrangedItems.Clear();

          _arrangedItemsStartIndex = _actualFirstVisibleChildIndex;
          // Heavy scrolling works best with at least two times the number of visible items arranged above and below
          // our visible children. That was tested out. If someone has a better heuristic, please use it here.
          int numArrangeAroundViewport = ((int) (actualExtendsInOrientationDirection / _averageItemSize) + 1) * NUM_ADD_MORE_FOCUS_ELEMENTS;
          // Elements before _actualFirstVisibleChildIndex

          //Calculate number of pixels to shift items up/left by based on offset
          float startOffset = -(physicalOffset * _averageItemSize);
          for (int i = _actualFirstVisibleChildIndex - 1; i >= 0 && i >= _actualFirstVisibleChildIndex - numArrangeAroundViewport; i--)
          {
            FrameworkElement item = GetItem(i, itemProvider, true);
            if (item == null || !item.IsVisible)
              continue;
            SizeF childSize = item.DesiredSize;
            // For Orientation == vertical, this is childSize.Height, for horizontal it is childSize.Width
            float desiredExtendsInOrientationDirection = GetExtendsInOrientationDirection(Orientation, childSize);
            startOffset -= desiredExtendsInOrientationDirection;
            if (Orientation == Orientation.Vertical)
            {
              PointF position = new PointF(actualPosition.X, actualPosition.Y + startOffset);

              childSize.Width = actualExtendsInNonOrientationDirection;

              ArrangeChildHorizontal(item, item.HorizontalAlignment, ref position, ref childSize);
              item.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize));
              _totalHeight += desiredExtendsInOrientationDirection;
            }
            else
            {
              PointF position = new PointF(actualPosition.X + startOffset, actualPosition.Y);

              childSize.Height = actualExtendsInNonOrientationDirection;

              ArrangeChildVertical(item, item.VerticalAlignment, ref position, ref childSize);
              item.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize));
              _totalWidth += desiredExtendsInOrientationDirection;
            }
            _arrangedItems.Insert(0, item);
            _arrangedItemsStartIndex = i;
          }

          //Calculate number of pixels to shift items up/left by based on offset
          startOffset = -(physicalOffset * _averageItemSize);
          // Elements from _actualFirstVisibleChildIndex to _actualLastVisibleChildIndex + _numArrangeAroundViewport
          for (int i = _actualFirstVisibleChildIndex; i < numItems && i <= _actualLastVisibleChildIndex + numArrangeAroundViewport; i++)
          {
            FrameworkElement item = GetItem(i, itemProvider, true);
            if (item == null || !item.IsVisible)
              continue;
            SizeF childSize = item.DesiredSize;
            // For Orientation == vertical, this is childSize.Height, for horizontal it is childSize.Width
            float desiredExtendsInOrientationDirection = GetExtendsInOrientationDirection(Orientation, childSize);
            if (Orientation == Orientation.Vertical)
            {
              PointF position = new PointF(actualPosition.X, actualPosition.Y + startOffset);

              childSize.Width = actualExtendsInNonOrientationDirection;

              ArrangeChildHorizontal(item, item.HorizontalAlignment, ref position, ref childSize);
              item.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize));
              _totalHeight += desiredExtendsInOrientationDirection;

              startOffset += desiredExtendsInOrientationDirection;
            }
            else
            {
              PointF position = new PointF(actualPosition.X + startOffset, actualPosition.Y);

              childSize.Height = actualExtendsInNonOrientationDirection;

              ArrangeChildVertical(item, item.VerticalAlignment, ref position, ref childSize);
              item.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize));
              _totalWidth += desiredExtendsInOrientationDirection;

              startOffset += desiredExtendsInOrientationDirection;
            }
            _arrangedItems.Add(item);
          }
          int numInvisible = numItems - _arrangedItems.Count; // Items which have not been arranged above, i.e. item extends have not been added to _totalHeight / _totalWidth
          float invisibleRequiredSize = numInvisible * _averageItemSize;
          if (_doScroll)
            invisibleRequiredSize += actualExtendsInOrientationDirection % _averageItemSize; // Size gap from the last item to the end of the actual extends
          if (Orientation == Orientation.Vertical)
            _totalHeight += invisibleRequiredSize;
          else
            _totalWidth += invisibleRequiredSize;

          itemProvider.Keep(_arrangedItemsStartIndex - INVISIBLE_KEEP_THRESHOLD,
              _arrangedItemsStartIndex + _arrangedItems.Count + INVISIBLE_KEEP_THRESHOLD);
        }
        else
        {
          _arrangedItemsStartIndex = 0;
          _actualFirstVisibleChildIndex = 0;
          _actualLastVisibleChildIndex = -1;
        }
      }
      if (fireScrolled)
        InvokeScrolled();
    }
Example #38
0
 protected bool LocatedBelow(RectangleF otherRect, out float topOrLeftDifference)
 {
   RectangleF actualBounds = ActualBounds;
   bool isNear = IsNear(actualBounds.Top, otherRect.Bottom);
   PointF start = new PointF((actualBounds.Right + actualBounds.Left) / 2, actualBounds.Top);
   PointF end = new PointF((otherRect.Right + otherRect.Left) / 2, otherRect.Bottom);
   float alpha = CalcDirection(start, end);
   topOrLeftDifference = Math.Abs(actualBounds.Left - otherRect.Left);
   return isNear || alpha > DELTA_DOUBLE && alpha < Math.PI - DELTA_DOUBLE;
 }
    protected override void ArrangeTemplateControl()
    {
      if (_templateControl == null)
      {
        _scrollOffsetX = 0;
        _scrollOffsetY = 0;
      }
      else
      {
        SizeF desiredSize = _templateControl.DesiredSize;
        PointF position;
        SizeF availableSize;
        if (_doScroll || AutoCentering != ScrollAutoCenteringEnum.None)
        {
          availableSize = _innerRect.Size;
          if (desiredSize.Width > _innerRect.Width)
          {
            if (!IsHorzCentering)
              _scrollOffsetX = Math.Max(_scrollOffsetX, _innerRect.Width - desiredSize.Width);
            availableSize.Width = desiredSize.Width;
          }
          else if (!IsHorzCentering)
            _scrollOffsetX = 0;

          if (desiredSize.Height > _innerRect.Height)
          {
            if (!IsVertCentering)
              _scrollOffsetY = Math.Max(_scrollOffsetY, _innerRect.Height - desiredSize.Height);
            availableSize.Height = desiredSize.Height;
          }
          else if (!IsVertCentering)
            _scrollOffsetY = 0;
          position = new PointF(_innerRect.X + _scrollOffsetX, _innerRect.Y + _scrollOffsetY);
        }
        else
        {
          _scrollOffsetX = 0;
          _scrollOffsetY = 0;
          position = new PointF(_innerRect.X, _innerRect.Y);
          availableSize = _innerRect.Size;
        }

        if (HorizontalFitToSpace)
          availableSize.Width = _innerRect.Size.Width;
        if (VerticalFitToSpace)
          availableSize.Height = _innerRect.Size.Height;

        ArrangeChild(_templateControl, _templateControl.HorizontalAlignment, _templateControl.VerticalAlignment,
            ref position, ref availableSize);
        RectangleF childRect = SharpDXExtensions.CreateRectangleF(position, availableSize);
        _templateControl.Arrange(childRect);
      }
      _actualScrollOffsetX = _scrollOffsetX;
      _actualScrollOffsetY = _scrollOffsetY;
    }
Example #40
0
 /// <summary>
 /// Transforms a screen point to local element space. The <see cref="UIElement.ActualPosition"/> is also taken into account.
 /// </summary>
 /// <param name="point">Screen point</param>
 /// <returns>Returns the transformed point in element coordinates.</returns>
 public virtual PointF TransformScreenPoint(PointF point)
 {
   // overridden in FrameworkElement to apply transformation
   var actualPosition = ActualPosition;
   return new PointF(point.X - actualPosition.X, point.Y - actualPosition.Y);
 }
Example #41
0
 protected virtual void ArrangeTemplateControl()
 {
   FrameworkElement templateControl = _templateControl;
   if (templateControl == null)
     return;
   PointF position = new PointF(_innerRect.X, _innerRect.Y);
   SizeF availableSize = new SizeF(_innerRect.Width, _innerRect.Height);
   ArrangeChild(templateControl, HorizontalContentAlignment, VerticalContentAlignment,
       ref position, ref availableSize);
   RectangleF childRect = SharpDXExtensions.CreateRectangleF(position, availableSize);
   templateControl.Arrange(childRect);
 }
Example #42
0
		public static s.Vector2[] ToDx(this PointF[] points)
		{
			var p = new s.Vector2[points.Length];
			for (var i = 0; i < points.Length; ++i)
				p[i] = points[i].ToDx();
			return p;
		}
    protected override void ArrangeOverride()
    {
      base.ArrangeOverride();

      IList<FrameworkElement> visibleChildren = GetVisibleChildren();
      if (visibleChildren.Count > 0)
      {
        float actualWidth = (float) ActualWidth;
        float actualHeight = (float) ActualHeight;

        // First check how many children we must leave out
        float availableSize = Orientation == Orientation.Vertical ? actualHeight : actualWidth;
        FrameworkElement firstChild = visibleChildren[0];
        SizeF firstChildDesiredSize = firstChild.DesiredSize;
        SizeF desiredEllipsisSize = _ellipsisControl == null ? new SizeF() : _ellipsisControl.DesiredSize;
        // The first element is always shown
        availableSize -= Orientation == Orientation.Vertical ? firstChildDesiredSize.Height : firstChildDesiredSize.Width;
        List<FrameworkElement> reversedChildren = new List<FrameworkElement>(visibleChildren);
        reversedChildren.Reverse();
        reversedChildren.RemoveAt(reversedChildren.Count - 1); // Remove first (home) element
        int numShownChildrenAfterEllipsis = 0; // Number of children which fit behind the ellipsis control
        float ellipsisSize = Orientation == Orientation.Vertical ? desiredEllipsisSize.Height : desiredEllipsisSize.Width;
        foreach (FrameworkElement child in reversedChildren)
        {
          SizeF desiredChildSize = child.DesiredSize;
          float size = Orientation == Orientation.Vertical ? desiredChildSize.Height : desiredChildSize.Width;
          if (availableSize >= size + ellipsisSize ||
              (availableSize >= size && numShownChildrenAfterEllipsis == visibleChildren.Count - 2))
          {
            availableSize -= size;
            numShownChildrenAfterEllipsis++;
          }
          else
            break;
        }
        float startPositionX = 0;
        float startPositionY = 0;
        List<FrameworkElement> childrenAfterEllipsis = new List<FrameworkElement>(visibleChildren);
        if (numShownChildrenAfterEllipsis < visibleChildren.Count - 1)
        { // Ellipsis necessary
          // Lay out first (home) element
          SizeF childSize = firstChild.DesiredSize;
          PointF position = new PointF(ActualPosition.X + startPositionX, ActualPosition.Y + startPositionY);

          if (Orientation == Orientation.Vertical)
          {
            childSize.Width = actualWidth;
            ArrangeChildHorizontal(firstChild, firstChild.HorizontalAlignment, ref position, ref childSize);
            startPositionY += childSize.Height;
          }
          else
          {
            childSize.Height = actualHeight;
            ArrangeChildVertical(firstChild, firstChild.VerticalAlignment, ref position, ref childSize);
            startPositionX += childSize.Width;
          }

          firstChild.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize));

          // Lay out ellipsis
          if (_ellipsisControl != null)
          {
            childSize = desiredEllipsisSize;
            position = new PointF(ActualPosition.X + startPositionX, ActualPosition.Y + startPositionY);

            if (Orientation == Orientation.Vertical)
            {
              childSize.Width = actualWidth;
              ArrangeChildHorizontal(_ellipsisControl, _ellipsisControl.HorizontalAlignment, ref position, ref childSize);
              startPositionY += childSize.Height;
            }
            else
            {
              childSize.Height = actualHeight;
              ArrangeChildVertical(_ellipsisControl, _ellipsisControl.VerticalAlignment, ref position, ref childSize);
              startPositionX += childSize.Width;
            }

            _ellipsisControl.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize));
          }

          int numBeforeEllipsis = childrenAfterEllipsis.Count - numShownChildrenAfterEllipsis;
          for (int i = 1; i < numBeforeEllipsis; i++)
            childrenAfterEllipsis[i].Arrange(RectangleF.Empty);
          childrenAfterEllipsis.RemoveRange(0, numBeforeEllipsis);
        }
        else if (_ellipsisControl != null)
          // childrenAfterEllipsis contains all children in this case
          _ellipsisControl.Arrange(RectangleF.Empty);

        // Lay out all other elements after ellipsis
        foreach (FrameworkElement child in childrenAfterEllipsis)
        {
          SizeF childSize = child.DesiredSize;
          PointF position = new PointF(ActualPosition.X + startPositionX, ActualPosition.Y + startPositionY);

          if (Orientation == Orientation.Vertical)
          {
            childSize.Width = actualWidth;
            ArrangeChildHorizontal(child, child.HorizontalAlignment, ref position, ref childSize);
            startPositionY += childSize.Height;
          }
          else
          {
            childSize.Height = actualHeight;
            ArrangeChildVertical(child, child.VerticalAlignment, ref position, ref childSize);
            startPositionX += childSize.Width;
          }

          child.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize));
        }
      }
    }
Example #44
0
 protected bool LocatedRightOf(RectangleF otherRect, out float topOrLeftDifference)
 {
   RectangleF actualBounds = ActualBounds;
   bool isNear = IsNear(actualBounds.Left, otherRect.Right);
   PointF start = new PointF(actualBounds.Left, (actualBounds.Top + actualBounds.Bottom) / 2);
   PointF end = new PointF(otherRect.Right, (otherRect.Top + otherRect.Bottom) / 2);
   float alpha = CalcDirection(start, end);
   topOrLeftDifference = VerticalDistance(actualBounds, otherRect); //Math.Abs(actualBounds.Top - otherRect.Top);
   return isNear || alpha > Math.PI / 2 + DELTA_DOUBLE && alpha < 3 * Math.PI / 2 - DELTA_DOUBLE;
 }
Example #45
0
 protected bool LocatedAbove(RectangleF otherRect, out float topOrLeftDifference)
 {
   RectangleF actualBounds = ActualBounds;
   bool isNear = IsNear(actualBounds.Bottom, otherRect.Top);
   PointF start = new PointF((actualBounds.Right + actualBounds.Left) / 2, actualBounds.Bottom);
   PointF end = new PointF((otherRect.Right + otherRect.Left) / 2, otherRect.Top);
   float alpha = CalcDirection(start, end);
   topOrLeftDifference = HorizontalDistance(actualBounds, otherRect); //Math.Abs(actualBounds.Left - otherRect.Left);
   return isNear || alpha > Math.PI + DELTA_DOUBLE && alpha < 2 * Math.PI - DELTA_DOUBLE;
 }
Example #46
0
 private static float CalcDirection(PointF start, PointF end)
 {
   if (IsNear(start.X, end.X) && IsNear(start.Y, end.Y))
     return float.NaN;
   double x = end.X - start.X;
   double y = end.Y - start.Y;
   double alpha = Math.Acos(x / Math.Sqrt(x * x + y * y));
   if (end.Y > start.Y) // Coordinates go from top to bottom, so y must be inverted
     alpha = -alpha;
   if (alpha < 0)
     alpha += 2 * Math.PI;
   return (float) alpha;
 }
        public static void AddPathFigureSegment(
            this D2D.GeometrySink sink, Jupiter.Media.PathSegment segment)
        {
            var bezierSegment = segment as BezierSegment;

            if (bezierSegment != null)
            {
                sink.AddBezier(
                    new D2D.BezierSegment
                    {
                        Point1 = bezierSegment.Point1.ToSharpDX(),
                        Point2 = bezierSegment.Point2.ToSharpDX(),
                        Point3 = bezierSegment.Point3.ToSharpDX()
                    });
                return;
            }

            var lineSegment = segment as LineSegment;

            if (lineSegment != null)
            {
                sink.AddLine(
                    lineSegment.Point.ToSharpDX());
                return;
            }

            var polyBezierSegment = segment as PolyBezierSegment;

            if (polyBezierSegment != null)
            {
                var beziers = new D2D.BezierSegment[polyBezierSegment.Points.Count / 3];

                for (int i = 0; i < beziers.Length; i++)
                {
                    beziers[i].Point1 = polyBezierSegment.Points[i * 3].ToSharpDX();
                    beziers[i].Point2 = polyBezierSegment.Points[i * 3 + 1].ToSharpDX();
                    beziers[i].Point3 = polyBezierSegment.Points[i * 3 + 2].ToSharpDX();
                }

                sink.AddBeziers(beziers);
                return;
            }

            var polyLineSegment = segment as PolyLineSegment;

            if (polyLineSegment != null)
            {
                var lines = new SharpDX.Vector2[polyLineSegment.Points.Count];

                for (int i = 0; i < lines.Length; i++)
                {
                    lines[i] = polyLineSegment.Points[i].ToSharpDX();
                }

                sink.AddLines(lines);
                return;
            }

            var quadraticBezierSegment = segment as QuadraticBezierSegment;

            if (quadraticBezierSegment != null)
            {
                sink.AddQuadraticBezier(
                    new D2D.QuadraticBezierSegment
                    {
                        Point1 = quadraticBezierSegment.Point1.ToSharpDX(),
                        Point2 = quadraticBezierSegment.Point2.ToSharpDX()
                    });
                return;
            }

            var polyQuadraticBezierSegment = segment as PolyQuadraticBezierSegment;

            if (polyQuadraticBezierSegment != null)
            {
                var quadraticBeziers = new D2D.QuadraticBezierSegment[polyBezierSegment.Points.Count / 2];

                for (int i = 0; i < quadraticBeziers.Length; i++)
                {
                    quadraticBeziers[i].Point1 = polyBezierSegment.Points[i * 2].ToSharpDX();
                    quadraticBeziers[i].Point2 = polyBezierSegment.Points[i * 2 + 1].ToSharpDX();
                }

                sink.AddQuadraticBeziers(quadraticBeziers);
                return;
            }

            var arcSegment = segment as ArcSegment;

            if (arcSegment != null)
            {
                sink.AddArc(
                    new D2D.ArcSegment
                    {
                        Point = arcSegment.Point.ToSharpDX(),
                        Size = arcSegment.Size.ToSharpDX(),
                        RotationAngle = (float)arcSegment.RotationAngle,
                        SweepDirection = arcSegment.SweepDirection.ToSharpDX(),
                        ArcSize = arcSegment.IsLargeArc ? D2D.ArcSize.Large : D2D.ArcSize.Small
                    });
                return;
            }
        }
 protected bool LocatedAbove(RectangleF otherRect)
 {
   RectangleF actualBounds = ActualBounds;
   if (IsNear(actualBounds.Bottom, otherRect.Top))
     return true;
   PointF start = new PointF((actualBounds.Right + actualBounds.Left) / 2, actualBounds.Bottom);
   PointF end = new PointF((otherRect.Right + otherRect.Left) / 2, otherRect.Top);
   float alpha = CalcDirection(start, end);
   return alpha > Math.PI + DELTA_DOUBLE && alpha < 2 * Math.PI - DELTA_DOUBLE;
 }
Example #49
0
 /// <summary>
 /// Transforms a screen point to local element space. The <see cref="UIElement.ActualPosition"/> is also taken into account.
 /// </summary>
 /// <param name="point">Screen point</param>
 /// <returns>Returns the transformed point in element coordinates.</returns>
 public override PointF TransformScreenPoint(PointF point)
 {
   float x = point.X;
   float y = point.Y;
   if (TransformMouseCoordinates(ref x, ref y))
   {
     return base.TransformScreenPoint(new PointF(x, y));
   }
   return base.TransformScreenPoint(point);
 }
Example #50
0
    protected override void ArrangeOverride()
    {
      base.ArrangeOverride();
      float x = _innerRect.Location.X;
      float y = _innerRect.Location.Y;

      foreach (FrameworkElement child in GetVisibleChildren())
      {
        // Get the coordinates relative to the canvas area.
        PointF location = new PointF(GetLeft(child, false) + x, GetTop(child, false) + y);

        // Get the child size
        SizeF childSize = child.DesiredSize;

        // Arrange the child
        child.Arrange(SharpDXExtensions.CreateRectangleF(location, childSize));
      }
    }
 protected bool LocatedRightOf(RectangleF otherRect)
 {
   RectangleF actualBounds = ActualBounds;
   if (IsNear(actualBounds.Left, otherRect.Right))
     return true;
   PointF start = new PointF(actualBounds.Left, (actualBounds.Top + actualBounds.Bottom) / 2);
   PointF end = new PointF(otherRect.Right, (otherRect.Top + otherRect.Bottom) / 2);
   float alpha = CalcDirection(start, end);
   return alpha > Math.PI / 2 + DELTA_DOUBLE && alpha < 3 * Math.PI / 2 - DELTA_DOUBLE;
 }
Example #52
0
 private static RectangleF CalculateBoundingBox(RectangleF rectangle, Matrix transformation)
 {
   PointF tl = rectangle.Location;
   PointF tr = new PointF(rectangle.Right, rectangle.Top);
   PointF bl = new PointF(rectangle.Left, rectangle.Bottom);
   PointF br = new PointF(rectangle.Right, rectangle.Bottom);
   transformation.Transform(ref tl);
   transformation.Transform(ref tr);
   transformation.Transform(ref bl);
   transformation.Transform(ref br);
   PointF rtl = new PointF(
       Math.Min(tl.X, Math.Min(tr.X, Math.Min(bl.X, br.X))),
       Math.Min(tl.Y, Math.Min(tr.Y, Math.Min(bl.Y, br.Y))));
   PointF rbr = new PointF(
       Math.Max(tl.X, Math.Max(tr.X, Math.Max(bl.X, br.X))),
       Math.Max(tl.Y, Math.Max(tr.Y, Math.Max(bl.Y, br.Y))));
   return SharpDXExtensions.CreateRectangleF(rtl, new SizeF(rbr.X - rtl.X, rbr.Y - rtl.Y));
 }
Example #53
0
 /// <summary>
 /// Arranges the child horizontal and vertical in a given area. If the area is bigger than
 /// the child's desired size, the child will be arranged according to the given <paramref name="horizontalAlignment"/>
 /// and <paramref name="verticalAlignment"/>.
 /// </summary>
 /// <param name="child">The child to arrange. The child will not be changed by this method.</param>
 /// <param name="horizontalAlignment">Alignment in horizontal direction.</param>
 /// <param name="verticalAlignment">Alignment in vertical direction.</param>
 /// <param name="location">Input: The starting position of the available area. Output: The position
 /// the child should be located.</param>
 /// <param name="childSize">Input: The available area for the <paramref name="child"/>. Output:
 /// The area the child should take.</param>
 public void ArrangeChild(FrameworkElement child, HorizontalAlignmentEnum horizontalAlignment, VerticalAlignmentEnum verticalAlignment, ref PointF location, ref SizeF childSize)
 {
   // Be careful when changing the implementation of those arrangement methods.
   // MPF behaves a bit different from WPF: We don't clip elements at the boundaries of containers,
   // instead, we arrange them with a maximum size calculated by the container. If we would not avoid
   // that controls can become bigger than their arrange size, we would have to accomplish a means to clip
   // their render size.
   ArrangeChildHorizontal(child, horizontalAlignment, ref location, ref childSize);
   ArrangeChildVertical(child, verticalAlignment, ref location, ref childSize);
 }
Example #54
0
    public override UIElement InputHitTest(PointF point)
    {
      if (!IsVisible)
        return null;

      if (IsInArea(point.X, point.Y))
      {
        // since we know the z-order here, lets use it, everything other is identical to UIElement implementation.
        foreach (var uiElement in GetChildren().OrderByDescending(e => (e is FrameworkElement) ? ((FrameworkElement)e)._lastZIndex : 0f))
        {
          var hitElement = uiElement.InputHitTest(point);
          if (hitElement != null)
          {
            return hitElement;
          }
        }
        if (IsInVisibleArea(point.X, point.Y))
        {
          return this;
        }
      }
      return null;
    }
Example #55
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;
        }
      }
    }
Example #56
0
    /// <summary>
    /// Arranges the child horizontal in a given area. If the area is bigger than the child's desired
    /// size, the child will be arranged according to the given <paramref name="alignment"/>.
    /// </summary>
    /// <param name="child">The child to arrange. The child will not be changed by this method.</param>
    /// <param name="alignment">Alignment in horizontal direction.</param>
    /// <param name="location">Input: The starting position of the available area. Output: The position
    /// the child should be located.</param>
    /// <param name="childSize">Input: The available area for the <paramref name="child"/>. Output:
    /// The area the child should take.</param>
    public void ArrangeChildHorizontal(FrameworkElement child, HorizontalAlignmentEnum alignment, ref PointF location, ref SizeF childSize)
    {
      // See comment in ArrangeChild
      SizeF desiredSize = child.DesiredSize;

      if (!double.IsNaN(desiredSize.Width) && desiredSize.Width <= childSize.Width)
      {
        // Width takes precedence over Stretch - Use Center as fallback
        if (alignment == HorizontalAlignmentEnum.Center ||
            (alignment == HorizontalAlignmentEnum.Stretch && !double.IsNaN(child.Width)))
        {
          location.X += (childSize.Width - desiredSize.Width) / 2;
          childSize.Width = desiredSize.Width;
        }
        if (alignment == HorizontalAlignmentEnum.Right)
        {
          location.X += childSize.Width - desiredSize.Width;
          childSize.Width = desiredSize.Width;
        }
        else if (alignment == HorizontalAlignmentEnum.Left)
        {
          // Leave location unchanged
          childSize.Width = desiredSize.Width;
        }
        //else if (child.HorizontalAlignment == HorizontalAlignmentEnum.Stretch)
        // - Use all the space, nothing to do here
      }
    }
Example #57
0
    /// <summary>
    /// Arranges the child vertical in a given area. If the area is bigger than the child's desired
    /// size, the child will be arranged according to the given <paramref name="alignment"/>.
    /// </summary>
    /// <param name="child">The child to arrange. The child will not be changed by this method.</param>
    /// <param name="alignment">Alignment in vertical direction.</param>
    /// <param name="location">Input: The starting position of the available area. Output: The position
    /// the child should be located.</param>
    /// <param name="childSize">Input: The available area for the <paramref name="child"/>. Output:
    /// The area the child should take.</param>
    public void ArrangeChildVertical(FrameworkElement child, VerticalAlignmentEnum alignment, ref PointF location, ref SizeF childSize)
    {
      // See comment in ArrangeChild
      SizeF desiredSize = child.DesiredSize;

      if (!double.IsNaN(desiredSize.Height) && desiredSize.Height <= childSize.Height)
      {
        // Height takes precedence over Stretch - Use Center as fallback
        if (alignment == VerticalAlignmentEnum.Center ||
            (alignment == VerticalAlignmentEnum.Stretch && !double.IsNaN(child.Height)))
        {
          location.Y += (childSize.Height - desiredSize.Height) / 2;
          childSize.Height = desiredSize.Height;
        }
        else if (alignment == VerticalAlignmentEnum.Bottom)
        {
          location.Y += childSize.Height - desiredSize.Height;
          childSize.Height = desiredSize.Height;
        }
        else if (alignment == VerticalAlignmentEnum.Top)
        {
          // Leave location unchanged
          childSize.Height = desiredSize.Height;
        }
        //else if (child.VerticalAlignment == VerticalAlignmentEnum.Stretch)
        // - Use all the space, nothing to do here
      }
    }
Example #58
0
    // WPF signature: public IInputElement InputHitTest(Point point)
    /// <summary>
    /// Returns the hit element.
    /// </summary>
    /// <param name="point">Point to check.</param>
    /// <returns><see cref="UIElement"/> that was hit or <c>null</c>.</returns>
    public virtual UIElement InputHitTest(PointF point)
    {
      if (!IsVisible)
        return null;

      if (IsInArea(point.X, point.Y))
      {
        foreach (var uiElement in GetChildren().Reverse())
        {
          var hitElement = uiElement.InputHitTest(point);
          if (hitElement != null)
          {
            return hitElement;
          }
        }
        if (IsInVisibleArea(point.X, point.Y))
        {
          return this;
        }
      }
      return null;
    }