void RenderLineNumberIcon(Widget widget, Cairo.Context cr, Gdk.Rectangle cell_area, int markupHeight, int yOffset)
        {
            if (!IsStackFrame)
            {
                return;
            }

            cr.Save();

                        #if CENTER_ROUNDED_RECTANGLE
            cr.Translate(cell_area.X + Padding, (cell_area.Y + (cell_area.Height - RoundedRectangleHeight) / 2.0));
                        #else
            cr.Translate(cell_area.X + Padding, cell_area.Y + Padding + yOffset);
                        #endif

            cr.Antialias = Cairo.Antialias.Subpixel;

            cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius);
            cr.Clip();

            if (IsUserCode)
            {
                cr.SetSourceRGBA(0.90, 0.60, 0.87, 1.0);                  // 230, 152, 223
            }
            else
            {
                cr.SetSourceRGBA(0.77, 0.77, 0.77, 1.0);                  // 197, 197, 197
            }
            cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius);
            cr.Fill();

            cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.11);
            cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius);
            cr.LineWidth = 2;
            cr.Stroke();

            using (var layout = PangoUtil.CreateLayout(widget, LineNumber != -1 ? LineNumber.ToString() : "???")) {
                layout.Alignment       = Pango.Alignment.Left;
                layout.FontDescription = LineNumberFont;

                int width, height;
                layout.GetPixelSize(out width, out height);

                double y_offset = (RoundedRectangleHeight - height) / 2.0;
                double x_offset = (RoundedRectangleWidth - width) / 2.0;

                // render the text shadow
                cr.Save();
                cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.34);
                cr.Translate(x_offset, y_offset + 1);
                cr.ShowLayout(layout);
                cr.Restore();

                cr.SetSourceRGBA(1.0, 1.0, 1.0, 1.0);
                cr.Translate(x_offset, y_offset);
                cr.ShowLayout(layout);
            }

            cr.Restore();
        }
示例#2
0
        /// <summary>
        /// Draws a bitmap image.
        /// </summary>
        /// <param name="source">The bitmap image.</param>
        /// <param name="opacity">The opacity to draw with.</param>
        /// <param name="sourceRect">The rect in the image to draw.</param>
        /// <param name="destRect">The rect in the output to draw to.</param>
        public void DrawImage(IBitmapImpl bitmap, double opacity, Rect sourceRect, Rect destRect)
        {
            var pixbuf = bitmap as Gdk.Pixbuf;
            var rtb    = bitmap as RenderTargetBitmapImpl;
            var size   = new Size(pixbuf?.Width ?? rtb.PixelWidth, pixbuf?.Height ?? rtb.PixelHeight);
            var scale  = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height);

            _context.Save();
            _context.Scale(scale.X, scale.Y);
            destRect /= scale;

            _context.PushGroup();

            if (pixbuf != null)
            {
                Gdk.CairoHelper.SetSourcePixbuf(
                    _context,
                    pixbuf,
                    -sourceRect.X + destRect.X,
                    -sourceRect.Y + destRect.Y);
            }
            else
            {
                _context.SetSourceSurface(
                    rtb.Surface,
                    (int)(-sourceRect.X + destRect.X),
                    (int)(-sourceRect.Y + destRect.Y));
            }

            _context.Rectangle(destRect.ToCairo());
            _context.Fill();
            _context.PopGroupToSource();
            _context.PaintWithAlpha(opacityOverride);
            _context.Restore();
        }
