/// 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();
        }
Пример #2
0
        private void ScribbleDrawn(object o, DrawnArgs args)
        {
            Cairo.Context cr = args.Cr;

            cr.SetSourceSurface(surface, 0, 0);
            cr.Paint();
        }
Пример #3
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();
        }
Пример #4
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 ();
		}
Пример #5
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();
                }
            }
        }
Пример #6
0
        void RenderIcon(Cairo.Context context, SurfaceWrapper surface, double opacity)
        {
            context.SetSourceSurface(surface.Surface,
                                     Allocation.X + (Allocation.Width - surface.Width) / 2,
                                     Allocation.Y + (Allocation.Height - surface.Height) / 2);

            context.PaintWithAlpha(opacity);
        }
Пример #7
0
        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;
        }
Пример #8
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();
     }
 }
Пример #9
0
        private static void MakeReflection(Cairo.Context context, Cairo.ImageSurface source, int w, int h)
        {
            context.ResetClip();
            context.SetSourceSurface(source, 2, 2);
            context.Paint();

            double alpha = -0.3;
            double step  = 1.0 / (double)source.Height;

            context.Translate(0, h);
            context.Scale(1, -1);
            context.SetSourceSurface(source, 2, 2);
            for (int i = 0; i < source.Height; i++)
            {
                context.Rectangle(0, i + 2, w, 1);
                context.Clip();
                alpha += step;
                context.PaintWithAlpha(Math.Max(Math.Min(alpha, 0.7), 0.0));
                context.ResetClip();
            }
        }
Пример #10
0
        // Used by the workspace drawing area expose render loop.
        // Takes care of the clipping.
        public void RenderLivePreviewLayer(Cairo.Context ctx, double opacity)
        {
            if (!IsEnabled)
            {
                throw new InvalidOperationException("Tried to render a live preview after live preview has ended.");
            }

            // TODO remove seam around selection during live preview.

            ctx.Save();
            if (selection_path != null)
            {
                // Paint area outsize of the selection path, with the pre-effect image.
                var imageSize = PintaCore.Workspace.ImageSize;
                ctx.Rectangle(0, 0, imageSize.Width, imageSize.Height);
                ctx.AppendPath(selection_path);
                ctx.Clip();
                ctx.SetSourceSurface(layer.Surface, (int)layer.Offset.X, (int)layer.Offset.Y);
                ctx.PaintWithAlpha(opacity);
                ctx.ResetClip();

                // Paint area inside the selection path, with the post-effect image.
                ctx.AppendPath(selection_path);
                ctx.Clip();

                ctx.SetSourceSurface(live_preview_surface, (int)layer.Offset.X, (int)layer.Offset.Y);
                ctx.PaintWithAlpha(opacity);

                ctx.AppendPath(selection_path);
                ctx.FillRule = Cairo.FillRule.EvenOdd;
                ctx.Clip();
            }
            else
            {
                ctx.SetSourceSurface(live_preview_surface, (int)layer.Offset.X, (int)layer.Offset.Y);
                ctx.PaintWithAlpha(opacity);
            }
            ctx.Restore();
        }
Пример #11
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);
        }
Пример #12
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            int width, height;

            if (this.Log().IsEnabled(LogLevel.Trace))
            {
                this.Log().Trace($"Render {renderCount++}");
            }

            if (_dpi == null)
            {
                UpdateDpi();
            }

            width  = (int)AllocatedWidth;
            height = (int)AllocatedHeight;

            var scaledWidth  = (int)(width * _dpi.Value);
            var scaledHeight = (int)(height * _dpi.Value);

            var info = new SKImageInfo(scaledWidth, scaledHeight, SKImageInfo.PlatformColorType, SKAlphaType.Premul);

            // reset the bitmap if the size has changed
            if (bitmap == null || info.Width != bitmap.Width || info.Height != bitmap.Height)
            {
                bitmap = new SKBitmap(scaledWidth, scaledHeight, SKColorType.Rgba8888, SKAlphaType.Premul);
            }

            using (var surface = SKSurface.Create(info, bitmap.GetPixels(out _)))
            {
                surface.Canvas.Clear(SKColors.White);

                surface.Canvas.Scale((float)_dpi);

                WUX.Window.Current.Compositor.Render(surface, info);

                using (var gtkSurface = new Cairo.ImageSurface(
                           bitmap.GetPixels(out _),
                           Cairo.Format.Argb32,
                           bitmap.Width, bitmap.Height,
                           bitmap.Width * 4))
                {
                    gtkSurface.MarkDirty();
                    cr.Scale(1 / _dpi.Value, 1 / _dpi.Value);
                    cr.SetSourceSurface(gtkSurface, 0, 0);
                    cr.Paint();
                }
            }

            return(true);
        }
