Paint() публичный Метод

public Paint ( ) : void
Результат void
		protected override void DrawBackground (Context context, Gdk.Rectangle region)
		{
			LayoutRoundedRectangle (context, region);
			context.Clip ();

			context.SetSourceColor (CairoExtensions.ParseColor ("D3E6FF"));
			context.Paint ();

			context.Save ();
			context.Translate (region.X + region.Width / 2.0, region.Y + region.Height);

			using (var rg = new RadialGradient (0, 0, 0, 0, 0, region.Height * 1.2)) {
				var color = CairoExtensions.ParseColor ("E5F0FF");
				rg.AddColorStop (0, color);
				color.A = 0;
				rg.AddColorStop (1, color);

				context.Scale (region.Width / (double)region.Height, 1.0);
				context.SetSource (rg);
				context.Paint ();
			}

			context.Restore ();

			LayoutRoundedRectangle (context, region, -3, -3, 2);
			context.SetSourceRGBA (1, 1, 1, 0.4);
			context.LineWidth = 1;
			context.StrokePreserve ();

			context.Clip ();

			int boxSize = 11;
			int x = region.Left + (region.Width % boxSize) / 2;
			for (; x < region.Right; x += boxSize) {
				context.MoveTo (x + 0.5, region.Top);
				context.LineTo (x + 0.5, region.Bottom);
			}

			int y = region.Top + (region.Height % boxSize) / 2;
			y += boxSize / 2;
			for (; y < region.Bottom; y += boxSize) {
				context.MoveTo (region.Left, y + 0.5);
				context.LineTo (region.Right, y + 0.5);
			}

			context.SetSourceRGBA (1, 1, 1, 0.2);
			context.Stroke ();

			context.ResetClip ();
		}
Пример #2
0
    void Draw(Context cr, int width, int height)
    {
        double radius = 0.5 * Math.Min (width, height) - 10;
        int xc = width / 2;
        int yc = height / 2;

        Surface overlay = cr.Target.CreateSimilar (Content.ColorAlpha, width, height);
        Surface punch   = cr.Target.CreateSimilar (Content.Alpha, width, height);
        Surface circles = cr.Target.CreateSimilar (Content.ColorAlpha, width, height);

        FillChecks (cr, 0, 0, width, height);
        cr.Save ();

        // Draw a black circle on the overlay
        using (Context cr_overlay = new Context (overlay)) {
            cr_overlay.Color = new Color (0.0, 0.0, 0.0);
            OvalPath (cr_overlay, xc, yc, radius, radius);
            cr_overlay.Fill ();

            // Draw 3 circles to the punch surface, then cut
            // that out of the main circle in the overlay
            using (Context cr_tmp = new Context (punch))
                Draw3Circles (cr_tmp, xc, yc, radius, 1.0);

            cr_overlay.Operator = Operator.DestOut;
            cr_overlay.SetSourceSurface (punch, 0, 0);
            cr_overlay.Paint ();

            // Now draw the 3 circles in a subgroup again
            // at half intensity, and use OperatorAdd to join up
            // without seams.
            using (Context cr_circles = new Context (circles)) {
                cr_circles.Operator = Operator.Over;
                Draw3Circles (cr_circles, xc, yc, radius, 0.5);
            }

            cr_overlay.Operator = Operator.Add;
            cr_overlay.SetSourceSurface (circles, 0, 0);
            cr_overlay.Paint ();
        }

        cr.SetSourceSurface (overlay, 0, 0);
        cr.Paint ();

        overlay.Destroy ();
        punch.Destroy ();
        circles.Destroy ();
    }
Пример #3
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            Debug.WriteLine("Form1_Shown");

            Win32Surface = new Win32Surface(this.CreateGraphics().GetHdc());
            FontContext = new Context(Win32Surface);

            //CRITICAL: Format of Win32Surface and ImageSurface must be identical!

            ImageSurface = new ImageSurface(Format.Rgb24, ClientSize.Width, ClientSize.Height);
            BackContext = new Context(ImageSurface);

            //Clear Surface2
            BackContext.SetSourceColor(new Color(1,1,1));
            BackContext.Operator = Operator.Source;
            BackContext.Paint();
            BackContext.Operator = Operator.Over;

            var textFormat = DWriteCairo.CreateTextFormat(
                "Arial",
                FontWeight.Normal,
                FontStyle.Normal,
                FontStretch.Normal,
                32f);
            
            Debug.Assert(Math.Abs(textFormat.FontSize - 32f) < 0.0001);
            
            const string s = "Hello World";
            textLayout = DWriteCairo.CreateTextLayout(s, textFormat, 300, 40);

        }
Пример #4
0
		public bool Convert (FilterRequest req)
		{
			string source = req.Current.LocalPath;
			Uri dest = req.TempUri (Path.GetExtension (source));
			
			using (ImageFile img = ImageFile.Create (source)) {
				using (Pixbuf pixbuf = img.Load ()) {
					using (ImageInfo info = new ImageInfo (pixbuf)) {
						MemorySurface surface = new MemorySurface (Format.Argb32, 
											   pixbuf.Width,
											   pixbuf.Height);
	
						Context ctx = new Context (surface);
						ctx.Matrix = info.Fill (info.Bounds, angle);
						Pattern p = new SurfacePattern (info.Surface);
						ctx.Source = p;
						ctx.Paint ();
						((IDisposable)ctx).Dispose ();
						p.Destroy ();
						using (Pixbuf result = CairoUtils.CreatePixbuf (surface)) {
							using (Stream output = File.OpenWrite (dest.LocalPath)) {
								img.Save (result, output);
							}
						}
						surface.Flush ();
						info.Dispose ();
						req.Current = dest;
						return true;
					}
				}
			}
		}
Пример #5
0
        protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress)
        {
            cr.Color = new Color (0, 0, 0);
            if (next != null) {
                double scale = Math.Min ((double)width/(double)next.Width, (double)height/(double)next.Height);
                cr.Save ();

                cr.Translate (width * (1.0 - progress), 0);

                cr.Rectangle (0, 0, width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, height - .5 * (height - scale*next.Height), width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (width - .5 * (width - scale*next.Width), 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (0, 0, width, height);
                cr.Scale (scale, scale);
                CairoHelper.SetSourcePixbuf (cr, next, .5 * ((double)width/scale - next.Width), .5 * ((double)height/scale - next.Height));
                cr.Paint ();
                cr.Restore ();
            }
        }
Пример #6
0
 public static void Clear(this ImageSurface surface)
 {
     using (Context g = new Context (surface)) {
         g.Operator = Operator.Clear;
         g.Paint ();
     }
 }
Пример #7
0
        public static ImageSurface Create (Gdk.Pixbuf pixbuf, bool disposePixbuf)
        {
            if (pixbuf == null || pixbuf.Handle == IntPtr.Zero) {
                return null;
            }

            if (!PlatformDetection.IsWindows) {
                try {
                    return new PixbufImageSurface (pixbuf, disposePixbuf);
                } catch {
                    return null;
                }
            } else {
                // FIXME:
                // Windows has some trouble running the PixbufImageSurface, so as a
                // workaround a slower but working version of this factory method is
                // implemented. One day we can come back and optimize this by finding
                // out what's causing the PixbufImageSurface to result in access
                // violations when the object is disposed.
                ImageSurface target = new ImageSurface (Format.ARGB32, pixbuf.Width, pixbuf.Height);
                Context context = new Context (target);
                try {
                    Gdk.CairoHelper.SetSourcePixbuf (context, pixbuf, 0, 0);
                    context.Paint ();
                } finally {
                    ((IDisposable)context).Dispose ();
                    if (disposePixbuf) {
                        ((IDisposable)pixbuf).Dispose ();
                    }
                }

                return target;
            }
        }
Пример #8
0
		public ImageInfo (ImageInfo info, Gdk.Rectangle allocation)
		{
			#if false
			Surface = new ImageSurface (Format.RGB24,
						    allocation.Width,
						    allocation.Height);
			Context ctx = new Context (Surface);
			#else
			Console.WriteLine ("source status = {0}", info.Surface.Status);
			Surface = info.Surface.CreateSimilar (Content.Color,
							      allocation.Width,
							      allocation.Height);
			
			System.Console.WriteLine ("status = {1} pointer = {0}", Surface.Handle.ToString (), Surface.Status);
			Context ctx = new Context (Surface);
			#endif
			Bounds = allocation;
			
			ctx.Matrix = info.Fill (allocation);
			Pattern p = new SurfacePattern (info.Surface);
			ctx.Source = p;
			ctx.Paint ();
			((IDisposable)ctx).Dispose ();
			p.Destroy ();
		}
Пример #9
0
        /*public static Pango.Layout CreateCairoLayout (Gtk.Widget widget, Cairo.Context cairo_context)
        {
            var layout = PangoCairoHelper.CreateLayout (cairo_context);
            layout.FontDescription = widget.PangoContext.FontDescription;

            double resolution = widget.Screen.Resolution;
            if (resolution != -1) {
                using (var context = PangoCairoHelper.LayoutGetContext (layout)) {
                    PangoCairoHelper.ContextSetResolution (context, resolution);
                }
            }

            return layout;
        }*/
        public static Surface CreateSurfaceForPixbuf(this Cairo.Context cr, Gdk.Pixbuf pixbuf)
        {
            var surface = cr.Target.CreateSimilar (cr.Target.Content, pixbuf.Width, pixbuf.Height);
            using (var surface_cr = new Context (surface)) {
                Gdk.CairoHelper.SetSourcePixbuf (surface_cr, pixbuf, 0, 0);
                surface_cr.Paint ();
                return surface;
            }
        }
Пример #10
0
 public static Surface CreateSurfaceForPixbuf (Cairo.Context cr, Gdk.Pixbuf pixbuf)
 {
     Surface surface = cr.Target.CreateSimilar (cr.Target.Content, pixbuf.Width, pixbuf.Height);
     Cairo.Context surface_cr = new Context (surface);
     Gdk.CairoHelper.SetSourcePixbuf (surface_cr, pixbuf, 0, 0);
     surface_cr.Paint ();
     ((IDisposable)surface_cr).Dispose ();
     return surface;
 }
Пример #11
0
        public static Gtk.Image create_big_starred_image(string pic_path)
        {
            using (Cairo.ImageSurface img_surface = new ImageSurface(pic_path)) {
                using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, img_surface.Width + 2, img_surface.Height + 2)) {
                    using (Cairo.Context context = new Context(surface)) {
                        Gdk.Pixbuf tmp_pixbuf = new Gdk.Pixbuf(pic_path);
                        if (!tmp_pixbuf.HasAlpha) { // img_surface.Format not available...
                            context.Rectangle(0, 0, img_surface.Width+2, img_surface.Height+2);
                            context.Fill();
                            context.Stroke();
                        }

                        context.SetSource(img_surface, 1, 1);
                        context.Paint();

                        // evil hack because the interface to cairo is pretty bad

                        Assembly asm = Assembly.GetCallingAssembly();

                        Stream s = asm.GetManifestResourceStream("big_star.png");

                        FileStream fs = new System.IO.FileStream(tmp_image_path, FileMode.Create);

                        for (int i = 0; i < s.Length; ++i)
                            fs.WriteByte((byte)s.ReadByte());

                        fs.Close();

                        using (Cairo.ImageSurface star_surface = new ImageSurface(tmp_image_path)) {
                            System.IO.File.Delete(tmp_image_path);

                            context.SetSource(star_surface, img_surface.Width-star_surface.Width, img_surface.Height-star_surface.Height);
                            context.Paint();

                            surface.WriteToPng(tmp_image_path);
                            Gtk.Image img = new Gtk.Image(tmp_image_path);
                            System.IO.File.Delete(tmp_image_path);
                            return img;
                        }
                    }
                }
            }
        }