示例#3
0
            protected override void OnDrawContent(Gdk.EventExpose evnt, Cairo.Context g)
            {
                Theme.BorderColor = marker.TooltipColor.Color;
                g.Rectangle(0, 0, Allocation.Width, Allocation.Height);
                g.SetSourceColor(marker.TooltipColor.Color);
                g.Fill();

                using (var drawingLayout = new Pango.Layout(this.PangoContext)) {
                    drawingLayout.FontDescription = cache.tooltipFontDescription;
                    double y = verticalTextBorder;

                    var showBulletedList = marker.Errors.Count > 1;
                    foreach (var msg in marker.Errors)
                    {
                        var icon = msg.IsError ? cache.errorPixbuf : cache.warningPixbuf;

                        if (!showBulletedList)
                        {
                            drawingLayout.Width = maxTextWidth;
                        }
                        drawingLayout.SetText(GetFirstLine(msg));
                        int w;
                        int h;
                        drawingLayout.GetPixelSize(out w, out h);

                        if (showBulletedList)
                        {
                            g.Save();

                            g.Translate(
                                textBorder,
                                y + verticalTextSpace / 2
                                );
                            Gdk.CairoHelper.SetSourcePixbuf(g, icon, 0, 0);
                            g.Paint();
                            g.Restore();
                        }

                        g.Save();

                        g.Translate(showBulletedList ? textBorder + iconTextSpacing + icon.Width: textBorder, y + verticalTextSpace / 2 + 1);
                        g.SetSourceColor(ShadowColor);
                        g.ShowLayout(drawingLayout);

                        g.Translate(0, -1);

                        g.SetSourceColor(marker.TagColor.SecondColor);
                        g.ShowLayout(drawingLayout);

                        g.Restore();


                        y += h + verticalTextSpace;
                    }
                }
            }
        private void PaintHeaderCell(Rectangle area, int ci, bool dragging)
        {
            if (ci < 0 || column_cache.Length <= ci)
            {
                return;
            }

            if (dragging)
            {
                Theme.DrawColumnHighlight(cairo_context, area,
                                          Theme.Colors.GetWidgetColor(GtkColorClass.Dark, StateType.Normal).ColorShade(0.9));

                Cairo.Color stroke_color = Theme.Colors.GetWidgetColor(
                    GtkColorClass.Base, StateType.Normal).ColorShade(0.0);
                stroke_color.A = 0.3;

                cairo_context.Color = stroke_color;
                cairo_context.MoveTo(area.X + 0.5, area.Y + 1.0);
                cairo_context.LineTo(area.X + 0.5, area.Bottom);
                cairo_context.MoveTo(area.Right - 0.5, area.Y + 1.0);
                cairo_context.LineTo(area.Right - 0.5, area.Bottom);
                cairo_context.Stroke();
            }

            Cell cell = column_cache [ci].Column.HeaderCell;

            if (cell != null)
            {
                cairo_context.Save();
                cairo_context.Translate(area.X, area.Y);
                cell_context.Area = area;
                cell.Render(cell_context, StateType.Normal, area.Width, area.Height, new CellPosition(ci, -1));
                cairo_context.Restore();
            }

            bool isLastVisibleColumn = true;

            for (int i = ci + 1; i < column_cache.Length; i++)
            {
                if (!column_cache [i].Column.Visible)
                {
                    continue;
                }

                isLastVisibleColumn = false;
                break;
            }

            if (!dragging && !isLastVisibleColumn)
            {
                Theme.DrawHeaderSeparator(cairo_context, area, area.Right);
            }
        }
        private void PaintHeaderCell(Rectangle area, int ci, bool dragging, ref bool have_drawn_separator)
        {
            if (ci < 0 || column_cache.Length <= ci)
            {
                return;
            }

            if (ci == ActiveColumn && HasFocus && HeaderFocused)
            {
                Theme.DrawColumnHeaderFocus(cairo_context, area);
            }

            if (dragging)
            {
                Theme.DrawColumnHighlight(cairo_context, area,
                                          CairoExtensions.ColorShade(Theme.Colors.GetWidgetColor(GtkColorClass.Dark, StateType.Normal), 0.9));

                Cairo.Color stroke_color = CairoExtensions.ColorShade(Theme.Colors.GetWidgetColor(
                                                                          GtkColorClass.Base, StateType.Normal), 0.0);
                stroke_color.A = 0.3;

                cairo_context.Color = stroke_color;
                cairo_context.MoveTo(area.X + 0.5, area.Y + 1.0);
                cairo_context.LineTo(area.X + 0.5, area.Bottom);
                cairo_context.MoveTo(area.Right - 0.5, area.Y + 1.0);
                cairo_context.LineTo(area.Right - 0.5, area.Bottom);
                cairo_context.Stroke();
            }

            ColumnCell cell = column_cache[ci].Column.HeaderCell;

            if (cell != null)
            {
                cairo_context.Save();
                cairo_context.Translate(area.X, area.Y);
                cell_context.Area  = area;
                cell_context.State = StateType.Normal;
                cell.Render(cell_context, area.Width, area.Height);
                cairo_context.Restore();
            }

            if (!dragging && ci < column_cache.Length - 1 && (have_drawn_separator ||
                                                              column_cache[ci].MaxWidth != column_cache[ci].MinWidth))
            {
                have_drawn_separator = true;
                Theme.DrawHeaderSeparator(cairo_context, area, area.Right);
            }
        }
