Esempio n. 1
0
        public override void DrawEllipse(Brush brush, Pen pen, Point center, double radiusX, double radiusY)
        {
            cr.Save();

            cr.Translate(center.X, center.Y);
            cr.Scale(1, radiusY / radiusX);

            if (brush != null)
            {
                if (brush is SolidColorBrush)
                {
                    var b = brush as SolidColorBrush;
                    cr.Color = new Cairo.Color(b.Color.R, b.Color.G, b.Color.B, b.Color.Alfa);
                    cr.Arc(0, 0, radiusX, 0, 2 * Math.PI);

                    cr.Fill();
                }
            }

            if (pen != null)
            {
                cr.Color     = new Cairo.Color(pen.Color.R, pen.Color.G, pen.Color.B, pen.Color.Alfa);
                cr.LineWidth = pen.Thickness;
                cr.Arc(0, 0, radiusX - pen.Thickness / 2, 0, 2 * Math.PI);

                cr.Stroke();
            }

            cr.Restore();
        }
        public bool Show(Cairo.Context context)
        {
            UpdateScale();
            if (surface == null || surface.Width != TargetWidth || surface.Height != TargetHeight)
            {
                return(false);
            }

            runningSignal.Wait();
            context.Scale(1 / Scale, 1 / Scale);
            surface.Surface.Show(context, owner.Allocation.X * Scale, owner.Allocation.Y * Scale);
            context.Scale(Scale, Scale);
            return(true);
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
        }
            public void Start()
            {
                allocation = mode.Allocation;
                var swapSurface = mode.swapIndicatorSurface;

                if (swapSurface != null)
                {
                    if (swapSurface.Width == allocation.Width && swapSurface.Height == allocation.Height)
                    {
                        surface = swapSurface;
                    }
                    else
                    {
                        mode.DestroyIndicatorSwapSurface();
                    }
                }

                var displayScale = Core.Platform.IsMac ? GtkWorkarounds.GetScaleFactor(mode) : 1.0;

                if (surface == null)
                {
                    using (var similiar = CairoHelper.Create(IdeApp.Workbench.RootWindow.GdkWindow))
                        surface = new SurfaceWrapper(similiar, (int)(allocation.Width * displayScale), (int)(allocation.Height * displayScale));
                }

                searchResults = mode.TextEditor.TextViewMargin.SearchResults.ToList().GetEnumerator();
                allUsages     = mode.AllUsages.GetEnumerator();
                allTasks      = mode.AllTasks.GetEnumerator();
                cr            = new Cairo.Context(surface.Surface);
                cr.Scale(displayScale, displayScale);
                GLib.Idle.Add(RunHandler);
            }
Esempio n. 6
0
        public virtual void DrawAnnotation(Cairo.Context context, Cdn.AnnotationInfo info)
        {
            var uw    = context.LineWidth;
            var alloc = AnnotationAllocation(1 / uw, context);

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

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

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

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

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

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

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

            context.Restore();
        }
Esempio n. 7
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();
        }
 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);
 }
Esempio n. 9
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();
                }
            }
        }
