示例#1
0
 protected void paintBackground(Cairo.Context context, Field[,] fields)
 {
     context.SetSourceRGB(0.8, 0.8, 0.8);
     context.Paint();
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             paintSquare(context, i * fieldSize, j * fieldSize, fields [i, j].Full);
         }
     }
     paintGrid(context);
     context.Paint();
 }
示例#2
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();
        }
示例#3
0
        public void Render(Player player, List <Ball> balls, List <Monster> monsters)
        {
            Gdk.Window canvas = area.GdkWindow;
            if (canvas != null)
            {
                using (Cairo.Context context = Gdk.CairoHelper.Create(canvas)) {
                    canvas.BeginPaintRegion(new Gdk.Region());
                    context.SetSourceSurface(background, 0, 0);
                    context.Paint();

                    foreach (Field field in player.Trail)
                    {
                        paintTrail(context, field.X * fieldSize, field.Y * fieldSize);
                    }

                    foreach (Ball ball in balls)
                    {
                        context.SetSourceRGB(1, 0, 0);
                        paintCircle(context, ball.X, ball.Y);
                    }

                    foreach (Monster monster in monsters)
                    {
                        paintMonster(context, monster);
                    }

                    context.SetSourceRGB(0, 0, 1);
                    paintPlayer(context, player);

                    canvas.EndPaint();
                }
            }
        }
示例#4
0
		public void Import (string fileName, Gtk.Window parent)
		{
			Pixbuf bg;

			// Handle any EXIF orientation flags
			using (var fs = new FileStream (fileName, FileMode.Open, FileAccess.Read))
				bg = new Pixbuf (fs);

			bg = bg.ApplyEmbeddedOrientation ();

			Size imagesize = new Size (bg.Width, bg.Height);

			Document doc = PintaCore.Workspace.CreateAndActivateDocument (fileName, imagesize);
			doc.HasFile = true;
			doc.ImageSize = imagesize;
			doc.Workspace.CanvasSize = imagesize;

			Layer layer = doc.AddNewLayer (Path.GetFileName (fileName));

			using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
				CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
				g.Paint ();
			}

			bg.Dispose ();
		}
示例#5
0
        public void IndexToXyShouldWorkCorrectly()
        {
            ITextContext context = new TypographyTextContext("0123456", FontFile, 36,
                                                             FontStretch.Normal, FontStyle.Normal, FontWeight.Normal,
                                                             1000, 100,
                                                             TextAlignment.Leading);

            // prepare debug contexts
            {
                surface = new Cairo.ImageSurface(Cairo.Format.Argb32, 2000, 2000);
                g       = new Cairo.Context(surface);
                g.SetSourceRGBA(1, 1, 1, 1);
                g.Paint();
                g.SetSourceRGBA(0, 0, 0, 1);
                g.LineWidth = 1;
            }

            // build path
            CairoPathBuilder cairoPathBuilder;

            cairoPathBuilder = new CairoPathBuilder(g, 0, 0, 1);
            context.Build(Point.Zero, cairoPathBuilder);

            float x, y, height;

            context.IndexToXY(0, false, out x, out y, out height);
            context.IndexToXY(1, false, out x, out y, out height);
            context.IndexToXY(2, false, out x, out y, out height);
            context.IndexToXY(3, false, out x, out y, out height);
            context.IndexToXY(4, false, out x, out y, out height);
            context.IndexToXY(5, false, out x, out y, out height);
        }
 public Cairo.Pattern GetPattern(ApplicationContext actx, double scaleFactor)
 {
     if (pattern == null || currentScaleFactor != scaleFactor)
     {
         if (pattern != null)
         {
             pattern.Dispose();
         }
         Gdk.Pixbuf pb = ((GtkImage)Image.Backend).GetBestFrame(actx, scaleFactor, Image.Size.Width, Image.Size.Height, false);
         using (var imgs = new Cairo.ImageSurface(Cairo.Format.ARGB32, (int)(Image.Size.Width * scaleFactor), (int)(Image.Size.Height * scaleFactor))) {
             var ic = new Cairo.Context(imgs);
             ic.Scale((double)imgs.Width / (double)pb.Width, (double)imgs.Height / (double)pb.Height);
             Gdk.CairoHelper.SetSourcePixbuf(ic, pb, 0, 0);
             ic.Paint();
             imgs.Flush();
             ((IDisposable)ic).Dispose();
             pattern = new Cairo.SurfacePattern(imgs);
         }
         pattern.Extend = Cairo.Extend.Repeat;
         var cm = new Cairo.Matrix();
         cm.Scale(scaleFactor, scaleFactor);
         pattern.Matrix     = cm;
         currentScaleFactor = scaleFactor;
     }
     return(pattern);
 }
示例#7
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 ();
		}
示例#8
0
        static void PrintOperation_DrawPage(object o, DrawPageArgs args)
        {
            using (PrintContext context = args.Context) {
                using (var pixBuf = currentImage.GetPixbuf()) {
                    Cairo.Context cr    = context.CairoContext;
                    double        scale = 1;
                    if (pixBuf.Height * context.Width / pixBuf.Width <= context.Height)
                    {
                        scale = context.Width / pixBuf.Width;
                    }
                    if (pixBuf.Width * context.Height / pixBuf.Height <= context.Width)
                    {
                        scale = context.Height / pixBuf.Height;
                    }

                    cr.Scale(scale, scale);

                    cr.MoveTo(0, 0);
                    CairoHelper.SetSourcePixbuf(cr, pixBuf, 0, 0);
                    cr.Paint();

                    ((IDisposable)cr).Dispose();
                }
            }
        }
示例#9
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();
        }
示例#10
0
        private void HandlePintaCoreActionsFileNewActivated(object sender, EventArgs e)
        {
            NewImageDialog dialog = new NewImageDialog ();

            dialog.ParentWindow = main_window.GdkWindow;
            dialog.WindowPosition = Gtk.WindowPosition.CenterOnParent;

            int response = dialog.Run ();

            if (response == (int)Gtk.ResponseType.Ok) {
                PintaCore.Workspace.ImageSize = new Cairo.PointD (dialog.NewImageWidth, dialog.NewImageHeight);
                PintaCore.Workspace.CanvasSize = new Cairo.PointD (dialog.NewImageWidth, dialog.NewImageHeight);

                PintaCore.Layers.Clear ();
                PintaCore.History.Clear ();
                PintaCore.Layers.DestroySelectionLayer ();
                PintaCore.Layers.ResetSelectionPath ();

                // Start with an empty white layer
                Layer background = PintaCore.Layers.AddNewLayer ("Background");

                using (Cairo.Context g = new Cairo.Context (background.Surface)) {
                    g.SetSourceRGB (255, 255, 255);
                    g.Paint ();
                }

                PintaCore.Workspace.Filename = "Untitled1";
                PintaCore.Workspace.IsDirty = false;
                PintaCore.Actions.View.ZoomToWindow.Activate ();
            }

            dialog.Destroy ();
        }
        /// TODO: CairoExtensions.CachedDraw seems not to work correctly for me.
        public static void CachedDraw(Cairo.Context self, ref SurfaceWrapper surface, Gdk.Rectangle region, object parameters = null, float opacity = 1.0f, Action <Cairo.Context, float> draw = null, double?forceScale = null)
        {
            double displayScale = forceScale.HasValue ? forceScale.Value : QuartzSurface.GetRetinaScale(self);
            int    targetWidth  = (int)(region.Width * displayScale);
            int    targetHeight = (int)(region.Height * displayScale);

            bool redraw = false;

            if (surface == null || surface.Width != targetWidth || surface.Height != targetHeight)
            {
                if (surface != null)
                {
                    surface.Dispose();
                }
                surface = new SurfaceWrapper(self, targetWidth, targetHeight);
                redraw  = true;
            }
            else if ((surface.Data == null && parameters != null) || (surface.Data != null && !surface.Data.Equals(parameters)))
            {
                redraw = true;
            }


            if (redraw)
            {
                surface.Data = parameters;
                using (var context = new Cairo.Context(surface.Surface)) {
                    draw(context, 1.0f);
                }
            }

            self.SetSourceSurface(surface.Surface, 0, 0);
            self.Paint();
        }