Пример #12
0
        public PlacedSurface(ImageSurface source, Gdk.Rectangle roi)
        {
            where = roi.Location;
            what = new ImageSurface (Format.Argb32, roi.Width, roi.Height);

            using (Context g = new Context (what)) {
                g.SetSourceSurface (source, -roi.X, -roi.Y);
                g.Paint ();
            }
        }
Пример #13
0
 public Surface(int width, int height, Image image, bool warnOnDispose = true)
 {
     this.warnOnDispose = warnOnDispose;
     surface = new ImageSurface (Format.ARGB32, width, height);
     if (image != null) {
         using (Context context = new Context (surface)) {
             Gdk.CairoHelper.SetSourcePixbuf (context, image.Value, 0, 0);
             context.Paint ();
         }
     }
 }
Пример #14
0
        public static ImageSurface Clone(this ImageSurface surf)
        {
            ImageSurface newsurf = new ImageSurface (surf.Format, surf.Width, surf.Height);

            using (Context g = new Context (newsurf)) {
                g.SetSource (surf);
                g.Paint ();
            }

            return newsurf;
        }
Пример #15
0
        public static Surface CreateSurfaceForPixbuf (Context cr, Pixbuf pixbuf)
        {
			Surface surface;
			using (var t = cr.GetTarget ()) {
				surface = t.CreateSimilar (t.Content, pixbuf.Width, pixbuf.Height);
			}
			using (Context surface_cr = new Context (surface)) {
				CairoHelper.SetSourcePixbuf (surface_cr, pixbuf, 0, 0);
				surface_cr.Paint ();
				surface_cr.Dispose ();
			}
            return surface;
        }
Пример #16
0
        public ImageInfo(ImageInfo info, Widget w, Gdk.Rectangle bounds)
        {
            Cairo.Surface similar = CairoUtils.CreateSurface (w.GdkWindow);
            Bounds = bounds;
            Surface = similar.CreateSimilar (Content.ColorAlpha, Bounds.Width, Bounds.Height);
            Context ctx = new Context (Surface);

            ctx.Matrix = info.Fill (Bounds);
            Pattern p = new SurfacePattern (info.Surface);
            ctx.Source = p;
            ctx.Paint ();
            ((IDisposable)ctx).Dispose ();
            p.Destroy ();
        }
		public static Cairo.ImageSurface PixbufToImageSurface (Gdk.Pixbuf pixbuf) {
			Cairo.Format format = Cairo.Format.RGB24;
			if (pixbuf.HasAlpha) {
				format = Cairo.Format.ARGB32;
			}
			
			Cairo.ImageSurface surface = new ImageSurface (format, pixbuf.Width, pixbuf.Height);
			using (Cairo.Context context = new Cairo.Context (surface)) {
				Gdk.CairoHelper.SetSourcePixbuf (context, pixbuf, 0.0, 0.0);
				context.Paint ();
			}
			
			return surface;
		}
Пример #18
0
		public bool OnExpose (Context ctx, Gdk.Rectangle allocation)
		{
			if (frames == 0)
				start = DateTime.UtcNow;
			
			frames ++;
			TimeSpan elapsed = DateTime.UtcNow - start;
			double fraction = elapsed.Ticks / (double) duration.Ticks; 
			double opacity = Math.Sin (Math.Min (fraction, 1.0) * Math.PI * 0.5);
			
			ctx.Operator = Operator.Source;
			
			SurfacePattern p = new SurfacePattern (begin_buffer.Surface);
			ctx.Matrix = begin_buffer.Fill (allocation);
			p.Filter = Filter.Fast;
			ctx.Source = p;
			ctx.Paint ();
			
			ctx.Operator = Operator.Over;
			ctx.Matrix = end_buffer.Fill (allocation);
			SurfacePattern sur = new SurfacePattern (end_buffer.Surface);
#if MONO_1_2_5
			Pattern black = new SolidPattern (new Cairo.Color (0.0, 0.0, 0.0, opacity));
#else
			Pattern black = new SolidPattern (new Cairo.Color (0.0, 0.0, 0.0, opacity), true);
#endif
			//ctx.Source = black;
			//ctx.Fill ();
			sur.Filter = Filter.Fast;
			ctx.Source = sur;
			ctx.Mask (black);
			//ctx.Paint ();
			
			ctx.Matrix = new Matrix ();
			
			ctx.MoveTo (allocation.Width / 2.0, allocation.Height / 2.0);
			ctx.Source = new SolidPattern (1.0, 0, 0);	
			#if debug
			ctx.ShowText (String.Format ("{0} {1} {2} {3} {4} {5} {6} {7}", 
						     frames,
						     sur.Status,
						     p.Status,
						     opacity, fraction, elapsed, start, DateTime.UtcNow));
			#endif
			sur.Destroy ();
			p.Destroy ();
			return fraction < 1.0;
		}
Пример #19
0
 // Returns a Gst.Buffer presentation of one 640x480 BGRA frame using Cairo
 static Gst.Buffer DrawData (ulong seconds) {
   Gst.Buffer buffer = new Gst.Buffer (640*480*4);
   Cairo.ImageSurface img = new Cairo.ImageSurface (buffer.Data, Cairo.Format.Argb32, 640, 480, 640*4);
   using (Cairo.Context context = new Cairo.Context (img)) {
     double dx = (double) (seconds % 2180) / 5;
     context.Color = new Color (1.0, 1.0, 0);
     context.Paint();
     context.MoveTo (300, 10 + dx);
     context.LineTo (500 - dx, 400);
     context.LineWidth = 4.0;
     context.Color = new Color (0, 0, 1.0);
     context.Stroke();
   }
   img.Destroy();
   return buffer;
 }
Пример #20
0
        public bool OnExpose(Context ctx, Gdk.Rectangle allocation)
        {
            ctx.Operator = Operator.Source;

            SurfacePattern p = new SurfacePattern (info.Surface);

            p.Filter = Filter.Fast;

            Matrix m = info.Fill (allocation, angle);

            ctx.Matrix = m;
            ctx.Source = p;
            ctx.Paint ();
            p.Destroy ();

            return true;
        }
Пример #21
0
        public override void Render(Node node, Context context)
        {
            ImageNode image = node as ImageNode;

            ImageSurface surfaceCache = image.Data as ImageSurface;
            if (surfaceCache == null) {
                surfaceCache = new ImageSurface (image.File);
            }
            int x = (int)((image.Width - surfaceCache.Width) * image.XAlign);
            int y = (int)((image.Height - surfaceCache.Height) * image.YAlign);
            context.SetSourceSurface (surfaceCache, x, y);
            double opacity = image.Opacity;
            if (opacity == 1)
                context.Paint ();
            else
                context.PaintWithAlpha (image.Opacity);
        }
Пример #22
0
		protected unsafe override void OnFillRegionComputed (IBitVector2D stencil)
		{
			Document doc = PintaCore.Workspace.ActiveDocument;
			ImageSurface surf = doc.ToolLayer.Surface;

			using (var g = new Context (surf)) {
				g.Operator = Operator.Source;
				g.SetSource (doc.CurrentUserLayer.Surface);
				g.Paint ();
			}

			SimpleHistoryItem hist = new SimpleHistoryItem (Icon, Name);
			hist.TakeSnapshotOfLayer (doc.CurrentUserLayer);

			ColorBgra color = fill_color.ToColorBgra ().ToPremultipliedAlpha ();
			ColorBgra* dstPtr = (ColorBgra*)surf.DataPtr;
			int width = surf.Width;

			surf.Flush ();

			// Color in any pixel that the stencil says we need to fill
			Parallel.For (0, stencil.Height, y =>
			{
				int stencil_width = stencil.Width;
				for (int x = 0; x < stencil_width; ++x) {
					if (stencil.GetUnchecked (x, y)) {
						surf.SetColorBgraUnchecked (dstPtr, width, color, x, y);
					}
				}
			});

			surf.MarkDirty ();

			// Transfer the temp layer to the real one,
			// respecting any selection area
			using (var g = doc.CreateClippedContext ()) {
				g.Operator = Operator.Source;
				g.SetSource (surf);
				g.Paint ();
			}

			doc.ToolLayer.Clear ();

			doc.History.PushNewItem (hist); 
			doc.Workspace.Invalidate ();
		}
