2015-09-02 22:46:23 +00:00
using System ;
using System.Collections.Generic ;
using System.Drawing ;
using System.Linq ;
using System.Windows.Forms ;
namespace BizHawk.Client.EmuHawk
{
public partial class InputRoll
{
protected override void OnPaint ( PaintEventArgs e )
{
using ( var LCK = Gdi . LockGraphics ( e . Graphics ) )
{
Gdi . StartOffScreenBitmap ( Width , Height ) ;
2015-09-05 18:00:08 +00:00
// White Background
2015-09-02 22:46:23 +00:00
Gdi . SetBrush ( Color . White ) ;
Gdi . SetSolidPen ( Color . White ) ;
Gdi . FillRectangle ( 0 , 0 , Width , Height ) ;
// Lag frame calculations
SetLagFramesArray ( ) ;
2015-09-05 18:00:08 +00:00
var visibleColumns = _columns . VisibleColumns . ToList ( ) ;
if ( visibleColumns . Any ( ) )
2015-09-02 22:46:23 +00:00
{
2015-09-05 18:00:08 +00:00
DrawColumnBg ( e , visibleColumns ) ;
DrawColumnText ( e , visibleColumns ) ;
2015-09-02 22:46:23 +00:00
}
//Background
2015-09-05 18:00:08 +00:00
DrawBg ( e , visibleColumns ) ;
2015-09-02 22:46:23 +00:00
//Foreground
2015-09-05 18:00:08 +00:00
DrawData ( e , visibleColumns ) ;
2015-09-02 22:46:23 +00:00
DrawColumnDrag ( e ) ;
DrawCellDrag ( e ) ;
Gdi . CopyToScreen ( ) ;
Gdi . EndOffScreenBitmap ( ) ;
}
}
protected override void OnPaintBackground ( PaintEventArgs pevent )
{
// Do nothing, and this should never be called
}
private void DrawColumnDrag ( PaintEventArgs e )
{
if ( _columnDown ! = null & & _currentX . HasValue & & _currentY . HasValue & & IsHoveringOnColumnCell )
{
int x1 = _currentX . Value - ( _columnDown . Width . Value / 2 ) ;
int y1 = _currentY . Value - ( CellHeight / 2 ) ;
int x2 = x1 + _columnDown . Width . Value ;
int y2 = y1 + CellHeight ;
2015-09-05 18:33:34 +00:00
Gdi . SetSolidPen ( _backColor ) ;
2015-09-02 22:46:23 +00:00
Gdi . DrawRectangle ( x1 , y1 , x2 , y2 ) ;
2015-09-05 18:33:34 +00:00
Gdi . PrepDrawString ( NormalFont , _foreColor ) ;
2015-09-02 22:46:23 +00:00
Gdi . DrawString ( _columnDown . Text , new Point ( x1 + CellWidthPadding , y1 + CellHeightPadding ) ) ;
}
}
private void DrawCellDrag ( PaintEventArgs e )
{
if ( DraggingCell ! = null )
{
var text = "" ;
int offsetX = 0 ;
int offsetY = 0 ;
if ( QueryItemText ! = null )
{
QueryItemText ( DraggingCell . RowIndex . Value , DraggingCell . Column , out text , ref offsetX , ref offsetY ) ;
}
2015-09-05 18:33:34 +00:00
Color bgColor = _backColor ;
2015-09-02 22:46:23 +00:00
if ( QueryItemBkColor ! = null )
{
QueryItemBkColor ( DraggingCell . RowIndex . Value , DraggingCell . Column , ref bgColor ) ;
}
int x1 = _currentX . Value - ( DraggingCell . Column . Width . Value / 2 ) ;
int y1 = _currentY . Value - ( CellHeight / 2 ) ;
int x2 = x1 + DraggingCell . Column . Width . Value ;
int y2 = y1 + CellHeight ;
Gdi . SetBrush ( bgColor ) ;
Gdi . FillRectangle ( x1 , y1 , x2 - x1 , y2 - y1 ) ;
2015-09-05 18:33:34 +00:00
Gdi . PrepDrawString ( NormalFont , _foreColor ) ;
2015-09-02 22:46:23 +00:00
Gdi . DrawString ( text , new Point ( x1 + CellWidthPadding + offsetX , y1 + CellHeightPadding + offsetY ) ) ;
}
}
2015-09-05 18:00:08 +00:00
private void DrawColumnText ( PaintEventArgs e , List < RollColumn > visibleColumns )
2015-09-02 22:46:23 +00:00
{
if ( HorizontalOrientation )
{
int start = - VBar . Value ;
2016-04-17 08:07:07 +00:00
Gdi . PrepDrawString ( NormalFont , _foreColor ) ;
2015-09-02 22:46:23 +00:00
2015-09-05 18:00:08 +00:00
foreach ( var column in visibleColumns )
2015-09-02 22:46:23 +00:00
{
var point = new Point ( CellWidthPadding , start + CellHeightPadding ) ;
if ( IsHoveringOnColumnCell & & column = = CurrentCell . Column )
{
2015-09-05 18:21:58 +00:00
Gdi . PrepDrawString ( NormalFont , SystemColors . HighlightText ) ;
2015-09-02 22:46:23 +00:00
Gdi . DrawString ( column . Text , point ) ;
2015-09-05 18:33:34 +00:00
Gdi . PrepDrawString ( NormalFont , _foreColor ) ;
2015-09-02 22:46:23 +00:00
}
else
{
Gdi . DrawString ( column . Text , point ) ;
}
start + = CellHeight ;
}
}
else
{
2016-04-16 18:46:47 +00:00
Gdi . PrepDrawString ( NormalFont , _foreColor ) ;
2015-09-02 22:46:23 +00:00
2015-09-05 18:00:08 +00:00
foreach ( var column in visibleColumns )
2015-09-02 22:46:23 +00:00
{
var point = new Point ( column . Left . Value + 2 * CellWidthPadding - HBar . Value , CellHeightPadding ) ; // TODO: fix this CellPadding issue (2 * CellPadding vs just CellPadding)
if ( IsHoveringOnColumnCell & & column = = CurrentCell . Column )
{
2016-04-16 18:46:47 +00:00
Gdi . PrepDrawString ( NormalFont , SystemColors . HighlightText ) ;
2015-09-02 22:46:23 +00:00
Gdi . DrawString ( column . Text , point ) ;
2016-04-16 18:46:47 +00:00
Gdi . PrepDrawString ( NormalFont , _foreColor ) ;
2015-09-02 22:46:23 +00:00
}
else
{
Gdi . DrawString ( column . Text , point ) ;
}
}
}
}
2015-09-05 18:00:08 +00:00
private void DrawData ( PaintEventArgs e , List < RollColumn > visibleColumns )
2015-09-02 22:46:23 +00:00
{
if ( QueryItemText ! = null )
{
if ( HorizontalOrientation )
{
int startRow = FirstVisibleRow ;
int range = Math . Min ( LastVisibleRow , RowCount - 1 ) - startRow + 1 ;
2015-09-05 18:33:34 +00:00
Gdi . PrepDrawString ( NormalFont , _foreColor ) ;
2015-09-02 22:46:23 +00:00
for ( int i = 0 , f = 0 ; f < range ; i + + , f + + )
{
f + = lagFrames [ i ] ;
int LastVisible = LastVisibleColumnIndex ;
for ( int j = FirstVisibleColumn ; j < = LastVisible ; j + + )
{
Bitmap image = null ;
int x = 0 ;
int y = 0 ;
int bitmapOffsetX = 0 ;
int bitmapOffsetY = 0 ;
if ( QueryItemIcon ! = null )
{
2015-09-05 18:00:08 +00:00
QueryItemIcon ( f + startRow , visibleColumns [ j ] , ref image , ref bitmapOffsetX , ref bitmapOffsetY ) ;
2015-09-02 22:46:23 +00:00
}
if ( image ! = null )
{
x = RowsToPixels ( i ) + CellWidthPadding + bitmapOffsetX ;
y = ( j * CellHeight ) + ( CellHeightPadding * 2 ) + bitmapOffsetY ;
Gdi . DrawBitmap ( image , new Point ( x , y ) , true ) ;
}
2015-09-05 20:37:52 +00:00
2015-09-02 22:46:23 +00:00
string text ;
int strOffsetX = 0 ;
int strOffsetY = 0 ;
2015-09-05 18:00:08 +00:00
QueryItemText ( f + startRow , visibleColumns [ j ] , out text , ref strOffsetX , ref strOffsetY ) ;
2015-09-02 22:46:23 +00:00
// Center Text
x = RowsToPixels ( i ) + ( CellWidth - text . Length * _charSize . Width ) / 2 ;
y = ( j * CellHeight ) + CellHeightPadding - VBar . Value ;
var point = new Point ( x + strOffsetX , y + strOffsetY ) ;
var rePrep = false ;
2016-04-17 08:07:07 +00:00
if ( j = = 1 )
2015-09-05 18:00:08 +00:00
if ( SelectedItems . Contains ( new Cell { Column = visibleColumns [ j ] , RowIndex = i + startRow } ) )
2015-09-02 22:46:23 +00:00
{
2016-04-17 08:07:07 +00:00
Gdi . PrepDrawString ( RotatedFont , SystemColors . HighlightText ) ;
2015-09-02 22:46:23 +00:00
rePrep = true ;
2016-04-17 08:07:07 +00:00
}
else if ( j = = 1 )
{
//1. not sure about this; 2. repreps may be excess, but if we render one column at a time, we do need to change back after rendering the header
rePrep = true ;
Gdi . PrepDrawString ( RotatedFont , _foreColor ) ;
2015-09-02 22:46:23 +00:00
}
2016-04-17 08:07:07 +00:00
2015-09-02 22:46:23 +00:00
if ( ! string . IsNullOrWhiteSpace ( text ) )
2016-04-17 08:07:07 +00:00
{
2015-09-02 22:46:23 +00:00
Gdi . DrawString ( text , point ) ;
}
if ( rePrep )
{
2015-09-05 18:33:34 +00:00
Gdi . PrepDrawString ( NormalFont , _foreColor ) ;
2015-09-02 22:46:23 +00:00
}
}
}
}
else
{
int startRow = FirstVisibleRow ;
int range = Math . Min ( LastVisibleRow , RowCount - 1 ) - startRow + 1 ;
2015-09-05 18:33:34 +00:00
Gdi . PrepDrawString ( NormalFont , _foreColor ) ;
2015-09-02 22:46:23 +00:00
int xPadding = CellWidthPadding + 1 - HBar . Value ;
for ( int i = 0 , f = 0 ; f < range ; i + + , f + + ) // Vertical
{
f + = lagFrames [ i ] ;
int LastVisible = LastVisibleColumnIndex ;
for ( int j = FirstVisibleColumn ; j < = LastVisible ; j + + ) // Horizontal
{
2015-09-05 18:00:08 +00:00
RollColumn col = visibleColumns [ j ] ;
2015-09-02 22:46:23 +00:00
string text ;
int strOffsetX = 0 ;
int strOffsetY = 0 ;
Point point = new Point ( col . Left . Value + xPadding , RowsToPixels ( i ) + CellHeightPadding ) ;
Bitmap image = null ;
int bitmapOffsetX = 0 ;
int bitmapOffsetY = 0 ;
if ( QueryItemIcon ! = null )
{
2015-09-05 18:00:08 +00:00
QueryItemIcon ( f + startRow , visibleColumns [ j ] , ref image , ref bitmapOffsetX , ref bitmapOffsetY ) ;
2015-09-02 22:46:23 +00:00
}
if ( image ! = null )
{
Gdi . DrawBitmap ( image , new Point ( point . X + bitmapOffsetX , point . Y + bitmapOffsetY + CellHeightPadding ) , true ) ;
}
2015-09-05 18:00:08 +00:00
QueryItemText ( f + startRow , visibleColumns [ j ] , out text , ref strOffsetX , ref strOffsetY ) ;
2015-09-02 22:46:23 +00:00
bool rePrep = false ;
2015-09-05 18:00:08 +00:00
if ( SelectedItems . Contains ( new Cell { Column = visibleColumns [ j ] , RowIndex = f + startRow } ) )
2015-09-02 22:46:23 +00:00
{
2015-09-05 18:21:58 +00:00
Gdi . PrepDrawString ( NormalFont , SystemColors . HighlightText ) ;
2015-09-02 22:46:23 +00:00
rePrep = true ;
}
if ( ! string . IsNullOrWhiteSpace ( text ) )
{
Gdi . DrawString ( text , new Point ( point . X + strOffsetX , point . Y + strOffsetY ) ) ;
}
if ( rePrep )
{
2015-09-05 18:33:34 +00:00
Gdi . PrepDrawString ( NormalFont , _foreColor ) ;
2015-09-02 22:46:23 +00:00
}
}
}
}
}
}
2015-09-05 18:00:08 +00:00
private void DrawColumnBg ( PaintEventArgs e , List < RollColumn > visibleColumns )
2015-09-02 22:46:23 +00:00
{
Gdi . SetBrush ( SystemColors . ControlLight ) ;
Gdi . SetSolidPen ( Color . Black ) ;
if ( HorizontalOrientation )
{
Gdi . FillRectangle ( 0 , 0 , ColumnWidth + 1 , DrawHeight + 1 ) ;
2015-09-05 18:00:08 +00:00
Gdi . Line ( 0 , 0 , 0 , visibleColumns . Count * CellHeight + 1 ) ;
Gdi . Line ( ColumnWidth , 0 , ColumnWidth , visibleColumns . Count * CellHeight + 1 ) ;
2015-09-02 22:46:23 +00:00
int start = - VBar . Value ;
2015-09-05 18:00:08 +00:00
foreach ( var column in visibleColumns )
2015-09-02 22:46:23 +00:00
{
Gdi . Line ( 1 , start , ColumnWidth , start ) ;
start + = CellHeight ;
}
2015-09-05 18:00:08 +00:00
if ( visibleColumns . Any ( ) )
2015-09-02 22:46:23 +00:00
{
Gdi . Line ( 1 , start , ColumnWidth , start ) ;
}
}
else
{
int bottomEdge = RowsToPixels ( 0 ) ;
// Gray column box and black line underneath
Gdi . FillRectangle ( 0 , 0 , Width + 1 , bottomEdge + 1 ) ;
Gdi . Line ( 0 , 0 , TotalColWidth . Value + 1 , 0 ) ;
Gdi . Line ( 0 , bottomEdge , TotalColWidth . Value + 1 , bottomEdge ) ;
// Vertical black seperators
2015-09-05 18:00:08 +00:00
for ( int i = 0 ; i < visibleColumns . Count ; i + + )
2015-09-02 22:46:23 +00:00
{
2015-09-05 18:00:08 +00:00
int pos = visibleColumns [ i ] . Left . Value - HBar . Value ;
2015-09-02 22:46:23 +00:00
Gdi . Line ( pos , 0 , pos , bottomEdge ) ;
}
// Draw right most line
2015-09-05 18:00:08 +00:00
if ( visibleColumns . Any ( ) )
2015-09-02 22:46:23 +00:00
{
int right = TotalColWidth . Value - HBar . Value ;
Gdi . Line ( right , 0 , right , bottomEdge ) ;
}
}
// Emphasis
2015-09-05 18:00:08 +00:00
foreach ( var column in visibleColumns . Where ( c = > c . Emphasis ) )
2015-09-02 22:46:23 +00:00
{
Gdi . SetBrush ( SystemColors . ActiveBorder ) ;
if ( HorizontalOrientation )
{
2015-09-05 18:00:08 +00:00
Gdi . FillRectangle ( 1 , visibleColumns . IndexOf ( column ) * CellHeight + 1 , ColumnWidth - 1 , ColumnHeight - 1 ) ;
2015-09-02 22:46:23 +00:00
}
else
{
Gdi . FillRectangle ( column . Left . Value + 1 - HBar . Value , 1 , column . Width . Value - 1 , ColumnHeight - 1 ) ;
}
}
// If the user is hovering over a column
if ( IsHoveringOnColumnCell )
{
if ( HorizontalOrientation )
{
2015-09-05 18:00:08 +00:00
for ( int i = 0 ; i < visibleColumns . Count ; i + + )
2015-09-02 22:46:23 +00:00
{
2015-09-05 18:00:08 +00:00
if ( visibleColumns [ i ] ! = CurrentCell . Column )
2015-09-02 22:46:23 +00:00
{
continue ;
}
if ( CurrentCell . Column . Emphasis )
{
Gdi . SetBrush ( Add ( SystemColors . Highlight , 0x00222222 ) ) ;
}
else
{
Gdi . SetBrush ( SystemColors . Highlight ) ;
}
Gdi . FillRectangle ( 1 , i * CellHeight + 1 , ColumnWidth - 1 , ColumnHeight - 1 ) ;
}
}
else
{
//TODO multiple selected columns
2015-09-05 18:00:08 +00:00
for ( int i = 0 ; i < visibleColumns . Count ; i + + )
2015-09-02 22:46:23 +00:00
{
2015-09-05 18:00:08 +00:00
if ( visibleColumns [ i ] = = CurrentCell . Column )
2015-09-02 22:46:23 +00:00
{
//Left of column is to the right of the viewable area or right of column is to the left of the viewable area
2015-09-05 18:00:08 +00:00
if ( visibleColumns [ i ] . Left . Value - HBar . Value > Width | | visibleColumns [ i ] . Right . Value - HBar . Value < 0 )
2015-09-02 22:46:23 +00:00
{
continue ;
}
2015-09-05 18:00:08 +00:00
int left = visibleColumns [ i ] . Left . Value - HBar . Value ;
int width = visibleColumns [ i ] . Right . Value - HBar . Value - left ;
2015-09-02 22:46:23 +00:00
if ( CurrentCell . Column . Emphasis )
{
Gdi . SetBrush ( Add ( SystemColors . Highlight , 0x00550000 ) ) ;
}
else
{
Gdi . SetBrush ( SystemColors . Highlight ) ;
}
Gdi . FillRectangle ( left + 1 , 1 , width - 1 , ColumnHeight - 1 ) ;
}
}
}
}
}
// TODO refactor this and DoBackGroundCallback functions.
/// <summary>
/// Draw Gridlines and background colors using QueryItemBkColor.
/// </summary>
/// <param name="e"></param>
2015-09-05 18:00:08 +00:00
private void DrawBg ( PaintEventArgs e , List < RollColumn > visibleColumns )
2015-09-02 22:46:23 +00:00
{
if ( UseCustomBackground & & QueryItemBkColor ! = null )
2015-09-05 19:44:08 +00:00
{
2015-09-05 19:09:55 +00:00
DoBackGroundCallback ( e , visibleColumns ) ;
2015-09-05 19:44:08 +00:00
}
2015-09-02 22:46:23 +00:00
2015-09-05 20:37:52 +00:00
if ( GridLines )
2015-09-02 22:46:23 +00:00
{
Gdi . SetSolidPen ( SystemColors . ControlLight ) ;
if ( HorizontalOrientation )
{
// Columns
for ( int i = 1 ; i < VisibleRows + 1 ; i + + )
{
int x = RowsToPixels ( i ) ;
Gdi . Line ( x , 1 , x , DrawHeight ) ;
}
// Rows
2015-09-05 18:00:08 +00:00
for ( int i = 0 ; i < visibleColumns . Count + 1 ; i + + )
2015-09-02 22:46:23 +00:00
{
Gdi . Line ( RowsToPixels ( 0 ) + 1 , i * CellHeight - VBar . Value , DrawWidth , i * CellHeight - VBar . Value ) ;
}
}
else
{
// Columns
int y = ColumnHeight + 1 ;
2015-09-05 19:44:08 +00:00
int? totalColWidth = TotalColWidth ;
2015-09-05 18:00:08 +00:00
foreach ( var column in visibleColumns )
2015-09-02 22:46:23 +00:00
{
int x = column . Left . Value - HBar . Value ;
Gdi . Line ( x , y , x , Height - 1 ) ;
}
2015-09-05 18:00:08 +00:00
if ( visibleColumns . Any ( ) )
2015-09-02 22:46:23 +00:00
{
2015-09-05 19:44:08 +00:00
Gdi . Line ( totalColWidth . Value - HBar . Value , y , totalColWidth . Value - HBar . Value , Height - 1 ) ;
2015-09-02 22:46:23 +00:00
}
// Rows
for ( int i = 1 ; i < VisibleRows + 1 ; i + + )
{
Gdi . Line ( 0 , RowsToPixels ( i ) , Width + 1 , RowsToPixels ( i ) ) ;
}
}
}
if ( SelectedItems . Any ( ) )
{
2015-09-05 19:09:55 +00:00
DoSelectionBG ( e , visibleColumns ) ;
2015-09-02 22:46:23 +00:00
}
}
2015-09-05 19:09:55 +00:00
private void DoSelectionBG ( PaintEventArgs e , List < RollColumn > visibleColumns )
2015-09-02 22:46:23 +00:00
{
// SuuperW: This allows user to see other colors in selected frames.
Color rowColor = Color . White ;
2015-09-05 19:27:59 +00:00
int _lastVisibleRow = LastVisibleRow ;
2015-09-02 22:46:23 +00:00
int lastRow = - 1 ;
foreach ( Cell cell in SelectedItems )
2016-09-25 20:04:57 +00:00
{
if ( cell . RowIndex > _lastVisibleRow | | cell . RowIndex < FirstVisibleRow | |
! VisibleColumns . Contains ( cell . Column ) )
continue ;
2015-09-02 22:46:23 +00:00
Cell relativeCell = new Cell
{
RowIndex = cell . RowIndex - FirstVisibleRow ,
Column = cell . Column ,
} ;
relativeCell . RowIndex - = CountLagFramesAbsolute ( relativeCell . RowIndex . Value ) ;
if ( QueryRowBkColor ! = null & & lastRow ! = cell . RowIndex . Value )
{
QueryRowBkColor ( cell . RowIndex . Value , ref rowColor ) ;
lastRow = cell . RowIndex . Value ;
}
Color cellColor = rowColor ;
QueryItemBkColor ( cell . RowIndex . Value , cell . Column , ref cellColor ) ;
// Alpha layering for cell before selection
float alpha = ( float ) cellColor . A / 255 ;
if ( cellColor . A ! = 255 & & cellColor . A ! = 0 )
{
cellColor = Color . FromArgb ( rowColor . R - ( int ) ( ( rowColor . R - cellColor . R ) * alpha ) ,
rowColor . G - ( int ) ( ( rowColor . G - cellColor . G ) * alpha ) ,
rowColor . B - ( int ) ( ( rowColor . B - cellColor . B ) * alpha ) ) ;
}
// Alpha layering for selection
alpha = 0.33f ;
cellColor = Color . FromArgb ( cellColor . R - ( int ) ( ( cellColor . R - SystemColors . Highlight . R ) * alpha ) ,
cellColor . G - ( int ) ( ( cellColor . G - SystemColors . Highlight . G ) * alpha ) ,
cellColor . B - ( int ) ( ( cellColor . B - SystemColors . Highlight . B ) * alpha ) ) ;
2015-09-05 19:09:55 +00:00
DrawCellBG ( cellColor , relativeCell , visibleColumns ) ;
2015-09-02 22:46:23 +00:00
}
}
/// <summary>
/// Given a cell with rowindex inbetween 0 and VisibleRows, it draws the background color specified. Do not call with absolute rowindices.
/// </summary>
2015-09-05 19:09:55 +00:00
private void DrawCellBG ( Color color , Cell cell , List < RollColumn > visibleColumns )
2015-09-02 22:46:23 +00:00
{
int x , y , w , h ;
if ( HorizontalOrientation )
{
x = RowsToPixels ( cell . RowIndex . Value ) + 1 ;
w = CellWidth - 1 ;
2015-09-05 19:09:55 +00:00
y = ( CellHeight * visibleColumns . IndexOf ( cell . Column ) ) + 1 - VBar . Value ; // We can't draw without row and column, so assume they exist and fail catastrophically if they don't
2015-09-02 22:46:23 +00:00
h = CellHeight - 1 ;
if ( x < ColumnWidth ) { return ; }
}
else
{
w = cell . Column . Width . Value - 1 ;
x = cell . Column . Left . Value - HBar . Value + 1 ;
y = RowsToPixels ( cell . RowIndex . Value ) + 1 ; // We can't draw without row and column, so assume they exist and fail catastrophically if they don't
h = CellHeight - 1 ;
if ( y < ColumnHeight )
{
return ;
}
}
if ( x > DrawWidth | | y > DrawHeight )
{
return ;
} // Don't draw if off screen.
Gdi . SetBrush ( color ) ;
Gdi . FillRectangle ( x , y , w , h ) ;
}
/// <summary>
/// Calls QueryItemBkColor callback for all visible cells and fills in the background of those cells.
/// </summary>
/// <param name="e"></param>
2015-09-05 19:09:55 +00:00
private void DoBackGroundCallback ( PaintEventArgs e , List < RollColumn > visibleColumns )
2015-09-02 22:46:23 +00:00
{
2015-09-02 23:39:57 +00:00
int startIndex = FirstVisibleRow ;
int range = Math . Min ( LastVisibleRow , RowCount - 1 ) - startIndex + 1 ;
int lastVisible = LastVisibleColumnIndex ;
2015-09-05 20:37:52 +00:00
int firstVisibleColumn = FirstVisibleColumn ;
2016-09-25 20:04:57 +00:00
if ( HorizontalOrientation )
2015-09-02 22:46:23 +00:00
{
for ( int i = 0 , f = 0 ; f < range ; i + + , f + + )
{
f + = lagFrames [ i ] ;
2015-09-02 23:38:33 +00:00
2015-09-02 22:46:23 +00:00
Color rowColor = Color . White ;
if ( QueryRowBkColor ! = null )
2015-09-02 23:38:33 +00:00
{
2015-09-02 22:46:23 +00:00
QueryRowBkColor ( f + startIndex , ref rowColor ) ;
2015-09-02 23:38:33 +00:00
}
2015-09-05 20:37:52 +00:00
for ( int j = firstVisibleColumn ; j < = lastVisible ; j + + )
2015-09-02 22:46:23 +00:00
{
Color itemColor = Color . White ;
2015-09-05 19:09:55 +00:00
QueryItemBkColor ( f + startIndex , visibleColumns [ j ] , ref itemColor ) ;
2015-09-02 22:46:23 +00:00
if ( itemColor = = Color . White )
2015-09-02 23:38:33 +00:00
{
2015-09-02 22:46:23 +00:00
itemColor = rowColor ;
2015-09-02 23:38:33 +00:00
}
2015-09-02 22:46:23 +00:00
else if ( itemColor . A ! = 255 & & itemColor . A ! = 0 )
{
float alpha = ( float ) itemColor . A / 255 ;
itemColor = Color . FromArgb ( rowColor . R - ( int ) ( ( rowColor . R - itemColor . R ) * alpha ) ,
rowColor . G - ( int ) ( ( rowColor . G - itemColor . G ) * alpha ) ,
rowColor . B - ( int ) ( ( rowColor . B - itemColor . B ) * alpha ) ) ;
}
if ( itemColor ! = Color . White ) // An easy optimization, don't draw unless the user specified something other than the default
{
2015-09-02 23:38:33 +00:00
var cell = new Cell
2015-09-02 22:46:23 +00:00
{
2015-09-05 19:09:55 +00:00
Column = visibleColumns [ j ] ,
2015-09-02 22:46:23 +00:00
RowIndex = i
} ;
2015-09-05 19:09:55 +00:00
DrawCellBG ( itemColor , cell , visibleColumns ) ;
2015-09-02 22:46:23 +00:00
}
}
}
}
else
{
for ( int i = 0 , f = 0 ; f < range ; i + + , f + + ) // Vertical
{
f + = lagFrames [ i ] ;
2015-09-02 23:38:33 +00:00
2015-09-02 22:46:23 +00:00
Color rowColor = Color . White ;
if ( QueryRowBkColor ! = null )
2015-09-02 23:38:33 +00:00
{
2015-09-02 23:39:57 +00:00
QueryRowBkColor ( f + startIndex , ref rowColor ) ;
2015-09-02 23:38:33 +00:00
}
for ( int j = FirstVisibleColumn ; j < = lastVisible ; j + + ) // Horizontal
2015-09-02 22:46:23 +00:00
{
Color itemColor = Color . White ;
2015-09-05 19:09:55 +00:00
QueryItemBkColor ( f + startIndex , visibleColumns [ j ] , ref itemColor ) ;
2015-09-02 22:46:23 +00:00
if ( itemColor = = Color . White )
2015-09-02 23:38:33 +00:00
{
2015-09-02 22:46:23 +00:00
itemColor = rowColor ;
2015-09-02 23:38:33 +00:00
}
2015-09-02 22:46:23 +00:00
else if ( itemColor . A ! = 255 & & itemColor . A ! = 0 )
{
float alpha = ( float ) itemColor . A / 255 ;
itemColor = Color . FromArgb ( rowColor . R - ( int ) ( ( rowColor . R - itemColor . R ) * alpha ) ,
rowColor . G - ( int ) ( ( rowColor . G - itemColor . G ) * alpha ) ,
rowColor . B - ( int ) ( ( rowColor . B - itemColor . B ) * alpha ) ) ;
}
if ( itemColor ! = Color . White ) // An easy optimization, don't draw unless the user specified something other than the default
{
var cell = new Cell
{
2015-09-05 19:09:55 +00:00
Column = visibleColumns [ j ] ,
2015-09-02 22:46:23 +00:00
RowIndex = i
} ;
2015-09-05 19:09:55 +00:00
DrawCellBG ( itemColor , cell , visibleColumns ) ;
2015-09-02 22:46:23 +00:00
}
}
}
}
}
}
}