示例#6
0
        void OnExpose(object sender, ExposeEventArgs args)
        {
            DrawingArea area = (DrawingArea)sender;

            Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow);

            IcnRecode icn = new IcnRecode(project, 1920, 1080, (x, y, w, h, s) =>
            {
                x *= scale;
                y *= scale;
                w *= scale;
                h *= scale;

                x += X;
                y += Y;
                w += X;
                h += Y;

                cr.Save();

                cr.SetSourceRGB(0, 0, 0);
                cr.LineWidth = s * 0.7;
                cr.MoveTo(x, y);
                cr.LineTo(w, h);
                cr.ClosePath();
                cr.Stroke();

                cr.Restore();
            });

            icn.Exec();

            cr.Dispose();
        }
示例#7
0
        public virtual void DrawAnnotation(Cairo.Context context, Cdn.AnnotationInfo info)
        {
            var uw    = context.LineWidth;
            var alloc = AnnotationAllocation(1 / uw, context);

            alloc.Offset(-Allocation.X / uw, -Allocation.Y / uw);

            context.Save();
            context.Scale(context.LineWidth, context.LineWidth);
            context.LineWidth = 1;

            context.Rectangle(alloc.X, alloc.Y, alloc.Width, alloc.Height);
            context.SetSourceRGBA(1, 1, 1, 0.75);
            context.Fill();

            context.Rectangle(alloc.X + 2, alloc.Y + 2, alloc.Width - 4, alloc.Height - 4);
            context.SetSourceRGB(0.95, 0.95, 0.95);
            context.SetDash(new double[] { 5, 5 }, 0);
            context.Stroke();

            Pango.Layout layout = Pango.CairoHelper.CreateLayout(context);
            Pango.CairoHelper.UpdateLayout(context, layout);
            layout.FontDescription = Settings.Font;

            layout.SetText(info.Text.Trim());

            context.MoveTo(alloc.X + 2, alloc.Y + 2);
            context.SetSourceRGB(0.5, 0.5, 0.5);
            Pango.CairoHelper.ShowLayout(context, layout);

            context.Restore();
        }
示例#8
0
        private void RenderErrorMarks(Cairo.Context context, Point scale, MarkerStyle style, double size, List <double> vals, int direction)
        {
            if (vals == null || vals.Count != Count)
            {
                return;
            }

            context.Save();

            if (d_errorColor != null)
            {
                d_errorColor.Set(context);
            }
            else if (Color != null)
            {
                Color.Set(context);
            }

            context.LineWidth = LineWidth;

            Marker.Renderer renderer = Marker.Lookup(style);

            for (int i = 0; i < Count; ++i)
            {
                Point pt = this[i].Copy();
                pt.Y += direction * vals[i];

                renderer(context, scale, pt, size, LineWidth);
            }

            context.Restore();
        }
示例#9
0
        private void RenderErrorBars(Cairo.Context context, Point scale)
        {
            LineStyle lt;

            if (d_errorLineStyle == LineStyle.Inherit)
            {
                lt = LineStyle;
            }
            else
            {
                lt = d_errorLineStyle;
            }

            if (lt == LineStyle.None || lt == LineStyle.Inherit)
            {
                return;
            }

            context.Save();

            SetLineStyle(context, LineWidth, lt);

            RenderErrorBars(context, scale, d_errorAbove, 1);
            RenderErrorBars(context, scale, d_errorBelow, -1);

            context.Restore();
        }
示例#10
0
        private void RenderErrorBars(Cairo.Context context, Point scale, List <double> errors, int direction)
        {
            if (errors == null || errors.Count != Count)
            {
                return;
            }

            context.Save();

            for (int i = 0; i < Count; ++i)
            {
                Point pt = this[i];

                context.MoveTo(pt.X * scale.X, pt.Y * scale.Y);
                context.RelLineTo(0, errors[i] * scale.Y * direction);
            }

            if (d_errorColor != null)
            {
                d_errorColor.Set(context);
            }
            else if (Color != null)
            {
                Color.Set(context);
            }

            context.Stroke();
            context.Restore();
        }
        public static void Ellipse(Cairo.Context context, PointF p, double r, Color color, bool filled, double width = 1.0)
        {
            context.Save();
            context.Translate(p.X, p.Y);

            if (!filled)
            {
                context.LineWidth = width;
                context.LineCap   = Cairo.LineCap.Butt;
                context.LineJoin  = Cairo.LineJoin.Bevel;
            }
            var c = color.ToCairo();

            context.SetSourceRGBA(c.R, c.G, c.B, c.A);

            context.Arc(0, 0, r, 0, Math.PI * 2);

            if (filled)
            {
                context.Fill();
            }
            else
            {
                context.Stroke();
            }

            context.Restore();
        }
        public static void Arc(Cairo.Context context, PointF p, double r, double a1, double a2, bool clockwise, Color color, bool filled, double width = 1.0)
        {
            context.Save();
            context.Translate(p.X, p.Y);

            if (!filled)
            {
                context.LineWidth = width;
                context.LineCap   = Cairo.LineCap.Butt;
                context.LineJoin  = Cairo.LineJoin.Bevel;
            }
            var c = color.ToCairo();

            context.SetSourceRGBA(c.R, c.G, c.B, c.A);

            if (clockwise)
            {
                context.Arc(0, 0, r, a1, a2);
            }
            else
            {
                context.ArcNegative(0, 0, r, a1, a2);
            }

            if (filled)
            {
                context.Fill();
            }
            else
            {
                context.Stroke();
            }

            context.Restore();
        }
