Exemple #1
0
            protected override bool OnExposeEvent(EventExpose evnt)
            {
                bool hideButton = widget.MainEditor.Document.IsReadOnly;

                using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                    cr.Rectangle(evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height);
                    cr.Clip();
                    int delta = widget.MainEditor.Allocation.Y - Allocation.Y;
                    if (Diff != null)
                    {
                        foreach (Hunk hunk in Diff)
                        {
                            double z1 = delta + fromEditor.LineToY(hunk.RemoveStart) - fromEditor.VAdjustment.Value;
                            double z2 = delta + fromEditor.LineToY(hunk.RemoveStart + hunk.Removed) - fromEditor.VAdjustment.Value;
                            if (z1 == z2)
                            {
                                z2 = z1 + 1;
                            }

                            double y1 = delta + toEditor.LineToY(hunk.InsertStart) - toEditor.VAdjustment.Value;
                            double y2 = delta + toEditor.LineToY(hunk.InsertStart + hunk.Inserted) - toEditor.VAdjustment.Value;

                            if (y1 == y2)
                            {
                                y2 = y1 + 1;
                            }

                            if (!useLeft)
                            {
                                var tmp = z1;
                                z1 = y1;
                                y1 = tmp;

                                tmp = z2;
                                z2  = y2;
                                y2  = tmp;
                            }

                            int x1 = 0;
                            int x2 = Allocation.Width;

                            if (!hideButton)
                            {
                                if (useLeft && hunk.Removed > 0 || !useLeft && hunk.Removed == 0)
                                {
                                    x1 += 16;
                                }
                                else
                                {
                                    x2 -= 16;
                                }
                            }

                            if (z1 == z2)
                            {
                                z2 = z1 + 1;
                            }

                            cr.MoveTo(x1, z1);

                            cr.CurveTo(x1 + (x2 - x1) / 4, z1,
                                       x1 + (x2 - x1) * 3 / 4, y1,
                                       x2, y1);

                            cr.LineTo(x2, y2);
                            cr.CurveTo(x1 + (x2 - x1) * 3 / 4, y2,
                                       x1 + (x2 - x1) / 4, z2,
                                       x1, z2);
                            cr.ClosePath();
                            cr.SetSourceColor(GetColor(hunk, this.useLeft, false, 1.0));
                            cr.Fill();

                            cr.SetSourceColor(GetColor(hunk, this.useLeft, true, 1.0));
                            cr.MoveTo(x1, z1);
                            cr.CurveTo(x1 + (x2 - x1) / 4, z1,
                                       x1 + (x2 - x1) * 3 / 4, y1,
                                       x2, y1);
                            cr.Stroke();

                            cr.MoveTo(x2, y2);
                            cr.CurveTo(x1 + (x2 - x1) * 3 / 4, y2,
                                       x1 + (x2 - x1) / 4, z2,
                                       x1, z2);
                            cr.Stroke();

                            if (!hideButton)
                            {
                                bool isButtonSelected = hunk == selectedHunk;

                                double x, y, w, h;
                                bool   drawArrow = useLeft ? GetButtonPosition(hunk, y1, y2, z1, z2, out x, out y, out w, out h) :
                                                   GetButtonPosition(hunk, z1, z2, y1, y2, out x, out y, out w, out h);

                                cr.Rectangle(x, y, w, h);
                                if (isButtonSelected)
                                {
                                    int mx, my;
                                    GetPointer(out mx, out my);
                                    //	mx -= (int)x;
                                    //	my -= (int)y;
                                    using (var gradient = new Cairo.RadialGradient(mx, my, h, mx, my, 2)) {
                                        var color = (MonoDevelop.Components.HslColor)Style.Mid(StateType.Normal);
                                        color.L *= 1.05;
                                        gradient.AddColorStop(0, color);
                                        color.L *= 1.07;
                                        gradient.AddColorStop(1, color);
                                        cr.SetSource(gradient);
                                    }
                                }
                                else
                                {
                                    cr.SetSourceColor((MonoDevelop.Components.HslColor)Style.Mid(StateType.Normal));
                                }
                                cr.FillPreserve();

                                cr.SetSourceColor((MonoDevelop.Components.HslColor)Style.Dark(StateType.Normal));
                                cr.Stroke();
                                cr.LineWidth = 1;
                                cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.BaseForegroundColor.ToCairoColor());
                                if (drawArrow)
                                {
                                    DrawArrow(cr, x + w / 1.5, y + h / 2);
                                    DrawArrow(cr, x + w / 2.5, y + h / 2);
                                }
                                else
                                {
                                    DrawCross(cr, x + w / 2, y + (h) / 2);
                                }
                                cr.Stroke();
                            }
                        }
                    }
                }
//				var result = base.OnExposeEvent (evnt);
//
//				Gdk.GC gc = Style.DarkGC (State);
//				evnt.Window.DrawLine (gc, Allocation.X, Allocation.Top, Allocation.X, Allocation.Bottom);
//				evnt.Window.DrawLine (gc, Allocation.Right, Allocation.Top, Allocation.Right, Allocation.Bottom);
//
//				evnt.Window.DrawLine (gc, Allocation.Left, Allocation.Y, Allocation.Right, Allocation.Y);
//				evnt.Window.DrawLine (gc, Allocation.Left, Allocation.Bottom, Allocation.Right, Allocation.Bottom);

                return(true);
            }
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            if (data == null)
            {
                BuildData();
            }

            hostSpots.Clear();
            int ytop    = padding;
            int markerX = 3;
            int lx      = markerX + MarkerWidth + 1;
            int tx      = 250;
            int ty      = ytop;
            int maxx    = lx;
            int maxy    = 0;

            DateTime initialTime = mainValue.TimeStamp;

            Cairo.Context ctx = CairoHelper.Create(GdkWindow);

            Gdk.GC gc = new Gdk.GC(GdkWindow);
            gc.RgbFgColor = Style.White;
            GdkWindow.DrawRectangle(gc, true, 0, 0, Allocation.Width, Allocation.Height);

            // Draw full time marker

            ctx.NewPath();
            ctx.Rectangle(markerX, ytop + baseTime + 0.5, MarkerWidth / 2, ((mainValue.Duration.TotalMilliseconds * scale) / 1000));
            HslColor hsl = Style.Foreground(Gtk.StateType.Normal);

            hsl.L     = 0.8;
            ctx.Color = hsl;
            ctx.Fill();

            // Draw values

            foreach (CounterValueInfo val in data)
            {
                DrawValue(ctx, gc, initialTime, ytop, lx, tx, ref ty, ref maxx, ref maxy, 0, val);
            }

            if (ty > maxy)
            {
                maxy = ty;
            }

            int totalms = (int)mainValue.Duration.TotalMilliseconds;
            int marks   = (totalms / 1000) + 1;

            ctx.LineWidth = 1;
            gc.RgbFgColor = Style.Foreground(Gtk.StateType.Normal);

            for (int n = 0; n <= marks; n++)
            {
                ctx.NewPath();
                int y = ytop + (int)(n * scale) + baseTime;
                ctx.MoveTo(markerX, y + 0.5);
                ctx.LineTo(markerX + MarkerWidth, y + 0.5);
                ctx.Color = Style.Foreground(Gtk.StateType.Normal).ToCairoColor();
                ctx.Stroke();

                y += 2;
                layout.SetText(n + "s");
                GdkWindow.DrawLayout(gc, markerX + 1, y + 2, layout);

                int tw, th;
                layout.GetPixelSize(out tw, out th);
                y += th;

                if (y > maxy)
                {
                    maxy = y;
                }
            }

            ((IDisposable)ctx).Dispose();

            maxy += padding;
            maxx += padding;

            if (lastHeight != maxy || lastWidth != maxx)
            {
                lastWidth  = maxx;
                lastHeight = maxy;
                SetSizeRequest(maxx, maxy);
            }

            return(true);
        }
        protected override void OnDrawContent(Gdk.EventExpose evnt, Cairo.Context context)
        {
            context.LineWidth = 1;
            var alloc = ChildAllocation;
            var adjustedMarginSize = alloc.X - Allocation.X + headerMarginSize;

            var r = results.Where(res => res.Item2.Count > 0).ToArray();

            if (r.Any())
            {
                context.SetSourceColor(lightSearchBackground);
                context.Rectangle(Allocation.X, Allocation.Y, adjustedMarginSize, Allocation.Height);
                context.Fill();

                context.SetSourceColor(darkSearchBackground);
                context.Rectangle(Allocation.X + adjustedMarginSize, Allocation.Y, Allocation.Width - adjustedMarginSize, Allocation.Height);
                context.Fill();
                context.MoveTo(0.5 + Allocation.X + adjustedMarginSize, 0);
                context.LineTo(0.5 + Allocation.X + adjustedMarginSize, Allocation.Height);
                context.SetSourceColor(separatorLine);
                context.Stroke();
            }
            else
            {
                context.SetSourceColor(darkSearchBackground);
                context.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
                context.Fill();
            }

            double y = alloc.Y + yMargin;
            int    w, h;

            if (topItem != null)
            {
                headerLayout.SetText(GettextCatalog.GetString("Top Result"));
                headerLayout.GetPixelSize(out w, out h);
                context.MoveTo(alloc.Left + headerMarginSize - w - xMargin, y + itemPadding);
                context.SetSourceColor(headerColor);
                Pango.CairoHelper.ShowLayout(context, headerLayout);

                var category   = topItem.Category;
                var dataSrc    = topItem.DataSource;
                var i          = topItem.Item;
                var isSelected = selectedItem != null && selectedItem.Category == category && selectedItem.Item == i;

                double x = alloc.X + xMargin + headerMarginSize;
                context.SetSourceRGB(0, 0, 0);
                layout.SetMarkup(GetRowMarkup(dataSrc[i], isSelected));
                layout.GetPixelSize(out w, out h);
                if (isSelected)
                {
                    context.SetSourceColor(selectionBackgroundColor);
                    context.Rectangle(alloc.X + headerMarginSize + 1, y, Allocation.Width - adjustedMarginSize - 1, h + itemPadding * 2);
                    context.Fill();
                    context.SetSourceRGB(1, 1, 1);
                }

                var px = dataSrc[i].Icon;
                if (px != null)
                {
                    if (isSelected)
                    {
                        px = px.WithStyles("sel");
                    }
                    context.DrawImage(this, px, (int)x + marginIconSpacing, (int)(y + itemPadding));
                    x += px.Width + iconTextSpacing + marginIconSpacing;
                }

                context.MoveTo(x, y + itemPadding);
                context.SetSourceRGB(0, 0, 0);
                Pango.CairoHelper.ShowLayout(context, layout);

                y += h + itemSeparatorHeight + itemPadding * 2;
            }

            foreach (var result in r)
            {
                var category = result.Item1;
                var dataSrc  = result.Item2;
                if (dataSrc.Count == 0)
                {
                    continue;
                }
                if (dataSrc.Count == 1 && topItem != null && topItem.DataSource == dataSrc)
                {
                    continue;
                }
                headerLayout.SetText(category.Name);
                headerLayout.GetPixelSize(out w, out h);

                if (y + h + itemPadding * 2 > Allocation.Height)
                {
                    break;
                }

                context.MoveTo(alloc.X + headerMarginSize - w - xMargin, y + itemPadding);
                context.SetSourceColor(headerColor);
                Pango.CairoHelper.ShowLayout(context, headerLayout);

                layout.Width = Pango.Units.FromPixels(Allocation.Width - adjustedMarginSize - 35);

                for (int i = 0; i < maxItems && i < dataSrc.Count; i++)
                {
                    if (topItem != null && topItem.Category == category && topItem.Item == i)
                    {
                        continue;
                    }
                    var    isSelected = selectedItem != null && selectedItem.Category == category && selectedItem.Item == i;
                    double x          = alloc.X + xMargin + headerMarginSize;
                    context.SetSourceRGB(0, 0, 0);
                    layout.SetMarkup(GetRowMarkup(dataSrc[i], isSelected));
                    layout.GetPixelSize(out w, out h);
                    if (y + h + itemSeparatorHeight + itemPadding * 2 > Allocation.Height)
                    {
                        break;
                    }
                    if (isSelected)
                    {
                        context.SetSourceColor(selectionBackgroundColor);
                        context.Rectangle(alloc.X + headerMarginSize + 1, y, Allocation.Width - adjustedMarginSize - 1, h + itemPadding * 2);
                        context.Fill();
                        context.SetSourceRGB(1, 1, 1);
                    }

                    var px = dataSrc[i].Icon;
                    if (px != null)
                    {
                        if (isSelected)
                        {
                            px = px.WithStyles("sel");
                        }
                        context.DrawImage(this, px, (int)x + marginIconSpacing, (int)(y + itemPadding));
                        x += px.Width + iconTextSpacing + marginIconSpacing;
                    }

                    context.MoveTo(x, y + itemPadding);
                    context.SetSourceRGB(0, 0, 0);
                    Pango.CairoHelper.ShowLayout(context, layout);

                    y += h + itemSeparatorHeight + itemPadding * 2;
                }
                if (result != r.Last())
                {
                    y += categorySeparatorHeight;
                }
            }
            if (y == alloc.Y + yMargin)
            {
                context.SetSourceColor(Styles.GlobalSearch.ResultTextColor.ToCairoColor());
                layout.SetMarkup(isInSearch ? GettextCatalog.GetString("Searching...") : GettextCatalog.GetString("No matches"));
                context.MoveTo(alloc.X + xMargin, y);
                Pango.CairoHelper.ShowLayout(context, layout);
            }
        }
        public void Draw(TextEditor editor, Cairo.Context g, int lineNr, Cairo.Rectangle lineArea)
        {
            EnsureLayoutCreated(editor);
            int    lineNumber        = editor.Document.OffsetToLineNumber(lineSegment.Offset);
            int    errorNumber       = lineNr - lineNumber;
            double x                 = editor.TextViewMargin.XOffset;
            double y                 = lineArea.Y;
            double right             = editor.Allocation.Width;
            int    errorCounterWidth = 0;

            int ew = 0, eh = 0;

            if (errors.Count > 1 && errorCountLayout != null)
            {
                errorCountLayout.GetPixelSize(out ew, out eh);
                errorCounterWidth = ew + 10;
            }

            double x2 = System.Math.Max(right - LayoutWidth - border - (ShowIconsInBubble ? errorPixbuf.Width : 0) - errorCounterWidth, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset);
//			bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != SelectionMode.Block ? editor.SelectionRange.Contains (lineSegment.Offset  + lineSegment.EditableLength) : false;
            int              active        = editor.Document.GetTextAt(lineSegment) == initialText ? 0 : 1;
            bool             isCaretInLine = lineSegment.Offset <= editor.Caret.Offset && editor.Caret.Offset <= lineSegment.EndOffset;
            int              highlighted   = active == 0 && isCaretInLine ? 1 : 0;
            int              selected      = 0;
            LayoutDescriptor layout        = layouts[errorNumber];

            x2 = right - LayoutWidth - border - (ShowIconsInBubble ? errorPixbuf.Width : 0);

            x2 -= errorCounterWidth;
            x2  = System.Math.Max(x2, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset);

            g.MoveTo(new Cairo.PointD(x2 + 0.5, y));
            g.LineTo(new Cairo.PointD(x2 + 0.5, y + editor.LineHeight));
            g.LineTo(new Cairo.PointD(right, y + editor.LineHeight));
            g.LineTo(new Cairo.PointD(right, y));
            g.ClosePath();
            g.Color = colorMatrix[active, BOTTOM, LIGHT, highlighted, selected];
            g.Fill();

            g.Color = colorMatrix[active, BOTTOM, LINE, highlighted, selected];
            g.MoveTo(new Cairo.PointD(x2 + 0.5, y));
            g.LineTo(new Cairo.PointD(x2 + 0.5, y + editor.LineHeight));
            if (errorNumber == errors.Count - 1)
            {
                g.LineTo(new Cairo.PointD(lineArea.X + lineArea.Width, y + editor.LineHeight));
            }
            g.Stroke();

            if (editor.Options.ShowRuler)
            {
                double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                if (divider >= x2)
                {
                    g.MoveTo(new Cairo.PointD(divider + 0.5, y));
                    g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight));
                    g.Color = colorMatrix[active, BOTTOM, DARK, highlighted, selected];
                    g.Stroke();
                }
            }
            g.Save();
            g.Translate(x2 + (ShowIconsInBubble ? errorPixbuf.Width : 0) + border, y + (editor.LineHeight - layout.Height) / 2 + layout.Height % 2);
            g.Color = selected == 0 ? gc : gcSelected;
            g.ShowLayout(layout.Layout);
            g.Restore();
