Esempio n. 1
0
        private void AddDefaultScreens(ScreenCapture screenCapture, MacroParser macroParser, FileSystem fileSystem, Log log)
        {
            int component = 1;

            foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
            {
                ScreenCapture.DeviceOptions deviceResolution = screenCapture.GetDevice(screen);

                Add(new Screen()
                {
                    ViewId      = Guid.NewGuid(),
                    Name        = "Screen " + component,
                    Folder      = fileSystem.ScreenshotsFolder,
                    Macro       = macroParser.DefaultMacro,
                    Component   = component,
                    Format      = _imageFormatCollection.GetByName(ScreenCapture.DefaultImageFormat),
                    JpegQuality = 100,
                    Mouse       = true,
                    Active      = true,
                    X           = screen.Bounds.X,
                    Y           = screen.Bounds.Y,
                    Width       = deviceResolution.width,
                    Height      = deviceResolution.height,
                    Source      = 0,
                    DeviceName  = deviceResolution.screen.DeviceName
                });

                log.WriteDebugMessage($"Screen {component} created using \"{fileSystem.ScreenshotsFolder}\" for folder path and \"{macroParser.DefaultMacro}\" for macro.");

                component++;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adjusts the position and size based on the selected component if AutoAdapt is enabled.
        /// This is useful for when your display setup changes over time while a screen capture session is running.
        /// </summary>
        /// <param name="screen">The screen to use.</param>
        /// <param name="x">The X value.</param>
        /// <param name="y">The Y value.</param>
        /// <param name="width">The Width value.</param>
        /// <param name="height">The Height value.</param>
        private void AutoAdapt(Screen screen, out int x, out int y, out int width, out int height)
        {
            x      = 0;
            y      = 0;
            width  = 0;
            height = 0;

            if (screen.AutoAdapt)
            {
                for (int i = 0; i < System.Windows.Forms.Screen.AllScreens.Length; i++)
                {
                    System.Windows.Forms.Screen screenFromWindows = System.Windows.Forms.Screen.AllScreens[i];
                    ScreenCapture.DeviceOptions deviceResolution  = _screenCapture.GetDevice(screenFromWindows);

                    if (i == screen.AutoAdaptIndex)
                    {
                        x      = screenFromWindows.Bounds.X;
                        y      = screenFromWindows.Bounds.Y;
                        width  = deviceResolution.width;
                        height = deviceResolution.height;

                        break;
                    }
                }
            }
            else
            {
                x      = screen.X;
                y      = screen.Y;
                width  = screen.Width;
                height = screen.Height;
            }
        }
Esempio n. 3
0
        private void comboBoxScreenSource_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBoxScreenComponent.Items.Clear();

            // Auto Screen Capture
            if (comboBoxScreenSource.SelectedIndex == 0)
            {
                comboBoxScreenComponent.Items.Add("Active Window");

                // Add screens from screens.xml file.
                foreach (Screen screen in ScreenCollection)
                {
                    // We don't want a Screen object that's null.
                    if (screen == null)
                    {
                        continue;
                    }

                    // We don't care if it's a Screen using Active Window as its Component because that's already available in the list.
                    // We also don't care if it's a Screen that's using AutoAdapt.
                    if ((screen.Component == 0 && screen.Source == 0) || screen.AutoAdapt)
                    {
                        continue;
                    }

                    comboBoxScreenComponent.Items.Add("\"" + screen.Name + "\" X:" + screen.X + " Y:" + screen.Y + " (" + screen.Width + "x" + screen.Height + ")");
                }

                // Add regions from regions.xml file.
                foreach (Region region in RegionCollection)
                {
                    // We don't want a Region object that's null.
                    if (region == null)
                    {
                        continue;
                    }

                    comboBoxScreenComponent.Items.Add("\"" + region.Name + "\" X:" + region.X + " Y:" + region.Y + " (" + region.Width + "x" + region.Height + ")");
                }
            }

            // EnumDisplaySettings (user32.dll)
            if (comboBoxScreenSource.SelectedIndex == 1)
            {
                foreach (System.Windows.Forms.Screen screenFromWindows in System.Windows.Forms.Screen.AllScreens)
                {
                    ScreenCapture.DeviceOptions deviceOptions = _screenCapture.GetDevice(screenFromWindows);

                    comboBoxScreenComponent.Items.Add("\"" + deviceOptions.screen.DeviceName + "\" X:" + deviceOptions.screen.Bounds.X + " Y:" + deviceOptions.screen.Bounds.Y + " (" + deviceOptions.width + "x" + deviceOptions.height + ")");
                }
            }

            // System.Windows.Forms.Screen (.NET)
            if (comboBoxScreenSource.SelectedIndex == 2)
            {
                foreach (System.Windows.Forms.Screen screenFromWindows in System.Windows.Forms.Screen.AllScreens)
                {
                    comboBoxScreenComponent.Items.Add("\"" + screenFromWindows.DeviceName + "\" X:" + screenFromWindows.Bounds.X + " Y:" + screenFromWindows.Bounds.Y + " (" + screenFromWindows.Bounds.Width + "x" + screenFromWindows.Bounds.Height + ")");
                }
            }

            if (ScreenObject != null && ScreenObject.Component < comboBoxScreenComponent.Items.Count)
            {
                comboBoxScreenComponent.SelectedIndex = ScreenObject.Component;
            }
            else
            {
                comboBoxScreenComponent.SelectedIndex = 0;
            }
        }
Esempio n. 4
0
        private void UpdatePreviewImage(ScreenCapture screenCapture)
        {
            try
            {
                // The mouse pointer gets really weird if we go under 100 resolution ratio
                // so disable the mouse checkbox control to indicate we can't show the mouse pointer.
                if (numericUpDownResolutionRatio.Value == 100)
                {
                    checkBoxMouse.Enabled = true;
                }
                else
                {
                    checkBoxMouse.Enabled = false;
                }

                if (checkBoxAutoAdapt.Checked)
                {
                    labelScreenSource.Enabled    = false;
                    labelScreenComponent.Enabled = false;

                    comboBoxScreenSource.Enabled    = false;
                    comboBoxScreenComponent.Enabled = false;

                    labelX.Enabled      = false;
                    labelY.Enabled      = false;
                    labelWidth.Enabled  = false;
                    labelHeight.Enabled = false;

                    numericUpDownX.Enabled      = false;
                    numericUpDownY.Enabled      = false;
                    numericUpDownWidth.Enabled  = false;
                    numericUpDownHeight.Enabled = false;
                }
                else
                {
                    labelScreenSource.Enabled    = true;
                    labelScreenComponent.Enabled = true;

                    comboBoxScreenSource.Enabled    = true;
                    comboBoxScreenComponent.Enabled = true;

                    labelX.Enabled      = true;
                    labelY.Enabled      = true;
                    labelWidth.Enabled  = true;
                    labelHeight.Enabled = true;

                    numericUpDownX.Enabled      = true;
                    numericUpDownY.Enabled      = true;
                    numericUpDownWidth.Enabled  = true;
                    numericUpDownHeight.Enabled = true;
                }

                // The Source is "Auto Screen Capture" and the Component is "Active Window".
                if (comboBoxScreenSource.SelectedIndex == 0 && comboBoxScreenComponent.SelectedIndex == 0)
                {
                    labelX.Enabled      = false;
                    labelY.Enabled      = false;
                    labelWidth.Enabled  = false;
                    labelHeight.Enabled = false;

                    numericUpDownX.Enabled      = false;
                    numericUpDownY.Enabled      = false;
                    numericUpDownWidth.Enabled  = false;
                    numericUpDownHeight.Enabled = false;
                }

                pictureBoxPreview.Image = null;

                if (checkBoxEnable.Checked)
                {
                    // This is for when the option "Automatically adapt to display setup" is enabled.
                    // We need to show the position and size based on what Windows provides.
                    if (checkBoxAutoAdapt.Checked)
                    {
                        int x      = 0;
                        int y      = 0;
                        int width  = 0;
                        int height = 0;

                        for (int i = 0; i < System.Windows.Forms.Screen.AllScreens.Length; i++)
                        {
                            System.Windows.Forms.Screen screenFromWindows = System.Windows.Forms.Screen.AllScreens[i];
                            ScreenCapture.DeviceOptions deviceResolution  = _screenCapture.GetDevice(screenFromWindows);

                            if (i == _autoAdaptIndex)
                            {
                                x      = screenFromWindows.Bounds.X;
                                y      = screenFromWindows.Bounds.Y;
                                width  = deviceResolution.width;
                                height = deviceResolution.height;

                                break;
                            }
                        }

                        pictureBoxPreview.Image = screenCapture.GetScreenBitmap(
                            comboBoxScreenSource.SelectedIndex,
                            comboBoxScreenComponent.SelectedIndex,
                            comboBoxScreenCaptureMethod.SelectedIndex,
                            x,
                            y,
                            width,
                            height,
                            (int)numericUpDownResolutionRatio.Value,
                            checkBoxMouse.Checked
                            );
                    }
                    else
                    {
                        // The Source is "Auto Screen Capture" and the Component is "Active Window".
                        if (comboBoxScreenSource.SelectedIndex == 0 && comboBoxScreenComponent.SelectedIndex == 0)
                        {
                            pictureBoxPreview.Image = screenCapture.GetActiveWindowBitmap((int)numericUpDownResolutionRatio.Value, checkBoxMouse.Checked);
                        }
                        else
                        {
                            pictureBoxPreview.Image = screenCapture.GetScreenBitmap(
                                comboBoxScreenSource.SelectedIndex,
                                comboBoxScreenComponent.SelectedIndex,
                                comboBoxScreenCaptureMethod.SelectedIndex,
                                (int)numericUpDownX.Value,
                                (int)numericUpDownY.Value,
                                (int)numericUpDownWidth.Value,
                                (int)numericUpDownHeight.Value,
                                (int)numericUpDownResolutionRatio.Value,
                                checkBoxMouse.Checked
                                );
                        }
                    }

                    UpdatePreviewMacro();
                }
                else
                {
                    textBoxMacroPreview.ForeColor = System.Drawing.Color.White;
                    textBoxMacroPreview.BackColor = System.Drawing.Color.Black;
                    textBoxMacroPreview.Text      = "[Enable option is off. No screenshots of this screen will be taken during a running screen capture session]";
                }
            }
            catch (Exception ex)
            {
                _log.WriteExceptionMessage("FormScreen::UpdatePreviewImage", ex);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Loads the screens.
        /// </summary>
        public bool LoadXmlFileAndAddScreens(ImageFormatCollection imageFormatCollection, Config config, MacroParser macroParser, ScreenCapture screenCapture, FileSystem fileSystem, Log log)
        {
            try
            {
                if (fileSystem.FileExists(fileSystem.ScreensFile))
                {
                    log.WriteDebugMessage("Screens file \"" + fileSystem.ScreensFile + "\" found. Attempting to load XML document");

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(fileSystem.ScreensFile);

                    log.WriteDebugMessage("XML document loaded");

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xScreens = xDoc.SelectNodes(SCREEN_XPATH);

                    foreach (XmlNode xScreen in xScreens)
                    {
                        Screen        screen  = new Screen();
                        XmlNodeReader xReader = new XmlNodeReader(xScreen);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement() && !xReader.IsEmptyElement)
                            {
                                switch (xReader.Name)
                                {
                                case SCREEN_VIEWID:
                                    xReader.Read();
                                    screen.ViewId = Guid.Parse(xReader.Value);
                                    break;

                                case SCREEN_NAME:
                                    xReader.Read();
                                    screen.Name = xReader.Value;
                                    break;

                                case SCREEN_FOLDER:
                                    xReader.Read();
                                    screen.Folder = xReader.Value;
                                    break;

                                case SCREEN_MACRO:
                                    xReader.Read();
                                    screen.Macro = xReader.Value;
                                    break;

                                case SCREEN_COMPONENT:
                                    xReader.Read();
                                    screen.Component = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_FORMAT:
                                    xReader.Read();
                                    screen.Format = imageFormatCollection.GetByName(xReader.Value);
                                    break;

                                case SCREEN_JPEG_QUALITY:
                                    xReader.Read();
                                    screen.JpegQuality = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_MOUSE:
                                    xReader.Read();
                                    screen.Mouse = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCREEN_ACTIVE:
                                    xReader.Read();
                                    screen.Active = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCREEN_X:
                                    xReader.Read();
                                    screen.X = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_Y:
                                    xReader.Read();
                                    screen.Y = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_WIDTH:
                                    xReader.Read();
                                    screen.Width = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_HEIGHT:
                                    xReader.Read();
                                    screen.Height = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_SOURCE:
                                    xReader.Read();
                                    screen.Source = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_DEVICE_NAME:
                                    xReader.Read();
                                    screen.DeviceName = xReader.Value;
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        // Change the data for each Screen that's being loaded if we've detected that
                        // the XML document is from an older version of the application.
                        if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                        {
                            log.WriteDebugMessage("An old version of the screens.xml file was detected. Attempting upgrade to new schema.");

                            Version v2300         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, Settings.CODEVERSION_BOOMBAYAH);
                            Version v2338         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, "2.3.3.8");
                            Version configVersion = config.Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                            if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                            {
                                log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                // This is a new property for Screen that was introduced in 2.3.0.0
                                // so any version before 2.3.0.0 needs to have it during an upgrade.
                                screen.Active = true;
                            }

                            if (v2338 != null && configVersion != null && configVersion.VersionNumber < v2338.VersionNumber)
                            {
                                log.WriteDebugMessage("Boombayah 2.3.3.7 or older detected");

                                int component = 1;

                                foreach (System.Windows.Forms.Screen screenFromWindows in System.Windows.Forms.Screen.AllScreens)
                                {
                                    ScreenCapture.DeviceOptions deviceOptions = screenCapture.GetDevice(screenFromWindows);

                                    if (screen.Component.Equals(component))
                                    {
                                        screen.X          = screenFromWindows.Bounds.X;
                                        screen.Y          = screenFromWindows.Bounds.Y;
                                        screen.Width      = deviceOptions.width;
                                        screen.Height     = deviceOptions.height;
                                        screen.Source     = 1;
                                        screen.DeviceName = deviceOptions.screen.DeviceName;
                                    }

                                    component++;
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(screen.Name))
                        {
                            Add(screen);
                        }
                    }

                    if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                    {
                        log.WriteDebugMessage("Screens file detected as an old version");
                        SaveToXmlFile(config, fileSystem, log);
                    }
                }
                else
                {
                    log.WriteDebugMessage("WARNING: Unable to load screens");

                    if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                    {
                        Version v2182         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_CLARA, Settings.CODEVERSION_CLARA);
                        Version configVersion = config.Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                        if (v2182 != null && configVersion != null && v2182.VersionNumber == configVersion.VersionNumber)
                        {
                            Add(new Screen()
                            {
                                ViewId      = Guid.NewGuid(),
                                Name        = "Active Window",
                                Folder      = fileSystem.ScreenshotsFolder,
                                Macro       = macroParser.DefaultMacro,
                                Component   = 0,
                                Format      = _imageFormatCollection.GetByName(ScreenCapture.DefaultImageFormat),
                                JpegQuality = 100,
                                Mouse       = true,
                                Active      = true,
                                X           = 0,
                                Y           = 0,
                                Width       = 0,
                                Height      = 0,
                                Source      = 0,
                                DeviceName  = string.Empty
                            });
                        }
                    }

                    AddDefaultScreens(screenCapture, macroParser, fileSystem, log);

                    SaveToXmlFile(config, fileSystem, log);
                }

                return(true);
            }
            catch (Exception ex)
            {
                log.WriteExceptionMessage("ScreenCollection::LoadXmlFileAndAddScreens", ex);

                return(false);
            }
        }
Esempio n. 6
0
        private void FormScreen_Load(object sender, EventArgs e)
        {
            textBoxScreenName.Focus();

            HelpMessage("This is where to configure a screen capture. Select a source and a component then change the display properties and image attributes");

            _toolTip.SetToolTip(checkBoxMouse, "You can include the mouse pointer in your screenshots if the \"Include mouse pointer\" option is checked");
            _toolTip.SetToolTip(comboBoxFormat, "Change the image format for the screenshots taken by this screen capture. JPEG is the recommended image format");
            _toolTip.SetToolTip(checkBoxActive, "You can capture this screen if Active is checked (turned on)");
            _toolTip.SetToolTip(buttonScreenBrowseFolder, "Browse for a folder where screenshots of this screen capture will be saved to");
            _toolTip.SetToolTip(buttonMacroTags, "Open a list of available macro tags. You can keep the Macro Tags window open while you modify your macro");

            comboBoxFormat.Items.Clear();

            pictureBoxPreview.Image = null;

            foreach (ImageFormat imageFormat in ImageFormatCollection)
            {
                comboBoxFormat.Items.Add(imageFormat.Name);
            }

            comboBoxScreenSource.Items.Clear();
            comboBoxScreenSource.Items.Add("Auto Screen Capture");
            comboBoxScreenSource.Items.Add("Graphics Card");
            comboBoxScreenSource.Items.Add("Operating System");

            for (int i = 1; i <= ScreenDictionary.Count; i++)
            {
                ScreenCapture.DeviceOptions deviceOptions = ScreenDictionary[i];
                comboBoxScreenComponent.Items.Add("Screen " + i + " (" + deviceOptions.width + " x " + deviceOptions.height + ")");
            }

            if (ScreenObject != null)
            {
                Text = "Change Screen";

                textBoxScreenName.Text             = ScreenObject.Name;
                textBoxFolder.Text                 = _fileSystem.CorrectScreenshotsFolderPath(ScreenObject.Folder);
                textBoxMacro.Text                  = ScreenObject.Macro;
                comboBoxScreenSource.SelectedIndex = ScreenObject.Source;
                comboBoxFormat.SelectedItem        = ScreenObject.Format.Name;
                numericUpDownJpegQuality.Value     = ScreenObject.JpegQuality;
                checkBoxMouse.Checked              = ScreenObject.Mouse;
                checkBoxActive.Checked             = ScreenObject.Active;
                numericUpDownX.Value               = ScreenObject.X;
                numericUpDownY.Value               = ScreenObject.Y;
                numericUpDownWidth.Value           = ScreenObject.Width;
                numericUpDownHeight.Value          = ScreenObject.Height;
            }
            else
            {
                Text = "Add Screen";

                textBoxScreenName.Text             = "Screen " + (ScreenCollection.Count + 1);
                textBoxFolder.Text                 = _fileSystem.ScreenshotsFolder;
                textBoxMacro.Text                  = _macroParser.DefaultMacro;
                comboBoxScreenSource.SelectedIndex = 0;
                comboBoxFormat.SelectedItem        = ScreenCapture.DefaultImageFormat;
                numericUpDownJpegQuality.Value     = 100;
                checkBoxMouse.Checked              = true;
                checkBoxActive.Checked             = true;
                numericUpDownX.Value               = 0;
                numericUpDownY.Value               = 0;
                numericUpDownWidth.Value           = 0;
                numericUpDownHeight.Value          = 0;
            }

            UpdatePreviewMacro();
            UpdatePreviewImage(_screenCapture);
        }