예제 #1
0
        //----------------------------------------------------------------------
        protected internal override bool OnMouseDown(Point _hitPoint, int _iButton)
        {
            if (_iButton != Screen.Game.InputMgr.PrimaryMouseButton)
            {
                return(false);
            }

            mHoverPoint = _hitPoint;

            if (mHoveredActionButton != null)
            {
                mHoveredActionButton.OnActivateDown();
                mbIsHoveredActionButtonDown = true;
            }
            else
            {
                mbIsMouseDown   = true;
                mMouseDownPoint = new Point(_hitPoint.X, _hitPoint.Y + (int)Scrollbar.LerpOffset);

                Screen.Focus(this);

                int iFocusedRowIndex = Math.Max(0, (_hitPoint.Y - (LayoutRect.Y + Padding.Top + (DisplayColumnHeaders ? Style.RowHeight : 0)) + (int)Scrollbar.LerpOffset) / (Style.RowHeight + Style.RowSpacing));

                if (iFocusedRowIndex > Rows.Count - 1)
                {
                    iFocusedRowIndex = -1;
                }

                FocusedRow = (iFocusedRowIndex != -1) ? Rows[iFocusedRowIndex] : null;
            }

            return(true);
        }
예제 #2
0
        //----------------------------------------------------------------------
        protected internal override void OnFocus()
        {
            base.OnFocus();

            if (FocusedRow == null)
            {
                FocusedRow = SelectedRow;
            }
        }
예제 #3
0
        protected internal override void OnMouseUp(Point _hitPoint, int _iButton)
        {
            if (_iButton != Screen.Game.InputMgr.PrimaryMouseButton)
            {
                return;
            }

            mbIsMouseDown = false;

            mHoverPoint = _hitPoint;

            if (mHoveredActionButton != null)
            {
                if (mbIsHoveredActionButtonDown)
                {
                    mHoveredActionButton.OnMouseUp(_hitPoint, _iButton);
                    mbIsHoveredActionButtonDown = false;
                }
            }
            else
            if (IsDragging)
            {
                Debug.Assert(FocusedRow != null);
                ListViewRow draggedRow = FocusedRow;

                if (HitBox.Contains(_hitPoint) && HoveredRow != draggedRow && DragNDropHandler != null)
                {
                    int iIndex = ((HoveredRow != null) ? Rows.IndexOf(HoveredRow) : (Rows.Count - 1)) + (mbInsertAfter ? 1 : 0);

                    if (iIndex > Rows.IndexOf(draggedRow))
                    {
                        iIndex--;
                    }

                    if (DragNDropHandler(draggedRow, iIndex))
                    {
                        Rows.Remove(draggedRow);
                        Rows.Insert(iIndex, draggedRow);
                    }
                }
            }
            else
            if (mbIsHoveringNewRow)
            {
                if (NewRowClickedHandler != null)
                {
                    NewRowClickedHandler(this);
                }
            }
            else
            {
                SelectRowAt(_hitPoint);
            }

            IsDragging = false;
        }
예제 #4
0
        //----------------------------------------------------------------------
        public ListView( Screen _screen )
            : base(_screen)
        {
            Columns = new List<ListViewColumn>();

            Rows    = new ObservableList<ListViewRow>();

            Rows.ListCleared += delegate {
                SelectedRow         = null;
                HoveredRow          = null;
                FocusedRow          = null;

                mHoveredActionButton = null;
                mbIsHoveredActionButtonDown = false;
            };

            Rows.ListChanged += delegate( object _source, ObservableList<ListViewRow>.ListChangedEventArgs _args )
            {
                if( ! _args.Added )
                {
                    if( _args.Item == SelectedRow )
                    {
                        SelectedRow = null;
                    }

                    if( _args.Item == HoveredRow )
                    {
                        UpdateHoveredRow();
                    }

                    if( _args.Item == FocusedRow )
                    {
                        FocusedRow = null;
                        IsDragging = false;
                    }
                }
            };

            SelectedRow     = null;
            FocusedRow      = null;
            HoveredRow      = null;
            TextColor = Screen.Style.DefaultTextColor;

            Style.ListFrame             = Screen.Style.ListFrame;
            Style.FrameSelected         = Screen.Style.GridBoxFrameSelected;
            Style.FrameSelectedHover    = Screen.Style.GridBoxFrameSelectedHover;
            Style.FrameSelectedFocus    = Screen.Style.GridBoxFrameSelectedFocus;

            Scrollbar = new Scrollbar( _screen );
            Scrollbar.Parent = this;

            ActionButtons = new List<Button>();

            UpdateContentSize();
        }
