# HG changeset patch # User StephaneLenclud # Date 1451168875 -3600 # Node ID 01c72c29cfaf6f4dfe14e262b97412b1a6616610 # Parent 391bce3c83682f55525b19a960a1d7f550939df2 Upgrade to SharpLibDisplay 0.1.3. Much improved layout construction. Not relying on field and control index anymore. diff -r 391bce3c8368 -r 01c72c29cfaf Client/MainForm.cs --- a/Client/MainForm.cs Sat Dec 26 17:43:41 2015 +0100 +++ b/Client/MainForm.cs Sat Dec 26 23:27:55 2015 +0100 @@ -52,7 +52,7 @@ { InitializeComponent(); Alignment = ContentAlignment.MiddleLeft; - iTextFieldTop = new TextField(0); + iTextFieldTop = new TextField(); } public void OnCloseOrder() @@ -212,8 +212,8 @@ //Set our fields iClient.CreateFields(new DataField[] { - new TextField(0, textBoxTop.Text, Alignment), - new TextField(1, textBoxBottom.Text, Alignment) + new TextField(textBoxTop.Text, Alignment, 0, 0), + new TextField(textBoxBottom.Text, Alignment, 0, 1) }); } @@ -234,10 +234,10 @@ //Set texts iClient.CreateFields(new DataField[] { - new TextField(0, textBoxTop.Text, Alignment), - new TextField(1, textBoxBottom.Text, Alignment), - new TextField(2, "Third text field", Alignment), - new TextField(3, "Forth text field", Alignment), + new TextField(textBoxTop.Text, Alignment, 0, 0), + new TextField(textBoxBottom.Text, Alignment, 0, 1), + new TextField("Third text field", Alignment, 1, 0), + new TextField("Forth text field", Alignment, 1, 1), recording }); @@ -260,7 +260,7 @@ graphics.DrawLine(blackPen, x1, y2, x2, y1); } - DataField field = new BitmapField(0, bitmap); + DataField field = new BitmapField(bitmap); //field.ColumnSpan = 2; iClient.SetField(field); } @@ -301,16 +301,15 @@ } //Create a bitmap field from the bitmap we just created - BitmapField field = new BitmapField(0, bitmap); //We want our bitmap field to span across two rows - field.RowSpan = 2; - + BitmapField bitmapField = new BitmapField(bitmap, 0, 0, 1, 2); + //Set texts iClient.CreateFields(new DataField[] { - field, - new TextField(1, textBoxTop.Text, Alignment), - new TextField(2, textBoxBottom.Text, Alignment) + bitmapField, + new TextField(textBoxTop.Text, Alignment, 1, 0), + new TextField(textBoxBottom.Text, Alignment, 1, 1) }); } @@ -343,21 +342,17 @@ } //Create a bitmap field from the bitmap we just created - DataField indicator1 = new BitmapField(2, bitmap); + DataField indicator1 = new BitmapField(bitmap, 1, 0); //Create a bitmap field from the bitmap we just created - DataField indicator2 = new BitmapField(3, bitmap); + DataField indicator2 = new BitmapField(bitmap, 1, 1); //Create a bitmap field from the bitmap we just created - DataField indicator3 = new BitmapField(4, bitmap); + DataField indicator3 = new BitmapField(bitmap, 1, 2); //Create a bitmap field from the bitmap we just created - DataField indicator4 = new BitmapField(5, bitmap); + DataField indicator4 = new BitmapField(bitmap, 1, 3); // - TextField textFieldTop = new TextField(0, textBoxTop.Text, Alignment); - textFieldTop.RowSpan = 2; - - TextField textFieldBottom = new TextField(1, textBoxBottom.Text, Alignment); - textFieldBottom.RowSpan = 2; - + TextField textFieldTop = new TextField(textBoxTop.Text, Alignment, 0, 0, 1, 2); + TextField textFieldBottom = new TextField(textBoxBottom.Text, Alignment, 0, 2, 1, 2); //Set texts iClient.CreateFields(new DataField[] @@ -377,8 +372,8 @@ bool res = iClient.SetFields(new DataField[] { - new TextField(0, textBoxTop.Text, Alignment), - new TextField(1, textBoxBottom.Text, Alignment) + new TextField(textBoxTop.Text, Alignment,0,0), + new TextField(textBoxBottom.Text, Alignment,0,1) }); if (!res) @@ -397,7 +392,7 @@ //Set our fields iClient.CreateFields(new DataField[] { - new TextField(0, textBoxTop.Text, Alignment) + new TextField(textBoxTop.Text, Alignment) }); } } diff -r 391bce3c8368 -r 01c72c29cfaf Client/SharpDisplayClient.csproj --- a/Client/SharpDisplayClient.csproj Sat Dec 26 17:43:41 2015 +0100 +++ b/Client/SharpDisplayClient.csproj Sat Dec 26 23:27:55 2015 +0100 @@ -85,7 +85,7 @@ - ..\packages\SharpLibDisplay.0.1.2\lib\net40\SharpLibDisplay.dll + ..\packages\SharpLibDisplay.0.1.3\lib\net40\SharpLibDisplay.dll True diff -r 391bce3c8368 -r 01c72c29cfaf Client/packages.config --- a/Client/packages.config Sat Dec 26 17:43:41 2015 +0100 +++ b/Client/packages.config Sat Dec 26 23:27:55 2015 +0100 @@ -1,4 +1,4 @@  - + \ No newline at end of file diff -r 391bce3c8368 -r 01c72c29cfaf Server/ClientData.cs --- a/Server/ClientData.cs Sat Dec 26 17:43:41 2015 +0100 +++ b/Server/ClientData.cs Sat Dec 26 23:27:55 2015 +0100 @@ -34,5 +34,46 @@ //Client management public DateTime LastSwitchTime { get; set; } + + /// + /// Look up the corresponding field in our field collection. + /// + /// + /// + public DataField FindSameFieldAs(DataField aField) + { + foreach (DataField field in Fields) + { + if (field.IsSameAs(aField)) + { + return field; + } + } + + return null; + } + + + /// + /// Look up the corresponding field in our field collection. + /// + /// + /// + public int FindSameFieldIndex(DataField aField) + { + int i = 0; + foreach (DataField field in Fields) + { + if (field.IsSameAs(aField)) + { + return i; + } + i++; + } + + return -1; + } + + } } diff -r 391bce3c8368 -r 01c72c29cfaf Server/MainForm.cs --- a/Server/MainForm.cs Sat Dec 26 17:43:41 2015 +0100 +++ b/Server/MainForm.cs Sat Dec 26 23:27:55 2015 +0100 @@ -1565,6 +1565,9 @@ } } + + + /// /// Set a data field in the given client. /// @@ -1578,40 +1581,49 @@ bool layoutChanged = false; bool contentChanged = true; - //Make sure all our fields are in place - while (client.Fields.Count < (aField.Index + 1)) + //Fetch our field index + int fieldIndex = client.FindSameFieldIndex(aField); + + if (fieldIndex < 0) { - //Add a data field with proper index - client.Fields.Add(new TextField(client.Fields.Count)); - layoutChanged = true; + //No corresponding field, just bail out + return; } //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; + DataField previousField = client.Fields[fieldIndex]; + //Just update that field then + client.Fields[fieldIndex] = aField; + if (!aField.IsTableField) + { + //We are done then if that field is not in our table layout + return; + } + + TableField tableField = (TableField) 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 < iTableLayoutPanel.Controls.Count && iTableLayoutPanel.Controls[aField.Index] is MarqueeLabel) + Control ctrl=iTableLayoutPanel.GetControlFromPosition(tableField.Column, tableField.Row); + if (aField.IsTextField && ctrl is MarqueeLabel) { TextField textField=(TextField)aField; //Text field control already in place, just change the text - MarqueeLabel label = (MarqueeLabel)iTableLayoutPanel.Controls[aField.Index]; + MarqueeLabel label = (MarqueeLabel)ctrl; contentChanged = (label.Text != textField.Text || label.TextAlign != textField.Alignment); label.Text = textField.Text; label.TextAlign = textField.Alignment; } - else if (aField.IsBitmapField && aField.Index < iTableLayoutPanel.Controls.Count && iTableLayoutPanel.Controls[aField.Index] is PictureBox) + else if (aField.IsBitmapField && ctrl 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)iTableLayoutPanel.Controls[aField.Index]; + PictureBox pictureBox = (PictureBox)ctrl; pictureBox.Image = bitmapField.Bitmap; } else @@ -1687,6 +1699,8 @@ //Apply layout and set data fields. UpdateTableLayoutPanel(iCurrentClientData); } + + UpdateClientTreeViewNode(client); } else { @@ -1832,7 +1846,6 @@ TableLayout layout = aClient.Layout; - int fieldCount = 0; //First clean our current panel iTableLayoutPanel.Controls.Clear(); @@ -1867,55 +1880,35 @@ //Create our row styles this.iTableLayoutPanel.RowStyles.Add(layout.Rows[j]); } - - //Check if we already have a control - Control existingControl = iTableLayoutPanel.GetControlFromPosition(i,j); - if (existingControl!=null) + else { - //We already have a control in that cell as a results of row/col spanning - //Move on to next cell then continue; } - - fieldCount++; - - //Check if a client field already exists for that cell - 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[iTableLayoutPanel.Controls.Count]; - if (!field.IsTableField) - { - //That field is not taking part in our table layout then - //We should be ok I guess - continue; - } - - TableField tableField = (TableField)field; - - //Create a control corresponding to the field specified for that cell - Control control = CreateControlForDataField(tableField); - - //Add newly created control to our table layout at the specified row and column - iTableLayoutPanel.Controls.Add(control, i, j); - //Make sure we specify row and column span for that new control - iTableLayoutPanel.SetRowSpan(control, tableField.RowSpan); - iTableLayoutPanel.SetColumnSpan(control, tableField.ColumnSpan); } } - // - while (aClient.Fields.Count > fieldCount) + //For each field + foreach (DataField field in aClient.Fields) { - //We have too much fields for this layout - //Just discard them until we get there - aClient.Fields.RemoveAt(aClient.Fields.Count-1); + if (!field.IsTableField) + { + //That field is not taking part in our table layout skip it + continue; + } + + TableField tableField = (TableField)field; + + //Create a control corresponding to the field specified for that cell + Control control = CreateControlForDataField(tableField); + + //Add newly created control to our table layout at the specified row and column + iTableLayoutPanel.Controls.Add(control, tableField.Column, tableField.Row); + //Make sure we specify column and row span for that new control + iTableLayoutPanel.SetColumnSpan(control, tableField.ColumnSpan); + iTableLayoutPanel.SetRowSpan(control, tableField.RowSpan); } + CheckFontHeight(); } @@ -1935,7 +1928,7 @@ label.Dock = System.Windows.Forms.DockStyle.Fill; label.Location = new System.Drawing.Point(1, 1); label.Margin = new System.Windows.Forms.Padding(0); - label.Name = "marqueeLabel" + aField.Index; + label.Name = "marqueeLabel" + aField; label.OwnTimer = false; label.PixelsPerSecond = cds.ScrollingSpeedInPixelsPerSecond; label.Separator = cds.Separator; diff -r 391bce3c8368 -r 01c72c29cfaf Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Sat Dec 26 17:43:41 2015 +0100 +++ b/Server/SharpDisplayManager.csproj Sat Dec 26 23:27:55 2015 +0100 @@ -121,7 +121,7 @@ ..\packages\NAudio.1.7.3\lib\net35\NAudio.dll - ..\packages\SharpLibDisplay.0.1.2\lib\net40\SharpLibDisplay.dll + ..\packages\SharpLibDisplay.0.1.3\lib\net40\SharpLibDisplay.dll True diff -r 391bce3c8368 -r 01c72c29cfaf Server/packages.config --- a/Server/packages.config Sat Dec 26 17:43:41 2015 +0100 +++ b/Server/packages.config Sat Dec 26 23:27:55 2015 +0100 @@ -2,7 +2,7 @@ - +