コード例 #1
0
        void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y)
        {
            if (!heightMeasured)
            {
                return;
            }

            Pango.Layout layout       = new Pango.Layout(PangoContext);
            TableRow     lastCategory = null;

            foreach (var r in rowList)
            {
                int w, h;
                layout.SetText(r.Label);
                layout.GetPixelSize(out w, out h);
                int indent = 0;

                if (r.IsCategory)
                {
                    var rh = h + CategoryTopBottomPadding * 2;
                    ctx.Rectangle(0, y, Allocation.Width, rh);
                    using (var gr = new LinearGradient(0, y, 0, rh)) {
                        gr.AddColorStop(0, new Cairo.Color(248d / 255d, 248d / 255d, 248d / 255d));
                        gr.AddColorStop(1, new Cairo.Color(240d / 255d, 240d / 255d, 240d / 255d));
                        ctx.SetSource(gr);
                        ctx.Fill();
                    }

                    if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand)
                    {
                        ctx.MoveTo(0, y + 0.5);
                        ctx.LineTo(Allocation.Width, y + 0.5);
                    }
                    ctx.MoveTo(0, y + rh - 0.5);
                    ctx.LineTo(Allocation.Width, y + rh - 0.5);
                    ctx.SetSourceColor(DividerColor);
                    ctx.Stroke();

                    ctx.MoveTo(x, y + CategoryTopBottomPadding);
                    ctx.SetSourceColor(CategoryLabelColor);
                    Pango.CairoHelper.ShowLayout(ctx, layout);

                    var img = r.Expanded ? discloseUp : discloseDown;
                    ctx.DrawImage(this, img, Allocation.Width - img.Width - CategoryTopBottomPadding, y + Math.Round((rh - img.Height) / 2));

                    y           += rh;
                    lastCategory = r;
                }
                else
                {
                    var cell = GetCell(r);
                    r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject;
                    var state = r.Enabled ? State : Gtk.StateType.Insensitive;
                    ctx.Save();
                    ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2);
                    ctx.Clip();
                    ctx.MoveTo(x, y + PropertyTopBottomPadding);
                    ctx.SetSourceColor(Style.Text(state).ToCairoColor());
                    Pango.CairoHelper.ShowLayout(ctx, layout);
                    ctx.Restore();

                    if (r != currentEditorRow)
                    {
                        var bounds = GetInactiveEditorBounds(r);

                        cell.Render(GdkWindow, ctx, bounds, state);

                        if (r.IsExpandable)
                        {
                            var img = r.Expanded ? discloseUp : discloseDown;
                            ctx.DrawImage(
                                this, img,
                                Allocation.Width - img.Width - PropertyTopBottomPadding,
                                y + Math.Round((h + PropertyTopBottomPadding * 2 - img.Height) / 2)
                                );
                        }
                    }

                    y     += r.EditorBounds.Height;
                    indent = PropertyIndent;
                }

                if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand))
                {
                    int py = y;

                    ctx.Save();
                    if (r.AnimatingExpand)
                    {
                        ctx.Rectangle(0, y, Allocation.Width, r.AnimationHeight);
                    }
                    else
                    {
                        ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height);
                    }

                    ctx.Clip();
                    Draw(ctx, r.ChildRows, dividerX, x + indent, ref y);
                    ctx.Restore();

                    if (r.AnimatingExpand)
                    {
                        y = py + r.AnimationHeight;
                        // Repaing the background because the cairo clip doesn't work for gdk primitives
                        int dx = (int)((double)Allocation.Width * dividerPosition);
                        ctx.Rectangle(0, y, dx, Allocation.Height - y);
                        ctx.SetSourceColor(LabelBackgroundColor);
                        ctx.Fill();
                        ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y);
                        ctx.SetSourceRGB(1, 1, 1);
                        ctx.Fill();
                    }
                }
            }
        }
コード例 #2
0
ファイル: HistogramPlot.cs プロジェクト: wwwK/XwPlot
        /// <summary>
        /// Draws the histogram.
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            double          yoff;
            SequenceAdapter data = new SequenceAdapter(DataSource, DataMember, OrdinateData, AbscissaData);

            ctx.Save();
            ctx.SetLineWidth(1);

            for (int i = 0; i < data.Count; ++i)
            {
                // (1) determine the top left hand point of the bar (assuming not centered)
                Point p1 = data[i];
                if (double.IsNaN(p1.X) || double.IsNaN(p1.Y))
                {
                    continue;
                }

                // (2) determine the top right hand point of the bar (assuming not centered)
                Point p2 = Point.Zero;;
                if (i + 1 != data.Count)
                {
                    p2 = data[i + 1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y))
                    {
                        continue;
                    }
                    p2.Y = p1.Y;
                }
                else if (i != 0)
                {
                    p2 = data[i - 1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y))
                    {
                        continue;
                    }
                    double offset = p1.X - p2.X;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }
                else
                {
                    double offset = 1.0;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }

                // (3) now account for plots this may be stacked on top of.
                HistogramPlot currentPlot = this;
                yoff = 0.0;
                double yval = 0.0;
                while (currentPlot.IsStacked)
                {
                    SequenceAdapter stackedToData = new SequenceAdapter(
                        currentPlot.stackedTo.DataSource,
                        currentPlot.stackedTo.DataMember,
                        currentPlot.stackedTo.OrdinateData,
                        currentPlot.stackedTo.AbscissaData);

                    yval       += stackedToData[i].Y;
                    yoff        = yAxis.WorldToPhysical(yval, false).Y;
                    p1.Y       += stackedToData[i].Y;
                    p2.Y       += stackedToData[i].Y;
                    currentPlot = currentPlot.stackedTo;
                }

                // (4) now account for centering
                if (Center)
                {
                    double offset = (p2.X - p1.X) / 2.0;
                    p1.X -= offset;
                    p2.X -= offset;
                }

                // (5) now account for BaseOffset (shift of bar sideways).
                p1.X += BaseOffset;
                p2.X += BaseOffset;

                // (6) now get physical coordinates of top two points.
                Point xPos1 = xAxis.WorldToPhysical(p1.X, false);
                Point yPos1 = yAxis.WorldToPhysical(p1.Y, false);
                Point xPos2 = xAxis.WorldToPhysical(p2.X, false);

                if (IsStacked)
                {
                    currentPlot = this;
                    while (currentPlot.IsStacked)
                    {
                        currentPlot = currentPlot.stackedTo;
                    }
                    baseWidth = currentPlot.baseWidth;
                }

                double width = xPos2.X - xPos1.X;
                double height;
                if (IsStacked)
                {
                    height = -yPos1.Y + yoff;
                }
                else
                {
                    height = -yPos1.Y + yAxis.PhysicalMin.Y;
                }

                double    xoff = (1.0 - baseWidth) / 2.0 * width;
                Rectangle bar  = new Rectangle(xPos1.X + xoff, yPos1.Y, width - 2 * xoff, height);

                ctx.Rectangle(bar);
                if (Filled)
                {
                    if (bar.Height != 0 && bar.Width != 0)
                    {
                        if (FillGradient != null)
                        {
                            // Scale FillGradient to bar rectangle
                            double         sX = bar.X + fillGradient.StartPoint.X * bar.Width;
                            double         sY = bar.Y + fillGradient.StartPoint.Y * bar.Height;
                            double         eX = bar.X + fillGradient.EndPoint.X * bar.Width;
                            double         eY = bar.Y + fillGradient.EndPoint.Y * bar.Height;
                            LinearGradient g  = new LinearGradient(sX, sY, eX, eY);
                            g.AddColorStop(0, FillGradient.StartColor);
                            g.AddColorStop(1, FillGradient.EndColor);
                            ctx.Pattern = g;
                        }
                        else
                        {
                            ctx.SetColor(FillColor);
                        }
                        ctx.FillPreserve();
                    }
                }
                ctx.SetColor(BorderColor);
                ctx.Stroke();
            }
            ctx.Restore();
        }
コード例 #3
0
        void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y)
        {
            if (!heightMeasured)
            {
                return;
            }

            Pango.Layout layout       = new Pango.Layout(PangoContext);
            TableRow     lastCategory = null;

            Pango.FontDescription defaultFont = new Pango.FontDescription();
            Pango.FontDescription changedFont = defaultFont.Copy();
            defaultFont.Weight = Pango.Weight.Bold;

            foreach (var r in rowList)
            {
                int w, h;
                layout.SetText(r.Label);
                if (r.IsDefaultValue && (r.Expanded || HasDefaultValue(r.ChildRows)))
                {
                    layout.FontDescription = changedFont;
                }
                else
                {
                    layout.FontDescription = defaultFont;
                }
                layout.GetPixelSize(out w, out h);
                int indent = 0;

                if (r.IsCategory)
                {
                    var rh = h + CategoryTopBottomPadding * 2;
                    ctx.Rectangle(0, y, Allocation.Width, rh);
                    using (var gr = new LinearGradient(0, y, 0, rh)) {
                        gr.AddColorStop(0, new Cairo.Color(248d / 255d, 248d / 255d, 248d / 255d));
                        gr.AddColorStop(1, new Cairo.Color(240d / 255d, 240d / 255d, 240d / 255d));
                        ctx.SetSource(gr);
                        ctx.Fill();
                    }

                    if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand)
                    {
                        ctx.MoveTo(0, y + 0.5);
                        ctx.LineTo(Allocation.Width, y + 0.5);
                    }
                    ctx.MoveTo(0, y + rh - 0.5);
                    ctx.LineTo(Allocation.Width, y + rh - 0.5);
                    ctx.SetSourceColor(DividerColor);
                    ctx.Stroke();

                    ctx.MoveTo(x, y + CategoryTopBottomPadding);
                    ctx.SetSourceColor(CategoryLabelColor);
                    Pango.CairoHelper.ShowLayout(ctx, layout);

                    var img  = r.Expanded ? discloseUp : discloseDown;
                    var area = GetCategoryArrowArea(r);

                    CairoHelper.SetSourcePixbuf(ctx, img, area.X + (area.Width - img.Width) / 2, area.Y + (area.Height - img.Height) / 2);
                    ctx.Paint();

                    y           += rh;
                    lastCategory = r;
                }
                else
                {
                    var cell = GetCell(r);
                    r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject;
                    var state = r.Enabled ? State : Gtk.StateType.Insensitive;
                    ctx.Save();

                    if (r == lastEditorRow)
                    {
                        ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2);
                        ctx.SetSourceColor(new Cairo.Color(0.8, 0.9, 1.0, 1));
                        ctx.Fill();


                        //int dividerX = (int)((double)Allocation.Width * dividerPosition);
                        //var cell = GetCell(r);
                        //cell.GetSize(Allocation.Width - dividerX, out w, out eh);
                        //eh = Math.Max(h + PropertyTopBottomPadding * 2, eh);
                        //r.EditorBounds = new Gdk.Rectangle(dividerX + PropertyContentLeftPadding, y, Allocation.Width - dividerX - PropertyContentLeftPadding, eh);

                        //var bounds = new Gdk.Rectangle(dividerX + 1, r.EditorBounds.Y, Allocation.Width - dividerX - 1, r.EditorBounds.Height);

                        //ctx.MoveTo(bounds.Right, bounds.Y+1);
                        //ctx.LineTo(bounds.X, bounds.Y+1);
                        //ctx.MoveTo(bounds.Right, bounds.Bottom);
                        //ctx.LineTo(bounds.X, bounds.Bottom);

                        //ctx.Stroke();

                        //ctx.Rectangle(dividerX + 1, r.EditorBounds.Y, Allocation.Width - dividerX - 1, r.EditorBounds.Height);
                        //ctx.SetSourceColor(new Cairo.Color(0.8, 0.9, 1.0, 1));
                        //ctx.Fill();
                    }

                    if (r.ChildRows != null && r.ChildRows.Count > 0)
                    {
                        var img = r.Expanded ? arrowLeft : arrowRight;
                        CairoHelper.SetSourcePixbuf(ctx, img, 2, y + (h + PropertyTopBottomPadding * 2) / 2 - img.Height / 2);
                        ctx.Paint();
                    }

                    ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2);
                    ctx.Clip();
                    ctx.MoveTo(x, y + PropertyTopBottomPadding);
                    ctx.SetSourceColor(Style.Text(state).ToCairoColor());
                    Pango.CairoHelper.ShowLayout(ctx, layout);
                    ctx.Restore();

                    if (r != currentEditorRow)
                    {
                        cell.Render(GdkWindow, ctx, r.EditorBounds, state);
                    }

                    y     += r.EditorBounds.Height;
                    indent = PropertyIndent;
                }

                if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand))
                {
                    int py = y;

                    ctx.Save();
                    if (r.AnimatingExpand)
                    {
                        ctx.Rectangle(0, y, Allocation.Width, r.AnimationHeight);
                    }
                    else
                    {
                        ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height);
                    }

                    ctx.Clip();
                    Draw(ctx, r.ChildRows, dividerX, x + indent, ref y);
                    ctx.Restore();

                    if (r.AnimatingExpand)
                    {
                        y = py + r.AnimationHeight;
                        // Repaing the background because the cairo clip doesn't work for gdk primitives
                        int dx = (int)((double)Allocation.Width * dividerPosition);
                        ctx.Rectangle(0, y, dx, Allocation.Height - y);
                        ctx.SetSourceColor(LabelBackgroundColor);
                        ctx.Fill();
                        ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y);
                        ctx.SetSourceRGB(1, 1, 1);
                        ctx.Fill();
                    }
                }
            }
        }