예제 #5
0
        //----------------------------------------------------------------------
        void SelectRowAt(Point _hitPoint)
        {
            UpdateHoveredRow();

            if (HoveredRow != SelectedRow)
            {
                if (HoveredRow != null || SelectFocusedRow)
                {
                    FocusedRow = SelectedRow = HoveredRow;
                    if (SelectHandler != null)
                    {
                        SelectHandler(this);
                    }
                }
            }
        }
예제 #6
0
 protected internal override void OnActivateUp()
 {
     if (FocusedRow != SelectedRow && FocusedRow != null)
     {
         SelectedRow = FocusedRow;
         if (SelectHandler != null)
         {
             SelectHandler(this);
         }
     }
     else
     {
         if (ValidateHandler != null)
         {
             ValidateHandler(this);
         }
     }
 }
예제 #7
0
        //----------------------------------------------------------------------
        protected internal override void OnPadMove(Direction _direction)
        {
            if (_direction == Direction.Up)
            {
                if (FocusedRow != null && !IsDragging)
                {
                    int iFocusedRowIndex = Math.Max(0, Rows.IndexOf(FocusedRow) - 1);
                    FocusedRow = Rows[iFocusedRowIndex];

                    if (SelectFocusedRow)
                    {
                        SelectedRow = FocusedRow;
                    }
                }

                if (SelectHandler != null)
                {
                    SelectHandler(this);
                }
            }
            else
            if (_direction == Direction.Down)
            {
                if (FocusedRow != null && !IsDragging)
                {
                    int iFocusedRowIndex = Math.Min(Rows.Count - 1, Rows.IndexOf(FocusedRow) + 1);
                    FocusedRow = Rows[iFocusedRowIndex];

                    if (SelectFocusedRow)
                    {
                        SelectedRow = FocusedRow;
                    }
                }

                if (SelectHandler != null)
                {
                    SelectHandler(this);
                }
            }
            else
            {
                base.OnPadMove(_direction);
            }
        }
예제 #8
0
        //----------------------------------------------------------------------
        public override void OnMouseOut(Point _hitPoint)
        {
            HoveredRow = null;

            if (mbIsHoveringNewRow)
            {
                Screen.Game.SetCursor(MouseCursor.Default);
                mbIsHoveringNewRow = false;
            }

            if (mHoveredActionButton != null)
            {
                if (mbIsHoveredActionButtonDown)
                {
                    mHoveredActionButton.ResetPressState();
                    mbIsHoveredActionButtonDown = false;
                }
                mHoveredActionButton = null;
            }
        }
예제 #9
0
        //----------------------------------------------------------------------
        protected internal override void OnPadMove( Direction _direction )
        {
            if( _direction == Direction.Up )
            {
                if( FocusedRow != null && ! IsDragging )
                {
                    int iFocusedRowIndex = Math.Max( 0, Rows.IndexOf( FocusedRow ) - 1 );
                    FocusedRow = Rows[ iFocusedRowIndex ];

                    if( SelectFocusedRow )
                    {
                        SelectedRow = FocusedRow;
                    }
                }
            }
            else
            if( _direction == Direction.Down )
            {
                if( FocusedRow != null && ! IsDragging )
                {
                    int iFocusedRowIndex = Math.Min( Rows.Count - 1, Rows.IndexOf( FocusedRow ) + 1 );
                    FocusedRow = Rows[ iFocusedRowIndex ];

                    if( SelectFocusedRow )
                    {
                        SelectedRow = FocusedRow;
                    }
                }
            }
            else
            {
                base.OnPadMove( _direction );
            }

            if( SelectHandler != null ) SelectHandler( this );
        }
