# HG changeset patch # User sl # Date 1411319238 -7200 # Node ID 544132d07c3b3f91d74a5f8567f5ddf46051404e # Parent e86d84480b327969b2f30764c37b07883f6e4d6f Simplifying client construction. Fixing our borders and sorting out our color issues. Adding inverse colors options. diff -r e86d84480b32 -r 544132d07c3b Client/Client.cs --- a/Client/Client.cs Sun Sep 21 13:40:21 2014 +0200 +++ b/Client/Client.cs Sun Sep 21 19:07:18 2014 +0200 @@ -60,8 +60,8 @@ public string Name { get; set; } public string SessionId { get { return InnerChannel.SessionId; } } - public Client(InstanceContext callbackInstance) - : base(callbackInstance, new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService")) + public Client(ICallback aCallback) + : base(new InstanceContext(aCallback), new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService")) { } public void SetName(string aClientName) @@ -84,5 +84,10 @@ { return Channel.ClientCount(); } + + public bool IsReady() + { + return State == CommunicationState.Opened; + } } } diff -r e86d84480b32 -r 544132d07c3b Client/MainForm.cs --- a/Client/MainForm.cs Sun Sep 21 13:40:21 2014 +0200 +++ b/Client/MainForm.cs Sun Sep 21 19:07:18 2014 +0200 @@ -33,9 +33,7 @@ private void MainForm_Load(object sender, EventArgs e) { iCallback = new Callback(this); - //Instance context is then managed by our client class - InstanceContext instanceContext = new InstanceContext(iCallback); - iClient = new Client(instanceContext); + iClient = new Client(iCallback); //Connect using unique name //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"); diff -r e86d84480b32 -r 544132d07c3b Server/Display.cs --- a/Server/Display.cs Sun Sep 21 13:40:21 2014 +0200 +++ b/Server/Display.cs Sun Sep 21 19:07:18 2014 +0200 @@ -85,7 +85,7 @@ return MiniDisplayHeightInPixels(iDevice); } - public void SetPixel(int aX, int aY, int aValue) + public void SetPixel(int aX, int aY, uint aValue) { MiniDisplaySetPixel(iDevice,aX,aY,aValue); } @@ -246,7 +246,7 @@ public static extern int MiniDisplayHeightInPixels(IntPtr aDevice); [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] - public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, int aValue); + public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, uint aValue); [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr MiniDisplayVendor(IntPtr aDevice); diff -r e86d84480b32 -r 544132d07c3b Server/DisplaySettings.cs --- a/Server/DisplaySettings.cs Sun Sep 21 13:40:21 2014 +0200 +++ b/Server/DisplaySettings.cs Sun Sep 21 19:07:18 2014 +0200 @@ -24,6 +24,7 @@ DisplayType = 0; TimerInterval = 150; ReverseScreen = false; + InverseColors = true; ShowBorders = false; FontName = "Microsoft Sans Serif, 9.75pt"; } @@ -44,6 +45,9 @@ public bool ReverseScreen { get; set; } [DataMember] + public bool InverseColors { get; set; } + + [DataMember] public bool ShowBorders { get; set; } [DataMember] diff -r e86d84480b32 -r 544132d07c3b Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Sun Sep 21 13:40:21 2014 +0200 +++ b/Server/MainForm.Designer.cs Sun Sep 21 19:07:18 2014 +0200 @@ -31,6 +31,8 @@ this.components = new System.ComponentModel.Container(); this.panelDisplay = new System.Windows.Forms.Panel(); this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel(); + this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel(); this.fontDialog = new System.Windows.Forms.FontDialog(); this.timer = new System.Windows.Forms.Timer(this.components); this.statusStrip = new System.Windows.Forms.StatusStrip(); @@ -72,10 +74,9 @@ this.checkBoxReverseScreen = new System.Windows.Forms.CheckBox(); this.buttonRemoveRow = new System.Windows.Forms.Button(); this.buttonAddRow = new System.Windows.Forms.Button(); - this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel(); - this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel(); this.labelFontWidth = new System.Windows.Forms.Label(); this.labelFontHeight = new System.Windows.Forms.Label(); + this.checkBoxInverseColors = new System.Windows.Forms.CheckBox(); this.panelDisplay.SuspendLayout(); this.tableLayoutPanel.SuspendLayout(); this.statusStrip.SuspendLayout(); @@ -206,6 +207,39 @@ this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64); this.tableLayoutPanel.TabIndex = 5; // + // marqueeLabelTop + // + this.marqueeLabelTop.AutoEllipsis = true; + this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent; + this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill; + this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1); + this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0); + this.marqueeLabelTop.Name = "marqueeLabelTop"; + this.marqueeLabelTop.OwnTimer = false; + this.marqueeLabelTop.PixelsPerSecond = 64; + this.marqueeLabelTop.Separator = "|"; + this.marqueeLabelTop.Size = new System.Drawing.Size(254, 30); + this.marqueeLabelTop.TabIndex = 2; + this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789"; + this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.marqueeLabelTop.UseCompatibleTextRendering = true; + // + // marqueeLabelBottom + // + this.marqueeLabelBottom.AutoEllipsis = true; + this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill; + this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 32); + this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0); + this.marqueeLabelBottom.Name = "marqueeLabelBottom"; + this.marqueeLabelBottom.OwnTimer = false; + this.marqueeLabelBottom.PixelsPerSecond = 64; + this.marqueeLabelBottom.Separator = "|"; + this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 31); + this.marqueeLabelBottom.TabIndex = 3; + this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789"; + this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.marqueeLabelBottom.UseCompatibleTextRendering = true; + // // timer // this.timer.Enabled = true; @@ -542,6 +576,7 @@ // // tabPageDesign // + this.tabPageDesign.Controls.Add(this.checkBoxInverseColors); this.tabPageDesign.Controls.Add(this.buttonAlignRight); this.tabPageDesign.Controls.Add(this.buttonAlignCenter); this.tabPageDesign.Controls.Add(this.buttonAlignLeft); @@ -643,39 +678,6 @@ this.buttonAddRow.UseVisualStyleBackColor = true; this.buttonAddRow.Click += new System.EventHandler(this.buttonAddRow_Click); // - // marqueeLabelTop - // - this.marqueeLabelTop.AutoEllipsis = true; - this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent; - this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1); - this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0); - this.marqueeLabelTop.Name = "marqueeLabelTop"; - this.marqueeLabelTop.OwnTimer = false; - this.marqueeLabelTop.PixelsPerSecond = 64; - this.marqueeLabelTop.Separator = "|"; - this.marqueeLabelTop.Size = new System.Drawing.Size(254, 9); - this.marqueeLabelTop.TabIndex = 2; - this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789"; - this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.marqueeLabelTop.UseCompatibleTextRendering = true; - // - // marqueeLabelBottom - // - this.marqueeLabelBottom.AutoEllipsis = true; - this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 21); - this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0); - this.marqueeLabelBottom.Name = "marqueeLabelBottom"; - this.marqueeLabelBottom.OwnTimer = false; - this.marqueeLabelBottom.PixelsPerSecond = 64; - this.marqueeLabelBottom.Separator = "|"; - this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 20); - this.marqueeLabelBottom.TabIndex = 3; - this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789"; - this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.marqueeLabelBottom.UseCompatibleTextRendering = true; - // // labelFontWidth // this.labelFontWidth.AutoSize = true; @@ -694,6 +696,18 @@ this.labelFontHeight.TabIndex = 20; this.labelFontHeight.Text = "Font height"; // + // checkBoxInverseColors + // + this.checkBoxInverseColors.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.checkBoxInverseColors.AutoSize = true; + this.checkBoxInverseColors.Location = new System.Drawing.Point(485, 52); + this.checkBoxInverseColors.Name = "checkBoxInverseColors"; + this.checkBoxInverseColors.Size = new System.Drawing.Size(92, 17); + this.checkBoxInverseColors.TabIndex = 21; + this.checkBoxInverseColors.Text = "Inverse colors"; + this.checkBoxInverseColors.UseVisualStyleBackColor = true; + this.checkBoxInverseColors.CheckedChanged += new System.EventHandler(this.checkBoxInverseColors_CheckedChanged); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -776,6 +790,7 @@ private System.Windows.Forms.Button buttonHideClock; private System.Windows.Forms.Label labelFontWidth; private System.Windows.Forms.Label labelFontHeight; + private System.Windows.Forms.CheckBox checkBoxInverseColors; } } diff -r e86d84480b32 -r 544132d07c3b Server/MainForm.cs --- a/Server/MainForm.cs Sun Sep 21 13:40:21 2014 +0200 +++ b/Server/MainForm.cs Sun Sep 21 19:07:18 2014 +0200 @@ -43,6 +43,8 @@ //We have a bug when drawing minimized and reusing our bitmap iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb); iCreateBitmap = false; + // + //this.tableLayoutPanel.CellPaint += new TableLayoutCellPaintEventHandler(tableLayoutPanel_CellPaint); } private void MainForm_Load(object sender, EventArgs e) @@ -55,6 +57,31 @@ } } + //Testing that stuff + private void tableLayoutPanel_CellPaint(object sender, TableLayoutCellPaintEventArgs e) + { + var panel = sender as TableLayoutPanel; + //e.Graphics.SmoothingMode = SmoothingMode.HighQuality; + var rectangle = e.CellBounds; + using (var pen = new Pen(Color.Black, 1)) + { + pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; + pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; + + if (e.Row == (panel.RowCount - 1)) + { + rectangle.Height -= 1; + } + + if (e.Column == (panel.ColumnCount - 1)) + { + rectangle.Width -= 1; + } + + e.Graphics.DrawRectangle(pen, rectangle); + } + } + private void buttonFont_Click(object sender, EventArgs e) { @@ -180,9 +207,20 @@ } + public delegate uint ColorProcessingDelegate(uint aPixel); + + public static uint ColorUntouched(uint aPixel) + { + return aPixel; + } + + public static uint ColorInversed(uint aPixel) + { + return ~aPixel; + } + public delegate int CoordinateTranslationDelegate(System.Drawing.Bitmap aBmp, int aInt); - public static int ScreenReversedX(System.Drawing.Bitmap aBmp, int aX) { return aBmp.Width - aX - 1; @@ -226,6 +264,19 @@ tableLayoutPanel.DrawToBitmap(iBmp, tableLayoutPanel.ClientRectangle); //iBmp.Save("D:\\capture.png"); + + //Select our pixel processing routine + ColorProcessingDelegate colorFx; + + if (cds.InverseColors) + { + colorFx = ColorInversed; + } + else + { + colorFx = ColorUntouched; + } + //Select proper coordinate translation functions //We used delegate/function pointer to support reverse screen without doing an extra test on each pixels CoordinateTranslationDelegate screenX; @@ -250,9 +301,12 @@ unchecked { uint color = (uint)iBmp.GetPixel(i, j).ToArgb(); + //Apply color effects + color = colorFx(color); //For some reason when the app is minimized in the task bar only the alpha of our color is set. //Thus that strange test for rendering to work both when the app is in the task bar and when it isn't. - iDisplay.SetPixel(screenX(iBmp, i), screenY(iBmp, j), Convert.ToInt32(!(color != 0xFF000000))); + //iDisplay.SetPixel(screenX(iBmp, i), screenY(iBmp, j), Convert.ToInt32(!(color != 0xFF000000))); + iDisplay.SetPixel(screenX(iBmp, i), screenY(iBmp, j), color); } } } @@ -384,6 +438,7 @@ CheckFontHeight(); checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup; checkBoxReverseScreen.Checked = cds.ReverseScreen; + checkBoxInverseColors.Checked = cds.InverseColors; comboBoxDisplayType.SelectedIndex = cds.DisplayType; timer.Interval = cds.TimerInterval; maskedTextBoxTimerInterval.Text = cds.TimerInterval.ToString(); @@ -453,6 +508,7 @@ tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); cds.ShowBorders = checkBoxShowBorders.Checked; Properties.Settings.Default.Save(); + CheckFontHeight(); } private void checkBoxConnectOnStartup_CheckedChanged(object sender, EventArgs e) @@ -469,6 +525,13 @@ Properties.Settings.Default.Save(); } + private void checkBoxInverseColors_CheckedChanged(object sender, EventArgs e) + { + //Save our inverse colors setting + cds.InverseColors = checkBoxInverseColors.Checked; + Properties.Settings.Default.Save(); + } + private void MainForm_Resize(object sender, EventArgs e) { if (WindowState == FormWindowState.Minimized)