Пример #13
0
        public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
        {
            var impl   = bitmap.PlatformImpl as BitmapImpl;
            var size   = new Size(impl.PixelWidth, impl.PixelHeight);
            var scaleX = destRect.Size.Width / sourceRect.Size.Width;
            var scaleY = destRect.Size.Height / sourceRect.Size.Height;

            _context.Save();
            _context.Scale(scaleX, scaleY);
            _context.SetSourceSurface(impl.Surface, (int)sourceRect.X, (int)sourceRect.Y);
            _context.Rectangle(sourceRect.ToCairo());
            _context.Fill();
            _context.Restore();
        }
Пример #14
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            var rect = Allocation;

            if (rect.Width > 0 && rect.Height > 0)
            {
                var         area  = evnt.Area;
                SKColorType ctype = SKColorType.Bgra8888;
                if (GlobalSettings.Settings.RunningPlatform() == GlobalSettings.Settings.Platform.Mac)
                {
                    ctype = SKColorType.Rgba8888;
                }
                using (Cairo.Context cr = Gdk.CairoHelper.Create(base.GdkWindow))
                {
                    if (cr == null)
                    {
                        Console.WriteLine("Cairo Context is null");
                    }
                    using (var bitmap = new SKBitmap(rect.Width, rect.Height, ctype, SKAlphaType.Premul))
                    {
                        if (bitmap == null)
                        {
                            Console.WriteLine("Bitmap is null");
                        }
                        IntPtr len;
                        using (var skSurface = SKSurface.Create(bitmap.Info.Width, bitmap.Info.Height, ctype, SKAlphaType.Premul, bitmap.GetPixels(out len), bitmap.Info.RowBytes))
                        {
                            if (skSurface == null)
                            {
                                Console.WriteLine("skSurface is null");
                            }
                            if (fsurface != null)
                            {
                                fsurface.UpdateSurface(skSurface);
                            }
                            skSurface.Canvas.Flush();
                            using (Cairo.Surface surface = new Cairo.ImageSurface(bitmap.GetPixels(out len), Cairo.Format.Argb32, bitmap.Width, bitmap.Height, bitmap.Width * 4))
                            {
                                surface.MarkDirty();
                                cr.SetSourceSurface(surface, 0, 0);
                                cr.Paint();
                            }
                        }
                    }
                }
            }

            return(true);
        }
Пример #15
0
        private void UpdateThumbnail()
        {
            double scalex = (double)Allocation.Width / (double)PintaCore.Workspace.ImageSize.Width;
            double scaley = (double)Allocation.Height / (double)PintaCore.Workspace.ImageSize.Height;

            thumbnail = new Cairo.ImageSurface(Cairo.Format.Argb32, Allocation.Width, Allocation.Height);

            using (Cairo.Context g = new Cairo.Context(thumbnail)) {
                g.Scale(scalex, scaley);
                foreach (Layer layer in PintaCore.Layers.GetLayersToPaint())
                {
                    g.SetSourceSurface(layer.Surface, (int)layer.Offset.X, (int)layer.Offset.Y);
                    g.PaintWithAlpha(layer.Opacity);
                }
            }
        }
Пример #16
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);
        }
Пример #17
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            const int width  = 1200;
            const int height = 800;

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

                    using (var paint = new SKPaint())
                    {
                        paint.TextSize = 80;

                        canvas.DrawText("Good Luck Dale!  :-)", new SKPoint()
                        {
                            X = 100, Y = 100
                        }, paint);
                    }

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


                    surface.MarkDirty();
                    cr.SetSourceSurface(surface, 0, 0);
                    cr.Paint();
                }
            }

            return(true);
        }