示例#12
0
        private void ScribbleDrawn(object o, DrawnArgs args)
        {
            Cairo.Context cr = args.Cr;

            cr.SetSourceSurface(surface, 0, 0);
            cr.Paint();
        }
示例#13
0
 void ClearSurface()
 {
     using (Cairo.Context ctx = new Cairo.Context(surface)) {
         ctx.SetSourceRGB(1, 1, 1);
         ctx.Paint();
     }
 }
示例#14
0
        public void Import(string fileName, Gtk.Window parent)
        {
            Pixbuf bg;

            // Handle any EXIF orientation flags
            using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                bg = new Pixbuf(fs);

            bg = bg.ApplyEmbeddedOrientation();

            Size imagesize = new Size(bg.Width, bg.Height);

            Document doc = PintaCore.Workspace.CreateAndActivateDocument(fileName, imagesize);

            doc.HasFile              = true;
            doc.ImageSize            = imagesize;
            doc.Workspace.CanvasSize = imagesize;

            Layer layer = doc.AddNewLayer(Path.GetFileName(fileName));

            using (Cairo.Context g = new Cairo.Context(layer.Surface)) {
                CairoHelper.SetSourcePixbuf(g, bg, 0, 0);
                g.Paint();
            }

            bg.Dispose();
        }
示例#15
0
        protected override bool OnExposeEvent(Gdk.EventExpose ev)
        {
            base.OnExposeEvent(ev);

            if (thumbnail == null)
            {
                UpdateThumbnail();
            }

            Rectangle rect = GdkWindow.GetBounds();

            Cairo.PointD pos   = PositionToClientPt(Position);
            Cairo.Color  black = new Cairo.Color(0, 0, 0);

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                //background
                g.SetSource(thumbnail, 0.0, 0.0);
                g.Paint();

                g.DrawRectangle(new Cairo.Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 1, rect.Height - 1), new Cairo.Color(.75, .75, .75), 1);
                g.DrawRectangle(new Cairo.Rectangle(rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3), black, 1);

                //cursor
                g.DrawLine(new Cairo.PointD(pos.X + 1, rect.Top + 2), new Cairo.PointD(pos.X + 1, rect.Bottom - 2), black, 1);
                g.DrawLine(new Cairo.PointD(rect.Left + 2, pos.Y + 1), new Cairo.PointD(rect.Right - 2, pos.Y + 1), black, 1);

                //point
                g.DrawEllipse(new Cairo.Rectangle(pos.X - 1, pos.Y - 1, 3, 3), black, 2);
            }
            return(true);
        }
示例#16
0
		void ClearSurface ()
		{
			using (Cairo.Context ctx = new Cairo.Context (surface)) {
				ctx.SetSourceRGB (1, 1, 1);
				ctx.Paint ();
			}
		}
示例#17
0
        protected Gdk.Pixbuf DrawConstDataIcon()
        {
            using (var surface = new Cairo.ImageSurface(Cairo.Format.Argb32, rectSizing.Width, rectSizing.Height)) {
                using (Cairo.Context cr = new Cairo.Context(surface)) {
                    // background
                    cr.SetSourceRGB(0.7, 0.7, 0.7);
                    cr.Paint();

                    // text
                    cr.SetSourceRGB(1, 0, 0);
                    // simple Cairo text API instead of Pango
                    //cr.MoveTo (10, 0.3 * height);
                    //cr.SetFontSize (20);
                    //cr.ShowText ("const");

                    using (var layout = Pango.CairoHelper.CreateLayout(cr)) {
                        // font size 12 seems suitable for iconHeight 48 pixels
                        float fontSize = 12 * rectSizing.Height / 48f;
                        layout.FontDescription = Pango.FontDescription.FromString("Sans " + fontSize.ToString());
                        layout.SetText("const");
                        layout.Width     = rectSizing.Width;
                        layout.Alignment = Pango.Alignment.Center;
                        int lwidth, lheight;
                        layout.GetPixelSize(out lwidth, out lheight);
                        // 0, 0 = left top
                        //cr.MoveTo (0.5 * (width - lwidth), 0.5 * (height - lheight));
                        cr.MoveTo(0.5 * rectSizing.Width, 0.5 * (rectSizing.Height - lheight));
                        Pango.CairoHelper.ShowLayout(cr, layout);
                    }
                }
                return(new Gdk.Pixbuf(surface.Data, Gdk.Colorspace.Rgb, true, 8, rectSizing.Width, rectSizing.Height, surface.Stride, null));
            }
        }
示例#18
0
 protected virtual void ShapeSurface(Cairo.Context cr, Cairo.Color color)
 {
     cr.Operator = Cairo.Operator.Source;
     Cairo.Pattern pattern = new Cairo.SolidPattern(color, false);
     cr.Source = pattern;
     pattern.Destroy();
     cr.Paint();
 }
示例#19
0
 protected virtual void ShapeSurface(Cairo.Context cr, Cairo.Color color)
 {
     cr.Operator = Cairo.Operator.Source;
     using (var pattern = new Cairo.SolidPattern(color, false)) {
         cr.SetSource(pattern);
         cr.Paint();
     }
 }
示例#20
0
 private void DrawImageTop(Cairo.Context ctx)
 {
     if (image != null)
     {
         Gdk.CairoHelper.SetSourcePixbuf(ctx, image_top, 0, 0);
         ctx.Paint();
     }
 }
        void OnExpose(object sender, ExposeEventArgs args)
        {
            DrawingArea area = (DrawingArea)sender;

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

            int width  = area.Allocation.Width;
            int height = area.Allocation.Height;

            PixelDimensions = new Vector2i(width, height);

            AxisAlignedBox2d bounds = DrawingBounds;

            double sx = (double)width / bounds.Width;
            double sy = (double)height / bounds.Height;

            float scale = (float)Math.Min(sx, sy);

            // we apply this translate after scaling to pixel coords
            Vector2f pixC      = Zoom * scale * (Vector2f)bounds.Center;
            Vector2f translate = new Vector2f(width / 2, height / 2) - pixC;


            using (var bitmap = new SKBitmap(width, height, SkiaUtil.ColorType(), SKAlphaType.Premul)) {
                IntPtr len;
                using (var skSurface = SKSurface.Create(bitmap.Info.Width, bitmap.Info.Height, SkiaUtil.ColorType(), SKAlphaType.Premul, bitmap.GetPixels(out len), bitmap.Info.RowBytes)) {
                    var canvas = skSurface.Canvas;

                    // update scene xform
                    Func <Vector2d, Vector2f> ViewTransformF = (pOrig) => {
                        Vector2f pNew = (Vector2f)pOrig - (Vector2f)bounds.Center;
                        pNew   = Zoom * scale * pNew;
                        pNew  += (Vector2f)pixC;
                        pNew  += translate + Zoom * PixelTranslate;
                        pNew.y = canvas.ClipBounds.Height - pNew.y;
                        return(pNew);
                    };

                    DrawScene(canvas, ViewTransformF);

                    Cairo.Surface cairoSurf = new Cairo.ImageSurface(
                        bitmap.GetPixels(out len),
                        Cairo.Format.Argb32,
                        bitmap.Width, bitmap.Height,
                        bitmap.Width * 4);

                    cairoSurf.MarkDirty();
                    cairoContext.SetSourceSurface(cairoSurf, 0, 0);
                    cairoContext.Paint();

                    cairoSurf.Dispose();
                }
            }

            cairoContext.Dispose();

            //return true;
        }