//			if (ShowIconsInBubble)
//				win.DrawPixbuf (editor.Style.BaseGC (Gtk.StateType.Normal), errors[errorNumber].IsError ? errorPixbuf : warningPixbuf, 0, 0, x2, y + (editor.LineHeight - errorPixbuf.Height) / 2, errorPixbuf.Width, errorPixbuf.Height, Gdk.RgbDither.None, 0, 0);
        }
Exemple #5
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            if (State == StateType.Prelight)
            {
                int    w = Allocation.Width, h = Allocation.Height;
                double x = Allocation.Left, y = Allocation.Top, r = 3;
                x += 0.5; y += 0.5; h -= 1; w -= 1;

                using (Cairo.Context ctx = Gdk.CairoHelper.Create(GdkWindow)) {
                    HslColor c  = new HslColor(Style.Background(Gtk.StateType.Normal));
                    HslColor c1 = c;
                    HslColor c2 = c;
                    if (State != StateType.Prelight)
                    {
                        c1.L *= 0.8;
                        c2.L *= 0.95;
                    }
                    else
                    {
                        c1.L *= 1.1;
                        c2.L *= 1;
                    }
                    Cairo.Gradient pat;
                    switch (bar.Position)
                    {
                    case PositionType.Top: pat = new Cairo.LinearGradient(x, y, x, y + h); break;

                    case PositionType.Bottom: pat = new Cairo.LinearGradient(x, y, x, y + h); break;

                    case PositionType.Left: pat = new Cairo.LinearGradient(x + w, y, x, y); break;

                    default: pat = new Cairo.LinearGradient(x, y, x + w, y); break;
                    }
                    pat.AddColorStop(0, c1);
                    pat.AddColorStop(1, c2);
                    ctx.NewPath();
                    ctx.Arc(x + r, y + r, r, 180 * (Math.PI / 180), 270 * (Math.PI / 180));
                    ctx.LineTo(x + w - r, y);
                    ctx.Arc(x + w - r, y + r, r, 270 * (Math.PI / 180), 360 * (Math.PI / 180));
                    ctx.LineTo(x + w, y + h);
                    ctx.LineTo(x, y + h);
                    ctx.ClosePath();
                    ctx.Pattern = pat;
                    ctx.FillPreserve();
                    c1            = c;
                    c1.L         *= 0.7;
                    ctx.LineWidth = 1;
                    ctx.Color     = c1;
                    ctx.Stroke();

                    // Inner line
                    ctx.NewPath();
                    ctx.Arc(x + r + 1, y + r + 1, r, 180 * (Math.PI / 180), 270 * (Math.PI / 180));
                    ctx.LineTo(x + w - r - 1, y + 1);
                    ctx.Arc(x + w - r - 1, y + r + 1, r, 270 * (Math.PI / 180), 360 * (Math.PI / 180));
                    ctx.LineTo(x + w - 1, y + h - 1);
                    ctx.LineTo(x + 1, y + h - 1);
                    ctx.ClosePath();
                    c1 = c;
                    //c1.L *= 0.9;
                    ctx.LineWidth = 1;
                    ctx.Color     = c1;
                    ctx.Stroke();
                }
            }

            bool res = base.OnExposeEvent(evnt);

            return(res);
        }
Exemple #6
0
            public void Read(string fontFileName, char character, int fontSize)
            {
                Typeface typeFace;

                using (var fs = Utility.ReadFile(Utility.FontDir + fontFileName))
                {
                    var reader = new OpenFontReader();
                    typeFace = reader.Read(fs);
                }

                Glyph glyph = typeFace.Lookup(character);

                // read polygons and bezier segments
                GlyphLoader.Read(glyph, out var polygons, out var bezierSegments);

                Rect aabb = new Rect(polygons[0][0], polygons[0][1]);

                //print to test output
                //calcualte the aabb
                for (int i = 0; i < polygons.Count; i++)
                {
                    o.WriteLine("Polygon " + i);
                    var polygon = polygons[i];
                    foreach (var p in polygon)
                    {
                        aabb.Union(p);
                        o.WriteLine("{0}, {1}", (int)p.X, (int)p.Y);
                    }
                    o.WriteLine("");
                }

                foreach (var segment in bezierSegments)
                {
                    aabb.Union(segment.Item1);
                    aabb.Union(segment.Item2);
                    aabb.Union(segment.Item3);
                    o.WriteLine("<{0}, {1}> <{2}, {3}> <{4}, {5}>",
                                (int)segment.Item1.X, (int)segment.Item1.Y,
                                (int)segment.Item2.X, (int)segment.Item2.Y,
                                (int)segment.Item3.X, (int)segment.Item3.Y);
                }

                o.WriteLine("");

                // draw to an image
                using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.Argb32, 2000, 2000))
                    using (Cairo.Context g = new Cairo.Context(surface))
                    {
                        g.Translate(-aabb.Min.X, -aabb.Min.Y);

                        for (var i = 0; i < polygons.Count; i++)
                        {
                            var polygon = polygons[i];
                            g.MoveTo(polygon[0].X, polygon[0].Y);
                            foreach (var point in polygon)
                            {
                                g.LineTo(point.X, point.Y);
                            }
                            g.ClosePath();
                        }
                        g.SetSourceColor(new Cairo.Color(0, 0, 0));
                        g.LineWidth = 2;
                        g.StrokePreserve();
                        g.SetSourceColor(new Cairo.Color(0.8, 0, 0, 0.6));
                        g.Fill();

                        foreach (var segment in bezierSegments)
                        {
                            var p0 = segment.Item1;
                            var c  = segment.Item2;
                            var p1 = segment.Item3;
                            g.MoveTo(p0.X, p0.Y);
                            g.QuadraticTo(c.X, c.Y, p1.X, p1.Y);
                        }

                        g.LineWidth = 4;
                        g.SetSourceColor(CairoEx.ColorRgb(0, 122, 204));
                        g.Stroke();

                        var path =
                            $"{OutputPath}\\GlyphReaderFacts.TheReadMethod.Read_{fontFileName}_{character}_{fontSize}.png";
                        surface.WriteToPng(path);

                        Util.OpenImage(path);

                        // Now inspect the image to check whether the glyph is correct
                        // TODO Are there a better way to do such kind of unit-test?
                    }
            }
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics layout, int startOffset, int endOffset)
        {
            if (DebuggingService.IsDebugging)
            {
                return;
            }
            int markerStart = Segment.Offset;
            int markerEnd   = Segment.EndOffset;

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

            double drawFrom;
            double drawTo;
            double y         = layout.LineYRenderStartPosition;
            double startXPos = layout.TextRenderStartPosition;
            double endXPos   = layout.TextRenderEndPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                drawTo = endXPos;
                var line   = editor.GetLineByOffset(startOffset);
                int offset = line.GetIndentation(editor.Document).Length;
                drawFrom = startXPos + (layout.Layout.Layout.IndexToPos(offset).X / Pango.Scale.PangoScale);
            }
            else
            {
                int start;
                if (startOffset < markerStart)
                {
                    start = markerStart;
                }
                else
                {
                    var line   = editor.GetLineByOffset(startOffset);
                    int offset = line.GetIndentation(editor.Document).Length;
                    start = startOffset + offset;
                }
                int end = endOffset < markerEnd ? endOffset : markerEnd;
                int x_pos;

                x_pos    = layout.Layout.Layout.IndexToPos(start - startOffset).X;
                drawFrom = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
                x_pos    = layout.Layout.Layout.IndexToPos(end - startOffset).X;

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

            drawFrom = Math.Max(drawFrom, editor.TextViewMargin.XOffset);
            drawTo   = Math.Max(drawTo, editor.TextViewMargin.XOffset);
            if (drawFrom >= drawTo)
            {
                return;
            }

            double height = editor.LineHeight / 5;

            cr.SetSourceColor(color);
            if (effect == MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.WavedLine)
            {
                Pango.CairoHelper.ShowErrorUnderline(cr, drawFrom, y + editor.LineHeight - height, drawTo - drawFrom, height);
            }
            else if (effect == MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.DottedLine)
            {
                cr.Save();
                cr.LineWidth = 1;
                cr.MoveTo(drawFrom + 1, y + editor.LineHeight - 1 + 0.5);
                cr.RelLineTo(Math.Min(drawTo - drawFrom, 4 * 3), 0);
                cr.SetDash(new double[] { 2, 2 }, 0);
                cr.Stroke();
                cr.Restore();
            }
            else
            {
                cr.MoveTo(drawFrom, y + editor.LineHeight - 1);
                cr.LineTo(drawTo, y + editor.LineHeight - 1);
                cr.Stroke();
            }
        }