예제 #10
0
        //----------------------------------------------------------------------
        protected internal override bool OnMouseDown( Point _hitPoint, int _iButton )
        {
            if( _iButton != Screen.Game.InputMgr.PrimaryMouseButton ) return false;

            mHoverPoint = _hitPoint;

            if( mHoveredActionButton != null )
            {
                mHoveredActionButton.OnActivateDown();
                mbIsHoveredActionButtonDown = true;
            }
            else
            {
                mbIsMouseDown = true;
                mMouseDownPoint = new Point( _hitPoint.X, _hitPoint.Y + (int)Scrollbar.LerpOffset );

                Screen.Focus( this );

                int iFocusedRowIndex = Math.Max( 0, ( _hitPoint.Y - ( LayoutRect.Y + 10 + ( DisplayColumnHeaders ? RowHeight : 0 ) ) + (int)Scrollbar.LerpOffset ) / ( RowHeight + RowSpacing ) );

                if( iFocusedRowIndex > Rows.Count - 1 )
                {
                    iFocusedRowIndex = -1;
                }

                FocusedRow = (iFocusedRowIndex != -1) ? Rows[ iFocusedRowIndex ] : null;
            }

            return true;
        }
예제 #11
0
        //----------------------------------------------------------------------
        protected internal override void OnFocus()
        {
            base.OnFocus();

            if( FocusedRow == null )
            {
                FocusedRow = SelectedRow;
            }
        }
예제 #12
0
 //----------------------------------------------------------------------
 protected internal override void OnBlur()
 {
     FocusedRow = null;
 }
예제 #13
0
 protected internal override void OnActivateUp()
 {
     if( FocusedRow != SelectedRow && FocusedRow != null )
     {
         SelectedRow = FocusedRow;
         if( SelectHandler != null ) SelectHandler( this );
     }
     else
     {
         if( ValidateHandler != null ) ValidateHandler( this );
     }
 }
예제 #14
0
        //----------------------------------------------------------------------
        public override void OnMouseOut( Point _hitPoint )
        {
            HoveredRow = null;

            if( mHoveredActionButton != null )
            {
                if( mbIsHoveredActionButtonDown )
                {
                    mHoveredActionButton.ResetPressState();
                    mbIsHoveredActionButtonDown = false;
                }
                mHoveredActionButton = null;
            }
        }
예제 #15
0
        //----------------------------------------------------------------------
        protected internal override void DoLayout(Rectangle _rect, int _iColumnIndex, ListViewColumn _col, ListViewRow _row)
        {
            int iIndicatorRight = _rect.Right;

            if (mListView.ActionButtonsColumn == _iColumnIndex && mListView.HoveredRow == _row && mListView.ActionButtons.Count > 0)
            {
                iIndicatorRight -= mListView.ActionButtons.Sum(x => x.ContentWidth + mListView.Style.CellHorizontalPadding) + mListView.Style.ActionButtonsRightPadding;
            }

            miIndicatorsWidth = 0;

            // Indicators
            foreach (ListViewCellIndicator indicator in Indicators)
            {
                miIndicatorsWidth += indicator.ContentWidth;
                indicator.DoLayout(new Rectangle(iIndicatorRight - miIndicatorsWidth - mListView.Style.CellHorizontalPadding - mListView.Style.ActionButtonsRightPadding, _rect.Top + mListView.Style.IndicatorVerticalPadding, indicator.ContentWidth, mListView.Style.RowHeight - mListView.Style.IndicatorVerticalPadding * 2));
                miIndicatorsWidth += mListView.Style.IndicatorHorizontalSpacing;
            }

            mstrText    = Text;
            mfTextWidth = mListView.Screen.Style.MediumFont.MeasureString(mstrText).X;
            if (mstrText != "")
            {
                int iOffset = mstrText.Length;

                while (mfTextWidth + mListView.Style.CellHorizontalPadding * 2 > _col.Width - miIndicatorsWidth)
                {
                    iOffset--;
                    mstrText = Text.Substring(0, iOffset) + "…";
                    if (iOffset == 0)
                    {
                        break;
                    }

                    mfTextWidth = mListView.Screen.Style.MediumFont.MeasureString(mstrText).X;
                }
            }

            mvTextOffset = Vector2.Zero;
            switch (_col.Anchor)
            {
            case Anchor.Start:
                mvTextOffset.X += mListView.Style.CellHorizontalPadding;
                break;

            case Anchor.Center:
                mvTextOffset.X += (int)(_col.Width / 2f - mfTextWidth / 2f);
                break;

            case Anchor.End:
                mvTextOffset.X += _col.Width - mListView.Style.CellHorizontalPadding - mfTextWidth;
                break;
            }
        }
