protected override void OnRender (Cairo.Context context)
		{
			if (surfaceCache == null) {
				// will improve with CGLayer surfaces
				surfaceCache = new SurfaceWrapper (context, pbuf);
			}
			int x = (int)((Width - pbuf.Width) * XAlign);
			int y = (int)((Height - pbuf.Height) * YAlign);
			context.SetSourceSurface (surfaceCache.Surface, x, y);
			double opacity = Opacity;
			if (opacity == 1)
				context.Paint ();
			else
				context.PaintWithAlpha (Opacity);

			base.OnRender (context);
		}
Example #2
0
		// Used by the workspace drawing area expose render loop.
		// Takes care of the clipping.
		public void RenderLivePreviewLayer (Cairo.Context ctx, double opacity)
		{
			if (!IsEnabled)
				throw new InvalidOperationException ("Tried to render a live preview after live preview has ended.");
						
			// TODO remove seam around selection during live preview.
			
			ctx.Save ();
			if (selection_path != null) {
				
				// Paint area outsize of the selection path, with the pre-effect image.
				var imageSize = PintaCore.Workspace.ImageSize;
				ctx.Rectangle (0, 0, imageSize.Width, imageSize.Height);
				ctx.AppendPath (selection_path);
				ctx.Clip ();
				layer.Draw(ctx, layer.Surface, opacity);
				ctx.ResetClip ();
				
				// Paint area inside the selection path, with the post-effect image.
				ctx.AppendPath (selection_path);
				ctx.Clip ();
				
				layer.Draw(ctx, live_preview_surface, opacity);
				ctx.PaintWithAlpha (opacity);
				
				ctx.AppendPath (selection_path);
				ctx.FillRule = Cairo.FillRule.EvenOdd;
				ctx.Clip ();			
			} else {
				
				layer.Draw(ctx, live_preview_surface, opacity);
			}
			ctx.Restore ();
		}
Example #3
0
        private void RenderAnimation(Cairo.Context cr)
        {
            if (stage.Actor == null) {
                // We are not in a transition, just render
                RenderStage (cr, current_track, current_image);
                return;
            }

            if (current_track == null) {
                // Fade in the whole stage, nothing to fade out
                CairoExtensions.PushGroup (cr);
                RenderStage (cr, incoming_track, incoming_image);
                CairoExtensions.PopGroupToSource (cr);

                cr.PaintWithAlpha (stage.Actor.Percent);
                return;
            }

            // Draw the old cover art more and more translucent
            CairoExtensions.PushGroup (cr);
            RenderCoverArt (cr, current_image);
            CairoExtensions.PopGroupToSource (cr);
            cr.PaintWithAlpha (1.0 - stage.Actor.Percent);

            // Draw the new cover art more and more opaque
            CairoExtensions.PushGroup (cr);
            RenderCoverArt (cr, incoming_image);
            CairoExtensions.PopGroupToSource (cr);
            cr.PaintWithAlpha (stage.Actor.Percent);

            bool same_artist_album = incoming_track != null ? incoming_track.ArtistAlbumEqual (current_track) : false;
            bool same_track = incoming_track != null ? incoming_track.Equals (current_track) : false;

            if (same_artist_album) {
                RenderTrackInfo (cr, incoming_track, same_track, true);
            }

            // Don't xfade the text since it'll look bad (overlapping words); instead, fade
            // the old out, and then the new in
            if (stage.Actor.Percent <= 0.5) {
                // Fade out old text
                CairoExtensions.PushGroup (cr);
                RenderTrackInfo (cr, current_track, !same_track, !same_artist_album);
                CairoExtensions.PopGroupToSource (cr);

                cr.PaintWithAlpha (1.0 - (stage.Actor.Percent * 2.0));
            } else {
                // Fade in new text
                CairoExtensions.PushGroup (cr);
                RenderTrackInfo (cr, incoming_track, !same_track, !same_artist_album);
                CairoExtensions.PopGroupToSource (cr);

                cr.PaintWithAlpha ((stage.Actor.Percent - 0.5) * 2.0);
            }
        }
Example #4
0
		void DrawPixbuf (Cairo.Context ctx, Gdk.Pixbuf img, double x, double y, ImageDescription idesc)
		{
			ctx.Save ();
			ctx.Translate (x, y);
			ctx.Scale (idesc.Size.Width / (double)img.Width, idesc.Size.Height / (double)img.Height);
			Gdk.CairoHelper.SetSourcePixbuf (ctx, img, 0, 0);

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

			if (idesc.Alpha >= 1)
				ctx.Paint ();
			else
				ctx.PaintWithAlpha (idesc.Alpha);
			ctx.Restore ();
		}
Example #5
0
 void DrawPixbuf(Cairo.Context ctx, Gdk.Pixbuf img, double x, double y, ImageDescription idesc)
 {
     ctx.Save ();
     ctx.Translate (x, y);
     ctx.Scale (idesc.Size.Width / (double)img.Width, idesc.Size.Height / (double)img.Height);
     Gdk.CairoHelper.SetSourcePixbuf (ctx, img, 0, 0);
     if (idesc.Alpha == 1)
         ctx.Paint ();
     else
         ctx.PaintWithAlpha (idesc.Alpha);
     ctx.Restore ();
 }