Exemple #8
0
        internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor)
        {
            Gdk.Pixbuf result = null;

            Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault(stockId);
            if (iconset != null)
            {
                // Find the size that better fits the requested size
                Gtk.IconSize gsize = Util.GetBestSizeFit(width);
                result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor);
                if (result == null || result.Width < width * scaleFactor)
                {
                    var gsize2x = Util.GetBestSizeFit(width * scaleFactor, iconset.Sizes);
                    if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize)
                    {
                        // Don't dispose the previous result since the icon is owned by the IconSet
                        result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null);
                    }
                }
            }

            if (result == null && Gtk.IconTheme.Default.HasIcon(stockId))
            {
                result = Gtk.IconTheme.Default.LoadIcon(stockId, (int)width, (Gtk.IconLookupFlags) 0);
            }

            if (result == null)
            {
                // render a custom gtk-missing-image icon
                // if Gtk.Stock.MissingImage is not found
                int w = (int)width;
                int h = (int)height;
                                #if XWT_GTK3
                Cairo.ImageSurface s  = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
                Cairo.Context      cr = new Cairo.Context(s);
                cr.SetSourceRGB(255, 255, 255);
                cr.Rectangle(0, 0, w, h);
                cr.Fill();
                cr.SetSourceRGB(0, 0, 0);
                cr.LineWidth = 1;
                cr.Rectangle(0.5, 0.5, w - 1, h - 1);
                cr.Stroke();
                cr.SetSourceRGB(255, 0, 0);
                cr.LineWidth = 3;
                cr.LineCap   = Cairo.LineCap.Round;
                cr.LineJoin  = Cairo.LineJoin.Round;
                cr.MoveTo(w / 4, h / 4);
                cr.LineTo((w - 1) - w / 4, (h - 1) - h / 4);
                cr.MoveTo(w / 4, (h - 1) - h / 4);
                cr.LineTo((w - 1) - w / 4, h / 4);
                cr.Stroke();
                result = Gtk3Extensions.GetFromSurface(s, 0, 0, w, h);
                                #else
                using (Gdk.Pixmap pmap = new Gdk.Pixmap(Gdk.Screen.Default.RootWindow, w, h))
                    using (Gdk.GC gc = new Gdk.GC(pmap)) {
                        gc.RgbFgColor = new Gdk.Color(255, 255, 255);
                        pmap.DrawRectangle(gc, true, 0, 0, w, h);
                        gc.RgbFgColor = new Gdk.Color(0, 0, 0);
                        pmap.DrawRectangle(gc, false, 0, 0, (w - 1), (h - 1));
                        gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
                        gc.RgbFgColor = new Gdk.Color(255, 0, 0);
                        pmap.DrawLine(gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4)));
                        pmap.DrawLine(gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4)));
                        result = Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, w, h);
                    }
                                #endif
            }
            return(result);
        }
        public override bool DrawBackground(MonoTextEditor editor, Cairo.Context g, LineMetrics metrics)
        {
            if (!IsVisible)
            {
                return(false);
            }
            bool markerShouldDrawnAsHidden = cache.CurrentSelectedTextMarker != null && cache.CurrentSelectedTextMarker != this;

            if (editor.Document.GetTextSegmentMarkersAt(metrics.LineSegment).Any(m => m is DebugTextMarker))
            {
                return(false);
            }

            EnsureLayoutCreated(editor);
            double x                 = editor.TextViewMargin.XOffset;
            int    right             = editor.Allocation.Width;
            bool   isCaretInLine     = metrics.TextStartOffset <= editor.Caret.Offset && editor.Caret.Offset <= metrics.TextEndOffset;
            int    errorCounterWidth = GetErrorCountBounds(metrics).Item1;

            var    min = right - LayoutWidth - border - (ShowIconsInBubble ? MessageBubbleCache.errorPixbuf.Width : 0) - errorCounterWidth;
            var    max = Math.Round(editor.TextViewMargin.XOffset + editor.LineHeight / 2);
            double x2  = Math.Max(min, max);

            bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != Mono.TextEditor.SelectionMode.Block ? editor.SelectionRange.Contains(LineSegment.Offset + LineSegment.Length) : false;

            int  active      = 0;
            bool highlighted = active == 0 && isCaretInLine;
            var  y           = metrics.LineYRenderStartPosition;

            // draw background
            if (!markerShouldDrawnAsHidden)
            {
                DrawRectangle(g, x, y, right, editor.LineHeight);
                g.SetSourceColor(LineColor.Color);
                g.Fill();

                if (metrics.Layout.StartSet || metrics.SelectionStart == metrics.TextEndOffset)
                {
                    double startX;
                    double endX;

                    if (metrics.SelectionStart != metrics.TextEndOffset)
                    {
                        var start = metrics.Layout.Layout.IndexToPos((int)metrics.Layout.SelectionStartIndex);
                        startX = (int)(start.X / Pango.Scale.PangoScale);
                        var end = metrics.Layout.Layout.IndexToPos((int)metrics.Layout.SelectionEndIndex);
                        endX = (int)(end.X / Pango.Scale.PangoScale);
                    }
                    else
                    {
                        startX = x2;
                        endX   = startX;
                    }

                    if (editor.MainSelection.SelectionMode == Mono.TextEditor.SelectionMode.Block && startX == endX)
                    {
                        endX = startX + 2;
                    }
                    startX += metrics.TextRenderStartPosition;
                    endX   += metrics.TextRenderStartPosition;
                    startX  = Math.Max(editor.TextViewMargin.XOffset, startX);
                    // clip region to textviewmargin start
                    if (isEolSelected)
                    {
                        endX = editor.Allocation.Width + (int)editor.HAdjustment.Value;
                    }
                    if (startX < endX)
                    {
                        DrawRectangle(g, startX, y, endX - startX, editor.LineHeight);
                        g.SetSourceColor(GetLineColor(highlighted, true));
                        g.Fill();
                    }
                }
                DrawErrorMarkers(editor, g, metrics, y);
            }

            double y2         = y + 0.5;
            double y2Bottom   = y2 + editor.LineHeight - 1;
            var    selected   = isEolSelected;
            var    lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + metrics.Layout.Width;

            if (x2 < lineTextPx)
            {
                x2 = lineTextPx;
            }

            if (editor.Options.ShowRuler)
            {
                double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                if (divider >= x2)
                {
                    g.MoveTo(new Cairo.PointD(divider + 0.5, y2));
                    g.LineTo(new Cairo.PointD(divider + 0.5, y2Bottom));
                    g.SetSourceColor(GetLineColorBorder(highlighted, selected));
                    g.Stroke();
                }
            }

            return(true);
        }
            public override void DrawForeground(TextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
            {
                cr.Arc(metrics.X + metrics.Width / 2 + 2, metrics.Y + metrics.Height / 2, 7 * editor.Options.Zoom, 0, Math.PI * 2);
                isFailed = false;
                var  test        = NUnitService.Instance.SearchTestById(unitTest.UnitTestIdentifier);
                bool searchCases = false;

                if (unitTest.IsIgnored)
                {
                    cr.SetSourceRGB(0.9, 0.9, 0);
                }
                else
                {
                    if (test != null)
                    {
                        var result = test.GetLastResult();
                        if (result == null)
                        {
                            cr.SetSourceRGB(0.5, 0.5, 0.5);
                            searchCases = true;
                        }
                        else if (result.IsNotRun)
                        {
                            cr.SetSourceRGBA(0.9, 0.9, 0, test.IsHistoricResult ? 0.5 : 1.0);
                        }
                        else if (result.IsSuccess)
                        {
                            cr.SetSourceRGBA(0, 1, 0, test.IsHistoricResult ? 0.2 : 1.0);
                        }
                        else if (result.IsFailure)
                        {
                            cr.SetSourceRGBA(1, 0, 0, test.IsHistoricResult ? 0.2 : 1.0);
                            failMessage = result.Message;
                            isFailed    = true;
                        }
                        else if (result.IsInconclusive)
                        {
                            cr.SetSourceRGBA(0, 1, 1, test.IsHistoricResult ? 0.2 : 1.0);
                        }
                        else
                        {
                            cr.SetSourceRGB(0.5, 0.5, 0.5);
                        }
                    }
                    else
                    {
                        cr.SetSourceRGB(0.5, 0.5, 0.5);
                        searchCases = true;
                    }
                    if (searchCases)
                    {
                        foreach (var caseId in unitTest.TestCases)
                        {
                            test = NUnitService.Instance.SearchTestById(unitTest.UnitTestIdentifier + caseId);
                            if (test != null)
                            {
                                var result = test.GetLastResult();
                                if (result == null || result.IsNotRun || test.IsHistoricResult)
                                {
                                }
                                else if (result.IsNotRun)
                                {
                                    cr.SetSourceRGB(0.9, 0.9, 0);
                                }
                                else if (result.IsSuccess)
                                {
                                    cr.SetSourceRGB(0, 1, 0);
                                }
                                else if (result.IsFailure)
                                {
                                    cr.SetSourceRGB(1, 0, 0);
                                    failMessage = result.Message;
                                    isFailed    = true;
                                    break;
                                }
                                else if (result.IsInconclusive)
                                {
                                    cr.SetSourceRGB(0, 1, 1);
                                }
                            }
                        }
                    }
                }

                cr.FillPreserve();
                if (unitTest.IsIgnored)
                {
                    cr.SetSourceRGB(0.4, 0.4, 0);
                    cr.Stroke();
                }
                else
                {
                    if (test != null)
                    {
                        var result = test.GetLastResult();
                        if (result == null)
                        {
                            cr.SetSourceRGB(0.2, 0.2, 0.2);
                            cr.Stroke();
                        }
                        else if (result.IsNotRun && !test.IsHistoricResult)
                        {
                            cr.SetSourceRGB(0.4, 0.4, 0);
                            cr.Stroke();
                        }
                        else if (result.IsSuccess && !test.IsHistoricResult)
                        {
                            cr.SetSourceRGB(0, 0.5, 0);
                            cr.Stroke();
                        }
                        else if (result.IsFailure && !test.IsHistoricResult)
                        {
                            cr.SetSourceRGB(0.5, 0, 0);
                            cr.Stroke();
                        }
                        else if (result.IsInconclusive && !test.IsHistoricResult)
                        {
                            cr.SetSourceRGB(0, 0.7, 0.7);
                            cr.Stroke();
                        }
                    }
                }
                cr.NewPath();
            }
Exemple #11
0
        public void ShowGlyphAsDirectedContours_Cairo()
        {
            //load the glyph
            Typeface typeFace;

            using (var fs = Utility.ReadFile(Utility.FontDir + fontFileName))
            {
                var reader = new OpenFontReader();
                typeFace = reader.Read(fs);
            }
            Glyph  glyph       = typeFace.Lookup(character);
            Bounds boundingBox = typeFace.Bounds;
            short  ascender    = typeFace.Ascender;

            //read polygons and quadratic bezier segments
            GlyphLoader.Read(glyph, out var polygons, out var quadraticBezierSegments);

            //The actual position of points should apply ascender offset
            var offset = new Vector(0, ascender);

            // draw to an image
            using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.Argb32,
                                                                       boundingBox.XMax - boundingBox.XMin,
                                                                       boundingBox.YMax - boundingBox.YMin))
                using (Cairo.Context g = new Cairo.Context(surface))
                {
                    //set surface back ground to white (1,1,1,1)
                    g.SetSourceColor(CairoEx.ColorWhite);
                    g.Paint();

                    //polygons
                    for (var i = 0; i < polygons.Count; i++)
                    {
                        var polygon    = polygons[i];
                        var startPoint = polygon[0] + offset;
                        g.MoveTo(startPoint.X, startPoint.Y);
                        var previousPoint = startPoint;
                        foreach (var point in polygon)
                        {
                            var p = point + offset;
                            g.LineTo(p.X, p.Y);
                            g.DrawArrow(previousPoint, p);
                            previousPoint = p;
                        }
                        g.LineTo(startPoint.X, startPoint.Y);
                        g.DrawArrow(previousPoint, startPoint);
                    }
                    g.LineWidth = polygonLineWidth;
                    g.SetSourceColor(polygonColor.ToCairoColor());
                    g.Stroke();

                    //quadratic bezier segments
                    foreach (var segment in quadraticBezierSegments)
                    {
                        var p0 = segment.Item1 + offset;
                        var c  = segment.Item2 + offset;
                        var p1 = segment.Item3 + offset;
                        g.MoveTo(p0.X, p0.Y);
                        g.QuadraticTo(c.X, c.Y, p1.X, p1.Y);
                    }
                    g.LineWidth = quadraticLineWidth;
                    g.SetSourceColor(quadraticSegmentColor.ToCairoColor());
                    g.Stroke();

                    //start points
                    g.SetSourceColor(startPointColor.ToCairoColor());
                    for (var i = 0; i < polygons.Count; i++)
                    {
                        var polygon    = polygons[i];
                        var startPoint = polygon[0] + offset;
                        g.Arc(startPoint.x, startPoint.y, 10, 0, System.Math.PI * 2);
                        g.Fill();
                    }

                    //show the image of contours
                    var path = $"{OutputDir}{Path.DirectorySeparatorChar}{fontFileName}_{character}.png";
                    surface.WriteToPng(path);
                    Util.OpenImage(path);
                }
        }
Exemple #12
0
        public override void Draw(TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
        {
            if (Debugger.DebuggingService.IsDebugging)
            {
                return;
            }
            int markerStart = Segment.Offset;
            int markerEnd   = Segment.EndOffset;

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

            bool drawOverlay = result.InspectionMark == IssueMarker.GrayOut;

            if (drawOverlay && editor.IsSomethingSelected)
            {
                var selectionRange = editor.SelectionRange;
                if (selectionRange.Contains(markerStart) && selectionRange.Contains(markerEnd))
                {
                    return;
                }
                if (selectionRange.Contains(markerEnd))
                {
                    markerEnd = selectionRange.Offset;
                }
                if (selectionRange.Contains(markerStart))
                {
                    markerStart = selectionRange.EndOffset;
                }
                if (markerEnd <= markerStart)
                {
                    return;
                }
            }

            double drawFrom;
            double drawTo;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                drawTo = endXPos;
                var line   = editor.GetLineByOffset(startOffset);
                int offset = line.GetIndentation(editor.Document).Length;
                drawFrom = startXPos + (layout.IndexToPos(offset).X / Pango.Scale.PangoScale);
            }
            else
            {
                int start;
                if (startOffset < markerStart)
                {
                    start = markerStart;
                }
                else
                {
                    var line   = editor.GetLineByOffset(startOffset);
                    int offset = line.GetIndentation(editor.Document).Length;
                    start = startOffset + offset;
                }
                int end = endOffset < markerEnd ? endOffset : markerEnd;
                int x_pos;

                x_pos    = layout.IndexToPos(start - startOffset).X;
                drawFrom = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
                x_pos    = layout.IndexToPos(end - startOffset).X;

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

            drawFrom = System.Math.Max(drawFrom, editor.TextViewMargin.XOffset);
            drawTo   = System.Math.Max(drawTo, editor.TextViewMargin.XOffset);
            if (drawFrom >= drawTo)
            {
                return;
            }

            double height = editor.LineHeight / 5;

            cr.SetSourceColor(GetColor(editor, Result));
            if (drawOverlay)
            {
                cr.Rectangle(drawFrom, y, drawTo - drawFrom, editor.LineHeight);
                var color = editor.ColorStyle.PlainText.Background;
                color.A = 0.6;
                cr.SetSourceColor(color);
                cr.Fill();
            }
            else if (result.InspectionMark == IssueMarker.WavedLine)
            {
                Pango.CairoHelper.ShowErrorUnderline(cr, drawFrom, y + editor.LineHeight - height, drawTo - drawFrom, height);
            }
            else if (result.InspectionMark == IssueMarker.DottedLine)
            {
                cr.Save();
                cr.LineWidth = 1;
                cr.MoveTo(drawFrom + 1, y + editor.LineHeight - 1 + 0.5);
                cr.RelLineTo(System.Math.Min(drawTo - drawFrom, 4 * 3), 0);
                cr.SetDash(new double[] { 2, 2 }, 0);
                cr.Stroke();
                cr.Restore();
            }
            else
            {
                cr.MoveTo(drawFrom, y + editor.LineHeight - 1);
                cr.LineTo(drawTo, y + editor.LineHeight - 1);
                cr.Stroke();
            }
        }
        public override void DrawEditor(IBitmapView view)
        {
            Gdk.Drawable  target             = ((FloatPixmapViewWidget)view).GdkWindow;
            Gdk.Rectangle image_position     = ((FloatPixmapViewWidget)view).CurrentImagePosition;
            ToneStageOperationParameters pms = (ToneStageOperationParameters)Parameters;


            Gdk.GC gc = new Gdk.GC(target);

            gc.Function = Gdk.Function.Copy;

            if (pms.AutoDarkTone)
            {
                // Drawing dark selection
                Point scrDarkCenter = new Point(image_position.X + (int)(pms.AutoDarkCenter.X * view.Image.Width),
                                                image_position.Y + (int)(pms.AutoDarkCenter.Y * view.Image.Height));
                double scrDarkRadius = pms.AutoDarkRadius * (view.Image.Width + view.Image.Height) / 2;

                using (Cairo.Context cc = Gdk.CairoHelper.Create(target))
                {
                    cc.LineCap  = Cairo.LineCap.Round;
                    cc.LineJoin = Cairo.LineJoin.Round;

                    cc.Color = new Cairo.Color(1, 1, 1, 0.3);

                    cc.LineWidth = 3;
                    cc.Arc(scrDarkCenter.X, scrDarkCenter.Y, scrDarkRadius, 0, 2 * Math.PI);
                    cc.ClosePath();
                    cc.Stroke();

                    cc.Color = new Cairo.Color(0, 0, 0, 1);

                    cc.LineWidth = 1;
                    cc.SetDash(new double[] { 3, 3 }, 0);
                    cc.Arc(scrDarkCenter.X, scrDarkCenter.Y, scrDarkRadius, 0, 2 * Math.PI);
                    cc.ClosePath();
                    cc.Stroke();
                }
            }

            if (pms.AutoLightTone)
            {
                // Drawing light selection
                Point scrLightCenter = new Point(image_position.X + (int)(pms.AutoLightCenter.X * view.Image.Width),
                                                 image_position.Y + (int)(pms.AutoLightCenter.Y * view.Image.Height));
                double scrLightRadius = pms.AutoLightRadius * (view.Image.Width + view.Image.Height) / 2;

                using (Cairo.Context cc = Gdk.CairoHelper.Create(target))
                {
                    cc.LineCap  = Cairo.LineCap.Round;
                    cc.LineJoin = Cairo.LineJoin.Round;

                    cc.Color = new Cairo.Color(0, 0, 0, 0.3);

                    cc.LineWidth = 3;
                    cc.Arc(scrLightCenter.X, scrLightCenter.Y, scrLightRadius, 0, 2 * Math.PI);
                    cc.ClosePath();
                    cc.Stroke();

                    cc.Color = new Cairo.Color(1, 1, 1, 1);

                    cc.LineWidth = 1;
                    cc.SetDash(new double[] { 3, 3 }, 0);
                    cc.Arc(scrLightCenter.X, scrLightCenter.Y, scrLightRadius, 0, 2 * Math.PI);
                    cc.ClosePath();
                    cc.Stroke();
                }
            }
        }
Exemple #14
0
        public void Draw(Gdk.Drawable window, Cairo.Context ctx, Gdk.Rectangle bounds, StateType state)
        {
            if (noise == null)
            {
                return;
            }

            var drawBounds  = GraphAreaFromBounds(new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height));
            var outerBounds = drawBounds.Inflated(3);

            // Outer clip area
            ctx.Save();
            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Clip();

            var colorSelectedBackground = WidgetTools.ColorSelectedBackground;
            var colorBorder             = WidgetTools.ColorBorder;
            var colorLine = WidgetTools.ColorLine;

            // Background
            if (state == StateType.Selected)
            {
                WidgetTools.SetColor(ctx, colorSelectedBackground);
                ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
                ctx.Fill();
            }

            // Border
            WidgetTools.SetColor(ctx, colorBorder);
            ctx.LineWidth = 1.0;
            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Stroke();

            // Zero line
            if (HasZeroLine)
            {
                var height = ToScreen(Vector2.Zero, drawBounds);
                WidgetTools.SetColor(ctx, colorBorder);
                ctx.MoveTo(outerBounds.X, height.Y);
                ctx.LineTo(outerBounds.X + outerBounds.Width, height.Y);
                ctx.LineWidth = 1.0;
                WidgetTools.SetDash(ctx, true);
                ctx.Stroke();
            }

            ////// Inner clip area
            ////ctx.Rectangle(drawBounds.X, drawBounds.Y, drawBounds.Width, drawBounds.Height);
            ////ctx.Clip();

            //if (noise.Count > 0)
            {
                WidgetTools.SetColor(ctx, colorLine);

                int numSteps = (int)drawBounds.Width;

                var p = Evaluate(0, drawBounds);
                ctx.MoveTo(p.X, p.Y);
                ctx.LineWidth = 1.2;
                WidgetTools.SetDash(ctx, false);

                int part = 0;

                for (int i = 0; numSteps > 0 && i <= numSteps; i++)
                {
                    var fraction = (float)i / numSteps;

                    //if (fraction >= startFraction && part == 0)
                    //{
                    //    p = ToScreen(noise.Front.Value, drawBounds);
                    //    ctx.LineTo(p.X, p.Y);
                    //    ctx.Stroke();
                    //    SetDash(ctx, false);
                    //    ctx.MoveTo(p.X, p.Y);

                    //    part++;
                    //}

                    //if (fraction >= endFraction && part == 1)
                    //{
                    //    p = ToScreen(noise.End.Value, drawBounds);
                    //    ctx.LineTo(p.X, p.Y);
                    //    ctx.Stroke();
                    //    SetDash(ctx, true);
                    //    ctx.MoveTo(p.X, p.Y);

                    //    part++;
                    //}

                    p = Evaluate(fraction, drawBounds);
                    ctx.LineTo(p.X, p.Y);
                }

                ctx.Stroke();
                //SetDash(ctx, false);

                //foreach (var entry in noise)
                //{
                //    var b = ToScreen(entry.Value, drawBounds);
                //    float size = 4;
                //    float outerSize = size + 1;

                //    var color = colorLine;
                //    var outerColor = MG.Framework.Numerics.Color.Transparent;


                //    if (outerColor.A != 0)
                //    {
                //        SetColor(ctx, outerColor);
                //        ctx.Rectangle(b.X - outerSize / 2, b.Y - outerSize / 2, outerSize, outerSize);
                //        ctx.LineWidth = 1.0;
                //        ctx.Stroke();
                //    }

                //    SetColor(ctx, color);
                //    ctx.Rectangle(b.X - size / 2, b.Y - size / 2, size, size);
                //    ctx.Fill();
                //}
            }

            ctx.Restore();
        }