예제 #16
0
        //----------------------------------------------------------------------
        protected internal override void DoLayout(Rectangle _rect, int _iColumnIndex, ListViewColumn _col, ListViewRow _row)
        {
            mvOffset = Vector2.Zero;

            mvSize = new Vector2(Image.Width, Image.Height);
            if (ForcedHeight > 0)
            {
                mvSize.X *= ForcedHeight / mvSize.Y;
                mvSize.Y  = ForcedHeight;
            }

            switch (_col.Anchor)
            {
            case Anchor.Start:
                mvOffset.X += 10;
                break;

            case Anchor.Center:
                mvOffset.X += (int)(_col.Width / 2f - mvSize.X / 2f);
                break;

            case Anchor.End:
                mvOffset.X += (int)(_col.Width - mvSize.X - 10);
                break;
            }
        }
예제 #17
0
        //----------------------------------------------------------------------
        void SelectRowAt( Point _hitPoint )
        {
            UpdateHoveredRow();

            if( HoveredRow != SelectedRow )
            {
                if( HoveredRow != null || SelectFocusedRow )
                {
                    FocusedRow = SelectedRow = HoveredRow;
                    if( SelectHandler != null ) SelectHandler( this );
                }
            }
        }
예제 #18
0
        //----------------------------------------------------------------------
        public ListView(Screen _screen)
            : base(_screen)
        {
            Columns = new List <ListViewColumn>();

            Rows = new ObservableList <ListViewRow>();

            Rows.ListCleared += delegate {
                SelectedRow = null;
                HoveredRow  = null;
                FocusedRow  = null;

                mHoveredActionButton        = null;
                mbIsHoveredActionButtonDown = false;
            };

            Rows.ListChanged += delegate(object _source, ObservableList <ListViewRow> .ListChangedEventArgs _args)
            {
                if (!_args.Added)
                {
                    if (_args.Item == SelectedRow)
                    {
                        SelectedRow = null;
                    }

                    if (_args.Item == HoveredRow)
                    {
                        UpdateHoveredRow();
                    }

                    if (_args.Item == FocusedRow)
                    {
                        FocusedRow = null;
                        IsDragging = false;
                    }
                }
            };

            SelectedRow = null;
            FocusedRow  = null;
            HoveredRow  = null;
            TextColor   = Screen.Style.DefaultTextColor;

            Padding = Screen.Style.ListViewPadding;
            Style   = Screen.Style.ListViewStyle;

            Scrollbar        = new Scrollbar(_screen);
            Scrollbar.Parent = this;

            ActionButtons = new ObservableList <Button>();

            ActionButtons.ListCleared += delegate {
                mHoveredActionButton = null;
            };

            ActionButtons.ListChanged += delegate {
                if (mHoveredActionButton != null && !ActionButtons.Contains(mHoveredActionButton))
                {
                    mHoveredActionButton = null;
                }
            };

            UpdateContentSize();
        }
