//---------------------------------------------------------------------- protected internal override void DrawFocused() { if (IsDragging) { Debug.Assert(FocusedRow != null); int iRowY = GetRowY(Rows.IndexOf(FocusedRow)); int iColX = 0; for (int i = 0; i < FocusedRow.Cells.Length; i++) { ListViewColumn col = Columns[i]; FocusedRow.Cells[i].Draw(new Point(LayoutRect.X + 10 + iColX + mMouseDragPoint.X - mMouseDownPoint.X, LayoutRect.Y + mMouseDragPoint.Y - mMouseDownPoint.Y + (int)Scrollbar.LerpOffset + iRowY)); iColX += col.Width + ColSpacing; } } }
//---------------------------------------------------------------------- protected internal abstract void DoLayout( Rectangle _rect, ListViewColumn _col );
//---------------------------------------------------------------------- protected internal override void DoLayout( Rectangle _rect, ListViewColumn _col ) { mstrText = Text; mfTextWidth = mListView.Screen.Style.MediumFont.MeasureString( mstrText ).X + 20 + mListView.ColSpacing; if( mstrText != "" && mfTextWidth > _col.Width ) { int iOffset = mstrText.Length; while( mfTextWidth > _col.Width ) { iOffset--; mstrText = Text.Substring( 0, iOffset ) + "…"; if( iOffset == 0 ) break; mfTextWidth = mListView.Screen.Style.MediumFont.MeasureString( mstrText ).X + 20 + mListView.ColSpacing; } } mvTextOffset = Vector2.Zero; switch( _col.Anchor ) { case Anchor.Start: mvTextOffset.X += 10; break; case Anchor.Center: mvTextOffset.X += _col.Width / 2f - mfTextWidth / 2f; break; case Anchor.End: mvTextOffset.X += 10 + _col.Width - mfTextWidth; break; } miIndicatorAndActionButtonsWidth = 0; // Indicators foreach( ListViewCellIndicator indicator in Indicators ) { miIndicatorAndActionButtonsWidth += indicator.ContentWidth + 5; indicator.DoLayout( new Rectangle ( _rect.Right - miIndicatorAndActionButtonsWidth - 5, _rect.Top + 10, indicator.ContentWidth, mListView.RowHeight - 20 ) ); } }
//---------------------------------------------------------------------- protected internal override void DoLayout( Rectangle _rect, ListViewColumn _col ) { mvOffset = Vector2.Zero; switch( _col.Anchor ) { case Anchor.Start: mvOffset.X += 10; break; case Anchor.Center: mvOffset.X += _col.Width / 2f - Image.Width / 2f; break; case Anchor.End: mvOffset.X += _col.Width - Image.Width - 10; break; } }
//---------------------------------------------------------------------- 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; } }
//---------------------------------------------------------------------- protected internal abstract void DoLayout(Rectangle _rect, int _iColumnIndex, ListViewColumn _col, ListViewRow _row);
//---------------------------------------------------------------------- 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; } }
//---------------------------------------------------------------------- public override void Draw() { Screen.DrawBox(Style.ListViewFrame, LayoutRect, Style.ListViewFrameCornerSize, Color.White); if (DisplayColumnHeaders) { int iColX = 0; foreach (ListViewColumn col in Columns) { Screen.DrawBox(Style.ColumnHeaderFrame, new Rectangle(LayoutRect.X + Padding.Left + iColX, LayoutRect.Y + Padding.Top, col.Width, Style.RowHeight), Style.ColumnHeaderCornerSize, Color.White); if (col.Label != null) { col.Label.Draw(); } else { col.Image.Draw(); } iColX += col.Width + ColSpacing; } } Screen.PushScissorRectangle(new Rectangle(LayoutRect.X + Padding.Left, LayoutRect.Y + Padding.Top + (DisplayColumnHeaders ? Style.RowHeight : 0), LayoutRect.Width - Padding.Horizontal, LayoutRect.Height - Padding.Vertical - (DisplayColumnHeaders ? Style.RowHeight : 0))); int iRowIndex = 0; foreach (ListViewRow row in Rows) { int iRowY = GetRowY(iRowIndex); if ((iRowY + Style.RowHeight + Style.RowSpacing < 0) || (iRowY > LayoutRect.Height - Padding.Vertical)) { iRowIndex++; continue; } if (MergeColumns) { Rectangle rowRect = new Rectangle(LayoutRect.X + Padding.Left, LayoutRect.Y + Padding.Top + iRowY, LayoutRect.Width - Padding.Horizontal, Style.RowHeight); Screen.DrawBox(SelectedRow == row ? Style.SelectedCellFrame : Style.CellFrame, rowRect, Style.CellCornerSize, Color.White); if (HasFocus && FocusedRow == row) { if (SelectedRow != row) { Screen.DrawBox(Style.CellFocusOverlay, rowRect, Style.CellCornerSize, Color.White); } else if (Style.SelectedCellFocusOverlay != null) { Screen.DrawBox(Style.SelectedCellFocusOverlay, rowRect, Style.CellCornerSize, Color.White); } } if (HoveredRow == row && !IsDragging) { if (SelectedRow != row) { Screen.DrawBox(Style.CellHoverOverlay, rowRect, Style.CellCornerSize, Color.White); } else if (Style.SelectedCellHoverOverlay != null) { Screen.DrawBox(Style.SelectedCellHoverOverlay, rowRect, Style.CellCornerSize, Color.White); } } } int iColX = 0; for (int i = 0; i < row.Cells.Length; i++) { ListViewColumn col = Columns[i]; Rectangle rowRect = new Rectangle(LayoutRect.X + Padding.Left + iColX, LayoutRect.Y + Padding.Top + iRowY, col.Width, Style.RowHeight); if (!MergeColumns) { Screen.DrawBox(SelectedRow == row ? Style.SelectedCellFrame : Style.CellFrame, rowRect, Style.CellCornerSize, Color.White); if (HasFocus && FocusedRow == row) { if (SelectedRow != row) { Screen.DrawBox(Style.CellFocusOverlay, rowRect, Style.CellCornerSize, Color.White); } else if (Style.SelectedCellFocusOverlay != null) { Screen.DrawBox(Style.SelectedCellFocusOverlay, rowRect, Style.CellCornerSize, Color.White); } } if (HoveredRow == row && !IsDragging) { if (SelectedRow != row) { Screen.DrawBox(Style.CellHoverOverlay, rowRect, Style.CellCornerSize, Color.White); } else if (Style.SelectedCellHoverOverlay != null) { Screen.DrawBox(Style.SelectedCellHoverOverlay, rowRect, Style.CellCornerSize, Color.White); } } } row.Cells[i].Draw(new Point(LayoutRect.X + Padding.Left + iColX, LayoutRect.Y + Padding.Top + iRowY)); iColX += col.Width + ColSpacing; } iRowIndex++; } if (NewRowText != null) { int iRowY = GetRowY(iRowIndex); Screen.DrawBox(mbIsHoveringNewRow ? Style.NewRowHoveredFrame : Style.NewRowFrame, new Rectangle(LayoutRect.X + Padding.Left, LayoutRect.Y + Padding.Top + iRowY, LayoutRect.Width - Padding.Horizontal, Style.RowHeight), Style.NewRowFrameCornerSize, Color.White); Vector2 vTextPos = new Vector2(LayoutRect.X + Padding.Left + Style.NewRowHorizontalPadding, LayoutRect.Y + Padding.Top + iRowY + Style.RowHeight / 2f - (int)(Screen.Style.MediumFont.LineSpacing * 0.9f / 2f) + Screen.Style.MediumFont.YOffset); Screen.Game.SpriteBatch.DrawString(Screen.Style.MediumFont, NewRowText, vTextPos, mbIsHoveringNewRow ? Style.NewRowHoveredTextColor : Style.NewRowTextColor); iRowIndex++; } if (HoveredRow != null && !IsDragging) { foreach (Button button in ActionButtons) { button.Draw(); } } if (IsDragging && HitBox.Contains(mHoverPoint)) { int iX = LayoutRect.X + Padding.Left; int iWidth = LayoutRect.Width - Padding.Horizontal; if (HoveredRow != null) { int iY = LayoutRect.Y + Padding.Top + GetRowY(Rows.IndexOf(HoveredRow) + (mbInsertAfter ? 1 : 0)) - (Style.RowSpacing + Screen.Style.ListRowInsertMarker.Height) / 2; Rectangle markerRect = new Rectangle(iX, iY, iWidth, Screen.Style.ListRowInsertMarker.Height); Screen.DrawBox(Screen.Style.ListRowInsertMarker, markerRect, Screen.Style.ListRowInsertMarkerCornerSize, Color.White); } else if (IsHovered) { int iY = LayoutRect.Y + Padding.Top + (mbInsertAfter ? GetRowY(Rows.Count) : 0) - (Style.RowSpacing + Screen.Style.ListRowInsertMarker.Height) / 2; Rectangle markerRect = new Rectangle(iX, iY, iWidth, Screen.Style.ListRowInsertMarker.Height); Screen.DrawBox(Screen.Style.ListRowInsertMarker, markerRect, Screen.Style.ListRowInsertMarkerCornerSize, Color.White); } } Screen.PopScissorRectangle(); Scrollbar.Draw(); }