Exemple #15
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (!painting || offset.IsNotSet ())
                return;

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.IsNotSet ()) {
                last_point = new Point (x, y);
                return;
            }

            using (Cairo.Context g = new Cairo.Context (PintaCore.Layers.ToolLayer.Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = Cairo.Antialias.Subpixel;

                g.MoveTo (last_point.X, last_point.Y);
                g.LineTo (x, y);

                g.SetSource (PintaCore.Workspace.ActiveDocument.CurrentLayer.Surface, offset.X, offset.Y);
                g.LineWidth = BrushWidth;
                g.LineCap = Cairo.LineCap.Round;

                g.Stroke ();
            }

            var dirty_rect = GetRectangleFromPoints (last_point, new Point (x, y));

            last_point = new Point (x, y);
            surface_modified = true;
            PintaCore.Workspace.Invalidate (dirty_rect);
        }
Exemple #16
0
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            if (0 == CurrentData.GetCurrentValueByIdFloat(XIVELY_DATA_STREAM_ID))
            {
                pumpON = false;
            }
            else
            {
                pumpON = true;
            }


            X = x;
            Y = y;
            int rectSideWidth  = Radius / 20;
            int rectSideLenght = Radius;
            int pumphead       = Radius / 5;

            surface.SetSourceRGB(0.3, 0.3, 0.3);
            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            surface.SetSourceRGBA(1, 1, 1, pumpLight);
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();
            surface.Fill();

            surface.SetSourceRGB(0.5, 0.5, 0.5);
            surface.Rectangle(X - (Radius / 2), Y - (Radius / 2), rectSideLenght, rectSideLenght);                                      // Middle
            surface.Fill();

            surface.SetSourceRGB(0, 0, 0);
            surface.Rectangle(X - (Radius / 2), Y - (Radius / 2), rectSideWidth, rectSideLenght);                       // Left
            surface.Rectangle(X + (Radius / 2) - rectSideWidth, Y - (Radius / 2), rectSideWidth, rectSideLenght);       // Right
            surface.Rectangle(X - (Radius / 2), Y - (Radius / 2), rectSideLenght, rectSideWidth);                       // Top
            surface.Rectangle(X - (Radius / 2), Y + (Radius / 2) - rectSideWidth, rectSideLenght, rectSideWidth);       // Bottom
            surface.Fill();

            surface.Rectangle(X - (Radius / 2) - pumphead, Y, pumphead, pumphead);
            surface.Fill();

            surface.SetSourceRGB(0.5, 0.5, 0.5);
            surface.Rectangle(X - (Radius / 2) - pumphead, Y + (pumphead / 2 / 2), (pumphead * 2), (pumphead / 2));
            surface.Fill();

            surface.SetSourceRGB(0, 0, 0);
            surface.Rectangle(X, Y - (Radius / 2) - pumphead, pumphead, pumphead);
            surface.Fill();

            surface.SetSourceRGB(0.5, 0.5, 0.5);
            surface.Rectangle(X + (pumphead / 2 / 2), Y - (Radius / 2) - (pumphead), (pumphead / 2), (pumphead * 2));
            surface.Fill();


            // - ON / OFF
            surface.SetSourceRGB(0.1, 0.1, 0.1);
            surface.Arc(X + Radius / 4, Y + Radius / 4, Radius / 10, 0, Math.PI * 2);
            surface.Stroke();
            if (pumpON == true)
            {
                surface.SetSourceRGB(0, 0.5, 0);
            }
            else
            {
                surface.SetSourceRGB(0.5, 0, 0);
            }


            surface.Arc(X + Radius / 4, Y + Radius / 4, Radius / 10, 0, Math.PI * 2);
            surface.Fill();
        }
        private bool DrawPreview()
        {
            Console.WriteLine(OldRefreshRate + "--------" + RefreshRate);

            if (OldRefreshRate == RefreshRate)
            {
                if (!moving_mouse)
                {
                    Console.WriteLine("Drawing with ref rate..." + RefreshRate);

                    int width  = 0;
                    int height = 0;

                    if (!BtnPressed)
                    {
                        try{
                            root = Gdk.Global.DefaultRootWindow;

                            // get its width and height
                            root.GetSize(out width, out height);
                            // create a new pixbuf from the root window
                            //try{
                            //LliureXMiniScreen.Core.getCore().win.Hide();
                            screenshot = Gdk.Pixbuf.FromDrawable(root, root.Colormap, 0, 0, 0, 0, width, height);

                            int miniscreen_size_x, miniscreen_size_y;                                   // dimensions de la minipantalla
                            int px, py, win_px, win_py;
                            if (LliureXMiniScreen.Core.getCore().win != null)
                            {
                                LliureXMiniScreen.Core.getCore().win.GetPosition(out win_px, out win_py);
                                MiniScreen.GetSizeRequest(out miniscreen_size_x, out miniscreen_size_y);
                                px = MiniScreenPosition * (width - miniscreen_size_x);
                                py = height - miniscreen_size_y;

                                Console.WriteLine("Dibuixe en: (" + px + "," + py + ") una finestra de " + miniscreen_size_x + "x" + miniscreen_size_y);
                                if (px != win_px || py != win_py)
                                {
                                    LliureXMiniScreen.Core.getCore().win.Move(px, py);
                                }

                                // Amaguem la minipantallla

                                // PATCH
                                //Gdk.Pixbuf HiddenMiniScreen=new Pixbuf("/usr/share/icons/LliureX-Accessibility/llx-miniscreen-hide.png", miniscreen_size_x, miniscreen_size_y);
                                HiddenMiniScreen = new Pixbuf(InitScreenshot, px, py, MiniScreenWidth, MiniScreenHeight);

                                // END PATCH

                                Console.WriteLine("->" + HiddenMiniScreen.Width + " " + HiddenMiniScreen.Height);
                                HiddenMiniScreen = HiddenMiniScreen.ScaleSimple(miniscreen_size_x, miniscreen_size_y, InterpType.Bilinear);
                                HiddenMiniScreen.CopyArea(0, 0, miniscreen_size_x, miniscreen_size_y,
                                                          screenshot, px, py);
                            }

                            //LliureXMiniScreen.Core.getCore().win.Activate();
                            //	LliureXMiniScreen.Core.getCore().win.Show();

                            /*} catch (Exception exc){
                             *      Console.WriteLine("Excepció...: "+exc);
                             * }*/

                            //Gdk.Pixbuf screenshot = Gdk.Pixbuf.FromDrawable(root, root.Colormap, 0,0, 0,0, width, height);
                            //
                            // Cal inserir una imatge al screenshot per poder ocultar la minifinestra a la captura!!!
                            //
                            screenshot = screenshot.ScaleSimple(this.MiniScreenWidth, this.MiniScreenHeight, InterpType.Bilinear);
                        }catch (Exception exc) {
                            Console.WriteLine("Excepció...: " + exc);
                        }
                    }

                    // Creem la imatge per emmagatzemar el pixbuf

                    Gtk.Image MyImage = new Gtk.Image();
                    MyImage.Pixbuf = screenshot;

                    // Agafem les dimensions de la finestra
                    Gdk.GC gc = ((Gtk.DrawingArea)MiniScreen).Style.TextGC(Gtk.StateType.Normal);

                    MiniScreen.GdkWindow.DrawPixbuf(gc, MyImage.Pixbuf, 0, 0, 0, 0, this.MiniScreenWidth, this.MiniScreenHeight, Gdk.RgbDither.Max, 0, 0);

                    Cairo.Context context = Gdk.CairoHelper.Create(MiniScreen.GdkWindow);

                    if (BtnPressed)
                    {
                        double r = double.Parse((PathColor.Red).ToString()) / 65535;
                        double g = double.Parse((PathColor.Green).ToString()) / 65535;
                        double b = double.Parse((PathColor.Blue).ToString()) / 65535;

                        context.Color = new Cairo.Color(r, g, b);

                        try{
                            if (Llista_Punts.Count > 1)
                            {
                                context.LineWidth = 3;
                                context.MoveTo(Llista_Punts[0].X, Llista_Punts[0].Y);
                                foreach (Gdk.Point p in Llista_Punts)
                                {
                                    context.LineTo(p.X, p.Y);
                                    context.MoveTo(p.X, p.Y);
                                }
                            }
                            context.Stroke();
                            context.FillPreserve();
                        }

                        catch (Exception ex) {
                            Console.WriteLine("Exception: " + ex.Message);
                        }
                    }

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


                    return(true);
                }
            }
            else
            {
                //if(RefreshRate!=OldRefreshRate){
                Console.WriteLine("Change refresg rate!!!");
                OldRefreshRate = RefreshRate;
                return(false);
                //}
            }
            return(false);
        }
Exemple #18
0
        public override void Render(Cairo.Context context, Point scale)
        {
            base.Render(context, scale);

            int idx    = 0;
            int length = Count;

            int endidx;

            endidx = Math.Min(idx + length, d_alpha.Count);

            context.SetSourceRGB(Color.R, Color.G, Color.B);
            context.LineWidth = LineWidth;

            if (d_lengthType == LengthType.Pixel && !SameScale(scale))
            {
                d_scale = scale.Copy();
                RecalculatePixelLength();
            }

            for (int i = idx; i < endidx; ++i)
            {
                Point item = PrivateData[i];

                // In pixel space
                double px = scale.X * item.X;
                double py = scale.Y * item.Y;

                // dx, dy from px, py to where to draw the line
                double pdx = d_lengthNorm[i] * scale.X * d_cosAlpha[i];
                double pdy = d_lengthNorm[i] * scale.Y * d_sinAlpha[i];

                double l = Math.Sqrt(pdx * pdx + pdy * pdy);

                if (MarkerStyle == MarkerStyle.Circle)
                {
                    // Start at the edge of the circle
                    px += 0.5 * MarkerSize / l * pdx;
                    py += 0.5 * MarkerSize / l * pdy;
                }

                context.MoveTo(px, py);

                // Scaling of pdx/pdy to incorporate arrow head
                double s   = 1;
                double ars = MarkerSize;

                if (d_arrowHeadSize > 0)
                {
                    ars = d_arrowHeadSize;
                }

                if (d_drawArrowHead)
                {
                    s = (l - ars) / l;
                }

                double pendx = px + pdx * s;
                double pendy = py + pdy * s;

                context.LineTo(pendx, pendy);
                context.Stroke();

                if (d_drawArrowHead)
                {
                    context.MoveTo(px + pdx, py + pdy);
                    context.LineTo(pendx - 0.5 * pdy * (1 - s), pendy + 0.5 * pdx * (1 - s));
                    context.LineTo(pendx + 0.5 * pdy * (1 - s), pendy - 0.5 * pdx * (1 - s));
                    context.ClosePath();

                    //context.LineTo(ppx - l * (pdx - pdy * 0.5), ppy - l * (pdy + pdx * 0.5));
                    //context.ClosePath();

                    if (MarkerStyle == MarkerStyle.FilledCircle ||
                        MarkerStyle == MarkerStyle.FilledSquare ||
                        MarkerStyle == MarkerStyle.FilledTriangle)
                    {
                        context.Fill();
                    }
                    else
                    {
                        context.Stroke();
                    }
                }
            }
        }
            protected override bool OnExposeEvent(Gdk.EventExpose e)
            {
                using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) {
                    cr.LineWidth = Math.Max(1.0, widget.Editor.Options.Zoom);

                    cr.Rectangle(leftSpacer, 0, Allocation.Width, Allocation.Height);
                    cr.SetSourceRGB(0.95, 0.95, 0.95);
                    cr.Fill();

                    int    startLine = widget.Editor.YToLine((int)widget.Editor.VAdjustment.Value);
                    double startY    = widget.Editor.LineToY(startLine);
                    while (startLine > 1 && startLine < annotations.Count && annotations[startLine - 1] != null && annotations[startLine] != null && annotations[startLine - 1].Revision == annotations[startLine].Revision)
                    {
                        startLine--;
                        startY -= widget.Editor.GetLineHeight(widget.Editor.Document.GetLine(startLine));
                    }
                    double curY = startY - widget.Editor.VAdjustment.Value;
                    int    line = startLine;
                    while (curY < Allocation.Bottom && line <= widget.Editor.LineCount)
                    {
                        double curStart = curY;
//						widget.JumpOverFoldings (ref line);
                        int        lineStart = line;
                        int        authorWidth = 0, revisionWidth = 0, dateWidth = 0, h = 16;
                        Annotation ann = line <= annotations.Count ? annotations[line - 1] : null;
                        if (ann != null)
                        {
                            do
                            {
                                widget.JumpOverFoldings(ref line);
                                line++;
                            } while (line <= annotations.Count && annotations[line - 1] != null && annotations[line - 1].Revision == ann.Revision);

                            double nextY = widget.editor.LineToY(line) - widget.editor.VAdjustment.Value;
                            if (highlightAnnotation != null && highlightAnnotation.Revision == ann.Revision && curStart <= highlightPositon && highlightPositon < nextY)
                            {
                                cr.Rectangle(leftSpacer, curStart + cr.LineWidth, Allocation.Width - leftSpacer, nextY - curStart - cr.LineWidth);
                                cr.SetSourceRGB(1, 1, 1);
                                cr.Fill();
                            }

                            // use a fixed size revision to get a approx. revision width
                            layout.SetText("88888888");
                            layout.GetPixelSize(out revisionWidth, out h);
                            layout.SetText(TruncRevision(ann.Revision));
                            e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout);

                            const int dateRevisionSpacing = 16;
                            if (ann.HasDate)
                            {
                                string dateTime = ann.Date.ToShortDateString();
                                // use a fixed size date to get a approx. date width
                                layout.SetText(new DateTime(1999, 10, 10).ToShortDateString());
                                layout.GetPixelSize(out dateWidth, out h);
                                layout.SetText(dateTime);
                                e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout);
                            }

                            using (var authorLayout = PangoUtil.CreateLayout(this)) {
                                var description = Pango.FontDescription.FromString("Tahoma " + (int)(10 * widget.Editor.Options.Zoom));
                                authorLayout.FontDescription = description;
                                authorLayout.SetText(ann.Author);
                                authorLayout.GetPixelSize(out authorWidth, out h);

                                var maxWidth = Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing;

                                /*				if (authorWidth > maxWidth) {
                                 *                                      int idx = ann.Author.IndexOf ('<');
                                 *                                      if (idx > 0)
                                 *                                              authorLayout.SetText (ann.Author.Substring (0, idx) + Environment.NewLine + ann.Author.Substring (idx));
                                 *                                      authorLayout.GetPixelSize (out authorWidth, out h);
                                 *                              }*/

                                cr.Save();
                                cr.Rectangle(0, 0, maxWidth, Allocation.Height);
                                cr.Clip();
                                cr.Translate(leftSpacer + margin, (int)(curY + (widget.Editor.LineHeight - h) / 2));
                                cr.SetSourceRGB(0, 0, 0);
                                cr.ShowLayout(authorLayout);
                                cr.ResetClip();
                                cr.Restore();
                            }

                            curY = nextY;
                        }
                        else
                        {
                            curY += widget.Editor.GetLineHeight(line);
                            line++;
                            widget.JumpOverFoldings(ref line);
                        }

                        if (ann != null && line - lineStart > 1)
                        {
                            string msg = GetCommitMessage(lineStart, false);
                            if (!string.IsNullOrEmpty(msg))
                            {
                                msg = FormatMessage(msg);

                                layout.SetText(msg);
                                layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale);
                                using (var gc = new Gdk.GC(e.Window)) {
                                    gc.RgbFgColor    = Style.Dark(State);
                                    gc.ClipRectangle = new Rectangle(0, (int)curStart, Allocation.Width, (int)(curY - curStart));
                                    e.Window.DrawLayout(gc, (int)(leftSpacer + margin), (int)(curStart + h), layout);
                                }
                            }
                        }

                        cr.Rectangle(0, curStart, leftSpacer, curY - curStart);

                        if (ann != null && ann != locallyModified && !string.IsNullOrEmpty(ann.Author))
                        {
                            double a;

                            if (ann != null && (maxDate - minDate).TotalHours > 0)
                            {
                                a = 1 - (ann.Date - minDate).TotalHours / (maxDate - minDate).TotalHours;
                            }
                            else
                            {
                                a = 1;
                            }
                            HslColor color = new Cairo.Color(0.90, 0.90, 1);
                            color.L = 0.4 + a / 2;
                            color.S = 1 - a / 2;
                            cr.SetSourceColor(color);
                        }
                        else
                        {
                            cr.SetSourceColor(ann != null ? new Cairo.Color(1, 1, 0) : new Cairo.Color(0.95, 0.95, 0.95));
                        }
                        cr.Fill();

                        if (ann != null)
                        {
                            cr.MoveTo(0, curY + 0.5);
                            cr.LineTo(Allocation.Width, curY + 0.5);
                            cr.SetSourceRGB(0.6, 0.6, 0.6);
                            cr.Stroke();
                        }
                    }
                }
                return(true);
            }
