Browse Source

Merge branch 'master' of github.com:icsharpcode/SharpDevelop

pull/19/head
PeterForstmeier 15 years ago
parent
commit
23ca112111
  1. 89
      src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs
  2. 16
      src/AddIns/Analysis/CodeQuality/Src/Utility/Helper.cs
  3. 8
      src/AddIns/Analysis/CodeQuality/Src/Utility/Matrix.cs

89
src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs

@ -38,20 +38,12 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
private int fontSize = 0; private int fontSize = 0;
private int penSize = 0; private int penSize = 0;
private TMatrix matrix;
public TMatrix Matrix
{ protected int PageSizeWidth { get; set; }
get { return matrix; } protected int PageSizeHeight { get; set; }
set
{ public TMatrix Matrix { get; set; }
matrix = value;
// matrixHeight = matrix.HeaderRows.Count - 1;
// matrixWidth = matrix.HeaderColumns.Count - 1;
}
}
public int CellHeight { get; set; } public int CellHeight { get; set; }
@ -77,10 +69,10 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
public void SetVisibleItems(HeaderType type, ICollection<TItem> visibleItems) public void SetVisibleItems(HeaderType type, ICollection<TItem> visibleItems)
{ {
matrix.SetVisibleItems(type, visibleItems); Matrix.SetVisibleItems(type, visibleItems);
matrixHeight = matrix.HeaderRows.Count; matrixHeight = Matrix.HeaderRows.Count;
matrixWidth = matrix.HeaderColumns.Count; matrixWidth = Matrix.HeaderColumns.Count;
bool changedCoords = false; bool changedCoords = false;
if (currentCell.X > matrixHeight) { if (currentCell.X > matrixHeight) {
@ -103,7 +95,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
public void HighlightLine(HeaderType type, INode node) public void HighlightLine(HeaderType type, INode node)
{ {
var items = type == HeaderType.Columns ? matrix.HeaderColumns : matrix.HeaderRows; var items = type == HeaderType.Columns ? Matrix.HeaderColumns : Matrix.HeaderRows;
for (int i = 0; i < items.Count; i++) { for (int i = 0; i < items.Count; i++) {
if (items[i].Value.Equals(node)) { if (items[i].Value.Equals(node)) {
if (currentCell.X == i && type == HeaderType.Rows) if (currentCell.X == i && type == HeaderType.Rows)
@ -156,7 +148,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
{ {
HoveredCell.RowIndex = currentCell.Y; HoveredCell.RowIndex = currentCell.Y;
HoveredCell.ColumnIndex = currentCell.X; HoveredCell.ColumnIndex = currentCell.X;
HoveredCell.Value = matrix[HoveredCell.RowIndex, HoveredCell.ColumnIndex]; HoveredCell.Value = Matrix[HoveredCell.RowIndex, HoveredCell.ColumnIndex];
if (HoveredCellChanged != null) if (HoveredCellChanged != null)
HoveredCellChanged(this, new HoveredCellEventArgs<TValue>(HoveredCell)); HoveredCellChanged(this, new HoveredCellEventArgs<TValue>(HoveredCell));
} }
@ -175,7 +167,10 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
var cellsHorizontally = maxWidth >= matrixWidth ? matrixWidth : maxWidth + 1; var cellsHorizontally = maxWidth >= matrixWidth ? matrixWidth : maxWidth + 1;
var cellsVertically = maxHeight >= matrixHeight ? matrixHeight : maxHeight + 1; var cellsVertically = maxHeight >= matrixHeight ? matrixHeight : maxHeight + 1;
// number of cell which will be drawn PageSizeWidth = cellsHorizontally;
PageSizeHeight = cellsVertically;
// number of cell which arent visible
var scaledOffsetX = (int)offset.X / CellWidth; var scaledOffsetX = (int)offset.X / CellWidth;
var scaledOffsetY = (int)offset.Y / CellHeight; var scaledOffsetY = (int)offset.Y / CellHeight;
@ -230,9 +225,14 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
// text // text
for (int i = 0; i < cellsHorizontally; i++) { for (int i = 0; i < cellsHorizontally; i++) {
for (int j = 0; j < cellsVertically; j++) { // dont draw text in unavailables places for (int j = 0; j < cellsVertically; j++) { // dont draw text in unavailables places
int rowIndex = j; int rowIndex = j + scaledOffsetY;
int columnIndex = i; int columnIndex = i + scaledOffsetX;
var value = matrix[rowIndex, columnIndex];
// adjust scales
rowIndex = rowIndex >= Matrix.HeaderRows.Count ? rowIndex - 1 : rowIndex;
columnIndex = columnIndex >= Matrix.HeaderColumns.Count ? columnIndex - 1 : columnIndex;
var value = Matrix[rowIndex, columnIndex];
if (Colorizer != null) { if (Colorizer != null) {
var rect = new Rect( var rect = new Rect(
@ -242,11 +242,18 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
CellHeight); CellHeight);
SolidColorBrush brush = null; SolidColorBrush brush = null;
// if ((i * CellWidth - offsetDiffX) == currentXLine || if ((i * CellWidth - offsetDiffX) == currentXLine ||
// ((i * CellWidth - offsetDiffX) == currentXLine)) ((j * CellHeight - offsetDiffY) == currentYLine)) {
// brush = Brushes.Pink; //Colorizer.GetColorBrushMixedWith(Colors.GreenYellow, value); var color = Colors.GreenYellow;
// else if (currentCell.X == i && currentCell.Y == j) {
brush = Colorizer.GetColorBrush(value); color = color.MixedWith(Colors.Red);
}
brush = Colorizer.GetColorBrushMixedWith(color, value);
}
else
brush = Colorizer.GetColorBrush(value);
drawingContext.DrawRectangle(brush, null, rect); drawingContext.DrawRectangle(brush, null, rect);
} }
@ -374,75 +381,75 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
public void LineUp() public void LineUp()
{ {
SetVerticalOffset(VerticalOffset - 1); SetVerticalOffset(VerticalOffset - CellHeight);
} }
public void LineDown() public void LineDown()
{ {
SetVerticalOffset(VerticalOffset + 1); SetVerticalOffset(VerticalOffset + CellHeight);
} }
public void LineLeft() public void LineLeft()
{ {
SetHorizontalOffset(HorizontalOffset - 1); SetHorizontalOffset(HorizontalOffset - CellWidth);
} }
public void LineRight() public void LineRight()
{ {
SetHorizontalOffset(HorizontalOffset + 1); SetHorizontalOffset(HorizontalOffset + CellWidth);
} }
public void PageUp() public void PageUp()
{ {
SetVerticalOffset(VerticalOffset - CellHeight); SetVerticalOffset(VerticalOffset - CellHeight * PageSizeHeight);
} }
public void PageDown() public void PageDown()
{ {
SetVerticalOffset(VerticalOffset + CellHeight); SetVerticalOffset(VerticalOffset + CellHeight * PageSizeHeight);
} }
public void PageLeft() public void PageLeft()
{ {
SetHorizontalOffset(HorizontalOffset - CellWidth); SetHorizontalOffset(HorizontalOffset - CellWidth * PageSizeWidth);
} }
public void PageRight() public void PageRight()
{ {
SetHorizontalOffset(HorizontalOffset + CellWidth); SetHorizontalOffset(HorizontalOffset + CellWidth * PageSizeWidth);
} }
public void MouseWheelUp() public void MouseWheelUp()
{ {
SetVerticalOffset(VerticalOffset - 4); SetVerticalOffset(VerticalOffset - CellHeight);
} }
public void MouseWheelDown() public void MouseWheelDown()
{ {
SetVerticalOffset(VerticalOffset + 4); SetVerticalOffset(VerticalOffset + CellHeight);
} }
public void MouseWheelLeft() public void MouseWheelLeft()
{ {
SetVerticalOffset(HorizontalOffset - 4); SetVerticalOffset(HorizontalOffset - CellWidth);
} }
public void MouseWheelRight() public void MouseWheelRight()
{ {
SetVerticalOffset(HorizontalOffset + 4); SetVerticalOffset(HorizontalOffset + CellWidth);
} }
public void SetHorizontalOffset(double offset) public void SetHorizontalOffset(double offset)
{ {
if (offset == this.offset.X) return; if (offset == this.offset.X) return;
this.offset.X = offset; this.offset.X = Math.Round(offset / CellWidth) * CellWidth;
InvalidateVisual(); InvalidateVisual();
} }
public void SetVerticalOffset(double offset) public void SetVerticalOffset(double offset)
{ {
if (offset == this.offset.Y) return; if (offset == this.offset.Y) return;
this.offset.Y = offset; this.offset.Y = Math.Round(offset / CellHeight) * CellHeight;
InvalidateVisual(); InvalidateVisual();
} }

16
src/AddIns/Analysis/CodeQuality/Src/Utility/Helper.cs

@ -57,16 +57,14 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility
public static Color MixedWith(this Color c1, Color c2) public static Color MixedWith(this Color c1, Color c2)
{ {
int r = Math.Min((c1.R + c2.R), 255); var percent = .5f;
int g = Math.Min((c1.G + c2.G), 255); var amountFrom = 1.0f - percent;
int b = Math.Min((c1.B + c2.B), 255);
return new Color return Color.FromArgb(
{ (byte)(c1.A * amountFrom + c2.A * percent),
R = Convert.ToByte(r), (byte)(c1.R * amountFrom + c2.R * percent),
G = Convert.ToByte(g), (byte)(c1.G * amountFrom + c2.G * percent),
B = Convert.ToByte(b) (byte)(c1.B * amountFrom + c2.B * percent));
};
} }
public static T FindVisualChild<T>( DependencyObject obj ) public static T FindVisualChild<T>( DependencyObject obj )

8
src/AddIns/Analysis/CodeQuality/Src/Utility/Matrix.cs

@ -64,12 +64,12 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility
columnIndex > HeaderColumns.Count || columnIndex < 0) columnIndex > HeaderColumns.Count || columnIndex < 0)
return default(TValue); return default(TValue);
var cacheResult = GetFromCache(rowIndex, columnIndex); // var cacheResult = GetFromCache(rowIndex, columnIndex);
if (cacheResult != null) // if (cacheResult != null)
return cacheResult; // return cacheResult;
var result = GetCellValue(rowIndex, columnIndex); var result = GetCellValue(rowIndex, columnIndex);
SaveToCache(rowIndex, columnIndex, result); // SaveToCache(rowIndex, columnIndex, result);
return result; return result;
} }
} }

Loading…
Cancel
Save