예제 #19
0
        void UpdateHoveredRow()
        {
            int iRowY            = (mHoverPoint.Y - (LayoutRect.Y + Padding.Top + (DisplayColumnHeaders ? Style.RowHeight : 0) - (int)Scrollbar.LerpOffset));
            int iHoveredRowIndex = Math.Max(-1, iRowY / (Style.RowHeight + Style.RowSpacing));

            var oldHoveredRow = HoveredRow;

            HoveredRow = null;

            bool bWasHoveringNewRow = mbIsHoveringNewRow;

            mbIsHoveringNewRow = false;

            int iOffset = iRowY % (Style.RowHeight + Style.RowSpacing);

            mbInsertAfter = iOffset >= (Style.RowHeight + Style.RowSpacing) / 2;

            if (iHoveredRowIndex >= Rows.Count)
            {
                mbInsertAfter = true;

                if (mbIsHoveredActionButtonDown)
                {
                    mHoveredActionButton.ResetPressState();
                    mbIsHoveredActionButtonDown = false;
                }
                mHoveredActionButton = null;

                if (iHoveredRowIndex == Rows.Count && NewRowText != null)
                {
                    mbIsHoveringNewRow = true;
                }
            }
            else
            if (iHoveredRowIndex >= 0)
            {
                HoveredRow = Rows[iHoveredRowIndex];

                if (HoverHandler != null && oldHoveredRow != HoveredRow)
                {
                    HoverHandler(this);
                }

                if (mHoveredActionButton != null)
                {
                    if (mHoveredActionButton.HitTest(mHoverPoint) != null)
                    {
                        mHoveredActionButton.OnMouseMove(mHoverPoint);
                    }
                    else
                    {
                        mHoveredActionButton.OnMouseOut(mHoverPoint);

                        if (mbIsHoveredActionButtonDown)
                        {
                            mHoveredActionButton.ResetPressState();
                            mbIsHoveredActionButtonDown = false;
                        }

                        mHoveredActionButton = null;
                    }
                }

                if (mHoveredActionButton == null)
                {
                    mbIsHoveredActionButtonDown = false;

                    foreach (Button button in ActionButtons)
                    {
                        if (button.HitTest(mHoverPoint) != null)
                        {
                            mHoveredActionButton = button;
                            mHoveredActionButton.OnMouseEnter(mHoverPoint);
                            break;
                        }
                    }
                }
            }

            if (bWasHoveringNewRow && !mbIsHoveringNewRow)
            {
                Screen.Game.SetCursor(MouseCursor.Default);
            }
            else
            if (!bWasHoveringNewRow && mbIsHoveringNewRow)
            {
                Screen.Game.SetCursor(MouseCursor.Hand);
            }
        }
예제 #20
0
 //----------------------------------------------------------------------
 protected internal abstract void DoLayout(Rectangle _rect, int _iColumnIndex, ListViewColumn _col, ListViewRow _row);
예제 #21
0
        void UpdateHoveredRow()
        {
            int iRowY = ( mHoverPoint.Y - ( LayoutRect.Y + 10 + ( DisplayColumnHeaders ? RowHeight : 0 ) - (int)Scrollbar.LerpOffset ) );
            int iHoveredRowIndex = Math.Max( -1, iRowY / ( RowHeight + RowSpacing ) );

            HoveredRow = null;

            int iOffset = iRowY % ( RowHeight + RowSpacing );
            mbInsertAfter = iOffset >= ( RowHeight + RowSpacing ) / 2;

            if( iHoveredRowIndex >= Rows.Count )
            {
                mbInsertAfter = true;

                if( mbIsHoveredActionButtonDown )
                {
                    mHoveredActionButton.ResetPressState();
                    mbIsHoveredActionButtonDown = false;
                }
                mHoveredActionButton = null;
            }
            else
            if( iHoveredRowIndex >= 0 )
            {
                HoveredRow = Rows[ iHoveredRowIndex ];
                if( mHoveredActionButton != null )
                {
                    if( mHoveredActionButton.HitTest( mHoverPoint ) != null )
                    {
                        mHoveredActionButton.OnMouseMove( mHoverPoint );
                    }
                    else
                    {
                        mHoveredActionButton.OnMouseOut( mHoverPoint );

                        if( mbIsHoveredActionButtonDown )
                        {
                            mHoveredActionButton.ResetPressState();
                            mbIsHoveredActionButtonDown = false;
                        }

                        mHoveredActionButton = null;
                    }
                }

                if( mHoveredActionButton == null )
                {
                    mbIsHoveredActionButtonDown = false;

                    foreach( Button button in ActionButtons )
                    {
                        if( button.HitTest( mHoverPoint ) != null )
                        {
                            mHoveredActionButton = button;
                            mHoveredActionButton.OnMouseEnter( mHoverPoint );
                            break;
                        }
                    }
                }
            }
        }
예제 #22
0
 //----------------------------------------------------------------------
 protected internal override void OnBlur()
 {
     FocusedRow = null;
 }