Exemple #20
0
 public override void Stroke(object backend)
 {
     Cairo.Context ctx = ((CairoContextBackend)backend).Context;
     ctx.Stroke();
 }
Exemple #21
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            Gdk.Rectangle rect = Allocation;

            //Gdk.Rectangle.Right and Bottom are inconsistent
            int right = rect.X + rect.Width, bottom = rect.Y + rect.Height;

            var bcolor = backgroundColorSet ? BackgroundColor : Style.Background(Gtk.StateType.Normal);

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                if (GradientBackround)
                {
                    cr.NewPath();
                    cr.MoveTo(rect.X, rect.Y);
                    cr.RelLineTo(rect.Width, 0);
                    cr.RelLineTo(0, rect.Height);
                    cr.RelLineTo(-rect.Width, 0);
                    cr.RelLineTo(0, -rect.Height);
                    cr.ClosePath();

                    // FIXME: VV: Remove gradient features
                    using (Cairo.Gradient pat = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, bottom)) {
                        pat.AddColorStop(0, bcolor.ToCairoColor());
                        Xwt.Drawing.Color gcol = bcolor.ToXwtColor();
                        gcol.Light -= 0.1;
                        if (gcol.Light < 0)
                        {
                            gcol.Light = 0;
                        }
                        pat.AddColorStop(1, gcol.ToCairoColor());
                        cr.SetSource(pat);
                        cr.Fill();
                    }
                }
                else
                {
                    if (backgroundColorSet)
                    {
                        Gdk.GC gc = new Gdk.GC(GdkWindow);
                        gc.RgbFgColor = bcolor;
                        evnt.Window.DrawRectangle(gc, true, rect.X, rect.Y, rect.Width, rect.Height);
                        gc.Dispose();
                    }
                }
            }
            base.OnExposeEvent(evnt);

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                cr.SetSourceColor(BorderColor.ToCairoColor());

                double y = rect.Y + topMargin / 2d;
                cr.LineWidth = topMargin;
                cr.Line(rect.X, y, right, y);
                cr.Stroke();

                y            = bottom - bottomMargin / 2d;
                cr.LineWidth = bottomMargin;
                cr.Line(rect.X, y, right, y);
                cr.Stroke();

                double x = rect.X + leftMargin / 2d;
                cr.LineWidth = leftMargin;
                cr.Line(x, rect.Y, x, bottom);
                cr.Stroke();

                x            = right - rightMargin / 2d;
                cr.LineWidth = rightMargin;
                cr.Line(x, rect.Y, x, bottom);
                cr.Stroke();

                return(false);
            }
        }
Exemple #22
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="showCursor">Whether or not to show the mouse cursor in the drawing.</param>
        /// <param name="useTextLayer">Whether or not to use the TextLayer (as opposed to the Userlayer).</param>
        private void RedrawText(bool showCursor, bool useTextLayer)
        {
            Rectangle r = CurrentTextEngine.GetLayoutBounds();

            r.Inflate(10 + OutlineWidth, 10 + OutlineWidth);
            CurrentTextBounds = r;

            Rectangle cursorBounds = Rectangle.Zero;

            Cairo.ImageSurface surf;

            if (!useTextLayer)
            {
                //Draw text on the current UserLayer's surface as finalized text.
                surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.Surface;
            }
            else
            {
                //Draw text on the current UserLayer's TextLayer's surface as re-editable text.
                surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.TextLayer.Surface;

                ClearTextLayer();
            }

            using (var g = new Cairo.Context(surf)) {
                g.Save();

                // Show selection if on text layer
                if (useTextLayer)
                {
                    // Selected Text
                    Cairo.Color c = new Cairo.Color(0.7, 0.8, 0.9, 0.5);
                    foreach (Rectangle rect in CurrentTextEngine.SelectionRectangles)
                    {
                        g.FillRectangle(rect.ToCairoRectangle(), c);
                    }
                }
                g.AppendPath(PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Clip();

                g.MoveTo(new Cairo.PointD(CurrentTextEngine.Origin.X, CurrentTextEngine.Origin.Y));

                g.Color = PintaCore.Palette.PrimaryColor;

                //Fill in background
                if (BackgroundFill)
                {
                    using (var g2 = new Cairo.Context(surf)) {
                        g2.FillRectangle(CurrentTextEngine.GetLayoutBounds().ToCairoRectangle(), PintaCore.Palette.SecondaryColor);
                    }
                }

                // Draw the text
                if (FillText)
                {
                    Pango.CairoHelper.ShowLayout(g, CurrentTextEngine.Layout);
                }

                if (FillText && StrokeText)
                {
                    g.Color     = PintaCore.Palette.SecondaryColor;
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath(g, CurrentTextEngine.Layout);
                    g.Stroke();
                }
                else if (StrokeText)
                {
                    g.Color     = PintaCore.Palette.PrimaryColor;
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath(g, CurrentTextEngine.Layout);
                    g.Stroke();
                }

                if (showCursor)
                {
                    var loc = CurrentTextEngine.GetCursorLocation();

                    g.Antialias = Cairo.Antialias.None;
                    g.DrawLine(new Cairo.PointD(loc.X, loc.Y), new Cairo.PointD(loc.X, loc.Y + loc.Height), new Cairo.Color(0, 0, 0, 1), 1);

                    cursorBounds = Rectangle.Inflate(loc, 2, 10);
                }

                g.Restore();


                if (useTextLayer && (is_editing || ctrlKey) && !CurrentTextEngine.IsEmpty())
                {
                    //Draw the text edit rectangle.

                    g.Save();

                    g.Translate(.5, .5);

                    using (Cairo.Path p = g.CreateRectanglePath(new Cairo.Rectangle(CurrentTextBounds.Left, CurrentTextBounds.Top,
                                                                                    CurrentTextBounds.Width, CurrentTextBounds.Height - FontSize)))
                    {
                        g.AppendPath(p);
                    }

                    g.LineWidth = 1;

                    g.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    g.SetDash(new double[] { 2, 4 }, 0);
                    g.Color = new Cairo.Color(1, .1, .2);

                    g.Stroke();

                    g.Restore();
                }
            }

            InflateAndInvalidate(PintaCore.Workspace.ActiveDocument.CurrentUserLayer.previousTextBounds);
            PintaCore.Workspace.Invalidate(old_cursor_bounds);
            PintaCore.Workspace.Invalidate(r);
            PintaCore.Workspace.Invalidate(cursorBounds);

            old_cursor_bounds = cursorBounds;
        }
        public bool DrawBackground(TextEditor editor, Cairo.Context g, TextViewMargin.LayoutWrapper layout2, int selectionStart, int selectionEnd, int startOffset, int endOffset, double y, double startXPos, double endXPos, ref bool drawBg)
        {
            if (!IsVisible || DebuggingService.IsDebugging)
            {
                return(true);
            }
            EnsureLayoutCreated(editor);
            double x = editor.TextViewMargin.XOffset;
            int    right = editor.Allocation.Width;
            int    errorCounterWidth = 0;
            bool   isCaretInLine = startOffset <= editor.Caret.Offset && editor.Caret.Offset <= endOffset;
            int    ew = 0, eh = 0;

            if (errors.Count > 1 && errorCountLayout != null)
            {
                errorCountLayout.GetPixelSize(out ew, out eh);
                errorCounterWidth = ew + 10;
            }

            double x2            = System.Math.Max(right - LayoutWidth - border - (ShowIconsInBubble ? errorPixbuf.Width : 0) - errorCounterWidth, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset);
            bool   isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != SelectionMode.Block ? editor.SelectionRange.Contains(lineSegment.Offset + lineSegment.EditableLength) : false;

            int active      = editor.Document.GetTextAt(lineSegment) == initialText ? 0 : 1;
            int highlighted = active == 0 && isCaretInLine ? 1 : 0;
            int selected    = 0;

            double topSize    = Math.Floor(editor.LineHeight / 2);
            double bottomSize = editor.LineHeight / 2 + editor.LineHeight % 2;

            if (!fitsInSameLine)
            {
                if (isEolSelected)
                {
                    x -= (int)editor.HAdjustment.Value;
                    editor.TextViewMargin.DrawRectangleWithRuler(g, x, new Cairo.Rectangle(x, y + editor.LineHeight, editor.TextViewMargin.TextStartPosition, editor.LineHeight), editor.ColorStyle.Default.CairoBackgroundColor, true);
                    editor.TextViewMargin.DrawRectangleWithRuler(g, x + editor.TextViewMargin.TextStartPosition, new Cairo.Rectangle(x + editor.TextViewMargin.TextStartPosition, y + editor.LineHeight, editor.Allocation.Width + (int)editor.HAdjustment.Value, editor.LineHeight), editor.ColorStyle.Selection.CairoBackgroundColor, true);
                    x += (int)editor.HAdjustment.Value;
                }
                else
                {
                    editor.TextViewMargin.DrawRectangleWithRuler(g, x, new Cairo.Rectangle(x, y + editor.LineHeight, x2, editor.LineHeight), editor.ColorStyle.Default.CairoBackgroundColor, true);
                }
            }
            DrawRectangle(g, x, y, right, topSize);
            g.Color = colorMatrix [active, TOP, LIGHT, highlighted, selected];
            g.Fill();
            DrawRectangle(g, x, y + topSize, right, bottomSize);
            g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected];
            g.Fill();

            g.MoveTo(new Cairo.PointD(x, y + 0.5));
            g.LineTo(new Cairo.PointD(x + right, y + 0.5));
            g.Color = colorMatrix [active, TOP, LINE, highlighted, selected];
            g.Stroke();

            g.MoveTo(new Cairo.PointD(x, y + editor.LineHeight - 0.5));
            g.LineTo(new Cairo.PointD((fitsInSameLine ? x + right : x2 + 1), y + editor.LineHeight - 0.5));
            g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
            g.Stroke();
            if (editor.Options.ShowRuler)
            {
                double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                g.MoveTo(new Cairo.PointD(divider + 0.5, y));
                g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight));
                g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
                g.Stroke();
            }

// draw background
            if (layout2.StartSet || selectionStart == endOffset)
            {
                double startX;
                double endX;

                if (selectionStart != endOffset)
                {
                    var start = layout2.Layout.IndexToPos((int)layout2.SelectionStartIndex);
                    startX = (int)(start.X / Pango.Scale.PangoScale);
                    var end = layout2.Layout.IndexToPos((int)layout2.SelectionEndIndex);
                    endX = (int)(end.X / Pango.Scale.PangoScale);
                }
                else
                {
                    startX = x2;
                    endX   = startX;
                }

                if (editor.MainSelection.SelectionMode == SelectionMode.Block && startX == endX)
                {
                    endX = startX + 2;
                }
                startX += startXPos;
                endX   += startXPos;
                startX  = Math.Max(editor.TextViewMargin.XOffset, startX);
// clip region to textviewmargin start
                if (isEolSelected)
                {
                    endX = editor.Allocation.Width + (int)editor.HAdjustment.Value;
                }
                if (startX < endX)
                {
                    DrawRectangle(g, startX, y, endX - startX, topSize);
                    g.Color = colorMatrix [active, TOP, LIGHT, highlighted, 1];
                    g.Fill();
                    DrawRectangle(g, startX, y + topSize, endX - startX, bottomSize);
                    g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, 1];
                    g.Fill();

                    g.MoveTo(new Cairo.PointD(startX, y + 0.5));
                    g.LineTo(new Cairo.PointD(endX, y + 0.5));
                    g.Color = colorMatrix [active, TOP, LINE, highlighted, 1];
                    g.Stroke();

                    if (startX < x2)
                    {
                        g.MoveTo(new Cairo.PointD(startX, y + editor.LineHeight - 0.5));
                        g.LineTo(new Cairo.PointD(System.Math.Min(endX, x2 + 1), y + editor.LineHeight - 0.5));
                        g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, 1];
                        g.Stroke();
                        if (x2 + 1 < endX)
                        {
                            g.MoveTo(new Cairo.PointD(x2 + 1, y + editor.LineHeight - 0.5));
                            g.LineTo(new Cairo.PointD(endX, y + editor.LineHeight - 0.5));
                            g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, 1];
                            g.Stroke();
                        }
                    }

                    if (editor.Options.ShowRuler)
                    {
                        double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                        g.MoveTo(new Cairo.PointD(divider + 0.5, y));
                        g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight));
                        g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, 1];
                        g.Stroke();
                    }
                }
            }

            if (!fitsInSameLine)
            {
                y += editor.LineHeight;
            }
            double y2       = y + 0.5;
            double y2Bottom = y2 + editor.LineHeight - 1;

            selected = isEolSelected && (CollapseExtendedErrors || errors.Count == 1) ? 1 : 0;