示例#22
0
        /// <summary>
        /// Creates a bitmap for each character in the font.
        /// Characters that the font does not include will not be assigned a bitmap.
        /// </summary>
        private void CreateBitmaps()
        {
            characters = new Dictionary <char, PixelSet>();
            ImageSurface surface = new ImageSurface(Format.RGB24, 1, 1);
            Context      context = new Context(surface);

            context.SelectFontFace(FontName, FontSlant.Normal, FontWeight.Normal);
            context.SetFontSize(Font.Size);
            TextExtents ext   = context.TextExtents("@");
            int         charW = (int)Math.Ceiling(ext.Width);
            int         charH = (int)Math.Ceiling(ext.Height);

            context.Dispose();
            surface.Dispose();

            surface = new ImageSurface(Format.RGB24, charW, charH);
            context = new Context(surface);
            PixelSet missingChar = null;

            for (int i = 0; i < asciiString.Length; i++)
            {
                // Render one character into a PixelSet
                string asciiChar = string.Empty + asciiString[i];
                context.SelectFontFace(FontName, FontSlant.Normal, FontWeight.Normal);
                context.SetFontSize(Font.Size);
                context.SetSourceRGB(0.067, 0.067, 0.067);
                context.Paint();
                context.SetSourceRGB(1, 1, 1);
                ext = context.TextExtents(asciiChar);
                context.MoveTo(ext.XBearing, ext.YBearing * -1);
                context.ShowText(asciiChar);
                PixelSet ch = new PixelSet(surface);

                // Filter out characters the font doesn't include
                // The first character is always unprintable, and serves as
                // a reference for what unprintable characters look like in this font
                if (i == 0)
                {
                    missingChar = ch;
                    continue;
                }
                else if (ch == missingChar)
                {
                    continue;
                }
                characters.Add(asciiString[i], ch);
            }
            context.Dispose();
            surface.Dispose();

            // Add the space manually if it wasn't included
            if (!characters.ContainsKey(' '))
            {
                var en = characters.Values.GetEnumerator();
                en.MoveNext();
                characters.Add(' ', new PixelSet(en.Current.Width, en.Current.Height));
            }
        }
示例#23
0
        // TileGridViewer override
        protected override void TileDrawer(int index, Cairo.Context cr)
        {
            int x      = index % _map.MapWidth;
            int y      = index / _map.MapWidth;
            var source = GetTileImage(x, y);

            cr.SetSource(source, 0, 0);
            cr.Paint();
        }
示例#24
0
        // Expose callback for the drawing area
        void DrawnCallback(object o, DrawnArgs args)
        {
            Cairo.Context cr = args.Cr;

            Gdk.CairoHelper.SetSourcePixbuf(cr, frame, 0, 0);
            cr.Paint();

            args.RetVal = true;
        }
 public void DrawIcon(TextEditor editor, Cairo.Context cr, DocumentLine line, int lineNumber, double x, double y, double width, double height)
 {
     Gdk.CairoHelper.SetSourcePixbuf(
         cr,
         errors.Any(e => e.IsError) ? cache.errorPixbuf : cache.warningPixbuf,
         (int)(x + (width - cache.errorPixbuf.Width) / 2),
         (int)(y + (height - cache.errorPixbuf.Height) / 2));
     cr.Paint();
 }
示例#26
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);
        }
示例#27
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;
                    }
                }
            }
示例#28
0
 public override void Draw(Bitmap bitmap, int x, int y)
 {
     using (Cairo.Surface s = new BitmapSurface(bitmap)) {
         cr.SetSourceSurface(s, x + xOffset, y + yOffset);
         using (Cairo.SurfacePattern pattern = (Cairo.SurfacePattern)cr.GetSource()) {
             pattern.Filter = Cairo.Filter.Nearest;
         }
         cr.Paint();
     }
 }
示例#29
0
        public static Cairo.Surface ToSurface(this Pixbuf pixbuf)
        {
            var surface = CairoExtensions.CreateImageSurface(Cairo.Format.ARGB32, pixbuf.Width, pixbuf.Height);

            using (var g = new Cairo.Context(surface)) {
                Gdk.CairoHelper.SetSourcePixbuf(g, pixbuf, 0, 0);
                g.Paint();
            }

            return(surface);
        }
示例#30
0
        private void Activated(object sender, EventArgs e)
        {
            int delay = PintaCore.Settings.GetSetting <int> ("screenshot-delay", 0);

            using var dialog = new SpinButtonEntryDialog(Translations.GetString("Take Screenshot"),
                                                         PintaCore.Chrome.MainWindow, Translations.GetString("Delay before taking a screenshot (seconds):"), 0, 300, delay);

            if (dialog.Run() == (int)Gtk.ResponseType.Ok)
            {
                delay = dialog.GetValue();

                PintaCore.Settings.PutSetting("screenshot-delay", delay);

                GLib.Timeout.Add((uint)delay * 1000, () => {
                    Screen screen   = Screen.Default;
                    var root_window = screen.RootWindow;
                    int width       = root_window.Width;
                    int height      = root_window.Height;

                    if (width == 0 || height == 0)
                    {
                        // Something went wrong...
                        // This might happen when running under wayland, see bug 1923241
                        PintaCore.Chrome.ShowErrorDialog(PintaCore.Chrome.MainWindow,
                                                         Translations.GetString("Failed to take screenshot"),
                                                         Translations.GetString("Could not obtain the size of display '{0}'", screen.Display.Name));
                        return(false);
                    }

                    Document doc = PintaCore.Workspace.NewDocument(new Size(width, height), new Cairo.Color(1, 1, 1));

                    using (var pb = new Pixbuf(root_window, 0, 0, width, height)) {
                        using (Cairo.Context g = new Cairo.Context(doc.Layers.UserLayers[0].Surface)) {
                            CairoHelper.SetSourcePixbuf(g, pb, 0, 0);
                            g.Paint();
                        }
                    }

                    doc.IsDirty = true;

                    if (!PintaCore.Chrome.MainWindow.IsActive)
                    {
                        PintaCore.Chrome.MainWindow.UrgencyHint = true;

                        // Don't flash forever
                        GLib.Timeout.Add(3 * 1000, () => PintaCore.Chrome.MainWindow.UrgencyHint = false);
                    }

                    return(false);
                });
            }
        }