Пример #18
0
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            if (TextEditor == null)
            {
                return(true);
            }

            using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) {
                var allocation   = Allocation;
                var displayScale = Core.Platform.IsMac ? GtkWorkarounds.GetScaleFactor(this) : 1.0;
                cr.Scale(1 / displayScale, 1 / displayScale);
                if (indicatorSurface != null)
                {
                    cr.SetSourceSurface(indicatorSurface.Surface, 0, 0);
                    cr.Paint();
                }
                else
                {
                    CachedDraw(cr,
                               ref backgroundSurface,
                               allocation,
                               draw: (c, o) => DrawBackground(c, allocation), forceScale: displayScale);
                }
                if (TextEditor == null)
                {
                    return(true);
                }

                DrawCaret(cr);

                if (QuickTaskStrip.MergeScrollBarAndQuickTasks)
                {
                    DrawBar(cr);
                }
            }

            return(true);
        }
Пример #19
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            const int width  = 100;
            const int height = 100;

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

                    using (var paint = new SKPaint())
                    {
                        paint.StrokeWidth = 4;
                        paint.Color       = new SKColor(0x2c, 0x3e, 0x50);

                        var rect = new SKRect(10, 10, 50, 50);
                        canvas.DrawRect(rect, paint);
                    }

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


                    surface.MarkDirty();
                    cr.SetSourceSurface(surface, 0, 0);
                    cr.Paint();
                }
            }

            return(true);
        }
Пример #20
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            int width, height;

            Console.WriteLine($"Render {renderCount++}");

            width  = (int)AllocatedWidth;
            height = (int)AllocatedHeight;

            var info = new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul);

            // reset the bitmap if the size has changed
            if (bitmap == null || info.Width != bitmap.Width || info.Height != bitmap.Height)
            {
                bitmap = new SKBitmap(width, height, SKColorType.Rgba8888, SKAlphaType.Premul);
            }

            using (var surface = SKSurface.Create(info, bitmap.GetPixels(out var len)))
            {
                surface.Canvas.Clear(SKColors.White);

                WUX.Window.Current.Compositor.Render(surface, info);

                using (var gtkSurface = new Cairo.ImageSurface(
                           bitmap.GetPixels(out _),
                           Cairo.Format.Argb32,
                           bitmap.Width, bitmap.Height,
                           bitmap.Width * 4))
                {
                    gtkSurface.MarkDirty();
                    cr.SetSourceSurface(gtkSurface, 0, 0);
                    cr.Paint();
                }
            }

            return(true);
        }
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            if (TextEditor == null)
            {
                return(true);
            }

            using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) {
                var allocation = Allocation;
                if (indicatorSurface != null)
                {
                    cr.SetSourceSurface(indicatorSurface.Surface, 0, 0);
                    cr.Paint();
                }
                else
                {
                    CachedDraw(cr,
                               ref backgroundSurface,
                               allocation,
                               draw: (c, o) => DrawBackground(c, allocation));
                }
                if (TextEditor == null)
                {
                    return(true);
                }

                DrawCaret(cr);

                if (QuickTaskStrip.MergeScrollBarAndQuickTasks)
                {
                    DrawBar(cr);
                }
            }

            return(true);
        }
Пример #22
0
        /// <summary>
        ///  Will throw InvalidAnimationException if initialization failed earlier...
        ///  TODO: does drawing code really belong here?
        /// </summary>
        public void Draw(Cairo.Context cr, int xPos, int yPos)
        {
            if (bitmaps == null)
            {
                throw new InvalidAnimationException();
            }

            int _numSprites = _oamData.GetIntValue(0);

            // Draw sprites in backwards order to respect priority properly
            for (int i = _numSprites - 1; i >= 0; i--)
            {
                Tuple <Bitmap, int, int> tup = bitmaps[i];
                Bitmap bitmap = tup.Item1;
                int    x      = tup.Item2 + xPos;
                int    y      = tup.Item3 + yPos;

                using (Cairo.Surface s = CairoHelper.LockBitmap(bitmap)) {
                    cr.SetSourceSurface(s, x, y);
                    cr.Paint();
                    CairoHelper.UnlockBitmap(bitmap);
                }
            }
        }