// draw message text background
            if (CollapseExtendedErrors || errors.Count == 1)
            {
                if (!fitsInSameLine)
                {
// draw box below line
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2 - 1));
                    g.ClosePath();
                    g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected];
                    g.Fill();

                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2Bottom));
                    g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
                    g.Stroke();
                }
                else
                {
// draw 'arrow marker' in the same line
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2));
                    double mid = y2 + topSize;
                    g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, mid));

                    g.LineTo(new Cairo.PointD(right, mid));
                    g.LineTo(new Cairo.PointD(right, y2));
                    g.ClosePath();
                    g.Color = colorMatrix [active, TOP, DARK, highlighted, selected];
                    g.Fill();
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                    g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, mid));

                    g.LineTo(new Cairo.PointD(right, mid));
                    g.LineTo(new Cairo.PointD(right, y2Bottom));
                    g.ClosePath();

                    g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected];
                    g.Fill();

// draw border
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2));
                    g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, y2 + editor.LineHeight / 2));

                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2));
                    g.ClosePath();

                    g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
                    g.Stroke();
                }
            }
            else
            {
                if (!fitsInSameLine)
                {
// draw box below line
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2 - 1));
                    g.ClosePath();
                }
                else
                {
// draw filled arrow box
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2));
                    g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, y2 + editor.LineHeight / 2));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2));
                    g.ClosePath();
                }
                g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected];
                g.Fill();

// draw light bottom line
                g.MoveTo(new Cairo.PointD(right, y2Bottom));
                g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                g.Stroke();

// stroke left line
                if (fitsInSameLine)
                {
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2));
                    g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, y2 + editor.LineHeight / 2));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                }
                else
                {
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom + 1));
                }

                g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
                g.Stroke();

// stroke top line
                if (fitsInSameLine)
                {
                    g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
                    g.MoveTo(new Cairo.PointD(right, y2));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2));
                    g.Stroke();
                }
            }

            if (editor.Options.ShowRuler)
            {
                double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                if (divider >= x2)
                {
                    g.MoveTo(new Cairo.PointD(divider + 0.5, y2));
                    g.LineTo(new Cairo.PointD(divider + 0.5, y2Bottom));
                    g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected];
                    g.Stroke();
                }
            }

            if (errors.Count > 1 && errorCountLayout != null)
            {
                double rX = x2 + (ShowIconsInBubble ? errorPixbuf.Width : 0) + border + LayoutWidth;
                double rY = y + editor.LineHeight / 6;
                double rW = errorCounterWidth - 2;
                double rH = editor.LineHeight * 3 / 4;
                BookmarkMarker.DrawRoundRectangle(g, rX, rY, 8, rW, rH);

                g.Color = oldIsOver ? new Cairo.Color(0.3, 0.3, 0.3) : new Cairo.Color(0.5, 0.5, 0.5);
                g.Fill();
                if (CollapseExtendedErrors)
                {
                    g.Color = gcLight;
                    g.Save();
                    g.Translate(x2 + (ShowIconsInBubble ? errorPixbuf.Width : 0) + border + LayoutWidth + 4, y + (editor.LineHeight - eh) / 2 + eh % 2);
                    g.ShowLayout(errorCountLayout);
                    g.Restore();
                }
                else
                {
                    g.MoveTo(rX + rW / 2 - rW / 4, rY + rH - rH / 4);
                    g.LineTo(rX + rW / 2 + rW / 4, rY + rH - rH / 4);
                    g.LineTo(rX + rW / 2, rY + rH / 4);
                    g.ClosePath();

                    g.Color = new Cairo.Color(1, 1, 1);
                    g.Fill();
                }
            }

            for (int i = 0; i < layouts.Count; i++)
            {
                LayoutDescriptor layout = layouts [i];
                x2 = right - layout.Width - border - errorPixbuf.Width;
                if (i == 0)
                {
                    x2 -= errorCounterWidth;
                }
                x2 = System.Math.Max(x2, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset);
                if (i > 0)
                {
                    editor.TextViewMargin.DrawRectangleWithRuler(g, x, new Cairo.Rectangle(x, y, right, editor.LineHeight), isEolSelected ? editor.ColorStyle.Selection.CairoBackgroundColor : editor.ColorStyle.Default.CairoBackgroundColor, true);
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y + editor.LineHeight));
                    g.LineTo(new Cairo.PointD(right, y + editor.LineHeight));
                    g.LineTo(new Cairo.PointD(right, y));
                    g.ClosePath();

                    if (CollapseExtendedErrors)
                    {
                        using (var pat = new Cairo.LinearGradient(x2, y, x2, y + editor.LineHeight)) {
                            pat.AddColorStop(0, colorMatrix [active, TOP, LIGHT, highlighted, selected]);
                            pat.AddColorStop(1, colorMatrix [active, BOTTOM, LIGHT, highlighted, selected]);
                            g.Pattern = pat;
                        }
                    }
                    else
                    {
                        g.Color = colorMatrix[active, TOP, LIGHT, highlighted, selected];
                    }
                    g.Fill();
                    if (editor.Options.ShowRuler)
                    {
                        double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                        if (divider >= x2)
                        {
                            g.MoveTo(new Cairo.PointD(divider + 0.5, y));
                            g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight));
                            g.Color = colorMatrix[active, BOTTOM, DARK, highlighted, selected];
                            g.Stroke();
                        }
                    }
                }
                int lw, lh;
                layout.Layout.GetPixelSize(out lw, out lh);
                g.Color = (HslColor)(selected == 0 ? gc : gcSelected);
                g.Save();
                g.Translate(x2 + errorPixbuf.Width + border, y + (editor.LineHeight - layout.Height) / 2 + layout.Height % 2);
                g.ShowLayout(layout.Layout);
                g.Restore();
                y += editor.LineHeight;
                if (!UseVirtualLines)
                {
                    break;
                }
            }
            return(true);
        }
        public bool DrawBackground(TextEditor editor, Cairo.Context g, TextViewMargin.LayoutWrapper layout2, int selectionStart, int selectionEnd, int startOffset, int endOffset, double y, double startXPos, double endXPos, ref bool drawBg)
        {
            if (!IsVisible)
            {
                return(true);
            }
            EnsureLayoutCreated(editor);
            double x                 = editor.TextViewMargin.XOffset;
            int    right             = editor.Allocation.Width;
            bool   isCaretInLine     = startOffset <= editor.Caret.Offset && editor.Caret.Offset <= endOffset;
            var    lineTextPx        = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + layout2.PangoWidth / Pango.Scale.PangoScale;
            int    errorCounterWidth = GetErrorCountBounds(layout2).Item1;
//			int eh = GetErrorCountBounds ().Item2;
            double x2 = System.Math.Max(right - LayoutWidth - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) - errorCounterWidth, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset);

            bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != SelectionMode.Block ? editor.SelectionRange.Contains(lineSegment.Offset + lineSegment.Length) : false;

            int active      = editor.Document.GetTextAt(lineSegment) == initialText ? 0 : 1;
            int highlighted = active == 0 && isCaretInLine ? 1 : 0;
            int selected    = 0;

            double topSize    = Math.Floor(editor.LineHeight / 2);
            double bottomSize = editor.LineHeight / 2 + editor.LineHeight % 2;

            if (!fitsInSameLine)
            {
                if (isEolSelected)
                {
                    x -= (int)editor.HAdjustment.Value;
                    editor.TextViewMargin.DrawRectangleWithRuler(g, x, new Cairo.Rectangle(x, y + editor.LineHeight, editor.TextViewMargin.TextStartPosition, editor.LineHeight), editor.ColorStyle.PlainText.Background, true);
                    editor.TextViewMargin.DrawRectangleWithRuler(g, x + editor.TextViewMargin.TextStartPosition, new Cairo.Rectangle(x + editor.TextViewMargin.TextStartPosition, y + editor.LineHeight, editor.Allocation.Width + (int)editor.HAdjustment.Value, editor.LineHeight), editor.ColorStyle.SelectedText.Background, true);
                    x += (int)editor.HAdjustment.Value;
                }
                else
                {
                    editor.TextViewMargin.DrawRectangleWithRuler(g, x, new Cairo.Rectangle(x, y + editor.LineHeight, x2, editor.LineHeight), editor.ColorStyle.PlainText.Background, true);
                }
            }
            DrawRectangle(g, x, y, right, topSize);
            g.Color = colorMatrix [active, TOP, LIGHT, highlighted, selected];
            g.Fill();
            DrawRectangle(g, x, y + topSize, right, bottomSize);
            g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected];
            g.Fill();

            g.MoveTo(new Cairo.PointD(x, y + 0.5));
            g.LineTo(new Cairo.PointD(x + right, y + 0.5));
            g.Color = colorMatrix [active, TOP, LINE, highlighted, selected];
            g.Stroke();

            g.MoveTo(new Cairo.PointD(x, y + editor.LineHeight - 0.5));
            g.LineTo(new Cairo.PointD((fitsInSameLine ? x + right : x2 + 1), y + editor.LineHeight - 0.5));
            g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
            g.Stroke();
            if (editor.Options.ShowRuler)
            {
                double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                g.MoveTo(new Cairo.PointD(divider + 0.5, y));
                g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight));
                g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
                g.Stroke();
            }

// draw background
            if (layout2.StartSet || selectionStart == endOffset)
            {
                double startX;
                double endX;

                if (selectionStart != endOffset)
                {
                    var start = layout2.Layout.IndexToPos((int)layout2.SelectionStartIndex);
                    startX = (int)(start.X / Pango.Scale.PangoScale);
                    var end = layout2.Layout.IndexToPos((int)layout2.SelectionEndIndex);
                    endX = (int)(end.X / Pango.Scale.PangoScale);
                }
                else
                {
                    startX = x2;
                    endX   = startX;
                }

                if (editor.MainSelection.SelectionMode == SelectionMode.Block && startX == endX)
                {
                    endX = startX + 2;
                }
                startX += startXPos;
                endX   += startXPos;
                startX  = Math.Max(editor.TextViewMargin.XOffset, startX);
// clip region to textviewmargin start
                if (isEolSelected)
                {
                    endX = editor.Allocation.Width + (int)editor.HAdjustment.Value;
                }
                if (startX < endX)
                {
                    DrawRectangle(g, startX, y, endX - startX, topSize);
                    g.Color = colorMatrix [active, TOP, LIGHT, highlighted, 1];
                    g.Fill();
                    DrawRectangle(g, startX, y + topSize, endX - startX, bottomSize);
                    g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, 1];
                    g.Fill();

                    g.MoveTo(new Cairo.PointD(startX, y + 0.5));
                    g.LineTo(new Cairo.PointD(endX, y + 0.5));
                    g.Color = colorMatrix [active, TOP, LINE, highlighted, 1];
                    g.Stroke();

                    if (startX < x2)
                    {
                        g.MoveTo(new Cairo.PointD(startX, y + editor.LineHeight - 0.5));
                        g.LineTo(new Cairo.PointD(System.Math.Min(endX, x2 + 1), y + editor.LineHeight - 0.5));
                        g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, 1];
                        g.Stroke();
                        if (x2 + 1 < endX)
                        {
                            g.MoveTo(new Cairo.PointD(x2 + 1, y + editor.LineHeight - 0.5));
                            g.LineTo(new Cairo.PointD(endX, y + editor.LineHeight - 0.5));
                            g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, 1];
                            g.Stroke();
                        }
                    }

                    if (editor.Options.ShowRuler)
                    {
                        double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                        g.MoveTo(new Cairo.PointD(divider + 0.5, y));
                        g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight));
                        g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, 1];
                        g.Stroke();
                    }
                }
            }

            if (!fitsInSameLine)
            {
                y += editor.LineHeight;
            }
            double y2       = y + 0.5;
            double y2Bottom = y2 + editor.LineHeight - 1;

            selected = isEolSelected && (CollapseExtendedErrors) ? 1 : 0;
            if (x2 < lineTextPx)
            {
                x2 = lineTextPx;
            }

// draw message text background
            if (CollapseExtendedErrors)
            {
                if (!fitsInSameLine)
                {
// draw box below line
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2 - 1));
                    g.ClosePath();
                    g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected];
                    g.Fill();

                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2Bottom));
                    g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
                    g.Stroke();
                }
                else
                {
// draw 'arrow marker' in the same line
                    if (errors.Count > 1)
                    {
                        g.MoveTo(new Cairo.PointD(x2 + 0.5, y2));
                        double mid = y2 + topSize;
                        g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, mid));

                        g.LineTo(new Cairo.PointD(right, mid));
                        g.LineTo(new Cairo.PointD(right, y2));
                        g.ClosePath();
                        g.Color = colorMatrix [active, TOP, DARK, highlighted, selected];
                        g.Fill();
                        g.MoveTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                        g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, mid));

                        g.LineTo(new Cairo.PointD(right, mid));
                        g.LineTo(new Cairo.PointD(right, y2Bottom));
                        g.ClosePath();

                        g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected];
                        g.Fill();
                    }

// draw border
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2));
                    g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, y2 + editor.LineHeight / 2));

                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2));
                    g.ClosePath();

                    g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
                    g.Stroke();
                }
            }
            else
            {
                if (!fitsInSameLine)
                {
// draw box below line
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2Bottom));
                    g.LineTo(new Cairo.PointD(right, y2 - 1));
                    g.ClosePath();
                }
                else
                {
// draw filled arrow box
                    if (!(errors.Count == 1 && !CollapseExtendedErrors))
                    {
                        g.MoveTo(new Cairo.PointD(x2 + 0.5, y2));
                        g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, y2 + editor.LineHeight / 2));
                        g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                        g.LineTo(new Cairo.PointD(right, y2Bottom));
                        g.LineTo(new Cairo.PointD(right, y2));
                        g.ClosePath();
                    }
                }
                g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected];
                g.Fill();

// draw light bottom line
                g.MoveTo(new Cairo.PointD(right, y2Bottom));
                g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                g.Stroke();

// stroke left line
                if (fitsInSameLine)
                {
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2));
                    g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, y2 + editor.LineHeight / 2));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom));
                }
                else
                {
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom + 1));
                }

                g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
                g.Stroke();

// stroke top line
                if (fitsInSameLine)
                {
                    g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
                    g.MoveTo(new Cairo.PointD(right, y2));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y2));
                    g.Stroke();
                }
            }

            if (editor.Options.ShowRuler)
            {
                double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                if (divider >= x2)
                {
                    g.MoveTo(new Cairo.PointD(divider + 0.5, y2));
                    g.LineTo(new Cairo.PointD(divider + 0.5, y2Bottom));
                    g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected];
                    g.Stroke();
                }
            }


            for (int i = 0; i < layouts.Count; i++)
            {
                if (!IsCurrentErrorTextFitting(layout2) && !CollapseExtendedErrors)
                {
                    break;
                }

                var layout = layouts [i];
                x2 = right - layout.Width - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0);
                if (i == 0)
                {
                    x2 -= errorCounterWidth;
                    if (x2 < lineTextPx)
                    {
                        //			if (CollapseExtendedErrors) {
                        x2 = lineTextPx;
                        //			}
                    }
                }
