public AmbiBeam() { _config = Properties.Settings.Default["Setting"] as Config; if (_config == null) _config = new Config(); var trayMenu = new ContextMenu(); trayMenu.MenuItems.Add("Start/Stop", OnStartStop); trayMenu.MenuItems.Add("Configure", OnConfigure); trayMenu.MenuItems.Add("Test", OnTest); trayMenu.MenuItems.Add("Exit", OnExit); _trayIcon = new NotifyIcon { Text = "AmbiBeam", Icon = Properties.Resources.Color, ContextMenu = trayMenu, Visible = true }; _timer = new System.Timers.Timer { AutoReset = true, Interval = 50 }; _mDnsBrowser = new ServiceBrowser(); _mDnsBrowser.StartBrowse("_ambibeam._udp"); }
private void OnConfigure(object sender, EventArgs e) { Configure configure = new Configure(_mDnsBrowser) {Config = _config}; var result = configure.ShowDialog(); if (result == DialogResult.OK) { _config = configure.Config; Properties.Settings.Default["Setting"] = _config; Properties.Settings.Default.Save(); } }
public Capture(Config config) { // init DX PresentParameters presentParameters = new PresentParameters { Windowed = true, SwapEffect = SwapEffect.Discard }; _config = config; int idx = Array.IndexOf(Screen.AllScreens, config.GetScreen()); _d = new Device(new Direct3D(), idx, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, presentParameters); // init capture positions int hx = config.GetCaptureRectangle().Width / config.LEDsWidth; int hy = config.GetCaptureRectangle().Height / config.LEDsHeight; TopLongs = new List<List<long>>(); BottomLongs = new List<List<long>>(); LeftLongs = new List<List<long>> (); RightLongs = new List<List<long>> (); int part = 0; Rectangle captureSize = config.GetCaptureRectangle(); int add = (captureSize.Width - (hx*config.LEDsWidth))/2; int nextBlock = hx + add ; TopLongs.Add(new List<long>()); BottomLongs.Add(new List<long>()); for (int i = 0; i < config.GetScreen().Bounds.Width; ++i) { if (i == nextBlock) { part++; nextBlock += hx; if (nextBlock == hx*config.LEDsWidth + add) nextBlock += add; TopLongs.Add(new List<long>()); BottomLongs.Add(new List<long>()); } for (int j = 0; j < config.MarginTop; ++j) TopLongs[part].Add(PointToLong(i, j + config.OffsetTop)); for (int j = 0; j < config.MarginBottom; ++j) BottomLongs[part].Add(PointToLong(i, config.GetScreen().Bounds.Height - 1 - j - config.OffsetBottom)); } part = 0; add = (captureSize.Height - (hy * config.LEDsHeight)) / 2; nextBlock = hy + add; LeftLongs.Add(new List<long>()); RightLongs.Add(new List<long>()); for (int i = 0; i < config.GetScreen().Bounds.Height; ++i) { if (i == nextBlock) { part++; nextBlock += hy; if (nextBlock == hy * config.LEDsHeight + add) nextBlock += add; LeftLongs.Add(new List<long>()); RightLongs.Add(new List<long>()); } for (int j = 0; j < config.MarginLeft; ++j) LeftLongs[part].Add(PointToLong(j + config.OffsetLeft, i)); for (int j = 0; j < config.MarginRight; ++j) RightLongs[part].Add(PointToLong(config.GetScreen().Bounds.Width - 1 - config.OffsetRight - j, i)); } // init color positions TopColors = new List<Color>(); BottomColors = new List<Color>(); LeftColors = new List<Color>(); RightColors = new List<Color>(); }