コード例 #4
0
        static void DrawCloseButton(Context context, Gdk.Point center, bool hovered, double opacity, double animationProgress)
        {
            if (hovered)
            {
                const double radius = 6;
                context.Arc(center.X, center.Y, radius, 0, Math.PI * 2);
                context.SetSourceRGBA(.6, .6, .6, opacity);
                context.Fill();

                context.SetSourceRGBA(0.95, 0.95, 0.95, opacity);
                context.LineWidth = 2;

                context.MoveTo(center.X - 3, center.Y - 3);
                context.LineTo(center.X + 3, center.Y + 3);
                context.MoveTo(center.X - 3, center.Y + 3);
                context.LineTo(center.X + 3, center.Y - 3);
                context.Stroke();
            }
            else
            {
                double       lineColor = .63 - .1 * animationProgress;
                const double fillColor = .74;

                double heightMod = Math.Max(0, 1.0 - animationProgress * 2);
                context.MoveTo(center.X - 3, center.Y - 3 * heightMod);
                context.LineTo(center.X + 3, center.Y + 3 * heightMod);
                context.MoveTo(center.X - 3, center.Y + 3 * heightMod);
                context.LineTo(center.X + 3, center.Y - 3 * heightMod);

                context.LineWidth = 2;
                context.SetSourceRGBA(lineColor, lineColor, lineColor, opacity);
                context.Stroke();

                if (animationProgress > 0.5)
                {
                    double partialProg = (animationProgress - 0.5) * 2;
                    context.MoveTo(center.X - 3, center.Y);
                    context.LineTo(center.X + 3, center.Y);

                    context.LineWidth = 2 - partialProg;
                    context.SetSourceRGBA(lineColor, lineColor, lineColor, opacity);
                    context.Stroke();

                    double radius = partialProg * 3.5;

                    // Background
                    context.Arc(center.X, center.Y, radius, 0, Math.PI * 2);
                    context.SetSourceRGBA(fillColor, fillColor, fillColor, opacity);
                    context.Fill();

                    // Inset shadow
                    using (var lg = new LinearGradient(0, center.Y - 5, 0, center.Y)) {
                        context.Arc(center.X, center.Y + 1, radius, 0, Math.PI * 2);
                        lg.AddColorStop(0, new Cairo.Color(0, 0, 0, 0.2 * opacity));
                        lg.AddColorStop(1, new Cairo.Color(0, 0, 0, 0));
                        context.SetSource(lg);
                        context.Stroke();
                    }

                    // Outline
                    context.Arc(center.X, center.Y, radius, 0, Math.PI * 2);
                    context.SetSourceRGBA(lineColor, lineColor, lineColor, opacity);
                    context.Stroke();
                }
            }
        }
コード例 #5
0
        protected override void OnDraw(Context ctx)
        {
            double rwidth = Bounds.Width, rheight = Bounds.Height;

            if (autoStartY || autoEndY)
            {
                double nstartY = double.MaxValue;
                double nendY   = double.MinValue;
                GetValueRange(AxisDimension.Y, out nstartY, out nendY);

                if (!autoStartY)
                {
                    nstartY = startY;
                }
                if (!autoEndY)
                {
                    nendY = endY;
                }
                if (nendY < nstartY)
                {
                    nendY = nstartY;
                }

                if (nstartY != startY || nendY != endY)
                {
                    yrangeChanged = true;
                    startY        = nstartY;
                    endY          = nendY;
                }
            }

            if (autoStartX || autoEndX)
            {
                double nstartX = double.MaxValue;
                double nendX   = double.MinValue;
                GetValueRange(AxisDimension.X, out nstartX, out nendX);

                if (!autoStartX)
                {
                    nstartX = startX;
                }
                if (!autoEndX)
                {
                    nendX = endX;
                }
                if (nendX < nstartX)
                {
                    nendX = nstartX;
                }

                if (nstartX != startX || nendX != endX)
                {
                    xrangeChanged = true;
                    startX        = nstartX;
                    endX          = nendX;
                }
            }

            if (yrangeChanged)
            {
                FixOrigins();
                double right = rwidth - 2 - AreaBorderWidth;
                left          = AreaBorderWidth;
                left         += MeasureAxisSize(ctx, AxisPosition.Left) + 1;
                right        -= MeasureAxisSize(ctx, AxisPosition.Right) + 1;
                yrangeChanged = false;
                width         = right - left + 1;
                if (width <= 0)
                {
                    width = 1;
                }
            }

            if (xrangeChanged)
            {
                FixOrigins();
                double bottom = rheight - 2 - AreaBorderWidth;
                top     = AreaBorderWidth;
                bottom -= MeasureAxisSize(ctx, AxisPosition.Bottom);
                top    += MeasureAxisSize(ctx, AxisPosition.Top);

                // Make room for cursor handles
                foreach (ChartCursor cursor in cursors)
                {
                    if (cursor.Dimension == AxisDimension.X && top - AreaBorderWidth < cursor.HandleSize)
                    {
                        top = cursor.HandleSize + AreaBorderWidth;
                    }
                }

                xrangeChanged = false;
                height        = bottom - top + 1;
                if (height <= 0)
                {
                    height = 1;
                }
            }

            if (AutoScaleMargin != 0 && height > 0)
            {
                double margin = (double)AutoScaleMargin * (endY - startY) / (double)height;
                if (autoStartY)
                {
                    startY -= margin;
                }
                if (autoEndY)
                {
                    endY += margin;
                }
            }

//			Console.WriteLine ("L:" + left + " T:" + top + " W:" + width + " H:" + height);

            // Draw the background

            if (backgroundDisplay == BackgroundDisplay.Gradient)
            {
                ctx.Rectangle(left - 1, top - 1, width + 2, height + 2);
                Gradient pat = new LinearGradient(left - 1, top - 1, left - 1, height + 2);
                pat.AddColorStop(0, backroundColor);
                Color endc = new Color(1, 1, 1);
                pat.AddColorStop(1, endc);
                ctx.Pattern = pat;
                ctx.Fill();
            }
            else
            {
                ctx.Rectangle(left - 1, top - 1, width + 2, height + 2);
                ctx.SetColor(backroundColor);
                ctx.Fill();
            }
//			win.DrawRectangle (Style.WhiteGC, true, left - 1, top - 1, width + 2, height + 2);
            ctx.SetColor(Color.Black);
            ctx.Rectangle(left - AreaBorderWidth, top - AreaBorderWidth, width + AreaBorderWidth * 2, height + AreaBorderWidth * 2);
            ctx.Stroke();

            // Draw selected area

            if (enableSelection)
            {
                int sx, sy, ex, ey;
                GetPoint(selectionStart.Value, selectionStart.Value, out sx, out sy);
                GetPoint(selectionEnd.Value, selectionEnd.Value, out ex, out ey);
                if (sx > ex)
                {
                    int tmp = sx; sx = ex; ex = tmp;
                }
                ctx.SetColor(new Color(225d / 255d, 225d / 255d, 225d / 255d));
                ctx.Rectangle(sx, top, ex - sx, height + 1);
                ctx.Fill();
            }

            // Draw axes

            foreach (Axis ax in axis)
            {
                DrawAxis(ctx, ax);
            }

            // Draw values
            foreach (Serie serie in series)
            {
                if (serie.Visible)
                {
                    DrawSerie(ctx, serie);
                }
            }

            // Draw cursors
            foreach (ChartCursor cursor in cursors)
            {
                DrawCursor(ctx, cursor);
            }

            // Draw cursor labels
            foreach (ChartCursor cursor in cursors)
            {
                if (cursor.ShowValueLabel)
                {
                    DrawCursorLabel(ctx, cursor);
                }
            }

            ((IDisposable)ctx).Dispose();
        }
コード例 #6
0
        protected override void PaintIconSurface(DockySurface surface)
        {
            if (DeskGrid == null)
            {
                return;
            }

            int cols = DeskGrid.GetLength(0);
            int rows = DeskGrid.GetLength(1);

            Gdk.Color   gdkColor        = Style.Backgrounds [(int)Gtk.StateType.Selected];
            Cairo.Color selection_color = new Cairo.Color((double)gdkColor.Red / ushort.MaxValue,
                                                          (double)gdkColor.Green / ushort.MaxValue,
                                                          (double)gdkColor.Blue / ushort.MaxValue,
                                                          0.5);
            Context cr = surface.Context;

            cr.AlphaPaint();

            LinearGradient lg = new LinearGradient(0, 0, 0, surface.Height);

            lg.AddColorStop(0, new Cairo.Color(.35, .35, .35, .6));
            lg.AddColorStop(1, new Cairo.Color(.05, .05, .05, .7));

            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    if (DeskGrid[x, y] != null)
                    {
                        Cairo.Rectangle area = DeskAreaOnIcon(surface.Width, surface.Height, x, y);
                        cr.Rectangle(area.X, area.Y, area.Width, area.Height);
                        cr.Pattern = lg;
                        cr.FillPreserve();
                        if (DeskGrid[x, y].IsActive)
                        {
                            cr.Color = selection_color;
                            cr.Fill();
                            if (area.Width >= 16 && area.Height >= 16)
                            {
                                using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon("desktop", (int)area.Width, (int)area.Height)) {
                                    Gdk.CairoHelper.SetSourcePixbuf(cr, pbuf, (int)area.X + (area.Width - pbuf.Width) / 2, (int)area.Y + (area.Height - pbuf.Height) / 2);
                                    cr.Paint();
                                }
                            }
                        }
                        cr.NewPath();
                    }
                }
            }

            lg.Destroy();

            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    if (DeskGrid[x, y] != null)
                    {
                        Cairo.Rectangle area = DeskAreaOnIcon(surface.Width, surface.Height, x, y);
                        cr.Rectangle(area.X, area.Y, area.Width, area.Height);
                    }
                }
            }

            lg = new LinearGradient(0, 0, 0, surface.Height);
            lg.AddColorStop(0, new Cairo.Color(.95, .95, .95, .7));
            lg.AddColorStop(1, new Cairo.Color(.5, .5, .5, .7));
            cr.Pattern = lg;
            cr.StrokePreserve();
            lg.Destroy();
        }
