ClipPreserve() public méthode

public ClipPreserve ( ) : void
Résultat void
Exemple #1
0
        public void clearAndClip(Context ctx)
        {
            if (list.Count == 0)
                return;
            foreach (Rectangle r in list)
                ctx.Rectangle(r);

            ctx.ClipPreserve();
            ctx.Operator = Operator.Clear;
            ctx.Fill();
            ctx.Operator = Operator.Over;
        }
        protected virtual void DrawBackground(Cairo.Context context, Gdk.Rectangle region)
        {
            LayoutRoundedRectangle(context, region);
            context.ClipPreserve();

            using (LinearGradient lg = new LinearGradient(region.X, region.Y, region.X, region.Y + region.Height)) {
                lg.AddColorStop(0, Styles.StatusBarFill1Color);
                lg.AddColorStop(1, Styles.StatusBarFill4Color);

                context.SetSource(lg);
                context.FillPreserve();
            }

            context.Save();
            double midX = region.X + region.Width / 2.0;
            double midY = region.Y + region.Height;

            context.Translate(midX, midY);

            using (RadialGradient rg = new RadialGradient(0, 0, 0, 0, 0, region.Height * 1.2)) {
                rg.AddColorStop(0, Styles.StatusBarFill1Color);
                rg.AddColorStop(1, Styles.WithAlpha(Styles.StatusBarFill1Color, 0));

                context.Scale(region.Width / (double)region.Height, 1.0);
                context.SetSource(rg);
                context.Fill();
            }
            context.Restore();

            using (LinearGradient lg = new LinearGradient(0, region.Y, 0, region.Y + region.Height)) {
                lg.AddColorStop(0, Styles.StatusBarShadowColor1);
                lg.AddColorStop(1, Styles.WithAlpha(Styles.StatusBarShadowColor1, Styles.StatusBarShadowColor1.A * 0.2));

                LayoutRoundedRectangle(context, region, 0, -1);
                context.LineWidth = 1;
                context.SetSource(lg);
                context.Stroke();
            }

            using (LinearGradient lg = new LinearGradient(0, region.Y, 0, region.Y + region.Height)) {
                lg.AddColorStop(0, Styles.StatusBarShadowColor2);
                lg.AddColorStop(1, Styles.WithAlpha(Styles.StatusBarShadowColor2, Styles.StatusBarShadowColor2.A * 0.2));

                LayoutRoundedRectangle(context, region, 0, -2);
                context.LineWidth = 1;
                context.SetSource(lg);
                context.Stroke();
            }

            context.ResetClip();
        }
