Axiom.Samples.Widget.CursorOffset C# (CSharp) Method

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
		public static Vector2 CursorOffset( OverlayElement element, Vector2 cursorPos )
		{
			OverlayManager om = OverlayManager.Instance;
			return new Vector2( cursorPos.x - ( element.DerivedLeft * om.ViewportWidth + element.Width / 2 ),
							   cursorPos.y - ( element.DerivedTop * om.ViewportHeight + element.Height / 2 ) );
		}

Usage Example

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);
        }
All Usage Examples Of Axiom.Samples.Widget::CursorOffset