示例#31
0
        Gdk.Pixbuf CreatePixBuf(Gdk.Rectangle bounds)
        {
            using (var pmap = new Gdk.Pixmap(Container.GdkWindow, bounds.Width, bounds.Height)) {
                using (Cairo.Context ctx = Gdk.CairoHelper.Create(pmap)) {
                    ctx.Rectangle(0, 0, bounds.Width, bounds.Height);
                    ctx.SetSourceRGBA(BackgroundColor.Red, BackgroundColor.Green, BackgroundColor.Blue, BackgroundColor.Alpha);
                    ctx.Paint();

                    Render(pmap, bounds, Gtk.StateType.Normal);
                    return(Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, bounds.Width, bounds.Height));
                }
            }
        }
示例#32
0
 public override object Create(object img)
 {
     Gdk.Pixbuf pb = (Gdk.Pixbuf)img;
     var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, pb.Width, pb.Height);
     var ic = new Cairo.Context (imgs);
     Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
     ic.Paint ();
     imgs.Flush ();
     ((IDisposable)ic).Dispose ();
     var p = new Cairo.SurfacePattern (imgs);
     p.Extend = Cairo.Extend.Repeat;
     return p;
 }
 public override void DrawForeground(TextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
 {
     cr.Save();
     cr.Translate(
         metrics.X + 0.5 + (metrics.Width - 2 - cache.errorPixbuf.Width) / 2,
         metrics.Y + 0.5 + (metrics.Height - cache.errorPixbuf.Height) / 2
         );
     Gdk.CairoHelper.SetSourcePixbuf(
         cr,
         errors.Any(e => e.IsError) ? cache.errorPixbuf : cache.warningPixbuf, 0, 0);
     cr.Paint();
     cr.Restore();
 }
示例#34
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (!base.OnDrawn(cr))
            {
                return(false);
            }

            if (ViewObjects)
            {
                using (Cairo.Surface source = CairoHelper.LockBitmap(Image)) {
                    cr.SetSourceSurface(source, XOffset, YOffset);
                    cr.Paint();
                    CairoHelper.UnlockBitmap(Image);
                }
            }
            else
            {
                base.OnDrawn(cr);
            }

            if (ViewObjects && objectEditor != null)
            {
                // Draw objects

                int cursorX = -1, cursorY = -1;
                int selectedX = -1, selectedY = -1;
                hoveringObjectIndices = new List <int>();

                ObjectGroup group = objectEditor.ObjectGroup;
                DrawObjectGroup(cr, 0, ref cursorX, ref cursorY, ref selectedX, ref selectedY, group, objectEditor, ref hoveringObjectIndices);

                // Object hovering over
                if (cursorX != -1)
                {
                    cr.Rectangle(cursorX + 0.5, cursorY + 0.5, 15, 15);
                    cr.SetSourceColor(TileGridViewer.HoverColor);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
                // Object selected
                if (selectedX != -1)
                {
                    cr.Rectangle(selectedX + 0.5, selectedY + 0.5, 15, 15);
                    cr.SetSourceColor(TileGridSelector.SelectionColor);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
            }

            return(true);
        }
示例#35
0
        public void Import(LayerManager layers, string fileName)
        {
            Pixbuf bg = new Pixbuf (fileName);
            Size imagesize = new Size (bg.Width, bg.Height);

            PintaCore.Workspace.CreateAndActivateDocument (fileName, imagesize);
            PintaCore.Workspace.ActiveDocument.HasFile = true;
            PintaCore.Workspace.ActiveDocument.ImageSize = imagesize;
            PintaCore.Workspace.ActiveWorkspace.CanvasSize = imagesize;

            Layer layer = layers.AddNewLayer (Path.GetFileName (fileName));

            using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
                CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
                g.Paint ();
            }

            bg.Dispose ();
        }
示例#36
0
        public void Import(LayerManager layers, string fileName)
        {
            Pixbuf bg = new Pixbuf (fileName);

            layers.Clear ();
            PintaCore.History.Clear ();
            layers.DestroySelectionLayer ();

            PintaCore.Workspace.ImageSize = new Size (bg.Width, bg.Height);
            PintaCore.Workspace.CanvasSize = new Gdk.Size (bg.Width, bg.Height);
            layers.ResetSelectionPath ();

            Layer layer = layers.AddNewLayer (Path.GetFileName (fileName));

            using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
                CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
                g.Paint ();
            }

            bg.Dispose ();
        }
示例#37
0
        private void Activated(object sender, EventArgs e)
        {
            int delay = PintaCore.Settings.GetSetting<int> ("screenshot-delay", 0);

            SpinButtonEntryDialog dialog = new SpinButtonEntryDialog (Catalog.GetString ("Take Screenshot"),
                    PintaCore.Chrome.MainWindow, Catalog.GetString ("Delay before taking a screenshot (seconds):"), 0, 300, delay);

            if (dialog.Run () == (int)Gtk.ResponseType.Ok) {
                delay = dialog.GetValue ();

                PintaCore.Settings.PutSetting ("screenshot-delay", delay);
                PintaCore.Settings.SaveSettings ();

                GLib.Timeout.Add ((uint)delay * 1000, () => {
                    Screen screen = Screen.Default;
                    Document doc = PintaCore.Workspace.NewDocument (new Size (screen.Width, screen.Height), false);

                    using (Pixbuf pb = Pixbuf.FromDrawable (screen.RootWindow, screen.RootWindow.Colormap, 0, 0, 0, 0, screen.Width, screen.Height)) {
                        using (Cairo.Context g = new Cairo.Context (doc.UserLayers[0].Surface)) {
                            CairoHelper.SetSourcePixbuf (g, pb, 0, 0);
                            g.Paint ();
                        }
                    }

                    doc.IsDirty = true;

                    if (!PintaCore.Chrome.MainWindow.IsActive) {
                        PintaCore.Chrome.MainWindow.UrgencyHint = true;

                        // Don't flash forever
                        GLib.Timeout.Add (3 * 1000, () => PintaCore.Chrome.MainWindow.UrgencyHint = false);
                    }

                    return false;
                });
            }

            dialog.Destroy ();
        }
示例#38
0
 public Cairo.Pattern GetPattern(ApplicationContext actx, double scaleFactor)
 {
     if (pattern == null || currentScaleFactor != scaleFactor) {
         if (pattern != null)
             pattern.Dispose ();
         Gdk.Pixbuf pb = ((GtkImage)Image.Backend).GetBestFrame (actx, scaleFactor, Image.Size.Width, Image.Size.Height, false);
         var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, (int)(Image.Size.Width * scaleFactor), (int)(Image.Size.Height * scaleFactor));
         var ic = new Cairo.Context (imgs);
         ic.Scale ((double)imgs.Width / (double)pb.Width, (double)imgs.Height / (double)pb.Height);
         Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
         ic.Paint ();
         imgs.Flush ();
         ((IDisposable)ic).Dispose ();
         pattern = new Cairo.SurfacePattern (imgs);
         pattern.Extend = Cairo.Extend.Repeat;
         var cm = new Cairo.Matrix ();
         cm.Scale (scaleFactor, scaleFactor);
         pattern.Matrix = cm;
         currentScaleFactor = scaleFactor;
     }
     return pattern;
 }
