Adding buttons to test our alignment setup.
Fixing a nasty bug in iStringFormat that would cause us to use the same instance in all marquee objects.
1.1 --- a/Server/MainForm.Designer.cs Fri Aug 22 08:24:51 2014 +0200
1.2 +++ b/Server/MainForm.Designer.cs Fri Aug 22 10:44:45 2014 +0200
1.3 @@ -31,6 +31,8 @@
1.4 this.components = new System.ComponentModel.Container();
1.5 this.panelDisplay = new System.Windows.Forms.Panel();
1.6 this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
1.7 + this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
1.8 + this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
1.9 this.fontDialog = new System.Windows.Forms.FontDialog();
1.10 this.timer = new System.Windows.Forms.Timer(this.components);
1.11 this.statusStrip = new System.Windows.Forms.StatusStrip();
1.12 @@ -57,13 +59,14 @@
1.13 this.buttonFont = new System.Windows.Forms.Button();
1.14 this.tabControl = new System.Windows.Forms.TabControl();
1.15 this.tabPageDesign = new System.Windows.Forms.TabPage();
1.16 + this.buttonAlignRight = new System.Windows.Forms.Button();
1.17 + this.buttonAlignCenter = new System.Windows.Forms.Button();
1.18 + this.buttonAlignLeft = new System.Windows.Forms.Button();
1.19 this.buttonRemoveColumn = new System.Windows.Forms.Button();
1.20 this.buttonAddColumn = new System.Windows.Forms.Button();
1.21 + this.checkBoxReverseScreen = new System.Windows.Forms.CheckBox();
1.22 this.buttonRemoveRow = new System.Windows.Forms.Button();
1.23 this.buttonAddRow = new System.Windows.Forms.Button();
1.24 - this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
1.25 - this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
1.26 - this.checkBoxReverseScreen = new System.Windows.Forms.CheckBox();
1.27 this.panelDisplay.SuspendLayout();
1.28 this.tableLayoutPanel.SuspendLayout();
1.29 this.statusStrip.SuspendLayout();
1.30 @@ -160,6 +163,39 @@
1.31 this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64);
1.32 this.tableLayoutPanel.TabIndex = 5;
1.33 //
1.34 + // marqueeLabelTop
1.35 + //
1.36 + this.marqueeLabelTop.AutoEllipsis = true;
1.37 + this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
1.38 + this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
1.39 + this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1);
1.40 + this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
1.41 + this.marqueeLabelTop.Name = "marqueeLabelTop";
1.42 + this.marqueeLabelTop.OwnTimer = false;
1.43 + this.marqueeLabelTop.PixelsPerSecond = 64;
1.44 + this.marqueeLabelTop.Separator = "|";
1.45 + this.marqueeLabelTop.Size = new System.Drawing.Size(254, 30);
1.46 + this.marqueeLabelTop.TabIndex = 2;
1.47 + this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
1.48 + this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.49 + this.marqueeLabelTop.UseCompatibleTextRendering = true;
1.50 + //
1.51 + // marqueeLabelBottom
1.52 + //
1.53 + this.marqueeLabelBottom.AutoEllipsis = true;
1.54 + this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
1.55 + this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 32);
1.56 + this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
1.57 + this.marqueeLabelBottom.Name = "marqueeLabelBottom";
1.58 + this.marqueeLabelBottom.OwnTimer = false;
1.59 + this.marqueeLabelBottom.PixelsPerSecond = 64;
1.60 + this.marqueeLabelBottom.Separator = "|";
1.61 + this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 31);
1.62 + this.marqueeLabelBottom.TabIndex = 3;
1.63 + this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
1.64 + this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.65 + this.marqueeLabelBottom.UseCompatibleTextRendering = true;
1.66 + //
1.67 // timer
1.68 //
1.69 this.timer.Enabled = true;
1.70 @@ -416,6 +452,9 @@
1.71 //
1.72 // tabPageDesign
1.73 //
1.74 + this.tabPageDesign.Controls.Add(this.buttonAlignRight);
1.75 + this.tabPageDesign.Controls.Add(this.buttonAlignCenter);
1.76 + this.tabPageDesign.Controls.Add(this.buttonAlignLeft);
1.77 this.tabPageDesign.Controls.Add(this.buttonRemoveColumn);
1.78 this.tabPageDesign.Controls.Add(this.checkBoxFixedPitchFontOnly);
1.79 this.tabPageDesign.Controls.Add(this.buttonAddColumn);
1.80 @@ -432,6 +471,36 @@
1.81 this.tabPageDesign.Text = "Design";
1.82 this.tabPageDesign.UseVisualStyleBackColor = true;
1.83 //
1.84 + // buttonAlignRight
1.85 + //
1.86 + this.buttonAlignRight.Location = new System.Drawing.Point(171, 105);
1.87 + this.buttonAlignRight.Name = "buttonAlignRight";
1.88 + this.buttonAlignRight.Size = new System.Drawing.Size(75, 23);
1.89 + this.buttonAlignRight.TabIndex = 20;
1.90 + this.buttonAlignRight.Text = "Align Right";
1.91 + this.buttonAlignRight.UseVisualStyleBackColor = true;
1.92 + this.buttonAlignRight.Click += new System.EventHandler(this.buttonAlignRight_Click);
1.93 + //
1.94 + // buttonAlignCenter
1.95 + //
1.96 + this.buttonAlignCenter.Location = new System.Drawing.Point(89, 106);
1.97 + this.buttonAlignCenter.Name = "buttonAlignCenter";
1.98 + this.buttonAlignCenter.Size = new System.Drawing.Size(75, 23);
1.99 + this.buttonAlignCenter.TabIndex = 19;
1.100 + this.buttonAlignCenter.Text = "Align Center";
1.101 + this.buttonAlignCenter.UseVisualStyleBackColor = true;
1.102 + this.buttonAlignCenter.Click += new System.EventHandler(this.buttonAlignCenter_Click);
1.103 + //
1.104 + // buttonAlignLeft
1.105 + //
1.106 + this.buttonAlignLeft.Location = new System.Drawing.Point(7, 106);
1.107 + this.buttonAlignLeft.Name = "buttonAlignLeft";
1.108 + this.buttonAlignLeft.Size = new System.Drawing.Size(75, 23);
1.109 + this.buttonAlignLeft.TabIndex = 18;
1.110 + this.buttonAlignLeft.Text = "Align Left";
1.111 + this.buttonAlignLeft.UseVisualStyleBackColor = true;
1.112 + this.buttonAlignLeft.Click += new System.EventHandler(this.buttonAlignLeft_Click);
1.113 + //
1.114 // buttonRemoveColumn
1.115 //
1.116 this.buttonRemoveColumn.Location = new System.Drawing.Point(89, 37);
1.117 @@ -452,6 +521,18 @@
1.118 this.buttonAddColumn.UseVisualStyleBackColor = true;
1.119 this.buttonAddColumn.Click += new System.EventHandler(this.buttonAddColumn_Click);
1.120 //
1.121 + // checkBoxReverseScreen
1.122 + //
1.123 + this.checkBoxReverseScreen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
1.124 + this.checkBoxReverseScreen.AutoSize = true;
1.125 + this.checkBoxReverseScreen.Location = new System.Drawing.Point(485, 6);
1.126 + this.checkBoxReverseScreen.Name = "checkBoxReverseScreen";
1.127 + this.checkBoxReverseScreen.Size = new System.Drawing.Size(101, 17);
1.128 + this.checkBoxReverseScreen.TabIndex = 14;
1.129 + this.checkBoxReverseScreen.Text = "Reverse screen";
1.130 + this.checkBoxReverseScreen.UseVisualStyleBackColor = true;
1.131 + this.checkBoxReverseScreen.CheckedChanged += new System.EventHandler(this.checkBoxReverseScreen_CheckedChanged);
1.132 + //
1.133 // buttonRemoveRow
1.134 //
1.135 this.buttonRemoveRow.Location = new System.Drawing.Point(7, 37);
1.136 @@ -472,51 +553,6 @@
1.137 this.buttonAddRow.UseVisualStyleBackColor = true;
1.138 this.buttonAddRow.Click += new System.EventHandler(this.buttonAddRow_Click);
1.139 //
1.140 - // marqueeLabelTop
1.141 - //
1.142 - this.marqueeLabelTop.AutoEllipsis = true;
1.143 - this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
1.144 - this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
1.145 - this.marqueeLabelTop.Location = new System.Drawing.Point(1, -9);
1.146 - this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
1.147 - this.marqueeLabelTop.Name = "marqueeLabelTop";
1.148 - this.marqueeLabelTop.OwnTimer = false;
1.149 - this.marqueeLabelTop.PixelsPerSecond = 64;
1.150 - this.marqueeLabelTop.Separator = "|";
1.151 - this.marqueeLabelTop.Size = new System.Drawing.Size(254, 1);
1.152 - this.marqueeLabelTop.TabIndex = 2;
1.153 - this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
1.154 - this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.155 - this.marqueeLabelTop.UseCompatibleTextRendering = true;
1.156 - //
1.157 - // marqueeLabelBottom
1.158 - //
1.159 - this.marqueeLabelBottom.AutoEllipsis = true;
1.160 - this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
1.161 - this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 2);
1.162 - this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
1.163 - this.marqueeLabelBottom.Name = "marqueeLabelBottom";
1.164 - this.marqueeLabelBottom.OwnTimer = false;
1.165 - this.marqueeLabelBottom.PixelsPerSecond = 64;
1.166 - this.marqueeLabelBottom.Separator = "|";
1.167 - this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 20);
1.168 - this.marqueeLabelBottom.TabIndex = 3;
1.169 - this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
1.170 - this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.171 - this.marqueeLabelBottom.UseCompatibleTextRendering = true;
1.172 - //
1.173 - // checkBoxReverseScreen
1.174 - //
1.175 - this.checkBoxReverseScreen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
1.176 - this.checkBoxReverseScreen.AutoSize = true;
1.177 - this.checkBoxReverseScreen.Location = new System.Drawing.Point(485, 6);
1.178 - this.checkBoxReverseScreen.Name = "checkBoxReverseScreen";
1.179 - this.checkBoxReverseScreen.Size = new System.Drawing.Size(101, 17);
1.180 - this.checkBoxReverseScreen.TabIndex = 14;
1.181 - this.checkBoxReverseScreen.Text = "Reverse screen";
1.182 - this.checkBoxReverseScreen.UseVisualStyleBackColor = true;
1.183 - this.checkBoxReverseScreen.CheckedChanged += new System.EventHandler(this.checkBoxReverseScreen_CheckedChanged);
1.184 - //
1.185 // MainForm
1.186 //
1.187 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
1.188 @@ -585,6 +621,9 @@
1.189 private System.Windows.Forms.Button buttonRemoveRow;
1.190 private System.Windows.Forms.Button buttonAddRow;
1.191 private System.Windows.Forms.CheckBox checkBoxReverseScreen;
1.192 + private System.Windows.Forms.Button buttonAlignRight;
1.193 + private System.Windows.Forms.Button buttonAlignCenter;
1.194 + private System.Windows.Forms.Button buttonAlignLeft;
1.195 }
1.196 }
1.197
2.1 --- a/Server/MainForm.cs Fri Aug 22 08:24:51 2014 +0200
2.2 +++ b/Server/MainForm.cs Fri Aug 22 10:44:45 2014 +0200
2.3 @@ -760,6 +760,23 @@
2.4 }
2.5 }
2.6
2.7 + private void buttonAlignLeft_Click(object sender, EventArgs e)
2.8 + {
2.9 + marqueeLabelTop.TextAlign = ContentAlignment.MiddleLeft;
2.10 + marqueeLabelBottom.TextAlign = ContentAlignment.MiddleLeft;
2.11 + }
2.12 +
2.13 + private void buttonAlignCenter_Click(object sender, EventArgs e)
2.14 + {
2.15 + marqueeLabelTop.TextAlign = ContentAlignment.MiddleCenter;
2.16 + marqueeLabelBottom.TextAlign = ContentAlignment.MiddleCenter;
2.17 + }
2.18 +
2.19 + private void buttonAlignRight_Click(object sender, EventArgs e)
2.20 + {
2.21 + marqueeLabelTop.TextAlign = ContentAlignment.MiddleRight;
2.22 + marqueeLabelBottom.TextAlign = ContentAlignment.MiddleRight;
2.23 + }
2.24
2.25 }
2.26
3.1 --- a/Server/MarqueeLabel.cs Fri Aug 22 08:24:51 2014 +0200
3.2 +++ b/Server/MarqueeLabel.cs Fri Aug 22 10:44:45 2014 +0200
3.3 @@ -20,7 +20,7 @@
3.4 private SizeF iTextSize;
3.5 private SizeF iSeparatorSize;
3.6 private SizeF iScrollSize;
3.7 - //private ContentAlignment iRequestedContentAlignment;
3.8 + private ContentAlignment iRequestedContentAlignment;
3.9
3.10 [Category("Appearance")]
3.11 [Description("Separator in our scrolling loop.")]
3.12 @@ -84,13 +84,13 @@
3.13 PixelsLeft = 0;
3.14 CurrentPosition = 0;
3.15 iBrush = new SolidBrush(ForeColor);
3.16 - //iRequestedContentAlignment = TextAlign;
3.17 + iRequestedContentAlignment = TextAlign;
3.18
3.19 - //Following is needed if we ever switch from Label to Control base class.
3.20 + //Following is needed if we ever switch from Label to Control base class.
3.21 //Without it you get some pretty nasty flicker
3.22 //SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
3.23 //SetStyle(ControlStyles.UserPaint, true);
3.24 - //SetStyle(ControlStyles.AllPaintingInWmPaint, true);
3.25 + //SetStyle(ControlStyles.AllPaintingInWmPaint, true);
3.26 //SetStyle(ControlStyles.DoubleBuffer, true);
3.27 }
3.28
3.29 @@ -161,8 +161,7 @@
3.30
3.31 private StringFormat GetStringFormatFromContentAllignment(ContentAlignment ca)
3.32 {
3.33 - StringFormat format = new StringFormat();
3.34 - format = StringFormat.GenericTypographic;
3.35 + StringFormat format = new StringFormat(StringFormat.GenericTypographic);
3.36 switch (ca)
3.37 {
3.38 case ContentAlignment.TopCenter:
3.39 @@ -251,9 +250,14 @@
3.40 //ContentAlignment original = TextAlign;
3.41 TextAlign = ContentAlignment.MiddleLeft;
3.42 //Make sure our original text alignment remain the same even though we override it when scrolling
3.43 - //iRequestedContentAlignment = original;
3.44 + //iRequestedContentAlignment = original;
3.45 //iStringFormat will get updated in OnTextAlignChanged
3.46 - //iStringFormat.Alignment = StringAlignment.Near;
3.47 + //StringFormat.Alignment = StringAlignment.Near;
3.48 + }
3.49 + else
3.50 + {
3.51 + //We don't need to scroll so make sure the desired alignment is used
3.52 + TextAlign = iRequestedContentAlignment;
3.53 }
3.54 }
3.55
3.56 @@ -273,10 +277,16 @@
3.57
3.58 protected override void OnTextAlignChanged(EventArgs e)
3.59 {
3.60 + iRequestedContentAlignment = TextAlign;
3.61 + if (NeedToScroll())
3.62 + {
3.63 + //Always align left when scrolling to avoid bugs
3.64 + TextAlign = ContentAlignment.MiddleLeft;
3.65 + }
3.66 iStringFormat = GetStringFormatFromContentAllignment(TextAlign);
3.67 - //iRequestedContentAlignment = TextAlign;
3.68 + Invalidate();
3.69 + //
3.70 base.OnTextAlignChanged(e);
3.71 -
3.72 }
3.73
3.74 protected override void OnPaint(PaintEventArgs e)
3.75 @@ -287,7 +297,7 @@
3.76 {
3.77 //Draw it all in a single call would take kerning into account
3.78 //e.Graphics.TranslateTransform(-(float)CurrentPosition, 0);
3.79 - //e.Graphics.DrawString(Text + Separator + Text, Font, iBrush, ClientRectangle, iStringFormat);
3.80 + //e.Graphics.DrawString(Text + Separator + Text, Font, iBrush, ClientRectangle, StringFormat);
3.81
3.82 //Doing separate draw operation allows us not to take kerning into account between separator and string
3.83 //Draw the first one