Пример #23
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);
            if (!drawGrid)
            {
                return;
            }


            Rectangle    cb            = ClientRectangle;
            const double gridLineWidth = 0.1;
            double       glhw          = gridLineWidth / 2.0;
            int          nbLines       = cb.Width / gridSpacing;
            double       d             = cb.Left + gridSpacing;

            for (int i = 0; i < nbLines; i++)
            {
                gr.MoveTo(d - glhw, cb.Y);
                gr.LineTo(d - glhw, cb.Bottom);
                d += gridSpacing;
            }
            nbLines = cb.Height / gridSpacing;
            d       = cb.Top + gridSpacing;
            for (int i = 0; i < nbLines; i++)
            {
                gr.MoveTo(cb.X, d - glhw);
                gr.LineTo(cb.Right, d - glhw);
                d += gridSpacing;
            }
            gr.LineWidth = gridLineWidth;
            Foreground.SetAsSource(gr, cb);
            gr.Stroke();

            lock (imlVE.RenderMutex) {
                using (Cairo.Surface surf = new Cairo.ImageSurface(imlVE.bmp, Cairo.Format.Argb32,
                                                                   imlVE.ClientRectangle.Width, imlVE.ClientRectangle.Height, imlVE.ClientRectangle.Width * 4)) {
                    gr.SetSourceSurface(surf, cb.Left, cb.Top);
                    gr.Paint();
                }
                imlVE.IsDirty = false;
            }

            Rectangle hr;

            if (imlVE.HoverWidget != null)
            {
                hr = imlVE.HoverWidget.ScreenCoordinates(imlVE.HoverWidget.getSlot());
//			gr.SetSourceColor (Color.LightGray);
//			gr.DrawCote (new Cairo.PointD (hr.X, hr.Center.Y), new Cairo.PointD (hr.Right, hr.Center.Y));
//			gr.DrawCote (new Cairo.PointD (hr.Center.X, hr.Y), new Cairo.PointD (hr.Center.X, hr.Bottom));
                //hr.Inflate (2);
                gr.SetSourceColor(Color.LightGray);
                gr.SetDash(new double[] { 3.0, 3.0 }, 0.0);
                gr.Rectangle(hr, 1.0);
            }

            if (SelectedItem == null)
            {
                return;
            }
            hr = SelectedItem.ScreenCoordinates(SelectedItem.getSlot());
            hr.Inflate(1);
            gr.SetSourceColor(Color.Yellow);
            gr.SetDash(new double[] { 5.0, 3.0 }, 0.0);
            gr.Rectangle(hr, 1.0);
        }
Пример #24
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.Layers.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 ();
			}
		}
Пример #25
0
        void OnExpose(object sender, ExposeEventArgs args)
        {
            DrawingArea area = (DrawingArea)sender;

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

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

            AxisAlignedBox3d bounds3 = Stack.Bounds;
            AxisAlignedBox2d bounds  = (bounds3 == AxisAlignedBox3d.Empty) ?
                                       new AxisAlignedBox2d(0, 0, 500, 500) :
                                       new AxisAlignedBox2d(bounds3.Min.x, bounds3.Min.y, bounds3.Max.x, bounds3.Max.y);

            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;
                    canvas.Clear(SkiaUtil.Color(240, 240, 240, 255));

                    Func <Vector2d, Vector2f> xformF = (pOrig) => {
                        Vector2f pNew = (Vector2f)pOrig;
                        pNew  -= (Vector2f)bounds.Center;
                        pNew   = Zoom * scale * pNew;
                        pNew  += (Vector2f)pixC;
                        pNew  += translate + Zoom * Translate;
                        pNew.y = canvas.LocalClipBounds.Height - pNew.y;
                        return(pNew);
                    };
                    Func <Vector2d, SKPoint> mapToSkiaF = (pOrig) => {
                        Vector2f p = xformF(pOrig);
                        return(new SKPoint(p.x, p.y));
                    };

                    using (var paint = new SKPaint())
                    {
                        SKBitmap sliceImg = get_slice_image(currentLayer);
                        float    w = sliceImg.Width / CurrentDPIMM, h = sliceImg.Height / CurrentDPIMM;
                        w *= Zoom * scale;
                        h *= Zoom * scale;
                        SKPoint sliceCenter = mapToSkiaF(Vector2d.Zero);
                        SKRect  drawRect    = new SKRect(
                            sliceCenter.X - w / 2, sliceCenter.Y - h / 2,
                            sliceCenter.X + w / 2, sliceCenter.Y + h / 2);
                        canvas.DrawBitmap(sliceImg, drawRect, paint);


                        paint.IsAntialias = true;
                        paint.Style       = SKPaintStyle.Stroke;

                        PlanarSlice slice = Stack.Slices[currentLayer];

                        paint.Color       = SkiaUtil.Color(255, 0, 0, 255);;
                        paint.StrokeWidth = 2;
                        foreach (GeneralPolygon2d poly in slice.Solids)
                        {
                            SKPath path = SkiaUtil.ToSKPath(poly, mapToSkiaF);
                            canvas.DrawPath(path, paint);
                        }
                    }

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

                    surface.MarkDirty();
                    cr.SetSourceSurface(surface, 0, 0);
                    cr.Paint();
                }
            }

            //return true;
        }
