コード例 #1
0
        /// <summary>
        /// Update our logic
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="mousePosition"></param>
        /// <param name="parentPosition"></param>
        public override void Update(GameTime gameTime, Vector2 mousePosition, Vector2 parentPosition)
        {
            if (IsHidden)
            {
                return;
            }

            float height = 0;

            for (int index = 0; index < _children.Count; index++)
            {
                GUIElement child = _children[index];

                if (child.IsHidden)
                {
                    continue;
                }

                child.Update(gameTime, mousePosition, parentPosition + Position + height * Vector2.UnitY);

                height += _children[index].Dimensions.Y;
            }
            if (Math.Abs(Dimensions.Y - height) > 0.01f)
            {
                Dimensions = new Vector2(Dimensions.X, height);
            }
        }
コード例 #2
0
ファイル: GuiListToggle.cs プロジェクト: yivoDev/Modelviewer
        public override void Update(GameTime gameTime, Vector2 mousePosition, Vector2 parentPosition)
        {
            if (IsHidden)
            {
                return;
            }

            if (IsToggled)
            {
                float height = ToggleButtonHeight;
                for (int index = 0; index < _children.Count; index++)
                {
                    GUIElement child = _children[index];

                    if (child.IsHidden)
                    {
                        continue;
                    }

                    child.Update(gameTime, mousePosition, parentPosition + Position + height * Vector2.UnitY);

                    height += _children[index].Dimensions.Y;
                }

                if (Math.Abs(Dimensions.Y - height) > 0.01f)
                {
                    Dimensions = new Vector2(Dimensions.X, height);
                }
            }
            else
            {
                Dimensions = _toggleDimensions;
            }

            _isHovered = false;

            if (GUIControl.UIElementEngaged)
            {
                return;
            }

            Vector2 bound1 = Position + parentPosition;
            Vector2 bound2 = bound1 + _toggleDimensions;

            if (mousePosition.X >= bound1.X && mousePosition.Y >= bound1.Y && mousePosition.X < bound2.X &&
                mousePosition.Y < bound2.Y)
            {
                _isHovered = true;
                if (GUIControl.WasLMBClicked())
                {
                    GUIControl.UIWasUsed = true;

                    IsToggled = !IsToggled;
                }
            }
        }
コード例 #3
0
ファイル: GUICanvas.cs プロジェクト: yivoDev/Modelviewer
 /// <summary>
 /// Update our logic
 /// </summary>
 /// <param name="gameTime"></param>
 /// <param name="mousePosition"></param>
 /// <param name="parentPosition"></param>
 public override void Update(GameTime gameTime, Vector2 mousePosition, Vector2 parentPosition)
 {
     if (!IsEnabled)
     {
         return;
     }
     for (int index = 0; index < _children.Count; index++)
     {
         GUIElement child = _children[index];
         child.Update(gameTime, mousePosition, parentPosition + Position);
     }
 }
コード例 #4
0
        public override void Update(GameTime gameTime, Vector2 mousePosition, Vector2 parentPosition)
        {
            if (IsHidden)
            {
                return;
            }

            if (IsToggled)
            {
                float height = ToggleButtonHeight;
                for (int index = 0; index < _children.Count; index++)
                {
                    GUIElement child = _children[index];

                    if (child.IsHidden)
                    {
                        continue;
                    }
                    child.Update(gameTime, mousePosition, parentPosition + Position + height * Vector2.UnitY + +ScrollTranslation * Vector2.UnitY);

                    height += _children[index].Dimensions.Y;
                }

                if (Math.Abs(Dimensions.Y - height) > 0.01f)
                {
                    Dimensions = new Vector2(Dimensions.X, height);
                }
            }
            else
            {
                Dimensions = _toggleDimensions;
            }

            //If this element is not engaged but some other one is, return.
            if (!IsEngaged && GUIControl.UIElementEngaged)
            {
                return;
            }

            Vector2 bound1 = Position + parentPosition + _toggleDimensions * Vector2.UnitX;
            Vector2 bound2 = bound1 + new Vector2(Scrollwidth, ScrollTotalHeight);

            if (ScrollBarEnabled)
            {
                if (!IsEngaged)
                {
                    ScrollBarHovered = false;

                    if (mousePosition.X >= bound1.X && mousePosition.Y >= bound1.Y && mousePosition.X < bound2.X &&
                        mousePosition.Y < bound2.Y)
                    {
                        ScrollBarHovered = true;

                        if (GUIControl.IsLMBPressed())
                        {
                            GUIControl.UIWasUsed = true;

                            GUIControl.UIElementEngaged = true;
                            IsEngaged = true;

                            // to percent
                            percentScroll = (mousePosition.Y - bound1.Y) / (bound2.Y - bound1.Y);

                            //Now get clamp to slider size
                            float minClamp = 1 / percentOverscroll / 2;
                            percentScroll = (MathHelper.Clamp(percentScroll, minClamp, 1 - minClamp) - minClamp) /
                                            (1 - minClamp * 2);

                            ScrollTranslation = -percentScroll * (ListHeight - ScrollTotalHeight);
                        }
                    }
                }
                else
                {
                    //Break engagement
                    if (!GUIControl.IsLMBPressed())
                    {
                        GUIControl.UIElementEngaged = false;
                        IsEngaged = false;
                    }
                    else
                    {
                        GUIControl.UIWasUsed = true;
                        ScrollBarHovered     = true;

                        percentScroll = (MathHelper.Clamp(mousePosition.Y, bound1.Y, bound2.Y) - bound1.Y) / (bound2.Y - bound1.Y);

                        //Now get clamp to slider size
                        float minClamp = 1 / percentOverscroll / 2;
                        percentScroll = (MathHelper.Clamp(percentScroll, minClamp, 1 - minClamp) - minClamp) /
                                        (1 - minClamp * 2);

                        ScrollTranslation = -percentScroll * (ListHeight - ScrollTotalHeight);
                    }
                }
            }

            if (IsEngaged)
            {
                return;
            }
            //Toggle

            _isHovered = false;

            bound1 = Position + parentPosition;
            bound2 = bound1 + _toggleDimensions;

            if (mousePosition.X >= bound1.X && mousePosition.Y >= bound1.Y && mousePosition.X < bound2.X &&
                mousePosition.Y < bound2.Y)
            {
                _isHovered = true;
                if (GUIControl.WasLMBClicked())
                {
                    GUIControl.UIWasUsed = true;

                    IsToggled = !IsToggled;
                }
            }

            //Scrollbar
        }