Esempio n. 1
0
        /// <summary>
        /// Detects the closing of the PreferenceForm.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PrefsFormClosing(object sender, EventArgs e)
        {
            if (!ignoreValues)
            {
                Preferences.PrinterName    = PrinterName;
                Preferences.PrinterScheme  = PrinterScheme;
                Preferences.SortingFilter  = SortingFilter;
                Preferences.FontReader     = FontReader;
                Preferences.FontSystem     = FontSystem;
                Preferences.FontWriter     = FontWriter;
                Preferences.ColourControls = ColourControls;
                Preferences.ColourFont     = ColourFont;
                Preferences.ROD_MaxNumber  = ROD_MaxNumber;

                Preferences.SaveData();
                if (parentForm != null)
                {
                    Font  font = new Font(Preferences.FontSystem, 14.25F, GraphicsUnit.Pixel);
                    Color backColor, foreColor;
                    backColor = ColorExtractor.ExtractColor(Preferences.ColourControls);
                    foreColor = ColorExtractor.ExtractColor(Preferences.ColourFont);
                    foreach (Control control in parentForm.Controls)
                    {
                        parentForm.UpdateControlColorsFonts(control, backColor, foreColor, font);
                    }
                }
            }
        }
Esempio n. 2
0
        private void CommonConstructor(bool show)
        {
            if (show)
            {
                isFromInitializeControls = true;
                AvailableFonts           = GetAvailableFonts();
                InitializeComponent();

                StartPosition = FormStartPosition.CenterScreen;

                PrinterName    = Preferences.PrinterName;
                PrinterScheme  = Preferences.PrinterScheme;
                ColourFont     = Preferences.ColourFont;
                ColourControls = Preferences.ColourControls;

                cmbxThemeColourControls.BackColor = ColorExtractor.ExtractColor(Preferences.ColourControls);
                cmbxThemeColourFont.BackColor     = ColorExtractor.ExtractColor(Preferences.ColourFont);
                cmbxThemeFontReader.SelectedIndex = cmbxThemeFontReader.FindString(FontReader);
                cmbxThemeFontReader.SelectedIndex = cmbxThemeFontReader.FindString(FontReader);
                cmbxThemeFontSystem.SelectedIndex = cmbxThemeFontSystem.FindString(FontSystem);
                cmbxThemeFontWriter.SelectedIndex = cmbxThemeFontWriter.FindString(FontWriter);

                FontSystem    = Preferences.FontSystem;
                FontReader    = Preferences.FontReader;
                FontWriter    = Preferences.FontWriter;
                SortingFilter = Preferences.SortingFilter;
                ROD_MaxNumber = Preferences.ROD_MaxNumber;

                SetValues();
                isFromInitializeControls = false;

                FormClosing += new FormClosingEventHandler(PrefsFormClosing);
                ShowDialog();
            }
        }
Esempio n. 3
0
        private void RenderBaZiPeriodModel(string period, int x, BaZiModel model)
        {
            var elementColor = ColorExtractor.Extract(model.Element);
            var animalColor  = ColorExtractor.Extract(model.Animal);

            AddTextToCanvas(x, 10, period);
            AddTextToCanvas(x, 30, EnumHelper <Element> .GetEnumMemberValue(model.Element), elementColor);
            AddTextToCanvas(x, 50, EnumHelper <Element> .GetDisplayValue(model.Element), elementColor);
            AddTextToCanvas(x, 70, EnumHelper <Animal> .GetDisplayValue(model.Animal), animalColor);
            AddTextToCanvas(x, 90, EnumHelper <Animal> .GetEnumMemberValue(model.Animal), animalColor);
        }
Esempio n. 4
0
        public static List <Color> GetColors(int numColors, string fileName, ColorExtractor extractor)
        {
            // Create a Bitmap object from an image file.
            //https://stackoverflow.com/questions/28161900/relative-path-when-creating-bitmap
            try
            {
                Bitmap myBitmap = new Bitmap(fileName);

                return(extractor.ExtractColors(numColors, myBitmap));
            }
            catch (System.ArgumentException e)
            {
                throw new System.Exception("File was not found or could not be read into a bitmap.");
            }
        }
Esempio n. 5
0
        public override IRow Process(IRow input, IUpdatableRow output)
        {
            var imgContent = input.Get <byte[]>("content");
            var colorList  = input.Get <SqlMap <int, string> >("colors");

            using (var ms = new MemoryStream(imgContent))
            {
                var bMap   = Image.FromStream(ms) as Bitmap;
                var result = ColorExtractor.GetMostUsedColor(bMap, _topColorCount);
                if (result.Any())
                {
                    colorList = new SqlMap <int, string>(result);
                }
            }
            output.Set("colors", colorList);
            return(output.AsReadOnly());
        }
