diff --git a/CSim.csproj b/CSim.csproj index 3aaa695..e5a2656 100644 --- a/CSim.csproj +++ b/CSim.csproj @@ -219,7 +219,10 @@ - + + + + diff --git a/Core/AppInfo.cs b/Core/AppInfo.cs index 6eb986b..3623c60 100644 --- a/Core/AppInfo.cs +++ b/Core/AppInfo.cs @@ -9,7 +9,7 @@ public static class AppInfo /// Author of the app. public const string Author = "jbgarcia@uvigo.es"; /// Version of the app. - public const string Version = "1.4 20170401"; + public const string Version = "1.5 20170711"; /// Website for this app. public const string Web = "http://webs.uvigo.es/jbgarcia/prys/csim/"; /// Extension for files created by this app. diff --git a/Core/ExtensionMethods.cs b/Core/ExtensionMethods.cs index 78a330d..0aa585d 100644 --- a/Core/ExtensionMethods.cs +++ b/Core/ExtensionMethods.cs @@ -80,6 +80,58 @@ public static BigInteger ToBigInteger(this object value) return toret; } + /// + /// Tries to convert anything to a double, without exceptions, + /// unless impossible. + /// + /// The double value. + /// A primitive, probably boxed. + public static double ToDouble(this object value) + { + double toret = 0.0; + + if ( value == null ) { + throw new ArgumentException( "trying to convert null to double" ); + } + + if ( value is float + || value is double ) + { + toret = (double) value; + } + else + if ( value is sbyte + || value is byte + || value is short + || value is ushort + || value is int + || value is uint + || value is long + || value is ulong ) + { + toret = Convert.ToDouble( value ); + } + else + if ( value is BigInteger ) { + toret = ( (double) ( (BigInteger) value ) ); + } else { + throw new ArgumentException( "cannot convert to double from: " + value.GetType() ); + } + + return toret; + } + + /// + /// Tries to convert anything to a float, without exceptions, + /// unless impossible. + /// + /// The float value. + /// A primitive, probably boxed. + public static float ToFloat(this object value) + { + return (float) value.ToDouble(); + } + /// /// Converts a to a byte. /// Overflow is allowed, so for example from a 128bit value diff --git a/Core/Literals/DoubleLiteral.cs b/Core/Literals/DoubleLiteral.cs index 18f7d32..4381e37 100644 --- a/Core/Literals/DoubleLiteral.cs +++ b/Core/Literals/DoubleLiteral.cs @@ -13,7 +13,7 @@ public class DoubleLiteral: Literal { /// The . /// A given double. public DoubleLiteral(Machine m, object x) - :this( m, System.Convert.ToDouble( x ) ) + :this( m, x.ToDouble() ) { } diff --git a/Core/Literals/FloatLiteral.cs b/Core/Literals/FloatLiteral.cs index 1fd7e80..7ba0606 100644 --- a/Core/Literals/FloatLiteral.cs +++ b/Core/Literals/FloatLiteral.cs @@ -14,7 +14,7 @@ public class FloatLiteral: Literal { /// The . /// A given double. public FloatLiteral(Machine m, object x) - :this( m, System.Convert.ToSingle( x ) ) + :this( m, x.ToFloat() ) { } diff --git a/Core/Native/Int128.cs b/Core/Native/Int128.cs index 755168b..e5f8524 100644 --- a/Core/Native/Int128.cs +++ b/Core/Native/Int128.cs @@ -2,9 +2,9 @@ // Int128.cs // // Author: -// Simon Mourier +// Simon Mourier // Adapted by: -// baltasarq +// baltasarq // // Copyright (c) 2017 baltasarq // @@ -30,6 +30,7 @@ namespace CSim.Core { using System; using System.Numerics; + /// Represents 64 bits integer values. public struct Int128 { /// The length in bytes for this integer's /// binary representation. @@ -129,12 +130,14 @@ public Int128(BigInteger value) { } + /// Gets the value as a . public BigInteger Value { get { return new BigInteger(); } } + /// Gets the representation in bytes. public byte[] Bytes { get { return this.Value.ToByteArray(); diff --git a/Res/appIcon.ico b/Res/appIcon.ico index 31f3454..3fe15f3 100644 Binary files a/Res/appIcon.ico and b/Res/appIcon.ico differ diff --git a/Res/appIcon.png b/Res/appIcon.png index eebc48b..3fbf17c 100644 Binary files a/Res/appIcon.png and b/Res/appIcon.png differ diff --git a/Res/back.png b/Res/back.png index cb01024..3574b32 100644 Binary files a/Res/back.png and b/Res/back.png differ diff --git a/Res/dec.png b/Res/dec.png index 405869b..2e50217 100644 Binary files a/Res/dec.png and b/Res/dec.png differ diff --git a/Res/diagram.png b/Res/diagram.png index 84f525a..dc0da8a 100644 Binary files a/Res/diagram.png and b/Res/diagram.png differ diff --git a/Res/help.png b/Res/help.png index 88ef2a8..52f1e4e 100644 Binary files a/Res/help.png and b/Res/help.png differ diff --git a/Res/hex.png b/Res/hex.png index 1590bd9..63c6ceb 100644 Binary files a/Res/hex.png and b/Res/hex.png differ diff --git a/Res/info.png b/Res/info.png index 1132ced..6685456 100644 Binary files a/Res/info.png and b/Res/info.png differ diff --git a/Res/memory.png b/Res/memory.png index 23c2bd9..32fce40 100644 Binary files a/Res/memory.png and b/Res/memory.png differ diff --git a/Res/open.png b/Res/open.png index c657c69..aa9b76a 100644 Binary files a/Res/open.png and b/Res/open.png differ diff --git a/Res/play.png b/Res/play.png index 8ce4797..2021c49 100644 Binary files a/Res/play.png and b/Res/play.png differ diff --git a/Res/question.png b/Res/question.png new file mode 100644 index 0000000..418d728 Binary files /dev/null and b/Res/question.png differ diff --git a/Res/random.png b/Res/random.png index e86ae65..c014210 100644 Binary files a/Res/random.png and b/Res/random.png differ diff --git a/Res/reset.png b/Res/reset.png index ac80082..6d0c170 100644 Binary files a/Res/reset.png and b/Res/reset.png differ diff --git a/Res/save.png b/Res/save.png index 2711576..697ee40 100644 Binary files a/Res/save.png and b/Res/save.png differ diff --git a/Res/settings.png b/Res/settings.png index fa7b456..ab754a4 100644 Binary files a/Res/settings.png and b/Res/settings.png differ diff --git a/Res/stop.png b/Res/stop.png index 3fa205a..addb5d6 100644 Binary files a/Res/stop.png and b/Res/stop.png differ diff --git a/Res/zero.png b/Res/zero.png index e2f9ae7..ae30974 100644 Binary files a/Res/zero.png and b/Res/zero.png differ diff --git a/Res/zoom_in.png b/Res/zoom_in.png index 315c8cc..4dd48c3 100644 Binary files a/Res/zoom_in.png and b/Res/zoom_in.png differ diff --git a/Res/zoom_out.png b/Res/zoom_out.png index 78bae47..c010491 100644 Binary files a/Res/zoom_out.png and b/Res/zoom_out.png differ diff --git a/Ui/MainWindow.cs b/Ui/MainWindow.cs index e32b7f8..e117f6c 100644 --- a/Ui/MainWindow.cs +++ b/Ui/MainWindow.cs @@ -333,8 +333,7 @@ private void ShowSettings() // UI this.tbIconBar.Hide(); - this.pnlMain.Hide(); - this.pnlIO.Hide(); + this.splMain.Hide(); this.pnlSettings.Show(); this.cbLocales.Focus(); this.SetStatus( L18n.Get( L18n.Id.ActSettings ) ); @@ -395,8 +394,7 @@ private void ApplySettings() this.UpdateView(); this.pnlSettings.Hide(); this.tbIconBar.Show(); - this.pnlMain.Show(); - this.pnlIO.Show(); + this.splMain.Show(); this.SetStatus(); this.FocusOnInput(); } @@ -416,14 +414,14 @@ private void DoReset() private void DoOpen() { - var dlg = new OpenFileDialog(); + var dlg = new OpenFileDialog() { + Title = "Load session", + Filter = AppInfo.Name + "|*." + AppInfo.FileExt + "|*|*.*", + CheckFileExists = true, + FileName = Path.GetFullPath( CurrentDir ) + }; - dlg.Title = "Load session"; - dlg.Filter = AppInfo.Name + "|*." + AppInfo.FileExt + "|*|*.*"; - dlg.CheckFileExists = true; - dlg.FileName = Path.GetFullPath( CurrentDir ); - - this.SetStatus(); + this.SetStatus(); if ( dlg.ShowDialog() == DialogResult.OK ) { this.DoReset(); @@ -451,13 +449,13 @@ private void DoOpen() private void DoSave() { - var dlg = new SaveFileDialog(); + var dlg = new SaveFileDialog() { + Title = "Save session", + Filter = AppInfo.Name + "|*." + AppInfo.FileExt + "|*|*.*", + FileName = Path.GetFullPath( CurrentDir ) + }; - dlg.Title = "Save session"; - dlg.Filter = AppInfo.Name + "|*." + AppInfo.FileExt + "|*|*.*"; - dlg.FileName = Path.GetFullPath( CurrentDir ); - - if ( dlg.ShowDialog() == DialogResult.OK ) { + if ( dlg.ShowDialog() == DialogResult.OK ) { using( var writer = new StreamWriter( dlg.FileName, false ) ) { foreach(string s in this.lbHistory.Items) { @@ -512,15 +510,18 @@ private void UpdateWatches() if ( !string.IsNullOrEmpty( input ) ) { try { - result = this.machine.Execute( new ExpressionParser( input, this.machine ) ); + result = this.machine.Execute( + new ExpressionParser( input, this.machine ) ); // Update output - lblWatch.ForeColor = Color.Navy; + lblWatch.ForeColor = SystemColors.InfoText; + lblWatch.BackColor = SystemColors.Info; lblWatch.Text = result.Value.ToString(); } catch(EngineException) { - lblWatch.ForeColor = Color.DarkRed; + lblWatch.ForeColor = SystemColors.GrayText; + lblWatch.BackColor = SystemColors.Window; lblWatch.Text = "ERROR"; } } @@ -538,7 +539,7 @@ private void UpdateSymbolTable() if ( vble is TempVariable ) { continue; } - + string varTypeAddr = vble.Type.Name + " :" + vble.Type.Size + " [" + FromIntToPrettyHex( vble.Address, this.machine.WordSize ) @@ -591,6 +592,19 @@ private int CharWidth return this.charWidth; } } + + private int CharHeight + { + get { + if ( this.charHeight == -1 ) { + Graphics grf = this.CreateGraphics(); + SizeF fontSize = grf.MeasureString( "H", this.Font ); + this.charHeight = (int) fontSize.Height +5; + } + + return this.charHeight; + } + } private void DoDrawing() { @@ -750,6 +764,11 @@ private void Execute(string input) { this.PrintError( exc.Message ); } + #if !DEBUG + catch(Exception exc) { + this.PrintError( "ERROR (internal): " + exc.Message ); + } + #endif finally { this.UpdateView(); } @@ -762,43 +781,20 @@ private void ChangeUILanguage(CultureInfo locale) L18n.SetLanguage( locale ); // Toolbar buttons - ToolBar.ToolBarButtonCollection tbButtons = this.tbIconBar.Buttons; - for(int i = 0; i < tbButtons.Count; ++i) { - ToolBarButton button = tbButtons[ i ]; - - switch( i ) { - case 0: button.ToolTipText = L18n.Get( L18n.Id.ActReset ); - break; - case 1: button.ToolTipText = L18n.Get( L18n.Id.ActOpen ); - break; - case 2: button.ToolTipText = L18n.Get( L18n.Id.ActSave ); - break; - case 3: button.ToolTipText = L18n.Get( L18n.Id.ActInHex ); - break; - case 4: button.ToolTipText = L18n.Get( L18n.Id.ActInDec ); - break; - case 5: button.ToolTipText = L18n.Get( L18n.Id.ActZoomIn ); - break; - case 6: button.ToolTipText = L18n.Get( L18n.Id.ActZoomOut ); - break; - case 7: button.ToolTipText = L18n.Get( L18n.Id.ActShowMemory ); - break; - case 8: button.ToolTipText = L18n.Get( L18n.Id.ActShowDiagram ); - break; - case 9: button.ToolTipText = L18n.Get( L18n.Id.ActSettings ); - break; - case 10: button.ToolTipText = L18n.Get( L18n.Id.ActHelp ); - break; - case 11: button.ToolTipText = L18n.Get( L18n.Id.ActAbout ); - break; - case 12: button.ToolTipText = L18n.Get( L18n.Id.ActPlay ); - break; - case 13: button.ToolTipText = L18n.Get( L18n.Id.ActStop ); - break; - default: - throw new ArgumentException( "unexpected toolbar button: unhandled" ); - } - } + this.tbbReset.ToolTipText = L18n.Get( L18n.Id.ActReset ); + this.tbbOpen.ToolTipText = L18n.Get( L18n.Id.ActOpen ); + this.tbbSave.ToolTipText = L18n.Get( L18n.Id.ActSave ); + this.tbbHex.ToolTipText = L18n.Get( L18n.Id.ActInHex ); + this.tbbDec.ToolTipText = L18n.Get( L18n.Id.ActInDec ); + this.tbbZoomIn.ToolTipText = L18n.Get( L18n.Id.ActZoomIn ); + this.tbbZoomOut.ToolTipText = L18n.Get( L18n.Id.ActZoomOut ); + this.tbbMemory.ToolTipText = L18n.Get( L18n.Id.ActShowMemory ); + this.tbbDiagram.ToolTipText = L18n.Get( L18n.Id.ActShowDiagram ); + this.tbbStop.ToolTipText = L18n.Get( L18n.Id.ActStop ); + this.tbbPlay.ToolTipText = L18n.Get( L18n.Id.ActPlay ); + this.tbbSettings.ToolTipText = L18n.Get( L18n.Id.ActSettings ); + this.tbbHelp.ToolTipText = L18n.Get( L18n.Id.ActHelp ); + this.tbbAbout.ToolTipText = L18n.Get( L18n.Id.ActAbout ); // Tabbed panel this.tcTabs.TabPages[ 0 ].Text = L18n.Get( L18n.Id.ActShowMemory ); @@ -820,6 +816,7 @@ private static string FromIntToPrettyHex(BigInteger value, int wordSize = 1) private bool doNotApplySnapshot; private int charWidth = -1; + private int charHeight = -1; private Machine machine; private SchemaDrawer sdDrawingBoard; private string cfgFile = ""; diff --git a/Ui/MainWindowView.cs b/Ui/MainWindowView.cs index 56084eb..d904b1a 100644 --- a/Ui/MainWindowView.cs +++ b/Ui/MainWindowView.cs @@ -1,519 +1,599 @@  namespace CSim.Ui { - using System; - using System.Globalization; - using System.Drawing; - using System.Windows.Forms; - - using CSim.Core; - - /// The main window for the application. This builds the view. - public partial class MainWindow { - - private void BuildInputPanel() - { - // Line input - this.edInput = new ComboBox(); - this.edInput.Dock = DockStyle.Bottom; - this.edInput.Font = this.baseFont; - this.edInput.KeyDown += (o, e) => { - if ( e.KeyCode == Keys.Enter ) { - this.DoInput(); - e.Handled = true; - e.SuppressKeyPress = true; - } - }; - - this.pnlIO.Controls.Add( this.edInput ); - } - - private void BuildWatchesView() - { - this.lblWatchesValue = new Label[ NumWatches ]; - this.edWatchesLabel = new TextBox[ NumWatches ]; - - for(int i = 0; i < NumWatches; ++i) { - var lblWatch = this.lblWatchesValue[ i ] = new Label { Text = "0", Dock = DockStyle.Right }; - var edWatch = this.edWatchesLabel[ i ] = new TextBox { Dock = DockStyle.Fill }; - - lblWatch.Font = new Font( FontFamily.GenericMonospace, 11 ); - - edWatch.LostFocus += (obj, args) => this.UpdateWatches(); - lblWatch.Font = new Font( FontFamily.GenericMonospace, 11 ); - } - - return; - } - - private void BuildWatchesPanel() - { - this.BuildWatchesView(); - this.gbWatches = new GroupBox { Text = "Watches", Dock = DockStyle.Fill }; - this.pnlWatches = new TableLayoutPanel { Dock = DockStyle.Fill, AutoScroll = true }; - - for(int i = 0; i < NumWatches; ++i) { - var panel = new Panel { Dock = DockStyle.Top }; - panel.Controls.Add( this.edWatchesLabel[ i ] ); - panel.Controls.Add( this.lblWatchesValue[ i ] ); - this.pnlWatches.Controls.Add( panel ); - panel.MaximumSize = new Size( int.MaxValue, this.edWatchesLabel[ i ].Height ); - } - - this.gbWatches.Controls.Add( this.pnlWatches ); - this.splWatches.Panel2.Controls.Add( this.gbWatches ); - } - - private void BuildHistoryPanel() - { - this.lbHistory = new ListBox(); - this.lbHistory.Font = new Font( FontFamily.GenericMonospace, 8 ); - this.lbHistory.Dock = DockStyle.Fill; - this.gbHistory = new GroupBox { Text = "History", Dock = DockStyle.Fill }; - this.gbHistory.Controls.Add( this.lbHistory ); - this.splWatches.Panel1.Controls.Add( this.gbHistory ); - - this.lbHistory.SelectedIndexChanged += (o, e) => this.OnHistoryIndexChanged(); - } - - private void BuildMemoryViewPanel() - { - // Grid for memory - int columnWidth = ( this.CharWidth * 2 ); - this.grdMemory = new DataGridView(); - this.grdMemory.AllowUserToResizeRows = false; - this.grdMemory.AllowUserToAddRows = false; - this.grdMemory.RowHeadersVisible = false; - this.grdMemory.AutoGenerateColumns = false; - this.grdMemory.MultiSelect = false; - this.grdMemory.ShowCellToolTips = true; - - // Style for regular columns - var style = new DataGridViewCellStyle(); - style.Font = new Font( this.baseFont, FontStyle.Bold ); - style.BackColor = Color.AntiqueWhite; - style.ForeColor = Color.Black; - style.SelectionBackColor = Color.Black; - style.SelectionForeColor = Color.AntiqueWhite; - this.grdMemory.DefaultCellStyle = style; - - // Style for headers - var styleHeaders = new DataGridViewCellStyle(); - styleHeaders.BackColor = Color.Black; - styleHeaders.ForeColor = Color.White; - styleHeaders.Font = new Font( this.baseFont, FontStyle.Bold ); - this.grdMemory.ColumnHeadersDefaultCellStyle = styleHeaders; - - // Style for first column - var styleFirstColumn = new DataGridViewCellStyle(); - styleFirstColumn.Font = new Font( this.baseFont, FontStyle.Bold ); - styleFirstColumn.BackColor = Color.Black; - styleFirstColumn.ForeColor = Color.White; - - // Create columns - DataGridViewTextBoxColumn[] columns = new DataGridViewTextBoxColumn[ MaxDataColumns +1 ]; - - for(int i = 0; i < columns.Length; ++i) { - columns[ i ] = new DataGridViewTextBoxColumn(); - - if ( i == 0 ) { - columns[ i ].DefaultCellStyle = styleFirstColumn; - columns[ i ].HeaderText = "/"; - columns[ i ].Width = columnWidth + ( (int) ( columnWidth * 0.2 ) ); - } else { - columns[ i ].HeaderText = FromIntToHex( i - 1 ); - columns[ i ].Width = columnWidth; - } - - columns[ i ].SortMode = DataGridViewColumnSortMode.NotSortable; - columns[ i ].ReadOnly = true; - } - - this.grdMemory.Columns.AddRange( columns ); - - // Create rows - var rows = new DataGridViewRow[ (int) this.machine.Memory.Max / MaxDataColumns ]; - - for(int i = 0; i < rows.Length; ++i) { - rows[ i ] = new DataGridViewRow(); - } - - this.grdMemory.Rows.AddRange( rows ); - - this.grdMemory.Dock = DockStyle.Fill; - this.tcTabs.TabPages[ 0 ].Controls.Add( this.grdMemory ); - this.splHistory.SplitterDistance = this.CharWidth * 10; - } - - private void BuildSymbolTable() - { - // Symbol table - this.gbSymbols = new GroupBox { Text = "Symbols", Dock = DockStyle.Fill }; - this.tvSymbolTable = new TreeView(); - this.tvSymbolTable.Dock = DockStyle.Fill; - this.tvSymbolTable.Font = this.baseFont; - this.tvSymbolTable.PathSeparator = "."; - this.tvSymbolTable.AfterSelect += (sender, e) => this.DoTreeSelect(); - this.gbSymbols.Controls.Add( this.tvSymbolTable ); - this.splSymbolTable.Panel1.Controls.Add( this.gbSymbols ); - this.splSymbolTable.SplitterDistance = this.CharWidth; - } - - private void BuildAboutPanel() - { - // Panel for about info - this.pnlAbout = new Panel(); - this.pnlAbout.SuspendLayout(); - this.pnlAbout.Dock = DockStyle.Bottom; - this.pnlAbout.BackColor = Color.LightYellow; - var lblAbout = new Label(); - lblAbout.Text = AppInfo.Name + " v" + AppInfo.Version + ", " + AppInfo.Author; - lblAbout.Dock = DockStyle.Left; - lblAbout.TextAlign = ContentAlignment.MiddleCenter; - lblAbout.AutoSize = true; - var font = new Font( lblAbout.Font, FontStyle.Bold ); - font = new Font( font.FontFamily, 14 ); - lblAbout.Font = font; - var btCloseAboutPanel = new Button(); - btCloseAboutPanel.Text = "X"; - btCloseAboutPanel.Font = new Font( btCloseAboutPanel.Font, FontStyle.Bold ); - btCloseAboutPanel.Dock = DockStyle.Right; - btCloseAboutPanel.Width = this.CharWidth * 5; - btCloseAboutPanel.FlatStyle = FlatStyle.Flat; - btCloseAboutPanel.FlatAppearance.BorderSize = 0; - btCloseAboutPanel.Click += (obj, args) => this.pnlAbout.Hide(); - this.pnlAbout.Controls.Add( lblAbout ); - this.pnlAbout.Controls.Add( btCloseAboutPanel ); - this.pnlAbout.Hide(); - this.pnlAbout.MinimumSize = new Size( this.Width, lblAbout.Height +5 ); - this.pnlAbout.MaximumSize = new Size( Int32.MaxValue, lblAbout.Height +5 ); - this.pnlAbout.ResumeLayout(); - this.Controls.Add( this.pnlAbout ); - } - - private void BuildIcons() - { - var resourceAppIcon = System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.appIcon.png" ); - - // Prepare icons - if ( resourceAppIcon != null ) { - this.appIconBmp = new Bitmap( resourceAppIcon ); - this.Icon = Icon.FromHandle( this.appIconBmp.GetHicon() ); - - this.backIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.back.png" ) ); - - this.playIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.play.png" ) ); - - this.stopIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.stop.png" ) ); - - this.openIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.open.png" ) ); - - this.saveIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.save.png" ) ); - - this.resetIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.reset.png" ) ); - - this.zoomInIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.zoom_in.png" ) ); - - this.zoomOutIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.zoom_out.png" ) ); - - this.aboutIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.info.png" ) ); - - this.helpIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.help.png" ) ); - - this.memoryIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.memory.png" ) ); - - this.diagramIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.diagram.png" ) ); - - this.hexIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.hex.png" ) ); - - this.decIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.dec.png" ) ); - - this.zeroIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.zero.png" ) ); - - this.randIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.random.png" ) ); - - this.settingsIconBmp = new Bitmap( System.Reflection.Assembly. - GetEntryAssembly(). - GetManifestResourceStream( "CSim.Res.settings.png" ) ); - } - - return; - } - - private void BuildDrawingTab() - { - var scroll = new Panel(); - - this.pbCanvas = new PictureBox(); - this.pbCanvas.BackColor = Color.GhostWhite; - this.pbCanvas.ForeColor = Color.Navy; - this.pbCanvas.Anchor = AnchorStyles.Left | AnchorStyles.Top; - this.pbCanvas.SizeMode = PictureBoxSizeMode.AutoSize; - - scroll.Dock = DockStyle.Fill; - scroll.Controls.Add( this.pbCanvas ); - scroll.AutoScroll = true; - - this.tcTabs.TabPages[ 1 ].Controls.Add( scroll ); - this.sdDrawingBoard = new SchemaDrawer( this.machine ); - } - - private void BuildToolbar() - { - // Image list - var imgList = new ImageList(); - imgList.ImageSize = new System.Drawing.Size( 24, 24 ); - imgList.Images.AddRange( new Bitmap[] { - this.resetIconBmp, this.openIconBmp, - this.saveIconBmp, this.hexIconBmp, - this.decIconBmp, this.zoomInIconBmp, - this.zoomOutIconBmp, this.memoryIconBmp, - this.diagramIconBmp, this.helpIconBmp, - this.aboutIconBmp, this.settingsIconBmp, - this.playIconBmp, this.stopIconBmp - } ); - - // Toolbar - this.tbIconBar = new ToolBar(); - this.tbIconBar.AutoSize = true; - this.tbIconBar.Dock = DockStyle.Top; - this.tbIconBar.Appearance = ToolBarAppearance.Flat; - this.tbIconBar.BorderStyle = BorderStyle.None; - this.tbIconBar.ImageList = imgList; - this.tbIconBar.ShowToolTips = true; - - // Toolbar buttons - var tbbReset = new ToolBarButton(); - tbbReset.ImageIndex = 0; - tbbReset.Style = ToolBarButtonStyle.DropDownButton; - - var mniZero = new MenuItem( "Zero", (o, e) => DoReset() ); - mniZero.OwnerDraw = true; - mniZero.DrawItem += (o, e) => { - double factor = (double) e.Bounds.Height / this.zeroIconBmp.Height; - var rect = new Rectangle( e.Bounds.X, e.Bounds.Y, - (int) ( this.zeroIconBmp.Width * factor ), - (int) ( this.zeroIconBmp.Height * factor ) ); - e.Graphics.DrawImage( this.zeroIconBmp, rect ); - }; - - var mniRandom = new MenuItem( "Random", (o, e) => DoReset( MemoryManager.ResetType.Random ) ); - mniRandom.OwnerDraw = true; - mniRandom.DrawItem += (o, e) => { - double factor = (double) ( e.Bounds.Height ) / this.randIconBmp.Height; - var rect = new Rectangle( e.Bounds.X, e.Bounds.Y, - (int) ( this.randIconBmp.Width * factor ), - (int) ( this.randIconBmp.Height * factor ) ); - e.Graphics.DrawImage( this.randIconBmp, rect ); - }; - - tbbReset.DropDownMenu = new ContextMenu( new MenuItem[]{ - mniZero, mniRandom - }); - - var tbbOpen = new ToolBarButton(); - tbbOpen.ImageIndex = 1; - var tbbSave = new ToolBarButton(); - tbbSave.ImageIndex = 2; - var tbbHex = new ToolBarButton(); - tbbHex.ImageIndex = 3; - var tbbDec = new ToolBarButton(); - tbbDec.ImageIndex = 4; - var tbbZoomIn = new ToolBarButton(); - tbbZoomIn.ImageIndex = 5; - var tbbZoomOut = new ToolBarButton(); - tbbZoomOut.ImageIndex = 6; - var tbbMem = new ToolBarButton(); - tbbMem.ImageIndex = 7; - var tbbVisual = new ToolBarButton(); - tbbVisual.ImageIndex = 8; - var tbbHelp = new ToolBarButton(); - tbbHelp.ImageIndex = 9; - var tbbAbout = new ToolBarButton(); - tbbAbout.ImageIndex = 10; - var tbbSettings = new ToolBarButton(); - tbbSettings.ImageIndex = 11; - var tbbPlay = new ToolBarButton(); - tbbPlay.ImageIndex = 12; - this.tbbStop = new ToolBarButton(); - tbbStop.ImageIndex = 13; - - this.tbIconBar.ButtonClick += (object o, ToolBarButtonClickEventArgs e) => { - switch( this.tbIconBar.Buttons.IndexOf( e.Button ) ) { - case 0: this.DoReset(); break; - case 1: this.DoOpen(); break; - case 2: this.DoSave(); break; - case 3: this.DoDisplayInHex(); break; - case 4: this.DoDisplayInDec(); break; - case 5: this.DoIncreaseFont(); break; - case 6: this.DoDecreaseFont(); break; - case 7: this.DoSwitchToMemory(); break; - case 8: this.DoSwitchToDrawing(); break; - case 9: this.ShowSettings(); break; - case 10: this.DoHelp(); break; - case 11: this.DoAbout(); break; - case 12: this.DoPlay(); break; - case 13: this.DoStop(); break; - default: throw new ArgumentException( "unexpected toolbar button: unhandled" ); - } - }; - - this.tbIconBar.Buttons.AddRange( new ToolBarButton[]{ - tbbReset, tbbOpen, tbbSave, - tbbHex, tbbDec, tbbZoomIn, - tbbZoomOut, tbbMem, tbbVisual, - tbbSettings, tbbHelp, tbbAbout, - tbbPlay, tbbStop - }); - - this.tbbStop.Enabled = false; - this.Controls.Add( this.tbIconBar ); - } - - private void BuildTabbedPanel() - { - this.gbMain = new GroupBox { Text = "Memory", Dock = DockStyle.Fill }; - this.tcTabs = new TabControl(); - this.tcTabs.SuspendLayout(); - this.tcTabs.SelectedIndexChanged += (o, e) => { - if ( tcTabs.SelectedIndex == 1 ) { - this.DoDrawing(); - } - this.FocusOnInput(); - }; - this.tcTabs.Dock = DockStyle.Fill; - this.tcTabs.Alignment = TabAlignment.Bottom; - this.tcTabs.TabPages.Add( new TabPage( "" ) ); - this.tcTabs.TabPages.Add( new TabPage( "" ) ); - this.tcTabs.ImageList = new ImageList(); - this.tcTabs.ImageList.ImageSize = new Size( 16, 16 ); - this.tcTabs.ImageList.Images.AddRange( new Image[] { - this.memoryIconBmp, this.diagramIconBmp - }); - this.tcTabs.TabPages[ 0 ].ImageIndex = 0; - this.tcTabs.TabPages[ 1 ].ImageIndex = 1; - this.gbMain.Controls.Add( this.tcTabs ); - this.splSymbolTable.Panel2.Controls.Add( this.gbMain ); - } - - private void BuildOutput() - { - this.rtbOutput = new RichTextBox(); - this.rtbOutput.Font = this.baseFont; - this.rtbOutput.ReadOnly = true; - this.rtbOutput.Dock = DockStyle.Fill; - this.pnlIO.Controls.Add( this.rtbOutput ); - } - - private void BuildStatusbar() - { - this.sbStatus = new StatusStrip( ); - this.lblStatus = new ToolStripStatusLabel( ); - this.sbStatus.Items.Add( this.lblStatus ); - this.Controls.Add( sbStatus ); - } - - private void BuildSettingsPanel() - { + using System; + using System.Drawing; + using System.Globalization; + using System.Windows.Forms; + + using CSim.Core; + + /// The main window for the application. This builds the view. + public partial class MainWindow { + private void BuildInputPanel() + { + // Line input + this.edInput = new ComboBox() { + Dock = DockStyle.Bottom, + Font = this.baseFont + }; + + this.edInput.KeyDown += (o, e) => { + if ( e.KeyCode == Keys.Enter ) { + this.DoInput(); + e.Handled = true; + e.SuppressKeyPress = true; + } + }; + + this.pnlIO.Controls.Add( this.edInput ); + } + + private void BuildWatchesView() + { + this.lblWatchesValue = new Label[ NumWatches ]; + this.edWatchesLabel = new TextBox[ NumWatches ]; + + for(int i = 0; i < NumWatches; ++i) { + var lblWatch = this.lblWatchesValue[ i ] = new Label { + Text = "0", + Dock = DockStyle.Right, + ForeColor = SystemColors.InfoText, + BackColor = SystemColors.Info + }; + var edWatch = this.edWatchesLabel[ i ] = new TextBox { + Dock = DockStyle.Fill + }; + + lblWatch.Font = new Font( FontFamily.GenericMonospace, 11 ); + + edWatch.LostFocus += (obj, args) => this.UpdateWatches(); + lblWatch.Font = new Font( FontFamily.GenericMonospace, 11 ); + } + + return; + } + + private void BuildWatchesPanel() + { + this.BuildWatchesView(); + this.gbWatches = new GroupBox { Text = "Watches", Dock = DockStyle.Fill }; + this.pnlWatches = new TableLayoutPanel { Dock = DockStyle.Fill, AutoScroll = true }; + + for(int i = 0; i < NumWatches; ++i) { + var panel = new Panel { Dock = DockStyle.Top }; + panel.Controls.Add( this.edWatchesLabel[ i ] ); + panel.Controls.Add( this.lblWatchesValue[ i ] ); + this.pnlWatches.Controls.Add( panel ); + panel.MaximumSize = new Size( int.MaxValue, this.edWatchesLabel[ i ].Height ); + } + + this.gbWatches.Controls.Add( this.pnlWatches ); + this.splWatches.Panel2.Controls.Add( this.gbWatches ); + } + + private void BuildHistoryPanel() + { + this.lbHistory = new ListBox() { + Font = new Font( FontFamily.GenericMonospace, 8 ), + Dock = DockStyle.Fill + }; + + this.gbHistory = new GroupBox { Text = "History", Dock = DockStyle.Fill }; + this.gbHistory.Controls.Add( this.lbHistory ); + this.splWatches.Panel1.Controls.Add( this.gbHistory ); + + this.lbHistory.SelectedIndexChanged += (o, e) => this.OnHistoryIndexChanged(); + } + + private void BuildMemoryViewPanel() + { + // Grid for memory + int columnWidth = ( this.CharWidth * 2 ); + this.grdMemory = new DataGridView() { + AllowUserToResizeRows = false, + AllowUserToAddRows = false, + RowHeadersVisible = false, + AutoGenerateColumns = false, + MultiSelect = false, + ShowCellToolTips = true + }; + + // Style for regular columns + var style = new DataGridViewCellStyle() { + Font = new Font( this.baseFont, FontStyle.Bold ), + BackColor = Color.AntiqueWhite, + ForeColor = Color.Black, + SelectionBackColor = Color.Black, + SelectionForeColor = Color.AntiqueWhite + }; + + this.grdMemory.DefaultCellStyle = style; + + // Style for headers + var styleHeaders = new DataGridViewCellStyle() { + BackColor = Color.Black, + ForeColor = Color.White, + Font = new Font( this.baseFont, FontStyle.Bold ) + }; + + this.grdMemory.ColumnHeadersDefaultCellStyle = styleHeaders; + + // Style for first column + var styleFirstColumn = new DataGridViewCellStyle() { + Font = new Font( this.baseFont, FontStyle.Bold ), + BackColor = Color.Black, + ForeColor = Color.White + }; + + // Create columns + DataGridViewTextBoxColumn[] columns = + new DataGridViewTextBoxColumn[ MaxDataColumns +1 ]; + + for(int i = 0; i < columns.Length; ++i) { + columns[ i ] = new DataGridViewTextBoxColumn(); + + if ( i == 0 ) { + columns[ i ].DefaultCellStyle = styleFirstColumn; + columns[ i ].HeaderText = "/"; + columns[ i ].Width = columnWidth + ( (int) ( columnWidth * 0.2 ) ); + } else { + columns[ i ].HeaderText = FromIntToHex( i - 1 ); + columns[ i ].Width = columnWidth; + } + + columns[ i ].SortMode = DataGridViewColumnSortMode.NotSortable; + columns[ i ].ReadOnly = true; + } + + this.grdMemory.Columns.AddRange( columns ); + + // Create rows + var rows = new DataGridViewRow[ (int) this.machine.Memory.Max / MaxDataColumns ]; + + for(int i = 0; i < rows.Length; ++i) { + rows[ i ] = new DataGridViewRow(); + } + + this.grdMemory.Rows.AddRange( rows ); + + this.grdMemory.Dock = DockStyle.Fill; + this.tcTabs.TabPages[ 0 ].Controls.Add( this.grdMemory ); + this.splHistory.SplitterDistance = this.CharWidth * 10; + } + + private void BuildSymbolTable() + { + // Symbol table + this.gbSymbols = new GroupBox { + Dock = DockStyle.Fill, + Text = "Symbols" + }; + + this.tvSymbolTable = new TreeView() { + Dock = DockStyle.Fill, + Font = this.baseFont, + PathSeparator = "." + }; + + this.tvSymbolTable.AfterSelect += (sender, e) => this.DoTreeSelect(); + this.gbSymbols.Controls.Add( this.tvSymbolTable ); + this.splSymbolTable.Panel1.Controls.Add( this.gbSymbols ); + this.splSymbolTable.SplitterDistance = this.CharWidth; + } + + private void BuildAboutPanel() + { + // Panel for about info + this.pnlAbout = new Panel() { + Dock = DockStyle.Bottom, + BackColor = SystemColors.Info + }; + this.pnlAbout.SuspendLayout(); + var lblAbout = new Label() { + Text = AppInfo.Name + + " v" + AppInfo.Version + ", " + AppInfo.Author, + Dock = DockStyle.Left, + TextAlign = ContentAlignment.MiddleCenter, + AutoSize = true, + ForeColor = SystemColors.InfoText + }; + var font = new Font( lblAbout.Font, FontStyle.Bold ); + font = new Font( font.FontFamily, 14 ); + lblAbout.Font = font; + + var btCloseAboutPanel = new Button() { + Text = "X", + Dock = DockStyle.Right, + Width = this.CharWidth * 5, + FlatStyle = FlatStyle.Flat, + }; + btCloseAboutPanel.FlatAppearance.BorderSize = 0; + btCloseAboutPanel.Font = new Font( btCloseAboutPanel.Font, FontStyle.Bold ); + btCloseAboutPanel.ForeColor = SystemColors.InfoText; + btCloseAboutPanel.Click += (obj, args) => this.pnlAbout.Hide(); + this.pnlAbout.Controls.Add( lblAbout ); + this.pnlAbout.Controls.Add( btCloseAboutPanel ); + this.pnlAbout.Hide(); + this.pnlAbout.MinimumSize = new Size( this.Width, lblAbout.Height +5 ); + this.pnlAbout.MaximumSize = new Size( Int32.MaxValue, lblAbout.Height +5 ); + this.pnlAbout.ResumeLayout(); + this.Controls.Add( this.pnlAbout ); + } + + private void BuildIcons() + { + var assembly = System.Reflection.Assembly.GetEntryAssembly(); + var resourceAppIcon = assembly. + GetManifestResourceStream( "CSim.Res.appIcon.png" ); + + // Prepare icons + if ( resourceAppIcon != null ) { + this.appIconBmp = new Bitmap( resourceAppIcon ); + this.Icon = Icon.FromHandle( this.appIconBmp.GetHicon() ); + + this.backIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.back.png" ) ); + + this.playIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.play.png" ) ); + + this.stopIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.stop.png" ) ); + + this.openIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.open.png" ) ); + + this.saveIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.save.png" ) ); + + this.resetIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.reset.png" ) ); + + this.zoomInIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.zoom_in.png" ) ); + + this.zoomOutIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.zoom_out.png" ) ); + + this.aboutIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.info.png" ) ); + + this.helpIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.help.png" ) ); + + this.memoryIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.memory.png" ) ); + + this.diagramIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.diagram.png" ) ); + + this.hexIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.hex.png" ) ); + + this.decIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.dec.png" ) ); + + this.zeroIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.zero.png" ) ); + + this.randIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.random.png" ) ); + + this.settingsIconBmp = new Bitmap( + assembly.GetManifestResourceStream( "CSim.Res.settings.png" ) ); + } + + return; + } + + private void BuildDrawingTab() + { + var scroll = new Panel() { + Dock = DockStyle.Fill, AutoScroll = true + }; + + this.pbCanvas = new PictureBox() { + BackColor = Color.GhostWhite, + ForeColor = Color.Navy, + Anchor = AnchorStyles.Left | AnchorStyles.Top, + SizeMode = PictureBoxSizeMode.AutoSize + }; + + scroll.Controls.Add( this.pbCanvas ); + this.tcTabs.TabPages[ 1 ].Controls.Add( scroll ); + this.sdDrawingBoard = new SchemaDrawer( this.machine ); + } + + private void BuildToolbar() + { + // Image list + var imgList = new ImageList() { ImageSize = new Size( 24, 24 ) }; + imgList.Images.AddRange( new []{ + this.resetIconBmp, this.openIconBmp, + this.saveIconBmp, this.hexIconBmp, + this.decIconBmp, this.zoomInIconBmp, + this.zoomOutIconBmp, this.memoryIconBmp, + this.diagramIconBmp, this.helpIconBmp, + this.aboutIconBmp, this.settingsIconBmp, + this.playIconBmp, this.stopIconBmp + } ); + + // Toolbar + this.tbIconBar = new ToolBar() { + AutoSize = true, + Dock = DockStyle.Top, + Appearance = ToolBarAppearance.Flat, + BorderStyle = BorderStyle.None, + ImageList = imgList, + ShowToolTips = true, + }; + + // Toolbar buttons + this.tbbOpen = new ToolBarButton() { ImageIndex = 1 }; + this.tbbSave = new ToolBarButton() { ImageIndex = 2 }; + this.tbbHex = new ToolBarButton() { ImageIndex = 3 }; + this.tbbDec = new ToolBarButton() { ImageIndex = 4 }; + this.tbbZoomIn = new ToolBarButton() { ImageIndex = 5 }; + this.tbbZoomOut = new ToolBarButton() { ImageIndex = 6 }; + this.tbbDiagram = new ToolBarButton() { ImageIndex = 7 }; + this.tbbMemory = new ToolBarButton() { ImageIndex = 8 }; + this.tbbPlay = new ToolBarButton() { ImageIndex = 12 }; + this.tbbStop = new ToolBarButton() { + ImageIndex = 13, + Enabled = false, + }; + this.tbbHelp = new ToolBarButton() { ImageIndex = 9 }; + this.tbbAbout = new ToolBarButton() { ImageIndex = 10 }; + this.tbbSettings = new ToolBarButton() { ImageIndex = 11 }; + this.tbbReset = new ToolBarButton() { + ImageIndex = 0, + Style = ToolBarButtonStyle.DropDownButton + }; + + var mniZero = new MenuItem( "Zero", (o, e) => DoReset() ) { + OwnerDraw = true + }; + + mniZero.DrawItem += (o, e) => { + double factor = (double) e.Bounds.Height / this.zeroIconBmp.Height; + var rect = new Rectangle( e.Bounds.X, e.Bounds.Y, + (int) ( this.zeroIconBmp.Width * factor ), + (int) ( this.zeroIconBmp.Height * factor ) ); + e.Graphics.DrawImage( this.zeroIconBmp, rect ); + }; + + var mniRandom = new MenuItem( "Random", (o, e) => DoReset( MemoryManager.ResetType.Random ) ) { + OwnerDraw = true + }; + + mniRandom.DrawItem += (o, e) => { + double factor = (double) ( e.Bounds.Height ) / this.randIconBmp.Height; + var rect = new Rectangle( e.Bounds.X, e.Bounds.Y, + (int) ( this.randIconBmp.Width * factor ), + (int) ( this.randIconBmp.Height * factor ) ); + e.Graphics.DrawImage( this.randIconBmp, rect ); + }; + + tbbReset.DropDownMenu = new ContextMenu( new []{ mniZero, mniRandom } ); + + // Action for each button + this.tbIconBar.ButtonClick += (object o, ToolBarButtonClickEventArgs e) => { + if ( e.Button == this.tbbReset ) { + this.DoReset(); + } + else + if ( e.Button == this.tbbOpen ) { + this.DoOpen(); + } + else + if ( e.Button == this.tbbSave ) { + this.DoSave(); + } + else + if ( e.Button == this.tbbHex ) { + this.DoDisplayInHex(); + } + else + if ( e.Button == this.tbbDec ) { + this.DoDisplayInDec(); + } + else + if ( e.Button == this.tbbZoomIn ) { + this.DoIncreaseFont(); + } + else + if ( e.Button == this.tbbZoomOut ) { + this.DoDecreaseFont(); + } + else + if ( e.Button == this.tbbDiagram ) { + this.DoSwitchToDrawing(); + } + else + if ( e.Button == this.tbbMemory ) { + this.DoSwitchToMemory(); + } + else + if ( e.Button == this.tbbPlay ) { + this.DoPlay(); + } + else + if ( e.Button == this.tbbStop ) { + this.DoStop(); + } + else + if ( e.Button == this.tbbHelp ) { + this.DoHelp(); + } + else + if ( e.Button == this.tbbAbout ) { + this.DoAbout(); + } + else + if ( e.Button == this.tbbSettings ) { + this.ShowSettings(); + } + else { + throw new ArgumentException( "unexpected toolbar button: unhandled" ); + } + }; + + this.tbIconBar.Buttons.AddRange( new[]{ + tbbSettings, + new ToolBarButton() { Style = ToolBarButtonStyle.Separator }, + tbbReset, + new ToolBarButton() { Style = ToolBarButtonStyle.Separator }, + tbbOpen, tbbSave, + new ToolBarButton() { Style = ToolBarButtonStyle.Separator }, + tbbHex, tbbDec, + new ToolBarButton() { Style = ToolBarButtonStyle.Separator }, + tbbZoomIn, tbbZoomOut, + new ToolBarButton() { Style = ToolBarButtonStyle.Separator }, + tbbMemory, tbbDiagram, + new ToolBarButton() { Style = ToolBarButtonStyle.Separator }, + tbbPlay, tbbStop, + new ToolBarButton() { Style = ToolBarButtonStyle.Separator }, + tbbHelp, tbbAbout + }); + + this.Controls.Add( this.tbIconBar ); + } + + private void BuildTabbedPanel() + { + this.gbMain = new GroupBox { Text = "Memory", Dock = DockStyle.Fill }; + this.tcTabs = new TabControl() { + Dock = DockStyle.Fill, + Alignment = TabAlignment.Bottom, + ImageList = new ImageList() + }; + + this.tcTabs.ImageList.ImageSize = new Size( 16, 16 ); + this.tcTabs.SuspendLayout(); + this.tcTabs.SelectedIndexChanged += (o, e) => { + if ( tcTabs.SelectedIndex == 1 ) { + this.DoDrawing(); + } + this.FocusOnInput(); + }; + this.tcTabs.TabPages.Add( new TabPage( "" ) ); + this.tcTabs.TabPages.Add( new TabPage( "" ) ); + this.tcTabs.ImageList.Images.AddRange( new Image[] { + this.memoryIconBmp, this.diagramIconBmp + }); + this.tcTabs.TabPages[ 0 ].ImageIndex = 0; + this.tcTabs.TabPages[ 1 ].ImageIndex = 1; + this.gbMain.Controls.Add( this.tcTabs ); + this.splSymbolTable.Panel2.Controls.Add( this.gbMain ); + } + + private void BuildOutput() + { + this.rtbOutput = new RichTextBox() { + Font = this.baseFont, + ReadOnly = true, + Dock = DockStyle.Fill, + ForeColor = Color.White, + BackColor = Color.Black + }; + this.rtbOutput.PreviewKeyDown += (sender, e) => { + this.edInput.Focus(); + }; + + this.pnlIO.Controls.Add( this.rtbOutput ); + } + + private void BuildStatusbar() + { + this.sbStatus = new StatusStrip( ); + this.lblStatus = new ToolStripStatusLabel( ); + this.sbStatus.Items.Add( this.lblStatus ); + this.Controls.Add( sbStatus ); + } + + private void BuildSettingsPanel() + { this.pnlSettings = new TableLayoutPanel { - BackColor = Color.White, + BackColor = SystemColors.Window, + ForeColor = SystemColors.WindowText, Dock = DockStyle.Fill, ColumnCount = 1, GrowStyle = TableLayoutPanelGrowStyle.AddRows }; - this.pnlSettings.SuspendLayout(); + this.pnlSettings.SuspendLayout(); // Button var btClose = new Button { - BackColor = Color.White, + BackColor = SystemColors.Info, + ForeColor = SystemColors.InfoText, Image = this.backIconBmp, Anchor = AnchorStyles.Left | AnchorStyles.Top, Font = new Font( Font, FontStyle.Bold ), FlatStyle = FlatStyle.Flat }; btClose.FlatAppearance.BorderSize = 0; - btClose.Click += (sender, e) => this.ApplySettings(); - this.pnlSettings.Controls.Add( btClose ); + btClose.Click += (sender, e) => this.ApplySettings(); + this.pnlSettings.Controls.Add( btClose ); // Locale - var pnlLocales = new Panel { Dock = DockStyle.Top }; + var pnlLocales = new Panel { + Dock = DockStyle.Top, + }; this.lblLocales = new Label { Text = L18n.Get( L18n.Id.LblLanguage ), - Dock = DockStyle.Left + Dock = DockStyle.Left, }; this.cbLocales = new ComboBox { + ForeColor = SystemColors.Menu, + BackColor = SystemColors.MenuText, Dock = DockStyle.Fill, DropDownStyle = ComboBoxStyle.DropDownList, - Text = Core.Locale.CurrentLocale.ToString() + Text = Core.Locale.CurrentLocale.ToString(), }; - CultureInfo[] locales = CultureInfo.GetCultures( CultureTypes.SpecificCultures ); - Array.Sort( locales, - (CultureInfo x, CultureInfo y) => string.Compare( x.ToString(), y.ToString() ) - ); + CultureInfo[] locales = CultureInfo.GetCultures( CultureTypes.SpecificCultures ); + Array.Sort( locales, + (CultureInfo x, CultureInfo y) => string.Compare( x.ToString(), y.ToString() ) + ); - this.cbLocales.Items.Add( "" ); - foreach(CultureInfo locale in locales ) { - this.cbLocales.Items.Add( locale.NativeName + ": " + locale ); - } + this.cbLocales.Items.Add( "" ); + foreach(CultureInfo locale in locales ) { + this.cbLocales.Items.Add( locale.NativeName + ": " + locale ); + } - pnlLocales.Controls.Add( this.cbLocales ); - pnlLocales.Controls.Add( this.lblLocales ); - this.pnlSettings.Controls.Add( pnlLocales ); + pnlLocales.Controls.Add( this.cbLocales ); + pnlLocales.Controls.Add( this.lblLocales ); + this.pnlSettings.Controls.Add( pnlLocales ); - // Endianness - var gbEndianness = new GroupBox { Text = "Alignment", Dock = DockStyle.Top }; - gbEndianness.SuspendLayout(); + // Endianness + var gbEndianness = new GroupBox { Text = "Alignment", Dock = DockStyle.Top }; + gbEndianness.SuspendLayout(); var pnlEndianness = new TableLayoutPanel { Dock = DockStyle.Fill }; - pnlEndianness.SuspendLayout(); - this.rbEndianness1 = new RadioButton { Text = "Little endian", Dock = DockStyle.Top }; - this.rbEndianness2 = new RadioButton { Text = "Big endian", Dock = DockStyle.Top }; - pnlEndianness.Controls.Add( this.rbEndianness1 ); - pnlEndianness.Controls.Add( this.rbEndianness2 ); - gbEndianness.Controls.Add( pnlEndianness ); - pnlEndianness.ResumeLayout( false ); - gbEndianness.ResumeLayout( false ); - this.pnlSettings.Controls.Add( gbEndianness ); + pnlEndianness.SuspendLayout(); + this.rbEndianness1 = new RadioButton { + Text = "Little endian", + Dock = DockStyle.Top, + }; + this.rbEndianness2 = new RadioButton { + Text = "Big endian", + Dock = DockStyle.Top, + }; + pnlEndianness.Controls.Add( this.rbEndianness1 ); + pnlEndianness.Controls.Add( this.rbEndianness2 ); + gbEndianness.Controls.Add( pnlEndianness ); + pnlEndianness.ResumeLayout( false ); + gbEndianness.ResumeLayout( false ); + this.pnlSettings.Controls.Add( gbEndianness ); // Alignment var gbAlignment = new GroupBox { Text = "Alignment", Dock = DockStyle.Top }; var pnlAlignment = new TableLayoutPanel { Dock = DockStyle.Fill }; gbAlignment.SuspendLayout(); pnlAlignment.SuspendLayout(); - this.chkAlign = new CheckBox { Text = "Align variables in memory", Dock = DockStyle.Top }; + this.chkAlign = new CheckBox { + Text = "Align variables in memory", + Dock = DockStyle.Top, + }; pnlAlignment.Controls.Add( this.chkAlign ); pnlAlignment.ResumeLayout( false ); gbAlignment.ResumeLayout( false ); @@ -524,185 +604,220 @@ private void BuildSettingsPanel() // Memory width var gbWordSize = new GroupBox { Text = "Word size", Dock = DockStyle.Top }; var pnlWordSize = new TableLayoutPanel { Dock = DockStyle.Fill }; - gbWordSize.SuspendLayout(); - pnlWordSize.SuspendLayout(); - this.rbWS16 = new RadioButton { Text = "16 bits", Dock = DockStyle.Top }; - this.rbWS32 = new RadioButton { Text = "32 bits", Dock = DockStyle.Top }; - this.rbWS64 = new RadioButton { Text = "64 bits", Dock = DockStyle.Top }; - pnlWordSize.Controls.Add( this.rbWS16 ); - pnlWordSize.Controls.Add( this.rbWS32 ); - pnlWordSize.Controls.Add( this.rbWS64 ); - gbWordSize.Controls.Add( pnlWordSize ); - pnlWordSize.ResumeLayout( false ); - gbWordSize.ResumeLayout( false ); - this.pnlSettings.Controls.Add( gbWordSize ); - - // Finishing - this.pnlSettings.ResumeLayout( false ); - this.pnlSettings.Hide(); - this.Controls.Add( this.pnlSettings ); - - // Sizes - this.pnlSettings.MinimumSize = new Size( - this.ClientSize.Width, - SystemInformation.VirtualScreen.Height - ); - return; - } - - private void SetStartingSize() - { - Rectangle size = Screen.FromControl( this ).Bounds; - - if ( size.Width > 1024 - && size.Height > 768 ) - { - this.MinimumSize = new Size( 800, 600 ); - - this.Width = 1024; - this.Height = 768; - } - else - if ( size.Width > 800 - && size.Height > 600 ) - { - this.MinimumSize = new Size( 640, 480 ); - - this.Width = 800; - this.Height = 600; - } - else { - this.MinimumSize = new Size( 480, 420 ); - this.Width = 640; - this.Height = 480; - } - - return; - } - - private void Build() - { - // Start - this.BuildIcons(); - this.StartPosition = FormStartPosition.CenterScreen; - this.SuspendLayout(); - - // Main panels - this.pnlIO = new Panel(); - this.pnlIO.Dock = DockStyle.Bottom; - this.pnlMain = new Panel(); - this.pnlMain.Dock = DockStyle.Fill; - this.pnlIO.SuspendLayout(); - this.pnlMain.SuspendLayout(); - this.Controls.Add( pnlMain ); - this.Controls.Add( pnlIO ); - - // Split panel for symbol explorer - // 1 - symbol table, 2 - tabs - this.splSymbolTable = new SplitContainer(); - this.splSymbolTable.SuspendLayout(); - this.splSymbolTable.Dock = DockStyle.Fill; - - // Split panel for history - // 1 - splSymbolTable (everything else), 2 - history - this.splHistory = new SplitContainer{ Dock = DockStyle.Fill }; - this.splHistory.SuspendLayout(); - this.splHistory.Panel1.Controls.Add( this.splSymbolTable ); - - // Split panel for history & watches - this.splWatches = new SplitContainer{ Dock = DockStyle.Fill, Orientation = Orientation.Horizontal }; - this.splWatches.SuspendLayout(); - this.splHistory.Panel2.Controls.Add( this.splWatches ); - - // Compose it up - this.pnlMain.Controls.Add( splHistory ); - - this.BuildTabbedPanel(); - this.BuildWatchesPanel(); - this.BuildHistoryPanel(); - this.BuildMemoryViewPanel(); - this.BuildSymbolTable(); - this.BuildDrawingTab(); - this.BuildToolbar(); - this.BuildOutput(); - this.BuildInputPanel(); - this.BuildSettingsPanel(); - this.BuildAboutPanel(); - this.BuildStatusbar(); - - // End - this.Closed += (sender, e) => this.DoQuit(); - this.Text = AppInfo.Name; - this.SetStartingSize(); - this.Shown += (o, e) => this.FocusOnInput(); - this.splHistory.ResumeLayout( false ); - this.splSymbolTable.ResumeLayout( false ); - this.splWatches.ResumeLayout( false ); - this.tcTabs.ResumeLayout( false ); - this.pnlIO.ResumeLayout( false ); - this.pnlMain.ResumeLayout( false ); - this.ResumeLayout( false ); - this.UpdateFont( 0 ); - this.FocusOnInput(); - - return; - } - - - private SplitContainer splSymbolTable; - private SplitContainer splHistory; - private SplitContainer splWatches; - private Font baseFont; - private Panel pnlAbout; - private Panel pnlIO; - private Panel pnlMain; - private GroupBox gbSymbols; - private GroupBox gbHistory; - private GroupBox gbMain; - private GroupBox gbWatches; - private TableLayoutPanel pnlSettings; - private TableLayoutPanel pnlWatches; - private ComboBox edInput; - private DataGridView grdMemory; - private TreeView tvSymbolTable; - private StatusStrip sbStatus; - private ToolStripStatusLabel lblStatus; - private ListBox lbHistory; - private RichTextBox rtbOutput; - private TabControl tcTabs; - private PictureBox pbCanvas; - private Bitmap bmDrawArea; - private ToolBar tbIconBar; - private ToolBarButton tbbStop; - private ComboBox cbLocales; - private Label lblLocales; + gbWordSize.SuspendLayout(); + pnlWordSize.SuspendLayout(); + this.rbWS16 = new RadioButton { + Text = "16 bits", + Dock = DockStyle.Top, + }; + this.rbWS32 = new RadioButton { + Text = "32 bits", + Dock = DockStyle.Top, + }; + this.rbWS64 = new RadioButton { + Text = "64 bits", + Dock = DockStyle.Top, + }; + pnlWordSize.Controls.Add( this.rbWS16 ); + pnlWordSize.Controls.Add( this.rbWS32 ); + pnlWordSize.Controls.Add( this.rbWS64 ); + gbWordSize.Controls.Add( pnlWordSize ); + pnlWordSize.ResumeLayout( false ); + gbWordSize.ResumeLayout( false ); + this.pnlSettings.Controls.Add( gbWordSize ); + + // Finishing + this.pnlSettings.PreviewKeyDown += ( o, evt ) => { + this.ApplySettings(); + }; + this.pnlSettings.ResumeLayout( false ); + this.pnlSettings.Hide(); + this.Controls.Add( this.pnlSettings ); + + // Sizes + this.pnlSettings.MinimumSize = new Size( + this.ClientSize.Width, + SystemInformation.VirtualScreen.Height + ); + + return; + } + + private void SetStartingSize() + { + Rectangle size = Screen.FromControl( this ).Bounds; + + if ( size.Width > 1024 + && size.Height > 768 ) + { + this.MinimumSize = new Size( 800, 600 ); + + this.Width = 1024; + this.Height = 768; + } + else + if ( size.Width > 800 + && size.Height > 600 ) + { + this.MinimumSize = new Size( 640, 480 ); + + this.Width = 800; + this.Height = 600; + } + else { + this.MinimumSize = new Size( 480, 420 ); + this.Width = 640; + this.Height = 480; + } + + return; + } + + private void Build() + { + // Start + this.BuildIcons(); + this.StartPosition = FormStartPosition.CenterScreen; + this.SuspendLayout(); + + // Main panels + this.splMain = new SplitContainer() { + Dock = DockStyle.Fill, + Orientation = Orientation.Horizontal + }; + this.pnlIO = new Panel() { Dock = DockStyle.Fill }; + this.pnlMain = new Panel() { Dock = DockStyle.Fill }; + this.pnlIO.SuspendLayout(); + this.pnlMain.SuspendLayout(); + this.Controls.Add( splMain ); + this.splMain.Panel1.Controls.Add( pnlMain ); + this.splMain.Panel2.Controls.Add( pnlIO ); + + // Split panel for symbol explorer + // 1 - symbol table, 2 - tabs + this.splSymbolTable = new SplitContainer() { Dock = DockStyle.Fill }; + this.splSymbolTable.SuspendLayout(); + + // Split panel for history + // 1 - splSymbolTable (everything else), 2 - history + this.splHistory = new SplitContainer{ Dock = DockStyle.Fill }; + this.splHistory.SuspendLayout(); + this.splHistory.Panel1.Controls.Add( this.splSymbolTable ); + + // Split panel for history & watches + this.splWatches = new SplitContainer{ Dock = DockStyle.Fill, Orientation = Orientation.Horizontal }; + this.splWatches.SuspendLayout(); + this.splHistory.Panel2.Controls.Add( this.splWatches ); + + // Compose it up + this.pnlMain.Controls.Add( splHistory ); + + this.BuildTabbedPanel(); + this.BuildWatchesPanel(); + this.BuildHistoryPanel(); + this.BuildMemoryViewPanel(); + this.BuildSymbolTable(); + this.BuildDrawingTab(); + this.BuildToolbar(); + this.BuildOutput(); + this.BuildInputPanel(); + this.BuildSettingsPanel(); + this.BuildAboutPanel(); + this.BuildStatusbar(); + + // End + this.Closed += (sender, e) => this.DoQuit(); + this.Text = AppInfo.Name; + this.SetStartingSize(); + this.Shown += (o, e) => this.FocusOnInput(); + this.splHistory.ResumeLayout( false ); + this.splSymbolTable.ResumeLayout( false ); + this.splWatches.ResumeLayout( false ); + this.tcTabs.ResumeLayout( false ); + this.pnlIO.ResumeLayout( false ); + this.pnlMain.ResumeLayout( false ); + this.ResumeLayout( false ); + this.UpdateFont( 0 ); + this.FocusOnInput(); + this.splMain.SplitterDistance = + this.ClientSize.Height + - this.tbIconBar.Height + - this.sbStatus.Height + - ( this.CharHeight * 5 ); + + return; + } + + + private SplitContainer splMain; + private SplitContainer splSymbolTable; + private SplitContainer splHistory; + private SplitContainer splWatches; + private Font baseFont; + private Panel pnlAbout; + private Panel pnlIO; + private Panel pnlMain; + private GroupBox gbSymbols; + private GroupBox gbHistory; + private GroupBox gbMain; + private GroupBox gbWatches; + private TableLayoutPanel pnlSettings; + private TableLayoutPanel pnlWatches; + private ComboBox edInput; + private DataGridView grdMemory; + private TreeView tvSymbolTable; + private StatusStrip sbStatus; + private ToolStripStatusLabel lblStatus; + private ListBox lbHistory; + private RichTextBox rtbOutput; + private TabControl tcTabs; + private PictureBox pbCanvas; + private Bitmap bmDrawArea; + private ToolBar tbIconBar; + private ComboBox cbLocales; + private Label lblLocales; private CheckBox chkAlign; - private RadioButton rbEndianness1; - private RadioButton rbEndianness2; - private RadioButton rbWS16; - private RadioButton rbWS32; - private RadioButton rbWS64; - private TextBox[] edWatchesLabel; - private Label[] lblWatchesValue; - - private Bitmap appIconBmp; - private Bitmap backIconBmp; - private Bitmap openIconBmp; - private Bitmap saveIconBmp; - private Bitmap resetIconBmp; - private Bitmap zoomInIconBmp; - private Bitmap zoomOutIconBmp; - private Bitmap helpIconBmp; - private Bitmap aboutIconBmp; - private Bitmap memoryIconBmp; - private Bitmap diagramIconBmp; - private Bitmap hexIconBmp; - private Bitmap decIconBmp; - private Bitmap zeroIconBmp; - private Bitmap randIconBmp; - private Bitmap settingsIconBmp; - private Bitmap playIconBmp; - private Bitmap stopIconBmp; - } + private RadioButton rbEndianness1; + private RadioButton rbEndianness2; + private RadioButton rbWS16; + private RadioButton rbWS32; + private RadioButton rbWS64; + private TextBox[] edWatchesLabel; + private Label[] lblWatchesValue; + + private ToolBarButton tbbReset; + private ToolBarButton tbbOpen; + private ToolBarButton tbbSave; + private ToolBarButton tbbHex; + private ToolBarButton tbbDec; + private ToolBarButton tbbZoomIn; + private ToolBarButton tbbZoomOut; + private ToolBarButton tbbMemory; + private ToolBarButton tbbDiagram; + private ToolBarButton tbbPlay; + private ToolBarButton tbbStop; + private ToolBarButton tbbHelp; + private ToolBarButton tbbAbout; + private ToolBarButton tbbSettings; + + private Bitmap appIconBmp; + private Bitmap backIconBmp; + private Bitmap openIconBmp; + private Bitmap saveIconBmp; + private Bitmap resetIconBmp; + private Bitmap zoomInIconBmp; + private Bitmap zoomOutIconBmp; + private Bitmap helpIconBmp; + private Bitmap aboutIconBmp; + private Bitmap memoryIconBmp; + private Bitmap diagramIconBmp; + private Bitmap hexIconBmp; + private Bitmap decIconBmp; + private Bitmap zeroIconBmp; + private Bitmap randIconBmp; + private Bitmap settingsIconBmp; + private Bitmap playIconBmp; + private Bitmap stopIconBmp; + } }