Ejemplo n.º 1
0
        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.SetSourceColor(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.SetSourceColor(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;
            }
        }
Ejemplo n.º 2
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return(true);
            }

            double scale = PintaCore.Workspace.Scale;

            int x = (int)PintaCore.Workspace.Offset.X;
            int y = (int)PintaCore.Workspace.Offset.Y;

            // Translate our expose area for the whole drawingarea to just our canvas
            Rectangle canvas_bounds = new Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height);

            canvas_bounds.Intersect(e.Area);

            if (canvas_bounds.IsEmpty)
            {
                return(true);
            }

            canvas_bounds.X -= x;
            canvas_bounds.Y -= y;

            // Resize our offscreen surface to a surface the size of our drawing area
            if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height)
            {
                if (canvas != null)
                {
                    (canvas as IDisposable).Dispose();
                }

                canvas = new Cairo.ImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

            cr.Initialize(PintaCore.Workspace.ImageSize, PintaCore.Workspace.CanvasSize);

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                // Draw our canvas drop shadow
                g.DrawRectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color(.5, .5, .5), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 1, y - 1, PintaCore.Workspace.CanvasSize.Width + 3, PintaCore.Workspace.CanvasSize.Height + 3), new Cairo.Color(.8, .8, .8), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 2, y - 2, PintaCore.Workspace.CanvasSize.Width + 5, PintaCore.Workspace.CanvasSize.Height + 5), new Cairo.Color(.9, .9, .9), 1);

                // Set up our clip rectangle
                g.Rectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height));
                g.Clip();

                g.Translate(x, y);

                // Render all the layers to a surface
                var layers = PintaCore.Layers.GetLayersToPaint();
                if (layers.Count == 0)
                {
                    canvas.Clear();
                }
                cr.Render(layers, canvas, canvas_bounds.Location);

                // Paint the surface to our canvas
                g.SetSourceSurface(canvas, canvas_bounds.X + (int)(0 * scale), canvas_bounds.Y + (int)(0 * scale));
                g.Paint();

                // Selection outline
                if (PintaCore.Layers.ShowSelection)
                {
                    g.Save();
                    g.Translate(0.5, 0.5);
                    g.Scale(scale, scale);

                    g.AppendPath(PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);

                    if (PintaCore.Tools.CurrentTool.Name.Contains("Select") && !PintaCore.Tools.CurrentTool.Name.Contains("Selected"))
                    {
                        g.Color    = new Cairo.Color(0.7, 0.8, 0.9, 0.2);
                        g.FillRule = Cairo.FillRule.EvenOdd;
                        g.FillPreserve();
                    }

                    g.LineWidth = 1 / scale;

                    // Draw a white line first so it shows up on dark backgrounds
                    g.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    // Draw a black dashed line over the white line
                    g.SetDash(new double[] { 2 / scale, 4 / scale }, 0);
                    g.Color = new Cairo.Color(0, 0, 0);

                    g.Stroke();
                    g.Restore();
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

            var scale = document.Workspace.Scale;

            var x = (int)document.Workspace.Offset.X;
            var y = (int)document.Workspace.Offset.Y;

            // Translate our expose area for the whole drawingarea to just our canvas
            var canvas_bounds = new Rectangle(x, y, document.Workspace.CanvasSize.Width, document.Workspace.CanvasSize.Height);

            canvas_bounds.Intersect(e.Area);

            if (canvas_bounds.IsEmpty)
            {
                return(true);
            }

            canvas_bounds.X -= x;
            canvas_bounds.Y -= y;

            // Resize our offscreen surface to a surface the size of our drawing area
            if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height)
            {
                if (canvas != null)
                {
                    (canvas as IDisposable).Dispose();
                }

                canvas = new Cairo.ImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

            cr.Initialize(document.ImageSize, document.Workspace.CanvasSize);

            using (var g = CairoHelper.Create(GdkWindow)) {
                // Draw our canvas drop shadow
                g.DrawRectangle(new Cairo.Rectangle(x - 1, y - 1, document.Workspace.CanvasSize.Width + 2, document.Workspace.CanvasSize.Height + 2), new Cairo.Color(.5, .5, .5), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 2, y - 2, document.Workspace.CanvasSize.Width + 4, document.Workspace.CanvasSize.Height + 4), new Cairo.Color(.8, .8, .8), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 3, y - 3, document.Workspace.CanvasSize.Width + 6, document.Workspace.CanvasSize.Height + 6), new Cairo.Color(.9, .9, .9), 1);

                // Set up our clip rectangle
                g.Rectangle(new Cairo.Rectangle(x, y, document.Workspace.CanvasSize.Width, document.Workspace.CanvasSize.Height));
                g.Clip();

                g.Translate(x, y);

                // Render all the layers to a surface
                var layers = document.GetLayersToPaint();

                if (layers.Count == 0)
                {
                    canvas.Clear();
                }

                cr.Render(layers, canvas, canvas_bounds.Location);

                // Paint the surface to our canvas
                g.SetSourceSurface(canvas, canvas_bounds.X + (int)(0 * scale), canvas_bounds.Y + (int)(0 * scale));
                g.Paint();

                // Selection outline
                if (document.Selection.Visible)
                {
                    bool fillSelection = PintaCore.Tools.CurrentTool.Name.Contains("Select") &&
                                         !PintaCore.Tools.CurrentTool.Name.Contains("Selected");
                    document.Selection.Draw(g, scale, fillSelection);
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        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);

            using (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.SetSourceColor(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.SetSourceColor(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);
        }
Ejemplo n.º 5
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            using (Context c = CairoHelper.Create(GdkWindow))
            {
                foreach (int k in vd.Keys)
                {
                    foreach (KeyValuePair <int, double> i in g[k])
                    {
                        c.SetSourceRGB(0.0, 0.0, 0.0);
                        c.MoveTo(vd[k].pos);
                        PointD p = vd[i.Key].pos;
                        c.LineTo(p);
                        c.Stroke();
                        PointD midP  = new PointD((vd[k].pos.X + p.X) / 2, (vd[k].pos.Y + p.Y) / 2);
                        PointD midP2 = new PointD((vd[i.Key].pos.X + midP.X) / 2, (vd[i.Key].pos.Y + midP.Y) / 2);
                        addMidPoint(k, i.Key, midP2);

                        PointD inter, p1, p2;
                        Intersection(vd[i.Key].radius, vd[k].pos, vd[i.Key].pos, out inter, out p1, out p2);
                        c.SetSourceRGB(0.0, 0.0, 0.0);
                        c.MoveTo(inter);
                        c.LineTo(p1);
                        c.LineTo(p2);
                        c.ClosePath();
                        c.Fill();

                        c.SetFontSize(18);
                        string st = i.Value.ToString();

                        if (updateWeight && weiToChange.Item1 == k && weiToChange.Item2 == i.Key)
                        {
                            st = String.Join("", weiToAdd);
                            if (blink)
                            {
                                st += "|";
                            }
                            c.SetSourceRGB(0.6, 0.4, 0.5);
                        }
                        else
                        {
                            c.SetSourceRGB(0.0, 0.0, 0.0);
                        }

                        TextExtents te = c.TextExtents(st);
                        PointD      mp = new PointD(10 + midP2.X - (te.Width / 2 + te.XBearing), 10 + midP2.Y - (te.Height / 2 + te.YBearing));
                        c.MoveTo(mp);
                        c.ShowText(st);
                        c.Stroke();
                    }
                }

                if (displayPath)
                {
                    c.SetSourceRGB(0.0, 0.8, 0.0);
                    for (int v = 0; v <= shortestPath.Count - 2; v++)
                    {
                        PointD from = vd[shortestPath[v]].pos;
                        PointD to   = vd[shortestPath[v + 1]].pos;
                        c.MoveTo(from);
                        c.LineTo(to);
                        c.Stroke();
                    }
                }

                foreach (int k in vd.Keys)
                {
                    string s      = k.ToString();
                    int    radius = s.Length > 1 ? 10 * s.Length : 15;
                    vd[k].radius = radius;
                    c.MoveTo(vd[k].pos);
                    c.SetSourceRGB(1.0, 1.0, 1.0);
                    c.Arc(vd[k].pos.X, vd[k].pos.Y, radius, 0.0, 2 * Math.PI);
                    c.Fill();
                    c.SetSourceRGB(0.0, 0.0, 0.0);
                    c.Arc(vd[k].pos.X, vd[k].pos.Y, radius, 0.0, 2 * Math.PI);
                    if (k == selectedVert)
                    {
                        c.Fill();
                    }
                    else
                    {
                        c.Stroke();
                    }
                    c.SetFontSize(30);
                    var t = (k == selectedVert) ? (1.0, 1.0, 1.0) : (0.0, 0.0, 0.0);
                    c.SetSourceRGB(t.Item1, t.Item2, t.Item3);
                    TextExtents te = c.TextExtents(s);
                    c.MoveTo(vd[k].pos.X - (te.Width / 2 + te.XBearing), vd[k].pos.Y - (te.Height / 2 + te.YBearing));
                    c.ShowText(s);
                    c.Fill();
                }
            }
            return(true);
        }