コード例 #7
0
        protected override void PaintIconSurface(DockySurface surface)
        {
            int     size = Math.Min(surface.Width, surface.Height);
            Context cr   = surface.Context;

            double center = size / 2.0;

            Cairo.Color base_color = new Cairo.Color(1, .3, .3, .5).SetHue(120 * (1 - CPUUtilization));

            double radius = Math.Max(Math.Min(CPUUtilization * 1.3, 1), .001);

            // draw underlay
            cr.Arc(center, center, center * RadiusPercent, 0, Math.PI * 2);
            cr.Color = new Cairo.Color(0, 0, 0, .5);
            cr.FillPreserve();

            RadialGradient rg = new RadialGradient(center, center, 0, center, center, center * RadiusPercent);

            rg.AddColorStop(0, base_color);
            rg.AddColorStop(0.2, base_color);
            rg.AddColorStop(1, new Cairo.Color(base_color.R, base_color.G, base_color.B, 0.15));
            cr.Pattern = rg;
            cr.FillPreserve();

            rg.Destroy();

            // draw cpu indicator
            rg = new RadialGradient(center, center, 0, center, center, center * RadiusPercent * radius);
            rg.AddColorStop(0, new Cairo.Color(base_color.R, base_color.G, base_color.B, 1));
            rg.AddColorStop(0.2, new Cairo.Color(base_color.R, base_color.G, base_color.B, 1));
            rg.AddColorStop(1, new Cairo.Color(base_color.R, base_color.G, base_color.B, Math.Max(0, CPUUtilization * 1.3 - 1)));
            cr.Pattern = rg;
            cr.Fill();

            rg.Destroy();

            // draw highlight
            cr.Arc(center, center * .8, center * .6, 0, Math.PI * 2);
            LinearGradient lg = new LinearGradient(0, 0, 0, center);

            lg.AddColorStop(0, new Cairo.Color(1, 1, 1, .35));
            lg.AddColorStop(1, new Cairo.Color(1, 1, 1, 0));
            cr.Pattern = lg;
            cr.Fill();
            lg.Destroy();

            // draw outer circles
            cr.LineWidth = 1;
            cr.Arc(center, center, center * RadiusPercent, 0, Math.PI * 2);
            cr.Color = new Cairo.Color(1, 1, 1, .75);
            cr.Stroke();

            cr.LineWidth = 1;
            cr.Arc(center, center, center * RadiusPercent - 1, 0, Math.PI * 2);
            cr.Color = new Cairo.Color(.8, .8, .8, .75);
            cr.Stroke();

            // draw memory indicate
            cr.LineWidth = size / 32.0;
            cr.ArcNegative(center, center, center * RadiusPercent - 1, Math.PI, Math.PI - Math.PI * (2 * MemoryUtilization));
            cr.Color = new Cairo.Color(1, 1, 1, .8);
            cr.Stroke();
        }
コード例 #8
0
        //FIXME: respect damage regions not just the whole areas, and skip more work when possible
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            if (sections.Count == 0)
            {
                return(false);
            }

            var alloc = Allocation;

            int    bw            = (int)BorderWidth;
            double halfLineWidth = borderLineWidth / 2.0;
            int    bw2           = bw * 2;
            int    w             = alloc.Width - bw2;
            int    h             = alloc.Height - bw2;

            using (var cr = CairoHelper.Create(evnt.Window)) {
                CairoHelper.Region(cr, evnt.Region);
                cr.Clip();

                cr.Translate(alloc.X + bw, alloc.Y + bw);

                var borderCol = Convert(Style.Dark(StateType.Normal));
                cr.SetSourceColor(borderCol);
                cr.Rectangle(halfLineWidth, halfLineWidth, w - borderLineWidth, h - borderLineWidth);
                cr.LineWidth = borderLineWidth;
                cr.Stroke();

                cr.Translate(borderLineWidth, borderLineWidth);
                w = w - (2 * borderLineWidth);

                using (LinearGradient unselectedGrad = new LinearGradient(0, 0, 0, headerHeight),
                       hoverGrad = new LinearGradient(0, 0, 0, headerHeight),
                       selectedGrad = new LinearGradient(0, 0, 0, headerHeight)
                       )
                {
                    var unselectedCol     = Convert(Style.Mid(StateType.Normal));
                    var unselectedTextCol = Convert(Style.Text(StateType.Normal));
                    unselectedCol.A = 0.6;
                    unselectedGrad.AddColorStop(0, unselectedCol);
                    unselectedCol.A = 1;
                    unselectedGrad.AddColorStop(1, unselectedCol);

                    var hoverCol     = Convert(Style.Mid(StateType.Prelight));
                    var hoverTextCol = Convert(Style.Text(StateType.Prelight));
                    hoverCol.A = 0.6;
                    hoverGrad.AddColorStop(0, unselectedCol);
                    hoverCol.A = 1;
                    hoverGrad.AddColorStop(1, unselectedCol);

                    var selectedCol     = Convert(Style.Mid(StateType.Normal));
                    var selectedTextCol = Convert(Style.Text(StateType.Normal));
                    selectedCol.A = 0.6;
                    selectedGrad.AddColorStop(0, selectedCol);
                    selectedCol.A = 1;
                    selectedGrad.AddColorStop(1, selectedCol);

                    for (int i = 0; i < sections.Count; i++)
                    {
                        var  section  = sections[i];
                        bool isActive = activeIndex == i;
                        bool isHover  = hoverIndex == i;

                        cr.Rectangle(0, 0, w, headerHeight);
                        cr.SetSource(isActive? selectedGrad : (isHover? hoverGrad : unselectedGrad));
                        cr.Fill();

                        cr.SetSourceColor(isActive? selectedTextCol : (isHover? hoverTextCol : unselectedTextCol));
                        layout.SetText(section.Title);
                        layout.Ellipsize = Pango.EllipsizeMode.End;
                        layout.Width     = (int)((w - headerPadding - headerPadding) * Pango.Scale.PangoScale);
                        cr.MoveTo(headerPadding, headerPadding);
                        Pango.CairoHelper.ShowLayout(cr, layout);

                        cr.MoveTo(-halfLineWidth, i > activeIndex? -halfLineWidth : headerHeight + halfLineWidth);
                        cr.RelLineTo(w + borderLineWidth, 0.0);
                        cr.SetSourceColor(borderCol);
                        cr.Stroke();

                        cr.Translate(0, headerHeight + borderLineWidth);
                        if (isActive)
                        {
                            cr.Translate(0, section.Child.Allocation.Height + borderLineWidth);
                        }
                    }
                }
            }

            PropagateExpose(sections[activeIndex].Child, evnt);
            return(true);           // base.OnExposeEvent (evnt);
        }
コード例 #9
0
ファイル: Block.cs プロジェクト: zeta1999/eithne
        private void DrawBlockGradient(Context c)
        {
            LinearGradient g = new LinearGradient(0, y, 0, y + h);

            if (plugin is Plugin.In)
            {
                g.AddColorStop(0, new Color(0.65, 0.85, 1.00, 0.85));
                g.AddColorStop(0.33, new Color(0.45, 0.65, 1.00, 0.85));
                g.AddColorStop(1, new Color(0.20, 0.50, 0.80, 0.85));
            }
            else if (plugin is Plugin.Out)
            {
                g.AddColorStop(0, new Color(1.00, 0.85, 1.00, 0.85));
                g.AddColorStop(0.33, new Color(1.00, 0.65, 1.00, 0.85));
                g.AddColorStop(1, new Color(0.80, 0.40, 0.80, 0.85));
            }
            else if (plugin is Plugin.ImgProc)
            {
                g.AddColorStop(0, new Color(0.75, 1.00, 0.75, 0.85));
                g.AddColorStop(0.33, new Color(0.55, 1.00, 0.55, 0.85));
                g.AddColorStop(1, new Color(0.30, 0.80, 0.30, 0.85));
            }
            else if (plugin is Plugin.ResProc)
            {
                g.AddColorStop(0, new Color(1.00, 0.75, 0.75, 0.85));
                g.AddColorStop(0.33, new Color(1.00, 0.55, 0.55, 0.85));
                g.AddColorStop(1, new Color(0.80, 0.30, 0.30, 0.85));
            }
            else if (plugin is Plugin.Comparator)
            {
                g.AddColorStop(0, new Color(1.00, 1.00, 0.75, 0.85));
                g.AddColorStop(0.33, new Color(1.00, 1.00, 0.55, 0.85));
                g.AddColorStop(1, new Color(0.80, 0.80, 0.30, 0.85));
            }
            else if (plugin is Plugin.Other)
            {
                g.AddColorStop(0, new Color(0.7, 0.7, 0.7, 0.85));
                g.AddColorStop(0.33, new Color(0.5, 0.5, 0.5, 0.85));
                g.AddColorStop(1, new Color(0.35, 0.35, 0.35, 0.85));
            }

            DrawPath(c);
            c.Pattern = g;
            c.FillPreserve();
        }
コード例 #10
0
ファイル: Tabstrip.cs プロジェクト: tomkcook/monodevelop
        public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.SetSourceColor(parent.Style.Dark(StateType.Normal).ToCairoColor());
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            if (Active || HoverPosition.X >= 0)
            {
                if (Active)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        gr.AddColorStop(0, Tabstrip.ActiveGradientStart);
                        gr.AddColorStop(1, Tabstrip.ActiveGradientEnd);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                    cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5, rectangle.Width - 1, rectangle.Height - 1);
                    cr.SetSourceRGBA(1, 1, 1, 0.05);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
                else if (HoverPosition.X >= 0)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        var c1 = Tabstrip.ActiveGradientStart;
                        var c2 = Tabstrip.ActiveGradientEnd;
                        c1.A = 0.2;
                        c2.A = 0.2;
                        gr.AddColorStop(0, c1);
                        gr.AddColorStop(1, c2);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                }
            }

            if (Active)
            {
                cr.SetSourceRGB(1, 1, 1);
            }
            else
            {
                cr.SetSourceColor(parent.Style.Text(StateType.Normal).ToCairoColor());
            }

            if (layout.Width != (int)rectangle.Width)
            {
                layout.Width = (int)rectangle.Width;
            }

                        #if MAC
            /* On Cocoa, Pango doesn't render text correctly using layout width/height computation.
             * For instance here we need to balance some kind of internal padding by two pixels which
             * only happens on Mac.
             */
            const int verticalOffset = -2;
                        #else
            const int verticalOffset = 0;
                        #endif

            cr.MoveTo(rectangle.X + (int)(rectangle.Width / 2), (rectangle.Height - h) / 2 + verticalOffset);
            Pango.CairoHelper.ShowLayout(cr, layout);
        }