示例#13
0
        // Called from asynchronously from Renderer.OnCompletion ()
        void HandleApply()
        {
            Debug.WriteLine("LivePreviewManager.HandleApply()");

            var item = new SimpleHistoryItem(effect.Icon, effect.Name);

            item.TakeSnapshotOfLayer(PintaCore.Layers.CurrentLayerIndex);

            using (var ctx = new Cairo.Context(layer.Surface)) {
                ctx.Save();
                PintaCore.Workspace.ActiveDocument.Selection.Clip(ctx);

                ctx.Operator = Cairo.Operator.Source;

                layer.Draw(ctx, live_preview_surface, 1);
                ctx.Restore();
            }

            PintaCore.History.PushNewItem(item);

            FireLivePreviewEndedEvent(RenderStatus.Completed, null);

            live_preview_enabled = false;

            PintaCore.Workspace.Invalidate();              //TODO keep track of dirty bounds.
            CleanUp();
        }
示例#14
0
        protected void RenderMarkers(Cairo.Context context, Point scale, int idx, int length)
        {
            if (d_markerRenderer == null)
            {
                return;
            }

            context.Save();

            if (d_color != null)
            {
                d_color.Set(context);
            }

            context.LineWidth = LineWidth;

            int curidx = idx;

            foreach (Point item in Range(idx, length))
            {
                d_markerRenderer(context, scale, item, d_markerSize, d_lineWidth);
                curidx++;
            }

            context.Restore();
        }
示例#15
0
        protected override void onDraw(Cairo.Context gr)
        {
            Rectangle rBack = new Rectangle(Slot.Size);

            //rBack.Inflate (-Margin);
//			if (BorderWidth > 0)
//				rBack.Inflate (-BorderWidth / 2);

            Background.SetAsSource(gr, rBack);
            CairoHelpers.CairoRectangle(gr, rBack, CornerRadius);
            gr.Fill();

            if (BorderWidth > 0)
            {
                Foreground.SetAsSource(gr, rBack);
                CairoHelpers.CairoRectangle(gr, rBack, CornerRadius, BorderWidth);
            }

            gr.Save();
            if (ClipToClientRect)
            {
                //clip to client zone
                CairoHelpers.CairoRectangle(gr, ClientRectangle, Math.Max(0.0, CornerRadius - Margin));
                gr.Clip();
            }

            if (child != null)
            {
                child.Paint(ref gr);
            }
            gr.Restore();
        }
示例#16
0
        protected override void onDraw(Cairo.Context gr)
        {
            gr.Save();

            int spacing = (Parent as TabView).Spacing;

            gr.MoveTo(0.5, TabTitle.Slot.Bottom - 0.5);
            gr.LineTo(TabTitle.Slot.Left - spacing, TabTitle.Slot.Bottom - 0.5);
            gr.CurveTo(
                TabTitle.Slot.Left - spacing / 2, TabTitle.Slot.Bottom - 0.5,
                TabTitle.Slot.Left - spacing / 2, 0.5,
                TabTitle.Slot.Left, 0.5);
            gr.LineTo(TabTitle.Slot.Right, 0.5);
            gr.CurveTo(
                TabTitle.Slot.Right + spacing / 2, 0.5,
                TabTitle.Slot.Right + spacing / 2, TabTitle.Slot.Bottom - 0.5,
                TabTitle.Slot.Right + spacing, TabTitle.Slot.Bottom - 0.5);
            gr.LineTo(Slot.Width - 0.5, TabTitle.Slot.Bottom - 0.5);


            gr.LineTo(Slot.Width - 0.5, Slot.Height - 0.5);
            gr.LineTo(0.5, Slot.Height - 0.5);
            gr.ClosePath();
            gr.LineWidth = 2;
            Foreground.SetAsSource(gr);
            gr.StrokePreserve();

            gr.Clip();
            base.onDraw(gr);
            gr.Restore();
        }