示例#39
0
        public void OpenFile(string file)
        {
            try {
                // Open the image and add it to the layers
                Pixbuf bg = new Pixbuf (file);

                PintaCore.Layers.Clear ();
                PintaCore.History.Clear ();
                PintaCore.Layers.DestroySelectionLayer ();

                PintaCore.Workspace.ImageSize = new Cairo.Point (bg.Width, bg.Height);
                PintaCore.Workspace.CanvasSize = new Cairo.Point (bg.Width, bg.Height);

                PintaCore.Layers.ResetSelectionPath ();

                Layer layer = PintaCore.Layers.AddNewLayer (System.IO.Path.GetFileName (file));

                using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
                    CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
                    g.Paint ();
                }

                bg.Dispose ();

                PintaCore.Workspace.Filename = System.IO.Path.GetFileName (file);
                PintaCore.History.PushNewItem (new BaseHistoryItem ("gtk-open", "Open Image"));
                PintaCore.Workspace.IsDirty = false;
                PintaCore.Actions.View.ZoomToWindow.Activate ();
                PintaCore.Workspace.Invalidate ();
            } catch {
                MessageDialog md = new MessageDialog (PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Could not open file: {0}", file);
                md.Title = "Error";

                md.Run ();
                md.Destroy ();
            }
        }
示例#40
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            painting = false;

            using (Cairo.Context g = new Cairo.Context (doc.CurrentLayer.Surface)) {
                g.SetSource (doc.ToolLayer.Surface);
                g.Paint ();
            }

            base.OnMouseUp (canvas, args, point);

            offset = new Point (int.MinValue, int.MinValue);
            last_point = new Point (int.MinValue, int.MinValue);

            doc.ToolLayer.Clear ();
            doc.ToolLayer.Hidden = true;
            doc.Workspace.Invalidate ();
        }
示例#41
0
        protected Gdk.Pixbuf DrawConstDataIcon()
        {
            using (var surface = new Cairo.ImageSurface (Cairo.Format.Argb32, rectSizing.Width, rectSizing.Height)) {
                using (Cairo.Context cr = new Cairo.Context (surface)) {
                    // background
                    cr.SetSourceRGB (0.7, 0.7, 0.7);
                    cr.Paint ();

                    // text
                    cr.SetSourceRGB (1, 0, 0);
                    // simple Cairo text API instead of Pango
                    //cr.MoveTo (10, 0.3 * height);
                    //cr.SetFontSize (20);
                    //cr.ShowText ("const");

                    using (var layout = Pango.CairoHelper.CreateLayout (cr)) {
                        // font size 12 seems suitable for iconHeight 48 pixels
                        float fontSize = 12 * rectSizing.Height / 48f;
                        layout.FontDescription = Pango.FontDescription.FromString ("Sans " + fontSize.ToString ());
                        layout.SetText ("const");
                        layout.Width = rectSizing.Width;
                        layout.Alignment = Pango.Alignment.Center;
                        int lwidth, lheight;
                        layout.GetPixelSize (out lwidth, out lheight);
                        // 0, 0 = left top
                        //cr.MoveTo (0.5 * (width - lwidth), 0.5 * (height - lheight));
                        cr.MoveTo (0.5 * rectSizing.Width, 0.5 * (rectSizing.Height - lheight));
                        Pango.CairoHelper.ShowLayout (cr, layout);
                    }
                }
                return new Gdk.Pixbuf (surface.Data, Gdk.Colorspace.Rgb, true, 8, rectSizing.Width, rectSizing.Height, surface.Stride, null);
            }
        }
示例#42
0
        private void HandlePintaCoreActionsLayersImportFromFileActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;
            PintaCore.Tools.Commit ();

            Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog (Catalog.GetString ("Open Image File"), null, FileChooserAction.Open, Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Ok);

            fcd.SetCurrentFolder (PintaCore.System.LastDialogDirectory);
            fcd.AlternativeButtonOrder = new int[] { (int) ResponseType.Ok, (int) ResponseType.Cancel };

            fcd.AddImagePreview ();

            int response = fcd.Run ();

            if (response == (int)Gtk.ResponseType.Ok) {

                string file = fcd.Filename;
                PintaCore.System.LastDialogDirectory = fcd.CurrentFolder;

                // Open the image and add it to the layers
                Layer layer = doc.AddNewLayer (System.IO.Path.GetFileName (file));

                using (var fs = new FileStream (file, FileMode.Open))
                    using (Pixbuf bg = new Pixbuf (fs))
                        using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
                            CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
                            g.Paint ();
                        }

                doc.SetCurrentLayer (layer);

                AddLayerHistoryItem hist = new AddLayerHistoryItem ("Menu.Layers.ImportFromFile.png", Catalog.GetString ("Import From File"), doc.Layers.IndexOf (layer));
                doc.History.PushNewItem (hist);

                doc.Workspace.Invalidate ();
            }

            fcd.Destroy ();
        }
示例#43
0
        // Create a new surface of the appropriate size to store our scribbles
        private void ScribbleConfigure(object o, ConfigureEventArgs args)
        {
            Widget widget = o as Widget;

            if (surface != null)
                surface.Destroy ();

            var allocation = widget.Allocation;

            surface = widget.Window.CreateSimilarSurface (Cairo.Content.Color, allocation.Width, allocation.Height);
            var cr = new Cairo.Context (surface);

            cr.SetSourceRGB (1, 1, 1);
            cr.Paint ();
            ((IDisposable)cr).Dispose ();

            // We've handled the configure event, no need for further processing.
            args.RetVal = true;
        }
示例#44
0
        public void NewFile(Size imageSize)
        {
            PintaCore.Workspace.ActiveDocument.HasFile = false;
            PintaCore.Workspace.ImageSize = imageSize;
            PintaCore.Workspace.CanvasSize = imageSize;

            PintaCore.Layers.Clear ();
            PintaCore.History.Clear ();
            PintaCore.Layers.DestroySelectionLayer ();
            PintaCore.Layers.ResetSelectionPath ();

            // Start with an empty white layer
            Layer background = PintaCore.Layers.AddNewLayer (Catalog.GetString ("Background"));

            using (Cairo.Context g = new Cairo.Context (background.Surface)) {
                g.SetSourceRGB (255, 255, 255);
                g.Paint ();
            }

            PintaCore.Workspace.Filename = "Untitled1";
            PintaCore.History.PushNewItem (new BaseHistoryItem (Stock.New, Catalog.GetString ("New Image")));
            PintaCore.Workspace.IsDirty = false;
            PintaCore.Actions.View.ZoomToWindow.Activate ();
        }