コード例 #11
0
        protected override void ClippedRender(Hyena.Data.Gui.CellContext context)
        {
            if (!EnsureLayout())
            {
                return;
            }

            var cr = context.Context;

            context.Theme.Widget.StyleContext.Save();
            if (context.TextAsForeground)
            {
                context.Theme.Widget.StyleContext.AddClass("button");
            }
            else
            {
                context.Theme.Widget.StyleContext.AddClass("entry");
            }
            Foreground = new Brush(context.Theme.Widget.StyleContext.GetColor(context.State));

            Brush foreground = Foreground;

            if (!foreground.IsValid)
            {
                return;
            }

            cr.Rectangle(0, 0, RenderSize.Width, RenderSize.Height);
            cr.Clip();

            bool fade = Fade && text_alloc.Width > RenderSize.Width;

            if (fade)
            {
                cr.PushGroup();
            }

            Foreground.Apply(cr);
            UpdateLayout(GetText(), RenderSize.Width, RenderSize.Height, true);
            if (Hyena.PlatformDetection.IsWindows)
            {
                // FIXME windows; working around some unknown issue with ShowLayout; bgo#644311

                cr.Antialias = Cairo.Antialias.None;
                PangoCairoHelper.LayoutPath(cr, layout, true);
            }
            else
            {
                PangoCairoHelper.ShowLayout(cr, layout);
            }

            TooltipMarkup = layout.IsEllipsized ? last_formatted_text : null;

            if (fade)
            {
                LinearGradient mask = new LinearGradient(RenderSize.Width - 20, 0, RenderSize.Width, 0);
                mask.AddColorStop(0, new Color(0, 0, 0, 1));
                mask.AddColorStop(1, new Color(0, 0, 0, 0));

                cr.PopGroupToSource();
                cr.Mask(mask);
                mask.Destroy();
            }

            cr.ResetClip();
            context.Theme.Widget.StyleContext.Restore();
        }
