Beispiel #1
0
        private void lbBulbs_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_suspendUi)
            {
                return;
            }
            _suspendUi = true;
            if (lbBulbs.SelectedItem == null)
            {
                cbArea.Enabled = false;
                return;
            }

            SelectedLabelAndLocation =
                LabelsAndLocations.Single(x => x.Label == (((ListBox)sender).SelectedItem.ToString()));

            foreach (var v in cbArea.Items)
            {
                if (v.ToString() == Enum.GetName(typeof(ScreenLocation), SelectedLabelAndLocation.ScreenLocation))
                {
                    cbArea.SelectedItem = v;
                }
            }

            cbArea.Enabled = true;

            _suspendUi = false;
        }
        private void Pb_Click(object sender, EventArgs e)
        {
            if (lbBulbs.SelectedItem == null)
            {
                return;
            }

            SelectedLabelAndLocation = LabelsAndLocations.SingleOrDefault(x => x.Label == (lbBulbs.SelectedItem.ToString()));
            if (SelectedLabelAndLocation == null)
            {
                return;
            }


            var pb = ((PictureBox)sender);

            if (SelectedLabelAndLocation.SelectedPixels.Contains(int.Parse((string)pb.Tag)))
            {
                SelectedLabelAndLocation.SelectedPixels.Remove(int.Parse((string)pb.Tag));
                pb.BackColor = Color.White;
            }
            else
            {
                SelectedLabelAndLocation.SelectedPixels.Add(int.Parse((string)pb.Tag));
                pb.BackColor = Color.Red;
            }
        }
        private void RefreshGrid()
        {
            if (lbBulbs.SelectedItem == null)
            {
                return;
            }

            SelectedLabelAndLocation = LabelsAndLocations.SingleOrDefault(x => x.Label == (lbBulbs.SelectedItem.ToString()));
            if (SelectedLabelAndLocation == null)
            {
                return;
            }

            var panel = panelScreenLocations;

            foreach (var pb in panel.Controls.OfType <PictureBox>())
            {
                if (SelectedLabelAndLocation.SelectedPixels.Contains(int.Parse((string)pb.Tag)))
                {
                    pb.BackColor = Color.Red;
                }
                else
                {
                    pb.BackColor = Color.White;
                }
            }
        }
Beispiel #4
0
        private void cbArea_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_suspendUi)
            {
                return;
            }
            _suspendUi = true;

            LabelsAndLocations.Remove(LabelsAndLocations.Single(x => x.Label == SelectedLabelAndLocation.Label));
            var l = new LabelAndLocationType();

            l.Label          = SelectedLabelAndLocation.Label;
            l.ScreenLocation =
                (ScreenLocation)(Enum.Parse(typeof(ScreenLocation), ((ComboBox)sender).SelectedItem.ToString()));
            LabelsAndLocations.Add(l);
            _suspendUi = false;
        }
        public void ScreenColour(MaxLifxBulbController bulbController, Random random)
        {
            var frames = 0;
            var start  = DateTime.Now;

            if (Settings == null)
            {
                Settings = new ScreenColourSettings();
            }

            foreach (var bulb in bulbController.Bulbs.Select(x => x))
            {
                if (!SettingsCast.LabelsAndLocations.Select(x => x.Label).Contains(bulb.Label))
                {
                    // populating SettingsCast fields
                    var l = new LabelAndLocationType();
                    l.Label          = bulb.Label;
                    l.ScreenLocation = ScreenLocation.All;
                    l.Zones          = bulb.Zones;
                    // default to None if more than 1 zone, so that can proper setup
                    if (bulb.Zones > 1)
                    {
                        l.ScreenLocation = ScreenLocation.None;
                        // if multizone enabled keep track of number of zones
                        SettingsCast.MultiColourZones.Add(bulb.Zones);
                    }
                    SettingsCast.LabelsAndLocations.Add(l);
                }
            }

            while (!TerminateThread)
            {
                // check if area has changed
                if (TopLeft == SettingsCast.TopLeft && BottomRight == SettingsCast.BottomRight)
                {
                    DoMainLoop(bulbController, ref frames, start);
                }
                else
                {
                    // if it has changed then recalculate zones and set
                    zoneCalculation();
                    TopLeft     = SettingsCast.TopLeft;
                    BottomRight = SettingsCast.BottomRight;
                }
            }
        }
Beispiel #6
0
        public void ScreenColour(MaxLifxBulbController bulbController, Random random)
        {
            var frames = 0;
            var start  = DateTime.Now;

            if (Settings == null)
            {
                Settings = new ScreenColourSettings();
            }

            foreach (var label in bulbController.Bulbs.Select(x => x.Label))
            {
                if (!SettingsCast.LabelsAndLocations.Select(x => x.Label).Contains(label))
                {
                    var l = new LabelAndLocationType();
                    l.Label          = label;
                    l.ScreenLocation = ScreenLocation.All;
                    SettingsCast.LabelsAndLocations.Add(l);
                }
            }

            var payload = new SetColourPayload {
                Kelvin = 3500, TransitionDuration = (uint)(SettingsCast.Fade)
            };

            while (!TerminateThread)
            {
                using (var screenPixel = new Bitmap(CaptureResolution.Width, CaptureResolution.Height, PixelFormat.Format32bppArgb))
                {
                    using (var gdest = Graphics.FromImage(screenPixel))
                    {
                        using (var gsrc = Graphics.FromHwnd(IntPtr.Zero))
                        {
                            DoMainLoop(bulbController, ref frames, start, ref payload, screenPixel, gdest, gsrc);
                        }
                    }
                }
            }
        }