Пример #26
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

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

            double scale = PintaCore.Workspace.Scale;

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

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

            canvas_bounds.Intersect(e.Area);

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

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

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

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

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

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

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

                g.Translate(x, y);

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

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

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

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

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

                    g.LineWidth = 1 / scale;

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

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

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

            return(true);
        }
Пример #27
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;
        }
Пример #28
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);

            Rectangle cb = new Rectangle(0, 0, designWidth, designHeight);

            gr.Save();

            double z = zoom / 100.0;

            gr.Scale(z, z);

            if (drawGrid)
            {
                double gridLineWidth = 0.2 / z;
                double glhw          = gridLineWidth / 2.0;
                int    nbLines       = cb.Width / gridSpacing;
                double d             = cb.Left + gridSpacing;
                for (int i = 0; i < nbLines; i++)
                {
                    gr.MoveTo(d - glhw, cb.Y);
                    gr.LineTo(d - glhw, cb.Bottom);
                    d += gridSpacing;
                }
                nbLines = cb.Height / gridSpacing;
                d       = cb.Top + gridSpacing;
                for (int i = 0; i < nbLines; i++)
                {
                    gr.MoveTo(cb.X, d - glhw);
                    gr.LineTo(cb.Right, d - glhw);
                    d += gridSpacing;
                }
                gr.LineWidth = gridLineWidth;
                Foreground.SetAsSource(gr, cb);
                gr.Stroke();
            }

            lock (imlVE.RenderMutex) {
                gr.SetSourceSurface(imlVE.surf, cb.Left, cb.Top);
                gr.Paint();
                imlVE.IsDirty = false;
            }

            /*if (Error == null) {
             *      gr.SetSourceColor (Color.Black);
             *      gr.Rectangle (cb, 1.0 / z);
             * } else {
             *      gr.SetSourceColor (Color.LavenderBlush);
             *      gr.Rectangle (cb, 2.0 / z);
             *      string[] lerrs = Error.ToString ().Split ('\n');
             *      Point p = cb.Center;
             *      p.Y -= lerrs.Length * 20;
             *      foreach (string le in lerrs) {
             *              drawCenteredTextLine(gr, p, le);
             *              p.Y += 20;
             *
             *      }
             * }
             * gr.Stroke ();*/

            Rectangle hr;

            if (SelectedItem?.Parent != null)
            {
                gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight);
                gr.SetFontSize(Font.Size);
                gr.FontOptions = Interface.FontRenderingOptions;
                gr.Antialias   = Interface.Antialias;

                Widget g = SelectedItem;
                hr = g.ScreenCoordinates(g.getSlot());

//				Rectangle rIcons = new Rectangle (iconSize);
//				rIcons.Width *= 4;
//				rIcons.Top = hr.Bottom;
//				rIcons.Left = hr.Right - rIcons.Width + iconSize.Width;
                Rectangle rIcoMove = new Rectangle(hr.BottomRight, iconSize);