コード例 #12
0
        /// <summary>Draws a ribbon.</summary>
        public void DrawRibbon(Context cr, Gdk.Rectangle bodyAllocation, double roundSize, double lineWidth, Ribbon widget)
        {
            double         lineWidth05 = lineWidth / 2;
            double         lineWidth15 = 3 * lineWidth05;
            double         x0, x1, y0, y1;
            LinearGradient linGrad;

            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();

                    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();
                }

                /*** 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();

                /*** 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();

                /*** 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();
            }
        }
コード例 #13
0
        /// <summary>Draws a button.</summary>
        public void DrawButton(Context cr, Rectangle bodyAllocation, ButtonState state, double roundSize, double lineWidth, double arrowSize, double arrowPadding, bool drawSeparator, BaseButton widget)
        {
            double lineWidth05 = lineWidth / 2;
            double lineWidth15 = lineWidth05 * 3;

            bool upLeft = true, upRight = true, downRight = true, downLeft = true;

            switch (widget.GroupStyle)
            {
            case GroupStyle.Left:
                upRight = downRight = false;
                break;

            case GroupStyle.Center:
                upLeft = downLeft = upRight = downRight = false;
                break;

            case GroupStyle.Right:
                upLeft = downLeft = false;
                break;
            }

            cr.LineWidth = lineWidth;

            if (state == ButtonState.Pressed || state == ButtonState.Hover)
            {
                LinearGradient bodyPattern, innerBorderPattern;
                Color          borderColor;

                if (state == ButtonState.Pressed)
                {
                    bodyPattern = new LinearGradient(bodyAllocation.X, bodyAllocation.Y, bodyAllocation.X, bodyAllocation.Y + bodyAllocation.Height);
                    bodyPattern.AddColorStopRgb(0.0, new Color(0.996, 0.847, 0.667));
                    bodyPattern.AddColorStopRgb(0.37, new Color(0.984, 0.710, 0.396));
                    bodyPattern.AddColorStopRgb(0.43, new Color(0.980, 0.616, 0.204));
                    bodyPattern.AddColorStopRgb(1.0, new Color(0.992, 0.933, 0.667));

                    innerBorderPattern = new LinearGradient(bodyAllocation.X, bodyAllocation.Y, bodyAllocation.X + bodyAllocation.Width, bodyAllocation.Y + bodyAllocation.Height);
                    innerBorderPattern.AddColorStop(0.0, new Color(0.876, 0.718, 0.533, 1));
                    innerBorderPattern.AddColorStop(1.0, new Color(0.876, 0.718, 0.533, 0));

                    borderColor = new Color(0.671, 0.631, 0.549);
                }
                else
                {
                    bodyPattern = new LinearGradient(bodyAllocation.X, bodyAllocation.Y, bodyAllocation.X, bodyAllocation.Y + bodyAllocation.Height);
                    bodyPattern.AddColorStopRgb(0.0, new Color(1, 0.996, 0.890));
                    bodyPattern.AddColorStopRgb(0.37, new Color(1, 0.906, 0.592));
                    bodyPattern.AddColorStopRgb(0.43, new Color(1, 0.843, 0.314));
                    bodyPattern.AddColorStopRgb(1.0, new Color(1, 0.906, 0.588));

                    innerBorderPattern = new LinearGradient(bodyAllocation.X, bodyAllocation.Y, bodyAllocation.X + bodyAllocation.Width, bodyAllocation.Y + bodyAllocation.Height);
                    innerBorderPattern.AddColorStop(0.0, new Color(1, 1, 0.969, 1));
                    innerBorderPattern.AddColorStop(1.0, new Color(1, 1, 0.969, 0));

                    borderColor = new Color(0.824, 0.753, 0.553);
                }

                double x0 = bodyAllocation.X + lineWidth05, y0 = bodyAllocation.Y + lineWidth05;
                double x1 = bodyAllocation.X + bodyAllocation.Width - lineWidth05, y1 = bodyAllocation.Y + bodyAllocation.Height - lineWidth05;

                if (upLeft)
                {
                    cr.MoveTo(x0 + roundSize, y0);
                }
                else
                {
                    cr.MoveTo(x0, y0);
                }
                if (upRight)
                {
                    cr.Arc(x1 - roundSize, y0 + roundSize, roundSize, 1.5 * Math.PI, 0);
                }
                else
                {
                    cr.LineTo(x1, y0);
                }
                if (downRight)
                {
                    cr.Arc(x1 - roundSize, y1 - roundSize, roundSize, 0, 0.5 * Math.PI);
                }
                else
                {
                    cr.LineTo(x1, y1);
                }
                if (downLeft)
                {
                    cr.Arc(x0 + roundSize, y1 - roundSize, roundSize, 0.5 * Math.PI, Math.PI);
                }
                else
                {
                    cr.LineTo(x0, y1);
                }
                if (upLeft)
                {
                    cr.Arc(x0 + roundSize, y0 + roundSize, roundSize, Math.PI, 1.5 * Math.PI);
                }
                else
                {
                    cr.LineTo(x0, y0);
                }

                cr.Pattern = bodyPattern;
                cr.Fill();

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

                double roundSizeMinusLineWidth = roundSize - lineWidth;

                if (widget.GroupStyle != GroupStyle.Left)
                {
                    x0 -= lineWidth;
                }

                if (upLeft)
                {
                    cr.MoveTo(x0 + roundSizeMinusLineWidth, y0);
                }
                else
                {
                    cr.MoveTo(x0, y0);
                }
                if (upRight)
                {
                    cr.Arc(x1 - roundSizeMinusLineWidth, y0 + roundSizeMinusLineWidth, roundSizeMinusLineWidth, 1.5 * Math.PI, 0);
                }
                else
                {
                    cr.LineTo(x1, y0);
                }
                if (downRight)
                {
                    cr.Arc(x1 - roundSizeMinusLineWidth, y1 - roundSizeMinusLineWidth, roundSizeMinusLineWidth, 0, 0.5 * Math.PI);
                }
                else
                {
                    cr.LineTo(x1, y1);
                }
                if (downLeft)
                {
                    cr.Arc(x0 + roundSizeMinusLineWidth, y1 - roundSizeMinusLineWidth, roundSizeMinusLineWidth, 0.5 * Math.PI, Math.PI);
                }
                else
                {
                    cr.LineTo(x0, y1);
                }
                if (upLeft)
                {
                    cr.Arc(x0 + roundSizeMinusLineWidth, y0 + roundSizeMinusLineWidth, roundSizeMinusLineWidth, Math.PI, 1.5 * Math.PI);
                }
                else
                {
                    cr.LineTo(x0, y0);
                }

                if (widget.GroupStyle != GroupStyle.Left)
                {
                    x0 += lineWidth;
                }

                cr.Pattern = innerBorderPattern;
                cr.Stroke();

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

                if (upLeft)
                {
                    cr.MoveTo(x0 + roundSize, y0);
                }
                else
                {
                    cr.MoveTo(x0, y0);
                }
                if (upRight)
                {
                    cr.Arc(x1 - roundSize, y0 + roundSize, roundSize, 1.5 * Math.PI, 0);
                }
                else
                {
                    cr.LineTo(x1, y0);
                }
                if (downRight)
                {
                    cr.Arc(x1 - roundSize, y1 - roundSize, roundSize, 0, 0.5 * Math.PI);
                }
                else
                {
                    cr.LineTo(x1, y1);
                }
                if (downLeft)
                {
                    cr.Arc(x0 + roundSize, y1 - roundSize, roundSize, 0.5 * Math.PI, Math.PI);
                }
                else
                {
                    cr.LineTo(x0, y1);
                }
                if (widget.GroupStyle == GroupStyle.Left)
                {
                    if (upLeft)
                    {
                        cr.Arc(x0 + roundSize, y0 + roundSize, roundSize, Math.PI, 1.5 * Math.PI);
                    }
                    else
                    {
                        cr.LineTo(x0, y0);
                    }
                }

                cr.Color = borderColor;
                cr.Stroke();
            }
            else if (widget.DrawBackground)
            {
                LinearGradient bodyPattern = new LinearGradient(bodyAllocation.X, bodyAllocation.Y, bodyAllocation.X, bodyAllocation.Y + bodyAllocation.Height);
                bodyPattern.AddColorStop(0.0, new Color(1, 1, 1, 0.7));
                bodyPattern.AddColorStop(0.37, new Color(1, 1, 1, 0.2));
                bodyPattern.AddColorStop(0.43, new Color(1, 1, 1, 0.2));
                bodyPattern.AddColorStop(1.0, new Color(1, 1, 1, 0.7));

                double x0 = bodyAllocation.X + lineWidth05, y0 = bodyAllocation.Y + lineWidth05;
                double x1 = bodyAllocation.X + bodyAllocation.Width - lineWidth05, y1 = bodyAllocation.Y + bodyAllocation.Height - lineWidth05;

                if (upLeft)
                {
                    cr.MoveTo(x0 + roundSize, y0);
                }
                else
                {
                    cr.MoveTo(x0, y0);
                }
                if (upRight)
                {
                    cr.Arc(x1 - roundSize, y0 + roundSize, roundSize, 1.5 * Math.PI, 0);
                }
                else
                {
                    cr.LineTo(x1, y0);
                }
                if (downRight)
                {
                    cr.Arc(x1 - roundSize, y1 - roundSize, roundSize, 0, 0.5 * Math.PI);
                }
                else
                {
                    cr.LineTo(x1, y1);
                }
                if (downLeft)
                {
                    cr.Arc(x0 + roundSize, y1 - roundSize, roundSize, 0.5 * Math.PI, Math.PI);
                }
                else
                {
                    cr.LineTo(x0, y1);
                }
                if (upLeft)
                {
                    cr.Arc(x0 + roundSize, y0 + roundSize, roundSize, Math.PI, 1.5 * Math.PI);
                }
                else
                {
                    cr.LineTo(x0, y0);
                }

                cr.Pattern = bodyPattern;
                cr.Fill();

                if (widget.GroupStyle != GroupStyle.Left)
                {
                    if (downLeft)
                    {
                        cr.Arc(x0 + roundSize, y1 - roundSize, roundSize, 0.5 * Math.PI, Math.PI);
                    }
                    else
                    {
                        cr.MoveTo(x0, y1);
                    }
                    if (upLeft)
                    {
                        cr.Arc(x0 + roundSize, y0 + roundSize, roundSize, Math.PI, 1.5 * Math.PI);
                    }
                    else
                    {
                        cr.LineTo(x0, y0);
                    }

                    cr.Color = new Color(1, 1, 1, 0.8);
                    cr.Stroke();
                }

                if (upLeft)
                {
                    cr.Arc(x0 + roundSize, y0 + roundSize, roundSize, Math.PI, 1.5 * Math.PI);
                }
                else
                {
                    cr.MoveTo(x0, y0);
                }
                if (upRight)
                {
                    cr.Arc(x1 - roundSize, y0 + roundSize, roundSize, 1.5 * Math.PI, 0);
                }
                else
                {
                    cr.LineTo(x1, y0);
                }
                if (downRight)
                {
                    cr.Arc(x1 - roundSize, y1 - roundSize, roundSize, 0, 0.5 * Math.PI);
                }
                else
                {
                    cr.LineTo(x1, y1);
                }
                if (downLeft)
                {
                    cr.Arc(x0 + roundSize, y1 - roundSize, roundSize, 0.5 * Math.PI, Math.PI);
                }
                else
                {
                    cr.LineTo(x0, y1);
                }
                if (widget.GroupStyle == GroupStyle.Left)
                {
                    if (upLeft)
                    {
                        cr.LineTo(x0, y0 + roundSize);
                    }
                    else
                    {
                        cr.LineTo(x0, y0);
                    }
                }

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

            if (arrowSize > 0)
            {
                double x, y;

                switch (widget.ImagePosition)
                {
                case Gtk.PositionType.Bottom:
                case Gtk.PositionType.Top:
                    x = bodyAllocation.X + (bodyAllocation.Width - arrowSize) / 2.0;
                    y = bodyAllocation.Y + bodyAllocation.Height - 2 * lineWidth - arrowSize - 2 * arrowPadding;

                    if (drawSeparator)
                    {
                        double left = bodyAllocation.X + 2 * lineWidth, right = bodyAllocation.X + bodyAllocation.Width - 2 * lineWidth;

                        cr.MoveTo(left, y - lineWidth / 2);
                        cr.LineTo(right, y - lineWidth / 2);
                        cr.Color = new Color(0, 0, 0, 0.1);
                        cr.Stroke();

                        cr.MoveTo(left, y + lineWidth / 2);
                        cr.LineTo(right, y + lineWidth / 2);
                        cr.Color = new Color(1, 1, 1, 0.6);
                        cr.Stroke();
                    }

                    y += arrowPadding;
                    break;

                default:
                    x = bodyAllocation.X + bodyAllocation.Width - 2 * lineWidth - arrowSize - 2 * arrowPadding;
                    y = bodyAllocation.Y + (bodyAllocation.Height - arrowSize) / 2.0;

                    if (drawSeparator)
                    {
                        double top = bodyAllocation.Y + 2 * lineWidth, bottom = bodyAllocation.Y + bodyAllocation.Height - 2 * lineWidth;
                        cr.MoveTo(x - lineWidth / 2, top);
                        cr.LineTo(x - lineWidth / 2, bottom);
                        cr.Color = new Color(0, 0, 0, 0.1);
                        cr.Stroke();

                        cr.MoveTo(x + lineWidth / 2, top);
                        cr.LineTo(x + lineWidth / 2, bottom);
                        cr.Color = new Color(1, 1, 1, 0.6);
                        cr.Stroke();
                    }

                    x += arrowPadding;
                    break;
                }

                y += arrowSize / 4.0 + lineWidth / 2.0;
                cr.MoveTo(x, y);
                cr.LineTo(x + arrowSize, y);
                cr.LineTo(x + arrowSize / 2.0, y + arrowSize / 2.0);
                cr.LineTo(x, y);
                cr.Color = new Color(0, 0, 0);
                cr.Fill();
            }
        }
コード例 #14
0
        /// <summary>Draws a group.</summary>
        internal void DrawGroup(Context cr, Rectangle r, double roundSize, double lineWidth, double space, Pango.Layout l, Gtk.Widget expandButton, RibbonGroup w)
        {
            double         lineWidth05 = lineWidth / 2, lineWidth15 = 3 * lineWidth05;
            LinearGradient linGrad;

            double x0 = r.X + roundSize, x1 = r.X + r.Width - roundSize;
            double y0 = r.Y + roundSize, y1 = r.Y + r.Height - roundSize;

            cr.Arc(x1, y1, roundSize - lineWidth05, 0, Math.PI / 2);
            cr.Arc(x0 + lineWidth, y1, roundSize - lineWidth05, Math.PI / 2, Math.PI);
            cr.Arc(x0, y0, roundSize - lineWidth15, Math.PI, 3 * Math.PI / 2);
            cr.Arc(x1, y0 + lineWidth, roundSize - lineWidth05, 3 * Math.PI / 2, 0);
            cr.LineTo(x1 + roundSize - lineWidth05, y1);
            cr.LineWidth = lineWidth;
            cr.Color     = colorScheme.Bright;
            cr.Stroke();

            if (l != null)
            {
                int lblWidth, lblHeight;
                Pango.CairoHelper.UpdateLayout(cr, l);
                l.GetPixelSize(out lblWidth, out lblHeight);

                double bandHeight = lblHeight + 2 * space;
                cr.Arc(x1, y1, roundSize - lineWidth15, 0, Math.PI / 2);
                cr.Arc(x0, y1 - lineWidth, roundSize - lineWidth05, Math.PI / 2, Math.PI);
                double bandY = y1 + roundSize - 2 * lineWidth - bandHeight;
                cr.LineTo(x0 - roundSize + lineWidth05, bandY);
                cr.LineTo(x1 + roundSize - lineWidth15, bandY);
                linGrad = new LinearGradient(0, bandY, 0, bandY + bandHeight);
                linGrad.AddColorStop(0.0, colorScheme.Dark);
                linGrad.AddColorStop(1.0, colorScheme.PrettyDark);
                cr.Pattern = linGrad;
                cr.Fill();

                double frameSize = 2 * lineWidth + space;
                double availableHorizontalSpace = r.Width - 2 * frameSize;
                if (expandButton.Visible)
                {
                    availableHorizontalSpace -= expandButton.WidthRequest + space;
                }

                cr.Save();
                cr.Rectangle(r.X + frameSize, bandY, availableHorizontalSpace, bandHeight);
                cr.Clip();

                cr.Color = new Color(1, 1, 1);
                Pango.CairoHelper.UpdateLayout(cr, l);
                cr.MoveTo(r.X + frameSize + Math.Max(0, (availableHorizontalSpace - lblWidth) / 2), bandY + space);
                Pango.CairoHelper.ShowLayout(cr, l);

                cr.Restore();
            }

            cr.MoveTo(x1 + roundSize - lineWidth15, y1);
            cr.Arc(x1, y1, roundSize - lineWidth15, 0, Math.PI / 2);
            cr.Arc(x0, y1 - lineWidth, roundSize - lineWidth05, Math.PI / 2, Math.PI);
            cr.Arc(x0, y0, roundSize - lineWidth05, Math.PI, 3 * Math.PI / 2);
            cr.Arc(x1 - lineWidth, y0, roundSize - lineWidth05, 3 * Math.PI / 2, 0);
            cr.LineTo(x1 + roundSize - lineWidth15, y1);
            cr.LineWidth = lineWidth;
            linGrad      = new LinearGradient(0, r.Y, 0, r.Y + r.Height - lineWidth);
            linGrad.AddColorStop(0.0, ColorScheme.GetColorRelative(colorScheme.PrettyDark, 0.1));
            linGrad.AddColorStop(1.0, colorScheme.PrettyDark);
            cr.Pattern = linGrad;
            cr.Stroke();
        }
コード例 #15
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            if (evnt.Window != GdkWindow)
            {
                return(base.OnExposeEvent(evnt));
            }

            Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window);

            if (reflect)
            {
                CairoExtensions.PushGroup(cr);
            }

            cr.Operator = Operator.Over;
            cr.Translate(Allocation.X + h_padding, Allocation.Y);
            cr.Rectangle(0, 0, Allocation.Width - h_padding, Math.Max(2 * bar_height,
                                                                      bar_height + bar_label_spacing + layout_height));
            cr.Clip();

            Pattern bar = RenderBar(Allocation.Width - 2 * h_padding, bar_height);

            cr.Save();
            cr.SetSource(bar);
            cr.Paint();
            cr.Restore();

            if (reflect)
            {
                cr.Save();

                cr.Rectangle(0, bar_height, Allocation.Width - h_padding, bar_height);
                cr.Clip();

                Matrix matrix = new Matrix();
                matrix.InitScale(1, -1);
                matrix.Translate(0, -(2 * bar_height) + 1);
                cr.Transform(matrix);

                cr.SetSource(bar);

                LinearGradient mask = new LinearGradient(0, 0, 0, bar_height);

                mask.AddColorStop(0.25, new Color(0, 0, 0, 0));
                mask.AddColorStop(0.5, new Color(0, 0, 0, 0.125));
                mask.AddColorStop(0.75, new Color(0, 0, 0, 0.4));
                mask.AddColorStop(1.0, new Color(0, 0, 0, 0.7));

                cr.Mask(mask);
                mask.Dispose();

                cr.Restore();

                CairoExtensions.PopGroupToSource(cr);
                cr.Paint();
            }

            if (show_labels)
            {
                cr.Translate((reflect ? Allocation.X : -h_padding) + (Allocation.Width - layout_width) / 2,
                             (reflect ? Allocation.Y : 0) + bar_height + bar_label_spacing);

                RenderLabels(cr);
            }

            bar.Dispose();
            CairoExtensions.DisposeContext(cr);

            return(true);
        }
コード例 #16
0
        void PaintProgressSurface(DockySurface surface)
        {
            if (Progress <= 0)
            {
                return;
            }

            double padding = 2.0;
            double width   = surface.Width - 2 * padding;
            double height  = Math.Min(26.0, 0.18 * surface.Height);
            double x       = padding;
            double y       = surface.Height - height - padding;

            double lineSize = 1.0;

            surface.Context.LineWidth = lineSize;

            // draw the outer stroke
            x      += lineSize / 2.0;
            y      += lineSize / 2.0;
            width  -= lineSize;
            height -= lineSize;

            LinearGradient outer_stroke = new LinearGradient(0, y, 0, y + height);

            outer_stroke.AddColorStop(0, new Cairo.Color(0, 0, 0, 0.3));
            outer_stroke.AddColorStop(1, new Cairo.Color(1, 1, 1, 0.3));

            DrawRoundedLine(surface, x, y, width, height, true, true, outer_stroke, null);
            outer_stroke.Destroy();

            // draw the finished stroke/fill
            x      += lineSize;
            y      += lineSize;
            width  -= 2 * lineSize;
            height -= 2 * lineSize;
            double finishedWidth = Progress * width - lineSize / 2.0;

            LinearGradient finished_stroke = new LinearGradient(0, y, 0, y + height);

            finished_stroke.AddColorStop(0, new Cairo.Color(67 / 255.0, 165 / 255.0, 226 / 255.0, 1));
            finished_stroke.AddColorStop(1, new Cairo.Color(32 / 255.0, 94 / 255.0, 136 / 255.0, 1));
            LinearGradient finished_fill = new LinearGradient(0, y, 0, y + height);

            finished_fill.AddColorStop(0, new Cairo.Color(91 / 255.0, 174 / 255.0, 226 / 255.0, 1));
            finished_fill.AddColorStop(1, new Cairo.Color(35 / 255.0, 115 / 255.0, 164 / 255.0, 1));

            DrawRoundedLine(surface, x, y, finishedWidth, height, true, false, finished_stroke, finished_fill);
            finished_stroke.Destroy();
            finished_fill.Destroy();

            // draw the remaining stroke/fill
            LinearGradient remaining_stroke = new LinearGradient(0, y, 0, y + height);

            remaining_stroke.AddColorStop(0, new Cairo.Color(82 / 255.0, 82 / 255.0, 82 / 255.0, 1));
            remaining_stroke.AddColorStop(1, new Cairo.Color(148 / 255.0, 148 / 255.0, 148 / 255.0, 1));
            LinearGradient remaining_fill = new LinearGradient(0, y, 0, y + height);

            remaining_fill.AddColorStop(0, new Cairo.Color(106 / 255.0, 106 / 255.0, 106 / 255.0, 1));
            remaining_fill.AddColorStop(1, new Cairo.Color(159 / 255.0, 159 / 255.0, 159 / 255.0, 1));

            DrawRoundedLine(surface, x + finishedWidth + lineSize, y, width - finishedWidth, height, false, true, remaining_stroke, remaining_fill);
            remaining_stroke.Destroy();
            remaining_fill.Destroy();

            // draw the highlight on the finished part
            x      += lineSize;
            y      += lineSize;
            width  -= lineSize;
            height -= 2 * lineSize;

            LinearGradient finished_highlight = new LinearGradient(0, y, 0, y + height);

            finished_highlight.AddColorStop(0, new Cairo.Color(1, 1, 1, 0.3));
            finished_highlight.AddColorStop(0.2, new Cairo.Color(1, 1, 1, 0));

            DrawRoundedLine(surface, x, y, finishedWidth, height, true, false, finished_highlight, null);
            finished_highlight.Destroy();
        }
コード例 #17
0
        void DrawTab(Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la)
        {
            // This logic is stupid to have here, should be in the caller!
            if (dragging)
            {
                tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress);
                tabBounds.X = Clamp(tabBounds.X, tabStartX, tabEndX - tabBounds.Width);
            }
            double rightPadding = (active ? TabActivePadding.Right : TabPadding.Right) - (LeanWidth / 2);

            rightPadding = (rightPadding * Math.Min(1.0, Math.Max(0.5, (tabBounds.Width - 30) / 70.0)));
            double leftPadding = (active ? TabActivePadding.Left : TabPadding.Left) - (LeanWidth / 2);

            leftPadding = (leftPadding * Math.Min(1.0, Math.Max(0.5, (tabBounds.Width - 30) / 70.0)));
            double bottomPadding = active ? TabActivePadding.Bottom : TabPadding.Bottom;

            DrawTabBackground(this, ctx, allocation, tabBounds.Width, tabBounds.X, active);

            ctx.LineWidth = 1;
            ctx.NewPath();

            // Render Close Button (do this first so we can tell how much text to render)

            var closeButtonAlloation = new Cairo.Rectangle(tabBounds.Right - rightPadding - (tabCloseImage.Width / 2) - CloseButtonMarginRight,
                                                           tabBounds.Height - bottomPadding - tabCloseImage.Height - CloseButtonMarginBottom,
                                                           tabCloseImage.Width, tabCloseImage.Height);

            tab.CloseButtonActiveArea = closeButtonAlloation.Inflate(2, 2);

            bool closeButtonHovered = tracker.Hovered && tab.CloseButtonActiveArea.Contains(tracker.MousePosition);
            bool tabHovered         = tracker.Hovered && tab.Allocation.Contains(tracker.MousePosition);
            bool drawCloseButton    = active || tabHovered;

            if (!closeButtonHovered && tab.DirtyStrength > 0.5)
            {
                ctx.DrawImage(this, tabDirtyImage, closeButtonAlloation.X, closeButtonAlloation.Y);
                drawCloseButton = false;
            }

            if (drawCloseButton)
            {
                ctx.DrawImage(this, tabCloseImage.WithAlpha((closeButtonHovered ? 1.0 : 0.5) * tab.Opacity), closeButtonAlloation.X, closeButtonAlloation.Y);
            }

            // Render Text
            double tw = tabBounds.Width - (leftPadding + rightPadding);

            if (drawCloseButton || tab.DirtyStrength > 0.5)
            {
                tw -= closeButtonAlloation.Width / 2;
            }

            double tx       = tabBounds.X + leftPadding;
            var    baseline = la.GetLine(0).Layout.GetPixelBaseline();
            double ty       = tabBounds.Height - bottomPadding - baseline;

            ctx.MoveTo(tx, ty);
            if (!MonoDevelop.Core.Platform.IsMac && !MonoDevelop.Core.Platform.IsWindows)
            {
                // This is a work around for a linux specific problem.
                // A bug in the proprietary ATI driver caused TAB text not to draw.
                // If that bug get's fixed remove this HACK asap.
                la.Ellipsize = Pango.EllipsizeMode.End;
                la.Width     = (int)(tw * Pango.Scale.PangoScale);
                ctx.SetSourceColor((tab.Notify ? Styles.TabBarNotifyTextColor : (active ? Styles.TabBarActiveTextColor : Styles.TabBarInactiveTextColor)).ToCairoColor());
                Pango.CairoHelper.ShowLayout(ctx, la.GetLine(0).Layout);
            }
            else
            {
                // ellipses are for space wasting ..., we cant afford that
                using (var lg = new LinearGradient(tx + tw - 10, 0, tx + tw, 0)) {
                    var color = (tab.Notify ? Styles.TabBarNotifyTextColor : (active ? Styles.TabBarActiveTextColor : Styles.TabBarInactiveTextColor)).ToCairoColor();
                    color = color.MultiplyAlpha(tab.Opacity);
                    lg.AddColorStop(0, color);
                    color.A = 0;
                    lg.AddColorStop(1, color);
                    ctx.SetSource(lg);
                    Pango.CairoHelper.ShowLayout(ctx, la.GetLine(0).Layout);
                }
            }
            la.Dispose();
        }
コード例 #18
0
        public override void DrawBackground(Mono.TextEditor.MonoTextEditor editor, Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            int markerStart = usage.Offset;
            int markerEnd   = usage.EndOffset;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            double @from;
            double to;
            var    startXPos = metrics.TextRenderStartPosition;
            var    endXPos   = metrics.TextRenderEndPosition;
            var    y         = metrics.LineYRenderStartPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;

                uint curIndex = 0, byteIndex = 0;
                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

                int x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
                x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            @from = Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from < to)
            {
                Mono.TextEditor.Highlighting.AmbientColor colorStyle;
                if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write ||
                    (usage.UsageType & ReferenceUsageType.Declariton) == ReferenceUsageType.Declariton)
                {
                    colorStyle = editor.ColorStyle.ChangingUsagesRectangle;
                }
                else
                {
                    colorStyle = editor.ColorStyle.UsagesRectangle;
                }

                using (var lg = new LinearGradient(@from + 1, y + 1, to, y + editor.LineHeight)) {
                    lg.AddColorStop(0, colorStyle.Color);
                    lg.AddColorStop(1, colorStyle.SecondColor);
                    cr.SetSource(lg);
                    cr.RoundedRectangle(@from + 0.5, y + 1.5, to - @from - 1, editor.LineHeight - 2, editor.LineHeight / 4);
                    cr.FillPreserve();
                }

                cr.SetSourceColor(colorStyle.BorderColor);
                cr.Stroke();
            }
        }
コード例 #19
0
            public override bool DrawBackground(TextEditor editor, Context cr, double y, LineMetrics metrics)
            {
                if (metrics.SelectionStart >= 0 || editor.CurrentMode is TextLinkEditMode || editor.TextViewMargin.SearchResultMatchCount > 0)
                {
                    return(false);
                }
                foreach (var usage in Usages)
                {
                    int markerStart = usage.TextSegment.Offset;
                    int markerEnd   = usage.TextSegment.EndOffset;

                    if (markerEnd < metrics.TextStartOffset || markerStart > metrics.TextEndOffset)
                    {
                        return(false);
                    }

                    double @from;
                    double to;

                    if (markerStart < metrics.TextStartOffset && metrics.TextEndOffset < markerEnd)
                    {
                        @from = metrics.TextRenderStartPosition;
                        to    = metrics.TextRenderEndPosition;
                    }
                    else
                    {
                        int start = metrics.TextStartOffset < markerStart ? markerStart : metrics.TextStartOffset;
                        int end   = metrics.TextEndOffset < markerEnd ? metrics.TextEndOffset : markerEnd;

                        uint curIndex = 0, byteIndex = 0;
                        TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(start - metrics.TextStartOffset), ref curIndex, ref byteIndex);

                        int x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                        @from = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);

                        TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(end - metrics.TextStartOffset), ref curIndex, ref byteIndex);
                        x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                        to = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);
                    }

                    @from = Math.Max(@from, editor.TextViewMargin.XOffset);
                    to    = Math.Max(to, editor.TextViewMargin.XOffset);
                    if (@from < to)
                    {
                        Mono.TextEditor.Highlighting.AmbientColor colorStyle;
                        if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write)
                        {
                            colorStyle = editor.ColorStyle.ChangingUsagesRectangle;
                        }
                        else
                        {
                            colorStyle = editor.ColorStyle.UsagesRectangle;
                        }

                        using (var lg = new LinearGradient(@from + 1, y + 1, to, y + editor.LineHeight)) {
                            lg.AddColorStop(0, colorStyle.Color);
                            lg.AddColorStop(1, colorStyle.SecondColor);
                            cr.SetSource(lg);
                            cr.RoundedRectangle(@from + 0.5, y + 1.5, to - @from - 1, editor.LineHeight - 2, editor.LineHeight / 4);
                            cr.FillPreserve();
                        }

                        cr.SetSourceColor(colorStyle.BorderColor);
                        cr.Stroke();
                    }
                }
                return(true);
            }
コード例 #20
0
        /// <summary>
        /// Draw the the PlotSurface and contents (axes, drawables, and legend) using the
        /// Drawing Context supplied and the bounding rectangle for the PlotSurface to cover
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw.</param>
        /// <param name="bounds">The rectangle within which to draw</param>
        public void Draw(Context ctx, Rectangle bounds)
        {
            Point titleOrigin = Point.Zero;

            ctx.Save();

            // determine font sizes and tick scale factor.
            double scale = DetermineScaleFactor(bounds.Width, bounds.Height);

            // if there is nothing to plot, draw title and return.
            if (drawables.Count == 0)
            {
                // draw title
                //TODO: Title should be centred here - not its origin
                Point origin = Point.Zero;
                titleOrigin.X = bounds.Width / 2;
                titleOrigin.Y = bounds.Height / 2;
                DrawTitle(ctx, titleOrigin, scale);
                ctx.Restore();
                return;
            }

            // determine the [non physical] axes to draw based on the axis properties set.
            Axis XAxis1 = null;
            Axis XAxis2 = null;
            Axis YAxis1 = null;
            Axis YAxis2 = null;

            DetermineAxesToDraw(out XAxis1, out XAxis2, out YAxis1, out YAxis2);

            // apply scale factor to axes as desired.

            if (XAxis1.AutoScaleTicks)
            {
                XAxis1.TickScale = scale;
            }
            if (XAxis1.AutoScaleText)
            {
                XAxis1.FontScale = scale;
            }
            if (YAxis1.AutoScaleTicks)
            {
                YAxis1.TickScale = scale;
            }
            if (YAxis1.AutoScaleText)
            {
                YAxis1.FontScale = scale;
            }
            if (XAxis2.AutoScaleTicks)
            {
                XAxis2.TickScale = scale;
            }
            if (XAxis2.AutoScaleText)
            {
                XAxis2.FontScale = scale;
            }
            if (YAxis2.AutoScaleTicks)
            {
                YAxis2.TickScale = scale;
            }
            if (YAxis2.AutoScaleText)
            {
                YAxis2.FontScale = scale;
            }

            // determine the default physical positioning of those axes.
            PhysicalAxis pXAxis1 = null;
            PhysicalAxis pYAxis1 = null;
            PhysicalAxis pXAxis2 = null;
            PhysicalAxis pYAxis2 = null;

            DeterminePhysicalAxesToDraw(
                bounds, XAxis1, XAxis2, YAxis1, YAxis2,
                out pXAxis1, out pXAxis2, out pYAxis1, out pYAxis2);

            double oldXAxis2Height = pXAxis2.PhysicalMin.Y;

            // Apply axes constraints
            for (int i = 0; i < axesConstraints.Count; ++i)
            {
                ((AxesConstraint)axesConstraints[i]).ApplyConstraint(
                    pXAxis1, pYAxis1, pXAxis2, pYAxis2);
            }

            // draw legend if have one.
            // Note: this will update axes if necessary.
            Point legendPosition = new Point(0, 0);

            if (legend != null)
            {
                legend.UpdateAxesPositions(
                    pXAxis1, pYAxis1, pXAxis2, pYAxis2,
                    drawables, scale, Padding, bounds,
                    out legendPosition);
            }

            double newXAxis2Height  = pXAxis2.PhysicalMin.Y;
            double titleExtraOffset = oldXAxis2Height - newXAxis2Height;

            // now we are ready to define the clipping region
            plotAreaBoundingBoxCache = new Rectangle(
                Math.Min(pXAxis1.PhysicalMin.X, pXAxis1.PhysicalMax.X),
                Math.Min(pYAxis1.PhysicalMax.Y, pYAxis1.PhysicalMin.Y),
                Math.Abs(pXAxis1.PhysicalMax.X - pXAxis1.PhysicalMin.X + 1),
                Math.Abs(pYAxis1.PhysicalMin.Y - pYAxis1.PhysicalMax.Y + 1)
                );
            bbXAxis1Cache = pXAxis1.GetBoundingBox();
            bbXAxis2Cache = pXAxis2.GetBoundingBox();
            bbYAxis1Cache = pYAxis1.GetBoundingBox();
            bbYAxis2Cache = pYAxis2.GetBoundingBox();

            Rectangle plotBounds = (Rectangle)plotAreaBoundingBoxCache;

            // set the clipping region.. (necessary for zoom)
            // Note: although clipping is enforced by the clip region, it is probably more efficient
            // for each Drawable to check against the plotBounds and not draw if points are outside.
            // This hasn't yet been implemented
            ctx.Save();
            ctx.Rectangle(plotBounds);
            ctx.Clip();

            // Fill in the plot background.
            if (plotBackImage != null)
            {
                // Ensure plotBounds has integer size for correct tiling/drawing
                plotBounds.Width  = Math.Truncate(plotBounds.Width);
                plotBounds.Height = Math.Truncate(plotBounds.Height);
                ctx.DrawImage(Utils.TiledImage(plotBackImage, plotBounds.Size), plotBounds);
            }
            else if (plotBackGradient != null)
            {
                // Scale plotBackGradient to plotBounds
                double         startX = plotBounds.X + (plotBackGradient.StartPoint.X * plotBounds.Width);
                double         startY = plotBounds.Y + (plotBackGradient.StartPoint.Y * plotBounds.Height);
                double         endX   = plotBounds.X + (plotBackGradient.EndPoint.X * plotBounds.Width);
                double         endY   = plotBounds.Y + (plotBackGradient.EndPoint.Y * plotBounds.Height);
                LinearGradient g      = new LinearGradient(startX, startY, endX, endY);
                g.AddColorStop(0, plotBackGradient.StartColor);
                g.AddColorStop(1, plotBackGradient.EndColor);
                ctx.Rectangle(plotBounds);
                ctx.Pattern = g;
                ctx.Fill();
            }
            else
            {
                ctx.Rectangle(plotBounds);
                ctx.SetColor(plotBackColor);
                ctx.Fill();
            }

            // draw title at centre of Physical X-axis and at top of plot

            titleOrigin.X = (pXAxis2.PhysicalMax.X + pXAxis2.PhysicalMin.X) / 2.0;
            titleOrigin.Y = bounds.Top + Padding - titleExtraOffset;
            Size s = DrawTitle(ctx, titleOrigin, scale);

            bbTitleCache = new Rectangle(titleOrigin.X - s.Width / 2, titleOrigin.Y, s.Width, s.Height);

            // draw drawables..
            bool legendDrawn = false;

            for (int i_o = 0; i_o < ordering.Count; ++i_o)
            {
                int    i      = (int)ordering.GetByIndex(i_o);
                double zOrder = (double)ordering.GetKey(i_o);
                if (zOrder > legendZOrder)
                {
                    // draw legend.
                    if (!legendDrawn && legend != null)
                    {
                        legend.Draw(ctx, legendPosition, drawables, scale);
                        legendDrawn = true;
                    }
                }

                IDrawable     drawable = (IDrawable)drawables[i];
                XAxisPosition xap      = (XAxisPosition)xAxisPositions[i];
                YAxisPosition yap      = (YAxisPosition)yAxisPositions[i];

                PhysicalAxis drawXAxis;
                PhysicalAxis drawYAxis;

                if (xap == XAxisPosition.Bottom)
                {
                    drawXAxis = pXAxis1;
                }
                else
                {
                    drawXAxis = pXAxis2;
                }

                if (yap == YAxisPosition.Left)
                {
                    drawYAxis = pYAxis1;
                }
                else
                {
                    drawYAxis = pYAxis2;
                }

                drawable.Draw(ctx, drawXAxis, drawYAxis);
            }

            if (!legendDrawn && legend != null)
            {
                legend.Draw(ctx, legendPosition, drawables, scale);
            }

            ctx.Restore();                      // end of clipping region

            // cache the physical axes we used on this draw;
            pXAxis1Cache = pXAxis1;
            pYAxis1Cache = pYAxis1;
            pXAxis2Cache = pXAxis2;
            pYAxis2Cache = pYAxis2;

            // now draw axes.
            Rectangle axisBounds;

            pXAxis1.Draw(ctx, out axisBounds);
            pXAxis2.Draw(ctx, out axisBounds);
            pYAxis1.Draw(ctx, out axisBounds);
            pYAxis2.Draw(ctx, out axisBounds);

#if DEBUG_BOUNDING_BOXES
            ctx.SetColor(Colors.Orange);
            ctx.Rectangle((Rectangle)bbXAxis1Cache);
            ctx.Rectangle((Rectangle)bbXAxis2Cache);
            ctx.Rectangle((Rectangle)bbYAxis1Cache);
            ctx.Rectangle((Rectangle)bbYAxis2Cache);
            ctx.Stroke();
            ctx.SetColor(Colors.Red);
            ctx.Rectangle((Rectangle)plotAreaBoundingBoxCache);
            ctx.Rectangle((Rectangle)bbTitleCache);
            ctx.Stroke();
#endif
            ctx.Restore();
        }
コード例 #21
0
        /// <summary>
        /// Recomposes a multi-line message.
        /// </summary>
        /// <param name="versionnumber">The version number of the new version.</param>
        public void RecomposeMultiLine(string versionnumber)
        {
            text = Lang.Get("Version {0} now available \\o/\nClick here to go to the downloads page", versionnumber);

            Bounds.fixedHeight = GetMultilineTextHeight() / RuntimeEnv.GUIScale;
            Bounds.CalcWorldBounds();

            offsetY = -2 * Bounds.fixedHeight;

            ImageSurface surface = new ImageSurface(Format.Argb32, (int)Bounds.OuterWidth, (int)Bounds.OuterHeight + shadowHeight);
            Context      ctx     = genContext(surface);

            double iconX    = scaled(15);
            double iconSize = scaled(14);
            double iconY    = (Bounds.InnerHeight - iconSize) / 2;

            double[] bgc = GuiStyle.DarkBrownColor;
            bgc[0] /= 2;
            bgc[1] /= 2;
            bgc[2] /= 2;
            LinearGradient gradient = new LinearGradient(0, Bounds.OuterHeightInt, 0, Bounds.OuterHeightInt + 10);

            gradient.AddColorStop(0, new Color(bgc[0], bgc[1], bgc[2], 1));
            gradient.AddColorStop(1, new Color(bgc[0], bgc[1], bgc[2], 0));
            ctx.SetSource(gradient);
            ctx.Rectangle(0, Bounds.OuterHeightInt, Bounds.OuterWidthInt, Bounds.OuterHeightInt + 10);
            ctx.Fill();
            gradient.Dispose();


            gradient = new LinearGradient(0, 0, Bounds.OuterWidth, 0);
            gradient.AddColorStop(0, new Color(backColor[0], backColor[1], backColor[2], 1));
            gradient.AddColorStop(0.99, new Color(backColor[0], backColor[1], backColor[2], 1));
            gradient.AddColorStop(1, new Color(backColor[0], backColor[1], backColor[2], 0));
            ctx.SetSource(gradient);
            ctx.Rectangle(0, 0, Bounds.OuterWidthInt, Bounds.OuterHeightInt);
            ctx.Fill();
            gradient.Dispose();

            ctx.Arc(Bounds.drawX + iconX, Bounds.OuterHeight / 2, iconSize / 2 + scaled(4), 0, Math.PI * 2);
            ctx.SetSourceRGBA(GuiStyle.DarkBrownColor);
            ctx.Fill();

            double fontheight = Font.GetFontExtents().Height;

            byte[]         pngdata = api.Assets.Get("textures/gui/newversion.png").Data;
            BitmapExternal bitmap  = (BitmapExternal)api.Render.BitmapCreateFromPng(pngdata);

            surface.Image(bitmap.bmp, (int)(Bounds.drawX + iconX - iconSize / 2), (int)(Bounds.drawY + iconY), (int)iconSize, (int)iconSize);
            bitmap.Dispose();

            DrawMultilineTextAt(ctx, Bounds.drawX + iconX + 20, Bounds.drawY);

            generateTexture(surface, ref texture);
            ctx.Dispose();
            surface.Dispose();


            surface = new ImageSurface(Format.Argb32, (int)Bounds.OuterWidth, (int)Bounds.OuterHeight);
            ctx     = genContext(surface);

            ctx.SetSourceRGBA(1, 1, 1, 0.1);
            ctx.Paint();

            generateTexture(surface, ref hoverTexture);

            ctx.Dispose();
            surface.Dispose();
        }
コード例 #22
0
        public void Render(Cairo.Context context, StatusArea.RenderArg arg)
        {
            context.CachedDraw(surface: ref backgroundSurface,
                               region: arg.Allocation,
                               draw: (c, o) => DrawBackground(c, new Gdk.Rectangle(0, 0, arg.Allocation.Width, arg.Allocation.Height)));

            if (arg.BuildAnimationOpacity > 0.001f)
            {
                DrawBuildEffect(context, arg.Allocation, arg.BuildAnimationProgress, arg.BuildAnimationOpacity);
            }

            if (arg.ErrorAnimationProgress > 0.001 && arg.ErrorAnimationProgress < .999)
            {
                DrawErrorAnimation(context, arg);
            }

            DrawBorder(context, arg.Allocation);

            if (arg.HoverProgress > 0.001f)
            {
                context.Clip();
                int x1 = arg.Allocation.X + arg.MousePosition.X - 200;
                int x2 = x1 + 400;
                using (Cairo.LinearGradient gradient = new LinearGradient(x1, 0, x2, 0))
                {
                    Cairo.Color targetColor      = Styles.StatusBarFill1Color;
                    Cairo.Color transparentColor = targetColor;
                    targetColor.A      = .7;
                    transparentColor.A = 0;

                    targetColor.A = .7 * arg.HoverProgress;

                    gradient.AddColorStop(0.0, transparentColor);
                    gradient.AddColorStop(0.5, targetColor);
                    gradient.AddColorStop(1.0, transparentColor);

                    context.Pattern = gradient;

                    context.Rectangle(x1, arg.Allocation.Y, x2 - x1, arg.Allocation.Height);
                    context.Fill();
                }
                context.ResetClip();
            }
            else
            {
                context.NewPath();
            }

            int progress_bar_x     = arg.ChildAllocation.X;
            int progress_bar_width = arg.ChildAllocation.Width;

            if (arg.CurrentPixbuf != null)
            {
                int y = arg.Allocation.Y + (arg.Allocation.Height - arg.CurrentPixbuf.Height) / 2;
                Gdk.CairoHelper.SetSourcePixbuf(context, arg.CurrentPixbuf, arg.ChildAllocation.X, y);
                context.Paint();
                progress_bar_x     += arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
                progress_bar_width -= arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
            }

            int center = arg.Allocation.Y + arg.Allocation.Height / 2;

            Gdk.Rectangle progressArea = new Gdk.Rectangle(progress_bar_x, center - Styles.ProgressBarHeight / 2, progress_bar_width, Styles.ProgressBarHeight);
            if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0)
            {
                DrawProgressBar(context, arg.ProgressBarFraction, progressArea, arg);
                ClipProgressBar(context, progressArea);
            }

            int text_x     = progress_bar_x + Styles.ProgressBarInnerPadding;
            int text_width = progress_bar_width - (Styles.ProgressBarInnerPadding * 2);

            float textTweenValue = arg.TextAnimationProgress;

            if (arg.LastText != null)
            {
                double opacity = Math.Max(0.0f, 1.0f - textTweenValue);
                DrawString(arg.LastText, arg.LastTextIsMarkup, context, text_x,
                           center - (int)(textTweenValue * arg.Allocation.Height * 0.3), text_width, opacity, arg.Pango, arg);
            }

            if (arg.CurrentText != null)
            {
                DrawString(arg.CurrentText, arg.CurrentTextIsMarkup, context, text_x,
                           center + (int)((1.0f - textTweenValue) * arg.Allocation.Height * 0.3), text_width, Math.Min(textTweenValue, 1.0), arg.Pango, arg);
            }

            if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0)
            {
                context.ResetClip();
            }
        }
コード例 #23
0
        void DrawTab(Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la)
        {
            // This logic is stupid to have here, should be in the caller!
            if (dragging)
            {
                tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress);
                tabBounds.X = Clamp(tabBounds.X, tabStartX, tabEndX - tabBounds.Width);
            }
            int padding = LeftRightPadding;

            padding = (int)(padding * Math.Min(1.0, Math.Max(0.5, (tabBounds.Width - 30) / 70.0)));

            ctx.LineWidth = 1;
            LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 0, active);
            ctx.ClosePath();
            using (var gr = new LinearGradient(tabBounds.X, TopBarPadding, tabBounds.X, allocation.Bottom)) {
                if (active)
                {
                    gr.AddColorStop(0, Styles.BreadcrumbGradientStartColor.MultiplyAlpha(tab.Opacity));
                    gr.AddColorStop(1, Styles.BreadcrumbBackgroundColor.MultiplyAlpha(tab.Opacity));
                }
                else
                {
                    gr.AddColorStop(0, CairoExtensions.ParseColor("f4f4f4").MultiplyAlpha(tab.Opacity));
                    gr.AddColorStop(1, CairoExtensions.ParseColor("cecece").MultiplyAlpha(tab.Opacity));
                }
                ctx.SetSource(gr);
            }
            ctx.Fill();

            ctx.SetSourceColor(new Cairo.Color(1, 1, 1, .5).MultiplyAlpha(tab.Opacity));
            LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 1, active);
            ctx.Stroke();

            ctx.SetSourceColor(Styles.BreadcrumbBorderColor.MultiplyAlpha(tab.Opacity));
            LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 0, active);
            ctx.StrokePreserve();

            if (tab.GlowStrength > 0)
            {
                Gdk.Point mouse = tracker.MousePosition;
                using (var rg = new RadialGradient(mouse.X, tabBounds.Bottom, 0, mouse.X, tabBounds.Bottom, 100)) {
                    rg.AddColorStop(0, new Cairo.Color(1, 1, 1, 0.4 * tab.Opacity * tab.GlowStrength));
                    rg.AddColorStop(1, new Cairo.Color(1, 1, 1, 0));

                    ctx.SetSource(rg);
                    ctx.Fill();
                }
            }
            else
            {
                ctx.NewPath();
            }

            // Render Close Button (do this first so we can tell how much text to render)

            var ch    = allocation.Height - TopBarPadding - BottomBarPadding + CloseImageTopOffset;
            var crect = new Gdk.Rectangle(tabBounds.Right - padding - CloseButtonSize + 3,
                                          tabBounds.Y + TopBarPadding + (ch - CloseButtonSize) / 2,
                                          CloseButtonSize, CloseButtonSize);

            tab.CloseButtonAllocation = crect;
            tab.CloseButtonAllocation.Inflate(2, 2);

            bool closeButtonHovered = tracker.Hovered && tab.CloseButtonAllocation.Contains(tracker.MousePosition) && tab.WidthModifier >= 1.0f;
            bool drawCloseButton    = tabBounds.Width > 60 || highlight || closeButtonHovered;

            if (drawCloseButton)
            {
                DrawCloseButton(ctx, new Gdk.Point(crect.X + crect.Width / 2, crect.Y + crect.Height / 2), closeButtonHovered, tab.Opacity, tab.DirtyStrength);
            }

            // Render Text
            int w = tabBounds.Width - (padding * 2 + CloseButtonSize);

            if (!drawCloseButton)
            {
                w += CloseButtonSize;
            }

            int textStart = tabBounds.X + padding;

            ctx.MoveTo(textStart, tabBounds.Y + TopPadding + TextOffset + VerticalTextSize);
            if (!MonoDevelop.Core.Platform.IsMac && !MonoDevelop.Core.Platform.IsWindows)
            {
                // This is a work around for a linux specific problem.
                // A bug in the proprietary ATI driver caused TAB text not to draw.
                // If that bug get's fixed remove this HACK asap.
                la.Ellipsize = Pango.EllipsizeMode.End;
                la.Width     = (int)(w * Pango.Scale.PangoScale);
                ctx.SetSourceColor(tab.Notify ? new Cairo.Color(0, 0, 1) : Styles.TabBarActiveTextColor);
                Pango.CairoHelper.ShowLayoutLine(ctx, la.GetLine(0));
            }
            else
            {
                // ellipses are for space wasting ..., we cant afford that
                using (var lg = new LinearGradient(textStart + w - 5, 0, textStart + w + 3, 0)) {
                    var color = tab.Notify ? new Cairo.Color(0, 0, 1) : Styles.TabBarActiveTextColor;
                    color = color.MultiplyAlpha(tab.Opacity);
                    lg.AddColorStop(0, color);
                    color.A = 0;
                    lg.AddColorStop(1, color);
                    ctx.SetSource(lg);
                    Pango.CairoHelper.ShowLayoutLine(ctx, la.GetLine(0));
                }
            }
            la.Dispose();
        }
コード例 #24
0
        private void Render(Clutter.CairoTexture texture, int with_state, bool outwards)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

            double alpha_f = with_state == 0 ? 0.5 : (with_state == 1 ? 0.8 : 1);

            double lwidth  = 1;
            double hlwidth = lwidth * 0.5;

            context.LineWidth = lwidth;

            if (outwards)
            {
                context.MoveTo(texture.Width * 0.5 - texture.Height * 0.45, texture.Height * 0.9);
                context.CurveTo(texture.Width * 0.3, texture.Height, texture.Width * 0.6, texture.Height, texture.Width * 0.5 + texture.Height * 0.45, texture.Height * 0.9);
                context.ArcNegative(texture.Width * 0.5, texture.Height * 0.9, texture.Height * 0.45, 0, Math.PI);
                context.ClosePath();
                Gradient g1 = new LinearGradient(0, texture.Height / 2, 0, texture.Height);
                g1.AddColorStop(0, new Cairo.Color(0.6, 0.6, 0.6, 1.0 * alpha_f));
                g1.AddColorStop(1.0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                context.Pattern = g1;
                context.FillPreserve();
                context.SetSourceRGBA(1.0, 1.0, 1.0, 1.0 * alpha_f);
                context.Stroke();
                ((IDisposable)g1).Dispose();

                context.Arc(Width * 0.5, Height * 0.33 + lwidth, Height * 0.33, 0, Math.PI * 2);
                context.ClosePath();
                context.Operator = Operator.Source;
                Gradient g2 = new RadialGradient(texture.Width * 0.5, texture.Height * 0.25, 0, texture.Width * 0.5, texture.Height * 0.25, texture.Width * 0.5);
                g2.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g2.AddColorStop(1.0, new Cairo.Color(0.6, 0.6, 0.6, 1.0 * alpha_f));
                context.Pattern = g2;
                //context.SetSourceRGBA (1.0, 1.0, 1.0, 1.0*alpha_f);
                context.FillPreserve();
                Gradient g3 = new LinearGradient(0, 0, 0, texture.Height * 0.5);
                g3.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g3.AddColorStop(1.0, new Cairo.Color(0, 0, 0, 1.0 * alpha_f));
                context.Pattern = g3;
                //context.SetSourceRGBA (1.0, 1.0, 1.0, 1.0*alpha_f);
                context.Stroke();
                ((IDisposable)g2).Dispose();
                ((IDisposable)g3).Dispose();
            }
            else
            {
                Cairo.PointD c     = new Cairo.PointD(texture.Width * 0.5, texture.Height * 0.5);
                double       max_r = Math.Min(c.X, c.Y) - hlwidth;

                context.Arc(c.X, c.Y, max_r, 0, Math.PI * 2);
                context.ArcNegative(c.X, c.Y, max_r * 0.25, Math.PI * 2, 0);
                context.ClosePath();
                context.SetSourceRGBA(0.5, 0.5, 0.5, 1.0 * alpha_f);
                context.StrokePreserve();
                Gradient g1 = new LinearGradient(0, texture.Height, texture.Width, 0);
                g1.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g1.AddColorStop(0.5, new Cairo.Color(0.7, 0.7, 0.7, 1.0 * alpha_f));
                g1.AddColorStop(1, new Cairo.Color(0.9, 0.9, 0.9, 1.0 * alpha_f));
                context.Pattern = g1;
                context.Fill();
                ((IDisposable)g1).Dispose();

                context.ArcNegative(c.X, c.Y, max_r * 0.25 + lwidth, Math.PI * 1.75, Math.PI * 0.75);
                context.Arc(c.X, c.Y, max_r, Math.PI * 0.75, Math.PI * 1.75);
                context.ClosePath();
                Gradient g2 = new LinearGradient(c.X, c.Y, c.X * 0.35, c.Y * 0.35);
                g2.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g2.AddColorStop(1, new Cairo.Color(1.0, 1.0, 1.0, 0.0));
                context.Pattern = g2;
                context.Fill();
                ((IDisposable)g2).Dispose();

                context.ArcNegative(c.X, c.Y, max_r * 0.25 + lwidth, Math.PI * 2, 0);
                context.Arc(c.X, c.Y, max_r * 0.45, 0, Math.PI * 2);
                context.SetSourceRGBA(1.0, 1.0, 1.0, 0.8 * alpha_f);
                context.Fill();

                context.Arc(c.X, c.Y, max_r - lwidth, 0, Math.PI * 2);
                Gradient g3 = new LinearGradient(0, texture.Height, texture.Width, 0);
                g3.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 0.0));
                g3.AddColorStop(1, new Cairo.Color(0.9, 0.9, 0.9, 1.0 * alpha_f));
                context.Pattern = g3;
                context.Stroke();
                ((IDisposable)g3).Dispose();
            }

            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }