Ejemplo n.º 1
0
        private void OpacityNumericValueChanged(object sender, EventArgs e)
        {
            NumericUpDown nud  = sender as NumericUpDown;
            ScreenInfo    scrn = nud.Tag as ScreenInfo;
            TrackBar      tb   = (nud.Parent as GroupBox).Controls[0] as TrackBar;

            scrn.Opacity = (double)nud.Value / 100;
            tb.Value     = (int)nud.Value;

            TriggerSave();
        }
Ejemplo n.º 2
0
        private void OpacityTrackBarScroll(object sender, EventArgs e)
        {
            TrackBar      tb   = sender as TrackBar;
            ScreenInfo    scrn = tb.Tag as ScreenInfo;
            NumericUpDown nud  = (tb.Parent as GroupBox).Controls[1] as NumericUpDown;

            scrn.Opacity = (double)tb.Value / 100;
            nud.Value    = tb.Value;

            TriggerSave();
        }
Ejemplo n.º 3
0
        //
        //  </ATTRIBUTES AND CONSTANTS>
        //



        //
        //  <CONSTRUCTORS>
        //

        // default constructor
        // used when "settings.xml" is not found, or contains invalid values
        public OptionsForm()
        {
            MessageBox.Show(FirstTimeText, "ScreenDimmer");

            screen_list  = new List <ScreenInfo>();
            basic_screen = new ScreenInfo("basic", 0, 0, 0, 0, 0, DEFAULT_OPACITY);
            DetectScreens();

            InitializeForm();
            InitializeTabs();
            InitializeTimer();
            SaveSettings();
        }
Ejemplo n.º 4
0
        private void DimmingCheckBoxClicked(object sender, MouseEventArgs e)
        {
            CheckBox   cb   = sender as CheckBox;
            ScreenInfo scrn = cb.Tag as ScreenInfo;

            if (cb.Checked)
            {
                scrn.Show = true;
            }
            else
            {
                scrn.Show = false;
            }
        }
Ejemplo n.º 5
0
        //
        //  </INITIALIZATION>
        //



        //
        //  <HELPER METHODS>
        //

        private ScreenInfo NewScreenInfo(Screen scrn, int index)
        {
            string     name      = scrn.DeviceName;
            int        originX   = scrn.Bounds.X;
            int        originY   = scrn.Bounds.Y;
            int        resX      = scrn.Bounds.Width;
            int        resY      = scrn.Bounds.Height;
            ScreenInfo scrn_info = new ScreenInfo(name, index, originX, originY, resX, resY, DEFAULT_OPACITY);

            scrn_info.Show = false;
            if (use_separate_screens)
            {
                scrn_info.Enabled = true;
            }
            return(scrn_info);
        }
Ejemplo n.º 6
0
        // creates a TabPage for a ScreenInfo
        TabPage CreateScreenTab(ScreenInfo scrn)
        {
            TabPage tab = new TabPage();

            tab.Text = "Screen " + scrn.ScreenIndex;
            tab.Tag  = scrn;

            // TableLayoutPanel setup
            TableLayoutPanel tbl = new TableLayoutPanel();

            tbl.Dock     = DockStyle.Fill;
            tbl.RowCount = 3;
            tbl.RowStyles.Add(new RowStyle(SizeType.Percent, 38));
            tbl.RowStyles.Add(new RowStyle(SizeType.Percent, 38));
            tbl.RowStyles.Add(new RowStyle(SizeType.Percent, 24));
            tbl.ColumnCount = 1;
            tab.Controls.Add(tbl);

            // screen information groupbox
            GroupBox gb = new GroupBox();

            gb.Text = "Screen Information";
            gb.Dock = DockStyle.Fill;
            tbl.Controls.Add(gb, 0, 0);

            ListBox lb = new ListBox();

            lb.Dock = DockStyle.Fill;
            lb.Items.Add("Resolution: " + scrn.ResolutionX + " by " + scrn.ResolutionY);
            lb.Items.Add("Position: (" + scrn.OriginX + ", " + scrn.OriginY + ")");
            gb.Controls.Add(lb);

            // opacity groupbox
            gb      = new GroupBox();
            gb.Text = "Opacity";
            gb.Dock = DockStyle.Fill;
            tbl.Controls.Add(gb, 0, 1);

            TrackBar tb = new TrackBar();

            tb.Tag           = scrn;
            tb.Location      = new Point(8, 14);
            tb.Width         = 280;
            tb.TickStyle     = TickStyle.Both;
            tb.TickFrequency = 1;
            tb.SmallChange   = 1;
            tb.LargeChange   = 10;

            tb.Maximum = (int)(ScreenInfo.MaxOpacity * 100);
            tb.Minimum = (int)(ScreenInfo.MinOpacity * 100);
            tb.Value   = (int)(scrn.Opacity * 100);
            tb.Scroll += OpacityTrackBarScroll;
            gb.Controls.Add(tb);

            NumericUpDown nud = new NumericUpDown();

            nud.Tag      = scrn;
            nud.Location = new Point(294, 26);
            nud.Size     = new Size(60, 40);

            nud.Maximum       = (int)(ScreenInfo.MaxOpacity * 100);
            nud.Minimum       = (int)(ScreenInfo.MinOpacity * 100);
            nud.Value         = (int)(scrn.Opacity * 100);
            nud.ValueChanged += OpacityNumericValueChanged;
            nud.KeyDown      += OpacityNumericKeyDown;
            gb.Controls.Add(nud);

            // dimming checkbox
            FlowLayoutPanel flp = new FlowLayoutPanel();

            flp.Dock          = DockStyle.Fill;
            flp.FlowDirection = FlowDirection.LeftToRight;
            flp.Padding       = new Padding(10, 6, 6, 10);
            tbl.Controls.Add(flp, 0, 2);

            CheckBox cb = new CheckBox();

            cb.Tag         = scrn;
            cb.Text        = "Enable dimming";
            cb.AutoSize    = true;
            cb.Checked     = scrn.Show;
            cb.MouseClick += DimmingCheckBoxClicked;
            flp.Controls.Add(cb);

            return(tab);
        }
