Skip to content

Commit

Permalink
Merge pull request #1 from rbergen/inline-source
Browse files Browse the repository at this point in the history
Inline source view
  • Loading branch information
rbergen authored Apr 18, 2021
2 parents 40d3c62 + 3210f48 commit 22f8718
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 172 deletions.
Binary file added img/Code_16x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/MixAssembler/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace MixAssembler
public static class Parser
{
public const int FieldSpacing = 2;
public const int MinAddressLength = 20;
public const int MinLocLength = 10;
public const int MinAddressLength = 10;
public const int MinLocLength = 8;
public const int MinOpLength = 4;

private const int LocFieldIndex = 0;
Expand Down
25 changes: 22 additions & 3 deletions src/MixEmul/Components/InstructionInstanceTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class InstructionInstanceTextBox : RichTextBox, IWordEditor, IEscapeConsu
private bool _updating;
private string _lastRenderedSourceLine;
private string _caption;

private bool _showShourceLineToolTip;
private bool _lastRenderedShowSourceLineToolTip;
private readonly ToolStripMenuItem _showAddressMenuItem;
private readonly ToolStripMenuItem _showIndexedAddressMenuItem;
private readonly ContextMenuStrip _contextMenu;
Expand All @@ -48,6 +49,7 @@ public class InstructionInstanceTextBox : RichTextBox, IWordEditor, IEscapeConsu
public SymbolCollection Symbols { get; set; }
public int MemoryAddress { get; set; }


public event WordEditorValueChangedEventHandler ValueChanged;
public event AddressSelectedHandler AddressSelected;

Expand Down Expand Up @@ -82,10 +84,25 @@ public InstructionInstanceTextBox(IFullWord instructionWord = null)
_lastRenderedSign = Word.Signs.Positive;
_lastRenderedSourceLine = null;
_noInstructionRendered = true;
_showShourceLineToolTip = true;

Update();
}

public bool ShowSourceLineToolTip
{
get => _showShourceLineToolTip;
set
{
if (_showShourceLineToolTip == value)
return;

_showShourceLineToolTip = value;
Update();
}
}


public Control EditorControl
=> this;

Expand Down Expand Up @@ -388,7 +405,8 @@ private void HandleNoInstruction(string caption)

if (_editMode || (_lastRenderedMagnitude == _instructionWord.MagnitudeLongValue
&& _lastRenderedSign == _instructionWord.Sign
&& _lastRenderedSourceLine == sourceLine))
&& _lastRenderedSourceLine == sourceLine
&& _lastRenderedShowSourceLineToolTip == _showShourceLineToolTip))
{
return;
}
Expand All @@ -402,7 +420,8 @@ private void HandleNoInstruction(string caption)
_lastRenderedSourceLine = sourceLine;
BackColor = _lastRenderedSourceLine != null ? _loadedInstructionBackgroundColor : _editorBackgroundColor;

string sourceCaption = _lastRenderedSourceLine != null ? "Original source: " + _lastRenderedSourceLine : null;
_lastRenderedShowSourceLineToolTip = _showShourceLineToolTip;
string sourceCaption = _lastRenderedShowSourceLineToolTip && _lastRenderedSourceLine != null ? "Original source: " + _lastRenderedSourceLine : null;

_lastRenderedMagnitude = _instructionWord.MagnitudeLongValue;
_lastRenderedSign = _instructionWord.Sign;
Expand Down
93 changes: 85 additions & 8 deletions src/MixEmul/Components/MemoryWordEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ public class MemoryWordEditor : UserControl, IWordEditor, INavigableControl
private readonly CheckBox _breakPointBox;
private readonly Label _colonLabel;
private readonly Label _colonLabel2;
private readonly Label _colonLabel3;
private readonly InstructionInstanceTextBox _instructionTextBox;
private readonly FullWordEditor _fullWordEditor;
private bool _marked;
private IMemoryFullWord _memoryWord;
private bool _readOnly;
private readonly Label _equalsLabel;
private readonly Label _profileLabel;
private readonly Label _sourceLineLabel;
private GetMaxProfilingCountCallback _getMaxProfilingCount;
private ToolTip _toolTip;