示例#45
0
        public MainWindow()
            : base(Gtk.WindowType.Toplevel)
        {
            Build ();

            Requisition req = new Requisition ();
            req.Height = 600;
            req.Width = 800;
            drawingarea1.Requisition = req;

            // Initialize interface things
            PintaCore.Actions.AccelGroup = new AccelGroup ();
            this.AddAccelGroup (PintaCore.Actions.AccelGroup);

            PintaCore.Initialize (tooltoolbar, label5, drawingarea1, treeview1, this);
            colorpalettewidget1.Initialize ();

            PintaCore.Chrome.StatusBarTextChanged += new EventHandler<TextChangedEventArgs> (Chrome_StatusBarTextChanged);
            PintaCore.History.HistoryItemAdded += new EventHandler<HistoryItemAddedEventArgs> (History_HistoryItemAdded);
            PintaCore.History.HistoryItemRemoved += new EventHandler<HistoryItemRemovedEventArgs> (History_HistoryItemRemoved);
            PintaCore.Workspace.CanvasInvalidated += new EventHandler<CanvasInvalidatedEventArgs> (Workspace_CanvasInvalidated);
            PintaCore.Workspace.CanvasSizeChanged += new EventHandler (Workspace_CanvasSizeChanged);
            CreateToolBox ();

            PintaCore.Actions.CreateMainMenu (menubar1);
            PintaCore.Actions.CreateToolBar (toolbar1);
            PintaCore.Actions.Layers.CreateLayerWindowToolBar (toolbar4);
            PintaCore.Actions.Edit.CreateHistoryWindowToolBar (toolbar2);

            Gtk.Image i = new Gtk.Image (PintaCore.Resources.GetIcon ("StatusBar.CursorXY.png"));
            i.Show ();

            statusbar1.Add (i);
            Gtk.Box.BoxChild box = (Gtk.Box.BoxChild)statusbar1[i];
            box.Position = 2;
            box.Fill = false;
            box.Expand = false;

            this.Icon = PintaCore.Resources.GetIcon ("Pinta.png");

            dialog_handler = new DialogHandlers (this);

            // Create a blank document
            Layer background = PintaCore.Layers.AddNewLayer ("Background");

            using (Cairo.Context g = new Cairo.Context (background.Surface)) {
                g.SetSourceRGB (255, 255, 255);
                g.Paint ();
            }

            PintaCore.Workspace.Filename = "Untitled1";
            PintaCore.Workspace.IsDirty = false;

            PintaCore.Workspace.Invalidate ();

            treeview1.Model = new ListStore (typeof (Pixbuf), typeof (string));
            treeview1.HeadersVisible = false;
            treeview1.RowActivated += HandleTreeview1RowActivated;
            AddColumns (treeview1);

            PintaCore.Actions.View.ZoomToWindow.Activated += new EventHandler (ZoomToWindow_Activated);
            DeleteEvent += new DeleteEventHandler (MainWindow_DeleteEvent);

            WindowAction.Visible = false;

            if (Platform.GetOS () == Platform.OS.Mac)
            {
                try {
                    //enable the global key handler for keyboard shortcuts
                    IgeMacMenu.GlobalKeyHandlerEnabled = true;

                    //Tell the IGE library to use your GTK menu as the Mac main menu
                    IgeMacMenu.MenuBar = menubar1;
                    /*
                    //tell IGE which menu item should be used for the app menu's quit item
                    IgeMacMenu.QuitMenuItem = yourQuitMenuItem;
                    */
                    //add a new group to the app menu, and add some items to it
                    var appGroup = IgeMacMenu.AddAppMenuGroup();
                    MenuItem aboutItem = (MenuItem) PintaCore.Actions.Help.About.CreateMenuItem();
                    appGroup.AddMenuItem(aboutItem, Mono.Unix.Catalog.GetString ("About"));

                    menubar1.Hide();
                } catch {
                    // If things don't work out, just use a normal menu.
                }
            }
        }
示例#46
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 ();
		}
示例#47
0
		void OnDraw (object data)
		{
			Action<Cairo.Context> callback = (Action<Cairo.Context>) data;

			using (var context = new Cairo.Context (surface.Surface)) {
				context.Operator = Cairo.Operator.Source;
				context.SetSourceRGBA (0, 0, 0, 0);
				context.Paint ();
				context.Operator = Cairo.Operator.Over;

				context.Scale (Scale, Scale);
				callback (context);
			}
			runningSignal.Set ();
		}
示例#48
0
        public MainWindow()
            : base(Gtk.WindowType.Toplevel)
        {
            Build ();

            Requisition req = new Requisition ();
            req.Height = 600;
            req.Width = 800;
            drawingarea1.Requisition = req;

            // Initialize interface things
            PintaCore.Actions.AccelGroup = new AccelGroup ();
            this.AddAccelGroup (PintaCore.Actions.AccelGroup);

            progress_dialog = new ProgressDialog ();

            PintaCore.Initialize (tooltoolbar, label5, drawingarea1, history_treeview, this, progress_dialog, (Gtk.Viewport)table1.Parent);
            colorpalettewidget1.Initialize ();

            PintaCore.Chrome.StatusBarTextChanged += new EventHandler<TextChangedEventArgs> (Chrome_StatusBarTextChanged);
            PintaCore.Workspace.CanvasInvalidated += new EventHandler<CanvasInvalidatedEventArgs> (Workspace_CanvasInvalidated);
            PintaCore.Workspace.CanvasSizeChanged += new EventHandler (Workspace_CanvasSizeChanged);
            CreateToolBox ();

            PintaCore.Actions.CreateMainMenu (menubar1);
            PintaCore.Actions.CreateToolBar (toolbar1);
            PintaCore.Actions.Layers.CreateLayerWindowToolBar (toolbar4);
            PintaCore.Actions.Edit.CreateHistoryWindowToolBar (toolbar2);

            Gtk.Image i = new Gtk.Image (PintaCore.Resources.GetIcon ("StatusBar.CursorXY.png"));
            i.Show ();

            statusbar1.Add (i);
            Gtk.Box.BoxChild box = (Gtk.Box.BoxChild)statusbar1[i];
            box.Position = 2;
            box.Fill = false;
            box.Expand = false;

            this.Icon = PintaCore.Resources.GetIcon ("Pinta.png");

            dialog_handler = new DialogHandlers (this);

            // Create a blank document
            Layer background = PintaCore.Layers.AddNewLayer ("Background");

            using (Cairo.Context g = new Cairo.Context (background.Surface)) {
                g.SetSourceRGB (255, 255, 255);
                g.Paint ();
            }

            PintaCore.Workspace.Filename = "Untitled1";
            PintaCore.History.PushNewItem (new BaseHistoryItem ("gtk-new", "New Image"));
            PintaCore.Workspace.IsDirty = false;
            PintaCore.Workspace.Invalidate ();

            //History
            history_treeview.Model = PintaCore.History.ListStore;
            history_treeview.HeadersVisible = false;
            history_treeview.Selection.Mode = SelectionMode.Single;
            history_treeview.Selection.SelectFunction = HistoryItemSelected;

            Gtk.TreeViewColumn icon_column = new Gtk.TreeViewColumn ();
            Gtk.CellRendererPixbuf icon_cell = new Gtk.CellRendererPixbuf ();
            icon_column.PackStart (icon_cell, true);

            Gtk.TreeViewColumn text_column = new Gtk.TreeViewColumn ();
            Gtk.CellRendererText text_cell = new Gtk.CellRendererText ();
            text_column.PackStart (text_cell, true);

            text_column.SetCellDataFunc (text_cell, new Gtk.TreeCellDataFunc (HistoryRenderText));
            icon_column.SetCellDataFunc (icon_cell, new Gtk.TreeCellDataFunc (HistoryRenderIcon));

            history_treeview.AppendColumn (icon_column);
            history_treeview.AppendColumn (text_column);

            PintaCore.History.HistoryItemAdded += new EventHandler<HistoryItemAddedEventArgs> (OnHistoryItemsChanged);
            PintaCore.History.ActionUndone += new EventHandler (OnHistoryItemsChanged);
            PintaCore.History.ActionRedone += new EventHandler (OnHistoryItemsChanged);

            PintaCore.Actions.View.ZoomToWindow.Activated += new EventHandler (ZoomToWindow_Activated);
            DeleteEvent += new DeleteEventHandler (MainWindow_DeleteEvent);

            PintaCore.LivePreview.RenderUpdated += LivePreview_RenderUpdated;

            WindowAction.Visible = false;

            hruler = new HRuler ();
            hruler.Metric = MetricType.Pixels;
            table1.Attach (hruler, 1, 2, 0, 1, AttachOptions.Shrink | AttachOptions.Fill, AttachOptions.Shrink | AttachOptions.Fill, 0, 0);

            vruler = new VRuler ();
            vruler.Metric = MetricType.Pixels;
            table1.Attach (vruler, 0, 1, 1, 2, AttachOptions.Shrink | AttachOptions.Fill, AttachOptions.Shrink | AttachOptions.Fill, 0, 0);

            UpdateRulerRange ();

            PintaCore.Actions.View.ZoomComboBox.ComboBox.Changed += HandlePintaCoreActionsViewZoomComboBoxComboBoxChanged;

            gr = new GridRenderer (cr);

            if (Platform.GetOS () == Platform.OS.Mac) {
                try {
                    //enable the global key handler for keyboard shortcuts
                    IgeMacMenu.GlobalKeyHandlerEnabled = true;

                    //Tell the IGE library to use your GTK menu as the Mac main menu
                    IgeMacMenu.MenuBar = menubar1;
                    /*
                    //tell IGE which menu item should be used for the app menu's quit item
                    IgeMacMenu.QuitMenuItem = yourQuitMenuItem;
                    */
                    //add a new group to the app menu, and add some items to it
                    var appGroup = IgeMacMenu.AddAppMenuGroup ();
                    MenuItem aboutItem = (MenuItem)PintaCore.Actions.Help.About.CreateMenuItem ();
                    appGroup.AddMenuItem (aboutItem, Mono.Unix.Catalog.GetString ("About"));

                    menubar1.Hide ();
                } catch {
                    // If things don't work out, just use a normal menu.
                }
            }
        }
