Пример #1
0
        public static Color ColorFromHSV(double hue, double saturation, double value)
        {
            int    hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
            double f  = hue / 60 - Math.Floor(hue / 60);

            value = value * 255;
            byte v = Convert.ToByte(value);
            byte p = Convert.ToByte(value * (1 - saturation));
            byte q = Convert.ToByte(value * (1 - f * saturation));
            byte t = Convert.ToByte(value * (1 - (1 - f) * saturation));

            if (hi == 0)
            {
                return(CairoEx.ColorArgb(255, v, t, p));
            }
            if (hi == 1)
            {
                return(CairoEx.ColorArgb(255, q, v, p));
            }
            if (hi == 2)
            {
                return(CairoEx.ColorArgb(255, p, v, t));
            }
            if (hi == 3)
            {
                return(CairoEx.ColorArgb(255, p, q, v));
            }
            if (hi == 4)
            {
                return(CairoEx.ColorArgb(255, t, p, v));
            }

            return(CairoEx.ColorArgb(255, v, p, q));
        }
Пример #2
0
            public void ShowResult()
            {
                var surface = CairoEx.BuildSurface((int)rect.Width, (int)rect.Height, CairoEx.ColorMetal, Cairo.Format.Rgb24);
                var context = new Cairo.Context(surface);

                Draw(context, isClipped);

                string outputPath = "D:\\LayoutTest";

                if (!System.IO.Directory.Exists(outputPath))
                {
                    System.IO.Directory.CreateDirectory(outputPath);
                }

                string filePath = outputPath + "\\" + DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss-fff_") + surface.GetHashCode() + ".png";

                surface.WriteToPng(filePath);
                surface.Dispose();
                context.Dispose();

                Process.Start("rundll32.exe", @"""C:\Program Files\Windows Photo Viewer\PhotoViewer.dll"",ImageView_Fullscreen " + filePath);
            }
Пример #3
0
        internal void DrawContent(Rect rect, string text, GUIStyle style)
        {
            var surface = CairoEx.BuildSurface((int)rect.Width, (int)rect.Height, CairoEx.ColorMetal, Format.Rgb24);
            var context = new Context(surface);

            context.DrawBoxModel(rect, text, style);

            string outputPath = "D:\\ContentTest";

            if (!System.IO.Directory.Exists(outputPath))
            {
                System.IO.Directory.CreateDirectory(outputPath);
            }

            string filePath = outputPath + "\\" + DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss-fff_") + surface.GetHashCode() + ".png";

            surface.WriteToPng(filePath);
            surface.Dispose();
            context.Dispose();

            Process.Start("rundll32.exe", @"""C:\Program Files\Windows Photo Viewer\PhotoViewer.dll"",ImageView_Fullscreen " + filePath);
        }
Пример #4
0
        public static void ShowResult(this LayoutGroup group, [System.Runtime.CompilerServices.CallerMemberName] string memberName = null)
        {
            var rect    = group.Rect;
            var surface = CairoEx.BuildSurface((int)rect.Width, (int)rect.Height, CairoEx.ColorMetal, Format.Rgb24);
            var context = new Cairo.Context(surface);

            Draw(group, context, needClip: true);

            string outputPath = "D:\\LayoutTest";

            if (!System.IO.Directory.Exists(outputPath))
            {
                System.IO.Directory.CreateDirectory(outputPath);
            }

            string filePath = outputPath + "\\" + DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss-fff_") + surface.GetHashCode() + memberName + ".png";

            surface.WriteToPng(filePath);
            surface.Dispose();
            context.Dispose();

            Process.Start("rundll32.exe", @"""C:\Program Files\Windows Photo Viewer\PhotoViewer.dll"",ImageView_Fullscreen " + filePath);
        }
Пример #5
0
        /// <summary>
        /// Draw a box model
        /// </summary>
        /// <param name="g">the Cairo context</param>
        /// <param name="rect">the rect (of the border-box) in which to draw this box model </param>
        /// <param name="content">content of the box mode</param>
        /// <param name="style">style of the box model</param>
        internal static void DrawBoxModel(this Cairo.Context g, Rect rect, string text, GUIStyle style)
        {
            //Widths of border
            var bt = style.BorderTop;
            var br = style.BorderRight;
            var bb = style.BorderBottom;
            var bl = style.BorderLeft;

            //Widths of padding
            var pt = style.PaddingTop;
            var pr = style.PaddingRight;
            var pb = style.PaddingBottom;
            var pl = style.PaddingLeft;

            //4 corner of the border-box
            var btl           = new Point(rect.Left, rect.Top);
            var btr           = new Point(rect.Right, rect.Top);
            var bbr           = new Point(rect.Right, rect.Bottom);
            var bbl           = new Point(rect.Left, rect.Bottom);
            var borderBoxRect = new Rect(btl, bbr);

            //4 corner of the padding-box
            var ptl            = new Point(btl.X + bl, btl.Y + bt);
            var ptr            = new Point(btr.X - br, btr.Y + bt);
            var pbr            = new Point(bbr.X - br, bbr.Y - bb);
            var pbl            = new Point(bbl.X + bl, bbl.Y - bb);
            var paddingBoxRect = new Rect(ptl, pbr);

            //4 corner of the content-box
            var ctl            = new Point(ptl.X + pl, ptl.Y + pt);
            var ctr            = new Point(ptr.X - pr, ptr.Y + pr);
            var cbr            = new Point(pbr.X - pr, pbr.Y - pb);
            var cbl            = new Point(pbl.X + pl, pbl.Y - pb);
            var contentBoxRect = new Rect(ctl, cbr);

            /*
             * Render from inner to outer: Content, Padding, Border, Margin, Outline
             */

            //Content
            //Content-box background(draw as a filled rectangle now)
            g.FillRectangle(rect, style.BackgroundColor);
            //Content-box
            if (text != null)
            {
                g.DrawText(contentBoxRect, text, style.FontSize, style.FontColor);
            }

            //Border
            //  Top
            if (bt != 0)
            {
                g.FillPolygon(new[] { ptl, btl, btr, ptr }, style.BorderTopColor);
            }
            //  Right
            if (br != 0)
            {
                g.FillPolygon(new[] { ptr, btr, bbr, pbr }, style.BorderRightColor);
            }
            //  Bottom
            if (bb != 0)
            {
                g.FillPolygon(new[] { pbr, bbr, bbl, pbl }, style.BorderBottomColor);
            }
            //  Left
            if (bl != 0)
            {
                g.FillPolygon(new[] { pbl, bbl, btl, ptl }, style.BorderLeftColor);
            }

            //Outline
            if (style.OutlineWidth != 0)
            {
                g.Rectangle(borderBoxRect.TopLeft.ToPointD(), borderBoxRect.Width, borderBoxRect.Height);
                g.LineWidth = style.OutlineWidth;
                g.SetSourceColor(style.OutlineColor);
                g.Stroke();
            }

#if DrawPaddingBox
            g.Rectangle(paddingBoxRect.TopLeft.ToPointD(), paddingBoxRect.Width, paddingBoxRect.Height);
            g.LineWidth = 1;
            g.SetSourceColor(CairoEx.ColorRgb(0, 100, 100));
            g.Stroke();
#endif

#if DrawContentBox
            g.Rectangle(contentBoxRect.TopLeft.ToPointD(), contentBoxRect.Width, contentBoxRect.Height);
            g.LineWidth = 1;
            g.SetSourceColor(CairoEx.ColorRgb(100, 0, 100));
            g.Stroke();
#endif
        }