Esempio n. 10
0
 public RenderCairo(Cairo.Context g, float scale)
 {
     this.g      = g;
     this.layout = Pango.CairoHelper.CreateLayout(g);
     this.scale  = scale;
     g.Scale(scale, scale);
 }
            public void Start()
            {
                allocation = mode.Allocation;
                var swapSurface = mode.swapIndicatorSurface;

                if (swapSurface != null)
                {
                    if (swapSurface.Width == allocation.Width && swapSurface.Height == allocation.Height)
                    {
                        surface = swapSurface;
                    }
                    else
                    {
                        mode.DestroyIndicatorSwapSurface();
                    }
                }

                var displayScale = Core.Platform.IsMac ? GtkWorkarounds.GetScaleFactor(mode) : 1.0;

                if (surface == null)
                {
                    using (var similiar = CairoHelper.Create(IdeApp.Workbench.RootWindow.GdkWindow))
                        surface = new SurfaceWrapper(similiar, (int)(allocation.Width * displayScale), (int)(allocation.Height * displayScale));
                }
                state        = IndicatorDrawingState.Create();
                state.Width  = allocation.Width;
                state.Height = allocation.Height;
                state.SearchResults.AddRange(mode.TextEditor.TextViewMargin.SearchResults);
                state.Usages.AddRange(mode.AllUsages);
                state.Tasks.AddRange(mode.AllTasks);
                state.ColorCache [IndicatorDrawingState.UsageColor]       = SyntaxHighlightingService.GetColor(mode.TextEditor.EditorTheme, EditorThemeColors.Foreground);
                state.ColorCache [IndicatorDrawingState.UsageColor].Alpha = 0.4;

                state.ColorCache [IndicatorDrawingState.FocusColor] = Styles.FocusColor.ToCairoColor();

                state.ColorCache [IndicatorDrawingState.ChangingUsagesColor] = SyntaxHighlightingService.GetColor(mode.TextEditor.EditorTheme, EditorThemeColors.ChangingUsagesRectangle);
                if (state.ColorCache [IndicatorDrawingState.ChangingUsagesColor].Alpha == 0.0)
                {
                    state.ColorCache [IndicatorDrawingState.ChangingUsagesColor] = SyntaxHighlightingService.GetColor(mode.TextEditor.EditorTheme, EditorThemeColors.UsagesRectangle);
                }

                state.ColorCache [IndicatorDrawingState.UsagesRectangleColor] = SyntaxHighlightingService.GetColor(mode.TextEditor.EditorTheme, EditorThemeColors.UsagesRectangle);
                for (int i = 0; i < 4; i++)
                {
                    state.ColorCache [i].L = 0.4;
                }

                state.ColorCache [IndicatorDrawingState.UnderlineErrorColor]      = SyntaxHighlightingService.GetColor(mode.TextEditor.EditorTheme, EditorThemeColors.UnderlineError);
                state.ColorCache [IndicatorDrawingState.UnderlineWarningColor]    = SyntaxHighlightingService.GetColor(mode.TextEditor.EditorTheme, EditorThemeColors.UnderlineWarning);
                state.ColorCache [IndicatorDrawingState.UnderlineSuggestionColor] = SyntaxHighlightingService.GetColor(mode.TextEditor.EditorTheme, EditorThemeColors.UnderlineSuggestion);
                state.ColorCache [IndicatorDrawingState.BackgroundColor]          = SyntaxHighlightingService.GetColor(mode.TextEditor.EditorTheme, EditorThemeColors.Background);

                ResetEnumerators();

                cr = new Cairo.Context(surface.Surface);
                cr.Scale(displayScale, displayScale);
                GLib.Idle.Add(RunHandler);
            }
Esempio n. 12
0
        internal static void DrawEllipse(Cairo.Context context, Ellipse el, double startAngle = 0, double endAngle = Math.PI * 2)
        {
            var radius = Math.Max(el.AxisA.Length, el.AxisB.Length);
            var scaleX = el.AxisA.Length / radius;
            var scaleY = el.AxisB.Length / radius;

            context.Save();
            context.Scale(scaleX, scaleY);
            context.Arc(el.Center.X, el.Center.Y, radius, startAngle, endAngle);
            context.Stroke();
            context.Restore();
        }
Esempio n. 13
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            base.DrawBackground(cr);

            cr.Save();

            cr.Translate(XOffset, YOffset);
            cr.Scale(Scale, Scale);

            hoveringComponent = null;

            foreach (RoomComponent com in roomComponents)
            {
                cr.SetSourceColor(com.BoxColor);
                cr.Rectangle(com.BoxRectangle);
                cr.Fill();
                com.Draw(cr);

                if (DrawRoomComponentHover)
                {
                    if (CairoHelper.PointInRect(mouseX, mouseY, com.BoxRectangle))
                    {
                        hoveringComponent = com;
                    }
                }
            }

            if (SelectRoomComponents)
            {
                // Object hovering over
                if (hoveringComponent != null)
                {
                    cr.SetSourceColor(ObjectHoverColor);
                    CairoHelper.DrawRectOutline(cr, 1, hoveringComponent.BoxRectangle);
                }
                // Object selected
                if (selectedComponent != null)
                {
                    cr.SetSourceColor(TileGridViewer.DefaultSelectionColor);
                    CairoHelper.DrawRectOutline(cr, 1, selectedComponent.BoxRectangle);
                }
            }

            cr.Restore();

            if (DrawTileHover)
            {
                base.DrawHoverAndSelection(cr);
            }

            return(true);
        }