Exemple #3
0
        protected override void onDraw(Cairo.Context gr)
        {
            if (datas == null)
            {
                return;
            }

            lock (mutex) {
                gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight);
                gr.SetFontSize(Font.Size);

                Crow.Rectangle scrBar = ClientRectangle;
                if (datas?.Count > visibleLines)
                {
                    scrBar.X    += ClientRectangle.Width - scrBarWidth;
                    scrBar.Width = scrBarWidth;
                }
                Crow.Rectangle r = ClientRectangle;
                r.Width -= scrBarWidth;

                int diffScroll  = lastScroll - scroll;
                int diffVisible = visibleLines - lastVisibleLines;

                int limInf = 0;
                int limSup = diffScroll + diffVisible;

                if (diffScroll < 0)
                {
                    limInf = lastVisibleLines + diffScroll;
                    limSup = visibleLines;
                }

                gr.Save();
                gr.ResetClip();

                gr.Rectangle(r.X, r.Y + limInf * fe.Height, r.Width, (limSup - limInf) * fe.Height);
                if (lastHoverIndex != HoverIndex)
                {
                    if (lastHoverIndex >= 0)
                    {
                        gr.Rectangle(r.X, r.Y + (lastHoverIndex - Scroll) * fe.Height, r.Width, fe.Height);
                    }
                    if (HoverIndex >= 0)
                    {
                        gr.Rectangle(r.X, r.Y + (HoverIndex - Scroll) * fe.Height, r.Width, fe.Height);
                    }
                }
                if (lastSelectedIndex != SelectedIndex)
                {
                    if (lastSelectedIndex >= 0)
                    {
                        gr.Rectangle(r.X, r.Y + (lastSelectedIndex - Scroll) * fe.Height, r.Width, fe.Height);
                    }
                    if (selectedIndex >= 0)
                    {
                        gr.Rectangle(r.X, r.Y + (SelectedIndex - Scroll) * fe.Height, r.Width, fe.Height);
                    }
                }
                if (datas?.Count > visibleLines && diffScroll != 0)
                {
                    gr.Rectangle(scrBar);
                }

                gr.ClipPreserve();
                gr.Operator = Operator.Clear;
                gr.Fill();
                gr.Operator = Operator.Over;

                base.onDraw(gr);

                Foreground.SetAsSource(gr);

                int i = limInf;
                while (i < limSup)
                {
                    if (i + Scroll >= Datas.Count)
                    {
                        break;
                    }
                    drawDataLine(gr, i + Scroll, r.X, r.Y + i * fe.Height, (double)r.Width, fe.Height);
                    i++;
                }
                int redrawnLines = limSup - limInf;
                System.Diagnostics.Debug.WriteLine("draw {0} lines from {1} to {2}", redrawnLines, limInf, limSup - 1);
                if (lastHoverIndex != HoverIndex)
                {
                    if (lastHoverIndex >= 0 && (redrawnLines == 0 || (lastHoverIndex < limInf + Scroll || lastHoverIndex >= limSup + Scroll)))
                    {
                        drawDataLine(gr, lastHoverIndex, r.X, r.Y + (lastHoverIndex - Scroll) * fe.Height, (double)r.Width, fe.Height);
                    }
                    if (HoverIndex >= 0 && (redrawnLines == 0 || (HoverIndex < limInf + Scroll || HoverIndex >= limSup + Scroll)))
                    {
                        drawDataLine(gr, HoverIndex, r.X, r.Y + (HoverIndex - Scroll) * fe.Height, (double)r.Width, fe.Height);
                    }
                }
                if (lastSelectedIndex != SelectedIndex)
                {
                    if (lastSelectedIndex >= 0 && (redrawnLines == 0 || (lastSelectedIndex < limInf + Scroll || lastSelectedIndex >= limSup + Scroll)))
                    {
                        drawDataLine(gr, lastSelectedIndex, r.X, r.Y + (lastSelectedIndex - Scroll) * fe.Height, (double)r.Width, fe.Height);
                    }
                    if (SelectedIndex >= 0 && (redrawnLines == 0 || (SelectedIndex < limInf + Scroll || SelectedIndex >= limSup + Scroll)))
                    {
                        drawDataLine(gr, SelectedIndex, r.X, r.Y + (SelectedIndex - Scroll) * fe.Height, (double)r.Width, fe.Height);
                    }
                }

                double x = ClientRectangle.X;
                gr.LineWidth = 1;
                for (i = 0; i < cols.Length; i++)
                {
                    x += (double)r.Width * cols [i];
                    gr.MoveTo(Math.Floor(x) + 0.5, 0);
                    gr.LineTo(Math.Floor(x) + 0.5, r.Height);
                }
                gr.Stroke();

                lastScroll        = Scroll;
                lastHoverIndex    = HoverIndex;
                lastSelectedIndex = SelectedIndex;
                lastVisibleLines  = visibleLines;

                if (Datas?.Count <= visibleLines)
                {
                    gr.Restore();
                    return;
                }
                if (mouseScrolling)
                {
                    new SolidColor(Crow.Color.Jet.AdjustAlpha(0.5)).SetAsSource(gr);
                }
                else
                {
                    new SolidColor(Crow.Color.LightGray.AdjustAlpha(0.5)).SetAsSource(gr);
                }
                CairoHelpers.CairoRectangle(gr, scrBar, 0.0);
                gr.Fill();
                new SolidColor(Crow.Color.BlueCrayola.AdjustAlpha(0.7)).SetAsSource(gr);
                scrBar.Y     += (int)((double)scrBar.Height * (double)Scroll / (double)Datas.Count);
                scrBar.Height = (int)((double)scrBar.Height * (double)visibleLines / (double)Datas.Count);
                CairoHelpers.CairoRectangle(gr, scrBar, 2.0);
                gr.Fill();
                gr.Restore();
            }
        }