//				Rectangle rIcoStyle = rIcoMove;
//				rIcoStyle.Left += iconSize.Width + 4;

                using (Surface mask = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) {
                    using (Context ctx = new Context(mask)) {
                        ctx.Save();
                        ctx.SetSourceRGBA(1.0, 1.0, 1.0, 0.4);
                        ctx.Paint();
                        ctx.Rectangle(hr);
                        ctx.Operator = Operator.Clear;
                        ctx.Fill();
                    }

                    gr.SetSourceSurface(mask, 0, 0);
                    gr.Paint();

                    using (Surface ol = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) {
                        using (Context ctx = new Context(ol)) {
                            ctx.SetSourceColor(Colors.Black);
                            drawDesignOverlay(ctx, g, cb, hr, 0.4 / z, 6.5);
                        }

                        gr.SetSourceSurface(ol, 0, 0);
                        gr.Paint();
                    }

                    drawIcon(gr, icoMove, rIcoMove);
                    //drawIcon (gr, icoStyle, rIcoStyle);
                }
            }
            if (HoverWidget != null)
            {
                hr = HoverWidget.ScreenCoordinates(HoverWidget.getSlot());
                gr.SetSourceColor(Colors.SkyBlue);
                //gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0);
                gr.Rectangle(hr, 0.4 / z);
            }
            gr.Restore();
        }
Пример #29
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

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

            double scale = PintaCore.Workspace.Scale;

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

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

            canvas_bounds.Intersect(e.Area);

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

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

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

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

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

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

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

                g.Translate(x, y);

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

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

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

            return(true);
        }
Пример #30
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 ();
		}
Пример #31
0
        private void UpdateThumbnail()
        {
            double scalex = (double)Allocation.Width / (double)PintaCore.Workspace.ImageSize.Width;
            double scaley = (double)Allocation.Height / (double)PintaCore.Workspace.ImageSize.Height;

            thumbnail = new Cairo.ImageSurface (Cairo.Format.Argb32, Allocation.Width, Allocation.Height);

            using (Cairo.Context g = new Cairo.Context (thumbnail)) {
                g.Scale (scalex, scaley);
                foreach (Layer layer in PintaCore.Layers.GetLayersToPaint ()) {
                    g.SetSourceSurface (layer.Surface, (int)layer.Offset.X, (int)layer.Offset.Y);
                    g.PaintWithAlpha (layer.Opacity);
                }
            }
        }
Пример #32
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

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

            double scale = PintaCore.Workspace.Scale;

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

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

            canvas_bounds.Intersect(e.Area);

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

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

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

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

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

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                // Draw our 1 px black border
                g.DrawRectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color(0, 0, 0), 1);

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

                g.Translate(x, y);

                bool checker = true;

                // Resize each layer and paint it to the screen
                foreach (Layer layer in PintaCore.Layers.GetLayersToPaint())
                {
                    cr.Render(layer.Surface, canvas, canvas_bounds.Location, checker);
                    g.SetSourceSurface(canvas, canvas_bounds.X + (int)(layer.Offset.X * scale), canvas_bounds.Y + (int)(layer.Offset.Y * scale));
                    g.PaintWithAlpha(layer.Opacity);

                    if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled)
                    {
                        cr.Render(PintaCore.LivePreview.LivePreviewSurface, canvas, canvas_bounds.Location, checker);

                        g.Save();
                        g.Scale(scale, scale);
                        g.AppendPath(PintaCore.Layers.SelectionPath);
                        g.Clip();

                        g.Scale(1 / scale, 1 / scale);
                        g.SetSourceSurface(canvas, canvas_bounds.X, canvas_bounds.Y);
                        g.PaintWithAlpha(layer.Opacity);

                        g.Restore();
                    }

                    checker = false;
                }

                // If we are at least 200% and grid is requested, draw it
                if (PintaCore.Actions.View.PixelGrid.Active && cr.ScaleFactor.Ratio <= 0.5d)
                {
                    gr.Render(canvas, canvas_bounds.Location);
                    g.SetSourceSurface(canvas, canvas_bounds.X, canvas_bounds.Y);
                    g.Paint();
                }

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

                    g.AppendPath(PintaCore.Layers.SelectionPath);

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

                    g.LineWidth = 1 / scale;

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

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

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

            return(true);
        }
Пример #33
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 ();
			}
		}
Пример #34
0
 protected override bool OnDrawn(Cairo.Context ctx)
 {
     ctx.SetSourceSurface(surface, 0, 0);
     ctx.Paint();
     return(false);
 }