Adding persistent settings and marquee separator.
authorsl
Tue, 08 Jul 2014 18:59:07 +0200
changeset 85129c03ab7ba
parent 7 69815d19796c
child 9 7c363a7a975e
Adding persistent settings and marquee separator.
App.config
MainForm.Designer.cs
MainForm.cs
MarqueeLabel.cs
Properties/Settings.Designer.cs
Properties/Settings.settings
     1.1 --- a/App.config	Tue Jul 08 16:41:29 2014 +0200
     1.2 +++ b/App.config	Tue Jul 08 18:59:07 2014 +0200
     1.3 @@ -1,6 +1,21 @@
     1.4  <?xml version="1.0" encoding="utf-8" ?>
     1.5  <configuration>
     1.6 +    <configSections>
     1.7 +        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
     1.8 +            <section name="SharpDisplayManager.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
     1.9 +        </sectionGroup>
    1.10 +    </configSections>
    1.11      <startup> 
    1.12          <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    1.13      </startup>
    1.14 +    <userSettings>
    1.15 +        <SharpDisplayManager.Properties.Settings>
    1.16 +            <setting name="DisplayBrightness" serializeAs="String">
    1.17 +                <value>1</value>
    1.18 +            </setting>
    1.19 +            <setting name="DisplayFont" serializeAs="String">
    1.20 +                <value>Microsoft Sans Serif, 9.75pt</value>
    1.21 +            </setting>
    1.22 +        </SharpDisplayManager.Properties.Settings>
    1.23 +    </userSettings>
    1.24  </configuration>
    1.25 \ No newline at end of file
     2.1 --- a/MainForm.Designer.cs	Tue Jul 08 16:41:29 2014 +0200
     2.2 +++ b/MainForm.Designer.cs	Tue Jul 08 18:59:07 2014 +0200
     2.3 @@ -38,14 +38,16 @@
     2.4              this.buttonOpen = new System.Windows.Forms.Button();
     2.5              this.buttonCapture = new System.Windows.Forms.Button();
     2.6              this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
     2.7 +            this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
     2.8 +            this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
     2.9              this.buttonFont = new System.Windows.Forms.Button();
    2.10              this.tabPageTests = new System.Windows.Forms.TabPage();
    2.11              this.fontDialog = new System.Windows.Forms.FontDialog();
    2.12              this.timer = new System.Windows.Forms.Timer(this.components);
    2.13              this.statusStrip = new System.Windows.Forms.StatusStrip();
    2.14              this.toolStripStatusLabelConnect = new System.Windows.Forms.ToolStripStatusLabel();
    2.15 -            this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
    2.16 -            this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
    2.17 +            this.toolStripStatusLabelSpring = new System.Windows.Forms.ToolStripStatusLabel();
    2.18 +            this.toolStripStatusLabelFps = new System.Windows.Forms.ToolStripStatusLabel();
    2.19              this.tabControl.SuspendLayout();
    2.20              this.tabPageDisplay.SuspendLayout();
    2.21              ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).BeginInit();
    2.22 @@ -196,6 +198,39 @@
    2.23              this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64);
    2.24              this.tableLayoutPanel.TabIndex = 4;
    2.25              // 
    2.26 +            // marqueeLabelTop
    2.27 +            // 
    2.28 +            this.marqueeLabelTop.AutoEllipsis = true;
    2.29 +            this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
    2.30 +            this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
    2.31 +            this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1);
    2.32 +            this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
    2.33 +            this.marqueeLabelTop.Name = "marqueeLabelTop";
    2.34 +            this.marqueeLabelTop.OwnTimer = false;
    2.35 +            this.marqueeLabelTop.PixelsPerSecond = 64;
    2.36 +            this.marqueeLabelTop.Separator = "";
    2.37 +            this.marqueeLabelTop.Size = new System.Drawing.Size(254, 30);
    2.38 +            this.marqueeLabelTop.TabIndex = 2;
    2.39 +            this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
    2.40 +            this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    2.41 +            this.marqueeLabelTop.UseCompatibleTextRendering = true;
    2.42 +            // 
    2.43 +            // marqueeLabelBottom
    2.44 +            // 
    2.45 +            this.marqueeLabelBottom.AutoEllipsis = true;
    2.46 +            this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
    2.47 +            this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 32);
    2.48 +            this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
    2.49 +            this.marqueeLabelBottom.Name = "marqueeLabelBottom";
    2.50 +            this.marqueeLabelBottom.OwnTimer = false;
    2.51 +            this.marqueeLabelBottom.PixelsPerSecond = 64;
    2.52 +            this.marqueeLabelBottom.Separator = " | ";
    2.53 +            this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 31);
    2.54 +            this.marqueeLabelBottom.TabIndex = 3;
    2.55 +            this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
    2.56 +            this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    2.57 +            this.marqueeLabelBottom.UseCompatibleTextRendering = true;
    2.58 +            // 
    2.59              // buttonFont
    2.60              // 
    2.61              this.buttonFont.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    2.62 @@ -226,9 +261,12 @@
    2.63              // statusStrip
    2.64              // 
    2.65              this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    2.66 -            this.toolStripStatusLabelConnect});
    2.67 +            this.toolStripStatusLabelConnect,
    2.68 +            this.toolStripStatusLabelSpring,
    2.69 +            this.toolStripStatusLabelFps});
    2.70              this.statusStrip.Location = new System.Drawing.Point(0, 420);
    2.71              this.statusStrip.Name = "statusStrip";
    2.72 +            this.statusStrip.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
    2.73              this.statusStrip.Size = new System.Drawing.Size(624, 22);
    2.74              this.statusStrip.TabIndex = 1;
    2.75              this.statusStrip.Text = "statusStrip";
    2.76 @@ -239,36 +277,17 @@
    2.77              this.toolStripStatusLabelConnect.Size = new System.Drawing.Size(86, 17);
    2.78              this.toolStripStatusLabelConnect.Text = "Not connected";
    2.79              // 
    2.80 -            // marqueeLabelTop
    2.81 +            // toolStripStatusLabelSpring
    2.82              // 
    2.83 -            this.marqueeLabelTop.AutoEllipsis = true;
    2.84 -            this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
    2.85 -            this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
    2.86 -            this.marqueeLabelTop.Location = new System.Drawing.Point(1, -103);
    2.87 -            this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
    2.88 -            this.marqueeLabelTop.Name = "marqueeLabelTop";
    2.89 -            this.marqueeLabelTop.OwnTimer = false;
    2.90 -            this.marqueeLabelTop.PixelsPerSecond = 64;
    2.91 -            this.marqueeLabelTop.Size = new System.Drawing.Size(254, 20);
    2.92 -            this.marqueeLabelTop.TabIndex = 2;
    2.93 -            this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
    2.94 -            this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    2.95 -            this.marqueeLabelTop.UseCompatibleTextRendering = true;
    2.96 +            this.toolStripStatusLabelSpring.Name = "toolStripStatusLabelSpring";
    2.97 +            this.toolStripStatusLabelSpring.Size = new System.Drawing.Size(497, 17);
    2.98 +            this.toolStripStatusLabelSpring.Spring = true;
    2.99              // 
   2.100 -            // marqueeLabelBottom
   2.101 +            // toolStripStatusLabelFps
   2.102              // 
   2.103 -            this.marqueeLabelBottom.AutoEllipsis = true;
   2.104 -            this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
   2.105 -            this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -19);
   2.106 -            this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
   2.107 -            this.marqueeLabelBottom.Name = "marqueeLabelBottom";
   2.108 -            this.marqueeLabelBottom.OwnTimer = false;
   2.109 -            this.marqueeLabelBottom.PixelsPerSecond = 64;
   2.110 -            this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 20);
   2.111 -            this.marqueeLabelBottom.TabIndex = 3;
   2.112 -            this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
   2.113 -            this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   2.114 -            this.marqueeLabelBottom.UseCompatibleTextRendering = true;
   2.115 +            this.toolStripStatusLabelFps.Name = "toolStripStatusLabelFps";
   2.116 +            this.toolStripStatusLabelFps.Size = new System.Drawing.Size(26, 17);
   2.117 +            this.toolStripStatusLabelFps.Text = "FPS";
   2.118              // 
   2.119              // MainForm
   2.120              // 
   2.121 @@ -311,6 +330,8 @@
   2.122          private System.Windows.Forms.TrackBar trackBarBrightness;
   2.123          private System.Windows.Forms.StatusStrip statusStrip;
   2.124          private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelConnect;
   2.125 +        private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelFps;
   2.126 +        private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSpring;
   2.127      }
   2.128  }
   2.129  
     3.1 --- a/MainForm.cs	Tue Jul 08 16:41:29 2014 +0200
     3.2 +++ b/MainForm.cs	Tue Jul 08 18:59:07 2014 +0200
     3.3 @@ -23,6 +23,9 @@
     3.4  
     3.5              InitializeComponent();
     3.6              UpdateStatus();
     3.7 +            //Load settings
     3.8 +            marqueeLabelTop.Font = Properties.Settings.Default.DisplayFont;
     3.9 +            marqueeLabelBottom.Font = Properties.Settings.Default.DisplayFont;
    3.10          }
    3.11  
    3.12          private void buttonFont_Click(object sender, EventArgs e)
    3.13 @@ -49,6 +52,8 @@
    3.14                  //MessageBox.Show("Ok");
    3.15                  marqueeLabelTop.Font = fontDialog.Font;
    3.16                  marqueeLabelBottom.Font = fontDialog.Font;
    3.17 +                Properties.Settings.Default.DisplayFont = fontDialog.Font;
    3.18 +                Properties.Settings.Default.Save();
    3.19                  //label1.Font = fontDlg.Font;
    3.20                  //textBox1.BackColor = fontDlg.Color;
    3.21                  //label1.ForeColor = fontDlg.Color;
    3.22 @@ -70,8 +75,6 @@
    3.23              marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
    3.24              marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
    3.25  
    3.26 -            LastTickTime = NewTickTime;
    3.27 -
    3.28              //Update our display
    3.29              if (iDisplay.IsOpen())
    3.30              {
    3.31 @@ -94,6 +97,12 @@
    3.32                  iDisplay.SwapBuffers();
    3.33  
    3.34              }
    3.35 +
    3.36 +            //Compute instant FPS
    3.37 +            toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " FPS";
    3.38 +
    3.39 +            LastTickTime = NewTickTime;
    3.40 +
    3.41          }
    3.42  
    3.43          private void buttonOpen_Click(object sender, EventArgs e)
    3.44 @@ -155,6 +164,5 @@
    3.45                  toolStripStatusLabelConnect.Text = "Not connected";
    3.46              }
    3.47          }
    3.48 -
    3.49      }
    3.50  }
     4.1 --- a/MarqueeLabel.cs	Tue Jul 08 16:41:29 2014 +0200
     4.2 +++ b/MarqueeLabel.cs	Tue Jul 08 18:59:07 2014 +0200
     4.3 @@ -17,6 +17,13 @@
     4.4          private StringFormat iStringFormat;
     4.5          private SolidBrush iBrush;
     4.6          private SizeF iTextSize;
     4.7 +        private SizeF iSeparatorSize;
     4.8 +
     4.9 +        [Category("Appearance")]
    4.10 +        [Description("Separator in our scrolling loop.")]
    4.11 +        [DefaultValue(" | ")]
    4.12 +        [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
    4.13 +        public string Separator { get; set; }
    4.14  
    4.15          [Category("Behavior")]
    4.16          [Description("How fast is our text scrolling, in pixels per second.")]
    4.17 @@ -80,9 +87,9 @@
    4.18                  return;
    4.19              }
    4.20  
    4.21 -            while (CurrentPosition > (iTextSize.Width))
    4.22 +            while (CurrentPosition > (iTextSize.Width + iSeparatorSize.Width))
    4.23              {
    4.24 -                CurrentPosition -= ((int)iTextSize.Width);
    4.25 +                CurrentPosition -= ((int)(iTextSize.Width + iSeparatorSize.Width));
    4.26              }
    4.27  
    4.28              PixelsLeft += aNewTickTime.Subtract(aLastTickTime).TotalSeconds * PixelsPerSecond;
    4.29 @@ -194,6 +201,7 @@
    4.30              Graphics g = this.CreateGraphics();
    4.31              g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
    4.32              iTextSize = g.MeasureString(Text, Font);
    4.33 +            iSeparatorSize = g.MeasureString(Separator, Font);
    4.34              iStringFormat = GetStringFormatFromContentAllignment(TextAlign);
    4.35  
    4.36              if (NeedToScroll())
    4.37 @@ -234,8 +242,11 @@
    4.38                  //Draw the first one
    4.39                  e.Graphics.TranslateTransform(-(float)CurrentPosition, 0);
    4.40                  e.Graphics.DrawString(Text, Font, iBrush, ClientRectangle, iStringFormat);
    4.41 +                //Draw separator
    4.42 +                e.Graphics.TranslateTransform(iTextSize.Width, 0);
    4.43 +                e.Graphics.DrawString(Separator, Font, iBrush, ClientRectangle, iStringFormat);
    4.44                  //Draw the last one
    4.45 -                e.Graphics.TranslateTransform(iTextSize.Width, 0);
    4.46 +                e.Graphics.TranslateTransform(iSeparatorSize.Width, 0);
    4.47                  e.Graphics.DrawString(Text, Font, iBrush, ClientRectangle, iStringFormat);
    4.48              }
    4.49              else
     5.1 --- a/Properties/Settings.Designer.cs	Tue Jul 08 16:41:29 2014 +0200
     5.2 +++ b/Properties/Settings.Designer.cs	Tue Jul 08 18:59:07 2014 +0200
     5.3 @@ -8,23 +8,43 @@
     5.4  // </auto-generated>
     5.5  //------------------------------------------------------------------------------
     5.6  
     5.7 -namespace SharpDisplayManager.Properties
     5.8 -{
     5.9 -
    5.10 -
    5.11 +namespace SharpDisplayManager.Properties {
    5.12 +    
    5.13 +    
    5.14      [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    5.15      [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
    5.16 -    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
    5.17 -    {
    5.18 -
    5.19 +    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
    5.20 +        
    5.21          private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
    5.22 -
    5.23 -        public static Settings Default
    5.24 -        {
    5.25 -            get
    5.26 -            {
    5.27 +        
    5.28 +        public static Settings Default {
    5.29 +            get {
    5.30                  return defaultInstance;
    5.31              }
    5.32          }
    5.33 +        
    5.34 +        [global::System.Configuration.UserScopedSettingAttribute()]
    5.35 +        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    5.36 +        [global::System.Configuration.DefaultSettingValueAttribute("1")]
    5.37 +        public int DisplayBrightness {
    5.38 +            get {
    5.39 +                return ((int)(this["DisplayBrightness"]));
    5.40 +            }
    5.41 +            set {
    5.42 +                this["DisplayBrightness"] = value;
    5.43 +            }
    5.44 +        }
    5.45 +        
    5.46 +        [global::System.Configuration.UserScopedSettingAttribute()]
    5.47 +        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    5.48 +        [global::System.Configuration.DefaultSettingValueAttribute("Microsoft Sans Serif, 9.75pt")]
    5.49 +        public global::System.Drawing.Font DisplayFont {
    5.50 +            get {
    5.51 +                return ((global::System.Drawing.Font)(this["DisplayFont"]));
    5.52 +            }
    5.53 +            set {
    5.54 +                this["DisplayFont"] = value;
    5.55 +            }
    5.56 +        }
    5.57      }
    5.58  }
     6.1 --- a/Properties/Settings.settings	Tue Jul 08 16:41:29 2014 +0200
     6.2 +++ b/Properties/Settings.settings	Tue Jul 08 18:59:07 2014 +0200
     6.3 @@ -1,7 +1,12 @@
     6.4  <?xml version='1.0' encoding='utf-8'?>
     6.5 -<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
     6.6 -  <Profiles>
     6.7 -    <Profile Name="(Default)" />
     6.8 -  </Profiles>
     6.9 -  <Settings />
    6.10 -</SettingsFile>
    6.11 +<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="SharpDisplayManager.Properties" GeneratedClassName="Settings">
    6.12 +  <Profiles />
    6.13 +  <Settings>
    6.14 +    <Setting Name="DisplayBrightness" Type="System.Int32" Scope="User">
    6.15 +      <Value Profile="(Default)">1</Value>
    6.16 +    </Setting>
    6.17 +    <Setting Name="DisplayFont" Type="System.Drawing.Font" Scope="User">
    6.18 +      <Value Profile="(Default)">Microsoft Sans Serif, 9.75pt</Value>
    6.19 +    </Setting>
    6.20 +  </Settings>
    6.21 +</SettingsFile>
    6.22 \ No newline at end of file