Exemple #4
0
        /// <summary>Draws a ribbon.</summary>
        public void DrawRibbon(Context cr, Gdk.Rectangle menuBarAllocation, Gdk.Rectangle bodyAllocation, double roundSize, double lineWidth, Ribbon widget)
        {
            double lineWidth05 = lineWidth / 2;
            double lineWidth15 = 3 * lineWidth05;
            double x0, x1, y0, y1;
            LinearGradient linGrad;

            if(menuBarAllocation.Height > 0)
            {
                cr.Rectangle (menuBarAllocation.X, menuBarAllocation.Y, menuBarAllocation.Width, menuBarAllocation.Height - 1);
                linGrad = new LinearGradient (0, menuBarAllocation.Y, 0, menuBarAllocation.Y + menuBarAllocation.Height - 1);
                linGrad.AddColorStop (0.0, new Color (1, 1, 1, 0.5));
                linGrad.AddColorStop (0.3, new Color (1, 1, 1, 0.2));
                linGrad.AddColorStop (0.3, new Color (1, 1, 1, 0.0));
                linGrad.AddColorStop (1.0, new Color (1, 1, 1, 0.5));
                cr.Pattern = linGrad;
                cr.Fill ();
                linGrad.Destroy ();

                cr.MoveTo (menuBarAllocation.X, menuBarAllocation.Bottom + 0.5);
                cr.LineTo (menuBarAllocation.Right, menuBarAllocation.Bottom + 0.5);
                cr.Color = new Color (1, 1, 1, 0.5);
                cr.LineWidth = 1;
                cr.Stroke ();

                // Quick Access Toolbar background

                Gdk.Rectangle alloc = widget.QuickAccessToolbar.Allocation;
                x0 = alloc.X;
                x1 = alloc.Right - 1;
                y0 = alloc.Y;
                y1 = alloc.Bottom - 1;
                double radius = (y1 - y0) / 2;

                cr.LineWidth = 1;

                if(widget.ApplicationButton != null)
                {
                    Gdk.Rectangle alloc2 = widget.ApplicationButton.Allocation;
                    double cx = alloc2.X + alloc2.Width / 2;
                    double cy = alloc2.Y + alloc2.Height / 2;
                    double radius2 = x0 - cx;
                    double alpha = Math.Asin ((y0 - cy) / radius2);
                    double beta = Math.Asin ((y1 - cy) / radius2);
                    double curveWidth0 = Math.Cos (Math.Abs (alpha)) * radius2;
                    double curveWidth1 = Math.Cos (Math.Abs (beta)) * radius2;
                    double curveWidth = Math.Min (curveWidth0, curveWidth1);

                    cr.Save ();
                    cr.Rectangle (cx + curveWidth, y0, x1 - cx - curveWidth, alloc.Height);
                    cr.ClipPreserve ();
                    cr.ArcNegative (cx, cy, radius2, -alpha, -beta);
                    linGrad = new LinearGradient (0, y0, 0, y1);
                    linGrad.AddColorStop (0.0, colorScheme.Bright);
                    linGrad.AddColorStop (1.0, colorScheme.PrettyDark);
                    cr.Pattern = linGrad;
                    //cr.Color = new Color (1, 0, 0);
                    cr.Fill ();
                    cr.Restore ();
                    cr.Arc (x1, y0 + radius, radius - 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
                    cr.Pattern = linGrad;
                    cr.Fill ();
                    linGrad.Destroy ();

                    cr.Arc (cx, cy, radius2, alpha, beta);
                    cr.Color = new Color (0, 0, 0, 0.6);
                    cr.Stroke ();
                    radius2 -= 1;
                    cr.Arc (cx, cy, radius2, alpha, beta);
                    cr.Color = new Color (1, 1, 1, 0.4);
                    cr.Stroke ();

                    cr.MoveTo (cx + curveWidth0, y0 - 0.5);
                    cr.LineTo (x1, y0 - 0.5);
                    cr.Color = new Color (1, 1, 1, 0.4);
                    cr.Stroke ();

                    cr.MoveTo (cx + curveWidth0, y0 + 0.5);
                    cr.LineTo (x1, y0 + 0.5);
                    cr.Color = new Color (0, 0, 0, 0.6);
                    cr.Stroke ();

                    cr.MoveTo (cx + curveWidth1, y1 - 0.5);
                    cr.LineTo (x1, y1 - 0.5);
                    cr.Color = new Color (0, 0, 0, 0.6);
                    cr.Stroke ();

                    cr.MoveTo (cx + curveWidth1, y1 + 0.5);
                    cr.LineTo (x1, y1 + 0.5);
                    cr.Color = new Color (1, 1, 1, 0.4);
                    cr.Stroke ();
                }
                else
                {
                    cr.Rectangle (x0, y0, x1 - x0, alloc.Height);
                    linGrad = new LinearGradient (0, y0, 0, y1);
                    linGrad.AddColorStop (0.0, colorScheme.Bright);
                    linGrad.AddColorStop (1.0, colorScheme.PrettyDark);
                    cr.Pattern = linGrad;
                    cr.Fill ();

                    cr.Arc (x1, y0 + radius, radius - 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
                    cr.Pattern = linGrad;
                    cr.Fill ();
                    linGrad.Destroy ();

                    cr.MoveTo (x0 + 0.5, y0);
                    cr.LineTo (x0 + 0.5, y1);
                    cr.Color = new Color (1, 1, 1, 0.4);
                    cr.Stroke ();

                    cr.MoveTo (x0 + 1.5, y0);
                    cr.LineTo (x0 + 1.5, y1);
                    cr.Color = new Color (0, 0, 0, 0.6);
                    cr.Stroke ();
                }

                cr.Arc (x1, y0 + radius, radius + 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
                cr.Color = new Color (1, 1, 1, 0.4);
                cr.Stroke ();

                cr.Arc (x1, y0 + radius, radius - 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
                cr.Color = new Color (0, 0, 0, 0.6);
                cr.Stroke ();
            }

            Ribbon.RibbonPage p = widget.CurrentPage;
            if(p != null)
            {
                //Color c = ColorScheme.GetColor(colorScheme.Bright, 0.92);
                Color c = colorScheme.Normal;

                if(bodyAllocation.Height > 0)
                {
                    /*** PAGE ***/

                    x0 = bodyAllocation.X; x1 = bodyAllocation.X + bodyAllocation.Width;
                    y0 = bodyAllocation.Y; y1 = bodyAllocation.Y + bodyAllocation.Height;

                    cr.Arc (x0 + roundSize, y1 - roundSize, roundSize - lineWidth05, Math.PI/2, Math.PI);
                    cr.Arc (x0 + roundSize, y0 + roundSize, roundSize - lineWidth05, Math.PI, 3*Math.PI/2);
                    cr.Arc (x1 - roundSize, y0 + roundSize, roundSize - lineWidth05, 3*Math.PI/2, 0);
                    cr.Arc (x1 - roundSize, y1 - roundSize, roundSize - lineWidth05, 0, Math.PI/2);
                    cr.LineTo (x0 + roundSize, y1 - lineWidth05);

                    /*** BACKGOUND ***/
                    cr.Color = c;
                    cr.FillPreserve ();

                    /*** DARK BORDER ***/
                    cr.LineWidth = lineWidth;
                    cr.Color = ColorScheme.GetColorAbsolute (colorScheme.Normal, 0.75);
                    cr.Stroke ();

                    /*** GLASS EFFECT ***/
                    double ymid = Math.Round (y0 + (y1 - y0) * 0.25);

                    cr.Arc (x0 + roundSize, y0 + roundSize, roundSize - lineWidth, Math.PI, 3*Math.PI/2);
                    cr.Arc (x1 - roundSize, y0 + roundSize, roundSize - lineWidth, 3*Math.PI/2, 0);
                    cr.LineTo (x1 - lineWidth, ymid);
                    cr.LineTo (x0 + lineWidth, ymid);
                    cr.LineTo (x0 + lineWidth, y0 + roundSize);
                    linGrad = new LinearGradient (0, y0, 0, ymid);
                    linGrad.AddColorStop (0.0, new Color (0, 0, 0, 0.0));
                    linGrad.AddColorStop (1.0, new Color (0, 0, 0, 0.075));
                    cr.Pattern = linGrad;
                    cr.Fill ();
                    linGrad.Destroy ();

                    cr.Arc (x0 + roundSize, y1 - roundSize, roundSize - lineWidth, Math.PI/2, Math.PI);
                    cr.LineTo (x0 + lineWidth, ymid);
                    cr.LineTo (x1 - lineWidth, ymid);
                    cr.Arc (x1 - roundSize, y1 - roundSize, roundSize - lineWidth, 0, Math.PI/2);
                    cr.LineTo (x0 + roundSize, y1 - lineWidth);
                    linGrad = new LinearGradient (0, ymid, 0, y1);
                    linGrad.AddColorStop (0.0, new Color (0, 0, 0, 0.1));
                    linGrad.AddColorStop (0.5, new Color (0, 0, 0, 0.0));
                    cr.Pattern = linGrad;
                    cr.Fill ();
                    linGrad.Destroy ();
                }

                /*** TAB ***/

                Gdk.Rectangle r = p.LabelAllocation;

                x0 = r.X; x1 = r.X + r.Width;
                y0 = r.Y; y1 = r.Y + r.Height + lineWidth;

                /*** TAB :: BACKGROUND ***/

                cr.MoveTo (x0 + lineWidth05, y1);
                cr.LineTo (x0 + lineWidth05, y0 + roundSize);
                cr.Arc (x0 + roundSize, y0 + roundSize, roundSize - lineWidth05, Math.PI, 3*Math.PI/2);
                cr.Arc (x1 - roundSize, y0 + roundSize, roundSize - lineWidth05, 3*Math.PI/2, 0);
                cr.LineTo (x1 - lineWidth05, y1);

                linGrad = new LinearGradient (0, y0, 0, y1);
                linGrad.AddColorStop (0.0, colorScheme.PrettyBright);
                linGrad.AddColorStop (1.0, c);
                cr.Pattern = linGrad;
                cr.Fill ();
                linGrad.Destroy ();

                /*** TAB :: DARK BORDER ***/

                cr.MoveTo (x0 + lineWidth05, y1);
                cr.LineTo (x0 + lineWidth05, y0 + roundSize);
                cr.Arc (x0 + roundSize, y0 + roundSize, roundSize - lineWidth05, Math.PI, 3*Math.PI/2);
                cr.Arc (x1 - roundSize, y0 + roundSize, roundSize - lineWidth05, 3*Math.PI/2, 0);
                cr.LineTo (x1 - lineWidth05, y1);

                cr.LineWidth = lineWidth;
                cr.Color = ColorScheme.GetColorRelative (colorScheme.Bright, -0.1);
                cr.Stroke ();

                y1 -= 1.0;

                /*** TAB :: HIGHLIGHT ***/

                cr.MoveTo (x0 + lineWidth15, y1);
                cr.LineTo (x0 + lineWidth15, y0 + roundSize);
                cr.Arc (x0 + roundSize, y0 + roundSize, roundSize - lineWidth15, Math.PI, 3*Math.PI/2);
                cr.Arc (x1 - roundSize, y0 + roundSize, roundSize - lineWidth15, 3*Math.PI/2, 0);
                cr.LineTo (x1 - lineWidth15, y1);

                cr.LineWidth = lineWidth;
                linGrad = new LinearGradient (0, y0+lineWidth, 0, y1);
                linGrad.AddColorStop (0.0, colorScheme.PrettyBright);
                linGrad.AddColorStop (1.0, ColorScheme.SetAlphaChannel (colorScheme.Bright, 0));
                cr.Pattern = linGrad;
                cr.Stroke ();
                linGrad.Destroy ();

                /*** TAB :: SHADOW ***/

                cr.MoveTo (x0 - lineWidth05, y1);
                cr.LineTo (x0 - lineWidth05, y0 + roundSize);
                cr.Arc (x0 + roundSize, y0 + roundSize, roundSize + lineWidth05, Math.PI, 3*Math.PI/2);
                cr.Arc (x1 - roundSize, y0 + roundSize, roundSize + lineWidth05, 3*Math.PI/2, 0);
                cr.LineTo (x1 + lineWidth05, y1);

                cr.LineWidth = lineWidth;
                cr.Color = new Color (0, 0, 0, 0.2);
                cr.Stroke ();
            }
        }