示例#49
0
        private Layer CreateOffsetLayer(Layer original)
        {
            var offset = OffsetLayer;
            offset.Surface.Clear ();

            using (var g = new Cairo.Context (offset.Surface)) {
                g.SetSourceSurface (original.Surface, (int)original.Offset.X, (int)original.Offset.Y);
                g.Paint ();
            }

            offset.BlendMode = original.BlendMode;
            offset.Offset = original.Offset;
            offset.Opacity = original.Opacity;

            return offset;
        }
示例#50
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;
        }
示例#51
0
        public bool OpenFile(string file)
        {
            bool fileOpened = false;

            try {
                // Open the image and add it to the layers
                if (System.IO.Path.GetExtension (file) == ".ora") {
                    new OraFormat ().Import (PintaCore.Layers, file);
                }
                else {
                    Pixbuf bg = new Pixbuf (file);

                    PintaCore.Layers.Clear ();
                    PintaCore.History.Clear ();
                    PintaCore.Layers.DestroySelectionLayer ();

                    PintaCore.Workspace.ImageSize = new Size (bg.Width, bg.Height);
                    PintaCore.Workspace.CanvasSize = new Gdk.Size (bg.Width, bg.Height);

                    PintaCore.Layers.ResetSelectionPath ();

                    Layer layer = PintaCore.Layers.AddNewLayer (System.IO.Path.GetFileName (file));

                    using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
                        CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
                        g.Paint ();
                    }

                    bg.Dispose ();
                }

                PintaCore.Workspace.DocumentPath = System.IO.Path.GetFullPath (file);
                PintaCore.History.PushNewItem (new BaseHistoryItem (Stock.Open, Catalog.GetString ("Open Image")));
                PintaCore.Workspace.IsDirty = false;
                PintaCore.Actions.View.ZoomToWindow.Activate ();
                PintaCore.Workspace.Invalidate ();

                fileOpened = true;
            } catch {
                MessageDialog md = new MessageDialog (PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Catalog.GetString ("Could not open file: {0}"), file);
                md.Title = Catalog.GetString ("Error");

                md.Run ();
                md.Destroy ();
            }

            return fileOpened;
        }
示例#52
0
        private void HandlePintaCoreActionsLayersImportFromFileActivated(object sender, EventArgs e)
        {
            PintaCore.Layers.FinishSelection ();

            Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog ("Open Image File", null, FileChooserAction.Open, Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Ok);

            int response = fcd.Run ();

            if (response == (int)Gtk.ResponseType.Ok) {

                string file = fcd.Filename;

                // Open the image and add it to the layers
                Layer layer = PintaCore.Layers.AddNewLayer (System.IO.Path.GetFileName (file));

                Pixbuf bg = new Pixbuf (file, (int)PintaCore.Workspace.ImageSize.X, (int)PintaCore.Workspace.ImageSize.Y, true);

                using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
                    CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
                    g.Paint ();
                }

                bg.Dispose ();

                PintaCore.Layers.SetCurrentLayer (layer);

                AddLayerHistoryItem hist = new AddLayerHistoryItem ("Menu.Layers.ImportFromFile.png", Mono.Unix.Catalog.GetString ("Import From File"), PintaCore.Layers.IndexOf (layer));
                PintaCore.History.PushNewItem (hist);

                PintaCore.Workspace.Invalidate ();
            }

            fcd.Destroy ();
        }
示例#53
0
        public static Cairo.Surface ToSurface (this Pixbuf pixbuf)
        {
            var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, pixbuf.Width, pixbuf.Height);

            using (var g = new Cairo.Context (surface)) {
                Gdk.CairoHelper.SetSourcePixbuf (g, pixbuf, 0, 0);
                g.Paint ();
            }

            return surface;
        }