Пример #23
0
        public static void DisplayMessage(Cube c, String msg, SiftColor color)
        {
            ImageSurface sr = new ImageSurface (Format.ARGB32, 128, 128);
            Cairo.Context context = new Cairo.Context (sr);

            context.Color = new Cairo.Color (0, 0, 0, 0);
            context.Paint ();
            Pango.Layout pango = Pango.CairoHelper.CreateLayout (context);

            pango.FontDescription = Pango.FontDescription.FromString ("Arial 16");
            pango.Alignment = Alignment.Center;
            pango.Wrap = WrapMode.WordChar;
            pango.Width = 128 * 1016;
            pango.SetText (msg);

            context.Color = color.ToCairo ();
            int pWidth = 0, pHeight = 0;
            pango.GetPixelSize (out pWidth, out pHeight);
            Log.Debug ("pango Pixel size: " + pWidth + "x" + pHeight);

            context.MoveTo (0, 64 - (pHeight / 2));
            CairoHelper.ShowLayout (context, pango);
            sr.Flush ();
            byte[] data = sr.Data;

            for (int i = 0, x = 0, y = 0; i < data.Length; i += 4, x++) {
                if (x >= 128) {
                    x = 0;
                    y++;
                }
                byte b = data [i],
                g = data [i + 1],
                r = data [i + 2],
                a = data [i + 3];
                if (a != 0 || r != 0 || g != 0 || b != 0) {
                    SiftColor sc = new SiftColor (r, g, b);
                    c.FillRect (sc.ToSifteo (), x, y, 1, 1);
                } else {
                    // we ignore it
                }
            }
            ((IDisposable)context).Dispose ();
            ((IDisposable)pango).Dispose ();
            ((IDisposable)sr).Dispose ();
        }
Пример #24
0
        protected override void RenderExpander(Context context, Gdk.Rectangle pix_rect)
        {
            Gdk.Pixbuf expander;

            if (IsExpanded)
                expander = new Gdk.Pixbuf(ExpandedIcon);
            else
                expander = new Gdk.Pixbuf(CollapsedIcon);

            context.Save();

            Gdk.CairoHelper.SetSourcePixbuf(context, expander, pix_rect.Left, pix_rect.Y);

            m_TextXOffset = expander.Width;

            context.Paint();
            context.Restore();
        }
Пример #25
0
    protected override bool OnDrawn(Cairo.Context cr)
    {
        Gdk.Rectangle titleArea = TitleArea;

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

        int layout_x = icon.Width + 1;

        titleArea.Width -= icon.Width - 1;

        int layoutWidth, layoutHeight;

        Layout.GetPixelSize(out layoutWidth, out layoutHeight);

        int layout_y = (titleArea.Height - layoutHeight) / 2;

        StyleContext.RenderLayout(cr, layout_x, layout_y, Layout);

        return(base.OnDrawn(cr));
    }
Пример #26
0
        public CellRendererSurface(int width, int height)
        {
            // TODO: Respect cell padding (Xpad and Ypad).
            SetFixedSize (width, height);

            transparent = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height);
            Cairo.Color gray = new Cairo.Color (.75, .75, .75);

            // Create checkerboard background
            int grid_width = 4;

            using (Cairo.Context g = new Cairo.Context (transparent)) {
                g.Color = new Cairo.Color (1, 1, 1);
                g.Paint ();

                for (int y = 0; y < height; y += grid_width)
                    for (int x = 0; x < width; x += grid_width)
                        if ((x / grid_width % 2) + (y / grid_width % 2) == 1)
                            g.FillRectangle (new Cairo.Rectangle (x, y, grid_width, grid_width), gray);
            }
        }
Пример #27
0
        // Duplicate current layer
        public UserLayer DuplicateCurrentLayer()
        {
            UserLayer source = CurrentUserLayer;
            UserLayer layer  = CreateLayer(string.Format("{0} {1}", source.Name, Catalog.GetString("copy")));

            using (Cairo.Context g = new Cairo.Context(layer.Surface)) {
                g.SetSource(source.Surface);
                g.Paint();
            }

            layer.Hidden  = source.Hidden;
            layer.Opacity = source.Opacity;
            layer.Tiled   = source.Tiled;

            UserLayers.Insert(++current_layer, layer);

            layer.PropertyChanged += RaiseLayerPropertyChangedEvent;

            PintaCore.Layers.OnLayerAdded();

            return(layer);
        }
Пример #28
0
        public SurfaceWrapper(Cairo.Context similar, Gdk.Pixbuf source)
        {
            Cairo.Surface surface;
            // There is a bug in Cairo for OSX right now that prevents creating additional accellerated surfaces.
            if (MonoDevelop.Core.Platform.IsMac)
            {
                surface = new QuartzSurface(Cairo.Format.ARGB32, source.Width, source.Height);
            }
            else
            {
                surface = similar.Target.CreateSimilar(Cairo.Content.ColorAlpha, source.Width, source.Height);
            }

            using (Cairo.Context context = new Cairo.Context(surface)) {
                Gdk.CairoHelper.SetSourcePixbuf(context, source, 0, 0);
                context.Paint();
            }

            Surface = surface;
            Width   = source.Width;
            Height  = source.Height;
        }
Пример #29
0
		private Pixbuf ProcessImpl (Pixbuf input, Cms.Profile input_profile, bool fast) {
			Pixbuf result;
			using (ImageInfo info = new ImageInfo (input)) {
				MemorySurface surface = new MemorySurface (Format.Argb32,
									   input.Width,
									   input.Height);

				Context ctx = new Context (surface);
				ctx.Matrix = info.Fill (info.Bounds, angle);
				SurfacePattern p = new SurfacePattern (info.Surface);
				if (fast) {
					p.Filter =  Filter.Fast;
				}
				ctx.Source = p;
				ctx.Paint ();
				((IDisposable)ctx).Dispose ();
				p.Destroy ();
				result = MemorySurface.CreatePixbuf (surface);
				surface.Flush ();
			}
			return result;
		}
Пример #30
0
        protected override void OnStartTransform()
        {
            base.OnStartTransform();

            Document doc = PintaCore.Workspace.ActiveDocument;

            original_selection = new List <List <IntPoint> > (doc.Selection.SelectionPolygons);
            original_transform.InitMatrix(doc.SelectionLayer.Transform);

            hist = new MovePixelsHistoryItem(Icon, Name, doc);
            hist.TakeSnapshot(!doc.ShowSelectionLayer);

            if (!doc.ShowSelectionLayer)
            {
                // Copy the selection to the temp layer
                doc.CreateSelectionLayer();
                doc.ShowSelectionLayer = true;

                using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) {
                    g.AppendPath(doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.SetSource(doc.CurrentUserLayer.Surface);
                    g.Clip();
                    g.Paint();
                }

                Cairo.ImageSurface surf = doc.CurrentUserLayer.Surface;

                using (Cairo.Context g = new Cairo.Context(surf)) {
                    g.AppendPath(doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Operator = Cairo.Operator.Clear;
                    g.Fill();
                }
            }

            PintaCore.Workspace.Invalidate();
        }
Пример #31
0
        public void DrawLine(Cairo.Context cr, Gdk.Rectangle rect)
        {
            cr.SetSourceRGB(1, 1, 1);
            cr.Paint();
            cr.SetSourceRGB(1.0, 0.2, 0.0);

            cr.Translate(rect.Width / 2, rect.Height / 10);

            cr.LineCap = Cairo.LineCap.Round;
            cr.MoveTo(start);

            cr.LineWidth = 1;
            int n = points.Count - 4;

            if (n > 0)
            {
                foreach (var p in points.Take(n))
                {
                    cr.LineTo(p);
                }
            }
            cr.Stroke();
            for (int i = Math.Max(0, n); i < points.Count; i++)
            {
                if (i < 1)
                {
                    cr.MoveTo(start);
                }
                else
                {
                    cr.MoveTo(points[i - 1]);
                }
                cr.LineWidth = Convert.ToDouble(i - points.Count + 6);
                cr.LineTo(points[i]);
                cr.Stroke();
            }
        }
Пример #32
0
        public Document NewDocument(Gdk.Size imageSize, Color backgroundColor)
        {
            Document doc = CreateAndActivateDocument(null, imageSize);

            doc.Workspace.CanvasSize = imageSize;

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

            if (backgroundColor.A != 0)
            {
                using (Cairo.Context g = new Cairo.Context(background.Surface)) {
                    g.SetSourceColor(backgroundColor);
                    g.Paint();
                }
            }

            doc.Workspace.History.PushNewItem(new BaseHistoryItem(Stock.New, Catalog.GetString("New Image")));
            doc.IsDirty = false;

            PintaCore.Actions.View.ZoomToWindow.Activate();

            return(doc);
        }
Пример #33
0
        public override void Paint(Cairo.Context gr, Rectangle rect, string subPart = "")
        {
            float widthRatio  = 1f;
            float heightRatio = 1f;

            if (Scaled)
            {
                widthRatio  = (float)rect.Width / Dimensions.Width;
                heightRatio = (float)rect.Height / Dimensions.Height;
            }

            if (KeepProportions)
            {
                if (widthRatio < heightRatio)
                {
                    heightRatio = widthRatio;
                }
                else
                {
                    widthRatio = heightRatio;
                }
            }

            gr.Save();

            gr.Translate(rect.Left, rect.Top);
            gr.Scale(widthRatio, heightRatio);
            gr.Translate((rect.Width / widthRatio - Dimensions.Width) / 2, (rect.Height / heightRatio - Dimensions.Height) / 2);

            using (ImageSurface imgSurf = new ImageSurface(image, Format.Argb32,
                                                           Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) {
                gr.SetSourceSurface(imgSurf, 0, 0);
                gr.Paint();
            }
            gr.Restore();
        }
Пример #34
0
        void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y)
        {
            if (!heightMeasured)
            {
                return;
            }

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

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

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

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

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

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

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

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

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

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

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

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

                    if (r.AnimatingExpand)
                    {
                        y = py + r.AnimationHeight;
                        // Repaing the background because the cairo clip doesn't work for gdk primitives
                        int dx = (int)((double)Allocation.Width * dividerPosition);
                        ctx.Rectangle(0, y, dx, Allocation.Height - y);
                        ctx.SetSourceColor(LabelBackgroundColor);
                        ctx.Fill();
                        ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y);
                        ctx.SetSourceRGB(1, 1, 1);
                        ctx.Fill();
                    }
                }
            }
        }