public event EventHandler AddressDoubleClick;
public event EventHandler BreakpointCheckedChanged;
Expand All @@ -51,12 +54,15 @@ public MemoryWordEditor(IMemoryFullWord memoryWord = null)
_colonLabel = new Label();
_equalsLabel = new Label();
_colonLabel = new Label();
_colonLabel3 = new Label();
_sourceLineLabel = new Label();
_colonLabel2 = new Label();
_profileLabel = new Label();
InitializeComponent();

MemoryWord = memoryWord;

UpdateShowSourceInlineLayout();
UpdateProfilingLayout();
}

Expand Down Expand Up @@ -172,33 +178,52 @@ private void InitializeComponent()
_instructionTextBox.Location = new Point(0, 0);
_instructionTextBox.Multiline = false;
_instructionTextBox.Name = "mInstructionTextBox";
_instructionTextBox.Size = new Size(128, 21);
_instructionTextBox.Size = new Size(39, 21);
_instructionTextBox.TabIndex = 0;
_instructionTextBox.KeyDown += This_KeyDown;
_instructionTextBox.ValueChanged += InstructionTextBox_ValueChanged;
_instructionTextBox.AddressSelected += InstructionTextBox_AddressSelected;
_instructionTextBox.MouseWheel += InstructionTextBox_MouseWheel;

_instructionPanel.Controls.Add(_instructionTextBox);
_instructionPanel.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
_instructionPanel.Anchor = AnchorStyles.Left | AnchorStyles.Top;
_instructionPanel.Location = new Point(_equalsLabel.Right, _fullWordEditor.Top);
_instructionPanel.Size = new Size(_instructionTextBox.Width, 21);
_instructionPanel.TabIndex = 4;
_instructionPanel.BorderStyle = BorderStyle.FixedSingle;

_colonLabel2.Location = new Point(_instructionPanel.Right, _addressPanel.Top + 3);
_colonLabel3.Location = new Point(_instructionPanel.Right, _addressPanel.Top + 3);
_colonLabel3.Anchor = AnchorStyles.Top;
_colonLabel3.Name = "mColonLabel3";
_colonLabel3.Size = new Size(10, _addressLabel.Height - 3);
_colonLabel3.TabIndex = 5;
_colonLabel3.Text = "<";
_colonLabel3.TextAlign = ContentAlignment.MiddleCenter;

_sourceLineLabel.Anchor = AnchorStyles.Right | AnchorStyles.Top;
_sourceLineLabel.Location = new Point(_colonLabel3.Right, _instructionPanel.Top);
_sourceLineLabel.Size = new Size(79, _instructionPanel.Height);
_sourceLineLabel.Name = "mSourceLineLabel";
_sourceLineLabel.TabIndex = 6;
_sourceLineLabel.Font = GuiSettings.GetFont(GuiSettings.FixedWidth);
_sourceLineLabel.Text = string.Empty;
_sourceLineLabel.TextAlign = ContentAlignment.MiddleLeft;
_sourceLineLabel.BorderStyle = BorderStyle.FixedSingle;
_sourceLineLabel.AutoEllipsis = true;

_colonLabel2.Location = new Point(_sourceLineLabel.Right, _addressPanel.Top + 3);
_colonLabel2.Anchor = AnchorStyles.Top | AnchorStyles.Right;
_colonLabel2.Name = "mColonLabel2";
_colonLabel2.Size = new Size(10, _addressLabel.Height - 3);
_colonLabel2.TabIndex = 5;
_colonLabel2.TabIndex = 7;
_colonLabel2.Text = "x";
_colonLabel2.TextAlign = ContentAlignment.MiddleCenter;

_profileLabel.Anchor = AnchorStyles.Right | AnchorStyles.Top;
_profileLabel.Location = new Point(_colonLabel2.Right, _instructionPanel.Top);
_profileLabel.Size = new Size(64, _instructionPanel.Height);
_profileLabel.Name = "mProfileLabel";
_profileLabel.TabIndex = 6;
_profileLabel.TabIndex = 8;
_profileLabel.Text = "0";
_profileLabel.TextAlign = ContentAlignment.MiddleRight;
_profileLabel.BorderStyle = BorderStyle.FixedSingle;
Expand All @@ -208,16 +233,42 @@ private void InitializeComponent()
Controls.Add(_fullWordEditor);
Controls.Add(_equalsLabel);
Controls.Add(_instructionPanel);
Controls.Add(_colonLabel3);
Controls.Add(_sourceLineLabel);
Controls.Add(_colonLabel2);
Controls.Add(_profileLabel);
Name = "MemoryWordEditor";
Size = new Size(_profileLabel.Right + 2, _instructionPanel.Height + 3);
KeyDown += This_KeyDown;
Layout += This_Layout;