Esempio n. 14
0
        public static void FillEllipse(this Cairo.Context dc, double x, double y, double width, double height)
        {
            dc.Save();
            dc.Translate(x + width / 2, y + height / 2);
            dc.Scale(width / 2, height / 2);
            dc.Arc(0, 0, 1, 0, 2 * Math.PI);

            //dc.fill.SetupFill();
            //dc.fill_preserve()
            //dc.SetupStroke()
            dc.Fill();
            dc.Restore();
        }
Esempio n. 15
0
        public override void Draw(Cairo.Context context)
        {
            Cairo.Matrix oldMatrix = context.Matrix;
            double       a         = MinorAxis / _majorAxis;

            context.Translate(0.0, _position.Y * (1 - a));
            context.Scale(1.0, a);
            context.MoveTo(_position.X + _majorAxis, _position.Y);
            context.Arc(_position.X, _position.Y, _majorAxis, 0.0, 2 * Math.PI);
            context.ClosePath();
            //todo change in order to process rotated ellipses (i.e. MajorAxis is collinear with OY)
            context.Matrix = oldMatrix;
        }
Esempio n. 16
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);
        }
Esempio n. 17
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();
        }
Esempio n. 18
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 ()) {
					layer.Draw(g);
				}
			}
		}
Esempio n. 19
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())
                {
                    layer.Draw(g);
                }
            }
        }
        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.Color    = new Cairo.Color(0, 0, 0, 0);
                context.Paint();
                context.Operator = Cairo.Operator.Over;

                context.Scale(Scale, Scale);
                callback(context);
            }
            runningSignal.Set();
        }
Esempio n. 21
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);
                }
            }
        }
Esempio n. 22
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);
     if (idesc.Alpha == 1)
     {
         ctx.Paint();
     }
     else
     {
         ctx.PaintWithAlpha(idesc.Alpha);
     }
     ctx.Restore();
 }
Esempio n. 23
0
        public Gdk.Pixbuf Icon(int size)
        {
            Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.Argb32, size, size);
            Gdk.Pixbuf         ret;

            Style         = DrawStyle.Icon;
            Cache.Enabled = false;

            using (Cairo.Context ct = new Cairo.Context(surface))
            {
                ct.Rectangle(0, 0, size, size);
                ct.Clip();

                ct.Translate(0, 0);
                ct.Scale(size, size);

                ct.LineWidth = 1.0 / size;

                Draw(ct);

                byte[] data = ConvertColorSpace(surface.Data);

                try
                {
                    ret = new Gdk.Pixbuf(data, Gdk.Colorspace.Rgb, true, 8, size, size, surface.Stride);
                }
                catch
                {
                    // Some stupid bug in older mono, fallback strategy
                    string filename = System.IO.Path.GetTempFileName();

                    if (System.IO.File.Exists(filename))
                    {
                        System.IO.File.Delete(filename);
                    }

                    surface.WriteToPng(filename);
                    ret = new Gdk.Pixbuf(filename);
                    System.IO.File.Delete(filename);
                }
            }

            Cache.Enabled = true;
            Style         = DrawStyle.Normal;

            return(ret);
        }
Esempio n. 24
0
        Gdk.Pixbuf RenderFrame(ApplicationContext actx, double scaleFactor, ImageDescription idesc)
        {
            var swidth  = Math.Max((int)(idesc.Size.Width * scaleFactor), 1);
            var sheight = Math.Max((int)(idesc.Size.Height * scaleFactor), 1);

            using (var sf = new Cairo.ImageSurface(Cairo.Format.ARGB32, swidth, sheight))
                using (var ctx = new Cairo.Context(sf)) {
                    ctx.Scale(scaleFactor, scaleFactor);
                    Draw(actx, ctx, scaleFactor, 0, 0, idesc);
                    var f = new ImageFrame(ImageBuilderBackend.CreatePixbuf(sf), Math.Max((int)idesc.Size.Width, 1), Math.Max((int)idesc.Size.Height, 1), true);
                    if (drawCallback == null)
                    {
                        AddFrame(f);
                    }
                    return(f.Pixbuf);
                }
        }
