Support row and column span.
1.1 --- a/Client/MainForm.Designer.cs Mon Oct 13 21:42:42 2014 +0200
1.2 +++ b/Client/MainForm.Designer.cs Tue Oct 14 19:32:09 2014 +0200
1.3 @@ -37,6 +37,7 @@
1.4 this.buttonSetTopText = new System.Windows.Forms.Button();
1.5 this.buttonLayoutUpdate = new System.Windows.Forms.Button();
1.6 this.buttonSetBitmap = new System.Windows.Forms.Button();
1.7 + this.buttonLayoutUpdatWithSpan = new System.Windows.Forms.Button();
1.8 this.SuspendLayout();
1.9 //
1.10 // buttonSetText
1.11 @@ -123,11 +124,22 @@
1.12 this.buttonSetBitmap.UseVisualStyleBackColor = true;
1.13 this.buttonSetBitmap.Click += new System.EventHandler(this.buttonSetBitmap_Click);
1.14 //
1.15 + // buttonLayoutUpdatWithSpan
1.16 + //
1.17 + this.buttonLayoutUpdatWithSpan.Location = new System.Drawing.Point(176, 189);
1.18 + this.buttonLayoutUpdatWithSpan.Name = "buttonLayoutUpdatWithSpan";
1.19 + this.buttonLayoutUpdatWithSpan.Size = new System.Drawing.Size(75, 23);
1.20 + this.buttonLayoutUpdatWithSpan.TabIndex = 27;
1.21 + this.buttonLayoutUpdatWithSpan.Text = "Layout span";
1.22 + this.buttonLayoutUpdatWithSpan.UseVisualStyleBackColor = true;
1.23 + this.buttonLayoutUpdatWithSpan.Click += new System.EventHandler(this.buttonLayoutUpdatWithSpan_Click);
1.24 + //
1.25 // MainForm
1.26 //
1.27 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
1.28 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
1.29 this.ClientSize = new System.Drawing.Size(443, 252);
1.30 + this.Controls.Add(this.buttonLayoutUpdatWithSpan);
1.31 this.Controls.Add(this.buttonSetBitmap);
1.32 this.Controls.Add(this.buttonLayoutUpdate);
1.33 this.Controls.Add(this.buttonSetTopText);
1.34 @@ -157,6 +169,7 @@
1.35 private System.Windows.Forms.Button buttonSetTopText;
1.36 private System.Windows.Forms.Button buttonLayoutUpdate;
1.37 private System.Windows.Forms.Button buttonSetBitmap;
1.38 + private System.Windows.Forms.Button buttonLayoutUpdatWithSpan;
1.39 }
1.40 }
1.41
2.1 --- a/Client/MainForm.cs Mon Oct 13 21:42:42 2014 +0200
2.2 +++ b/Client/MainForm.cs Tue Oct 14 19:32:09 2014 +0200
2.3 @@ -177,7 +177,48 @@
2.4 graphics.DrawLine(blackPen, x1, y2, x2, y1);
2.5 }
2.6
2.7 - iClient.SetBitmap(new BitmapField(0, bitmap));
2.8 + BitmapField field = new BitmapField(0, bitmap);
2.9 + field.ColumnSpan = 2;
2.10 + iClient.SetBitmap(field);
2.11 + }
2.12 +
2.13 + private void buttonLayoutUpdatWithSpan_Click(object sender, EventArgs e)
2.14 + {
2.15 + //Define a 2 by 2 layout
2.16 + TableLayout layout = new TableLayout(2, 2);
2.17 + //Second column only takes up 25%
2.18 + layout.Columns[0].Width = 25F;
2.19 + layout.Columns[1].Width = 75F;
2.20 + //Send layout to server
2.21 + iClient.SetLayout(layout);
2.22 +
2.23 + //Set a bitmap for our first field
2.24 + int x1 = 0;
2.25 + int y1 = 0;
2.26 + int x2 = 64;
2.27 + int y2 = 64;
2.28 +
2.29 + Bitmap bitmap = new Bitmap(x2, y2);
2.30 + Pen blackPen = new Pen(Color.Black, 3);
2.31 +
2.32 + // Draw line to screen.
2.33 + using (var graphics = Graphics.FromImage(bitmap))
2.34 + {
2.35 + graphics.DrawLine(blackPen, x1, y1, x2, y2);
2.36 + graphics.DrawLine(blackPen, x1, y2, x2, y1);
2.37 + }
2.38 +
2.39 + BitmapField field = new BitmapField(0, bitmap);
2.40 + field.RowSpan = 2;
2.41 + iClient.SetBitmap(field);
2.42 +
2.43 + //Set texts
2.44 + iClient.SetTexts(new TextField[]
2.45 + {
2.46 + new TextField(1, textBoxTop.Text, Alignment),
2.47 + new TextField(2, textBoxBottom.Text, Alignment)
2.48 + });
2.49 +
2.50 }
2.51 }
2.52 }
3.1 --- a/Server/MainForm.cs Mon Oct 13 21:42:42 2014 +0200
3.2 +++ b/Server/MainForm.cs Tue Oct 14 19:32:09 2014 +0200
3.3 @@ -160,7 +160,7 @@
3.4 labelFontWidth.Text = "Font width: " + charWidth;
3.5 }
3.6
3.7 - MarqueeLabel label = null;
3.8 + MarqueeLabel label = null;
3.9 //Get the first label control we can find
3.10 foreach (Control ctrl in tableLayoutPanel.Controls)
3.11 {
3.12 @@ -863,18 +863,15 @@
3.13 if (client != null)
3.14 {
3.15 //Populate our client with the given text fields
3.16 - int j = 0;
3.17 foreach (TextField textField in aTextFields)
3.18 {
3.19 - if (client.Fields.Count < (j + 1))
3.20 + //Make sure all our texts are in place
3.21 + while (client.Fields.Count < (textField.Index + 1))
3.22 {
3.23 - client.Fields.Add(textField);
3.24 + //Add a text field with proper index
3.25 + client.Fields.Add(new TextField(client.Fields.Count));
3.26 }
3.27 - else
3.28 - {
3.29 - client.Fields[j] = textField;
3.30 - }
3.31 - j++;
3.32 + client.Fields[textField.Index] = textField;
3.33 }
3.34 //Put each our text fields in a label control
3.35 foreach (TextField field in aTextFields)
3.36 @@ -1024,7 +1021,7 @@
3.37 if (aClient.Fields.Count > 0)
3.38 {
3.39 //Create root node for our texts
3.40 - TreeNode textsRoot = new TreeNode("Text");
3.41 + TreeNode textsRoot = new TreeNode("Fields");
3.42 node.Nodes.Add(textsRoot);
3.43 //For each text add a new entry
3.44 foreach (DataField field in aClient.Fields)
3.45 @@ -1032,16 +1029,16 @@
3.46 if (field is TextField)
3.47 {
3.48 TextField textField = (TextField)field;
3.49 - textsRoot.Nodes.Add(new TreeNode(textField.Text));
3.50 + textsRoot.Nodes.Add(new TreeNode("[Text]" + textField.Text));
3.51 }
3.52 else if (field is BitmapField)
3.53 {
3.54 - textsRoot.Nodes.Add(new TreeNode("[Bitmap Field]"));
3.55 + textsRoot.Nodes.Add(new TreeNode("[Bitmap]"));
3.56 }
3.57 else
3.58 {
3.59 - textsRoot.Nodes.Add(new TreeNode("[Unknown Field Type]"));
3.60 - }
3.61 + textsRoot.Nodes.Add(new TreeNode("[Unknown]"));
3.62 + }
3.63 }
3.64 }
3.65
3.66 @@ -1096,6 +1093,7 @@
3.67 }
3.68 }
3.69
3.70 + /// DEPRECATED
3.71 /// <summary>
3.72 /// Empty and recreate our table layout with the given number of columns and rows.
3.73 /// Sizes of rows and columns are uniform.
3.74 @@ -1166,7 +1164,8 @@
3.75 private void UpdateTableLayoutPanel(ClientData aClient)
3.76 {
3.77 TableLayout layout = aClient.Layout;
3.78 -
3.79 + int fieldCount = 0;
3.80 +
3.81 tableLayoutPanel.Controls.Clear();
3.82 tableLayoutPanel.RowStyles.Clear();
3.83 tableLayoutPanel.ColumnStyles.Clear();
3.84 @@ -1196,6 +1195,17 @@
3.85 this.tableLayoutPanel.RowStyles.Add(layout.Rows[j]);
3.86 }
3.87
3.88 + //Check if we already have a control
3.89 + Control existingControl = tableLayoutPanel.GetControlFromPosition(i,j);
3.90 + if (existingControl!=null)
3.91 + {
3.92 + //We already have a control in that cell as a results of row/col spanning
3.93 + //Move on to next cell then
3.94 + continue;
3.95 + }
3.96 +
3.97 + fieldCount++;
3.98 +
3.99 //Check if a client field already exists for that cell
3.100 if (aClient.Fields.Count <= tableLayoutPanel.Controls.Count)
3.101 {
3.102 @@ -1204,17 +1214,30 @@
3.103 }
3.104
3.105 //Create a control corresponding to the field specified for that cell
3.106 - Control control = CreateControlForDataField(aClient.Fields[tableLayoutPanel.Controls.Count]);
3.107 + DataField field = aClient.Fields[tableLayoutPanel.Controls.Count];
3.108 + Control control = CreateControlForDataField(field);
3.109 +
3.110 //Add newly created control to our table layout at the specified row and column
3.111 tableLayoutPanel.Controls.Add(control, i, j);
3.112 + //Make sure we specify row and column span for that new control
3.113 + tableLayoutPanel.SetRowSpan(control,field.RowSpan);
3.114 + tableLayoutPanel.SetColumnSpan(control, field.ColumnSpan);
3.115 }
3.116 }
3.117
3.118 + //
3.119 + while (aClient.Fields.Count > fieldCount)
3.120 + {
3.121 + //We have too much fields for this layout
3.122 + //Just discard them until we get there
3.123 + aClient.Fields.RemoveAt(aClient.Fields.Count-1);
3.124 + }
3.125 +
3.126 CheckFontHeight();
3.127 }
3.128
3.129 /// <summary>
3.130 - /// Not used yet.
3.131 + /// Check our type of data field and create corresponding control
3.132 /// </summary>
3.133 /// <param name="aField"></param>
3.134 private Control CreateControlForDataField(DataField aField)