Ejemplo n.º 6
0
        protected override bool OnExposeEvent(EventExpose ev)
        {
            Context c = CairoHelper.Create(GdkWindow);

            c.SetSourceRGB((double)111 / (double)255, (double)120 / (double)255, (double)237 / (double)255);
            c.Rectangle(0, 0, BoardWidth, BoardHeight);
            c.Fill();


            // ToDo: draw win positions
            if (game.winCombination != null)
            {
                for (int i = 0; i < game.winCombination.Length; i++)
                {
                    int row = game.winCombination[i].row, column = game.winCombination[i].column;
                    // green color
                    c.SetSourceRGB((double)24 / (double)255, (double)227 / (double)255, (double)111 / (double)255);
                    c.Rectangle(getX(column), getY(row), fieldSize, fieldSize);
                    c.Fill();
                }
            }

            // draw pieces in the holes

            for (int row = 0; row < Game.rows; row++)
            {
                for (int col = 0; col < Game.columns; col++)
                {
                    // set color of field
                    if (game[row, col] == Game.FieldState.yellow)
                    {
                        // yellow
                        c.SetSourceRGB(1.0, 1.0, (double)74 / (double)255);
                    }
                    else if (game[row, col] == Game.FieldState.red)
                    {
                        // red
                        c.SetSourceRGB((double)250 / (double)255, (double)40 / (double)255, (double)40 / (double)255);
                    }
                    else
                    {
                        c.SetSourceRGB((double)223 / (double)255, (double)215 / (double)255, (double)215 / (double)255);
                    }

                    c.Arc(getX(col) + fieldMargin + holeRadius, getY(row) + fieldMargin + holeRadius, holeRadius, 0, 2 * Math.PI);
                    c.Fill();
                }
            }


            // draw piece in the 0. row that will fall down
            if (game[0, currentColumn] == Game.FieldState.none)
            {
                if (game.player == Game.FieldState.yellow)
                {
                    // yellow
                    c.SetSourceRGB(1.0, 1.0, (double)74 / (double)255);
                }
                else if (game.player == Game.FieldState.red)
                {
                    // red
                    c.SetSourceRGB((double)250 / (double)255, (double)40 / (double)255, (double)40 / (double)255);
                }
                c.Arc(getX(currentColumn) + fieldMargin + holeRadius, 0 + fieldMargin + holeRadius, holeRadius, 0, 2 * Math.PI);
                c.Fill();
            }

            c.GetTarget().Dispose();
            c.Dispose();
            return(true);
        }
Ejemplo n.º 7
0
        private void UpdateImage()
        {
            float   scale  = Math.Min(Allocation.Width / _svgOriginalW, Allocation.Height / _svgOriginalH);
            int     width  = (int)(_svgOriginalW * scale);
            int     height = (int)(_svgOriginalH * scale);
            Context cr     = Gdk.CairoHelper.Create(this.GdkWindow);

            cr.SetSourceRGB(0, 0, 0);
            cr.Rectangle(0, 0, width, height);
            cr.Fill();

            cr.Save();
            using (MemoryStream ms = new MemoryStream())
            {
                _svg.Draw(width, height).Save(ms, ImageFormat.Png);
                //            imageView.Pixbuf = new Pixbuf(ms.ToArray());
                CairoHelper.SetSourcePixbuf(cr, new Pixbuf(ms.ToArray()), 0, 0);
            }

            cr.Paint();
            cr.Restore();

            cr.SetSourceRGB(1, 1, 1);
            foreach (SvgText text in _svgTexts)
            {
                if (text.Text == null)
                {
                    continue;
                }

                float dx = text.X[0].Value / _svgOriginalW * width;
                float dy = text.Y[0].Value / _svgOriginalH * height;
                cr.MoveTo(dx, dy);

                if (text.Color == warningColor)
                {
                    cr.SetSourceColor(cWarningColor);
                }
                else if (text.Color == disabledColor)
                {
                    cr.SetSourceColor(cDisabledColor);
                }
                else
                {
                    cr.SetSourceColor(cNominalColor);
                }

                if (text.FontSize.Value is float size)
                {
                    cr.SetFontSize(size * scale);
                }

                FontWeight weight = (text.FontWeight == SvgFontWeight.Bold) ? FontWeight.Bold : FontWeight.Normal;
                FontSlant  slant  = (text.FontStyle == SvgFontStyle.Italic) ? FontSlant.Italic : FontSlant.Normal;
                cr.SelectFontFace("sans serif", slant, weight);

                if (text.TextAnchor == SvgTextAnchor.Middle)
                {
                    TextExtents te = cr.TextExtents(text.Text);
                    cr.RelMoveTo(-te.Width / 2.0, 0);
                }

                cr.ShowText(text.Text);
            }


            // GC from example
            ((IDisposable)cr.GetTarget()).Dispose();
            ((IDisposable)cr).Dispose();
        }
Ejemplo n.º 8
0
        //FIXME: respect damage regions not just the whole areas, and skip more work when possible
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            if (sections.Count == 0)
            {
                return(false);
            }

            var alloc = Allocation;

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

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

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

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

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

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

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

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

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

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

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

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

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

            PropagateExpose(sections[activeIndex].Child, evnt);
            return(true);           // base.OnExposeEvent (evnt);
        }
        protected override void Render(Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags)
        {
            if (isDisposed)
            {
                return;
            }
            if (diffMode)
            {
                if (path.Equals(selctedPath))
                {
                    selectedLine = -1;
                    selctedPath  = null;
                }

                int w, maxy;
                window.GetSize(out w, out maxy);
                if (DrawLeft)
                {
                    cell_area.Width += cell_area.X - leftSpace;
                    cell_area.X      = leftSpace;
                }
                var treeview = widget as FileTreeView;
                var p        = treeview != null? treeview.CursorLocation : null;

                cell_area.Width -= RightPadding;

                window.DrawRectangle(widget.Style.BaseGC(Gtk.StateType.Normal), true, cell_area.X, cell_area.Y, cell_area.Width - 1, cell_area.Height);

                Gdk.GC normalGC  = widget.Style.TextGC(StateType.Normal);
                Gdk.GC removedGC = new Gdk.GC(window);
                removedGC.Copy(normalGC);
                removedGC.RgbFgColor = baseRemoveColor.AddLight(-0.3);
                Gdk.GC addedGC = new Gdk.GC(window);
                addedGC.Copy(normalGC);
                addedGC.RgbFgColor = baseAddColor.AddLight(-0.3);
                Gdk.GC infoGC = new Gdk.GC(window);
                infoGC.Copy(normalGC);
                infoGC.RgbFgColor = widget.Style.Text(StateType.Normal).AddLight(0.2);

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

                // Rendering is done in two steps:
                // 1) Get a list of blocks to render
                // 2) render the blocks

                int y = cell_area.Y + 2;

                // cline keeps track of the current source code line (the one to jump to when double clicking)
                int       cline        = 1;
                bool      inHeader     = true;
                BlockInfo currentBlock = null;

                List <BlockInfo> blocks = new List <BlockInfo> ();

                for (int n = 0; n < lines.Length; n++, y += lineHeight)
                {
                    string line = lines [n];
                    if (line.Length == 0)
                    {
                        currentBlock = null;
                        y           -= lineHeight;
                        continue;
                    }

                    char tag = line [0];

                    if (line.StartsWith("---") || line.StartsWith("+++"))
                    {
                        // Ignore this part of the header.
                        currentBlock = null;
                        y           -= lineHeight;
                        continue;
                    }
                    if (tag == '@')
                    {
                        int l = ParseCurrentLine(line);
                        if (l != -1)
                        {
                            cline = l - 1;
                        }
                        inHeader = false;
                    }
                    else if (tag != '-' && !inHeader)
                    {
                        cline++;
                    }

                    BlockType type;
                    switch (tag)
                    {
                    case '-':
                        type = BlockType.Removed;
                        break;

                    case '+':
                        type = BlockType.Added;
                        break;

                    case '@':
                        type = BlockType.Info;
                        break;

                    default:
                        type = BlockType.Unchanged;
                        break;
                    }

                    if (currentBlock == null || type != currentBlock.Type)
                    {
                        if (y > maxy)
                        {
                            break;
                        }

                        // Starting a new block. Mark section ends between a change block and a normal code block
                        if (currentBlock != null && IsChangeBlock(currentBlock.Type) && !IsChangeBlock(type))
                        {
                            currentBlock.SectionEnd = true;
                        }

                        currentBlock = new BlockInfo()
                        {
                            YStart          = y,
                            FirstLine       = n,
                            Type            = type,
                            SourceLineStart = cline,
                            SectionStart    = (blocks.Count == 0 || !IsChangeBlock(blocks[blocks.Count - 1].Type)) && IsChangeBlock(type)
                        };
                        blocks.Add(currentBlock);
                    }
                    // Include the line in the current block
                    currentBlock.YEnd     = y + lineHeight;
                    currentBlock.LastLine = n;
                }

                // Now render the blocks

                // The y position of the highlighted line
                int selectedLineRowTop = -1;

                BlockInfo lastCodeSegmentStart = null;
                BlockInfo lastCodeSegmentEnd   = null;

                foreach (BlockInfo block in blocks)
                {
                    if (block.Type == BlockType.Info)
                    {
                        // Finished drawing the content of a code segment. Now draw the segment border and label.
                        if (lastCodeSegmentStart != null)
                        {
                            DrawCodeSegmentBorder(infoGC, ctx, cell_area.X, cell_area.Width, lastCodeSegmentStart, lastCodeSegmentEnd, lines, widget, window);
                        }
                        lastCodeSegmentStart = block;
                    }

                    lastCodeSegmentEnd = block;

                    if (block.YEnd < 0)
                    {
                        continue;
                    }

                    // Draw the block background
                    DrawBlockBg(ctx, cell_area.X + 1, cell_area.Width - 2, block);

                    // Get all text for the current block
                    StringBuilder sb = new StringBuilder();
                    for (int n = block.FirstLine; n <= block.LastLine; n++)
                    {
                        string s = ProcessLine(lines [n]);
                        if (n > block.FirstLine)
                        {
                            sb.Append('\n');
                        }
                        if (block.Type != BlockType.Info && s.Length > 0)
                        {
                            sb.Append(s, 1, s.Length - 1);
                        }
                        else
                        {
                            sb.Append(s);
                        }
                    }

                    // Draw a special background for the selected line

                    if (block.Type != BlockType.Info && p.HasValue && p.Value.X >= cell_area.X && p.Value.X <= cell_area.Right && p.Value.Y >= block.YStart && p.Value.Y <= block.YEnd)
                    {
                        int    row  = (p.Value.Y - block.YStart) / lineHeight;
                        double yrow = block.YStart + lineHeight * row;
                        double xrow = cell_area.X + LeftPaddingBlock;
                        int    wrow = cell_area.Width - 1 - LeftPaddingBlock;
                        if (block.Type == BlockType.Added)
                        {
                            ctx.Color = baseAddColor.AddLight(0.1).ToCairoColor();
                        }
                        else if (block.Type == BlockType.Removed)
                        {
                            ctx.Color = baseRemoveColor.AddLight(0.1).ToCairoColor();
                        }
                        else
                        {
                            ctx.Color = widget.Style.Base(Gtk.StateType.Prelight).AddLight(0.1).ToCairoColor();
                            xrow     -= LeftPaddingBlock;
                            wrow     += LeftPaddingBlock;
                        }
                        ctx.Rectangle(xrow, yrow, wrow, lineHeight);
                        ctx.Fill();
                        selectedLine       = block.SourceLineStart + row;
                        selctedPath        = path;
                        selectedLineRowTop = (int)yrow;
                    }

                    // Draw the line text. Ignore header blocks, since they are drawn as labels in DrawCodeSegmentBorder

                    if (block.Type != BlockType.Info)
                    {
                        layout.SetMarkup("");
                        layout.SetText(sb.ToString());
                        Gdk.GC gc;
                        switch (block.Type)
                        {
                        case BlockType.Removed:
                            gc = removedGC;
                            break;

                        case BlockType.Added:
                            gc = addedGC;
                            break;

                        case BlockType.Info:
                            gc = infoGC;
                            break;

                        default:
                            gc = normalGC;
                            break;
                        }
                        window.DrawLayout(gc, cell_area.X + 2 + LeftPaddingBlock, block.YStart, layout);
                    }

                    // Finally draw the change symbol at the left margin

                    DrawChangeSymbol(ctx, cell_area.X + 1, cell_area.Width - 2, block);
                }

                // Finish the drawing of the code segment
                if (lastCodeSegmentStart != null)
                {
                    DrawCodeSegmentBorder(infoGC, ctx, cell_area.X, cell_area.Width, lastCodeSegmentStart, lastCodeSegmentEnd, lines, widget, window);
                }

                // Draw the source line number at the current selected line. It must be done at the end because it must
                // be drawn over the source code text and segment borders.
                if (selectedLineRowTop != -1)
                {
                    DrawLineBox(normalGC, ctx, ((Gtk.TreeView)widget).VisibleRect.Right - 4, selectedLineRowTop, selectedLine, widget, window);
                }

                ((IDisposable)ctx).Dispose();
                removedGC.Dispose();
                addedGC.Dispose();
                infoGC.Dispose();
            }
            else
            {
                // Rendering a normal text row
                int y = cell_area.Y + (cell_area.Height - height) / 2;
                window.DrawLayout(widget.Style.TextGC(GetState(flags)), cell_area.X, y, layout);
            }
        }