示例#54
0
        public MainWindow()
            : base(Gtk.WindowType.Toplevel)
        {
            Build ();

            Requisition req = new Requisition ();
            req.Height = 600;
            req.Width = 800;
            drawingarea1.Requisition = req;

            // Initialize interface things
            PintaCore.Actions.AccelGroup = new AccelGroup ();
            this.AddAccelGroup (PintaCore.Actions.AccelGroup);

            PintaCore.Initialize (tooltoolbar, label5, drawingarea1, treeview1, this);
            colorpalettewidget1.Initialize ();

            PintaCore.Chrome.StatusBarTextChanged += new EventHandler<TextChangedEventArgs> (Chrome_StatusBarTextChanged);
            PintaCore.History.HistoryItemAdded += new EventHandler<HistoryItemAddedEventArgs> (History_HistoryItemAdded);
            PintaCore.History.HistoryItemRemoved += new EventHandler<HistoryItemRemovedEventArgs> (History_HistoryItemRemoved);
            PintaCore.Workspace.CanvasInvalidated += new EventHandler<CanvasInvalidatedEventArgs> (Workspace_CanvasInvalidated);
            PintaCore.Workspace.CanvasSizeChanged += new EventHandler (Workspace_CanvasSizeChanged);
            CreateToolBox ();

            PintaCore.Actions.CreateMainMenu (menubar1);
            PintaCore.Actions.CreateToolBar (toolbar1);
            PintaCore.Actions.Layers.CreateLayerWindowToolBar (toolbar4);
            PintaCore.Actions.Edit.CreateHistoryWindowToolBar (toolbar2);

            Gtk.Image i = new Gtk.Image (PintaCore.Resources.GetIcon ("StatusBar.CursorXY.png"));
            i.Show ();

            statusbar1.Add (i);
            Gtk.Box.BoxChild box = (Gtk.Box.BoxChild)statusbar1[i];
            box.Position = 2;
            box.Fill = false;
            box.Expand = false;

            this.Icon = PintaCore.Resources.GetIcon ("Pinta.png");

            dialog_handler = new DialogHandlers (this);

            // Create a blank document
            Layer background = PintaCore.Layers.AddNewLayer ("Background");

            using (Cairo.Context g = new Cairo.Context (background.Surface)) {
                g.SetSourceRGB (255, 255, 255);
                g.Paint ();
            }

            PintaCore.Workspace.Filename = "Untitled1";
            PintaCore.Workspace.IsDirty = false;

            PintaCore.Workspace.Invalidate ();

            treeview1.Model = new ListStore (typeof (Pixbuf), typeof (string));
            treeview1.HeadersVisible = false;
            treeview1.RowActivated += HandleTreeview1RowActivated;
            AddColumns (treeview1);

            PintaCore.Actions.View.ZoomToWindow.Activated += new EventHandler (ZoomToWindow_Activated);
            DeleteEvent += new DeleteEventHandler (MainWindow_DeleteEvent);

            EffectsAction.Visible = false;
            WindowAction.Visible = false;
        }
示例#55
0
		public void Start (BaseEffect effect)
		{			
			if (live_preview_enabled)
				throw new InvalidOperationException ("LivePreviewManager.Start() called while live preview is already enabled.");
			
			// Create live preview surface.
			// Start rendering.
			// Listen for changes to effectConfiguration object, and restart render if needed.
			
			live_preview_enabled = true;
			apply_live_preview_flag = false;
			cancel_live_preview_flag = false;
			
			layer = PintaCore.Layers.CurrentLayer;
			this.effect = effect;
			
			// Handle selection path.
			PintaCore.Tools.Commit ();
			selection_path = (PintaCore.Layers.ShowSelection) ? PintaCore.Workspace.ActiveDocument.Selection.SelectionPath : null;
			render_bounds = selection_path.GetBounds ();
			render_bounds = PintaCore.Workspace.ClampToImageSize (render_bounds);			
									
			//TODO Use the current tool layer instead.
			live_preview_surface = new Cairo.ImageSurface (Cairo.Format.Argb32,
			                                  PintaCore.Workspace.ImageSize.Width,
			                                  PintaCore.Workspace.ImageSize.Height);
			
			// Paint the pre-effect layer surface into into the working surface.
			using (var ctx = new Cairo.Context (live_preview_surface)) {
				ctx.SetSourceSurface (layer.Surface, (int) layer.Offset.X, (int) layer.Offset.Y);
				ctx.Paint ();
			}
			
			if (effect.EffectData != null)
				effect.EffectData.PropertyChanged += EffectData_PropertyChanged;
			
			if (Started != null) {
				Started (this, new LivePreviewStartedEventArgs());
			}
			
			var settings = new AsyncEffectRenderer.Settings () {
				ThreadCount = PintaCore.System.RenderThreads,
				TileWidth = render_bounds.Width,
				TileHeight = 1,
				ThreadPriority = ThreadPriority.BelowNormal
			};
			
			Debug.WriteLine (DateTime.Now.ToString("HH:mm:ss:ffff") + "Start Live preview.");
			
			renderer = new Renderer (this, settings);
			renderer.Start (effect, layer.Surface, live_preview_surface, render_bounds);
			
			if (effect.IsConfigurable) {		
				if (!effect.LaunchConfiguration ()) {
					PintaCore.Chrome.MainWindowBusy = true;
					Cancel ();
				} else {
					PintaCore.Chrome.MainWindowBusy = true;
					Apply ();
				}
			} else {
				PintaCore.Chrome.MainWindowBusy = true;
				Apply ();
			}
		}
示例#56
0
        private void HandlePintaCoreActionsFileOpenActivated(object sender, EventArgs e)
        {
            Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog ("Open Image File", PintaCore.Chrome.MainWindow, FileChooserAction.Open, Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Ok);

            int response = fcd.Run ();

            if (response == (int)Gtk.ResponseType.Ok) {

                string file = fcd.Filename;

                PintaCore.Layers.Clear ();
                PintaCore.History.Clear ();
                PintaCore.Layers.DestroySelectionLayer ();

                // Open the image and add it to the layers
                Pixbuf bg = new Pixbuf (file);

                PintaCore.Workspace.ImageSize = new Cairo.PointD (bg.Width, bg.Height);
                PintaCore.Workspace.CanvasSize = new Cairo.PointD (bg.Width, bg.Height);

                PintaCore.Layers.ResetSelectionPath ();

                Layer layer = PintaCore.Layers.AddNewLayer (System.IO.Path.GetFileName (file));

                using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
                    CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
                    g.Paint ();
                }

                bg.Dispose ();

                PintaCore.Workspace.Filename = System.IO.Path.GetFileName (file);
                PintaCore.Workspace.IsDirty = false;

                PintaCore.Workspace.Invalidate ();
                PintaCore.Actions.View.ZoomToWindow.Activate ();
            }

            fcd.Destroy ();
        }
示例#57
0
        public void NewFile(Size imageSize)
        {
            PintaCore.Workspace.CreateAndActivateDocument (null, imageSize);
            PintaCore.Workspace.ActiveDocument.HasFile = false;
            PintaCore.Workspace.ActiveWorkspace.CanvasSize = imageSize;

            // Start with an empty white layer
            Layer background = PintaCore.Workspace.ActiveDocument.AddNewLayer (Catalog.GetString ("Background"));

            using (Cairo.Context g = new Cairo.Context (background.Surface)) {
                g.SetSourceRGB (1, 1, 1);
                g.Paint ();
            }

            PintaCore.Workspace.ActiveWorkspace.History.PushNewItem (new BaseHistoryItem (Stock.New, Catalog.GetString ("New Image")));
            PintaCore.Workspace.ActiveDocument.IsDirty = false;
            PintaCore.Actions.View.ZoomToWindow.Activate ();
        }
示例#58
0
        public void NewFileWithScreenshot()
        {
            Screen screen = Screen.Default;
            Pixbuf pb = Pixbuf.FromDrawable (screen.RootWindow, screen.RootWindow.Colormap, 0, 0, 0, 0, screen.Width, screen.Height);
            NewFile (new Size (screen.Width, screen.Height));

            using (Cairo.Context g = new Cairo.Context (PintaCore.Layers[0].Surface)) {
                CairoHelper.SetSourcePixbuf (g, pb, 0, 0);
                g.Paint ();
            }

            (pb as IDisposable).Dispose ();
            PintaCore.Workspace.ActiveDocument.IsDirty = true;
        }