示例#17
0
        public static void DrawText(Cairo.Context cr, string text, int size, Cairo.Rectangle rect)
        {
            cr.Save();
            cr.Translate(rect.X, rect.Y);
            using (var context = Pango.CairoHelper.CreateContext(cr))
                using (var layout = new Pango.Layout(context)) {
                    layout.Width     = Pango.Units.FromPixels((int)rect.Width);
                    layout.Height    = Pango.Units.FromPixels((int)rect.Height);
                    layout.Alignment = Pango.Alignment.Center;

                    // TODO: install the font on the system
                    layout.FontDescription = Pango.FontDescription.FromString("ZeldaOracles " + size);
                    //layout.FontDescription.Weight = (Pango.Weight)10000;

                    layout.SetText(text);

                    // Center vertically
                    int pixelWidth, pixelHeight;
                    layout.GetPixelSize(out pixelWidth, out pixelHeight);
                    cr.Translate(0, ((int)rect.Height - pixelHeight) / 2.0);

                    Pango.CairoHelper.ShowLayout(cr, layout);
                }
            cr.Restore();
        }
示例#18
0
            static void DrawLineEndAtIter(Cairo.Context cntx, TextView view, TextIter iter)
            {
                Gdk.Rectangle rect = view.GetIterLocation(iter);
                int           x, y;

                view.BufferToWindowCoords(TextWindowType.Text,
                                          rect.X,
                                          rect.Y + rect.Height / 2,
                                          out x, out y);
                cntx.Save();
                cntx.Color = GetDrawingColorForIter(view, iter);

                double arrowSize = 3;

                cntx.MoveTo(x + 10, y);
                cntx.RelLineTo(new Cairo.Distance(0, -arrowSize));
                cntx.RelMoveTo(new Cairo.Distance(0, arrowSize));
                cntx.RelLineTo(new Cairo.Distance(-8, 0));
                cntx.RelLineTo(new Cairo.Distance(arrowSize, arrowSize));
                cntx.RelMoveTo(new Cairo.Distance(-arrowSize, -arrowSize));
                cntx.RelLineTo(new Cairo.Distance(arrowSize, -arrowSize));

                cntx.Stroke();
                cntx.Restore();
            }
示例#19
0
        void DrawPixbuf(Cairo.Context ctx, Gdk.Pixbuf img, double x, double y, ImageDescription idesc)
        {
            ctx.Save();
            ctx.Translate(x, y);
            ctx.Scale(idesc.Size.Width / (double)img.Width, idesc.Size.Height / (double)img.Height);
            Gdk.CairoHelper.SetSourcePixbuf(ctx, img, 0, 0);

                        #pragma warning disable 618
            using (var p = ctx.Source) {
                var pattern = p as Cairo.SurfacePattern;
                if (pattern != null)
                {
                    if (idesc.Size.Width > img.Width || idesc.Size.Height > img.Height)
                    {
                        // Fixes blur issue when rendering on an image surface
                        pattern.Filter = Cairo.Filter.Fast;
                    }
                    else
                    {
                        pattern.Filter = Cairo.Filter.Good;
                    }
                }
            }
                        #pragma warning restore 618

            if (idesc.Alpha >= 1)
            {
                ctx.Paint();
            }
            else
            {
                ctx.PaintWithAlpha(idesc.Alpha);
            }
            ctx.Restore();
        }
示例#20
0
		// Called from asynchronously from Renderer.OnCompletion ()
		void HandleApply ()
		{
			Debug.WriteLine ("LivePreviewManager.HandleApply()");

			var item = new SimpleHistoryItem (effect.Icon, effect.Name);
			item.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayerIndex);			
			
			using (var ctx = new Cairo.Context (layer.Surface)) {
				
				ctx.Save ();
				ctx.AppendPath (PintaCore.Layers.SelectionPath);
				ctx.FillRule = Cairo.FillRule.EvenOdd;
				ctx.Clip ();				
			
				ctx.Operator = Cairo.Operator.Source;
				
				ctx.SetSourceSurface (live_preview_surface, (int)layer.Offset.X, (int)layer.Offset.Y);
				ctx.Paint ();
				ctx.Restore ();
			}
			
			PintaCore.History.PushNewItem (item);
			
			FireLivePreviewEndedEvent(RenderStatus.Completed, null);
			
			live_preview_enabled = false;
			
			PintaCore.Workspace.Invalidate (); //TODO keep track of dirty bounds.
			CleanUp ();
		}
示例#21
0
        public void Restore()
        {
            Context.Restore();
            var d = dataStack.Pop();

            PatternAlpha = d.PatternAlpha;
        }