//				x2 = System.Math.Max (x2, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset);

                if (i > 0)
                {
                    editor.TextViewMargin.DrawRectangleWithRuler(g, x, new Cairo.Rectangle(x, y, right, editor.LineHeight), isEolSelected ? editor.ColorStyle.SelectedText.Background : editor.ColorStyle.PlainText.Background, true);
                    g.MoveTo(new Cairo.PointD(x2 + 0.5, y));
                    g.LineTo(new Cairo.PointD(x2 + 0.5, y + editor.LineHeight));
                    g.LineTo(new Cairo.PointD(right, y + editor.LineHeight));
                    g.LineTo(new Cairo.PointD(right, y));
                    g.ClosePath();

                    if (CollapseExtendedErrors)
                    {
                        using (var pat = new Cairo.LinearGradient(x2, y, x2, y + editor.LineHeight)) {
                            pat.AddColorStop(0, colorMatrix [active, TOP, LIGHT, highlighted, selected]);
                            pat.AddColorStop(1, colorMatrix [active, BOTTOM, LIGHT, highlighted, selected]);
                            g.Pattern = pat;
                        }
                    }
                    else
                    {
                        g.Color = colorMatrix [active, TOP, LIGHT, highlighted, selected];
                    }
                    g.Fill();
                    if (editor.Options.ShowRuler)
                    {
                        double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                        if (divider >= x2)
                        {
                            g.MoveTo(new Cairo.PointD(divider + 0.5, y));
                            g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight));
                            g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected];
                            g.Stroke();
                        }
                    }
                }
                g.Color = (HslColor)(selected == 0 ? gc : cache.gcSelected);
                g.Save();
                g.Translate(x2 + (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) + border, y + (editor.LineHeight - layout.Height) / 2 + layout.Height % 2);
                g.ShowLayout(layout.Layout);
                g.Restore();
                y += editor.LineHeight;
                if (!UseVirtualLines)
                {
                    break;
                }
            }
            return(true);
        }
        static void DrawCloseButton(Cairo.Context context, Gdk.Point center, bool hovered, double opacity, double animationProgress)
        {
            if (hovered)
            {
                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;
                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 Cairo.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();
                }
            }
        }
        public void Draw(TextEditor editor, Cairo.Context g, int lineNr, Cairo.Rectangle lineArea)
        {
            EnsureLayoutCreated(editor);
            int lineNumber  = editor.Document.OffsetToLineNumber(lineSegment.Offset);
            int errorNumber = lineNr - lineNumber;

            if (!IsCurrentErrorTextFitting())
            {
                errorNumber--;
            }
            double x                 = editor.TextViewMargin.XOffset;
            double y                 = lineArea.Y;
            double right             = editor.Allocation.Width;
            int    errorCounterWidth = GetErrorCountBounds().Item1;
//			int eh = GetErrorCountBounds ().Item2;

            double x2 = System.Math.Max(right - LayoutWidth - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) - errorCounterWidth, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset);

            if (errors.Count == 1)
            {
                x2 = editor.TextViewMargin.XOffset;
            }
//			bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != SelectionMode.Block ? editor.SelectionRange.Contains (lineSegment.Offset  + lineSegment.EditableLength) : false;
            int  active        = editor.Document.GetTextAt(lineSegment) == initialText ? 0 : 1;
            bool isCaretInLine = lineSegment.Offset <= editor.Caret.Offset && editor.Caret.Offset <= lineSegment.EndOffsetIncludingDelimiter;
            int  highlighted   = active == 0 && isCaretInLine ? 1 : 0;
            int  selected      = 0;
            var  layout        = layouts [errorNumber];

            x2 = right - LayoutWidth - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0);

            x2 -= errorCounterWidth;
            x2  = System.Math.Max(x2, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset);

            g.MoveTo(new Cairo.PointD(x2 + 0.5, y));
            g.LineTo(new Cairo.PointD(x2 + 0.5, y + editor.LineHeight));
            g.LineTo(new Cairo.PointD(right, y + editor.LineHeight));
            g.LineTo(new Cairo.PointD(right, y));
            g.ClosePath();
            g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected];
            g.Fill();

            g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected];
            g.MoveTo(new Cairo.PointD(x2 + 0.5, y));
            g.LineTo(new Cairo.PointD(x2 + 0.5, y + editor.LineHeight));
            if (errorNumber == errors.Count - 1)
            {
                g.LineTo(new Cairo.PointD(lineArea.X + lineArea.Width, y + editor.LineHeight));
            }
            g.Stroke();

            if (editor.Options.ShowRuler)
            {
                double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                if (divider >= x2)
                {
                    g.MoveTo(new Cairo.PointD(divider + 0.5, y));
                    g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight));
                    g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected];
                    g.Stroke();
                }
            }
            g.Save();
            g.Translate(x2 + (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) + border, y + (editor.LineHeight - layout.Height) / 2 + layout.Height % 2);
            g.Color = selected == 0 ? gc : cache.gcSelected;
            g.ShowLayout(layout.Layout);
            g.Restore();

            if (ShowIconsInBubble)
            {
                var pixbuf = errors [errorNumber].IsError ? cache.errorPixbuf: cache.warningPixbuf;
                Gdk.CairoHelper.SetSourcePixbuf(g, pixbuf, x2, y + (editor.LineHeight - cache.errorPixbuf.Height) / 2);
                g.Paint();
            }
        }
        void DrawValue(Cairo.Context ctx, Gdk.GC gc, DateTime initialTime, int ytop, int lx, int tx, ref int ty, ref int maxx, ref int maxy, int indent, CounterValueInfo val)
        {
            Gdk.Color color;
            if (val.Counter != null)
            {
                color = val.Counter.GetColor();
            }
            else
            {
                color = Style.Black;
            }

            // Draw text
            gc.RgbFgColor = color;

            double ms = (val.Time - initialTime).TotalMilliseconds;

            string txt = (ms / 1000).ToString("0.00000") + ": " + (val.Duration.TotalMilliseconds / 1000).ToString("0.00000") + " " + val.Trace;

            layout.SetText(txt);
            GdkWindow.DrawLayout(gc, tx + indent, ty, layout);
            int tw, th;

            layout.GetPixelSize(out tw, out th);
            if (tx + tw + indent > maxx)
            {
                maxx = tx + tw + indent;
            }

            HotSpot hp     = AddHotSpot(tx + indent, ty, tw, th);
            int     tempTy = ty;

            hp.Action = delegate {
                int ytm = ytop + (int)((ms * scale) / 1000);
                SetBaseTime((int)(tempTy + (th / 2) + 0.5) - ytm);
            };
            hp.OnMouseOver += delegate {
                overValue = val;
                QueueDraw();
            };
            hp.Action += delegate {
                focusedValue = val;
                QueueDraw();
            };

            // Draw time marker
            int ytime = ytop + (int)((ms * scale) / 1000) + baseTime;

            if (val == focusedValue || val == overValue)
            {
                ctx.NewPath();
                double dx = val == focusedValue ? 0 : 2;
                ctx.Rectangle(lx + 0.5 + dx - SelectedValuePadding, ytime + 0.5, LineEndWidth - dx * 2 + SelectedValuePadding, ((val.Duration.TotalMilliseconds * scale) / 1000));
                HslColor hsl = color;
                hsl.L     = val == focusedValue ? 0.9 : 0.8;
                ctx.Color = hsl;
                ctx.Fill();
            }

            ctx.NewPath();
            ctx.LineWidth = 1;
            ctx.MoveTo(lx + 0.5, ytime + 0.5);
            ctx.LineTo(lx + LineEndWidth + 0.5, ytime + 0.5);
            ctx.LineTo(tx - 3 - LineEndWidth + 0.5, ty + (th / 2) + 0.5);
            ctx.LineTo(tx + indent - 3 + 0.5, ty + (th / 2) + 0.5);
            ctx.Color = color.ToCairoColor();
            ctx.Stroke();

            // Expander

            bool incLine = true;

            if (val.CanExpand)
            {
                double ex = tx + indent - 3 - ExpanderSize - 2 + 0.5;
                double ey = ty + (th / 2) - (ExpanderSize / 2) + 0.5;
                hp = AddHotSpot(ex, ey, ExpanderSize, ExpanderSize);
                DrawExpander(ctx, ex, ey, val.Expanded, false);
                hp.OnMouseOver = delegate {
                    using (Cairo.Context c = CairoHelper.Create(GdkWindow)) {
                        DrawExpander(c, ex, ey, val.Expanded, true);
                    }
                };
                hp.OnMouseLeave = delegate {
                    using (Cairo.Context c = CairoHelper.Create(GdkWindow)) {
                        DrawExpander(c, ex, ey, val.Expanded, false);
                    }
                };
                hp.Action = delegate {
                    ToggleExpand(val);
                };

                if (val.Expanded && val.ExpandedTimerTraces.Count > 0)
                {
                    ty += th + LineSpacing;
                    foreach (CounterValueInfo cv in val.ExpandedTimerTraces)
                    {
                        DrawValue(ctx, gc, initialTime, ytop, lx, tx, ref ty, ref maxx, ref maxy, indent + ChildIndent, cv);
                    }
                    incLine = false;
                }
            }
            if (incLine)
            {
                ty += th + LineSpacing;
            }

            if (ytime > maxy)
            {
                maxy = ytime;
            }
        }
Exemple #28
0
 public void AddContour(Color color)
 {
     g.ClosePath();
     g.Stroke();
     builder.AppendLine("AddContour.");
 }
Exemple #29
0
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            Cairo.Context cr = Gdk.CairoHelper.Create(e.Window);

            Gdk.Rectangle area = e.Area;

            if (this.categories.Count == 0 || !string.IsNullOrEmpty(CustomMessage))
            {
                Pango.Layout messageLayout = new Pango.Layout(this.PangoContext);
                messageLayout.Alignment = Pango.Alignment.Center;
                messageLayout.Width     = (int)(Allocation.Width * 2 / 3 * Pango.Scale.PangoScale);
                if (!string.IsNullOrEmpty(CustomMessage))
                {
                    messageLayout.SetText(CustomMessage);
                }
                else
                {
                    messageLayout.SetText(MonoDevelop.Core.GettextCatalog.GetString("There are no tools available for the current document."));
                }
                cr.MoveTo(Allocation.Width * 1 / 6, 12);
                cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor());
                Pango.CairoHelper.ShowLayout(cr, messageLayout);
                messageLayout.Dispose();
                ((IDisposable)cr).Dispose();
                return(true);
            }

            var backColor = Style.Base(StateType.Normal).ToCairoColor();

            cr.SetSourceColor(backColor);
            cr.Rectangle(area.X, area.Y, area.Width, area.Height);
            cr.Fill();

            int      xpos             = (this.hAdjustement != null ? (int)this.hAdjustement.Value : 0);
            int      vadjustment      = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0);
            int      ypos             = -vadjustment;
            Category lastCategory     = null;
            int      lastCategoryYpos = 0;

            cr.LineWidth = 1;

            Iterate(ref xpos, ref ypos, delegate(Category category, Gdk.Size itemDimension) {
                const int foldSegmentHeight = 8;

                ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

                if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension)))
                {
                    return(true);
                }
                cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                cr.SetSourceColor(Ide.Gui.Styles.PadCategoryBackgroundColor.ToCairoColor());
                cr.Fill();

                if (lastCategory == null || lastCategory.IsExpanded || lastCategory.AnimatingExpand)
                {
                    cr.MoveTo(xpos, ypos + 0.5);
                    cr.LineTo(itemDimension.Width, ypos + 0.5);
                }
                cr.MoveTo(0, ypos + itemDimension.Height - 0.5);
                cr.LineTo(xpos + Allocation.Width, ypos + itemDimension.Height - 0.5);
                cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryBorderColor.ToCairoColor());
                cr.Stroke();

                headerLayout.SetMarkup(category.Text);
                int width, height;
                cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryLabelColor.ToCairoColor());
                layout.GetPixelSize(out width, out height);
                cr.MoveTo(xpos + CategoryLeftPadding, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2)));
                Pango.CairoHelper.ShowLayout(cr, headerLayout);

                var img = category.IsExpanded ? discloseUp : discloseDown;
                cr.DrawImage(this, img, Allocation.Width - img.Width - CategoryRightPadding, ypos + Math.Round((itemDimension.Height - img.Height) / 2));

                lastCategory     = category;
                lastCategoryYpos = ypos + itemDimension.Height;

                return(true);
            }, delegate(Category curCategory, Item item, Gdk.Size itemDimension) {
                if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension)))
                {
                    return(true);
                }

                var icon = item.Icon;
                if (item == SelectedItem)
                {
                    icon = icon.WithStyles("sel");
                    cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                    cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                    cr.Fill();
                }
                if (listMode || !curCategory.CanIconizeItems)
                {
                    cr.DrawImage(this, icon, xpos + ItemLeftPadding, ypos + Math.Round((itemDimension.Height - icon.Height) / 2));
                    layout.SetMarkup(item.Text);
                    int width, height;
                    layout.GetPixelSize(out width, out height);
                    cr.SetSourceColor(Style.Text(item != this.SelectedItem ? StateType.Normal : StateType.Selected).ToCairoColor());
                    cr.MoveTo(xpos + ItemLeftPadding + IconSize.Width + ItemIconTextItemSpacing, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2)));
                    Pango.CairoHelper.ShowLayout(cr, layout);
                }
                else
                {
                    cr.DrawImage(this, icon, xpos + Math.Round((itemDimension.Width - icon.Width) / 2), ypos + Math.Round((itemDimension.Height - icon.Height) / 2));
                }

                if (item == mouseOverItem)
                {
                    cr.SetSourceColor(Style.Dark(StateType.Prelight).ToCairoColor());
                    cr.Rectangle(xpos + 0.5, ypos + 0.5, itemDimension.Width - 1, itemDimension.Height - 1);
                    cr.Stroke();
                }

                return(true);
            });

            ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

            if (lastCategory != null && lastCategory.AnimatingExpand)
            {
                // Closing line when animating the last group of the toolbox
                cr.MoveTo(area.X, ypos + 0.5);
                cr.RelLineTo(area.Width, 0);
                cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryBorderColor.ToCairoColor());
                cr.Stroke();
            }

            ((IDisposable)cr).Dispose();
            return(true);
        }
