//Save settings and close window
        public void saveSettings(object sender, RoutedEventArgs e)
        {
            try
            {
                KeyboardHook.VKeys onOffKey   = getKeyFromString(onOffShortcut.Content.ToString());
                KeyboardHook.VKeys nextPosKey = getKeyFromString(nextPosShortcut.Content.ToString());
                KeyboardHook.VKeys nextDisKey = getKeyFromString(nextDisShortcut.Content.ToString());
                KeyboardHook.VKeys resultKey  = getKeyFromString(resultShortcut.Content.ToString());

                SingletonSettings.DISPLAY_MODES mode = SingletonSettings.DISPLAY_MODES.FULLSCREEN;
                if (windowedItem.IsSelected)
                {
                    mode = (SingletonSettings.DISPLAY_MODES)Enum.Parse(typeof(SingletonSettings.DISPLAY_MODES), windowedItem.Content.ToString());
                }

                SingletonSettings.Instance.saveSettings(overlayCheckbox.IsChecked.Value, mode, shortcutCheckbox.IsChecked.Value,
                                                        onOffKey, nextPosKey, nextDisKey, resultKey);

                shouldUpdate = true;
            }
            catch (Exception)
            {
                MessageBox.Show("Saving settings failed!", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            this.Close();
        }
        //Init UI with actual settings
        private void getDataFromSettings()
        {
            SingletonSettings.Instance.updateSettings();

            overlayCheckbox.IsChecked  = SingletonSettings.Instance.shouldUseOverlay();
            shortcutCheckbox.IsChecked = SingletonSettings.Instance.shouldUseShortcuts();
            shortcutCheckboxChanged(null, null);

            SingletonSettings.DISPLAY_MODES mode = SingletonSettings.Instance.getDisplayMode();
            if (mode == SingletonSettings.DISPLAY_MODES.FULLSCREEN)
            {
                fullscreenItem.IsSelected = true;
            }
            if (mode == SingletonSettings.DISPLAY_MODES.WINDOWED)
            {
                windowedItem.IsSelected = true;
            }

            onOffShortcut.Content   = getStringFromKey(SingletonSettings.Instance.getOpenShortcut());
            nextPosShortcut.Content = getStringFromKey(SingletonSettings.Instance.getPosShortcut());
            nextDisShortcut.Content = getStringFromKey(SingletonSettings.Instance.getDisShortcut());
            resultShortcut.Content  = getStringFromKey(SingletonSettings.Instance.getResultShortcut());
        }
        public double getOreDistance(Bitmap image, bool showWarning)
        {
            //16:9
            double ratioX = 2843.0 / 3840.0;
            double ratioY = 1163.0 / 2160.0;

            double height;
            int    baseHeight, baseWidth, heightTracker;

            SingletonSettings.DISPLAY_MODES screenChoiceMenu = SingletonSettings.Instance.getDisplayMode();

            if (SingletonSettings.DISPLAY_MODES.WINDOWED == screenChoiceMenu)
            {
                height     = image.Height - 32;
                baseHeight = (int)(ratioY * height) + 31;
                baseWidth  = (int)Math.Round(ratioX * (image.Width - 2)) + 1;
            }
            else
            {
                height     = image.Height;
                baseHeight = (int)(ratioY * height);
                baseWidth  = (int)Math.Round(ratioX * image.Width);
            }
            heightTracker = baseHeight;

            while (heightTracker > 1)
            {
                Color color     = image.GetPixel(baseWidth, heightTracker);
                Color nextColor = image.GetPixel(baseWidth, heightTracker - 1);

                if (isOreRange(color, nextColor))
                {
                    int count = getFinalPos(heightTracker, image, baseWidth);

                    if (count > 3)
                    {
                        heightTracker -= count / 2;
                        break;
                    }
                }

                heightTracker--;
            }

            int    finalHeight = baseHeight - heightTracker;
            double stepper     = 172.0 / 2160.0 * height;
            double finalAmount = (100.0 / stepper) * finalHeight;


            if (finalAmount < 10 || finalAmount > 674)
            {
                if (showWarning)
                {
                    MessageBox.Show("Scanner lines not found! Check instructions!", "ERROR!", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                finalAmount = 0;
            }

            finalAmount = Math.Round(finalAmount, 5);

            return(finalAmount);
        }