示例#22
0
        // Render the dirtied window
        void OnExpose(object sender, ExposeEventArgs args)
        {
            DrawingArea area = (DrawingArea)sender;

            Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow);

            // Clear background
            cr.SetSourceRGB(1.0, 1.0, 1.0);
            cr.Paint();

            // Set the coordinate system origin at bottom left
            cr.Translate(0, area.Allocation.Height);
            cr.Scale(1.0, -1.0);

            // Render all Drawables, resetting the coordinate transform for each
            foreach (Drawable d in drawable)
            {
                cr.Save();
                d.Draw(cr);
                cr.Restore();
            }

            cr.GetTarget().Dispose();
            ((IDisposable)cr).Dispose();
        }
        public void DrawLineNumber(TextEditor editor, double width, Cairo.Context cr, Cairo.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
        {
            var lineNumberBgGC = editor.ColorStyle.LineNumbers.Background;
            var lineNumberGC   = editor.ColorStyle.LineNumbers.Foreground;

            cr.Rectangle(x, y, width, lineHeight);
            cr.Color = editor.Caret.Line == line?editor.ColorStyle.LineMarker.GetColor("color") : lineNumberGC;

            cr.Fill();

            if (line <= editor.Document.LineCount)
            {
                // Due to a mac? gtk bug I need to re-create the layout here
                // otherwise I get pango exceptions.
                using (var layout = PangoUtil.CreateLayout(editor)) {
                    layout.FontDescription = editor.Options.Font;
                    layout.Width           = (int)width;
                    layout.Alignment       = Pango.Alignment.Right;
                    layout.SetText(line.ToString());
                    cr.Save();
                    cr.Translate(x + (int)width + (editor.Options.ShowFoldMargin ? 0 : -2), y);
                    cr.Color = lineNumberBgGC;
                    cr.ShowLayout(layout);
                    cr.Restore();
                }
            }
        }
示例#24
0
        public static void DrawNode(Node n, Cairo.Color pen, Cairo.Context context)
        {
            var color = new Cairo.Color(0, 0, 0);

            context.SetSourceColor(color);
            ICurve  curve = n.BoundaryCurve;
            Ellipse el    = curve as Ellipse;

            if (el != null)
            {
                DrawEllipse(context, el);
            }
            else
            {
                // graphics.DrawPath(pen, CreateGraphicsPath(curve));
                DrawGraphicsPath(context, curve);
            }
            if (n.UserData != null)
            {
                var font     = Pango.FontDescription.FromString("sans 8");
                var text     = (string)n.UserData;
                var textSize = MeasureTextSize(font, text);
                context.Save();
                var layout = Pango.CairoHelper.CreateLayout(context);
                layout.FontDescription = font;
                layout.SetText(text);
                context.SetSourceColor(new Cairo.Color(0.5, 0.5, 0.5));
                context.MoveTo(n.Center.X - textSize.X / 2, n.Center.Y - textSize.Y / 2);
                Pango.CairoHelper.ShowLayout(context, layout);
                context.Restore();
            }
            context.Stroke();
        }
示例#25
0
        public override void Render(Cairo.Context context, Point scale)
        {
            context.Save();
            RenderArea(context, scale);
            context.Restore();

            base.Render(context, scale);
        }
示例#26
0
        protected void DrawTo(Cairo.Context ctx)
        {
            ctx.Save();
            d_graph.Draw(ctx);
            ctx.Restore();

            DrawSelection(ctx);
        }
示例#27
0
        private void DrawFocusRect(Cairo.Context cr, float x, float y, float width, float height)
        {
            cr.Save();

            cr.Rectangle(x, y, width, height);
            CairoHelper.PaintFocus(cr, gtk_style, state);

            cr.Restore();
        }
示例#28
0
 protected override bool OnDrawn(Cairo.Context cr)
 {
     cr.Save();
     cr.SetSourceRGB(0.0, 0.0, 0.0);
     cr.Rectangle(0, 0, Allocation.Width, Allocation.Height);
     cr.Fill();
     cr.Restore();
     return(base.OnDrawn(cr));
 }
示例#29
0
        public Gdk.Pixbuf BuildImage(FontService fontService)
        {
            Cairo.ImageSurface image = new Cairo.ImageSurface(Cairo.Format.ARGB32, WIDTH, HEIGHT);
            Cairo.Context      ctx   = new Cairo.Context(image);

            Pango.Layout layout = Pango.CairoHelper.CreateLayout(ctx);
            fontService.AssignLayout(layout);

            // fill background
            ctx.Save();
            ctx.Color = new Cairo.Color(0.0, 0.0, 0.0, 1.0);
            ctx.Paint();
            ctx.Restore();

            int charCode  = 0;
            int maxHeight = 0;

            Cairo.Point pos = new Cairo.Point(PADDING, PADDING);
            while ((!fontService.OnlyEnglish && charCode < 224) ||
                   (fontService.OnlyEnglish && charCode < (224 - 66)))
            {
                layout.SetText(alphabet[charCode].ToString());

                Pango.Rectangle te = GetTextExtents(layout, pos);

                // next line
                if (pos.X + te.Width + fontService.Spacing + PADDING > image.Width)
                {
                    pos.X = PADDING;
                    pos.Y = te.Y + maxHeight + PADDING;
                }
                te = DrawText(ctx, layout, pos);
                boxes[charCode] = te;

                pos.X     = te.X + te.Width + fontService.Spacing + PADDING;
                maxHeight = Math.Max(maxHeight, te.Height);

                charCode++;
            }

            int cropHeight = NextP2(boxes[charCode - 1].Y + boxes[charCode - 1].Height - 1);

            Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(
                image.Data, true, 8,
                image.Width,
                cropHeight,
                image.Stride);

            // manual dispose
            (image as IDisposable).Dispose();
            (layout as IDisposable).Dispose();
            (ctx.Target as IDisposable).Dispose();
            (ctx as IDisposable).Dispose();

            return(pixbuf);
        }
示例#30
0
        public void Render(List <Layer> layers, Cairo.ImageSurface dst, Point offset)
        {
            dst.Flush();

            // Our rectangle of interest
            var r   = new Rectangle(offset, dst.GetBounds().Size).ToCairoRectangle();
            var doc = PintaCore.Workspace.ActiveDocument;

            using (var g = new Cairo.Context(dst)) {
                // Create the transparent checkerboard background
                g.Translate(-offset.X, -offset.Y);
                g.FillRectangle(r, tranparent_pattern, new Cairo.PointD(offset.X, offset.Y));

                for (var i = 0; i < layers.Count; i++)
                {
                    var layer = layers[i];

                    // If we're in LivePreview, substitute current layer with the preview layer
                    if (layer == doc.Layers.CurrentUserLayer && PintaCore.LivePreview.IsEnabled)
                    {
                        layer = CreateLivePreviewLayer(layer);
                    }

                    // If the layer is offset, handle it here
                    if (!layer.Transform.IsIdentity())
                    {
                        layer = CreateOffsetLayer(layer);
                    }

                    // No need to resize the surface if we're at 100% zoom
                    if (scale_factor.Ratio == 1)
                    {
                        layer.Draw(g, layer.Surface, layer.Opacity, false);
                    }
                    else
                    {
                        using (var scaled = CairoExtensions.CreateImageSurface(Cairo.Format.Argb32, dst.Width, dst.Height)) {
                            g.Save();
                            // Have to undo the translate set above
                            g.Translate(offset.X, offset.Y);
                            CopyScaled(layer.Surface, scaled, r.ToGdkRectangle());
                            layer.Draw(g, scaled, layer.Opacity, false);
                            g.Restore();
                        }
                    }
                }
            }

            // If we are at least 200% and grid is requested, draw it
            if (enable_pixel_grid && PintaCore.Actions.View.PixelGrid.Value && scale_factor.Ratio <= 0.5d)
            {
                RenderPixelGrid(dst, offset);
            }

            dst.MarkDirty();
        }
示例#31
0
		public void Render (List<Layer> layers, Cairo.ImageSurface dst, Gdk.Point offset)
		{
			dst.Flush ();

            // Our rectangle of interest
            var r = new Gdk.Rectangle (offset, dst.GetBounds ().Size).ToCairoRectangle ();

            using (var g = new Cairo.Context (dst)) {
                // Create the transparent checkerboard background
                g.Translate (-offset.X, -offset.Y);
                g.FillRectangle (r, tranparent_pattern, new Cairo.PointD (offset.X, offset.Y));

                for (var i = 0; i < layers.Count; i++) {
                    var layer = layers[i];

                    // If we're in LivePreview, substitute current layer with the preview layer
                    if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled)
                        layer = CreateLivePreviewLayer (layer);

                    // If the layer is offset, handle it here
                    if (!layer.Transform.IsIdentity ())
                        layer = CreateOffsetLayer (layer);

                    // No need to resize the surface if we're at 100% zoom
                    if (scale_factor.Ratio == 1)
                        layer.Draw (g, layer.Surface, layer.Opacity, false);
                    else {
                        using (var scaled = new Cairo.ImageSurface (Cairo.Format.Argb32, dst.Width, dst.Height)) {
                            g.Save ();
                            // Have to undo the translate set above
                            g.Translate (offset.X, offset.Y);
                            CopyScaled (layer.Surface, scaled, r.ToGdkRectangle ());
                            layer.Draw (g, scaled, layer.Opacity, false);
                            g.Restore ();
                        }
                    }
                }
            }

            // If we are at least 200% and grid is requested, draw it
            if (enable_pixel_grid && PintaCore.Actions.View.PixelGrid.Active && scale_factor.Ratio <= 0.5d)
                RenderPixelGrid (dst, offset);
			
			dst.MarkDirty ();
		}
