MainForm.cs
changeset 16 985ca4b6e099
parent 14 d1fa9de444b0
child 17 19c1aaf900dc
     1.1 --- a/MainForm.cs	Tue Aug 05 22:11:08 2014 +0200
     1.2 +++ b/MainForm.cs	Mon Aug 11 23:18:45 2014 +0200
     1.3 @@ -34,6 +34,7 @@
     1.4              marqueeLabelBottom.Font = Properties.Settings.Default.DisplayFont;
     1.5              checkBoxShowBorders.Checked = Properties.Settings.Default.DisplayShowBorders;
     1.6              checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup;
     1.7 +            checkBoxReverseScreen.Checked = Properties.Settings.Default.DisplayReverseScreen;
     1.8              //
     1.9              tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
    1.10              //We have a bug when drawing minimized and reusing our bitmap
    1.11 @@ -139,6 +140,32 @@
    1.12              }
    1.13          }
    1.14  
    1.15 +
    1.16 +        public delegate int CoordinateTranslationDelegate(System.Drawing.Bitmap aBmp, int aInt);
    1.17 +
    1.18 +
    1.19 +        public static int ScreenReversedX(System.Drawing.Bitmap aBmp, int aX)
    1.20 +        {
    1.21 +            return aBmp.Width - aX - 1;
    1.22 +        }
    1.23 +
    1.24 +        public int ScreenReversedY(System.Drawing.Bitmap aBmp, int aY)
    1.25 +        {
    1.26 +            return iBmp.Height - aY - 1;
    1.27 +        }
    1.28 +
    1.29 +        public int ScreenX(System.Drawing.Bitmap aBmp, int aX)
    1.30 +        {
    1.31 +            return aX;
    1.32 +        }
    1.33 +
    1.34 +        public int ScreenY(System.Drawing.Bitmap aBmp, int aY)
    1.35 +        {
    1.36 +            return aY;
    1.37 +        }
    1.38 +
    1.39 +
    1.40 +        //This is our timer tick responsible to perform our render
    1.41          private void timer_Tick(object sender, EventArgs e)
    1.42          {
    1.43              //Update our animations
    1.44 @@ -159,9 +186,23 @@
    1.45                  }
    1.46                  tableLayoutPanel.DrawToBitmap(iBmp, tableLayoutPanel.ClientRectangle);
    1.47                  //iBmp.Save("D:\\capture.png");
    1.48 +
    1.49 +                //Select proper coordinate translation functions
    1.50 +                //We used delegate/function pointer to support reverse screen without doing an extra test on each pixels
    1.51 +                CoordinateTranslationDelegate screenX;
    1.52 +                CoordinateTranslationDelegate screenY;
    1.53 +
    1.54 +                if (Properties.Settings.Default.DisplayReverseScreen)
    1.55 +                {
    1.56 +                    screenX = ScreenReversedX;
    1.57 +                    screenY = ScreenReversedY;
    1.58 +                }
    1.59 +                else
    1.60 +                {
    1.61 +                    screenX = ScreenX;
    1.62 +                    screenY = ScreenY;
    1.63 +                }
    1.64                  
    1.65 -                //iBmp.
    1.66 -
    1.67                  //Send it to our display
    1.68                  for (int i = 0; i < iBmp.Width; i++)
    1.69                  {
    1.70 @@ -172,7 +213,7 @@
    1.71                              uint color = (uint)iBmp.GetPixel(i, j).ToArgb();
    1.72                              //For some reason when the app is minimized in the task bar only the alpha of our color is set.
    1.73                              //Thus that strange test for rendering to work both when the app is in the task bar and when it isn't.
    1.74 -                            iDisplay.SetPixel(i, j, Convert.ToInt32(!(color != 0xFF000000)));
    1.75 +                            iDisplay.SetPixel(screenX(iBmp, i), screenY(iBmp, j), Convert.ToInt32(!(color != 0xFF000000)));
    1.76                          }
    1.77                      }
    1.78                  }
    1.79 @@ -263,6 +304,7 @@
    1.80  
    1.81          private void checkBoxShowBorders_CheckedChanged(object sender, EventArgs e)
    1.82          {
    1.83 +            //Save our show borders setting
    1.84              tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
    1.85              Properties.Settings.Default.DisplayShowBorders = checkBoxShowBorders.Checked;
    1.86              Properties.Settings.Default.Save();
    1.87 @@ -270,10 +312,18 @@
    1.88  
    1.89          private void checkBoxConnectOnStartup_CheckedChanged(object sender, EventArgs e)
    1.90          {
    1.91 +            //Save our connect on startup setting
    1.92              Properties.Settings.Default.DisplayConnectOnStartup = checkBoxConnectOnStartup.Checked;
    1.93              Properties.Settings.Default.Save();
    1.94          }
    1.95  
    1.96 +        private void checkBoxReverseScreen_CheckedChanged(object sender, EventArgs e)
    1.97 +        {
    1.98 +            //Save our reverse screen setting
    1.99 +            Properties.Settings.Default.DisplayReverseScreen = checkBoxReverseScreen.Checked;
   1.100 +            Properties.Settings.Default.Save();
   1.101 +        }
   1.102 +
   1.103          private void MainForm_Resize(object sender, EventArgs e)
   1.104          {
   1.105              if (WindowState == FormWindowState.Minimized)