Exemple #30
0
            protected override bool OnExposeEvent(Gdk.EventExpose e)
            {
                using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) {
                    cr.LineWidth = Math.Max(1.0, widget.Editor.Options.Zoom);

                    cr.Rectangle(leftSpacer, 0, Allocation.Width, Allocation.Height);
                    cr.Color = new Cairo.Color(0.95, 0.95, 0.95);
                    cr.Fill();

                    int    startLine = widget.Editor.YToLine((int)widget.Editor.VAdjustment.Value);
                    double startY    = widget.Editor.LineToY(startLine);
                    while (startLine > 1 && startLine < annotations.Count && annotations[startLine - 1] != null && annotations[startLine] != null && annotations[startLine - 1].Revision == annotations[startLine].Revision)
                    {
                        startLine--;
                        startY -= widget.Editor.GetLineHeight(widget.Editor.Document.GetLine(startLine));
                    }
                    double curY = startY - widget.Editor.VAdjustment.Value;
                    int    line = startLine;
                    while (curY < Allocation.Bottom)
                    {
                        double curStart = curY;
//						widget.JumpOverFoldings (ref line);
                        int        lineStart = line;
                        int        w = 0, w2 = 0, h = 16;
                        Annotation ann = line <= annotations.Count ? annotations[line - 1] : null;
                        if (ann != null)
                        {
                            do
                            {
                                widget.JumpOverFoldings(ref line);
                                line++;
                            } while (line <= annotations.Count && annotations[line - 1] != null && annotations[line - 1].Revision == ann.Revision);
                            double nextY = widget.editor.LineToY(line) - widget.editor.VAdjustment.Value;
                            if (highlightAnnotation != null && highlightAnnotation.Revision == ann.Revision && curStart <= highlightPositon && highlightPositon < nextY)
                            {
                                cr.Rectangle(leftSpacer, curStart + cr.LineWidth, Allocation.Width - leftSpacer, nextY - curStart - cr.LineWidth);
                                cr.Color = new Cairo.Color(1, 1, 1);
                                cr.Fill();
                            }
                            layout.SetText(ann.Author);
                            layout.GetPixelSize(out w, out h);
                            e.Window.DrawLayout(Style.BlackGC, leftSpacer + margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout);


                            layout.SetText(TruncRevision(ann.Revision));
                            layout.GetPixelSize(out w2, out h);
                            e.Window.DrawLayout(Style.BlackGC, Allocation.Width - w2 - margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout);

                            if (ann.HasDate)
                            {
                                string dateTime = ann.Date.ToShortDateString();
                                int    middle   = w + (Allocation.Width - margin * 2 - leftSpacer - w - w2) / 2;
                                layout.SetText(dateTime);
                                layout.GetPixelSize(out w, out h);
                                e.Window.DrawLayout(Style.BlackGC, leftSpacer + margin + middle - w / 2, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout);
                            }
                            curY = nextY;
                        }
                        else
                        {
                            curY += widget.Editor.GetLineHeight(line);
                            line++;
                            widget.JumpOverFoldings(ref line);
                        }

                        if (ann != null && line - lineStart > 1)
                        {
                            string msg = GetCommitMessage(lineStart);
                            if (!string.IsNullOrEmpty(msg))
                            {
                                msg = FormatMessage(msg);
                                layout.SetText(msg);
                                layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale);
                                using (var gc = new Gdk.GC(e.Window)) {
                                    gc.RgbFgColor    = Style.Dark(State);
                                    gc.ClipRectangle = new Rectangle(0, (int)curStart, Allocation.Width, (int)(curY - curStart));
                                    e.Window.DrawLayout(gc, (int)(leftSpacer + margin), (int)(curStart + h), layout);
                                }
                            }
                        }

                        cr.Rectangle(0, curStart, leftSpacer, curY - curStart);

                        if (ann != null && ann != locallyModified && !string.IsNullOrEmpty(ann.Author))
                        {
                            double a;

                            if (ann != null && (maxDate - minDate).TotalHours > 0)
                            {
                                a = 1 - (ann.Date - minDate).TotalHours / (maxDate - minDate).TotalHours;
                            }
                            else
                            {
                                a = 1;
                            }
                            HslColor color = new Cairo.Color(0.90, 0.90, 1);
                            color.L  = 0.4 + a / 2;
                            color.S  = 1 - a / 2;
                            cr.Color = color;
                        }
                        else
                        {
                            cr.Color = ann != null ? new Cairo.Color(1, 1, 0) : new Cairo.Color(0.95, 0.95, 0.95);
                        }
                        cr.Fill();

                        if (ann != null)
                        {
                            cr.MoveTo(0, curY + 0.5);
                            cr.LineTo(Allocation.Width, curY + 0.5);
                            cr.Color = new Cairo.Color(0.6, 0.6, 0.6);
                            cr.Stroke();
                        }
                    }
                }
                return(true);
            }
Exemple #31
0
        private void RedrawText(bool showCursor, bool useToolLayer)
        {
            Cairo.ImageSurface surf;
            var invalidate_cursor = old_cursor_bounds;

            if (!useToolLayer)
                surf = PintaCore.Workspace.ActiveDocument.CurrentLayer.Surface;
            else {
                surf = PintaCore.Workspace.ActiveDocument.ToolLayer.Surface;
                surf.Clear ();
            }

            using (var g = new Cairo.Context (surf)) {
                g.Save ();

                // Show selection if on tool layer
                if (useToolLayer) {
                    // Selected Text
                    Cairo.Color c = new Cairo.Color (0.7, 0.8, 0.9, 0.5);
                    foreach (Rectangle rect in engine.SelectionRectangles)
                        g.FillRectangle (rect.ToCairoRectangle (), c);
                }
                g.AppendPath (PintaCore.Workspace.ActiveDocument.SelectionPath);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Clip ();
                g.MoveTo (new Cairo.PointD (engine.Origin.X, engine.Origin.Y));
                g.Color = PintaCore.Palette.PrimaryColor;

                if (BackgroundFill)	{

                    using (var g2 = new Cairo.Context (surf)) {

                        g2.FillRectangle (engine.GetLayoutBounds ().ToCairoRectangle (),PintaCore.Palette.SecondaryColor);

                    }
            }

                if (FillText) {
                    Pango.CairoHelper.ShowLayout (g, engine.Layout);
            }

                if (FillText && StrokeText) {
                    g.Color = PintaCore.Palette.SecondaryColor;
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath (g, engine.Layout);
                    g.Stroke ();
                } else if (StrokeText) {
                    g.Color = PintaCore.Palette.PrimaryColor;
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath (g, engine.Layout);
                    g.Stroke ();
                }

                if (showCursor) {
                    var loc = engine.GetCursorLocation ();

                    g.Antialias = Cairo.Antialias.None;
                    g.DrawLine (new Cairo.PointD (loc.X, loc.Y), new Cairo.PointD (loc.X, loc.Y + loc.Height), new Cairo.Color (0, 0, 0, 1), 1);

                    loc.Inflate (2, 10);
                    old_cursor_bounds = loc;
                }

                g.Restore ();
            }

            Rectangle r = engine.GetLayoutBounds ();
            r.Inflate (10 + OutlineWidth, 10 + OutlineWidth);

            PintaCore.Workspace.Invalidate (old_bounds);
            PintaCore.Workspace.Invalidate (invalidate_cursor);
            PintaCore.Workspace.Invalidate (r);

            old_bounds = r;
        }
Exemple #32
0
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) {
                double xPos = padding, yPos = padding;
                var    layout = PangoUtil.CreateLayout(this);
                int    w, h;
                layout.SetText(new string ('X', maxLength));
                layout.GetPixelSize(out w, out h);

                foreach (Category cat in categories)
                {
                    yPos = padding;
                    cr.MoveTo(xPos, yPos);
                    layout.SetMarkup("<b>" + cat.Title + "</b>");
                    cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor());
                    cr.ShowLayout(layout);

                    if (cat.Items.Count == 0)
                    {
                        continue;
                    }

                    layout.SetMarkup("");
                    int w2, h2;
                    layout.GetPixelSize(out w2, out h2);
                    yPos += h2;
                    yPos += headerDistance;
                    var startY     = yPos;
                    int curItem    = 0;
                    int row        = 0;
                    var iconHeight = Math.Max(h, cat.Items [0].Icon.Height + 2) + itemPadding * 2;
                    if (cat.FirstVisibleItem > 0)
                    {
                        Gtk.Style.PaintArrow(Style, e.Window, State, ShadowType.None,
                                             new Rectangle((int)xPos, (int)yPos, w, h),
                                             this,
                                             "",
                                             ArrowType.Up,
                                             true,
                                             (int)xPos,
                                             (int)yPos,
                                             w,
                                             h);
                        yPos += iconHeight;
                        curItem++;
                    }

                    for (int i = cat.FirstVisibleItem; i < cat.Items.Count; i++)
                    {
                        var item = cat.Items [i];

                        if (curItem + 1 >= maxItems && row + 1 >= maxRows && i + 1 < cat.Items.Count)
                        {
                            Gtk.Style.PaintArrow(Style, e.Window, State, ShadowType.None,
                                                 new Rectangle((int)xPos, (int)yPos, w, h),
                                                 this,
                                                 "",
                                                 ArrowType.Down,
                                                 true,
                                                 (int)xPos,
                                                 (int)yPos,
                                                 w,
                                                 h);
                            break;
                        }

                        if (item == ActiveItem)
                        {
                            int itemWidth = w + (int)item.Icon.Width + 2 + itemPadding * 2;
                            cr.Rectangle(xPos, yPos, itemWidth, iconHeight);
                            cr.LineWidth = 1;
                            cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                            cr.Fill();
                        }
                        else if (item == hoverItem)
                        {
                            int itemWidth = w + (int)item.Icon.Width + 2 + itemPadding * 2;
                            cr.Rectangle(xPos + 0.5, yPos + 0.5, itemWidth - 1, iconHeight);
                            cr.LineWidth = 1;
                            cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                            cr.Stroke();
                        }
                        cr.SetSourceColor(Style.Text(item == ActiveItem? StateType.Selected : StateType.Normal).ToCairoColor());
                        cr.MoveTo(xPos + item.Icon.Width + 2 + itemPadding, yPos + (iconHeight - h) / 2);
                        layout.SetText(Ellipsize(item.ListTitle ?? item.Title, maxLength));
                        cr.ShowLayout(layout);
                        cr.DrawImage(this, item == ActiveItem ? item.Icon.WithStyles("sel") : item.Icon, (int)xPos + itemPadding,
                                     (int)(yPos + (iconHeight - item.Icon.Height) / 2));
                        yPos += iconHeight;
                        if (++curItem >= maxItems)
                        {
                            curItem = 0;
                            yPos    = startY;
                            xPos   += w + cat.Items [0].Icon.Width + 2 + padding + itemPadding * 2;
                            row++;
                        }
                    }


                    xPos += w + cat.Items [0].Icon.Width + 2 + padding + itemPadding * 2;
                }
                layout.Dispose();
            }
            return(true);
        }
Exemple #33
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="showCursor">Whether or not to show the mouse cursor in the drawing.</param>
        /// <param name="useTextLayer">Whether or not to use the TextLayer (as opposed to the Userlayer).</param>
        private void RedrawText(bool showCursor, bool useTextLayer)
        {
            Rectangle r = CurrentTextEngine.GetLayoutBounds();
            r.Inflate(10 + OutlineWidth, 10 + OutlineWidth);
            CurrentTextBounds = r;

            Rectangle cursorBounds = Rectangle.Zero;

            Cairo.ImageSurface surf;

            if (!useTextLayer)
            {
                //Draw text on the current UserLayer's surface as finalized text.
                surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.Surface;
            }
            else
            {
                //Draw text on the current UserLayer's TextLayer's surface as re-editable text.
                surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.TextLayer.Surface;

                ClearTextLayer();
            }

            using (var g = new Cairo.Context (surf)) {
                g.Save ();

                // Show selection if on text layer
                if (useTextLayer) {
                    // Selected Text
                    Cairo.Color c = new Cairo.Color (0.7, 0.8, 0.9, 0.5);
                    foreach (Rectangle rect in CurrentTextEngine.SelectionRectangles)
                        g.FillRectangle (rect.ToCairoRectangle (), c);
                }
                g.AppendPath (PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Clip ();

                g.MoveTo (new Cairo.PointD (CurrentTextEngine.Origin.X, CurrentTextEngine.Origin.Y));

                g.Color = PintaCore.Palette.PrimaryColor;

                //Fill in background
                if (BackgroundFill) {
                    using (var g2 = new Cairo.Context (surf)) {
                        g2.FillRectangle(CurrentTextEngine.GetLayoutBounds().ToCairoRectangle(), PintaCore.Palette.SecondaryColor);
                    }
                }

                // Draw the text
                if (FillText)
                    Pango.CairoHelper.ShowLayout (g, CurrentTextEngine.Layout);

                if (FillText && StrokeText) {
                    g.Color = PintaCore.Palette.SecondaryColor;
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath (g, CurrentTextEngine.Layout);
                    g.Stroke ();
                } else if (StrokeText) {
                    g.Color = PintaCore.Palette.PrimaryColor;
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath (g, CurrentTextEngine.Layout);
                    g.Stroke ();
                }

                if (showCursor) {
                    var loc = CurrentTextEngine.GetCursorLocation ();

                    g.Antialias = Cairo.Antialias.None;
                    g.DrawLine (new Cairo.PointD (loc.X, loc.Y), new Cairo.PointD (loc.X, loc.Y + loc.Height), new Cairo.Color (0, 0, 0, 1), 1);

                    cursorBounds = Rectangle.Inflate (loc, 2, 10);
                }

                g.Restore ();

                if (useTextLayer && (is_editing || ctrlKey) && !CurrentTextEngine.IsEmpty())
                {
                    //Draw the text edit rectangle.

                    g.Save();

                    g.Translate(.5, .5);

                    using (Cairo.Path p = g.CreateRectanglePath(new Cairo.Rectangle(CurrentTextBounds.Left, CurrentTextBounds.Top,
                        CurrentTextBounds.Width, CurrentTextBounds.Height - FontSize)))
                    {
                        g.AppendPath(p);
                    }

                    g.LineWidth = 1;

                    g.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    g.SetDash(new double[] { 2, 4 }, 0);
                    g.Color = new Cairo.Color(1, .1, .2);

                    g.Stroke();

                    g.Restore();
                }
            }

            InflateAndInvalidate(PintaCore.Workspace.ActiveDocument.CurrentUserLayer.previousTextBounds);
            PintaCore.Workspace.Invalidate(old_cursor_bounds);
            PintaCore.Workspace.Invalidate(r);
            PintaCore.Workspace.Invalidate(cursorBounds);

            old_cursor_bounds = cursorBounds;
        }
Exemple #34
0
        internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor)
        {
            Gdk.Pixbuf result = null;

            Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault (stockId);
            if (iconset != null) {
                // Find the size that better fits the requested size
                Gtk.IconSize gsize = Util.GetBestSizeFit (width);
                result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor);
                if (result == null || result.Width < width * scaleFactor) {
                    var gsize2x = Util.GetBestSizeFit (width * scaleFactor, iconset.Sizes);
                    if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize)
                        // Don't dispose the previous result since the icon is owned by the IconSet
                        result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null);
                }
            }

            if (result == null && Gtk.IconTheme.Default.HasIcon (stockId))
                result = Gtk.IconTheme.Default.LoadIcon (stockId, (int)width, (Gtk.IconLookupFlags)0);

            if (result == null)
            {
                // render a custom gtk-missing-image icon
                // if Gtk.Stock.MissingImage is not found
                int w = (int)width;
                int h = (int)height;
                #if XWT_GTK3
                Cairo.ImageSurface s = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
                Cairo.Context cr = new Cairo.Context(s);
                cr.SetSourceRGB(255, 255, 255);
                cr.Rectangle(0, 0, w, h);
                cr.Fill();
                cr.SetSourceRGB(0, 0, 0);
                cr.LineWidth = 1;
                cr.Rectangle(0.5, 0.5, w - 1, h - 1);
                cr.Stroke();
                cr.SetSourceRGB(255, 0, 0);
                cr.LineWidth = 3;
                cr.LineCap = Cairo.LineCap.Round;
                cr.LineJoin = Cairo.LineJoin.Round;
                cr.MoveTo(w / 4, h / 4);
                cr.LineTo((w - 1) - w / 4, (h - 1) - h / 4);
                cr.MoveTo(w / 4, (h - 1) - h / 4);
                cr.LineTo((w - 1) - w / 4, h / 4);
                cr.Stroke();
                result = Gtk3Extensions.GetFromSurface(s, 0, 0, w, h);
                #else
                using (Gdk.Pixmap pmap = new Gdk.Pixmap (Gdk.Screen.Default.RootWindow, w, h))
                using (Gdk.GC gc = new Gdk.GC (pmap)) {
                    gc.RgbFgColor = new Gdk.Color (255, 255, 255);
                    pmap.DrawRectangle (gc, true, 0, 0, w, h);
                    gc.RgbFgColor = new Gdk.Color (0, 0, 0);
                    pmap.DrawRectangle (gc, false, 0, 0, (w - 1), (h - 1));
                    gc.SetLineAttributes (3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
                    gc.RgbFgColor = new Gdk.Color (255, 0, 0);
                    pmap.DrawLine (gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4)));
                    pmap.DrawLine (gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4)));
                    result = Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, w, h);
                }
                #endif
            }
            return result;
        }