Server/MainForm.cs
changeset 58 2a527027024d
parent 57 544132d07c3b
child 59 9979787100b1
     1.1 --- a/Server/MainForm.cs	Sun Sep 21 19:07:18 2014 +0200
     1.2 +++ b/Server/MainForm.cs	Sun Sep 21 21:51:01 2014 +0200
     1.3 @@ -19,8 +19,16 @@
     1.4  
     1.5  namespace SharpDisplayManager
     1.6  {
     1.7 +    //Types declarations
     1.8 +    public delegate uint ColorProcessingDelegate(int aX, int aY, uint aPixel);
     1.9 +    public delegate int CoordinateTranslationDelegate(System.Drawing.Bitmap aBmp, int aInt);
    1.10 +
    1.11 +    /// <summary>
    1.12 +    /// Our Display manager main form
    1.13 +    /// </summary>
    1.14      public partial class MainForm : Form
    1.15      {
    1.16 +
    1.17          DateTime LastTickTime;
    1.18          Display iDisplay;
    1.19          System.Drawing.Bitmap iBmp;
    1.20 @@ -31,6 +39,9 @@
    1.21          /// </summary>
    1.22          public Dictionary<string, ClientData> iClients;
    1.23          public bool iClosing;
    1.24 +        ColorProcessingDelegate iColorFx;
    1.25 +        CoordinateTranslationDelegate iScreenX;
    1.26 +        CoordinateTranslationDelegate iScreenY;
    1.27  
    1.28          public MainForm()
    1.29          {
    1.30 @@ -206,20 +217,38 @@
    1.31              }
    1.32          }
    1.33  
    1.34 +        public static uint ColorWhiteIsOn(int aX, int aY, uint aPixel)
    1.35 +        {
    1.36 +            if ((aPixel & 0x00FFFFFF) == 0x00FFFFFF)
    1.37 +            {
    1.38 +                return 0xFFFFFFFF;
    1.39 +            }
    1.40 +            return 0x00000000;
    1.41 +        }
    1.42  
    1.43 -        public delegate uint ColorProcessingDelegate(uint aPixel);
    1.44 -
    1.45 -        public static uint ColorUntouched(uint aPixel)
    1.46 +        public static uint ColorUntouched(int aX, int aY, uint aPixel)
    1.47          {
    1.48              return aPixel;
    1.49          }
    1.50  
    1.51 -        public static uint ColorInversed(uint aPixel)
    1.52 +        public static uint ColorInversed(int aX, int aY, uint aPixel)
    1.53          {
    1.54              return ~aPixel;
    1.55          }
    1.56  
    1.57 -        public delegate int CoordinateTranslationDelegate(System.Drawing.Bitmap aBmp, int aInt);
    1.58 +        public static uint ColorChessboard(int aX, int aY, uint aPixel)
    1.59 +        {
    1.60 +            if ((aX % 2 == 0) && (aY % 2 == 0))
    1.61 +            {
    1.62 +                return ~aPixel;
    1.63 +            }
    1.64 +            else if ((aX % 2 != 0) && (aY % 2 != 0))
    1.65 +            {
    1.66 +                return ~aPixel;
    1.67 +            }
    1.68 +            return 0x00000000;
    1.69 +        }
    1.70 +
    1.71  
    1.72          public static int ScreenReversedX(System.Drawing.Bitmap aBmp, int aX)
    1.73          {
    1.74 @@ -241,6 +270,36 @@
    1.75              return aY;
    1.76          }
    1.77  
    1.78 +        /// <summary>
    1.79 +        /// Select proper pixel delegates according to our current settings.
    1.80 +        /// </summary>
    1.81 +        private void SetupPixelDelegates()
    1.82 +        {
    1.83 +            //Select our pixel processing routine                
    1.84 +            if (cds.InverseColors)
    1.85 +            {
    1.86 +                //iColorFx = ColorChessboard;
    1.87 +                iColorFx = ColorInversed;
    1.88 +            }
    1.89 +            else
    1.90 +            {
    1.91 +                iColorFx = ColorWhiteIsOn;
    1.92 +            }
    1.93 +
    1.94 +            //Select proper coordinate translation functions
    1.95 +            //We used delegate/function pointer to support reverse screen without doing an extra test on each pixels
    1.96 +            if (cds.ReverseScreen)
    1.97 +            {
    1.98 +                iScreenX = ScreenReversedX;
    1.99 +                iScreenY = ScreenReversedY;
   1.100 +            }
   1.101 +            else
   1.102 +            {
   1.103 +                iScreenX = ScreenX;
   1.104 +                iScreenY = ScreenY;
   1.105 +            }
   1.106 +
   1.107 +        }
   1.108  
   1.109          //This is our timer tick responsible to perform our render
   1.110          private void timer_Tick(object sender, EventArgs e)
   1.111 @@ -264,35 +323,6 @@
   1.112                  tableLayoutPanel.DrawToBitmap(iBmp, tableLayoutPanel.ClientRectangle);
   1.113                  //iBmp.Save("D:\\capture.png");
   1.114  
   1.115 -
   1.116 -                //Select our pixel processing routine
   1.117 -                ColorProcessingDelegate colorFx;
   1.118 -
   1.119 -                if (cds.InverseColors)
   1.120 -                {
   1.121 -                    colorFx = ColorInversed;
   1.122 -                }
   1.123 -                else
   1.124 -                {
   1.125 -                    colorFx = ColorUntouched;
   1.126 -                }
   1.127 -
   1.128 -                //Select proper coordinate translation functions
   1.129 -                //We used delegate/function pointer to support reverse screen without doing an extra test on each pixels
   1.130 -                CoordinateTranslationDelegate screenX;
   1.131 -                CoordinateTranslationDelegate screenY;
   1.132 -
   1.133 -                if (cds.ReverseScreen)
   1.134 -                {
   1.135 -                    screenX = ScreenReversedX;
   1.136 -                    screenY = ScreenReversedY;
   1.137 -                }
   1.138 -                else
   1.139 -                {
   1.140 -                    screenX = ScreenX;
   1.141 -                    screenY = ScreenY;
   1.142 -                }
   1.143 -
   1.144                  //Send it to our display
   1.145                  for (int i = 0; i < iBmp.Width; i++)
   1.146                  {
   1.147 @@ -300,13 +330,15 @@
   1.148                      {
   1.149                          unchecked
   1.150                          {
   1.151 +                            //Get our processed pixel coordinates
   1.152 +                            int x = iScreenX(iBmp, i);
   1.153 +                            int y = iScreenY(iBmp, j);
   1.154 +                            //Get pixel color
   1.155                              uint color = (uint)iBmp.GetPixel(i, j).ToArgb();
   1.156                              //Apply color effects
   1.157 -                            color = colorFx(color);
   1.158 -                            //For some reason when the app is minimized in the task bar only the alpha of our color is set.
   1.159 -                            //Thus that strange test for rendering to work both when the app is in the task bar and when it isn't.
   1.160 -                            //iDisplay.SetPixel(screenX(iBmp, i), screenY(iBmp, j), Convert.ToInt32(!(color != 0xFF000000)));
   1.161 -                            iDisplay.SetPixel(screenX(iBmp, i), screenY(iBmp, j), color);
   1.162 +                            color = iColorFx(x,y,color);
   1.163 +                            //Now set our pixel
   1.164 +                            iDisplay.SetPixel(x, y, color);
   1.165                          }
   1.166                      }
   1.167                  }
   1.168 @@ -430,7 +462,6 @@
   1.169          {
   1.170              //Synchronize UI with settings
   1.171              //Load settings
   1.172 -
   1.173              checkBoxShowBorders.Checked = cds.ShowBorders;
   1.174              tableLayoutPanel.CellBorderStyle = (cds.ShowBorders ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
   1.175              marqueeLabelTop.Font = cds.Font;
   1.176 @@ -442,7 +473,8 @@
   1.177              comboBoxDisplayType.SelectedIndex = cds.DisplayType;
   1.178              timer.Interval = cds.TimerInterval;
   1.179              maskedTextBoxTimerInterval.Text = cds.TimerInterval.ToString();
   1.180 -
   1.181 +            //
   1.182 +            SetupPixelDelegates();
   1.183  
   1.184              if (iDisplay.IsOpen())
   1.185              {
   1.186 @@ -523,6 +555,7 @@
   1.187              //Save our reverse screen setting
   1.188              cds.ReverseScreen = checkBoxReverseScreen.Checked;
   1.189              Properties.Settings.Default.Save();
   1.190 +            SetupPixelDelegates();
   1.191          }
   1.192  
   1.193          private void checkBoxInverseColors_CheckedChanged(object sender, EventArgs e)
   1.194 @@ -530,6 +563,7 @@
   1.195              //Save our inverse colors setting
   1.196              cds.InverseColors = checkBoxInverseColors.Checked;
   1.197              Properties.Settings.Default.Save();
   1.198 +            SetupPixelDelegates();
   1.199          }
   1.200  
   1.201          private void MainForm_Resize(object sender, EventArgs e)