MainForm.cs
author sl
Tue, 08 Jul 2014 18:59:07 +0200
changeset 8 5129c03ab7ba
parent 7 69815d19796c
child 9 7c363a7a975e
permissions -rw-r--r--
Adding persistent settings and marquee separator.
sl@0
     1
´╗┐using System;
sl@0
     2
using System.Collections.Generic;
sl@0
     3
using System.ComponentModel;
sl@0
     4
using System.Data;
sl@0
     5
using System.Drawing;
sl@0
     6
using System.Linq;
sl@0
     7
using System.Text;
sl@0
     8
using System.Threading.Tasks;
sl@0
     9
using System.Windows.Forms;
sl@0
    10
using CodeProject.Dialog;
sl@0
    11
sl@0
    12
namespace SharpDisplayManager
sl@0
    13
{
sl@0
    14
    public partial class MainForm : Form
sl@0
    15
    {
sl@2
    16
        DateTime LastTickTime;
sl@3
    17
        Display iDisplay;
sl@2
    18
sl@0
    19
        public MainForm()
sl@0
    20
        {
sl@2
    21
            LastTickTime = DateTime.Now;
sl@3
    22
            iDisplay = new Display();
sl@2
    23
sl@0
    24
            InitializeComponent();
sl@7
    25
            UpdateStatus();
sl@8
    26
            //Load settings
sl@8
    27
            marqueeLabelTop.Font = Properties.Settings.Default.DisplayFont;
sl@8
    28
            marqueeLabelBottom.Font = Properties.Settings.Default.DisplayFont;
sl@0
    29
        }
sl@0
    30
sl@0
    31
        private void buttonFont_Click(object sender, EventArgs e)
sl@0
    32
        {
sl@0
    33
            //fontDialog.ShowColor = true;
sl@0
    34
            //fontDialog.ShowApply = true;
sl@0
    35
            fontDialog.ShowEffects = true;
sl@0
    36
            //fontDialog.ShowHelp = true;
sl@0
    37
sl@0
    38
            //fontDlg.MaxSize = 40;
sl@0
    39
            //fontDlg.MinSize = 22;
sl@0
    40
sl@0
    41
            //fontDialog.Parent = this;
sl@0
    42
            //fontDialog.StartPosition = FormStartPosition.CenterParent;
sl@0
    43
sl@0
    44
            //DlgBox.ShowDialog(fontDialog);
sl@0
    45
sl@0
    46
            //if (fontDialog.ShowDialog(this) != DialogResult.Cancel)
sl@0
    47
            if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel)
sl@0
    48
            {
sl@0
    49
sl@4
    50
                //MsgBox.Show("MessageBox MsgBox", "MsgBox caption");
sl@0
    51
sl@0
    52
                //MessageBox.Show("Ok");
sl@4
    53
                marqueeLabelTop.Font = fontDialog.Font;
sl@4
    54
                marqueeLabelBottom.Font = fontDialog.Font;
sl@8
    55
                Properties.Settings.Default.DisplayFont = fontDialog.Font;
sl@8
    56
                Properties.Settings.Default.Save();
sl@0
    57
                //label1.Font = fontDlg.Font;
sl@0
    58
                //textBox1.BackColor = fontDlg.Color;
sl@0
    59
                //label1.ForeColor = fontDlg.Color;
sl@0
    60
            }
sl@0
    61
        }
sl@0
    62
sl@0
    63
        private void buttonCapture_Click(object sender, EventArgs e)
sl@0
    64
        {
sl@0
    65
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
sl@0
    66
            tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
sl@0
    67
            bmp.Save("c:\\capture.png");
sl@0
    68
        }
sl@2
    69
sl@2
    70
        private void timer_Tick(object sender, EventArgs e)
sl@2
    71
        {
sl@2
    72
            //Update our animations
sl@2
    73
            DateTime NewTickTime = DateTime.Now;
sl@2
    74
sl@2
    75
            marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
sl@2
    76
            marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
sl@2
    77
sl@4
    78
            //Update our display
sl@4
    79
            if (iDisplay.IsOpen())
sl@4
    80
            {
sl@4
    81
                //Draw to bitmap
sl@4
    82
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
sl@4
    83
                tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
sl@7
    84
                //Send it to our display
sl@4
    85
                for (int i = 0; i < bmp.Width; i++)
sl@4
    86
                {
sl@4
    87
                    for (int j = 0; j < bmp.Height; j++)
sl@4
    88
                    {
sl@4
    89
                        unchecked
sl@4
    90
                        {
sl@4
    91
                        uint color=(uint)bmp.GetPixel(i, j).ToArgb();
sl@4
    92
                        iDisplay.SetPixel(i, j, Convert.ToInt32(color!=0xFFFFFFFF));
sl@4
    93
                        }
sl@4
    94
                    }
sl@4
    95
                }
sl@4
    96
sl@4
    97
                iDisplay.SwapBuffers();
sl@4
    98
sl@4
    99
            }
sl@8
   100
sl@8
   101
            //Compute instant FPS
sl@8
   102
            toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " FPS";
sl@8
   103
sl@8
   104
            LastTickTime = NewTickTime;
sl@8
   105
sl@2
   106
        }
sl@3
   107
sl@3
   108
        private void buttonOpen_Click(object sender, EventArgs e)
sl@3
   109
        {
sl@3
   110
            if (iDisplay.Open())
sl@3
   111
            {
sl@7
   112
                UpdateStatus();
sl@3
   113
            }
sl@7
   114
            else
sl@7
   115
            {
sl@7
   116
                UpdateStatus();
sl@7
   117
                toolStripStatusLabelConnect.Text = "Connection error";
sl@7
   118
            }
sl@7
   119
sl@3
   120
        }
sl@3
   121
sl@3
   122
        private void buttonClose_Click(object sender, EventArgs e)
sl@3
   123
        {
sl@3
   124
            iDisplay.Close();
sl@3
   125
        }
sl@3
   126
sl@3
   127
        private void buttonClear_Click(object sender, EventArgs e)
sl@3
   128
        {
sl@3
   129
            iDisplay.Clear();
sl@3
   130
            iDisplay.SwapBuffers();
sl@3
   131
        }
sl@3
   132
sl@3
   133
        private void buttonFill_Click(object sender, EventArgs e)
sl@3
   134
        {
sl@3
   135
            iDisplay.Fill();
sl@3
   136
            iDisplay.SwapBuffers();
sl@3
   137
        }
sl@3
   138
sl@3
   139
        private void trackBarBrightness_Scroll(object sender, EventArgs e)
sl@3
   140
        {
sl@3
   141
            iDisplay.SetBrightness(trackBarBrightness.Value);
sl@3
   142
        }
sl@7
   143
sl@7
   144
        private void UpdateStatus()
sl@7
   145
        {
sl@7
   146
            if (iDisplay.IsOpen())
sl@7
   147
            {
sl@7
   148
                buttonFill.Enabled = true;
sl@7
   149
                buttonClear.Enabled = true;
sl@7
   150
                buttonOpen.Enabled = false;
sl@7
   151
                buttonClose.Enabled = true;
sl@7
   152
                trackBarBrightness.Enabled = true;
sl@7
   153
                trackBarBrightness.Minimum = iDisplay.MinBrightness();
sl@7
   154
                trackBarBrightness.Maximum = iDisplay.MaxBrightness();
sl@7
   155
                toolStripStatusLabelConnect.Text = "Connected";
sl@7
   156
            }
sl@7
   157
            else
sl@7
   158
            {
sl@7
   159
                buttonFill.Enabled = false;
sl@7
   160
                buttonClear.Enabled = false;
sl@7
   161
                buttonOpen.Enabled = true;
sl@7
   162
                buttonClose.Enabled = false;
sl@7
   163
                trackBarBrightness.Enabled = false;
sl@7
   164
                toolStripStatusLabelConnect.Text = "Not connected";
sl@7
   165
            }
sl@7
   166
        }
sl@0
   167
    }
sl@0
   168
}