Ejemplo n.º 1
0
        public void Add(string content, RgbaColor rgba, Action action)
        {
            if (Document.Blocks.Count <= 0)
            {
                Document.Blocks.Add(new Paragraph());
            }
            Run run = new Run(content);

            if (action == null)
            {
                if (rgba != null)
                {
                    run.Foreground = rgba.SolidColorBrush;
                }
                (Document.Blocks.LastBlock as Paragraph).Inlines.Add(run);
            }
            else
            {
                Hyperlink hl = new Hyperlink(run);
                if (rgba != null)
                {
                    hl.Foreground = rgba.SolidColorBrush;
                }
                hl.Click += delegate { action(); };
                hl.MouseLeftButtonDown += delegate { action(); };
                (Document.Blocks.LastBlock as Paragraph).Inlines.Add(hl);
            }
            ScrollToEnd();
        }
Ejemplo n.º 2
0
        public RgbaColor(double h, double s, double b, double a = 1)
        {
            RgbaColor rgba = Utility.HsbaToRgba(new HsbaColor(h, s, b, a));

            R = rgba.R;
            G = rgba.G;
            B = rgba.B;
            A = rgba.A;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Rgba转Hsba
        /// </summary>
        /// <param name="rgba"></param>
        /// <returns></returns>
        internal static HsbaColor RgbaToHsba(RgbaColor rgba)
        {
            int[] rgb = new int[] { rgba.R, rgba.G, rgba.B };
            Array.Sort(rgb);
            int max = rgb[2];
            int min = rgb[0];

            double hsbB = max / 255.0;
            double hsbS = max == 0 ? 0 : (max - min) / (double)max;
            double hsbH = 0;

            if (rgba.R == rgba.G && rgba.R == rgba.B)
            {
            }
            else
            {
                if (max == rgba.R && rgba.G >= rgba.B)
                {
                    hsbH = (rgba.G - rgba.B) * 60.0 / (max - min) + 0.0;
                }
                else if (max == rgba.R && rgba.G < rgba.B)
                {
                    hsbH = (rgba.G - rgba.B) * 60.0 / (max - min) + 360.0;
                }
                else if (max == rgba.G)
                {
                    hsbH = (rgba.B - rgba.R) * 60.0 / (max - min) + 120.0;
                }
                else if (max == rgba.B)
                {
                    hsbH = (rgba.R - rgba.G) * 60.0 / (max - min) + 240.0;
                }
            }

            return(new HsbaColor(hsbH, hsbS, hsbB, rgba.A / 255.0));
        }
Ejemplo n.º 4
0
 public void Add(string content, RgbaColor rgba)
 {
     Add(content, rgba, null);
 }