public virtual void AddChild( Widget _widget, int _iIndex ) { Debug.Assert( _widget.Parent == null ); //Debug.Assert( _widget.Screen == Screen ); _widget.Parent = this; mlChildren.Insert( _iIndex, _widget ); UpdateContentSize(); }
//---------------------------------------------------------------------- public void AddChild( Widget _widget, int _iIndex, bool _bExpand ) { Debug.Assert( _widget.Parent == null ); Debug.Assert( _widget.Screen == Screen ); _widget.Parent = this; mlExpandedChildren.Insert( _iIndex, _bExpand ); mlChildren.Insert( _iIndex, _widget ); UpdateContentSize(); }
public void AddChildAt( Widget _child, int _iColumn, int _iRow ) { Debug.Assert( ! maWidgetLocations.ContainsKey( _child ) ); Debug.Assert( _child.Parent == null ); //Debug.Assert( _child.Screen == Screen ); wtf?? _child.Parent = this; maTiles[ _iColumn, _iRow ] = _child; maWidgetLocations[ _child ] = new Point( _iColumn, _iRow ); mlChildren.Add( _child ); }
public virtual void RemoveChild( Widget _widget ) { Debug.Assert( _widget.Parent == this ); _widget.Parent = null; mlChildren.Remove( _widget ); UpdateContentSize(); }
//---------------------------------------------------------------------- public override Widget GetSibling( Direction _direction, Widget _child ) { Widget nearestSibling = null; Widget focusableSibling = null; Widget fixedChild = (Widget)_child; foreach( Widget child in mlChildren ) { if( child == _child ) continue; switch( _direction ) { case Direction.Up: if( child.LayoutRect.Bottom <= fixedChild.LayoutRect.Center.Y && ( nearestSibling == null || child.LayoutRect.Bottom > nearestSibling.LayoutRect.Bottom ) ) { Widget childFocusableWidget = child.GetFirstFocusableDescendant( _direction ); if( childFocusableWidget != null ) { nearestSibling = child; focusableSibling = childFocusableWidget; } } break; case Direction.Down: if( child.LayoutRect.Top >= fixedChild.LayoutRect.Center.Y && ( nearestSibling == null || child.LayoutRect.Top < nearestSibling.LayoutRect.Top ) ) { Widget childFocusableWidget = child.GetFirstFocusableDescendant( _direction ); if( childFocusableWidget != null ) { nearestSibling = child; focusableSibling = childFocusableWidget; } } break; case Direction.Left: if( child.LayoutRect.Right <= fixedChild.LayoutRect.Center.X && ( nearestSibling == null || child.LayoutRect.Right > nearestSibling.LayoutRect.Right ) ) { Widget childFocusableWidget = child.GetFirstFocusableDescendant( _direction ); if( childFocusableWidget != null ) { nearestSibling = child; focusableSibling = childFocusableWidget; } } break; case Direction.Right: if( child.LayoutRect.Left >= fixedChild.LayoutRect.Center.X && ( nearestSibling == null || child.LayoutRect.Left < nearestSibling.LayoutRect.Left ) ) { Widget childFocusableWidget = child.GetFirstFocusableDescendant( _direction ); if( childFocusableWidget != null ) { nearestSibling = child; focusableSibling = childFocusableWidget; } } break; } } if( focusableSibling == null ) { return base.GetSibling( _direction, this ); } return focusableSibling; }
//---------------------------------------------------------------------- public override Widget GetSibling( Direction _direction, Widget _child ) { int iIndex = mlButtons.IndexOf( (Button)_child ); switch( _direction ) { case Direction.Left: if( iIndex > 0 ) { return mlButtons[iIndex - 1]; } break; case Direction.Right: if( iIndex < mlButtons.Count - 1 ) { return mlButtons[iIndex + 1]; } break; } return base.GetSibling( _direction, this ); }
public virtual Widget GetSibling( UI.Direction _direction, Widget _child ) { if( Parent != null ) { return Parent.GetSibling( _direction, this ); } return null; }
public override void AddChild( Widget _widget, int _iIndex ) { throw new NotSupportedException(); }
public override Widget GetSibling( Direction _direction, Widget _child ) { Widget tileChild = null; Point childLocation = maWidgetLocations[ _child ]; int iOffset = 0; do { iOffset++; switch( _direction ) { case Direction.Left: if( childLocation.X - iOffset < 0 ) return base.GetSibling( _direction, _child ); tileChild = maTiles[ childLocation.X - iOffset, childLocation.Y ]; break; case Direction.Right: if( childLocation.X + iOffset >= maTiles.GetLength(0) ) return base.GetSibling( _direction, _child ); tileChild = maTiles[ childLocation.X + iOffset, childLocation.Y ]; break; case Direction.Up: if( childLocation.Y - iOffset < 0 ) return base.GetSibling( _direction, _child ); tileChild = maTiles[ childLocation.X, childLocation.Y - iOffset ]; break; case Direction.Down: if( childLocation.Y + iOffset >= maTiles.GetLength(1) ) return base.GetSibling( _direction, _child ); tileChild = maTiles[ childLocation.X, childLocation.Y + iOffset ]; break; } } while( tileChild == null ); if( tileChild != null ) { return tileChild; } else { return base.GetSibling( _direction, this ); } }
//---------------------------------------------------------------------- public void HandleInput() { //------------------------------------------------------------------ // Make sure we don't hold references to orphaned widgets if( FocusedWidget != null && FocusedWidget.IsOrphan ) FocusedWidget = null; if( HoveredWidget != null && HoveredWidget.IsOrphan ) { #if !MONOGAME Game.Form.Cursor = System.Windows.Forms.Cursors.Default; #endif HoveredWidget = null; } if( mClickedWidget != null && mClickedWidget.IsOrphan ) mClickedWidget = null; //------------------------------------------------------------------ Point mouseHitPoint = new Point( (int)( Game.InputMgr.MouseState.X / Resolution.ScaleFactor ), (int)( ( Game.InputMgr.MouseState.Y - Game.GraphicsDevice.Viewport.Y ) / Resolution.ScaleFactor ) ); if( ! IsActive ) { if( HoveredWidget != null ) { HoveredWidget.OnMouseOut( mouseHitPoint ); HoveredWidget = null; } if( mClickedWidget != null ) { mClickedWidget.OnMouseUp( mouseHitPoint, miClickedWidgetMouseButton ); mClickedWidget = null; } return; } foreach( Buttons button in Enum.GetValues(typeof(Buttons)) ) { PlayerIndex playerIndex; bool bPressed; if( Game.InputMgr.WasButtonJustPressed( button, Game.PlayerInCharge, out playerIndex, true ) ) { bPressed = true; } else if( Game.InputMgr.WasButtonJustReleased( button, Game.PlayerInCharge, out playerIndex ) ) { bPressed = false; } else { continue; } switch( button ) { case Buttons.A: if( FocusedWidget != null ) { if( bPressed ) { FocusedWidget.OnActivateDown(); mbHasActivatedFocusedWidget = true; } else if( mbHasActivatedFocusedWidget ) { FocusedWidget.OnActivateUp(); mbHasActivatedFocusedWidget = false; } } break; case Buttons.B: if( FocusedWidget == null || ! FocusedWidget.OnCancel( bPressed ) ) { Root.OnPadButton( button, bPressed ); } break; case Buttons.LeftThumbstickLeft: case Buttons.DPadLeft: if( bPressed && FocusedWidget != null ) FocusedWidget.OnPadMove( UI.Direction.Left ); break; case Buttons.LeftThumbstickRight: case Buttons.DPadRight: if( bPressed && FocusedWidget != null ) FocusedWidget.OnPadMove( UI.Direction.Right ); break; case Buttons.LeftThumbstickUp: case Buttons.DPadUp: if( bPressed && FocusedWidget != null ) FocusedWidget.OnPadMove( UI.Direction.Up ); break; case Buttons.LeftThumbstickDown: case Buttons.DPadDown: if( bPressed && FocusedWidget != null ) FocusedWidget.OnPadMove( UI.Direction.Down ); break; default: Root.OnPadButton( button, bPressed ); break; } } #if WINDOWS || LINUX || MACOSX //------------------------------------------------------------------ // Mouse buttons bool bHasMouseEvent = false; if( miIgnoreClickFrames == 0 ) { for( int iButton = 0; iButton < 3; iButton++ ) { if( Game.InputMgr.WasMouseButtonJustPressed( iButton ) ) { bHasMouseEvent = true; if( mClickedWidget == null ) { miClickedWidgetMouseButton = iButton; Widget hitWidget = null; if( FocusedWidget != null ) { hitWidget = FocusedWidget.HitTest( mouseHitPoint ); } if( hitWidget == null ) { hitWidget = Root.HitTest( mouseHitPoint ); } while( hitWidget != null && ! hitWidget.OnMouseDown( mouseHitPoint, iButton ) ) { hitWidget = hitWidget.Parent; } mClickedWidget = hitWidget; } } } if( Game.InputMgr.WasMouseJustDoubleClicked() ) { bHasMouseEvent = true; Widget widget = FocusedWidget == null ? null : FocusedWidget.HitTest( mouseHitPoint ); if( widget != null ) { bool bPressed; switch( Game.InputMgr.PrimaryMouseButton ) { case 0: bPressed = Game.InputMgr.MouseState.LeftButton == ButtonState.Pressed; break; case 2: bPressed = Game.InputMgr.MouseState.RightButton == ButtonState.Pressed; break; default: throw new NotSupportedException(); } if( bPressed ) { mClickedWidget = widget; miClickedWidgetMouseButton = Game.InputMgr.PrimaryMouseButton; } if( widget.OnMouseDoubleClick( mouseHitPoint ) ) { miIgnoreClickFrames = 3; } } } } else { miIgnoreClickFrames--; } for( int iButton = 0; iButton < 3; iButton++ ) { if( Game.InputMgr.WasMouseButtonJustReleased( iButton ) ) { bHasMouseEvent = true; if( mClickedWidget != null && iButton == miClickedWidgetMouseButton ) { mClickedWidget.OnMouseUp( mouseHitPoint, iButton ); mClickedWidget = null; } } } if( ! bHasMouseEvent ) { Widget hoveredWidget = ( FocusedWidget == null ? null : FocusedWidget.HitTest( mouseHitPoint ) ) ?? Root.HitTest( mouseHitPoint ); if( mouseHitPoint != mPreviousMouseHitPoint ) { if( mClickedWidget == null ) { if( hoveredWidget != null && hoveredWidget == HoveredWidget ) { HoveredWidget.OnMouseMove( mouseHitPoint ); } else { if( HoveredWidget != null ) { HoveredWidget.OnMouseOut( mouseHitPoint ); } HoveredWidget = hoveredWidget; if( HoveredWidget != null ) { HoveredWidget.OnMouseEnter( mouseHitPoint ); } } } else { mClickedWidget.OnMouseMove( mouseHitPoint ); } } } // Mouse wheel int iWheelDelta = Game.InputMgr.GetMouseWheelDelta(); if( iWheelDelta != 0 ) { Widget hoveredWidget = ( FocusedWidget == null ? null : FocusedWidget.HitTest( mouseHitPoint ) ) ?? Root.HitTest( mouseHitPoint ); if( hoveredWidget != null ) { hoveredWidget.OnMouseWheel( mouseHitPoint, iWheelDelta ); } } mPreviousMouseHitPoint = mouseHitPoint; //------------------------------------------------------------------ // Keyboard if( FocusedWidget != null ) { foreach( char character in Game.InputMgr.EnteredText ) { FocusedWidget.OnTextEntered( character ); } foreach( Keys key in Game.InputMgr.JustPressedKeys ) { FocusedWidget.OnKeyPress( key ); } foreach( var key in Game.InputMgr.JustPressedOSKeys ) { FocusedWidget.OnOSKeyPress( key ); } } #endif }
//---------------------------------------------------------------------- public void Focus( Widget _widget ) { Debug.Assert( _widget.Screen == this ); mbHasActivatedFocusedWidget = false; if( FocusedWidget != null && FocusedWidget != _widget ) { FocusedWidget.OnBlur(); } if( FocusedWidget != _widget ) { FocusedWidget = _widget; FocusedWidget.OnFocus(); } }
//---------------------------------------------------------------------- public override Widget GetSibling( Direction _direction, Widget _child ) { int iIndex = mlChildren.IndexOf( _child ); if( mOrientation == Orientation.Horizontal ) { if( _direction == Direction.Right ) { if( iIndex < mlChildren.Count - 1 ) { return mlChildren[iIndex + 1]; } } else if( _direction == Direction.Left ) { if( iIndex > 0 ) { return mlChildren[iIndex - 1]; } } } else { if( _direction == Direction.Down ) { if( iIndex < mlChildren.Count - 1 ) { return mlChildren[iIndex + 1]; } } else if( _direction == Direction.Up ) { if( iIndex > 0 ) { return mlChildren[iIndex - 1]; } } } return base.GetSibling( _direction, this ); }
public void AddChild( Widget _widget, bool _bExpand ) { AddChild( _widget, mlChildren.Count, _bExpand ); }
public override void AddChild( Widget _widget, int _iIndex ) { AddChild( _widget, _iIndex, false ); }
public void AddChild( Widget _widget ) { AddChild( _widget, mlChildren.Count ); }
public override void RemoveChild( Widget _widget ) { Debug.Assert( _widget.Parent == this ); _widget.Parent = null; Point widgetLocation = maWidgetLocations[ _widget ]; maWidgetLocations.Remove( _widget ); maTiles[ widgetLocation.X, widgetLocation.Y ] = null; mlChildren.Remove( _widget ); }
public override void RemoveChild( Widget _widget ) { Debug.Assert( _widget.Parent == this ); _widget.Parent = null; mlExpandedChildren.RemoveAt( mlChildren.IndexOf( _widget ) ); mlChildren.Remove( _widget ); UpdateContentSize(); }