_addressPanel.ResumeLayout(false);
ResumeLayout(false);
}

private void This_Layout(object sender, LayoutEventArgs e)
{

int sourceWidth = Width - (_addressPanel.Width + _colonLabel.Width + _fullWordEditor.Width + _equalsLabel.Width + 2);
if (ExecutionSettings.ProfilingEnabled)
sourceWidth -= _colonLabel2.Width + _profileLabel.Width;

if (!GuiSettings.ShowSourceInline)
{
_instructionPanel.Width = sourceWidth;
return;
}

_instructionPanel.Width = (sourceWidth - _colonLabel3.Width) / 3;
_colonLabel3.Left = _instructionPanel.Right;
_sourceLineLabel.Left = _colonLabel3.Right;
_sourceLineLabel.Width = sourceWidth - (_colonLabel3.Width + _instructionPanel.Width);
SetSourceLineLabelToolTip();
}

private void SetSourceLineLabelToolTip()
=> _toolTip?.SetToolTip(_sourceLineLabel, _sourceLineLabel.PreferredWidth > _sourceLineLabel.Width && !string.IsNullOrEmpty(_memoryWord.SourceLine) ? _memoryWord.SourceLine : null);

private static Color Interpolate(Color color1, Color color2, double fraction)
{
var r = RoundForArgb(Interpolate(color1.R, color2.R, fraction));
Expand Down Expand Up @@ -245,6 +296,26 @@ private void UpdateProfilingCount()
}
}

private void UpdateShowSourceInlineLayout()
{
if (_sourceLineLabel.Visible == GuiSettings.ShowSourceInline)
return;

if (!GuiSettings.ShowSourceInline)
{
_colonLabel3.Visible = false;
_sourceLineLabel.Visible = false;
_instructionTextBox.ShowSourceLineToolTip = true;
}
else
{
_colonLabel3.Visible = true;
_sourceLineLabel.Visible = true;
_instructionTextBox.ShowSourceLineToolTip = false;
}
}


private void UpdateProfilingLayout()
{
if (ExecutionSettings.ProfilingEnabled)
Expand All @@ -255,7 +326,6 @@ private void UpdateProfilingLayout()

if (!ExecutionSettings.ProfilingEnabled)
{
_instructionPanel.Width += _colonLabel2.Width + _profileLabel.Width;
_colonLabel2.Visible = false;
_profileLabel.Visible = false;
_profileLabel.Enabled = false;
Expand All @@ -265,7 +335,6 @@ private void UpdateProfilingLayout()
_colonLabel2.Visible = true;
_profileLabel.Visible = true;
_profileLabel.Enabled = true;
_instructionPanel.Width -= _colonLabel2.Width + _profileLabel.Width;
}
}

Expand Down Expand Up @@ -366,6 +435,7 @@ public void UpdateLayout()
_fullWordEditor.UpdateLayout();
_instructionTextBox.UpdateLayout();

UpdateShowSourceInlineLayout();
UpdateProfilingLayout();
}

Expand Down Expand Up @@ -412,6 +482,9 @@ public IMemoryFullWord MemoryWord
_instructionTextBox.MemoryAddress = _memoryWord.Index;
_fullWordEditor.WordValue = _memoryWord;
_instructionTextBox.InstructionWord = _memoryWord;
_sourceLineLabel.Text = _memoryWord.SourceLine ?? string.Empty;

SetSourceLineLabelToolTip();

if (_profileLabel.Enabled)
UpdateProfilingCount();
Expand Down Expand Up @@ -440,7 +513,11 @@ public SymbolCollection Symbols

public ToolTip ToolTip
{
set => _instructionTextBox.ToolTip = value;
set
{
_toolTip = value;
_instructionTextBox.ToolTip = _toolTip;
}
}

public IWord WordValue
Expand Down
Loading

0 comments on commit 22f8718

Please sign in to comment.