# HG changeset patch # User StephaneLenclud # Date 1451148221 -3600 # Node ID 391bce3c83682f55525b19a960a1d7f550939df2 # Parent f5a6cec31e817cfcfc3eb0e796730fea726e8751 Improving layout change workflow efficiency. diff -r f5a6cec31e81 -r 391bce3c8368 Client/MainForm.cs --- a/Client/MainForm.cs Wed Dec 23 18:54:38 2015 +0100 +++ b/Client/MainForm.cs Sat Dec 26 17:43:41 2015 +0100 @@ -238,7 +238,7 @@ new TextField(1, textBoxBottom.Text, Alignment), new TextField(2, "Third text field", Alignment), new TextField(3, "Forth text field", Alignment), - //recording + recording }); } @@ -363,9 +363,9 @@ iClient.CreateFields(new DataField[] { textFieldTop, + textFieldBottom, indicator1, - indicator2, - textFieldBottom, + indicator2, indicator3, indicator4 }); diff -r f5a6cec31e81 -r 391bce3c8368 Server/ClientData.cs --- a/Server/ClientData.cs Wed Dec 23 18:54:38 2015 +0100 +++ b/Server/ClientData.cs Sat Dec 26 17:43:41 2015 +0100 @@ -21,6 +21,7 @@ Fields = new List(); Layout = new TableLayout(1, 2); //Default to one column and two rows Callback = aCallback; + HasNewLayout = true; } public string SessionId { get; set; } @@ -29,6 +30,8 @@ public TableLayout Layout { get; set; } public ICallback Callback { get; set; } + public bool HasNewLayout { get; set; } + //Client management public DateTime LastSwitchTime { get; set; } } diff -r f5a6cec31e81 -r 391bce3c8368 Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Wed Dec 23 18:54:38 2015 +0100 +++ b/Server/MainForm.Designer.cs Sat Dec 26 17:43:41 2015 +0100 @@ -40,7 +40,7 @@ this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.panelDisplay = new System.Windows.Forms.Panel(); - this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.iTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel(); this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel(); this.fontDialog = new System.Windows.Forms.FontDialog(); @@ -112,7 +112,7 @@ this.toolTip = new System.Windows.Forms.ToolTip(this.components); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.panelDisplay.SuspendLayout(); - this.tableLayoutPanel.SuspendLayout(); + this.iTableLayoutPanel.SuspendLayout(); this.statusStrip.SuspendLayout(); this.tabPageClients.SuspendLayout(); this.tabPageDisplay.SuspendLayout(); @@ -130,35 +130,35 @@ // panelDisplay // this.panelDisplay.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.panelDisplay.Controls.Add(this.tableLayoutPanel); + this.panelDisplay.Controls.Add(this.iTableLayoutPanel); this.panelDisplay.Location = new System.Drawing.Point(173, 40); this.panelDisplay.Margin = new System.Windows.Forms.Padding(0); this.panelDisplay.Name = "panelDisplay"; this.panelDisplay.Size = new System.Drawing.Size(258, 66); this.panelDisplay.TabIndex = 12; // - // tableLayoutPanel + // iTableLayoutPanel // - this.tableLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.iTableLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.tableLayoutPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.tableLayoutPanel.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.tableLayoutPanel.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single; - this.tableLayoutPanel.ColumnCount = 1; - this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel.Controls.Add(this.marqueeLabelTop, 0, 0); - this.tableLayoutPanel.Controls.Add(this.marqueeLabelBottom, 0, 1); - this.tableLayoutPanel.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize; - this.tableLayoutPanel.Location = new System.Drawing.Point(0, 0); - this.tableLayoutPanel.Margin = new System.Windows.Forms.Padding(0); - this.tableLayoutPanel.Name = "tableLayoutPanel"; - this.tableLayoutPanel.RowCount = 2; - this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64); - this.tableLayoutPanel.TabIndex = 5; - this.tableLayoutPanel.SizeChanged += new System.EventHandler(this.tableLayoutPanel_SizeChanged); + this.iTableLayoutPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.iTableLayoutPanel.BackColor = System.Drawing.SystemColors.ControlLightLight; + this.iTableLayoutPanel.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single; + this.iTableLayoutPanel.ColumnCount = 1; + this.iTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.iTableLayoutPanel.Controls.Add(this.marqueeLabelTop, 0, 0); + this.iTableLayoutPanel.Controls.Add(this.marqueeLabelBottom, 0, 1); + this.iTableLayoutPanel.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize; + this.iTableLayoutPanel.Location = new System.Drawing.Point(0, 0); + this.iTableLayoutPanel.Margin = new System.Windows.Forms.Padding(0); + this.iTableLayoutPanel.Name = "iTableLayoutPanel"; + this.iTableLayoutPanel.RowCount = 2; + this.iTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.iTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.iTableLayoutPanel.Size = new System.Drawing.Size(256, 64); + this.iTableLayoutPanel.TabIndex = 5; + this.iTableLayoutPanel.SizeChanged += new System.EventHandler(this.tableLayoutPanel_SizeChanged); // // marqueeLabelTop // @@ -954,8 +954,8 @@ this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); this.Resize += new System.EventHandler(this.MainForm_Resize); this.panelDisplay.ResumeLayout(false); - this.tableLayoutPanel.ResumeLayout(false); - this.tableLayoutPanel.PerformLayout(); + this.iTableLayoutPanel.ResumeLayout(false); + this.iTableLayoutPanel.PerformLayout(); this.statusStrip.ResumeLayout(false); this.statusStrip.PerformLayout(); this.tabPageClients.ResumeLayout(false); @@ -990,7 +990,7 @@ private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSpring; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelPower; private System.Windows.Forms.Panel panelDisplay; - private System.Windows.Forms.TableLayoutPanel tableLayoutPanel; + private System.Windows.Forms.TableLayoutPanel iTableLayoutPanel; private MarqueeLabel marqueeLabelTop; private MarqueeLabel marqueeLabelBottom; private System.Windows.Forms.TabPage tabPageClients; diff -r f5a6cec31e81 -r 391bce3c8368 Server/MainForm.cs --- a/Server/MainForm.cs Wed Dec 23 18:54:38 2015 +0100 +++ b/Server/MainForm.cs Sat Dec 26 17:43:41 2015 +0100 @@ -144,7 +144,7 @@ //We have a bug when drawing minimized and reusing our bitmap //Though I could not reproduce it on Windows 10 - iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb); + iBmp = new System.Drawing.Bitmap(iTableLayoutPanel.Width, iTableLayoutPanel.Height, PixelFormat.Format32bppArgb); iCreateBitmap = false; //Minimize our window if desired @@ -668,7 +668,7 @@ if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel) { //Set the fonts to all our labels in our layout - foreach (Control ctrl in tableLayoutPanel.Controls) + foreach (Control ctrl in iTableLayoutPanel.Controls) { if (ctrl is MarqueeLabel) { @@ -704,7 +704,7 @@ MarqueeLabel label = null; //Get the first label control we can find - foreach (Control ctrl in tableLayoutPanel.Controls) + foreach (Control ctrl in iTableLayoutPanel.Controls) { if (ctrl is MarqueeLabel) { @@ -728,12 +728,12 @@ private void buttonCapture_Click(object sender, EventArgs e) { - System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height); - tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle); + System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(iTableLayoutPanel.Width, iTableLayoutPanel.Height); + iTableLayoutPanel.DrawToBitmap(bmp, iTableLayoutPanel.ClientRectangle); //Bitmap bmpToSave = new Bitmap(bmp); bmp.Save("D:\\capture.png"); - ((MarqueeLabel)tableLayoutPanel.Controls[0]).Text = "Captured"; + ((MarqueeLabel)iTableLayoutPanel.Controls[0]).Text = "Captured"; /* string outputFileName = "d:\\capture.png"; @@ -876,7 +876,7 @@ UpdateNetworkSignal(LastTickTime, NewTickTime); //Update animation for all our marquees - foreach (Control ctrl in tableLayoutPanel.Controls) + foreach (Control ctrl in iTableLayoutPanel.Controls) { if (ctrl is MarqueeLabel) { @@ -896,10 +896,10 @@ //Draw to bitmap if (iCreateBitmap) { - iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb); + iBmp = new System.Drawing.Bitmap(iTableLayoutPanel.Width, iTableLayoutPanel.Height, PixelFormat.Format32bppArgb); iCreateBitmap = false; } - tableLayoutPanel.DrawToBitmap(iBmp, tableLayoutPanel.ClientRectangle); + iTableLayoutPanel.DrawToBitmap(iBmp, iTableLayoutPanel.ClientRectangle); //iBmp.Save("D:\\capture.png"); //Send it to our display @@ -1057,10 +1057,10 @@ { //Load settings checkBoxShowBorders.Checked = cds.ShowBorders; - tableLayoutPanel.CellBorderStyle = (cds.ShowBorders ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); + iTableLayoutPanel.CellBorderStyle = (cds.ShowBorders ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); //Set the proper font to each of our labels - foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls) + foreach (MarqueeLabel ctrl in iTableLayoutPanel.Controls) { ctrl.Font = cds.Font; } @@ -1123,7 +1123,7 @@ //We have a display connection //Reflect that in our UI - tableLayoutPanel.Enabled = true; + iTableLayoutPanel.Enabled = true; panelDisplay.Enabled = true; //Only setup brightness if display is open @@ -1195,7 +1195,7 @@ //Display is connection not available //Reflect that in our UI checkBoxShowVolumeLabel.Enabled = false; - tableLayoutPanel.Enabled = false; + iTableLayoutPanel.Enabled = false; panelDisplay.Enabled = false; buttonFill.Enabled = false; buttonClear.Enabled = false; @@ -1228,7 +1228,7 @@ private void checkBoxShowBorders_CheckedChanged(object sender, EventArgs e) { //Save our show borders setting - tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); + iTableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); cds.ShowBorders = checkBoxShowBorders.Checked; Properties.Settings.Default.Save(); CheckFontHeight(); @@ -1382,9 +1382,9 @@ /// private void ClearLayout() { - tableLayoutPanel.Controls.Clear(); - tableLayoutPanel.RowStyles.Clear(); - tableLayoutPanel.ColumnStyles.Clear(); + iTableLayoutPanel.Controls.Clear(); + iTableLayoutPanel.RowStyles.Clear(); + iTableLayoutPanel.ColumnStyles.Clear(); iCurrentClientData = null; } @@ -1529,6 +1529,8 @@ Debug.Print("SetClientLayoutThreadSafe: Layout updated."); //Set our client layout then client.Layout = aLayout; + //So that next time we update all our fields at ones + client.HasNewLayout = true; //Layout has changed clear our fields then client.Fields.Clear(); // @@ -1564,7 +1566,7 @@ } /// - /// + /// Set a data field in the given client. /// /// /// @@ -1584,30 +1586,32 @@ layoutChanged = true; } + //Keep our previous field in there + DataField previousField = client.Fields[aField.Index]; //Now that we know our fields are in place just update that one client.Fields[aField.Index] = aField; - if (client.Fields[aField.Index].IsSameLayout(aField)) + if (previousField.IsSameLayout(aField)) { //If we are updating a field in our current client we need to update it in our panel if (aSessionId == iCurrentClientSessionId) { - if (aField.IsTextField && aField.Index < tableLayoutPanel.Controls.Count && tableLayoutPanel.Controls[aField.Index] is MarqueeLabel) + if (aField.IsTextField && aField.Index < iTableLayoutPanel.Controls.Count && iTableLayoutPanel.Controls[aField.Index] is MarqueeLabel) { TextField textField=(TextField)aField; //Text field control already in place, just change the text - MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aField.Index]; + MarqueeLabel label = (MarqueeLabel)iTableLayoutPanel.Controls[aField.Index]; contentChanged = (label.Text != textField.Text || label.TextAlign != textField.Alignment); label.Text = textField.Text; label.TextAlign = textField.Alignment; } - else if (aField.IsBitmapField && aField.Index < tableLayoutPanel.Controls.Count && tableLayoutPanel.Controls[aField.Index] is PictureBox) + else if (aField.IsBitmapField && aField.Index < iTableLayoutPanel.Controls.Count && iTableLayoutPanel.Controls[aField.Index] is PictureBox) { BitmapField bitmapField = (BitmapField)aField; contentChanged = true; //TODO: Bitmap comp or should we leave that to clients? //Bitmap field control already in place just change the bitmap - PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index]; + PictureBox pictureBox = (PictureBox)iTableLayoutPanel.Controls[aField.Index]; pictureBox.Image = bitmapField.Bitmap; } else @@ -1664,10 +1668,33 @@ } else { - //Put each our text fields in a label control - foreach (DataField field in aFields) + ClientData client = iClients[aSessionId]; + + if (client.HasNewLayout) { - SetClientField(aSessionId, field); + //TODO: Assert client.Count == 0 + //Our layout was just changed + //Do some special handling to avoid re-creating our panel N times, once for each fields + client.HasNewLayout = false; + //Just set all our fields then + client.Fields.AddRange(aFields); + //Try switch to that client + SetCurrentClient(aSessionId); + + //If we are updating the current client update our panel + if (aSessionId == iCurrentClientSessionId) + { + //Apply layout and set data fields. + UpdateTableLayoutPanel(iCurrentClientData); + } + } + else + { + //Put each our text fields in a label control + foreach (DataField field in aFields) + { + SetClientField(aSessionId, field); + } } } } @@ -1780,20 +1807,22 @@ /// private void UpdateTableLayoutRowStyles() { - foreach (RowStyle rowStyle in tableLayoutPanel.RowStyles) + foreach (RowStyle rowStyle in iTableLayoutPanel.RowStyles) { rowStyle.SizeType = SizeType.Percent; - rowStyle.Height = 100 / tableLayoutPanel.RowCount; + rowStyle.Height = 100 / iTableLayoutPanel.RowCount; } } /// /// Update our display table layout. + /// Will instanciated every field control as defined by our client. + /// Fields must be specified by rows from the left. /// /// private void UpdateTableLayoutPanel(ClientData aClient) { - Debug.Print("UpdateClientTreeViewNode"); + Debug.Print("UpdateTableLayoutPanel"); if (aClient == null) { @@ -1806,37 +1835,41 @@ int fieldCount = 0; //First clean our current panel - tableLayoutPanel.Controls.Clear(); - tableLayoutPanel.RowStyles.Clear(); - tableLayoutPanel.ColumnStyles.Clear(); - tableLayoutPanel.RowCount = 0; - tableLayoutPanel.ColumnCount = 0; + iTableLayoutPanel.Controls.Clear(); + iTableLayoutPanel.RowStyles.Clear(); + iTableLayoutPanel.ColumnStyles.Clear(); + iTableLayoutPanel.RowCount = 0; + iTableLayoutPanel.ColumnCount = 0; - while (tableLayoutPanel.RowCount < layout.Rows.Count) + //Then recreate our rows... + while (iTableLayoutPanel.RowCount < layout.Rows.Count) { - tableLayoutPanel.RowCount++; + iTableLayoutPanel.RowCount++; } - while (tableLayoutPanel.ColumnCount < layout.Columns.Count) + // ...and columns + while (iTableLayoutPanel.ColumnCount < layout.Columns.Count) { - tableLayoutPanel.ColumnCount++; + iTableLayoutPanel.ColumnCount++; } - for (int i = 0; i < tableLayoutPanel.ColumnCount; i++) + //For each column + for (int i = 0; i < iTableLayoutPanel.ColumnCount; i++) { //Create our column styles - this.tableLayoutPanel.ColumnStyles.Add(layout.Columns[i]); + this.iTableLayoutPanel.ColumnStyles.Add(layout.Columns[i]); - for (int j = 0; j < tableLayoutPanel.RowCount; j++) + //For each rows + for (int j = 0; j < iTableLayoutPanel.RowCount; j++) { if (i == 0) { //Create our row styles - this.tableLayoutPanel.RowStyles.Add(layout.Rows[j]); + this.iTableLayoutPanel.RowStyles.Add(layout.Rows[j]); } //Check if we already have a control - Control existingControl = tableLayoutPanel.GetControlFromPosition(i,j); + Control existingControl = iTableLayoutPanel.GetControlFromPosition(i,j); if (existingControl!=null) { //We already have a control in that cell as a results of row/col spanning @@ -1847,14 +1880,14 @@ fieldCount++; //Check if a client field already exists for that cell - if (aClient.Fields.Count <= tableLayoutPanel.Controls.Count) + if (aClient.Fields.Count <= iTableLayoutPanel.Controls.Count) { //No client field specified, create a text field by default aClient.Fields.Add(new TextField(aClient.Fields.Count)); } // - DataField field = aClient.Fields[tableLayoutPanel.Controls.Count]; + DataField field = aClient.Fields[iTableLayoutPanel.Controls.Count]; if (!field.IsTableField) { //That field is not taking part in our table layout then @@ -1868,10 +1901,10 @@ Control control = CreateControlForDataField(tableField); //Add newly created control to our table layout at the specified row and column - tableLayoutPanel.Controls.Add(control, i, j); + iTableLayoutPanel.Controls.Add(control, i, j); //Make sure we specify row and column span for that new control - tableLayoutPanel.SetRowSpan(control, tableField.RowSpan); - tableLayoutPanel.SetColumnSpan(control, tableField.ColumnSpan); + iTableLayoutPanel.SetRowSpan(control, tableField.RowSpan); + iTableLayoutPanel.SetColumnSpan(control, tableField.ColumnSpan); } } @@ -2018,7 +2051,7 @@ Properties.Settings.Default.Save(); //Update our text fields - foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls) + foreach (MarqueeLabel ctrl in iTableLayoutPanel.Controls) { ctrl.Separator = cds.Separator; } diff -r f5a6cec31e81 -r 391bce3c8368 Server/MainForm.resx --- a/Server/MainForm.resx Wed Dec 23 18:54:38 2015 +0100 +++ b/Server/MainForm.resx Sat Dec 26 17:43:41 2015 +0100 @@ -185,9 +185,6 @@ WSC3/b/CbwiR/gNzbuWksIMBOAAAAABJRU5ErkJggg== - - 315, 17 - 405, 17 diff -r f5a6cec31e81 -r 391bce3c8368 Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Wed Dec 23 18:54:38 2015 +0100 +++ b/Server/SharpDisplayManager.csproj Sat Dec 26 17:43:41 2015 +0100 @@ -204,7 +204,6 @@ - SettingsSingleFileGenerator