Esempio n. 25
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            base.OnExposeEvent(evnt);

            Cairo.Context context = Gdk.CairoHelper.Create(GdkWindow);
            context.Save();
            context.Translate(transformX, transformY);
            context.Scale(scale, scale);

            if (shape != null)
            {
                shape.Draw(context, scale);
            }

            ((IDisposable)context).Dispose();

            return(true);
        }
        /// 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)) {
                    context.Operator = Cairo.Operator.Clear;
                    context.Paint();
                    context.Operator = Cairo.Operator.Over;
                    context.Save();
                    context.Scale(displayScale, displayScale);
                    draw(context, 1.0f);
                    context.Restore();
                }
            }

            self.Save();
            self.Translate(region.X, region.Y);
            self.Scale(1 / displayScale, 1 / displayScale);
            self.SetSourceSurface(surface.Surface, 0, 0);
            self.PaintWithAlpha(opacity);
            self.Restore();
        }
Esempio n. 27
0
        protected void placeShapes()
        {
            if (_surface != null)
            {
                drawingArea.GdkWindow.Clear();
                _surface.Dispose();
                _surface = null;
            }

            _min = Vertex.CreateMax();
            _max = Vertex.CreateMin();

            foreach (AbstractShape shape in _shapes)
            {
                _min.Minimize(shape.Min);
                _max.Maximize(shape.Max);
                log("фигура {0} расположена на позиции от {1} до {2}", shape, shape.Min.Literal, shape.Max.Literal);
            }

            _min            -= _lineWidthGap;
            _max            += _lineWidthGap;
            _logicCanvasSize = _max - _min;
            log("размер логического холста (с учётом толщины линий) - {0}", _logicCanvasSize.Literal);
            _logicCanvasSize *= _prescale;
            _surface          = new Cairo.ImageSurface(Cairo.Format.Argb32, ( int )_logicCanvasSize.X, ( int )_logicCanvasSize.Y);

            using (var surfaceContext = new Cairo.Context(_surface)) {
                surfaceContext.SetSourceRGB(1.0, 1.0, 1.0);
                surfaceContext.Paint();
                surfaceContext.LineWidth = 1.0;
                surfaceContext.SetSourceRGB(.0, .0, .0);
                surfaceContext.Scale(_prescale, -_prescale);
                surfaceContext.Translate(-_min.X, -_max.Y);

                if (null != _shapes && 0 < _shapes.Count)
                {
                    foreach (AbstractShape shape in _shapes)
                    {
                        shape.Draw(surfaceContext);
                        surfaceContext.Stroke();
                    }
                }
            }
        }
Esempio n. 28
0
        Gdk.Pixbuf RenderFrame(ApplicationContext actx, double scaleFactor, double width, double height)
        {
            var swidth  = Math.Max((int)(width * scaleFactor), 1);
            var sheight = Math.Max((int)(height * scaleFactor), 1);

            using (var sf = new Cairo.ImageSurface(Cairo.Format.ARGB32, swidth, sheight))
                using (var ctx = new Cairo.Context(sf)) {
                    ImageDescription idesc = new ImageDescription()
                    {
                        Alpha = 1,
                        Size  = new Size(width, height)
                    };
                    ctx.Scale(scaleFactor, scaleFactor);
                    Draw(actx, ctx, scaleFactor, 0, 0, idesc);
                    var f = new ImageFrame(ImageBuilderBackend.CreatePixbuf(sf), Math.Max((int)width, 1), Math.Max((int)height, 1), true);
                    AddFrame(f);
                    return(f.Pixbuf);
                }
        }
Esempio n. 29
0
        // Overridable function which generates the image for a tile on the map.
        // Child classes could choose override "TileDrawer" instead. The advantage of overriding
        // this function is that the image will be cached.
        protected virtual Cairo.Surface GenerateTileImage(int x, int y)
        {
            RoomLayout layout      = GetRoomLayout(x, y);
            var        tileSurface = this.Window.CreateSimilarSurface(Cairo.Content.Color,
                                                                      (int)(layout.Width * 16 * _scale), (int)(layout.Height * 16 * _scale));

            // The below line works fine, but doesn't look as good on hidpi monitors
            //_surface = new Cairo.ImageSurface(Cairo.Format.Rgb24,
            //        (int)(layout.Width * 16 * _scale), (int)(layout.Height * 16 * _scale));

            Bitmap img = layout.GetImage();

            using (var cr = new Cairo.Context(tileSurface))
                using (var source = new BitmapSurface(img)) {
                    cr.Scale(_scale, _scale);
                    cr.SetSource(source, 0, 0);
                    cr.Paint();
                }

            return(tileSurface);
        }