Ejemplo n.º 10
0
        void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y)
        {
            if (!heightMeasured)
            {
                return;
            }

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

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

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

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

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

                    var img = r.Expanded ? discloseUp : discloseDown;
                    CairoHelper.SetSourcePixbuf(ctx, img, Allocation.Width - img.Width - CategoryTopBottomPadding, y + (rh - img.Height) / 2);
                    ctx.Paint();

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

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

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

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

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

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

                    if (r.AnimatingExpand)
                    {
                        y = py + r.AnimationHeight;
                        // Repaing the background because the cairo clip doesn't work for gdk primitives
                        int dx = (int)((double)Allocation.Width * dividerPosition);
                        ctx.Rectangle(0, y, dx, Allocation.Height - y);
                        ctx.SetSourceColor(LabelBackgroundColor);
                        ctx.Fill();
                        ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y);
                        ctx.SetSourceRGB(1, 1, 1);
                        ctx.Fill();
                    }
                }
            }
        }
Ejemplo n.º 11
0
        protected override bool OnExposeEvent(Gdk.EventExpose args)
        {
            Gdk.Window win = GdkWindow;
            int        rwidth, rheight;

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

            win.GetSize(out rwidth, out rheight);

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

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

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

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

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

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

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

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

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

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

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

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

            // Draw the background

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

            // Draw selected area

            if (enableSelection)
            {
                int sx, sy, ex, ey;
                GetPoint(selectionStart.Value, selectionStart.Value, out sx, out sy);
                GetPoint(selectionEnd.Value, selectionEnd.Value, out ex, out ey);
                if (sx > ex)
                {
                    int tmp = sx; sx = ex; ex = tmp;
                }
                Gdk.GC sgc = new Gdk.GC(GdkWindow);
                sgc.RgbFgColor = new Color(225, 225, 225);
                win.DrawRectangle(sgc, true, sx, top, ex - sx, height + 1);
            }

            // Draw axes

            Gdk.GC gc = Style.BlackGC;

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

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

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

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

            ((IDisposable)ctx).Dispose();
            return(true);
        }