Debugger: Fixed minor UI issues with hex view in header editor

This commit is contained in:
Sour 2018-02-24 14:56:22 -05:00
parent 287479c694
commit 522eccc710
3 changed files with 93 additions and 89 deletions

View file

@ -2619,96 +2619,94 @@ namespace Be.Windows.Forms
stringToDisplay = string.Empty;
};
using(Brush selBrushBack = new SolidBrush(_selectionBackColor)) {
for(long i = startByte; i < intern_endByte + 1; i++) {
Color byteColor = defaultForeColor;
Color bgColor = Color.Transparent;
bool isSelectedByte = i >= _bytePos && i <= (_bytePos + _selectionLength - 1) && _selectionLength != 0;
if(this.ByteColorProvider != null) {
byteColor = this.ByteColorProvider.GetByteColor(_startByte, i, out bgColor);
}
counter++;
Point currentPoint = GetGridBytePoint(counter);
bool lineChanged = false;
if(yPrevious != currentPoint.Y) {
if(_xPosList.ContainsKey(yPrevious)) {
_xPosList[yPrevious].Add(xPrevious);
}
_xPosList[currentPoint.Y] = new List<float>();
_lineWidthCache[yPrevious] = _recStringView.Width + xOffset;
xOffset = 0;
yPrevious = currentPoint.Y;
lineChanged = true;
}
if(forceDraw || lineChanged || byteColor != prevByteColor || bgColor != prevBgColor || prevSelected != isSelectedByte) {
outputHex(prevByteColor, prevSelected ? _selectionBackColor : prevBgColor);
gridPoint = GetGridBytePoint(counter);
prevXOffset = xOffset;
forceDraw = false;
}
byte b = _byteProvider.ReadByte(i);
bytesToDisplay.Add(b);
prevSelected = isSelectedByte;
prevBgColor = bgColor;
prevByteColor = byteColor;
if(!_stringViewVisible) {
continue;
}
string s;
if(skipCount > 0) {
skipCount--;
s = "";
} else {
long len = _byteProvider.Length;
UInt64 tblValue = (UInt64)b;
for(int j = 1; j < 8; j++) {
if(len > i + j) {
tblValue += (UInt64)_byteProvider.ReadByte(i + j) << (8 * j);
}
}
int keyLength;
s = ByteCharConverter.ToChar(tblValue, out keyLength);
skipCount = keyLength - 1;
}
float width;
if(!_measureCache.TryGetValue(s, out width)) {
width = g.MeasureString(s, Font, 1000, _stringFormat).Width;
_measureCache[s] = width;
}
PointF byteStringPointF = GetByteStringPointF(currentPoint, false);
float xPos = byteStringPointF.X + xOffset;
if(currentPoint.Y < 150) {
_xPosCache[currentPoint.Y * 64 + currentPoint.X] = xPos;
}
_xPosList[currentPoint.Y].Add(xPos);
if(currentPoint == caretPoint) {
caretWidth = width;
}
stringToDisplay += s;
if(s.Length > 1 || s.Length > 0 && s[0] > 127 || s[0] < 32) {
//Force draw if we hit a non-ascii character (to avoid minor positioning issues)
forceDraw = true;
}
xOffset += width - _charSize.Width;
xPrevious = xPos + width;
for(long i = startByte; i < intern_endByte + 1; i++) {
Color byteColor = defaultForeColor;
Color bgColor = Color.Transparent;
bool isSelectedByte = i >= _bytePos && i <= (_bytePos + _selectionLength - 1) && _selectionLength != 0;
if(this.ByteColorProvider != null) {
byteColor = this.ByteColorProvider.GetByteColor(_startByte, i, out bgColor);
}
counter++;
Point currentPoint = GetGridBytePoint(counter);
bool lineChanged = false;
if(yPrevious != currentPoint.Y) {
if(_xPosList.ContainsKey(yPrevious)) {
_xPosList[yPrevious].Add(xPrevious);
}
_xPosList[currentPoint.Y] = new List<float>();
_lineWidthCache[yPrevious] = _recStringView.Width + xOffset;
xOffset = 0;
yPrevious = currentPoint.Y;
lineChanged = true;
}
if(forceDraw || lineChanged || byteColor != prevByteColor || bgColor != prevBgColor || prevSelected != isSelectedByte) {
outputHex(this.ByteColorProvider != null ? prevByteColor : (prevSelected ? _selectionForeColor : defaultForeColor), prevSelected ? _selectionBackColor : prevBgColor);
gridPoint = GetGridBytePoint(counter);
prevXOffset = xOffset;
forceDraw = false;
}
byte b = _byteProvider.ReadByte(i);
bytesToDisplay.Add(b);
prevSelected = isSelectedByte;
prevBgColor = bgColor;
prevByteColor = byteColor;
if(!_stringViewVisible) {
continue;
}
string s;
if(skipCount > 0) {
skipCount--;
s = "";
} else {
long len = _byteProvider.Length;
UInt64 tblValue = (UInt64)b;
for(int j = 1; j < 8; j++) {
if(len > i + j) {
tblValue += (UInt64)_byteProvider.ReadByte(i + j) << (8 * j);
}
}
int keyLength;
s = ByteCharConverter.ToChar(tblValue, out keyLength);
skipCount = keyLength - 1;
}
float width;
if(!_measureCache.TryGetValue(s, out width)) {
width = g.MeasureString(s, Font, 1000, _stringFormat).Width;
_measureCache[s] = width;
}
PointF byteStringPointF = GetByteStringPointF(currentPoint, false);
float xPos = byteStringPointF.X + xOffset;
if(currentPoint.Y < 150) {
_xPosCache[currentPoint.Y * 64 + currentPoint.X] = xPos;
}
_xPosList[currentPoint.Y].Add(xPos);
if(currentPoint == caretPoint) {
caretWidth = width;
}
stringToDisplay += s;
if(s.Length > 1 || s.Length > 0 && s[0] > 127 || s[0] < 32) {
//Force draw if we hit a non-ascii character (to avoid minor positioning issues)
forceDraw = true;
}
xOffset += width - _charSize.Width;
xPrevious = xPos + width;
}
outputHex(prevByteColor, prevBgColor);
outputHex(this.ByteColorProvider != null ? prevByteColor : (prevSelected ? _selectionForeColor : defaultForeColor), prevSelected ? _selectionBackColor : prevBgColor);
}
float GetLineWidth(int y)
@ -2918,7 +2916,7 @@ namespace Be.Windows.Forms
RequiredWidth = requiredWidth;
int vmax = (int)Math.Floor((double)_recHex.Height / (double)_charSize.Height);
SetVerticalByteCount(vmax);
SetVerticalByteCount(vmax > 0 ? vmax : 1);
_iHexMaxBytes = _iHexMaxHBytes * _iHexMaxVBytes;

View file

@ -376,11 +376,14 @@
this.hexBox.ByteColorProvider = null;
this.tableLayoutPanel1.SetColumnSpan(this.hexBox, 3);
this.hexBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.hexBox.EnablePerByteNavigation = false;
this.hexBox.Font = new System.Drawing.Font("Segoe UI", 9F);
this.hexBox.HighDensityMode = false;
this.hexBox.InfoBackColor = System.Drawing.Color.DarkGray;
this.hexBox.Location = new System.Drawing.Point(86, 196);
this.hexBox.Name = "hexBox";
this.hexBox.ReadOnly = true;
this.hexBox.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
this.hexBox.ShadowSelectionColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(60)))), ((int)(((byte)(188)))), ((int)(((byte)(255)))));
this.hexBox.Size = new System.Drawing.Size(402, 18);
this.hexBox.TabIndex = 26;

View file

@ -9,6 +9,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Be.Windows.Forms;
using Mesen.GUI.Controls;
using Mesen.GUI.Forms;
namespace Mesen.GUI.Debugger
@ -19,6 +20,8 @@ namespace Mesen.GUI.Debugger
{
InitializeComponent();
this.hexBox.Font = new Font(BaseControl.MonospaceFontFamily, 10, FontStyle.Regular);
NesHeader header = NesHeader.FromBytes(InteropEmu.DebugGetNesHeader());
Entity = header;