Upgrade to SharpLibDisplay 0.1.3.
authorStephaneLenclud
Sat, 26 Dec 2015 23:27:55 +0100
changeset 17601c72c29cfaf
parent 175 391bce3c8368
child 177 c24dc0c6b64b
Upgrade to SharpLibDisplay 0.1.3.
Much improved layout construction.
Not relying on field and control index anymore.
Client/MainForm.cs
Client/SharpDisplayClient.csproj
Client/packages.config
Server/ClientData.cs
Server/MainForm.cs
Server/SharpDisplayManager.csproj
Server/packages.config
     1.1 --- a/Client/MainForm.cs	Sat Dec 26 17:43:41 2015 +0100
     1.2 +++ b/Client/MainForm.cs	Sat Dec 26 23:27:55 2015 +0100
     1.3 @@ -52,7 +52,7 @@
     1.4          {
     1.5              InitializeComponent();
     1.6              Alignment = ContentAlignment.MiddleLeft;
     1.7 -            iTextFieldTop = new TextField(0);
     1.8 +            iTextFieldTop = new TextField();
     1.9          }
    1.10  
    1.11          public void OnCloseOrder()
    1.12 @@ -212,8 +212,8 @@
    1.13  			//Set our fields
    1.14  			iClient.CreateFields(new DataField[]
    1.15              {
    1.16 -                new TextField(0, textBoxTop.Text, Alignment),
    1.17 -                new TextField(1, textBoxBottom.Text, Alignment)
    1.18 +                new TextField(textBoxTop.Text, Alignment, 0, 0),
    1.19 +                new TextField(textBoxBottom.Text, Alignment, 0, 1)
    1.20              });
    1.21  
    1.22  		}
    1.23 @@ -234,10 +234,10 @@
    1.24              //Set texts
    1.25              iClient.CreateFields(new DataField[]
    1.26              {                
    1.27 -                new TextField(0, textBoxTop.Text, Alignment),
    1.28 -                new TextField(1, textBoxBottom.Text, Alignment),
    1.29 -                new TextField(2, "Third text field", Alignment),
    1.30 -                new TextField(3, "Forth text field", Alignment),
    1.31 +                new TextField(textBoxTop.Text, Alignment, 0, 0),
    1.32 +                new TextField(textBoxBottom.Text, Alignment, 0, 1),
    1.33 +                new TextField("Third text field", Alignment, 1, 0),
    1.34 +                new TextField("Forth text field", Alignment, 1, 1),
    1.35                  recording
    1.36              });
    1.37  
    1.38 @@ -260,7 +260,7 @@
    1.39                  graphics.DrawLine(blackPen, x1, y2, x2, y1);
    1.40              }
    1.41  
    1.42 -            DataField field = new BitmapField(0, bitmap);
    1.43 +            DataField field = new BitmapField(bitmap);
    1.44              //field.ColumnSpan = 2;
    1.45              iClient.SetField(field);
    1.46          }
    1.47 @@ -301,16 +301,15 @@
    1.48              }
    1.49  
    1.50              //Create a bitmap field from the bitmap we just created
    1.51 -            BitmapField field = new BitmapField(0, bitmap);
    1.52              //We want our bitmap field to span across two rows
    1.53 -            field.RowSpan = 2;
    1.54 -
    1.55 +            BitmapField bitmapField = new BitmapField(bitmap, 0, 0, 1, 2);
    1.56 +            
    1.57              //Set texts
    1.58              iClient.CreateFields(new DataField[]
    1.59              {
    1.60 -                field,
    1.61 -                new TextField(1, textBoxTop.Text, Alignment),
    1.62 -                new TextField(2, textBoxBottom.Text, Alignment)
    1.63 +                bitmapField,
    1.64 +                new TextField(textBoxTop.Text, Alignment, 1, 0),
    1.65 +                new TextField(textBoxBottom.Text, Alignment, 1, 1)
    1.66              });
    1.67  
    1.68          }
    1.69 @@ -343,21 +342,17 @@
    1.70              }
    1.71  
    1.72              //Create a bitmap field from the bitmap we just created
    1.73 -            DataField indicator1 = new BitmapField(2, bitmap);
    1.74 +            DataField indicator1 = new BitmapField(bitmap, 1, 0);
    1.75              //Create a bitmap field from the bitmap we just created
    1.76 -            DataField indicator2 = new BitmapField(3, bitmap);
    1.77 +            DataField indicator2 = new BitmapField(bitmap, 1, 1);
    1.78              //Create a bitmap field from the bitmap we just created
    1.79 -            DataField indicator3 = new BitmapField(4, bitmap);
    1.80 +            DataField indicator3 = new BitmapField(bitmap, 1, 2);
    1.81              //Create a bitmap field from the bitmap we just created
    1.82 -            DataField indicator4 = new BitmapField(5, bitmap);
    1.83 +            DataField indicator4 = new BitmapField(bitmap, 1, 3);
    1.84  
    1.85              //
    1.86 -            TextField textFieldTop = new TextField(0, textBoxTop.Text, Alignment);
    1.87 -            textFieldTop.RowSpan = 2;
    1.88 -
    1.89 -            TextField textFieldBottom = new TextField(1, textBoxBottom.Text, Alignment);
    1.90 -            textFieldBottom.RowSpan = 2;
    1.91 -
    1.92 +            TextField textFieldTop = new TextField(textBoxTop.Text, Alignment, 0, 0, 1, 2);
    1.93 +            TextField textFieldBottom = new TextField(textBoxBottom.Text, Alignment, 0, 2, 1, 2);
    1.94  
    1.95              //Set texts
    1.96              iClient.CreateFields(new DataField[]
    1.97 @@ -377,8 +372,8 @@
    1.98  
    1.99              bool res = iClient.SetFields(new DataField[]
   1.100              {
   1.101 -                new TextField(0, textBoxTop.Text, Alignment),
   1.102 -                new TextField(1, textBoxBottom.Text, Alignment)
   1.103 +                new TextField(textBoxTop.Text, Alignment,0,0),
   1.104 +                new TextField(textBoxBottom.Text, Alignment,0,1)
   1.105              });
   1.106  
   1.107              if (!res)
   1.108 @@ -397,7 +392,7 @@
   1.109  			//Set our fields
   1.110  			iClient.CreateFields(new DataField[]
   1.111              {
   1.112 -                new TextField(0, textBoxTop.Text, Alignment)
   1.113 +                new TextField(textBoxTop.Text, Alignment)
   1.114              });
   1.115  		}
   1.116      }
     2.1 --- a/Client/SharpDisplayClient.csproj	Sat Dec 26 17:43:41 2015 +0100
     2.2 +++ b/Client/SharpDisplayClient.csproj	Sat Dec 26 23:27:55 2015 +0100
     2.3 @@ -85,7 +85,7 @@
     2.4    </PropertyGroup>
     2.5    <ItemGroup>
     2.6      <Reference Include="SharpLibDisplay, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
     2.7 -      <HintPath>..\packages\SharpLibDisplay.0.1.2\lib\net40\SharpLibDisplay.dll</HintPath>
     2.8 +      <HintPath>..\packages\SharpLibDisplay.0.1.3\lib\net40\SharpLibDisplay.dll</HintPath>
     2.9        <Private>True</Private>
    2.10      </Reference>
    2.11      <Reference Include="System" />
     3.1 --- a/Client/packages.config	Sat Dec 26 17:43:41 2015 +0100
     3.2 +++ b/Client/packages.config	Sat Dec 26 23:27:55 2015 +0100
     3.3 @@ -1,4 +1,4 @@
     3.4  <?xml version="1.0" encoding="utf-8"?>
     3.5  <packages>
     3.6 -  <package id="SharpLibDisplay" version="0.1.2" targetFramework="net46" />
     3.7 +  <package id="SharpLibDisplay" version="0.1.3" targetFramework="net46" />
     3.8  </packages>
     3.9 \ No newline at end of file
     4.1 --- a/Server/ClientData.cs	Sat Dec 26 17:43:41 2015 +0100
     4.2 +++ b/Server/ClientData.cs	Sat Dec 26 23:27:55 2015 +0100
     4.3 @@ -34,5 +34,46 @@
     4.4  
     4.5          //Client management
     4.6          public DateTime LastSwitchTime { get; set; }
     4.7 +
     4.8 +        /// <summary>
     4.9 +        /// Look up the corresponding field in our field collection.
    4.10 +        /// </summary>
    4.11 +        /// <param name="aField"></param>
    4.12 +        /// <returns></returns>
    4.13 +        public DataField FindSameFieldAs(DataField aField)
    4.14 +        {
    4.15 +            foreach (DataField field in Fields)
    4.16 +            {
    4.17 +                if (field.IsSameAs(aField))
    4.18 +                {
    4.19 +                    return field;
    4.20 +                }                
    4.21 +            }
    4.22 +
    4.23 +            return null;
    4.24 +        }
    4.25 +
    4.26 +
    4.27 +        /// <summary>
    4.28 +        /// Look up the corresponding field in our field collection.
    4.29 +        /// </summary>
    4.30 +        /// <param name="aField"></param>
    4.31 +        /// <returns></returns>
    4.32 +        public int FindSameFieldIndex(DataField aField)
    4.33 +        {
    4.34 +            int i = 0;
    4.35 +            foreach (DataField field in Fields)
    4.36 +            {
    4.37 +                if (field.IsSameAs(aField))
    4.38 +                {
    4.39 +                    return i;
    4.40 +                }
    4.41 +                i++;
    4.42 +            }
    4.43 +
    4.44 +            return -1;
    4.45 +        }
    4.46 +
    4.47 +
    4.48      }
    4.49  }
     5.1 --- a/Server/MainForm.cs	Sat Dec 26 17:43:41 2015 +0100
     5.2 +++ b/Server/MainForm.cs	Sat Dec 26 23:27:55 2015 +0100
     5.3 @@ -1565,6 +1565,9 @@
     5.4              }
     5.5          }
     5.6  
     5.7 +
     5.8 +
     5.9 +
    5.10          /// <summary>
    5.11          /// Set a data field in the given client.
    5.12          /// </summary>
    5.13 @@ -1578,40 +1581,49 @@
    5.14              bool layoutChanged = false;
    5.15              bool contentChanged = true;
    5.16  
    5.17 -            //Make sure all our fields are in place
    5.18 -            while (client.Fields.Count < (aField.Index + 1))
    5.19 +            //Fetch our field index
    5.20 +            int fieldIndex = client.FindSameFieldIndex(aField);
    5.21 +
    5.22 +            if (fieldIndex < 0)
    5.23              {
    5.24 -                //Add a data field with proper index
    5.25 -                client.Fields.Add(new TextField(client.Fields.Count));
    5.26 -                layoutChanged = true;
    5.27 +                //No corresponding field, just bail out
    5.28 +                return;
    5.29              }
    5.30  
    5.31              //Keep our previous field in there
    5.32 -            DataField previousField = client.Fields[aField.Index];
    5.33 -            //Now that we know our fields are in place just update that one
    5.34 -            client.Fields[aField.Index] = aField;
    5.35 +            DataField previousField = client.Fields[fieldIndex];
    5.36 +            //Just update that field then 
    5.37 +            client.Fields[fieldIndex] = aField;
    5.38  
    5.39 +            if (!aField.IsTableField)
    5.40 +            {
    5.41 +                //We are done then if that field is not in our table layout
    5.42 +                return;
    5.43 +            }
    5.44 +
    5.45 +            TableField tableField = (TableField) aField;
    5.46  
    5.47              if (previousField.IsSameLayout(aField))
    5.48              {
    5.49                  //If we are updating a field in our current client we need to update it in our panel
    5.50                  if (aSessionId == iCurrentClientSessionId)
    5.51                  {
    5.52 -                    if (aField.IsTextField && aField.Index < iTableLayoutPanel.Controls.Count && iTableLayoutPanel.Controls[aField.Index] is MarqueeLabel)
    5.53 +                    Control ctrl=iTableLayoutPanel.GetControlFromPosition(tableField.Column, tableField.Row);
    5.54 +                    if (aField.IsTextField && ctrl is MarqueeLabel)
    5.55                      {
    5.56                          TextField textField=(TextField)aField;
    5.57                          //Text field control already in place, just change the text
    5.58 -                        MarqueeLabel label = (MarqueeLabel)iTableLayoutPanel.Controls[aField.Index];
    5.59 +                        MarqueeLabel label = (MarqueeLabel)ctrl;
    5.60                          contentChanged = (label.Text != textField.Text || label.TextAlign != textField.Alignment);
    5.61                          label.Text = textField.Text;
    5.62                          label.TextAlign = textField.Alignment;
    5.63                      }
    5.64 -                    else if (aField.IsBitmapField && aField.Index < iTableLayoutPanel.Controls.Count && iTableLayoutPanel.Controls[aField.Index] is PictureBox)
    5.65 +                    else if (aField.IsBitmapField && ctrl is PictureBox)
    5.66                      {
    5.67                          BitmapField bitmapField = (BitmapField)aField;
    5.68                          contentChanged = true; //TODO: Bitmap comp or should we leave that to clients?
    5.69                          //Bitmap field control already in place just change the bitmap
    5.70 -                        PictureBox pictureBox = (PictureBox)iTableLayoutPanel.Controls[aField.Index];
    5.71 +                        PictureBox pictureBox = (PictureBox)ctrl;
    5.72                          pictureBox.Image = bitmapField.Bitmap;
    5.73                      }
    5.74                      else
    5.75 @@ -1687,6 +1699,8 @@
    5.76                          //Apply layout and set data fields.
    5.77                          UpdateTableLayoutPanel(iCurrentClientData);
    5.78                      }
    5.79 +
    5.80 +                    UpdateClientTreeViewNode(client);
    5.81                  }
    5.82                  else
    5.83                  {
    5.84 @@ -1832,7 +1846,6 @@
    5.85  
    5.86  
    5.87              TableLayout layout = aClient.Layout;
    5.88 -            int fieldCount = 0;
    5.89  
    5.90              //First clean our current panel
    5.91              iTableLayoutPanel.Controls.Clear();
    5.92 @@ -1867,55 +1880,35 @@
    5.93                          //Create our row styles
    5.94                          this.iTableLayoutPanel.RowStyles.Add(layout.Rows[j]);
    5.95                      }
    5.96 -
    5.97 -                    //Check if we already have a control
    5.98 -                    Control existingControl = iTableLayoutPanel.GetControlFromPosition(i,j);
    5.99 -                    if (existingControl!=null)
   5.100 +                    else
   5.101                      {
   5.102 -                        //We already have a control in that cell as a results of row/col spanning
   5.103 -                        //Move on to next cell then
   5.104                          continue;
   5.105                      }
   5.106 -
   5.107 -                    fieldCount++;
   5.108 -
   5.109 -                    //Check if a client field already exists for that cell
   5.110 -                    if (aClient.Fields.Count <= iTableLayoutPanel.Controls.Count)
   5.111 -                    {
   5.112 -                        //No client field specified, create a text field by default
   5.113 -                        aClient.Fields.Add(new TextField(aClient.Fields.Count));
   5.114 -                    }
   5.115 -
   5.116 -                    //
   5.117 -                    DataField field = aClient.Fields[iTableLayoutPanel.Controls.Count];
   5.118 -                    if (!field.IsTableField)
   5.119 -                    {
   5.120 -                        //That field is not taking part in our table layout then 
   5.121 -                        //We should be ok I guess
   5.122 -                        continue;
   5.123 -                    }
   5.124 -
   5.125 -                    TableField tableField = (TableField)field;
   5.126 -
   5.127 -                    //Create a control corresponding to the field specified for that cell
   5.128 -                    Control control = CreateControlForDataField(tableField);
   5.129 -
   5.130 -                    //Add newly created control to our table layout at the specified row and column
   5.131 -                    iTableLayoutPanel.Controls.Add(control, i, j);
   5.132 -                    //Make sure we specify row and column span for that new control
   5.133 -                    iTableLayoutPanel.SetRowSpan(control, tableField.RowSpan);
   5.134 -                    iTableLayoutPanel.SetColumnSpan(control, tableField.ColumnSpan);
   5.135                  }
   5.136              }
   5.137  
   5.138 -            //
   5.139 -            while (aClient.Fields.Count > fieldCount)
   5.140 +            //For each field
   5.141 +            foreach (DataField field in aClient.Fields)
   5.142              {
   5.143 -                //We have too much fields for this layout
   5.144 -                //Just discard them until we get there
   5.145 -                aClient.Fields.RemoveAt(aClient.Fields.Count-1);
   5.146 +                if (!field.IsTableField)
   5.147 +                {
   5.148 +                    //That field is not taking part in our table layout skip it
   5.149 +                    continue;
   5.150 +                }
   5.151 +
   5.152 +                TableField tableField = (TableField)field;
   5.153 +
   5.154 +                //Create a control corresponding to the field specified for that cell
   5.155 +                Control control = CreateControlForDataField(tableField);
   5.156 +
   5.157 +                //Add newly created control to our table layout at the specified row and column
   5.158 +                iTableLayoutPanel.Controls.Add(control, tableField.Column, tableField.Row);
   5.159 +                //Make sure we specify column and row span for that new control
   5.160 +                iTableLayoutPanel.SetColumnSpan(control, tableField.ColumnSpan);
   5.161 +                iTableLayoutPanel.SetRowSpan(control, tableField.RowSpan);
   5.162              }
   5.163  
   5.164 +
   5.165              CheckFontHeight();
   5.166          }
   5.167  
   5.168 @@ -1935,7 +1928,7 @@
   5.169                  label.Dock = System.Windows.Forms.DockStyle.Fill;
   5.170                  label.Location = new System.Drawing.Point(1, 1);
   5.171                  label.Margin = new System.Windows.Forms.Padding(0);
   5.172 -                label.Name = "marqueeLabel" + aField.Index;
   5.173 +                label.Name = "marqueeLabel" + aField;
   5.174                  label.OwnTimer = false;
   5.175                  label.PixelsPerSecond = cds.ScrollingSpeedInPixelsPerSecond;
   5.176                  label.Separator = cds.Separator;
     6.1 --- a/Server/SharpDisplayManager.csproj	Sat Dec 26 17:43:41 2015 +0100
     6.2 +++ b/Server/SharpDisplayManager.csproj	Sat Dec 26 23:27:55 2015 +0100
     6.3 @@ -121,7 +121,7 @@
     6.4        <HintPath>..\packages\NAudio.1.7.3\lib\net35\NAudio.dll</HintPath>
     6.5      </Reference>
     6.6      <Reference Include="SharpLibDisplay, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
     6.7 -      <HintPath>..\packages\SharpLibDisplay.0.1.2\lib\net40\SharpLibDisplay.dll</HintPath>
     6.8 +      <HintPath>..\packages\SharpLibDisplay.0.1.3\lib\net40\SharpLibDisplay.dll</HintPath>
     6.9        <Private>True</Private>
    6.10      </Reference>
    6.11      <Reference Include="SharpLibHid">
     7.1 --- a/Server/packages.config	Sat Dec 26 17:43:41 2015 +0100
     7.2 +++ b/Server/packages.config	Sat Dec 26 23:27:55 2015 +0100
     7.3 @@ -2,7 +2,7 @@
     7.4  <packages>
     7.5    <package id="LibMiniDisplay" version="1.1.8" targetFramework="net46" />
     7.6    <package id="NAudio" version="1.7.3" targetFramework="net45" />
     7.7 -  <package id="SharpLibDisplay" version="0.1.2" targetFramework="net46" />
     7.8 +  <package id="SharpLibDisplay" version="0.1.3" targetFramework="net46" />
     7.9    <package id="SharpLibHid" version="1.2.1" targetFramework="net45" />
    7.10    <package id="SharpLibNotification" version="0.0.1" targetFramework="net46" />
    7.11    <package id="SharpLibWin32" version="0.0.7" targetFramework="net45" />