Debugger - Added arrow on current statement + Font size config

This commit is contained in:
Souryo 2015-08-04 19:50:57 -04:00
parent 4b9ab622ca
commit f55436daf1
5 changed files with 133 additions and 35 deletions

View file

@ -35,6 +35,13 @@ namespace Mesen.GUI.Debugger
}
}
[DefaultValue(13F)]
public float FontSize
{
get { return this.ctrlCodeViewer.FontSize; }
set { this.ctrlCodeViewer.FontSize = value; }
}
private UInt32? _currentActiveAddress = null;
public void SelectActiveAddress(UInt32 address)
{
@ -46,7 +53,7 @@ namespace Mesen.GUI.Debugger
{
//Set line background to yellow
this.ctrlCodeViewer.ClearLineStyles();
this.ctrlCodeViewer.SetLineColor((int)address, Color.Black, Color.Yellow, null, LineSymbol.None);
this.ctrlCodeViewer.SetLineColor((int)address, Color.Black, Color.Yellow, null, LineSymbol.Arrow);
_currentActiveAddress = address;
}
@ -145,23 +152,27 @@ namespace Mesen.GUI.Debugger
{
ctrlCodeViewer.ClearLineStyles();
if(_currentActiveAddress.HasValue) {
this.ctrlCodeViewer.SetLineColor((int)_currentActiveAddress.Value, Color.Black, Color.Yellow, null, LineSymbol.None);
SetActiveAddress(_currentActiveAddress.Value);
}
foreach(Breakpoint breakpoint in breakpoints) {
Color? fgColor = Color.White;
Color? bgColor = null;
Color? outlineColor = Color.FromArgb(140, 40, 40);
LineSymbol symbol;
if(breakpoint.Enabled) {
bgColor = Color.FromArgb(140, 40, 40);
symbol = LineSymbol.Circle;
} else {
fgColor = Color.Black;
symbol = LineSymbol.CircleOutline;
}
if(breakpoint.Address == (UInt32)(_currentActiveAddress.HasValue ? (int)_currentActiveAddress.Value : -1)) {
fgColor = Color.Black;
bgColor = Color.Yellow;
symbol |= LineSymbol.Arrow;
}
ctrlCodeViewer.SetLineColor((int)breakpoint.Address, fgColor, bgColor, outlineColor, breakpoint.Enabled ? LineSymbol.Circle : LineSymbol.CircleOutline);
ctrlCodeViewer.SetLineColor((int)breakpoint.Address, fgColor, bgColor, outlineColor, symbol);
}
}

View file

@ -38,6 +38,18 @@ namespace Mesen.GUI.Debugger
new ToolTip().SetToolTip(picSearchPrevious, "Find Previous (Shift-F3)");
}
public float FontSize
{
get { return this.ctrlTextbox.Font.SizeInPoints; }
set
{
if(value >= 6 && value <= 20) {
this.ctrlTextbox.Font = new Font("Consolas", value);
this.ctrlTextbox.Invalidate();
}
}
}
public string GetWordUnderLocation(Point position)
{
return this.ctrlTextbox.GetWordUnderLocation(position);

View file

@ -10,11 +10,13 @@ using System.Windows.Forms;
namespace Mesen.GUI.Debugger
{
[Flags]
public enum LineSymbol
{
None = 0,
Circle,
CircleOutline,
Circle = 1,
CircleOutline = 2,
Arrow = 4,
}
public class LineProperties
@ -29,7 +31,6 @@ namespace Mesen.GUI.Debugger
{
public event EventHandler ScrollPositionChanged;
//Dictionary<int,
private string[] _contents = new string[0];
private int[] _lineNumbers = new int[0];
private Dictionary<int, int> _lineNumberIndex = new Dictionary<int,int>();
@ -45,7 +46,6 @@ namespace Mesen.GUI.Debugger
InitializeComponent();
this.ResizeRedraw = true;
this.DoubleBuffered = true;
this.Font = new Font("Consolas", 13);
}
public string[] TextLines
@ -205,7 +205,7 @@ namespace Mesen.GUI.Debugger
using(Graphics g = Graphics.FromHwnd(this.Handle)) {
int marginLeft = this.GetMargin(g);
int positionX = position.X - marginLeft;
int lineOffset = position.Y / (this.Font.Height - 1);
int lineOffset = position.Y / this.LineHeight;
if(positionX >= 0 && this.ScrollPosition + lineOffset < _contents.Length) {
string text = _contents[this.ScrollPosition + lineOffset];
int charIndex = -1;
@ -245,7 +245,7 @@ namespace Mesen.GUI.Debugger
private int GetNumberVisibleLines()
{
Rectangle rect = this.ClientRectangle;
return rect.Height / (this.Font.Height - 1);
return rect.Height / this.LineHeight;
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
@ -296,6 +296,11 @@ namespace Mesen.GUI.Debugger
set { _showLineInHex = value; }
}
private int LineHeight
{
get { return this.Font.Height - 1; }
}
protected override void OnMouseDown(MouseEventArgs e)
{
this.Focus();
@ -305,7 +310,7 @@ namespace Mesen.GUI.Debugger
protected override void OnMouseClick(MouseEventArgs e)
{
if(e.Button == System.Windows.Forms.MouseButtons.Left) {
int clickedLine = e.Y / (this.Font.Height - 1);
int clickedLine = e.Y / this.LineHeight;
this.CursorPosition = this.ScrollPosition + clickedLine;
}
base.OnMouseClick(e);
@ -322,7 +327,7 @@ namespace Mesen.GUI.Debugger
if(currentLine == this.CursorPosition) {
//Highlight current line
g.FillRectangle(Brushes.AliceBlue, marginLeft, positionY, this.ClientRectangle.Width - marginLeft, this.Font.Height-1);
g.FillRectangle(Brushes.AliceBlue, marginLeft, positionY, this.ClientRectangle.Width - marginLeft, this.LineHeight);
}
Color textColor = Color.Black;
@ -335,33 +340,41 @@ namespace Mesen.GUI.Debugger
if(lineProperties.BgColor.HasValue) {
using(Brush bgBrush = new SolidBrush(lineProperties.BgColor.Value)) {
g.FillRectangle(bgBrush, marginLeft + 1, positionY + 1, stringLength, this.Font.Height-2);
g.FillRectangle(bgBrush, marginLeft + 1, positionY + 1, stringLength, this.LineHeight-1);
}
}
if(lineProperties.OutlineColor.HasValue) {
using(Pen outlinePen = new Pen(lineProperties.OutlineColor.Value, 1)) {
g.DrawRectangle(outlinePen, marginLeft + 1, positionY + 1, stringLength, this.Font.Height-2);
g.DrawRectangle(outlinePen, marginLeft + 1, positionY + 1, stringLength, this.LineHeight-1);
}
}
switch(lineProperties.Symbol) {
case LineSymbol.Circle:
using(Brush brush = new SolidBrush(lineProperties.OutlineColor.Value)) {
g.FillEllipse(brush, 2, positionY + 3, this.Font.Height - 7, this.Font.Height - 7);
if(lineProperties.OutlineColor.HasValue) {
using(Pen pen = new Pen(lineProperties.OutlineColor.Value, 1)) {
g.DrawEllipse(pen, 2, positionY + 3, this.Font.Height - 7, this.Font.Height - 7);
}
}
}
break;
case LineSymbol.CircleOutline:
if(lineProperties.OutlineColor.HasValue) {
using(Pen pen = new Pen(lineProperties.OutlineColor.Value, 1)) {
g.DrawEllipse(pen, 2, positionY + 3, this.Font.Height - 7, this.Font.Height - 7);
}
}
break;
if(lineProperties.Symbol.HasFlag(LineSymbol.Circle)) {
using(Brush brush = new SolidBrush(lineProperties.OutlineColor.Value)) {
g.FillEllipse(brush, 1, positionY + 2, this.LineHeight - 3, this.LineHeight - 3);
}
}
if(lineProperties.Symbol.HasFlag(LineSymbol.CircleOutline) && lineProperties.OutlineColor.HasValue) {
using(Pen pen = new Pen(lineProperties.OutlineColor.Value, 1)) {
g.DrawEllipse(pen, 1, positionY + 2, this.LineHeight - 3, this.LineHeight - 3);
}
}
if(lineProperties.Symbol.HasFlag(LineSymbol.Arrow)) {
int arrowY = positionY + this.LineHeight / 2 + 1;
using(Pen pen = new Pen(Color.Black, this.LineHeight * 0.33f)) {
//Outline
g.DrawLine(pen, 3, arrowY, 3 + this.LineHeight * 0.25f, arrowY);
pen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
g.DrawLine(pen, 3 + this.LineHeight * 0.25f, arrowY, 3 + this.LineHeight * 0.75f, arrowY);
//Fill
pen.Width-=2f;
pen.Color = lineProperties.BgColor.Value;
pen.EndCap = System.Drawing.Drawing2D.LineCap.Square;
g.DrawLine(pen, 4, arrowY, 3 + this.LineHeight * 0.25f - 1, arrowY);
pen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
g.DrawLine(pen, 3 + this.LineHeight * 0.25f, arrowY, this.LineHeight * 0.75f + 1, arrowY);
}
}
}
@ -376,7 +389,7 @@ namespace Mesen.GUI.Debugger
float offsetX = g.MeasureString(_contents[currentLine].Substring(0, searchIndex), this.Font, Int32.MaxValue, stringFormat).Width;
using(Brush selBrush = new SolidBrush(Color.White), selBgBrush = new SolidBrush(Color.CornflowerBlue)) {
g.FillRectangle(selBgBrush, marginLeft+offsetX+1, positionY, searchStringWidth+2, this.Font.Height - 1);
g.FillRectangle(selBgBrush, marginLeft+offsetX+1, positionY, searchStringWidth+2, this.LineHeight);
g.DrawString(searchString, this.Font, selBrush, marginLeft+offsetX, positionY);
}
offsetX += searchStringWidth;
@ -406,7 +419,7 @@ namespace Mesen.GUI.Debugger
int positionY = 0;
while(positionY < rect.Bottom && currentLine < _contents.Length) {
this.DrawLine(pe.Graphics, currentLine, marginLeft, positionY);
positionY += this.Font.Height - 1;
positionY += this.LineHeight;
currentLine++;
}
}

View file

@ -45,6 +45,10 @@
this.mnuClose = new System.Windows.Forms.ToolStripMenuItem();
this.mnuView = new System.Windows.Forms.ToolStripMenuItem();
this.mnuSplitView = new System.Windows.Forms.ToolStripMenuItem();
this.fontSizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.mnuIncreaseFontSize = new System.Windows.Forms.ToolStripMenuItem();
this.mnuDecreaseFontSize = new System.Windows.Forms.ToolStripMenuItem();
this.mnuResetFontSize = new System.Windows.Forms.ToolStripMenuItem();
this.debugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.mnuContinue = new System.Windows.Forms.ToolStripMenuItem();
this.mnuBreak = new System.Windows.Forms.ToolStripMenuItem();
@ -218,7 +222,8 @@
// mnuView
//
this.mnuView.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuSplitView});
this.mnuSplitView,
this.fontSizeToolStripMenuItem});
this.mnuView.Name = "mnuView";
this.mnuView.Size = new System.Drawing.Size(44, 20);
this.mnuView.Text = "View";
@ -227,10 +232,47 @@
//
this.mnuSplitView.CheckOnClick = true;
this.mnuSplitView.Name = "mnuSplitView";
this.mnuSplitView.Size = new System.Drawing.Size(125, 22);
this.mnuSplitView.Size = new System.Drawing.Size(152, 22);
this.mnuSplitView.Text = "Split View";
this.mnuSplitView.Click += new System.EventHandler(this.mnuSplitView_Click);
//
// fontSizeToolStripMenuItem
//
this.fontSizeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuIncreaseFontSize,
this.mnuDecreaseFontSize,
this.mnuResetFontSize});
this.fontSizeToolStripMenuItem.Name = "fontSizeToolStripMenuItem";
this.fontSizeToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.fontSizeToolStripMenuItem.Text = "Text Size";
//
// mnuIncreaseFontSize
//
this.mnuIncreaseFontSize.Name = "mnuIncreaseFontSize";
this.mnuIncreaseFontSize.ShortcutKeyDisplayString = "Ctrl++";
this.mnuIncreaseFontSize.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Oemplus)));
this.mnuIncreaseFontSize.Size = new System.Drawing.Size(197, 22);
this.mnuIncreaseFontSize.Text = "Increase";
this.mnuIncreaseFontSize.Click += new System.EventHandler(this.mnuIncreaseFontSize_Click);
//
// mnuDecreaseFontSize
//
this.mnuDecreaseFontSize.Name = "mnuDecreaseFontSize";
this.mnuDecreaseFontSize.ShortcutKeyDisplayString = "Ctrl+-";
this.mnuDecreaseFontSize.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.OemMinus)));
this.mnuDecreaseFontSize.Size = new System.Drawing.Size(197, 22);
this.mnuDecreaseFontSize.Text = "Decrease";
this.mnuDecreaseFontSize.Click += new System.EventHandler(this.mnuDecreaseFontSize_Click);
//
// mnuResetFontSize
//
this.mnuResetFontSize.Name = "mnuResetFontSize";
this.mnuResetFontSize.ShortcutKeyDisplayString = "Ctrl+0";
this.mnuResetFontSize.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D0)));
this.mnuResetFontSize.Size = new System.Drawing.Size(197, 22);
this.mnuResetFontSize.Text = "Reset to Default";
this.mnuResetFontSize.Click += new System.EventHandler(this.mnuResetFontSize_Click);
//
// debugToolStripMenuItem
//
this.debugToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -511,5 +553,9 @@
private System.Windows.Forms.ToolStripMenuItem mnuMemoryViewer;
private Controls.ctrlBreakpoints ctrlBreakpoints;
private System.Windows.Forms.ToolStripMenuItem mnuGoTo;
private System.Windows.Forms.ToolStripMenuItem fontSizeToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem mnuIncreaseFontSize;
private System.Windows.Forms.ToolStripMenuItem mnuDecreaseFontSize;
private System.Windows.Forms.ToolStripMenuItem mnuResetFontSize;
}
}

View file

@ -52,6 +52,7 @@ namespace Mesen.GUI.Debugger
{
if(mnuSplitView.Checked) {
tlpTop.ColumnStyles[1].SizeType = SizeType.Percent;
tlpTop.ColumnStyles[0].Width = 50f;
tlpTop.ColumnStyles[1].Width = 50f;
this.MinimumSize = new Size(1250, 650);
} else {
@ -195,5 +196,20 @@ namespace Mesen.GUI.Debugger
{
_lastCodeWindow.GoToAddress();
}
private void mnuIncreaseFontSize_Click(object sender, EventArgs e)
{
_lastCodeWindow.FontSize++;
}
private void mnuDecreaseFontSize_Click(object sender, EventArgs e)
{
_lastCodeWindow.FontSize--;
}
private void mnuResetFontSize_Click(object sender, EventArgs e)
{
_lastCodeWindow.FontSize = 13;
}
}
}