示例#32
0
		// Called from asynchronously from Renderer.OnCompletion ()
		void HandleApply ()
		{
			Debug.WriteLine ("LivePreviewManager.HandleApply()");

			using (var ctx = new Cairo.Context (layer.Surface)) {
				
				ctx.Save ();
				PintaCore.Workspace.ActiveDocument.Selection.Clip (ctx);
			
				ctx.Operator = Cairo.Operator.Source;
				
				layer.Draw(ctx, live_preview_surface, 1);
				ctx.Restore ();
			}
			
			PintaCore.History.PushNewItem (history_item);
			history_item = null;
			
			FireLivePreviewEndedEvent(RenderStatus.Completed, null);
			
			live_preview_enabled = false;
			
			PintaCore.Workspace.Invalidate (); //TODO keep track of dirty bounds.
			CleanUp ();
		}
示例#33
0
		// Called from asynchronously from Renderer.OnCompletion ()
		void HandleApply ()
		{
			Debug.WriteLine ("LivePreviewManager.HandleApply()");

			var item = new SimpleHistoryItem (effect.Icon, effect.Name);
			item.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayerIndex);			
			
			using (var ctx = new Cairo.Context (layer.Surface)) {
				
				ctx.Save ();
				ctx.AppendPath (PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);
				ctx.FillRule = Cairo.FillRule.EvenOdd;
				ctx.Clip ();				
			
				ctx.Operator = Cairo.Operator.Source;
				
				ctx.SetSourceSurface (live_preview_surface, (int)layer.Offset.X, (int)layer.Offset.Y);
				ctx.Paint ();
				ctx.Restore ();
			}
			
			PintaCore.History.PushNewItem (item);
			
			FireLivePreviewEndedEvent(RenderStatus.Completed, null);
			
			live_preview_enabled = false;
			
			PintaCore.Workspace.Invalidate (); //TODO keep track of dirty bounds.
			CleanUp ();
		}
