Server/MainForm.cs
changeset 65 464486b81635
parent 63 cd9924457275
child 67 6e50baf5a811
     1.1 --- a/Server/MainForm.cs	Mon Sep 22 22:04:39 2014 +0200
     1.2 +++ b/Server/MainForm.cs	Fri Oct 03 18:43:55 2014 +0200
     1.3 @@ -42,17 +42,24 @@
     1.4          System.Drawing.Bitmap iBmp;
     1.5          bool iCreateBitmap; //Workaround render to bitmap issues when minimized
     1.6          ServiceHost iServiceHost;
     1.7 -        /// <summary>
     1.8 -        /// Our collection of clients
     1.9 -        /// </summary>
    1.10 +        // Our collection of clients sorted by session id.
    1.11          public Dictionary<string, ClientData> iClients;
    1.12 +        // The name of the client which informations are currently displayed.
    1.13 +        public string iCurrentClientSessionId;
    1.14 +        ClientData iCurrentClientData;
    1.15 +        //
    1.16          public bool iClosing;
    1.17 +        //Function pointer for pixel color filtering
    1.18          ColorProcessingDelegate iColorFx;
    1.19 +        //Function pointer for pixel X coordinate intercept
    1.20          CoordinateTranslationDelegate iScreenX;
    1.21 +        //Function pointer for pixel Y coordinate intercept
    1.22          CoordinateTranslationDelegate iScreenY;
    1.23  
    1.24          public MainForm()
    1.25          {
    1.26 +            iCurrentClientSessionId = "";
    1.27 +            iCurrentClientData = null;
    1.28              LastTickTime = DateTime.Now;
    1.29              iDisplay = new Display();
    1.30              iClients = new Dictionary<string, ClientData>();
    1.31 @@ -62,8 +69,6 @@
    1.32              //We have a bug when drawing minimized and reusing our bitmap
    1.33              iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
    1.34              iCreateBitmap = false;
    1.35 -            //
    1.36 -            //this.tableLayoutPanel.CellPaint += new TableLayoutCellPaintEventHandler(tableLayoutPanel_CellPaint);
    1.37          }
    1.38  
    1.39          private void MainForm_Load(object sender, EventArgs e)
    1.40 @@ -76,32 +81,28 @@
    1.41              }
    1.42          }
    1.43  
    1.44 -        //Testing that stuff
    1.45 -        private void tableLayoutPanel_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
    1.46 +        /// <summary>
    1.47 +        /// Set our current client.
    1.48 +        /// This will take care of applying our client layout and set data fields.
    1.49 +        /// </summary>
    1.50 +        /// <param name="aSessionId"></param>
    1.51 +        void SetCurrentClient(string aSessionId)
    1.52          {
    1.53 -            var panel = sender as TableLayoutPanel;
    1.54 -            //e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
    1.55 -            var rectangle = e.CellBounds;
    1.56 -            using (var pen = new Pen(Color.Black, 1))
    1.57 +            if (aSessionId == iCurrentClientSessionId)
    1.58              {
    1.59 -                pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Center;
    1.60 -                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
    1.61 +                //Given client is already the current one.
    1.62 +                //Don't bother changing anything then.
    1.63 +                return;
    1.64 +            }
    1.65  
    1.66 -                if (e.Row == (panel.RowCount - 1))
    1.67 -                {
    1.68 -                    rectangle.Height -= 1;
    1.69 -                }
    1.70 -
    1.71 -                if (e.Column == (panel.ColumnCount - 1))
    1.72 -                {
    1.73 -                    rectangle.Width -= 1;
    1.74 -                }
    1.75 -
    1.76 -                e.Graphics.DrawRectangle(pen, rectangle);
    1.77 -            }
    1.78 +            //Set current client ID.
    1.79 +            iCurrentClientSessionId = aSessionId;
    1.80 +            //Fetch and set current client data.
    1.81 +            iCurrentClientData = iClients[aSessionId];
    1.82 +            //Apply layout and set data fields.
    1.83 +            UpdateTableLayoutPanel(iCurrentClientData);
    1.84          }
    1.85  
    1.86 -
    1.87          private void buttonFont_Click(object sender, EventArgs e)
    1.88          {
    1.89              //fontDialog.ShowColor = true;
    1.90 @@ -430,12 +431,12 @@
    1.91          {
    1.92              get
    1.93              {
    1.94 -                DisplaysSettings settings = Properties.Settings.Default.DisplaySettings;
    1.95 +                DisplaysSettings settings = Properties.Settings.Default.DisplaysSettings;
    1.96                  if (settings == null)
    1.97                  {
    1.98                      settings = new DisplaysSettings();
    1.99                      settings.Init();
   1.100 -                    Properties.Settings.Default.DisplaySettings = settings;
   1.101 +                    Properties.Settings.Default.DisplaysSettings = settings;
   1.102                  }
   1.103  
   1.104                  //Make sure all our settings have been created
   1.105 @@ -776,7 +777,7 @@
   1.106                  if (client != null)
   1.107                  {
   1.108                      client.Layout = aLayout;
   1.109 -                    UpdateTableLayoutPanel(client.Layout);
   1.110 +                    UpdateTableLayoutPanel(client);
   1.111                      //
   1.112                      UpdateClientTreeViewNode(client);
   1.113                  }
   1.114 @@ -788,16 +789,17 @@
   1.115          /// </summary>
   1.116          /// <param name="aLineIndex"></param>
   1.117          /// <param name="aText"></param>
   1.118 -        public void SetTextThreadSafe(string aSessionId, TextField aTextField)
   1.119 +        public void SetClientTextThreadSafe(string aSessionId, TextField aTextField)
   1.120          {
   1.121              if (this.InvokeRequired)
   1.122              {
   1.123                  //Not in the proper thread, invoke ourselves
   1.124 -                SetTextDelegate d = new SetTextDelegate(SetTextThreadSafe);
   1.125 +                SetTextDelegate d = new SetTextDelegate(SetClientTextThreadSafe);
   1.126                  this.Invoke(d, new object[] { aSessionId, aTextField });
   1.127              }
   1.128              else
   1.129              {
   1.130 +                SetCurrentClient(aSessionId);
   1.131                  ClientData client = iClients[aSessionId];
   1.132                  if (client != null)
   1.133                  {
   1.134 @@ -823,16 +825,17 @@
   1.135          ///
   1.136          /// </summary>
   1.137          /// <param name="aTexts"></param>
   1.138 -        public void SetTextsThreadSafe(string aSessionId, System.Collections.Generic.IList<TextField> aTextFields)
   1.139 +        public void SetClientTextsThreadSafe(string aSessionId, System.Collections.Generic.IList<TextField> aTextFields)
   1.140          {
   1.141              if (this.InvokeRequired)
   1.142              {
   1.143                  //Not in the proper thread, invoke ourselves
   1.144 -                SetTextsDelegate d = new SetTextsDelegate(SetTextsThreadSafe);
   1.145 +                SetTextsDelegate d = new SetTextsDelegate(SetClientTextsThreadSafe);
   1.146                  this.Invoke(d, new object[] { aSessionId, aTextFields });
   1.147              }
   1.148              else
   1.149              {
   1.150 +                SetCurrentClient(aSessionId);
   1.151                  //We are in the proper thread
   1.152                  ClientData client = iClients[aSessionId];
   1.153                  if (client != null)
   1.154 @@ -851,7 +854,7 @@
   1.155                          }
   1.156                          j++;
   1.157                      }
   1.158 -                    //Only support two lines for now
   1.159 +                    //Put each our text fields in a label control
   1.160                      for (int i = 0; i < aTextFields.Count; i++)
   1.161                      {
   1.162                          MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextFields[i].Index];
   1.163 @@ -1069,20 +1072,22 @@
   1.164          /// Update our display table layout.
   1.165          /// </summary>
   1.166          /// <param name="aLayout"></param>
   1.167 -        private void UpdateTableLayoutPanel(TableLayout aLayout)
   1.168 +        private void UpdateTableLayoutPanel(ClientData aClient)
   1.169          {
   1.170 +            TableLayout layout = aClient.Layout;
   1.171 +            
   1.172              tableLayoutPanel.Controls.Clear();
   1.173              tableLayoutPanel.RowStyles.Clear();
   1.174              tableLayoutPanel.ColumnStyles.Clear();
   1.175              tableLayoutPanel.RowCount = 0;
   1.176              tableLayoutPanel.ColumnCount = 0;
   1.177  
   1.178 -            while (tableLayoutPanel.RowCount < aLayout.Rows.Count)
   1.179 +            while (tableLayoutPanel.RowCount < layout.Rows.Count)
   1.180              {
   1.181                  tableLayoutPanel.RowCount++;
   1.182              }
   1.183  
   1.184 -            while (tableLayoutPanel.ColumnCount < aLayout.Columns.Count)
   1.185 +            while (tableLayoutPanel.ColumnCount < layout.Columns.Count)
   1.186              {
   1.187                  tableLayoutPanel.ColumnCount++;
   1.188              }
   1.189 @@ -1090,14 +1095,14 @@
   1.190              for (int i = 0; i < tableLayoutPanel.ColumnCount; i++)
   1.191              {
   1.192                  //Create our column styles
   1.193 -                this.tableLayoutPanel.ColumnStyles.Add(aLayout.Columns[i]);
   1.194 +                this.tableLayoutPanel.ColumnStyles.Add(layout.Columns[i]);
   1.195  
   1.196                  for (int j = 0; j < tableLayoutPanel.RowCount; j++)
   1.197                  {
   1.198                      if (i == 0)
   1.199                      {
   1.200                          //Create our row styles
   1.201 -                        this.tableLayoutPanel.RowStyles.Add(aLayout.Rows[j]);
   1.202 +                        this.tableLayoutPanel.RowStyles.Add(layout.Rows[j]);
   1.203                      }
   1.204  
   1.205                      MarqueeLabel control = new SharpDisplayManager.MarqueeLabel();
   1.206 @@ -1107,14 +1112,20 @@
   1.207                      control.Dock = System.Windows.Forms.DockStyle.Fill;
   1.208                      control.Location = new System.Drawing.Point(1, 1);
   1.209                      control.Margin = new System.Windows.Forms.Padding(0);
   1.210 -                    control.Name = "marqueeLabelCol" + aLayout.Columns.Count + "Row" + aLayout.Rows.Count;
   1.211 +                    control.Name = "marqueeLabelCol" + layout.Columns.Count + "Row" + layout.Rows.Count;
   1.212                      control.OwnTimer = false;
   1.213                      control.PixelsPerSecond = 64;
   1.214                      control.Separator = "|";
   1.215                      //control.Size = new System.Drawing.Size(254, 30);
   1.216                      //control.TabIndex = 2;
   1.217                      control.Font = cds.Font;
   1.218 -                    control.Text = "ABCDEFGHIJKLMNOPQRST[0123456789]";
   1.219 +                    control.Text = "";
   1.220 +                    //If we already have a text for that field
   1.221 +                    if (aClient.Texts.Count > tableLayoutPanel.Controls.Count)
   1.222 +                    {
   1.223 +                        control.Text = aClient.Texts[tableLayoutPanel.Controls.Count].Text;
   1.224 +                    }
   1.225 +                    
   1.226                      control.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   1.227                      control.UseCompatibleTextRendering = true;
   1.228                      //