Esempio n. 30
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();
            }
        }
Esempio n. 31
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(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
        {
            var impl  = bitmap.PlatformImpl as BitmapImpl;
            var size  = new Size(impl.PixelWidth, impl.PixelHeight);
            var scale = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height);

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

            if (opacityOverride < 1.0f)
            {
                _context.PushGroup();
                Gdk.CairoHelper.SetSourcePixbuf(
                    _context,
                    impl.Surface,
                    -sourceRect.X + destRect.X,
                    -sourceRect.Y + destRect.Y);

                _context.Rectangle(destRect.ToCairo());
                _context.Fill();
                _context.PopGroupToSource();
                _context.PaintWithAlpha(opacityOverride);
            }
            else
            {
                _context.PushGroup();
                Gdk.CairoHelper.SetSourcePixbuf(
                    _context,
                    impl.Surface,
                    -sourceRect.X + destRect.X,
                    -sourceRect.Y + destRect.Y);

                _context.Rectangle(destRect.ToCairo());
                _context.Fill();
                _context.PopGroupToSource();
                _context.PaintWithAlpha(opacityOverride);
            }
            _context.Restore();
        }
Esempio n. 32
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;
 }
Esempio n. 33
0
		Gdk.Pixbuf RenderFrame (ApplicationContext actx, double scaleFactor, double width, double height)
		{
			var swidth = Math.Max ((int)(width * scaleFactor), 1);
			var sheight = Math.Max ((int)(height * scaleFactor), 1);

			using (var sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, swidth, sheight))
			using (var ctx = new Cairo.Context (sf)) {
				ImageDescription idesc = new ImageDescription () {
					Alpha = 1,
					Size = new Size (width, height)
				};
				ctx.Scale (scaleFactor, scaleFactor);
				Draw (actx, ctx, scaleFactor, 0, 0, idesc);
				var f = new ImageFrame (ImageBuilderBackend.CreatePixbuf (sf), Math.Max((int)width,1), Math.Max((int)height,1), true);
				AddFrame (f);
				return f.Pixbuf;
			}
		}
Esempio n. 34
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);
                }
            }
        }
Esempio n. 35
0
        Gdk.Pixbuf RenderFrame(ApplicationContext actx, double scaleFactor, ImageDescription idesc)
        {
            var swidth = Math.Max ((int)(idesc.Size.Width * scaleFactor), 1);
            var sheight = Math.Max ((int)(idesc.Size.Height * scaleFactor), 1);

            using (var sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, swidth, sheight))
            using (var ctx = new Cairo.Context (sf)) {
                ctx.Scale (scaleFactor, scaleFactor);
                Draw (actx, ctx, scaleFactor, 0, 0, idesc);
                var f = new ImageFrame (ImageBuilderBackend.CreatePixbuf (sf), Math.Max ((int)idesc.Size.Width, 1), Math.Max ((int)idesc.Size.Height, 1), true);
                if (drawCallback == null)
                    AddFrame (f);
                return f.Pixbuf;
            }
        }
Esempio n. 36
0
				public BgBufferUpdate (Minimpap mode)
				{
					this.mode = mode;
					
					cr = Gdk.CairoHelper.Create (mode.backgroundBuffer);
					
					cr.LineWidth = 1;
					int w = mode.backgroundBuffer.ClipRegion.Clipbox.Width;
					int h = mode.backgroundBuffer.ClipRegion.Clipbox.Height;
					cr.Rectangle (0, 0, w, h);
					if (mode.TextEditor.ColorStyle != null)
						cr.Color = mode.TextEditor.ColorStyle.Default.CairoBackgroundColor;
					cr.Fill ();
					
					maxLine = mode.TextEditor.GetTextEditorData ().VisibleLineCount;
					sx = w / (double)mode.TextEditor.Allocation.Width;
					sy = Math.Min (1, lineHeight * maxLine / (double)mode.TextEditor.GetTextEditorData ().TotalHeight );
					cr.Scale (sx, sy);
					
					handler = GLib.Idle.Add (BgBufferUpdater);
				}
Esempio n. 37
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 ();
		}