示例#34
0
文件: TextTool.cs 项目: rini18/Pinta
        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;
        }
示例#35
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;
        }
示例#36
0
        public Gdk.Pixbuf BuildImage(FontService fontService)
        {
            Cairo.ImageSurface image = new Cairo.ImageSurface (Cairo.Format.ARGB32, WIDTH, HEIGHT);
            Cairo.Context ctx = new Cairo.Context (image);

            Pango.Layout layout = Pango.CairoHelper.CreateLayout (ctx);
            fontService.AssignLayout (layout);

            // fill background
            ctx.Save ();
            ctx.Color = new Cairo.Color (0.0, 0.0, 0.0, 1.0);
            ctx.Paint ();
            ctx.Restore ();

            int charCode = 0;
            int maxHeight = 0;
            Cairo.Point pos = new Cairo.Point (PADDING, PADDING);
            while ((!fontService.OnlyEnglish && charCode < 224) ||
                   (fontService.OnlyEnglish && charCode < (224 - 66))) {

                layout.SetText (alphabet[charCode].ToString());

                Pango.Rectangle te = GetTextExtents (layout, pos);

                // next line
                if (pos.X + te.Width + fontService.Spacing + PADDING > image.Width) {
                    pos.X = PADDING;
                    pos.Y = te.Y + maxHeight + PADDING;
                }
                te = DrawText (ctx, layout, pos);
                boxes[charCode] = te;

                pos.X = te.X + te.Width + fontService.Spacing + PADDING;
                maxHeight = Math.Max (maxHeight, te.Height);

                charCode++;
            }

            int cropHeight = NextP2 (boxes[charCode - 1].Y + boxes[charCode - 1].Height - 1);
            Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (
                image.Data, true, 8,
                image.Width,
                cropHeight,
                image.Stride);

            // manual dispose
            (image as IDisposable).Dispose ();
            (layout as IDisposable).Dispose ();
            (ctx.Target as IDisposable).Dispose ();
            (ctx as IDisposable).Dispose ();

            return pixbuf;
        }