Ground work for supporting generic field and bitmap ones.
authorsl
Mon, 13 Oct 2014 20:05:48 +0200
changeset 676e50baf5a811
parent 66 a02bd242f219
child 68 1d0cd5e6e0a9
Ground work for supporting generic field and bitmap ones.
Client/Client.cs
Client/MainForm.Designer.cs
Client/MainForm.cs
Interface/Interface.cs
Server/MainForm.Designer.cs
Server/MainForm.cs
Server/Session.cs
     1.1 --- a/Client/Client.cs	Mon Oct 13 19:24:30 2014 +0200
     1.2 +++ b/Client/Client.cs	Mon Oct 13 20:05:48 2014 +0200
     1.3 @@ -86,6 +86,11 @@
     1.4              Channel.SetTexts(aTextFields);
     1.5          }
     1.6  
     1.7 +        public void SetBitmap(BitmapField aBitmapField)
     1.8 +        {
     1.9 +            Channel.SetBitmap(aBitmapField);
    1.10 +        }
    1.11 +
    1.12          public int ClientCount()
    1.13          {
    1.14              return Channel.ClientCount();
     2.1 --- a/Client/MainForm.Designer.cs	Mon Oct 13 19:24:30 2014 +0200
     2.2 +++ b/Client/MainForm.Designer.cs	Mon Oct 13 20:05:48 2014 +0200
     2.3 @@ -36,6 +36,7 @@
     2.4              this.buttonAlignLeft = new System.Windows.Forms.Button();
     2.5              this.buttonSetTopText = new System.Windows.Forms.Button();
     2.6              this.buttonLayoutUpdate = new System.Windows.Forms.Button();
     2.7 +            this.button1 = new System.Windows.Forms.Button();
     2.8              this.SuspendLayout();
     2.9              // 
    2.10              // buttonSetText
    2.11 @@ -112,11 +113,22 @@
    2.12              this.buttonLayoutUpdate.UseVisualStyleBackColor = true;
    2.13              this.buttonLayoutUpdate.Click += new System.EventHandler(this.buttonLayoutUpdate_Click);
    2.14              // 
    2.15 +            // button1
    2.16 +            // 
    2.17 +            this.button1.Location = new System.Drawing.Point(12, 190);
    2.18 +            this.button1.Name = "button1";
    2.19 +            this.button1.Size = new System.Drawing.Size(75, 23);
    2.20 +            this.button1.TabIndex = 26;
    2.21 +            this.button1.Text = "Set Bitmap";
    2.22 +            this.button1.UseVisualStyleBackColor = true;
    2.23 +            this.button1.Click += new System.EventHandler(this.button1_Click);
    2.24 +            // 
    2.25              // MainForm
    2.26              // 
    2.27              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    2.28              this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    2.29              this.ClientSize = new System.Drawing.Size(443, 252);
    2.30 +            this.Controls.Add(this.button1);
    2.31              this.Controls.Add(this.buttonLayoutUpdate);
    2.32              this.Controls.Add(this.buttonSetTopText);
    2.33              this.Controls.Add(this.buttonAlignRight);
    2.34 @@ -144,6 +156,7 @@
    2.35          private System.Windows.Forms.Button buttonAlignLeft;
    2.36          private System.Windows.Forms.Button buttonSetTopText;
    2.37          private System.Windows.Forms.Button buttonLayoutUpdate;
    2.38 +        private System.Windows.Forms.Button button1;
    2.39      }
    2.40  }
    2.41  
     3.1 --- a/Client/MainForm.cs	Mon Oct 13 19:24:30 2014 +0200
     3.2 +++ b/Client/MainForm.cs	Mon Oct 13 20:05:48 2014 +0200
     3.3 @@ -159,5 +159,23 @@
     3.4              //Send layout to server
     3.5              iClient.SetLayout(layout);
     3.6          }
     3.7 +
     3.8 +        private void button1_Click(object sender, EventArgs e)
     3.9 +        {
    3.10 +            Bitmap bitmap = new Bitmap(60,60);
    3.11 +            Pen blackPen = new Pen(Color.Black, 3);
    3.12 +
    3.13 +            int x1 = 0;
    3.14 +            int y1 = 0;
    3.15 +            int x2 = 60;
    3.16 +            int y2 = 60;
    3.17 +            // Draw line to screen.
    3.18 +            using (var graphics = Graphics.FromImage(bitmap))
    3.19 +            {
    3.20 +                graphics.DrawLine(blackPen, x1, y1, x2, y2);
    3.21 +            }
    3.22 +
    3.23 +            iClient.SetBitmap(new BitmapField(0, bitmap));
    3.24 +        }
    3.25      }
    3.26  }
     4.1 --- a/Interface/Interface.cs	Mon Oct 13 19:24:30 2014 +0200
     4.2 +++ b/Interface/Interface.cs	Mon Oct 13 20:05:48 2014 +0200
     4.3 @@ -16,9 +16,6 @@
     4.4  
     4.5  namespace SharpDisplay
     4.6  {
     4.7 -
     4.8 -
     4.9 -
    4.10      /// <summary>
    4.11      /// For client to specify a specific layout.
    4.12      /// </summary>
    4.13 @@ -177,6 +174,14 @@
    4.14          void SetTexts(System.Collections.Generic.IList<TextField> aTextFields);
    4.15  
    4.16          /// <summary>
    4.17 +        /// Put the given bitmap in the given field on your display.
    4.18 +        /// Fields are often just lines of text.
    4.19 +        /// </summary>
    4.20 +        /// <param name="aBitmapField"></param>
    4.21 +        [OperationContract(IsOneWay = true)]
    4.22 +        void SetBitmap(BitmapField aBitmapField);
    4.23 +
    4.24 +        /// <summary>
    4.25          /// Provides the number of clients currently connected
    4.26          /// </summary>
    4.27          /// <returns></returns>
     5.1 --- a/Server/MainForm.Designer.cs	Mon Oct 13 19:24:30 2014 +0200
     5.2 +++ b/Server/MainForm.Designer.cs	Mon Oct 13 20:05:48 2014 +0200
     5.3 @@ -77,6 +77,7 @@
     5.4              this.buttonAddRow = new System.Windows.Forms.Button();
     5.5              this.labelFontWidth = new System.Windows.Forms.Label();
     5.6              this.labelFontHeight = new System.Windows.Forms.Label();
     5.7 +            this.pictureBoxDemo = new System.Windows.Forms.PictureBox();
     5.8              this.panelDisplay.SuspendLayout();
     5.9              this.tableLayoutPanel.SuspendLayout();
    5.10              this.statusStrip.SuspendLayout();
    5.11 @@ -85,6 +86,7 @@
    5.12              ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).BeginInit();
    5.13              this.tabControl.SuspendLayout();
    5.14              this.tabPageDesign.SuspendLayout();
    5.15 +            ((System.ComponentModel.ISupportInitialize)(this.pictureBoxDemo)).BeginInit();
    5.16              this.SuspendLayout();
    5.17              // 
    5.18              // panelDisplay
    5.19 @@ -622,11 +624,20 @@
    5.20              this.labelFontHeight.TabIndex = 20;
    5.21              this.labelFontHeight.Text = "Font height";
    5.22              // 
    5.23 +            // pictureBoxDemo
    5.24 +            // 
    5.25 +            this.pictureBoxDemo.Location = new System.Drawing.Point(478, 54);
    5.26 +            this.pictureBoxDemo.Name = "pictureBoxDemo";
    5.27 +            this.pictureBoxDemo.Size = new System.Drawing.Size(100, 50);
    5.28 +            this.pictureBoxDemo.TabIndex = 21;
    5.29 +            this.pictureBoxDemo.TabStop = false;
    5.30 +            // 
    5.31              // MainForm
    5.32              // 
    5.33              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    5.34              this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    5.35              this.ClientSize = new System.Drawing.Size(624, 442);
    5.36 +            this.Controls.Add(this.pictureBoxDemo);
    5.37              this.Controls.Add(this.labelFontHeight);
    5.38              this.Controls.Add(this.labelFontWidth);
    5.39              this.Controls.Add(this.labelWarning);
    5.40 @@ -651,6 +662,7 @@
    5.41              this.tabControl.ResumeLayout(false);
    5.42              this.tabPageDesign.ResumeLayout(false);
    5.43              this.tabPageDesign.PerformLayout();
    5.44 +            ((System.ComponentModel.ISupportInitialize)(this.pictureBoxDemo)).EndInit();
    5.45              this.ResumeLayout(false);
    5.46              this.PerformLayout();
    5.47  
    5.48 @@ -706,6 +718,7 @@
    5.49          private System.Windows.Forms.Label labelFontWidth;
    5.50          private System.Windows.Forms.Label labelFontHeight;
    5.51          private System.Windows.Forms.CheckBox checkBoxInverseColors;
    5.52 +        private System.Windows.Forms.PictureBox pictureBoxDemo;
    5.53      }
    5.54  }
    5.55  
     6.1 --- a/Server/MainForm.cs	Mon Oct 13 19:24:30 2014 +0200
     6.2 +++ b/Server/MainForm.cs	Mon Oct 13 20:05:48 2014 +0200
     6.3 @@ -26,6 +26,7 @@
     6.4      public delegate void AddClientDelegate(string aSessionId, ICallback aCallback);
     6.5      public delegate void RemoveClientDelegate(string aSessionId);
     6.6      public delegate void SetTextDelegate(string SessionId, TextField aTextField);
     6.7 +    public delegate void SetBitmapDelegate(string SessionId, BitmapField aTextField);
     6.8      public delegate void SetLayoutDelegate(string SessionId, TableLayout aLayout);
     6.9      public delegate void SetTextsDelegate(string SessionId, System.Collections.Generic.IList<TextField> aTextFields);
    6.10      public delegate void SetClientNameDelegate(string aSessionId, string aName);
    6.11 @@ -787,8 +788,8 @@
    6.12          /// <summary>
    6.13          ///
    6.14          /// </summary>
    6.15 -        /// <param name="aLineIndex"></param>
    6.16 -        /// <param name="aText"></param>
    6.17 +        /// <param name="aSessionId"></param>
    6.18 +        /// <param name="aTextField"></param>
    6.19          public void SetClientTextThreadSafe(string aSessionId, TextField aTextField)
    6.20          {
    6.21              if (this.InvokeRequired)
    6.22 @@ -804,12 +805,12 @@
    6.23                  if (client != null)
    6.24                  {
    6.25                      //Make sure all our texts are in place
    6.26 -                    while (client.Texts.Count < (aTextField.Index + 1))
    6.27 +                    while (client.Fields.Count < (aTextField.Index + 1))
    6.28                      {
    6.29                          //Add a text field with proper index
    6.30 -                        client.Texts.Add(new TextField(client.Texts.Count));
    6.31 +                        client.Fields.Add(new TextField(client.Fields.Count));
    6.32                      }
    6.33 -                    client.Texts[aTextField.Index] = aTextField;
    6.34 +                    client.Fields[aTextField.Index] = aTextField;
    6.35  
    6.36                      //We are in the proper thread
    6.37                      MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextField.Index];
    6.38 @@ -844,13 +845,13 @@
    6.39                      int j = 0;
    6.40                      foreach (TextField textField in aTextFields)
    6.41                      {
    6.42 -                        if (client.Texts.Count < (j + 1))
    6.43 +                        if (client.Fields.Count < (j + 1))
    6.44                          {
    6.45 -                            client.Texts.Add(textField);
    6.46 +                            client.Fields.Add(textField);
    6.47                          }
    6.48                          else
    6.49                          {
    6.50 -                            client.Texts[j] = textField;
    6.51 +                            client.Fields[j] = textField;
    6.52                          }
    6.53                          j++;
    6.54                      }
    6.55 @@ -868,6 +869,44 @@
    6.56              }
    6.57          }
    6.58  
    6.59 +        /// <summary>
    6.60 +        ///
    6.61 +        /// </summary>
    6.62 +        /// <param name="aSessionId"></param>
    6.63 +        /// <param name="aTextField"></param>
    6.64 +        public void SetClientBitmapThreadSafe(string aSessionId, BitmapField aBitmapField)
    6.65 +        {
    6.66 +            if (this.InvokeRequired)
    6.67 +            {
    6.68 +                //Not in the proper thread, invoke ourselves
    6.69 +                SetBitmapDelegate d = new SetBitmapDelegate(SetClientBitmapThreadSafe);
    6.70 +                this.Invoke(d, new object[] { aSessionId, aBitmapField });
    6.71 +            }
    6.72 +            else
    6.73 +            {
    6.74 +                SetCurrentClient(aSessionId);
    6.75 +                ClientData client = iClients[aSessionId];
    6.76 +                if (client != null)
    6.77 +                {
    6.78 +                    //Make sure all our texts are in place
    6.79 +                    while (client.Fields.Count < (aBitmapField.Index + 1))
    6.80 +                    {
    6.81 +                        //Add a text field with proper index
    6.82 +                        client.Fields.Add(new TextField(client.Fields.Count));
    6.83 +                    }
    6.84 +
    6.85 +                    client.Fields[aBitmapField.Index] = aBitmapField;
    6.86 +
    6.87 +                    //We are in the proper thread
    6.88 +                    MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aBitmapField.Index];
    6.89 +                    label.Text = "Bitmap";
    6.90 +                    //
    6.91 +                    UpdateClientTreeViewNode(client);
    6.92 +                }
    6.93 +            }
    6.94 +        }
    6.95 +
    6.96 +
    6.97  
    6.98          /// <summary>
    6.99          ///
   6.100 @@ -942,15 +981,27 @@
   6.101                      node.Text = aClient.SessionId;
   6.102                  }
   6.103  
   6.104 -                if (aClient.Texts.Count > 0)
   6.105 +                if (aClient.Fields.Count > 0)
   6.106                  {
   6.107                      //Create root node for our texts
   6.108                      TreeNode textsRoot = new TreeNode("Text");
   6.109                      node.Nodes.Add(textsRoot);
   6.110                      //For each text add a new entry
   6.111 -                    foreach (TextField field in aClient.Texts)
   6.112 +                    foreach (DataField field in aClient.Fields)
   6.113                      {
   6.114 -                        textsRoot.Nodes.Add(new TreeNode(field.Text));
   6.115 +                        if (field is TextField)
   6.116 +                        {
   6.117 +                            TextField textField = (TextField)field;
   6.118 +                            textsRoot.Nodes.Add(new TreeNode(textField.Text));
   6.119 +                        }
   6.120 +                        else if (field is BitmapField)
   6.121 +                        {
   6.122 +                            textsRoot.Nodes.Add(new TreeNode("[Bitmap Field]"));
   6.123 +                        }
   6.124 +                        else
   6.125 +                        {
   6.126 +                            textsRoot.Nodes.Add(new TreeNode("[Unknown Field Type]"));
   6.127 +                        }                        
   6.128                      }
   6.129                  }
   6.130  
   6.131 @@ -1121,9 +1172,14 @@
   6.132                      control.Font = cds.Font;
   6.133                      control.Text = "";
   6.134                      //If we already have a text for that field
   6.135 -                    if (aClient.Texts.Count > tableLayoutPanel.Controls.Count)
   6.136 +                    if (aClient.Fields.Count > tableLayoutPanel.Controls.Count)
   6.137                      {
   6.138 -                        control.Text = aClient.Texts[tableLayoutPanel.Controls.Count].Text;
   6.139 +                        DataField field = aClient.Fields[tableLayoutPanel.Controls.Count];
   6.140 +                        if (field is TextField)
   6.141 +                        {
   6.142 +                            TextField textField = (TextField)field;
   6.143 +                            control.Text = textField.Text;
   6.144 +                        }
   6.145                      }
   6.146                      
   6.147                      control.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   6.148 @@ -1223,14 +1279,14 @@
   6.149          {
   6.150              SessionId = aSessionId;
   6.151              Name = "";
   6.152 -            Texts = new List<TextField>();
   6.153 +            Fields = new List<DataField>();
   6.154              Layout = new TableLayout(1, 2); //Default to one column and two rows
   6.155              Callback = aCallback;
   6.156          }
   6.157  
   6.158          public string SessionId { get; set; }
   6.159          public string Name { get; set; }
   6.160 -        public List<TextField> Texts { get; set; }
   6.161 +        public List<DataField> Fields { get; set; }
   6.162          public TableLayout Layout { get; set; }
   6.163          public ICallback Callback { get; set; }
   6.164      }
     7.1 --- a/Server/Session.cs	Mon Oct 13 19:24:30 2014 +0200
     7.2 +++ b/Server/Session.cs	Mon Oct 13 20:05:48 2014 +0200
     7.3 @@ -71,6 +71,11 @@
     7.4              SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aTextField);
     7.5          }
     7.6  
     7.7 +        //
     7.8 +        public void SetBitmap(BitmapField aBitmapField)
     7.9 +        {
    7.10 +            SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aBitmapField);
    7.11 +        }
    7.12  
    7.13          ///
    7.14          public int ClientCount()