Example #6
0
		void RenderIcon (Cairo.Context context, SurfaceWrapper surface, double opacity)
		{
			context.SetSourceSurface (surface.Surface, 
			                          Allocation.X + (Allocation.Width - surface.Width) / 2,
			                          Allocation.Y + (Allocation.Height - surface.Height) / 2);

			context.PaintWithAlpha (opacity);
		}
		void RenderPreview (Cairo.Context context, Gdk.Point position, double opacity)
		{
			if (brandedIcon != null) {
				if (previewSurface == null) {
					previewSurface = new SurfaceWrapper (context, brandedIcon);
				}
				double scale = PreviewSize / previewSurface.Width;

				context.Save ();
				context.Translate (position.X, position.Y);
				context.Scale (scale * IconScale, scale * IconScale);
				context.SetSourceSurface (previewSurface.Surface, -previewSurface.Width / 2, -previewSurface.Height / 2);
				context.PaintWithAlpha (opacity);
				context.Restore ();
			}
		}
		/// <summary>
		/// Paints an overview of the forecast including high/low temps and a condition icon.
		/// </summary>
		/// <param name="cr">
		/// A <see cref="Cairo.Context"/> to do the painting.
		/// </param>
		void DrawVertForecast (Cairo.Context cr)
		{
			int cellHeight = (int) ((Allocation.Height - BUTTON_SIZE) / WeatherController.Weather.ForecastDays / 1.5);
			double xOffset = 0;
			double yOffset = cellHeight / 4.0;
			
			using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {
				Pango.Rectangle inkRect, logicalRect;
				
				layout.FontDescription = new Gtk.Style().FontDescription;
				layout.FontDescription.Weight = Pango.Weight.Bold;
				layout.Ellipsize = Pango.EllipsizeMode.None;
				layout.Width = Pango.Units.FromPixels (cellHeight);
				
				for (int day = 0; day < WeatherController.Weather.ForecastDays; day++) {
					layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellHeight / 5));
					
					cr.Color = colorTitle;
					layout.SetText (string.Format ("{0}", WeatherForecast.DayShortName (WeatherController.Weather.Forecasts [day].dow)));
					layout.GetPixelExtents (out inkRect, out logicalRect);
					cr.MoveTo (xOffset + (cellHeight - inkRect.Width) / 2, yOffset);
					Pango.CairoHelper.LayoutPath (cr, layout);
					cr.Fill ();
					
					cr.Color = colorHigh;
					layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].high, AbstractWeatherSource.TempUnit));
					layout.GetPixelExtents (out inkRect, out logicalRect);
					cr.MoveTo (xOffset + (cellHeight - inkRect.Width) / 2, yOffset + (cellHeight - logicalRect.Height) / 2);
					Pango.CairoHelper.LayoutPath (cr, layout);
					cr.Fill ();
					
					cr.Color = colorLow;
					layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].low, AbstractWeatherSource.TempUnit));
					layout.GetPixelExtents (out inkRect, out logicalRect);
					cr.MoveTo (xOffset + (cellHeight - inkRect.Width) / 2, yOffset + cellHeight - logicalRect.Height);
					Pango.CairoHelper.LayoutPath (cr, layout);
					cr.Fill ();
					
					using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon (WeatherController.Weather.Forecasts [day].image, cellHeight - 5)) {
						Gdk.CairoHelper.SetSourcePixbuf (cr, pbuf, xOffset + 5 + cellHeight, yOffset + 2);
						cr.PaintWithAlpha (WeatherController.Weather.Forecasts [day].chanceOf ? .6 : 1);
					}
					
					if (WeatherController.Weather.Forecasts [day].chanceOf) {
						layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellHeight / 2));
						
						layout.SetText ("?");
						
						layout.GetPixelExtents (out inkRect, out logicalRect);
						cr.MoveTo (xOffset + cellHeight + (cellHeight - inkRect.Width) / 2, yOffset + (cellHeight - logicalRect.Height) / 2);
						
						cr.LineWidth = 4;
						cr.Color = new Cairo.Color (0, 0, 0, 0.3);
						Pango.CairoHelper.LayoutPath (cr, layout);
						cr.StrokePreserve ();
						
						cr.Color = new Cairo.Color (1, 1, 1, .6);
						cr.Fill ();
					}
					
					yOffset += (int) (1.5 * cellHeight);
				}
				
				layout.FontDescription.Dispose ();
				layout.Context.Dispose ();
			}
		}
Example #9
0
        void DrawPixbuf(Cairo.Context ctx, Gdk.Pixbuf img, double x, double y, ImageDescription idesc)
        {
            ctx.Save ();
            ctx.Translate (x, y);
            ctx.Scale (idesc.Size.Width / (double)img.Width, idesc.Size.Height / (double)img.Height);
            Gdk.CairoHelper.SetSourcePixbuf (ctx, img, 0, 0);

            // Fixes blur issue when rendering on an image surface
            ((Cairo.SurfacePattern)ctx.GetSource ()).Filter = Cairo.Filter.Fast;

            if (idesc.Alpha >= 1)
                ctx.Paint ();
            else
                ctx.PaintWithAlpha (idesc.Alpha);
            ctx.Restore ();
        }