CursorOffset() public static method

Static utility method used to get the cursor's offset from the center

of an overlay element in pixels.
public static CursorOffset ( OverlayElement element, Vector2 cursorPos ) : Vector2
element Axiom.Overlays.OverlayElement
cursorPos Vector2
return Vector2
Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cursorPos"></param>
        public override void OnCursorPressed(Vector2 cursorPos)
        {
            if (!this.scrollHandle.IsVisible)
            {
                return;                 // don't care about clicks if text not scrollable
            }

            Vector2 co = Widget.CursorOffset(this.scrollHandle, cursorPos);

            if (co.LengthSquared <= 81)
            {
                this.isDragging = true;
                this.dragOffset = co.y;
            }
            else if (Widget.IsCursorOver(this.scrollTrack, cursorPos))
            {
                Real newTop        = this.scrollHandle.Top + co.y;
                Real lowerBoundary = this.scrollTrack.Height - this.scrollHandle.Height;
                this.scrollHandle.Top = Math.Utility.Clamp <Real>(newTop, lowerBoundary, 0);

                // update text area contents based on new scroll percentage
                this.scrollPercentage = Math.Utility.Clamp <Real>(newTop / lowerBoundary, 1, 0);
                FilterLines();
            }

            base.OnCursorPressed(cursorPos);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cursorPos"></param>
        public override void OnCursorPressed(Vector2 cursorPos)
        {
            if (!this.handle.IsVisible)
            {
                return;
            }

            Vector2 co = Widget.CursorOffset(this.handle, cursorPos);

            if (co.LengthSquared <= 81)
            {
                this.isDragging = true;
                this.dragOffset = co.x;
            }
            else if (Widget.IsCursorOver(this.track, cursorPos))
            {
                Real newLeft       = this.handle.Left + co.x;
                Real rightBoundary = this.track.Width - this.handle.Width;

                this.handle.Left = Math.Utility.Clamp <Real>(newLeft, rightBoundary, 0);
                Value            = GetSnappedValue(newLeft / rightBoundary);
            }

            base.OnCursorPressed(cursorPos);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cursorPos"></param>
        public override void OnCursorMoved(Vector2 cursorPos)
        {
            OverlayManager om = OverlayManager.Instance;

            if (this.isExpanded)
            {
                if (this.isDragging)
                {
                    Vector2 co            = Widget.CursorOffset(this.scrollHandle, cursorPos);
                    Real    newTop        = this.scrollHandle.Top + co.y - this.dragOffset;
                    Real    lowerBoundary = this.scrollTrack.Height - this.scrollHandle.Height;
                    this.scrollHandle.Top = Math.Utility.Clamp <Real>(newTop, lowerBoundary, 0);

                    var scrollPercentage = Math.Utility.Clamp <Real>(newTop / lowerBoundary, 0, 1);
                    var newIndex         = (int)(scrollPercentage * (this.items.Count - this.itemElements.Count) + 0.5);
                    if (newIndex != this.displayIndex)
                    {
                        DisplayIndex = newIndex;
                    }
                    return;
                }

                Real l = this.itemElements[0].DerivedLeft * om.ViewportWidth + 5;
                Real t = this.itemElements[0].DerivedTop * om.ViewportHeight + 5;
                Real r = l + this.itemElements[this.itemElements.Count - 1].Width - 10;
                Real b = this.itemElements[this.itemElements.Count - 1].DerivedTop * om.ViewportHeight +
                         this.itemElements[this.itemElements.Count - 1].Height - 5;

                if (cursorPos.x >= l && cursorPos.x <= r && cursorPos.y >= t && cursorPos.y <= b)
                {
                    var newIndex = (int)(this.displayIndex + (cursorPos.y - t) / (b - t) * this.itemElements.Count);
                    if (this.highlightIndex != newIndex)
                    {
                        this.highlightIndex = newIndex;
                        DisplayIndex        = this.displayIndex;
                    }
                }
            }
            else
            {
                if (IsCursorOver(this.smallBox, cursorPos, 4))
                {
                    this.smallBox.MaterialName       = "SdkTrays/MiniTextBox/Over";
                    this.smallBox.BorderMaterialName = "SdkTrays/MiniTextBox/Over";
                    this.IsCursorOver = true;
                }
                else
                {
                    if (this.IsCursorOver)
                    {
                        this.smallBox.MaterialName       = "SdkTrays/MiniTextBox";
                        this.smallBox.BorderMaterialName = "SdkTrays/MiniTextBox";
                        this.IsCursorOver = false;
                    }
                }
            }

            base.OnCursorMoved(cursorPos);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cursorPos"></param>
        public override void OnCursorMoved(Vector2 cursorPos)
        {
            if (this.isDragging)
            {
                Vector2 co            = Widget.CursorOffset(this.handle, cursorPos);
                Real    newLeft       = this.handle.Left + co.x - this.dragOffset;
                Real    rightBoundary = this.track.Width - this.handle.Width;

                this.handle.Left = Math.Utility.Clamp <Real>(newLeft, rightBoundary, 0);
                Value            = GetSnappedValue(newLeft / rightBoundary);
            }

            base.OnCursorMoved(cursorPos);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cursorPos"></param>
        public override void OnCursorMoved(Vector2 cursorPos)
        {
            if (this.isDragging)
            {
                Vector2 co            = Widget.CursorOffset(this.scrollHandle, cursorPos);
                Real    newTop        = this.scrollHandle.Top + co.y - this.dragOffset;
                Real    lowerBoundary = this.scrollTrack.Height - this.scrollHandle.Height;
                this.scrollHandle.Top = Math.Utility.Clamp <Real>(newTop, lowerBoundary, 0);

                // update text area contents based on new scroll percentage
                this.scrollPercentage = Math.Utility.Clamp <Real>(newTop / lowerBoundary, 1, 0);
                FilterLines();
            }

            base.OnCursorMoved(cursorPos);
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cursorPos"></param>
        public override void OnCursorPressed(Vector2 cursorPos)
        {
            OverlayManager om = OverlayManager.Instance;

            if (this.isExpanded)
            {
                if (this.scrollHandle.IsVisible)                   // check for scrolling
                {
                    Vector2 co = Widget.CursorOffset(this.scrollHandle, cursorPos);

                    if (co.LengthSquared <= 81)
                    {
                        this.isDragging = true;
                        this.dragOffset = co.y;
                        return;
                    }
                    else if (Widget.IsCursorOver(this.scrollTrack, cursorPos))
                    {
                        Real newTop        = this.scrollHandle.Top + co.y;
                        Real lowerBoundary = this.scrollTrack.Height - this.scrollHandle.Height;
                        this.scrollHandle.Top = Math.Utility.Clamp <Real>(newTop, lowerBoundary, 0);

                        var scrollPercentage = Math.Utility.Clamp <Real>(newTop / lowerBoundary, 1, 0);
                        DisplayIndex = (int)(scrollPercentage * (this.items.Count - this.itemElements.Count) + 0.5);
                        return;
                    }
                }

                if (!IsCursorOver(this.expandedBox, cursorPos, 3))
                {
                    Retract();
                }
                else
                {
                    Real l = this.itemElements[0].DerivedLeft * om.ViewportWidth + 5;
                    Real t = this.itemElements[0].DerivedTop * om.ViewportHeight + 5;
                    Real r = l + this.itemElements[this.itemElements.Count - 1].Width - 10;
                    Real b = this.itemElements[this.itemElements.Count - 1].DerivedTop * om.ViewportHeight +
                             this.itemElements[this.itemElements.Count - 1].Height - 5;

                    if (cursorPos.x >= l && cursorPos.x <= r && cursorPos.y >= t && cursorPos.y <= b)
                    {
                        if (this.highlightIndex != this.sectionIndex)
                        {
                            SelectItem(this.highlightIndex);
                        }
                        Retract();
                    }
                }
            }
            else
            {
                if (this.items.Count < 2)
                {
                    return;                     // don't waste time showing a menu if there's no choice
                }

                if (IsCursorOver(this.smallBox, cursorPos, 4))
                {
                    this.expandedBox.Show();
                    this.smallBox.Hide();

                    // calculate how much vertical space we need
                    Real idealHeight = this.itemsShown * (this.smallBox.Height - 8) + 20;
                    this.expandedBox.Height = idealHeight;
                    this.scrollTrack.Height = this.expandedBox.Height - 20;

                    this.expandedBox.Left = this.smallBox.Left - 4;

                    // if the expanded menu goes down off the screen, make it go up instead
                    if (this.smallBox.DerivedTop * om.ViewportHeight + idealHeight > om.ViewportHeight)
                    {
                        this.expandedBox.Top = this.smallBox.Top + this.smallBox.Height - idealHeight + 3;
                        // if we're in thick style, hide the caption because it will interfere with the expanded menu
                        if (this.textArea.HorizontalAlignment == HorizontalAlignment.Center)
                        {
                            this.textArea.Hide();
                        }
                    }
                    else
                    {
                        this.expandedBox.Top = this.smallBox.Top + 3;
                    }

                    this.isExpanded     = true;
                    this.highlightIndex = this.sectionIndex;
                    DisplayIndex        = this.highlightIndex;

                    if (this.itemsShown < this.items.Count)                       // update scrollbar position
                    {
                        this.scrollHandle.Show();
                        Real lowerBoundary = this.scrollTrack.Height - this.scrollHandle.Height;
                        this.scrollHandle.Top = (int)(this.displayIndex * lowerBoundary / (this.items.Count - this.itemElements.Count));
                    }
                    else
                    {
                        this.scrollHandle.Hide();
                    }
                }
            }

            base.OnCursorPressed(cursorPos);
        }