Esempio n. 6
0
        private void ShowSplashScreen()
        {
            var helper        = new WindowInteropHelper(this);
            var currentScreen = Screen.FromHandle(helper.Handle);

            FormClosing    += new FormClosingEventHandler(EhClosing);
            Opacity         = 0;
            TopMost         = false; //Enabling other apps to be accessed while it loads
            ShowInTaskbar   = false;
            FormBorderStyle = FormBorderStyle.None;
            BackColor       = ColorExtractor.ExtractColor(Preferences.ColourControls);
            ForeColor       = ColorExtractor.ExtractColor(Preferences.ColourFont);
            StartPosition   = FormStartPosition.CenterScreen;

            Size = new Size(currentScreen.WorkingArea.Height * 3 / 4, currentScreen.WorkingArea.Height * 1 / 2);
            AddControls(Size, this);

            Show();
            Update();
            FadeIn();
        }
        public IActionResult All([FromQuery] string hexColor = null)
        {
            var files = Directory.EnumerateFiles("wwwroot\\images");

            var result = files.Select(file => {
                using var stream = System.IO.File.OpenRead(file);

                var colors = ColorExtractor.GetCached(stream, Path.GetFileName(file));

                return(colors);
            });

            if (!string.IsNullOrWhiteSpace(hexColor))
            {
                var color = Rgba32.ParseHex(hexColor);
                var(hue, saturation, value) = ColorExtractor.ColorToHsv(color);

                const double hueRange        = 255 * .15d;
                const double saturationRange = .15d;
                const double valueRange      = .15d;

                result = result.Where(image => {
                    foreach (var imageColor in image.Colors)
                    {
                        var hsv = imageColor.Hsv;
                        imageColor.MatchedColor = hsv.H - hueRange <hue && hsv.H + hueRange> hue &&
                                                  hsv.S - saturationRange <saturation && hsv.S + saturationRange> saturation &&
                                                  hsv.V - valueRange <value && hsv.V + valueRange> value;
                    }

                    return(image.Colors.Any(x => x.MatchedColor));
                });
            }

            return(Ok(result));
        }
Esempio n. 8
0
        private void RetrieveWalkthroughFiles(Panel panel)
        {
            if (Directory.Exists(FileNames.WalkthroughsDirectory))
            {
                string[] files = Directory.GetFiles(FileNames.WalkthroughsDirectory);
                char     delimiter1 = Path.DirectorySeparatorChar, delimiter2 = Path.AltDirectorySeparatorChar;

                int howToIndex = 1;
                foreach (string file in files)
                {
                    if (file.ToLower().EndsWith(".rtf"))
                    {
                        LinkLabel link = new LinkLabel()
                        {
                            Text      = "How to #" + howToIndex + ": " + Path.GetFileNameWithoutExtension(file),
                            Name      = Path.GetFileNameWithoutExtension(file),
                            ForeColor = ColorExtractor.ExtractColor("222233")
                        };
                        int            linkStart = link.Text.IndexOf(":") + 2;
                        LinkLabel.Link labelLink = new LinkLabel.Link(linkStart, link.Text.Length - linkStart);
                        link.Links.Add(labelLink);
                        link.LinkClicked += delegate
                        {
                            holder = new Form()
                            {
                                ShowInTaskbar   = true,
                                ShowIcon        = false,
                                FormBorderStyle = FormBorderStyle.FixedToolWindow,
                                StartPosition   = FormStartPosition.CenterScreen,
                                Size            = new Size(800, 500),
                                Text            = link.Text,
                                Visible         = true
                            };
                            rtb = new RichTextBox()
                            {
                                Parent   = holder,
                                Dock     = DockStyle.Fill,
                                ReadOnly = true
                            };
                            rtb.GotFocus += delegate
                            {
                                using (Button btn = new Button())
                                {
                                    btn.Focus();
                                }
                            };

                            string fileName = FileNames.WalkthroughsDirectory + link.Name + ".rtf";
                            if (File.Exists(fileName))
                            {
                                GetWalkthroughText(fileName);
                                holder.Show();
                            }
                        };
                        link.Width = 800;
                        panel.Controls.Add(link);
                    }
                    howToIndex++;
                }
            }
            else
            {
            }
        }