Пример #35
0
        void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y)
        {
            if (!heightMeasured)
            {
                return;
            }

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

            Pango.FontDescription defaultFont = new Pango.FontDescription();
            Pango.FontDescription changedFont = defaultFont.Copy();
            defaultFont.Weight = Pango.Weight.Bold;

            foreach (var r in rowList)
            {
                int w, h;
                layout.SetText(r.Label);
                if (r.IsDefaultValue && (r.Expanded || HasDefaultValue(r.ChildRows)))
                {
                    layout.FontDescription = changedFont;
                }
                else
                {
                    layout.FontDescription = defaultFont;
                }
                layout.GetPixelSize(out w, out h);
                int indent = 0;

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

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

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

                    var img  = r.Expanded ? discloseUp : discloseDown;
                    var area = GetCategoryArrowArea(r);

                    CairoHelper.SetSourcePixbuf(ctx, img, area.X + (area.Width - img.Width) / 2, area.Y + (area.Height - img.Height) / 2);
                    ctx.Paint();

                    y           += rh;
                    lastCategory = r;
                }
                else
                {
                    var cell = GetCell(r);
                    r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject;
                    var state = r.Enabled ? State : Gtk.StateType.Insensitive;
                    ctx.Save();

                    if (r == lastEditorRow)
                    {
                        ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2);
                        ctx.SetSourceColor(new Cairo.Color(0.8, 0.9, 1.0, 1));
                        ctx.Fill();


                        //int dividerX = (int)((double)Allocation.Width * dividerPosition);
                        //var cell = GetCell(r);
                        //cell.GetSize(Allocation.Width - dividerX, out w, out eh);
                        //eh = Math.Max(h + PropertyTopBottomPadding * 2, eh);
                        //r.EditorBounds = new Gdk.Rectangle(dividerX + PropertyContentLeftPadding, y, Allocation.Width - dividerX - PropertyContentLeftPadding, eh);

                        //var bounds = new Gdk.Rectangle(dividerX + 1, r.EditorBounds.Y, Allocation.Width - dividerX - 1, r.EditorBounds.Height);

                        //ctx.MoveTo(bounds.Right, bounds.Y+1);
                        //ctx.LineTo(bounds.X, bounds.Y+1);
                        //ctx.MoveTo(bounds.Right, bounds.Bottom);
                        //ctx.LineTo(bounds.X, bounds.Bottom);

                        //ctx.Stroke();

                        //ctx.Rectangle(dividerX + 1, r.EditorBounds.Y, Allocation.Width - dividerX - 1, r.EditorBounds.Height);
                        //ctx.SetSourceColor(new Cairo.Color(0.8, 0.9, 1.0, 1));
                        //ctx.Fill();
                    }

                    if (r.ChildRows != null && r.ChildRows.Count > 0)
                    {
                        var img = r.Expanded ? arrowLeft : arrowRight;
                        CairoHelper.SetSourcePixbuf(ctx, img, 2, y + (h + PropertyTopBottomPadding * 2) / 2 - img.Height / 2);
                        ctx.Paint();
                    }

                    ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2);
                    ctx.Clip();
                    ctx.MoveTo(x, y + PropertyTopBottomPadding);
                    ctx.SetSourceColor(Style.Text(state).ToCairoColor());
                    Pango.CairoHelper.ShowLayout(ctx, layout);
                    ctx.Restore();

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

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

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

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

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

                    if (r.AnimatingExpand)
                    {
                        y = py + r.AnimationHeight;
                        // Repaing the background because the cairo clip doesn't work for gdk primitives
                        int dx = (int)((double)Allocation.Width * dividerPosition);
                        ctx.Rectangle(0, y, dx, Allocation.Height - y);
                        ctx.SetSourceColor(LabelBackgroundColor);
                        ctx.Fill();
                        ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y);
                        ctx.SetSourceRGB(1, 1, 1);
                        ctx.Fill();
                    }
                }
            }
        }
Пример #36
0
        public static DockySurface CreateMask(this DockySurface self, double cutOff, out Gdk.Rectangle extents)
        {
            ImageSurface original = new ImageSurface(Format.ARGB32, self.Width, self.Height);

            using (Cairo.Context cr = new Cairo.Context(original)) {
                cr.Operator = Operator.Source;
                cr.SetSource(self.Internal);
                cr.Paint();
            }

            int  width  = original.Width;
            int  height = original.Height;
            byte slice  = (byte)(byte.MaxValue * cutOff);

            int left   = width;
            int right  = 0;
            int top    = height;
            int bottom = 0;

            unsafe {
                byte *dataPtr = (byte *)original.DataPtr;

                int src;
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        src = (y * width + x) * 4;

                        bool mask = dataPtr[src + 3] > slice;

                        dataPtr[src + 0] = 0;
                        dataPtr[src + 1] = 0;
                        dataPtr[src + 2] = 0;
                        dataPtr[src + 3] = mask ? byte.MaxValue : (byte)0;

                        if (mask)
                        {
                            if (y < top)
                            {
                                top = y;
                            }
                            if (y > bottom)
                            {
                                bottom = y;
                            }
                            if (x < left)
                            {
                                left = x;
                            }
                            if (x > right)
                            {
                                right = x;
                            }
                        }
                    }
                }
            }

            extents = new Gdk.Rectangle(left, top, right - left, bottom - top);

            return(new DockySurface(original));
        }
Пример #37
0
        public unsafe static void ExponentialBlur(this DockySurface self, int radius, Gdk.Rectangle area)
        {
            if (radius < 1)
            {
                return;
            }

            area.Intersect(new Gdk.Rectangle(0, 0, self.Width, self.Height));

            int alpha  = (int)((1 << AlphaPrecision) * (1.0 - Math.Exp(-2.3 / (radius + 1.0))));
            int height = self.Height;
            int width  = self.Width;

            ImageSurface original;
            bool         owned;

            if (self.Internal is ImageSurface)
            {
                original = self.Internal  as ImageSurface;
                owned    = true;
            }
            else
            {
                original = new ImageSurface(Format.Argb32, width, height);
                owned    = false;
            }

            if (!owned)
            {
                using (Cairo.Context cr = new Cairo.Context(original)) {
                    cr.Operator = Operator.Source;
                    cr.SetSource(self.Internal);
                    cr.Paint();
                    (cr.Target as IDisposable).Dispose();
                }
            }

            byte *pixels = (byte *)original.DataPtr;

            // Process Rows
            Thread th = new Thread((ThreadStart) delegate {
                ExponentialBlurRows(pixels, width, height, 0, height / 2, area.X, area.Right, alpha);
            });

            th.Start();

            ExponentialBlurRows(pixels, width, height, height / 2, height, area.X, area.Right, alpha);
            th.Join();

            // Process Columns
            th = new Thread((ThreadStart) delegate {
                ExponentialBlurColumns(pixels, width, height, 0, width / 2, area.Y, area.Bottom, alpha);
            });
            th.Start();

            ExponentialBlurColumns(pixels, width, height, width / 2, width, area.Y, area.Bottom, alpha);
            th.Join();

            original.MarkDirty();

            if (!owned)
            {
                self.Context.Operator = Operator.Source;
                self.Context.SetSource(original);
                self.Context.Paint();
                self.Context.Operator = Operator.Over;

                (original as IDisposable).Dispose();
                original.Destroy();
            }
        }
Пример #38
0
        void UpdateBgImage()
        {
            m_bgImage = null;

            if (TextColumn < 0 || WeightColumn < 0)
            {
                return;
            }

            m_bgImage = new Cairo.ImageSurface(Format.Rgb24, Allocation.Width, this.Allocation.Height);

            using (var c = new Cairo.Context(m_bgImage))
            {
                // Paint the default background (linear gradient)
                var g = new Cairo.LinearGradient(0, 0, 1, this.Allocation.Height);
                g.AddColorStop(0.2, CairoExtensions.GdkColorToCairoColor(m_Background));
                g.AddColorStop(0.9, CairoExtensions.GdkColorToCairoColor(this.Style.Background(Gtk.StateType.Normal)));
                c.Rectangle(0, 0, this.Allocation.Width, this.Allocation.Height);
                c.Pattern = g;
                c.Paint();
                g.Dispose();

                Gtk.TreeIter iter;

                List <TreeMapItem> rootItems = new List <TreeMapItem> ();

                if (m_Model.GetIterFirst(out iter))
                {
                    do
                    {
                        var item = new TreeMapItem(m_Model, ref iter, true, m_TextColumn, m_WeightColumn);
                        rootItems.Add(item);
                    } while (m_Model.IterNext(ref iter));

                    double t = 0.0;

                    rootItems.ForEach(delegate(TreeMapItem i) {
                        t += Math.Abs(i.Weight);
                    });

                    double x = 0, y = 0, w = this.Allocation.Width, h = this.Allocation.Height;
                    double myx = 0, myy = 0, myw = 0, myh = 0;

                    rootItems.ForEach(delegate(TreeMapItem i) {
                        var ratio = Math.Abs(i.Weight) / t;
                        myx       = x;
                        myy       = y;
                        myw       = w * ratio;
                        myh       = h;
                        x        += myw;

                        i.SetArea(myx, myy, myw, myh);
                        i.Render(c, m_Background);
                    });

                    // clear right away to lower refs
                    if (this.m_rootItems != null)
                    {
                        this.m_rootItems.Clear();
                    }

                    this.m_rootItems = rootItems;
                }
            }
        }
Пример #39
0
        void HandleExposeEvent(object o, Gtk.ExposeEventArgs args)
        {
            if (display == null)
            {
                return;
            }

            DrawingArea area = (DrawingArea)o;

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

            int border = Math.Min((int)(Allocation.Width * 0.1), (int)(Allocation.Height * 0.1));

            scale = Math.Max(1.0 * display.Width / (Allocation.Width - border * 2), 1.0 * display.Height / (Allocation.Height - border * 2));

            Gdk.Pixbuf image = display.ScaleSimple((int)(display.Width / scale), (int)(display.Height / scale), InterpType.Bilinear);

            imageX = (Allocation.Width - image.Width) / 2;
            imageY = (Allocation.Height - image.Height) / 2;

            Gdk.CairoHelper.SetSourcePixbuf(cr, image, imageX, imageY);
            cr.Paint();

            for (int i = 0; i < CurrentDefinition.Leds.Count; i++)
            {
                DrawLed(i, cr);
            }

            if (FocussedLed != -1)
            {
                cr.LineWidth = 5 / scale;
                cr.Save();
                cr.SetSourceRGB(0, 0, 1);
                cr.Arc(
                    imageX + CurrentDefinition.Leds[FocussedLed].X / scale,
                    imageY + CurrentDefinition.Leds[FocussedLed].Y / scale,
                    (LedSize + 5) / scale / 2,
                    0,
                    2 * Math.PI);
                cr.Stroke();
                cr.Restore();
            }

            if (SelectedLed != -1)
            {
                cr.LineWidth = 5 / scale;
                cr.Save();
                cr.SetSourceRGB(1, 0, 0);
                cr.Arc(
                    imageX + CurrentDefinition.Leds[SelectedLed].X / scale,
                    imageY + CurrentDefinition.Leds[SelectedLed].Y / scale,
                    LedSize / scale / 2,
                    0,
                    2 * Math.PI);
                cr.Stroke();
                cr.Restore();
            }

            image.Dispose();

            ((IDisposable)cr).Dispose();
        }
