More consistent clock and clear support.
authorStephaneLenclud
Tue, 10 Feb 2015 15:41:34 +0100
changeset 122300f3d3114a8
parent 121 5551b64e1eeb
child 123 0df386e37e29
More consistent clock and clear support.
Server/Display.cs
Server/MainForm.cs
Server/SharpDisplayManager.csproj
     1.1 --- a/Server/Display.cs	Mon Feb 09 22:50:43 2015 +0100
     1.2 +++ b/Server/Display.cs	Tue Feb 10 15:41:34 2015 +0100
     1.3 @@ -73,10 +73,6 @@
     1.4  				return;
     1.5  			}
     1.6  
     1.7 -			//Controversially clearing our screen before closing
     1.8 -			//Consider moving this up into the UI layer
     1.9 -			Clear(); 
    1.10 -			SwapBuffers();
    1.11  			//
    1.12              MiniDisplayClose(iDevice);
    1.13              iDevice = IntPtr.Zero;
    1.14 @@ -239,7 +235,6 @@
    1.15  					SetIconStatus(icon,i,aStatus);
    1.16  				}
    1.17  			}
    1.18 -
    1.19  		}
    1.20  
    1.21  		/// <summary>
     2.1 --- a/Server/MainForm.cs	Mon Feb 09 22:50:43 2015 +0100
     2.2 +++ b/Server/MainForm.cs	Tue Feb 10 15:41:34 2015 +0100
     2.3 @@ -57,6 +57,8 @@
     2.4          ClientData iCurrentClientData;
     2.5          //
     2.6          public bool iClosing;
     2.7 +		//
     2.8 +		public bool iSkipFrameRendering;
     2.9          //Function pointer for pixel color filtering
    2.10          ColorProcessingDelegate iColorFx;
    2.11          //Function pointer for pixel X coordinate intercept
    2.12 @@ -82,6 +84,8 @@
    2.13  
    2.14          public MainForm()
    2.15          {
    2.16 +			iSkipFrameRendering = false;
    2.17 +			iClosing = false;
    2.18              iCurrentClientSessionId = "";
    2.19              iCurrentClientData = null;
    2.20              LastTickTime = DateTime.Now;
    2.21 @@ -177,6 +181,9 @@
    2.22  		/// <param name="aDisplay"></param>
    2.23  		private void OnDisplayOpened(Display aDisplay)
    2.24  		{
    2.25 +			//Make sure we resume frame rendering
    2.26 +			iSkipFrameRendering = false;
    2.27 +
    2.28  			//Set our screen size now that our display is connected
    2.29  			//Our panelDisplay is the container of our tableLayoutPanel
    2.30  			//tableLayoutPanel will resize itself to fit the client size of our panelDisplay
    2.31 @@ -779,42 +786,45 @@
    2.32                  }
    2.33              }
    2.34  
    2.35 -
    2.36              //Update our display
    2.37              if (iDisplay.IsOpen())
    2.38              {
    2.39                  CheckForRequestResults();
    2.40  
    2.41 -                //Draw to bitmap
    2.42 -                if (iCreateBitmap)
    2.43 -                {
    2.44 -                    iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
    2.45 -                }
    2.46 -                tableLayoutPanel.DrawToBitmap(iBmp, tableLayoutPanel.ClientRectangle);
    2.47 -                //iBmp.Save("D:\\capture.png");
    2.48 +				//Check if frame rendering is needed
    2.49 +				//Typically used when showing clock
    2.50 +				if (!iSkipFrameRendering)
    2.51 +				{
    2.52 +					//Draw to bitmap
    2.53 +					if (iCreateBitmap)
    2.54 +					{
    2.55 +						iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
    2.56 +					}
    2.57 +					tableLayoutPanel.DrawToBitmap(iBmp, tableLayoutPanel.ClientRectangle);
    2.58 +					//iBmp.Save("D:\\capture.png");
    2.59  
    2.60 -                //Send it to our display
    2.61 -                for (int i = 0; i < iBmp.Width; i++)
    2.62 -                {
    2.63 -                    for (int j = 0; j < iBmp.Height; j++)
    2.64 -                    {
    2.65 -                        unchecked
    2.66 -                        {
    2.67 -                            //Get our processed pixel coordinates
    2.68 -                            int x = iScreenX(iBmp, i);
    2.69 -                            int y = iScreenY(iBmp, j);
    2.70 -                            //Get pixel color
    2.71 -                            uint color = (uint)iBmp.GetPixel(i, j).ToArgb();
    2.72 -                            //Apply color effects
    2.73 -                            color = iColorFx(x,y,color);
    2.74 -                            //Now set our pixel
    2.75 -                            iDisplay.SetPixel(x, y, color);
    2.76 -                        }
    2.77 -                    }
    2.78 -                }
    2.79 +					//Send it to our display
    2.80 +					for (int i = 0; i < iBmp.Width; i++)
    2.81 +					{
    2.82 +						for (int j = 0; j < iBmp.Height; j++)
    2.83 +						{
    2.84 +							unchecked
    2.85 +							{
    2.86 +								//Get our processed pixel coordinates
    2.87 +								int x = iScreenX(iBmp, i);
    2.88 +								int y = iScreenY(iBmp, j);
    2.89 +								//Get pixel color
    2.90 +								uint color = (uint)iBmp.GetPixel(i, j).ToArgb();
    2.91 +								//Apply color effects
    2.92 +								color = iColorFx(x, y, color);
    2.93 +								//Now set our pixel
    2.94 +								iDisplay.SetPixel(x, y, color);
    2.95 +							}
    2.96 +						}
    2.97 +					}
    2.98  
    2.99 -                iDisplay.SwapBuffers();
   2.100 -
   2.101 +					iDisplay.SwapBuffers();
   2.102 +				}
   2.103              }
   2.104  
   2.105              //Compute instant FPS
   2.106 @@ -841,6 +851,21 @@
   2.107          private void CloseDisplayConnection()
   2.108          {
   2.109  			//Status will be updated upon receiving the closed event
   2.110 +
   2.111 +			if (iDisplay == null || !iDisplay.IsOpen())
   2.112 +			{
   2.113 +				return;
   2.114 +			}
   2.115 +
   2.116 +			//Do not clear if we gave up on rendering already.
   2.117 +			//This means we will keep on displaying clock on MDM166AA for instance.
   2.118 +			if (!iSkipFrameRendering)
   2.119 +			{
   2.120 +				iDisplay.Clear();
   2.121 +				iDisplay.SwapBuffers();
   2.122 +			}
   2.123 +
   2.124 +			iDisplay.SetAllIconsStatus(0); //Turn off all icons
   2.125              iDisplay.Close();
   2.126          }
   2.127  
   2.128 @@ -1229,6 +1254,7 @@
   2.129  			tableLayoutPanel.Controls.Clear();
   2.130  			tableLayoutPanel.RowStyles.Clear();
   2.131  			tableLayoutPanel.ColumnStyles.Clear();
   2.132 +			iCurrentClientData = null;
   2.133  		}
   2.134  
   2.135  		/// <summary>
   2.136 @@ -1578,72 +1604,6 @@
   2.137              }
   2.138          }
   2.139  
   2.140 -        /// DEPRECATED
   2.141 -        /// <summary>
   2.142 -        /// Empty and recreate our table layout with the given number of columns and rows.
   2.143 -        /// Sizes of rows and columns are uniform.
   2.144 -        /// </summary>
   2.145 -        /// <param name="aColumn"></param>
   2.146 -        /// <param name="aRow"></param>
   2.147 -        private void UpdateTableLayoutPanel(int aColumn, int aRow)
   2.148 -        {
   2.149 -            tableLayoutPanel.Controls.Clear();
   2.150 -            tableLayoutPanel.RowStyles.Clear();
   2.151 -            tableLayoutPanel.ColumnStyles.Clear();
   2.152 -            tableLayoutPanel.RowCount = 0;
   2.153 -            tableLayoutPanel.ColumnCount = 0;
   2.154 -
   2.155 -            while (tableLayoutPanel.RowCount < aRow)
   2.156 -            {
   2.157 -                tableLayoutPanel.RowCount++;
   2.158 -            }
   2.159 -
   2.160 -            while (tableLayoutPanel.ColumnCount < aColumn)
   2.161 -            {
   2.162 -                tableLayoutPanel.ColumnCount++;
   2.163 -            }
   2.164 -
   2.165 -            for (int i = 0; i < tableLayoutPanel.ColumnCount; i++)
   2.166 -            {
   2.167 -                //Create our column styles
   2.168 -                this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100 / tableLayoutPanel.ColumnCount));
   2.169 -
   2.170 -                for (int j = 0; j < tableLayoutPanel.RowCount; j++)
   2.171 -                {
   2.172 -                    if (i == 0)
   2.173 -                    {
   2.174 -                        //Create our row styles
   2.175 -                        this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100 / tableLayoutPanel.RowCount));
   2.176 -                    }
   2.177 -
   2.178 -                    MarqueeLabel control = new SharpDisplayManager.MarqueeLabel();
   2.179 -                    control.AutoEllipsis = true;
   2.180 -                    control.AutoSize = true;
   2.181 -                    control.BackColor = System.Drawing.Color.Transparent;
   2.182 -                    control.Dock = System.Windows.Forms.DockStyle.Fill;
   2.183 -                    control.Location = new System.Drawing.Point(1, 1);
   2.184 -                    control.Margin = new System.Windows.Forms.Padding(0);
   2.185 -                    control.Name = "marqueeLabelCol" + aColumn + "Row" + aRow;
   2.186 -                    control.OwnTimer = false;
   2.187 -                    control.PixelsPerSecond = 64;
   2.188 -                    control.Separator = cds.Separator;
   2.189 -                    control.MinFontSize = cds.MinFontSize;
   2.190 -                    control.ScaleToFit = cds.ScaleToFit;
   2.191 -                    //control.Size = new System.Drawing.Size(254, 30);
   2.192 -                    //control.TabIndex = 2;
   2.193 -                    control.Font = cds.Font;
   2.194 -                    control.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
   2.195 -                    control.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   2.196 -                    control.UseCompatibleTextRendering = true;
   2.197 -                    //
   2.198 -                    tableLayoutPanel.Controls.Add(control, i, j);
   2.199 -                }
   2.200 -            }
   2.201 -
   2.202 -            CheckFontHeight();
   2.203 -        }
   2.204 -
   2.205 -
   2.206          /// <summary>
   2.207          /// Update our display table layout.
   2.208          /// </summary>
   2.209 @@ -1878,12 +1838,12 @@
   2.210  
   2.211          private void buttonShowClock_Click(object sender, EventArgs e)
   2.212          {
   2.213 -            iDisplay.ShowClock();
   2.214 +			ShowClock();
   2.215          }
   2.216  
   2.217          private void buttonHideClock_Click(object sender, EventArgs e)
   2.218          {
   2.219 -            iDisplay.HideClock();
   2.220 +			HideClock();
   2.221          }
   2.222  
   2.223          private void buttonUpdate_Click(object sender, EventArgs e)
   2.224 @@ -1891,6 +1851,39 @@
   2.225              InstallUpdateSyncWithInfo();
   2.226          }
   2.227  
   2.228 +		/// <summary>
   2.229 +		/// 
   2.230 +		/// </summary>
   2.231 +		void ShowClock()
   2.232 +		{
   2.233 +			if (!iDisplay.IsOpen())
   2.234 +			{
   2.235 +				return;
   2.236 +			}
   2.237 +
   2.238 +			//Devices like MDM166AA don't support windowing and frame rendering must be stopped while showing our clock
   2.239 +			iSkipFrameRendering = true;
   2.240 +			//Clear our screen 
   2.241 +			iDisplay.Clear();
   2.242 +			iDisplay.SwapBuffers();
   2.243 +			//Then show our clock
   2.244 +			iDisplay.ShowClock();
   2.245 +		}
   2.246 +
   2.247 +		/// <summary>
   2.248 +		/// 
   2.249 +		/// </summary>
   2.250 +		void HideClock()
   2.251 +		{
   2.252 +			if (!iDisplay.IsOpen())
   2.253 +			{
   2.254 +				return;
   2.255 +			}
   2.256 +
   2.257 +			//Devices like MDM166AA don't support windowing and frame rendering must be stopped while showing our clock
   2.258 +			iSkipFrameRendering = false;
   2.259 +			iDisplay.HideClock();
   2.260 +		}
   2.261  
   2.262          private void InstallUpdateSyncWithInfo()
   2.263          {
     3.1 --- a/Server/SharpDisplayManager.csproj	Mon Feb 09 22:50:43 2015 +0100
     3.2 +++ b/Server/SharpDisplayManager.csproj	Tue Feb 10 15:41:34 2015 +0100
     3.3 @@ -31,7 +31,7 @@
     3.4      <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
     3.5      <WebPage>index.htm</WebPage>
     3.6      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
     3.7 -    <ApplicationRevision>1</ApplicationRevision>
     3.8 +    <ApplicationRevision>2</ApplicationRevision>
     3.9      <ApplicationVersion>0.2.1.%2a</ApplicationVersion>
    3.10      <UseApplicationTrust>false</UseApplicationTrust>
    3.11      <CreateDesktopShortcut>true</CreateDesktopShortcut>