forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blame: Display author avatar and a recency marker in the gutter
+ add a setting to disable it Note: Height estimation (proposed in gitextensions#6605 (comment) ) + Use greenish colors for heatmap with color adaptation for other themes Color chosen from: https://colorbrewer2.org/#type=sequential&scheme=Greens&n=7
- Loading branch information
Showing
11 changed files
with
286 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Windows.Forms; | ||
using GitExtUtils.GitUI; | ||
using ICSharpCode.TextEditor; | ||
|
||
namespace GitUI.Editor | ||
{ | ||
/// <summary> | ||
/// This class display avatars in the gutter in a blame control. | ||
/// </summary> | ||
public class BlameAuthorMargin : AbstractMargin | ||
{ | ||
private static readonly int RecencyIndexWidth = Convert.ToInt32(4 * DpiUtil.ScaleX); | ||
private List<Image> _avatars; | ||
private readonly int _lineHeight; | ||
private readonly Color _backgroundColor; | ||
private List<GitBlameEntry> _blameLines; | ||
private readonly Dictionary<int, SolidBrush> _brushs = new Dictionary<int, SolidBrush>(); | ||
private bool _isVisible = true; | ||
|
||
public BlameAuthorMargin(TextArea textArea) : base(textArea) | ||
{ | ||
_lineHeight = GetFontHeight(textArea.Font); | ||
_backgroundColor = SystemColors.Window; | ||
Width = _lineHeight + RecencyIndexWidth + DpiUtil.Scale(2); | ||
} | ||
|
||
public override int Width { get; } | ||
public override bool IsVisible => _isVisible; | ||
|
||
private static int GetFontHeight(Font font) | ||
{ | ||
var max = Math.Max( | ||
TextRenderer.MeasureText("_", font).Height, | ||
(int)Math.Ceiling(font.GetHeight())); | ||
|
||
return max + 1; | ||
} | ||
|
||
public void Initialize(List<GitBlameEntry> blameLines) | ||
{ | ||
_blameLines = blameLines; | ||
_avatars = blameLines.Select(a => a.Avatar).ToList(); | ||
|
||
// Update the resolution otherwise the image is not drawn at the good size :( | ||
foreach (var avatar in _avatars) | ||
{ | ||
if (avatar is Bitmap bitmapAvatar) | ||
{ | ||
bitmapAvatar.SetResolution(DpiUtil.DpiX, DpiUtil.DpiY); | ||
} | ||
} | ||
|
||
// Build brushes | ||
foreach (var blameLine in blameLines) | ||
{ | ||
if (!_brushs.ContainsKey(blameLine.AgeBucketIndex)) | ||
{ | ||
_brushs.Add(blameLine.AgeBucketIndex, new SolidBrush(blameLine.AgeBucketColor)); | ||
} | ||
} | ||
} | ||
|
||
public void SetVisiblity(bool isVisible) | ||
{ | ||
_isVisible = isVisible; | ||
} | ||
|
||
public override void Paint(Graphics g, Rectangle rect) | ||
{ | ||
if (rect.Width <= 0 || rect.Height <= 0) | ||
{ | ||
return; | ||
} | ||
|
||
g.Clear(_backgroundColor); | ||
|
||
if (_avatars == null || _avatars.Count == 0) | ||
{ | ||
return; | ||
} | ||
|
||
var verticalOffset = textArea.VirtualTop.Y; | ||
var lineStart = verticalOffset / _lineHeight; | ||
var negativeOffset = (lineStart * _lineHeight) - verticalOffset; | ||
var lineCount = (int)Math.Ceiling((double)(rect.Height - negativeOffset) / _lineHeight); | ||
|
||
for (int i = 0; i < lineCount; i++) | ||
{ | ||
if (lineStart + i >= _avatars.Count) | ||
{ | ||
break; | ||
} | ||
|
||
int y = negativeOffset + (i * _lineHeight); | ||
g.FillRectangle(_brushs[_blameLines[lineStart + i].AgeBucketIndex], 0, y, RecencyIndexWidth, _lineHeight); | ||
|
||
if (_avatars[lineStart + i] != null) | ||
{ | ||
g.DrawImage(_avatars[lineStart + i], new Point(RecencyIndexWidth, y)); | ||
} | ||
} | ||
|
||
base.Paint(g, rect); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Drawing; | ||
|
||
namespace GitUI.Editor | ||
{ | ||
public class GitBlameEntry | ||
{ | ||
public Image Avatar { get; set; } | ||
public int AgeBucketIndex { get; set; } | ||
public Color AgeBucketColor { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.