Ejemplo n.º 7
0
        // constructor for valid XML document
        // XElements can have invalid values
        public OptionsForm(XDocument xml)
        {
            bool use_default_values = false;

            screen_list = new List <ScreenInfo>();

            var screens = xml.Descendants("screen");

            // get the options and basic screen information from the XML file
            basic_screen = new ScreenInfo("basic", 0, 0, 0, 0, 0, DEFAULT_OPACITY);
            try
            {
                XElement options = xml.Descendants("options").First();
                XElement basic   = xml.Descendants("basicScreen").First();
                use_separate_screens = (Boolean.Parse(options.Element("separateScreens").Value));

                basic_screen.OriginX     = Int32.Parse(basic.Element("left").Value);
                basic_screen.OriginY     = Int32.Parse(basic.Element("up").Value);
                basic_screen.ResolutionX = Int32.Parse(basic.Element("right").Value) - basic_screen.OriginX;
                basic_screen.ResolutionY = Int32.Parse(basic.Element("down").Value) - basic_screen.OriginY;
                basic_screen.Show        = Boolean.Parse(basic.Element("enabled").Value);
                basic_screen.Opacity     = Double.Parse(basic.Element("opacity").Value);
                basic_screen.Enabled     = !use_separate_screens;
            }
            catch (InvalidOperationException)
            { use_default_values = ExceptionMessageBox(InvalidOperationExceptionMessage, "Warning: InvalidOperationException"); }
            catch (FormatException)
            { use_default_values = ExceptionMessageBox(FormatExceptionMessage, "Warning: FormatException"); }
            catch (OverflowException)
            { use_default_values = ExceptionMessageBox(OverflowExceptionMessage, "Warning: OverflowException"); }
            catch (ArgumentOutOfRangeException)
            { use_default_values = ExceptionMessageBox(ArgumentOutOfRangeExceptionMessage, "Warning: ArgumentOutOfRangeException"); }

            // copy screen information from the XML file
            foreach (XElement screen in screens)
            {
                if (use_default_values)
                {
                    break;
                }

                // ensure that the XML file does not have invalid values
                try
                {
                    ScreenInfo scrn_info = new ScreenInfo(screen);
                    if (use_separate_screens)
                    {
                        scrn_info.Enabled = true;
                    }

                    // ignore screens that do not appear in Screen.AllScreens
                    // they will not be added to screen_list, so they should not get their own tab
                    foreach (Screen scrn in Screen.AllScreens)
                    {
                        if (scrn_info.Name.Equals(scrn.DeviceName))
                        {
                            screen_list.Add(scrn_info);

                            bool screen_enabled = Boolean.Parse(screen.Element("enabled").Value);
                            if (screen_enabled)
                            {
                                scrn_info.Show = true;
                            }

                            break;
                        }
                    }
                }
                catch (FormatException)
                { use_default_values = ExceptionMessageBox(FormatExceptionMessage, "Warning: FormatException"); }
                catch (OverflowException)
                { use_default_values = ExceptionMessageBox(OverflowExceptionMessage, "Warning: OverflowException"); }
                catch (ArgumentOutOfRangeException)
                { use_default_values = ExceptionMessageBox(ArgumentOutOfRangeExceptionMessage, "Warning: ArgumentOutOfRangeException"); }
            }

            // if there was an error in the XML file, recreate screen_list using AllScreens
            if (use_default_values)
            {
                ClearScreenList();
                DetectScreens();
                SaveSettings();
            }

            InitializeForm();
            InitializeTabs();
            InitializeTimer();
        }