Пример #40
0
    public static void Do(List <JumpsProfileIndex> l_jpi, DrawingArea area)
    {
        //1 create context
        Cairo.Context g = Gdk.CairoHelper.Create(area.GdkWindow);

        //2 clear DrawingArea (white)
        g.SetSourceRGB(1, 1, 1);
        g.Paint();

        //3 calculate sum
        double sum = 0;

        foreach (JumpsProfileIndex jpi in l_jpi)
        {
            sum += jpi.Result;
        }

        //4 prepare font
        g.SelectFontFace("Helvetica", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
        int textHeight = 12;

        g.SetFontSize(textHeight);

        //5 plot arcs
        if (sum > 0)
        {
            double acc = 0;             //accumulated
            foreach (JumpsProfileIndex jpi in l_jpi)
            {
                double percent = 2 * jpi.Result / sum;                              //*2 to be in range 0*pi - 2*pi
                plotArc(200, 200, 150, acc - .5, acc + percent - .5, g, jpi.Color); //-.5 to start at top of the pie
                acc += percent;
            }
        }

        //6 draw legend at right
        int y = 50;

        //R seq(from=50,to=(350-24),length.out=5)
        //[1] 50 119 188 257 326 #difference is 69
        foreach (JumpsProfileIndex jpi in l_jpi)
        {
            drawRoundedRectangle(400, y, 40, 24, 6, g, jpi.Color);

            double percent = 0;
            if (sum > 0)
            {
                percent = 100 * jpi.Result / sum;
            }

            printText(460, y, 24, textHeight, Util.TrimDecimals(percent, 1) + jpi.Text, g);
            y += 69;
        }

        //7 print errors (if any)
        g.SetSourceRGB(0.5, 0, 0);
        y = 70;
        foreach (JumpsProfileIndex jpi in l_jpi)
        {
            printText(460, y, 24, textHeight, jpi.ErrorMessage, g);
            y += 69;
        }

        //8 dispose
        g.GetTarget().Dispose();
        g.Dispose();
    }
Пример #41
0
            public static void DrawShadow(Cairo.Context cr, double x, double y, double width,
                                          double height, double radius, ShadowParameters shadowParams)
            {
                using (Surface sr = cr.CreateSimilarToTarget((int)width + (int)(2 * shadowParams.shadowRadius) + (int)x,
                                                             (int)height + (int)(2 * shadowParams.shadowRadius) + (int)y))
                {
                    using (Context cairo = new Context(sr))
                    {
                        radius++;
                        y++;
                        height--;
                        Cairo.Gradient shadow;
                        /* Top Left */
                        using (shadow = new Cairo.RadialGradient(x + radius, y + radius, radius,
                                                                 x + radius, y + radius, radius + shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(x - shadowParams.shadowRadius, y - shadowParams.shadowRadius,
                                            radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }
                        /* Top */
                        using (shadow = new Cairo.LinearGradient(0.0, y, 0.0, y - shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(x + radius, y - shadowParams.shadowRadius,
                                            width - radius * 2, shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }
                        /* Top Right */
                        using (shadow = new Cairo.RadialGradient(width + x - radius, y + radius, radius,
                                                                 width + x - radius, y + radius, radius + shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(width + x - radius, y - shadowParams.shadowRadius,
                                            radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        /* Right */
                        using (shadow = new Cairo.LinearGradient(width + x, 0.0,
                                                                 width + x + shadowParams.shadowRadius, 0.0))
                        {
                            cairo.Rectangle(width + x, y + radius, shadowParams.shadowRadius, height - radius * 2);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        /* Bottom Right */
                        using (shadow = new Cairo.RadialGradient(width + x - radius, height + y - radius, radius,
                                                                 width + x - radius, height + y - radius, radius + shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(width + x - radius, height + y - radius,
                                            radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        /* Bottom */
                        using (shadow = new Cairo.LinearGradient(0.0, height + y,
                                                                 0.0, height + y + shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(x + radius, height + y,
                                            width - radius * 2, shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        /* Bottom Left */
                        using (shadow = new Cairo.RadialGradient(x + radius, height + y - radius, radius,
                                                                 x + radius, height + y - radius, radius + shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(x - shadowParams.shadowRadius, height + y - radius,
                                            radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        /* Left */
                        using (shadow = new Cairo.LinearGradient(x, 0.0,
                                                                 x - shadowParams.shadowRadius, 0.0))
                        {
                            cairo.Rectangle(x - shadowParams.shadowRadius, y + radius,
                                            radius + shadowParams.shadowRadius, height - radius * 2);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        y--;
                        height++;
                        /* Clear inner rectangle */
                        GetFrame(cairo, x, y, width, height, radius);
                        cairo.Operator = Cairo.Operator.Clear;
                        cairo.Fill();

                        cr.SetSource(sr);
                        cr.Paint();
                    }
                }
            }
Пример #42
0
        public bool OnExpose(Context ctx, Gdk.Rectangle viewport)
        {
            double percent = Math.Min ((DateTime.UtcNow - start).Ticks / (double) duration.Ticks, 1.0);

            //Matrix m = info.Fill (allocation);
            Matrix m = new Matrix ();
            m.Translate (pan_x, pan_y);
            m.Scale (zoom, zoom);
            ctx.Matrix = m;

            SurfacePattern p = new SurfacePattern (info.Surface);
            ctx.Source = p;
            ctx.Paint ();
            p.Destroy ();

            return percent < 1.0;
        }
Пример #43
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            if (evnt.Window != GdkWindow)
            {
                return(base.OnExposeEvent(evnt));
            }

            Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window);

            if (reflect)
            {
                CairoExtensions.PushGroup(cr);
            }

            cr.Operator = Operator.Over;
            cr.Translate(Allocation.X + h_padding, Allocation.Y);
            cr.Rectangle(0, 0, Allocation.Width - h_padding, Math.Max(2 * bar_height,
                                                                      bar_height + bar_label_spacing + layout_height));
            cr.Clip();

            Pattern bar = RenderBar(Allocation.Width - 2 * h_padding, bar_height);

            cr.Save();
            cr.SetSource(bar);
            cr.Paint();
            cr.Restore();

            if (reflect)
            {
                cr.Save();

                cr.Rectangle(0, bar_height, Allocation.Width - h_padding, bar_height);
                cr.Clip();

                var matrix = new Matrix();
                matrix.InitScale(1, -1);
                matrix.Translate(0, -(2 * bar_height) + 1);
                cr.Transform(matrix);

                cr.SetSource(bar);

                var mask = new LinearGradient(0, 0, 0, bar_height);

                mask.AddColorStop(0.25, new Color(0, 0, 0, 0));
                mask.AddColorStop(0.5, new Color(0, 0, 0, 0.125));
                mask.AddColorStop(0.75, new Color(0, 0, 0, 0.4));
                mask.AddColorStop(1.0, new Color(0, 0, 0, 0.7));

                cr.Mask(mask);
                mask.Dispose();

                cr.Restore();

                CairoExtensions.PopGroupToSource(cr);
                cr.Paint();
            }

            if (show_labels)
            {
                cr.Translate((reflect ? Allocation.X : -h_padding) + (Allocation.Width - layout_width) / 2,
                             (reflect ? Allocation.Y : 0) + bar_height + bar_label_spacing);

                RenderLabels(cr);
            }

            bar.Dispose();
            CairoExtensions.DisposeContext(cr);

            return(true);
        }
Пример #44
0
    public Flower( )
    {
        int idx      = -1;
        int last_idx = -1;

        int petal_size = PETAL_MIN + rand() % PETAL_VAR;
        int size       = petal_size * 8;

        int n_groups = rand() % 3 + 1;

        this.ctex = new CairoTexture((uint)size, (uint)size);

        // the using statement make sure the cr is disposed at the end,
        // otherwise we get no bling
        using (Cairo.Context cr = this.ctex.Create())
        {
            cr.Tolerance = 0.1;

            // Clear
            cr.Operator = Operator.Clear;
            cr.Paint();
            cr.Operator = Operator.Over;

            cr.Translate(size / 2, size / 2);

            // petals
            for (int i = 0; i < n_groups; i++)
            {
                int n_petals = rand() % 5 + 4;
                cr.Save();

                cr.Rotate(rand() % 6);

                do
                {
                    idx = (rand() % (colors.Length / 3)) * 3;
                } while (idx == last_idx);

                cr.SetSourceRGBA(colors[idx], colors[idx + 1], colors[idx + 2], 0.5);

                int pm1 = rand() % 20;
                int pm2 = rand() % 4;

                for (int j = 0; j < n_petals; j++)
                {
                    cr.Save();

                    cr.Rotate(((2 * Math.PI) / n_petals) * j);

                    cr.NewPath();
                    cr.MoveTo(0, 0);

                    cr.RelCurveTo(petal_size, petal_size, (pm2 + 2) * petal_size,
                                  petal_size, (2 * petal_size) + pm1, 0);

                    cr.RelCurveTo(0 + (pm2 * petal_size), -petal_size, -petal_size,
                                  -petal_size, -((2 * petal_size) + pm1), 0);

                    cr.ClosePath();
                    cr.Fill();
                    cr.Restore();
                }

                petal_size -= rand() % (size / 8);

                cr.Restore();
            }

            // flower center
            do
            {
                idx = (rand() % (colors.Length / 4 / 3)) * 3;
            } while (idx == last_idx);

            if (petal_size < 0)
            {
                petal_size = rand() % 10;
            }

            cr.SetSourceRGBA(colors[idx], colors[idx + 1], colors[idx + 2], 0.5);

            cr.Arc(0, 0, petal_size, 0, Math.PI * 2);
            cr.Fill();
        }
    }
Пример #45
0
    public static void Do(List <JumpsProfileIndex> l_jpi, DrawingArea area, string title, string date)
    {
        //1 create context
        Cairo.Context g = Gdk.CairoHelper.Create(area.GdkWindow);

        //2 clear DrawingArea (white)
        g.SetSourceRGB(1, 1, 1);
        g.Paint();

        //3 calculate sum
        double sum = 0;

        foreach (JumpsProfileIndex jpi in l_jpi)
        {
            if (jpi.Result >= 0)
            {
                sum += jpi.Result;
            }
        }

        //4 prepare font
        g.SelectFontFace("Helvetica", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
        int textHeight = 12;

        g.SetFontSize(textHeight);

        if (sum == 0)
        {
            g.SetSourceRGB(0, 0, 0);
            g.SetFontSize(16);
            printText(100, 100, 24, textHeight, Constants.JumpsProfileNeededJumps, g, false);
            g.GetTarget().Dispose();
            g.Dispose();
            return;
        }


        //5 plot arcs
        if (sum > 0)
        {
            double acc = 0;             //accumulated
            foreach (JumpsProfileIndex jpi in l_jpi)
            {
                double percent = 2 * jpi.Result / sum;                 //*2 to be in range 0*pi - 2*pi
                if (percent > 0)
                {
                    plotArc(200, 200, 150, acc - .5, acc + percent - .5, g, jpi.Color);                   //-.5 to start at top of the pie
                    acc += percent;
                }
            }
            //fix last radius line, because ClosePath has been disabled
            g.MoveTo(200, 50);
            g.LineTo(200, 200);
            g.LineWidth = 2;
            g.Stroke();
        }

        //6 draw legend at right
        int legendX = findLegendTextXPos(l_jpi, sum, 400);
        int y       = 40;

        //R seq(from=50,to=(350-24),length.out=5)
        //[1] 50 119 188 257 326 #difference is 69
        //g.SelectFontFace("Helvetica", Cairo.FontSlant.Normal, Cairo.FontWeight.Bold);
        foreach (JumpsProfileIndex jpi in l_jpi)
        {
            double percent = 100 * Util.DivideSafe(jpi.Result, sum);
            printText(legendX, y, 24, textHeight, Util.TrimDecimals(percent, 1) + jpi.Text, g, false);
            if (percent != 0)
            {
                drawRoundedRectangle(legendX, y + 30, Convert.ToInt32(2 * percent), 20, 4, g, jpi.Color);
            }

            y += 69;
        }
        //print title and date
        g.SetFontSize(18);
        printText(200, y, 0, textHeight, title, g, true);
        g.SetFontSize(textHeight);
        printText(200, y + 20, 0, textHeight, "Chronojump profile (" + date + ")", g, true);

        //g.SelectFontFace("Helvetica", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);

        //7 print errors (if any)
        g.SetSourceRGB(0.5, 0, 0);
        y = 70;
        foreach (JumpsProfileIndex jpi in l_jpi)
        {
            if (jpi.ErrorMessage != "")
            {
                printText(legendX + 12, y, 24, textHeight, jpi.ErrorMessage, g, false);
            }
            y += 69;
        }

        //8 dispose
        g.GetTarget().Dispose();
        g.Dispose();
    }
Пример #46
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (!CairoHelper.ShouldDrawWindow(cr, Window))
            {
                return(base.OnDrawn(cr));
            }

            if (reflect)
            {
                cr.PushGroup();
            }

            cr.Operator = Operator.Over;
            cr.Translate(h_padding, 0);
            cr.Rectangle(0, 0, Allocation.Width - h_padding, Math.Max(2 * bar_height,
                                                                      bar_height + bar_label_spacing + layout_height));
            cr.Clip();

            using (var bar = RenderBar(Allocation.Width - 2 * h_padding, bar_height)) {
                cr.Save();
                cr.SetSource(bar);
                cr.Paint();
                cr.Restore();

                if (reflect)
                {
                    cr.Save();

                    cr.Rectangle(0, bar_height, Allocation.Width - h_padding, bar_height);
                    cr.Clip();

                    Matrix matrix = new Matrix();
                    matrix.InitScale(1, -1);
                    matrix.Translate(0, -(2 * bar_height) + 1);
                    cr.Transform(matrix);

                    cr.SetSource(bar);

                    using (var mask = new LinearGradient(0, 0, 0, bar_height)) {
                        mask.AddColorStop(0.25, new Color(0, 0, 0, 0));
                        mask.AddColorStop(0.5, new Color(0, 0, 0, 0.125));
                        mask.AddColorStop(0.75, new Color(0, 0, 0, 0.4));
                        mask.AddColorStop(1.0, new Color(0, 0, 0, 0.7));

                        cr.Mask(mask);
                    }

                    cr.Restore();

                    cr.PopGroupToSource();
                    cr.Paint();
                }

                if (show_labels)
                {
                    cr.Translate((reflect ? 0 : -h_padding) + (Allocation.Width - layout_width) / 2,
                                 bar_height + bar_label_spacing);
                    RenderLabels(cr);
                }
            }

            return(true);
        }
Пример #47
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            if (!IsRealized)
            {
                return(false);
            }

            Gdk.Rectangle allocation = Allocation;

            int pixbufSize = allocation.Height - IconBuffer * 2;

            if (item.ShowIcons && (icon_surface == null || (icon_surface.Height != pixbufSize && icon_surface.Width != pixbufSize)))
            {
                if (icon_surface != null)
                {
                    icon_surface.Dispose();
                }
                if (emblem_surface != null)
                {
                    emblem_surface.Dispose();
                }

                if (item.ForcePixbuf == null)
                {
                    icon_surface = LoadIcon(item.Icon, pixbufSize);
                }
                else
                {
                    icon_surface = LoadIcon(item.ForcePixbuf, pixbufSize);
                }

                if (!string.IsNullOrEmpty(item.Emblem))
                {
                    emblem_surface = LoadIcon(item.Emblem, pixbufSize);
                }
            }

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                if (Selected && !item.Disabled)
                {
                    cr.Rectangle(allocation.X, allocation.Y, allocation.Width, allocation.Height);
                    cr.Color = TextColor.SetAlpha(.1);
                    cr.Fill();
                }

                if (item.ShowIcons)
                {
                    PlaceSurface(cr, icon_surface, allocation);
                    cr.PaintWithAlpha(item.Disabled ? 0.5 : 1);

                    if (item.Bold)
                    {
                        cr.Operator = Operator.Add;
                        PlaceSurface(cr, icon_surface, allocation);
                        cr.PaintWithAlpha(.8);
                        cr.Operator = Operator.Over;
                    }

                    if (!string.IsNullOrEmpty(item.Emblem))
                    {
                        PlaceSurface(cr, emblem_surface, allocation);
                        cr.Paint();
                    }
                }

                using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) {
                    char   accel;
                    string text = GLib.Markup.EscapeText(item.Text.Replace("\n", ""));
                    if (item.Mnemonic.HasValue)
                    {
                        layout.SetMarkupWithAccel(text, '_', out accel);
                    }
                    else
                    {
                        layout.SetMarkup(text);
                    }
                    layout.Width           = Pango.Units.FromPixels(TextWidth);
                    layout.FontDescription = Style.FontDescription;
                    layout.Ellipsize       = Pango.EllipsizeMode.End;
                    layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(FontSize);
                    layout.FontDescription.Weight       = Pango.Weight.Bold;

                    Pango.Rectangle logical, ink;
                    layout.GetPixelExtents(out ink, out logical);

                    int offset = Padding;
                    if (MenuShowingIcons)
                    {
                        offset += MenuHeight + Padding;
                    }
                    cr.MoveTo(allocation.X + offset, allocation.Y + (allocation.Height - logical.Height) / 2);
                    Pango.CairoHelper.LayoutPath(cr, layout);
                    cr.Color = TextColor.SetAlpha(item.Disabled ? 0.5 : 1);
                    cr.Fill();

                    layout.Context.Dispose();
                }

                (cr.Target as IDisposable).Dispose();
            }

            return(true);
        }
Пример #48
0
        public void Render(Cairo.Context context, StatusArea.RenderArg arg)
        {
            context.CachedDraw(surface: ref backgroundSurface,
                               region: arg.Allocation,
                               draw: (c, o) => DrawBackground(c, new Gdk.Rectangle(0, 0, arg.Allocation.Width, arg.Allocation.Height)));

            if (arg.BuildAnimationOpacity > 0.001f)
            {
                DrawBuildEffect(context, arg.Allocation, arg.BuildAnimationProgress, arg.BuildAnimationOpacity);
            }

            if (arg.ErrorAnimationProgress > 0.001 && arg.ErrorAnimationProgress < .999)
            {
                DrawErrorAnimation(context, arg);
            }

            DrawBorder(context, arg.Allocation);

            if (arg.HoverProgress > 0.001f)
            {
                context.Clip();
                int x1 = arg.Allocation.X + arg.MousePosition.X - 200;
                int x2 = x1 + 400;
                using (Cairo.LinearGradient gradient = new LinearGradient(x1, 0, x2, 0))
                {
                    Cairo.Color targetColor      = Styles.StatusBarFill1Color;
                    Cairo.Color transparentColor = targetColor;
                    targetColor.A      = .7;
                    transparentColor.A = 0;

                    targetColor.A = .7 * arg.HoverProgress;

                    gradient.AddColorStop(0.0, transparentColor);
                    gradient.AddColorStop(0.5, targetColor);
                    gradient.AddColorStop(1.0, transparentColor);

                    context.SetSource(gradient);

                    context.Rectangle(x1, arg.Allocation.Y, x2 - x1, arg.Allocation.Height);
                    context.Fill();
                }
                context.ResetClip();
            }
            else
            {
                context.NewPath();
            }

            int progress_bar_x     = arg.ChildAllocation.X;
            int progress_bar_width = arg.ChildAllocation.Width;

            if (arg.CurrentPixbuf != null)
            {
                int y = arg.Allocation.Y + (arg.Allocation.Height - arg.CurrentPixbuf.Height) / 2;
                Gdk.CairoHelper.SetSourcePixbuf(context, arg.CurrentPixbuf, arg.ChildAllocation.X, y);
                context.Paint();
                progress_bar_x     += arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
                progress_bar_width -= arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
            }

            int center = arg.Allocation.Y + arg.Allocation.Height / 2;

            Gdk.Rectangle progressArea = new Gdk.Rectangle(progress_bar_x, center - Styles.ProgressBarHeight / 2, progress_bar_width, Styles.ProgressBarHeight);
            if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0)
            {
                DrawProgressBar(context, arg.ProgressBarFraction, progressArea, arg);
                ClipProgressBar(context, progressArea);
            }

            int text_x     = progress_bar_x + Styles.ProgressBarInnerPadding;
            int text_width = progress_bar_width - (Styles.ProgressBarInnerPadding * 2);

            double textTweenValue = arg.TextAnimationProgress;

            if (arg.LastText != null)
            {
                double opacity = Math.Max(0.0f, 1.0f - textTweenValue);
                DrawString(arg.LastText, arg.LastTextIsMarkup, context, text_x,
                           center - (int)(textTweenValue * arg.Allocation.Height * 0.3), text_width, opacity, arg.Pango, arg);
            }

            if (arg.CurrentText != null)
            {
                DrawString(arg.CurrentText, arg.CurrentTextIsMarkup, context, text_x,
                           center + (int)((1.0f - textTweenValue) * arg.Allocation.Height * 0.3), text_width, Math.Min(textTweenValue, 1.0), arg.Pango, arg);
            }

            if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0)
            {
                context.ResetClip();
            }
        }
Пример #49
0
    bool DrawBoard()

    {
        if (!isGameOver)
        {
            Cairo.Context ct = Gdk.CairoHelper.Create(picGameBoard.GdkWindow);

            // fazer a ultima parte do corpo da snake desaparecer
            ct.Rectangle(snakeXY[snakeLength - 1].x * 35, snakeXY[snakeLength - 1].y * 35, 35, 35);
            //ct.StrokePreserve();
            ct.SetSourceRGB(1, 1, 1);
            ct.Fill();
            gameBoardField[snakeXY[snakeLength - 1].x, snakeXY[snakeLength - 1].y] = GameBoardFields.Free;

            //move snake's body parts
            for (int i = snakeLength; i >= 1; i--)
            {
                snakeXY[i].x = snakeXY[i - 1].x;
                snakeXY[i].y = snakeXY[i - 1].y;
            }

            //draw new body part position
            ct.SetSourceSurface(images[4], snakeXY[0].x * 35, snakeXY[0].y * 35);
            ct.Paint();

            if (direction == Directions.Up)
            {
                snakeXY[0].y = snakeXY[0].y - 1;
            }
            else if (direction == Directions.Down)
            {
                snakeXY[0].y = snakeXY[0].y + 1;
            }
            else if (direction == Directions.Left)
            {
                snakeXY[0].x = snakeXY[0].x - 1;
            }
            else if (direction == Directions.Right)
            {
                snakeXY[0].x = snakeXY[0].x + 1;
            }
            else
            {
                Environment.Exit(0);
            }
            Console.WriteLine($"x: {snakeXY[0].x} y: {snakeXY[0].y}");
            //check if it hits a wall
            if (snakeXY[0].x > 10 || snakeXY[0].x < 1 || snakeXY[0].y > 10 || snakeXY[0].y < 1)
            {
                GameOver("Bateu na borda");
            }
            // if snake head hits its body
            else if (gameBoardField[snakeXY[0].x, snakeXY[0].y] == GameBoardFields.Snake)
            {
                GameOver("Bateu no corpo");
            }
            // if snake eats the bonus
            else if (gameBoardField[snakeXY[0].x, snakeXY[0].y] == GameBoardFields.Bonus)
            {
                ct.SetSourceSurface(images[4], snakeXY[snakeLength].x * 35, snakeXY[snakeLength].y * 35);
                ct.Paint();

                //draw snake's head
                ct.SetSourceSurface(images[5], snakeXY[0].x * 35, snakeXY[0].y * 35);
                ct.Paint();

                gameBoardField[snakeXY[snakeLength].x, snakeXY[snakeLength].y] = GameBoardFields.Snake;
                snakeLength++;

                if (snakeLength < 96)
                {
                    Bonus();
                }
                timeTick -= 100;
                Console.WriteLine($"Snake score: {snakeLength - 3}");
            }
            else
            {
                //draw snake's head
                ct.SetSourceSurface(images[5], snakeXY[0].x * 35, snakeXY[0].y * 35);
                ct.Paint();
            }
            gameBoardField[snakeXY[0].x, snakeXY[0].y] = GameBoardFields.Snake;
        }
        return(true);
    }
Пример #50
0
        protected override void Render(Cairo.Context cr, double width, double height, CellRendererState state)
        {
            // Scale the border size w/ the cell size
            var border_width = width / 128.0;

            width  -= 2 * border_width;
            height -= 2 * border_width;
            if (width < 0 || height < 0)
            {
                return;
            }

            //Console.WriteLine ("SurfaceCache has HitRatio = {0:0.00} ({1} hits, {2} misses, max_count = {3})", surface_cache.HitRatio, surface_cache.Hits, surface_cache.Misses, surface_cache.MaxCount);
            PageThumbnail cache_obj;
            ImageSurface  surface = null;

            if (surface_cache.TryGetValue(Page, out cache_obj))
            {
                // Don't use if not big enough, dirty, or corrupt
                surface = cache_obj.Surface;
                if (Page.SurfaceDirty || surface == null || surface.Handle == IntPtr.Zero || (surface.Width < width && surface.Height < height))
                {
                    surface_cache.Remove(Page);
                    cache_obj = null;
                    surface   = null;
                }
            }

            if (surface == null)
            {
                // Create a new thumbnail surface, but only on 200px boundaries, then we scale down if needed
                var w = width + (width % scale_every);
                var h = height + (height % scale_every);
                cache_obj = Page.Document.GetSurface(Page, (int)w, (int)h, DocumentIconView.MIN_WIDTH);
                if (cache_obj == null)
                {
                    return;
                }
                surface = cache_obj.Surface;

                // Put it in the cache
                surface_cache.Add(Page, cache_obj);
            }

            double scale      = Math.Min(width / (double)surface.Width, height / (double)surface.Height);
            double doc_width  = scale * surface.Width;
            double doc_height = scale * surface.Height;

            // Center the thumbnail if either dimension is smaller than the cell's
            if (doc_width < width || doc_height < height)
            {
                var x = ((width - doc_width) / 2.0) - border_width;
                var y = ((height - doc_height) / 2.0) - border_width;
                cr.Translate(x, y);
            }

            PaintDocumentBorder(cr, doc_width, doc_height, border_width);

            // Scale down the surface if it's not exactly the right size
            if (scale < 1)
            {
                cr.Scale(scale, scale);
            }

            // Paint the scaled/translated thumbnail
            cr.SetSource(surface);
            cr.Paint();
        }
Пример #51
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            int x = (int)point.X;
            int y = (int)point.Y;

            if (args.Event.Button == 1)//Left
            {
                //Select an origin with Ctrl + Click
                if((args.Event.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask)
                {
                    from_point = new Point (x, y);
                    stamp = new Cairo.ImageSurface (PintaCore.Layers.CurrentLayer.Surface.Format, BrushWidth*2, BrushWidth*2);
                    from_point = ClampPoint(from_point);

                    using (Context g = new Context (stamp)) {
                        g.SetSourceSurface (PintaCore.Layers.CurrentLayer.Surface,
                                            0 - (from_point.X - BrushWidth),
                                            0 - (from_point.Y - BrushWidth));//dest - source

                        g.Rectangle(0, 0, BrushWidth * 2, BrushWidth * 2);

                        Gradient radpat = new RadialGradient(from_point.X, from_point.Y, BrushWidth, from_point.X, from_point.Y, BrushWidth);
                        radpat.AddColorStop(0, new Color(0, 0, 0, 1));
                        radpat.AddColorStop(1, new Color(0, 0, 0, 0));

                        g.Mask(radpat);

                        g.Fill ();
                    }

                // Draw the copy
                } else {
                    to_point = new Point (x, y);

                    if (PintaCore.Workspace.PointInCanvas (point) && !from_point.Equals (point_empty))
                    {
                        to_point = ClampPoint(to_point);
                        surface_modified = true;

                        undo_surface = PintaCore.Layers.CurrentLayer.Surface.Clone ();

                        ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

                        using (Context g = new Context (surf)) {
                            g.SetSourceSurface (stamp, to_point.X - BrushWidth, to_point.Y - BrushWidth);
                            g.Paint ();
                        }

                        Gdk.Rectangle r = GetRectangleFromPoints (to_point, to_point);

                        PintaCore.Workspace.Invalidate ();
                        PintaCore.History.PushNewItem(new SimpleHistoryItem (Icon, Name,undo_surface, PintaCore.Layers.CurrentLayerIndex));
                    }
                    from_point = point_empty;
                }
            }
            base.OnMouseDown (canvas, args, point);
        }
Пример #52
0
        void ejecutar_consulta_reporte(PrintContext context)
        {
            Cairo.Context         cr     = context.CairoContext;
            Pango.Layout          layout = context.CreatePangoLayout();
            Pango.FontDescription desc   = Pango.FontDescription.FromString("Sans");
            // cr.Rotate(90)  Imprimir Orizontalmente rota la hoja cambian las posiciones de las lineas y columna
            fontSize  = 8.0;                 layout = null;                  layout = context.CreatePangoLayout();
            desc.Size = (int)(fontSize * pangoScale);               layout.FontDescription = desc;

            imprime_encabezado(cr, layout);
            comienzo_linea += separacion_linea;
            //cr.Rotate(90);  //Imprimir Orizontalmente rota la hoja cambian las posiciones de las lineas y columna
            fontSize  = 9.0;
            desc.Size = (int)(fontSize * pangoScale);                                       layout.FontDescription = desc;
            layout.FontDescription.Weight = Weight.Bold;                        // Letra negrita
            cr.MoveTo(05 * escala_en_linux_windows, comienzo_linea * escala_en_linux_windows);                   layout.SetText(this.nombre_estudio);            Pango.CairoHelper.ShowLayout(cr, layout);
            layout.FontDescription.Weight = Weight.Normal;                      // Letra negrita

            cr.MoveTo(570 * escala_en_linux_windows, (comienzo_linea + separacion_linea) * escala_en_linux_windows);
            cr.LineTo(05, comienzo_linea + separacion_linea);                   // Linea Horizontal 4
            cr.Stroke();

            fontSize        = 8.0;
            desc.Size       = (int)(fontSize * pangoScale);                                       layout.FontDescription = desc;
            comienzo_linea += separacion_linea;
            comienzo_linea += separacion_linea;
            cr.MoveTo(100 * escala_en_linux_windows, comienzo_linea * escala_en_linux_windows);                  layout.SetText("PARAMETROS");           Pango.CairoHelper.ShowLayout(cr, layout);
            cr.MoveTo(250 * escala_en_linux_windows, comienzo_linea * escala_en_linux_windows);                  layout.SetText("RESULTADOS");           Pango.CairoHelper.ShowLayout(cr, layout);
            cr.MoveTo(400 * escala_en_linux_windows, comienzo_linea * escala_en_linux_windows);                  layout.SetText("V.R.");         Pango.CairoHelper.ShowLayout(cr, layout);
            comienzo_linea += separacion_linea;
            comienzo_linea += separacion_linea;

            int lineahorizontal = comienzo_linea;

            TreeIter iter;

            if (this.treeViewEngineresultados.GetIterFirst(out iter))
            {
                if ((bool)this.lista_de_resultados.Model.GetValue(iter, 5) == true)
                {
                    if ((string)this.lista_de_resultados.Model.GetValue(iter, 0) != "")
                    {
                        cr.MoveTo(570 * escala_en_linux_windows, (comienzo_linea) * escala_en_linux_windows);
                        cr.LineTo(05, comienzo_linea);                                  // Linea Horizontal 4
                        cr.LineWidth = 0.1;
                        cr.Stroke();
                    }
                    cr.MoveTo(25 * escala_en_linux_windows, comienzo_linea * escala_en_linux_windows);                   layout.SetText((string)this.lista_de_resultados.Model.GetValue(iter, 0));              Pango.CairoHelper.ShowLayout(cr, layout);
                    cr.MoveTo(230 * escala_en_linux_windows, comienzo_linea * escala_en_linux_windows);                  layout.SetText((string)this.lista_de_resultados.Model.GetValue(iter, 1));              Pango.CairoHelper.ShowLayout(cr, layout);
                    cr.MoveTo(360 * escala_en_linux_windows, comienzo_linea * escala_en_linux_windows);                  layout.SetText((string)this.lista_de_resultados.Model.GetValue(iter, 2));              Pango.CairoHelper.ShowLayout(cr, layout);
                    cr.MoveTo(570 * escala_en_linux_windows, (comienzo_linea + separacion_linea) * escala_en_linux_windows);
                    cr.LineTo(05, comienzo_linea + separacion_linea);                           // Linea Horizontal 4
                    cr.Stroke();
                    comienzo_linea += separacion_linea;
                }
                while (treeViewEngineresultados.IterNext(ref iter))
                {
                    if ((bool)this.lista_de_resultados.Model.GetValue(iter, 5) == true)
                    {
                        if ((string)this.lista_de_resultados.Model.GetValue(iter, 0) != "")
                        {
                            cr.MoveTo(570 * escala_en_linux_windows, (comienzo_linea) * escala_en_linux_windows);
                            cr.LineTo(05, comienzo_linea);                                      // Linea Horizontal 4
                            cr.LineWidth = 0.1;
                            cr.Stroke();
                        }
                        cr.MoveTo(25 * escala_en_linux_windows, comienzo_linea * escala_en_linux_windows);                   layout.SetText((string)this.lista_de_resultados.Model.GetValue(iter, 0));              Pango.CairoHelper.ShowLayout(cr, layout);
                        cr.MoveTo(230 * escala_en_linux_windows, comienzo_linea * escala_en_linux_windows);                  layout.SetText((string)this.lista_de_resultados.Model.GetValue(iter, 1));              Pango.CairoHelper.ShowLayout(cr, layout);
                        cr.MoveTo(360 * escala_en_linux_windows, comienzo_linea * escala_en_linux_windows);                  layout.SetText((string)this.lista_de_resultados.Model.GetValue(iter, 2));              Pango.CairoHelper.ShowLayout(cr, layout);
                        comienzo_linea += separacion_linea;
                    }
                }
            }
            cr.MoveTo(570 * escala_en_linux_windows, (comienzo_linea) * escala_en_linux_windows);
            cr.LineTo(05, comienzo_linea);
            cr.LineWidth = 0.1;

            cr.MoveTo(05 * escala_en_linux_windows, lineahorizontal * escala_en_linux_windows);
            cr.LineTo(05, comienzo_linea);

            cr.MoveTo(570 * escala_en_linux_windows, lineahorizontal * escala_en_linux_windows);
            cr.LineTo(570, comienzo_linea);

            cr.Stroke();
            comienzo_linea += separacion_linea;
            comienzo_linea += separacion_linea;
            cr.MoveTo(05 * escala_en_linux_windows, comienzo_linea * escala_en_linux_windows);           layout.SetText("Observaciones: " + observa);              Pango.CairoHelper.ShowLayout(cr, layout);

            cr.MoveTo(300 * escala_en_linux_windows, 660 * escala_en_linux_windows);             layout.SetText("Quimico: ");            Pango.CairoHelper.ShowLayout(cr, layout);
            cr.MoveTo(300 * escala_en_linux_windows, 670 * escala_en_linux_windows);             layout.SetText(quimicoautorizado);      Pango.CairoHelper.ShowLayout(cr, layout);
            cr.MoveTo(300 * escala_en_linux_windows, 680 * escala_en_linux_windows);             layout.SetText("Ced.Prof. " + cedulaquimico);             Pango.CairoHelper.ShowLayout(cr, layout);

            Gtk.Image image5 = new Gtk.Image();
            image5.Name = "image5";
            //image5.Pixbuf = new Gdk.Pixbuf(System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "osiris.jpg"));
            image5.Pixbuf = new Gdk.Pixbuf("/opt/osiris/bin/firma_quimica.jpg");               // en Linux
            //image5.Pixbuf.ScaleSimple(128, 128, Gdk.InterpType.Bilinear);
            //Gdk.CairoHelper.SetSourcePixbuf(cr,image5.Pixbuf,05,comienzo_linea*escala_en_linux_windows);
            //Gdk.CairoHelper.SetSourcePixbuf(cr,image5.Pixbuf.ScaleSimple(145, 50, Gdk.InterpType.Bilinear),1,1);
            //Gdk.CairoHelper.SetSourcePixbuf(cr,image5.Pixbuf.ScaleSimple(130, 91, Gdk.InterpType.Bilinear),300*escala_en_linux_windows,570*escala_en_linux_windows);
            Gdk.CairoHelper.SetSourcePixbuf(cr, image5.Pixbuf, 300 * escala_en_linux_windows, 570 * escala_en_linux_windows);
            cr.Fill();
            cr.Paint();
            cr.Restore();
        }
Пример #53
0
        public bool OnExpose(Context ctx, Gdk.Rectangle viewport)
        {
            double percent = Math.Min ((DateTime.UtcNow - start).Ticks / (double) duration.Ticks, 1.0);
            frames ++;

            //ctx.Matrix = m;

            SurfacePattern p = new SurfacePattern (buffer.Surface);
            p.Filter = Filter.Fast;
            Matrix m = new Matrix ();
            m.Translate (pan_x * zoom, pan_y * zoom);
            m.Scale (zoom, zoom);
            zoom *= .98;
            p.Matrix = m;
            ctx.Source = p;
            ctx.Paint ();
            p.Destroy ();

            return percent < 1.0;
        }
Пример #54
0
        public Gdk.Pixbuf LoadToPixbuf()
        {
            bool         needsDispose  = false;
            ImageSurface image_surface = (Internal as ImageSurface);

            if (image_surface == null)
            {
                image_surface = new ImageSurface(Format.Argb32, Width, Height);
                using (Cairo.Context cr = new Cairo.Context(image_surface)) {
                    cr.Operator = Operator.Source;
                    cr.SetSource(Internal);
                    cr.Paint();
                }
                needsDispose = true;
            }

            int width  = image_surface.Width;
            int height = image_surface.Height;

            Gdk.Pixbuf pb = new Gdk.Pixbuf(Colorspace.Rgb, true, 8, width, height);
            pb.Fill(0x00000000);

            unsafe {
                byte *data   = (byte *)image_surface.DataPtr;
                byte *pixels = (byte *)pb.Pixels;
                int   length = width * height;

                if (image_surface.Format == Format.Argb32)
                {
                    for (int i = 0; i < length; i++)
                    {
                        // if alpha is 0 set nothing
                        if (data[3] > 0)
                        {
                            pixels[0] = (byte)(data[2] * 255 / data[3]);
                            pixels[1] = (byte)(data[1] * 255 / data[3]);
                            pixels[2] = (byte)(data[0] * 255 / data[3]);
                            pixels[3] = data[3];
                        }

                        pixels += 4;
                        data   += 4;
                    }
                }
                else if (image_surface.Format == Format.Rgb24)
                {
                    for (int i = 0; i < length; i++)
                    {
                        pixels[0] = data[2];
                        pixels[1] = data[1];
                        pixels[2] = data[0];
                        pixels[3] = data[3];

                        pixels += 4;
                        data   += 4;
                    }
                }
            }

            if (needsDispose)
            {
                (image_surface as IDisposable).Dispose();
            }

            return(pb);
        }
Пример #55
0
			protected override bool OnDrawn (Context cr)
			{
				int w, h;
				this.GdkWindow.GetSize (out w, out h);
				var bounds = new Xwt.Rectangle (0.5, 0.5, w - 1, h - 1);
				var black = Xwt.Drawing.Color.FromBytes (0xee, 0xee, 0xee);
				
				// We clear the surface with a transparent color if possible
				if (supportAlpha)
					cr.SetSourceRGBA (1.0, 1.0, 1.0, 0.0);
				else
					cr.SetSourceRGB (1.0, 1.0, 1.0);
				cr.Operator = Operator.Source;
				cr.Paint ();
				
				var calibratedRect = RecalibrateChildRectangle (bounds);
				// Fill it with one round rectangle
				RoundRectangle (cr, calibratedRect, radius);
				cr.LineWidth = 1;
				
				// Triangle
				// We first begin by positionning ourselves at the top-center or bottom center of the previous rectangle
				var arrowX = bounds.Center.X + arrowDelta;
				var arrowY = arrowPosition == Xwt.Popover.Position.Top ? calibratedRect.Top + cr.LineWidth : calibratedRect.Bottom;
				cr.MoveTo (arrowX, arrowY);
				// We draw the rectangle path
				DrawTriangle (cr);

				// We use it
				cr.SetSourceRGBA (black.Red, black.Green, black.Blue, black.Alpha);
				cr.StrokePreserve ();
				cr.SetSourceRGBA (BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, BackgroundColor.A);
				cr.Fill ();

				return base.OnDrawn (cr);
			}
Пример #56
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);

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

            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) {
                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;
            }
            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;

                GraphicObject 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(Color.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(Color.SkyBlue);
                //gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0);
                gr.Rectangle(hr, 0.4 / z);
            }
            gr.Restore();
        }