Example #1
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 ();
        }
		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 #3
0
        private static void Desktop()
        {
            var Data    = new byte[Compositor.PACKET_SIZE];
            var Request = (GuiRequest *)Data.GetDataOffset();

            Request->ClientID = 0;
            Request->Type     = RequestType.NewWindow;

            var Window = (NewWindow *)Request;

            Window->X      = 0;
            Window->Y      = 0;
            Window->Width  = VBE.Xres;
            Window->Height = VBE.Yres;

            Compositor.Server.Write(Data);
            Client.Read(Data);

            string HashCode = new string(Window->Buffer);
            var    aBuffer  = SHM.Obtain(HashCode, 0, false);

            DesktopID = Window->WindowID;

            uint surface = Cairo.ImageSurfaceCreateForData(Window->Width * 4, Window->Height, Window->Width, ColorFormat.ARGB32, aBuffer);
            uint context = Cairo.Create(surface);

            uint wallpaper = Cairo.ImageSurfaceFromPng(Marshal.C_String("disk0/wallpaper.png"));

            Cairo.SetSourceSurface(0, 0, wallpaper, context);
            Cairo.Paint(context);
            Cairo.SurfaceDestroy(wallpaper);

            Request->Type = RequestType.Redraw;
            var Redraw = (Redraw *)Request;

            Redraw->WindowID = DesktopID;
            Redraw->X        = 0;
            Redraw->Y        = 0;
            Redraw->Width    = VBE.Xres;
            Redraw->Height   = VBE.Yres;
            Compositor.Server.Write(Data);

            DesktopSurface = surface;
            DesktopContext = context;
            Heap.Free(Data);
        }
Example #4
0
		// Used by the workspace drawing area expose render loop.
		// Takes care of the clipping.
		public void RenderLivePreviewLayer (Cairo.Context ctx, double opacity)
		{
			if (!IsEnabled)
				throw new InvalidOperationException ("Tried to render a live preview after live preview has ended.");
						
			// TODO remove seam around selection during live preview.
			
			ctx.Save ();
			if (selection_path != null) {
				
				// Paint area outsize of the selection path, with the pre-effect image.
				var imageSize = PintaCore.Workspace.ImageSize;
				ctx.Rectangle (0, 0, imageSize.Width, imageSize.Height);
				ctx.AppendPath (selection_path);
				ctx.Clip ();
				ctx.SetSourceSurface (layer.Surface, (int)layer.Offset.X, (int)layer.Offset.Y);
				ctx.PaintWithAlpha (opacity);
				ctx.ResetClip ();
				
				// Paint area inside the selection path, with the post-effect image.
				ctx.AppendPath (selection_path);
				ctx.Clip ();
				
				ctx.SetSourceSurface (live_preview_surface, (int)layer.Offset.X, (int)layer.Offset.Y);
				ctx.PaintWithAlpha (opacity);
				
				ctx.AppendPath (selection_path);
				ctx.FillRule = Cairo.FillRule.EvenOdd;
				ctx.Clip ();			
			} else {
				
				ctx.SetSourceSurface (live_preview_surface, (int)layer.Offset.X, (int)layer.Offset.Y);
				ctx.PaintWithAlpha (opacity);				
			}
			ctx.Restore ();
		}
Example #5
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);
		}
 public void Render(Cairo.Context context, int x, int y, int width, int height)
 {
     // scale and draw moodbar
     double scaled_width = (width) / 1000.0;
     context.Save ();
     context.Scale (scaled_width, height * 2);
     context.SetSourceSurface (Surface, (int)(x / scaled_width), y);
     context.Paint ();
     context.Restore ();
 }
		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 ();
			}
		}
		/// TODO: CairoExtensions.CachedDraw seems not to work correctly for me.
		public static void CachedDraw (Cairo.Context self, ref SurfaceWrapper surface, Gdk.Rectangle region, object parameters = null, float opacity = 1.0f, Action<Cairo.Context, float> draw = null, double? forceScale = null)
		{
			double displayScale = forceScale.HasValue ? forceScale.Value : QuartzSurface.GetRetinaScale (self);
			int targetWidth = (int) (region.Width * displayScale);
			int targetHeight = (int) (region.Height * displayScale);

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


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

			self.SetSourceSurface (surface.Surface, 0, 0);
			self.Paint ();
		}
Example #9
0
        private static unsafe void Renderer()
        {
            int tmp_mouse_X, tmp_mouse_Y;
            int old_mouse_X = -1, old_mouse_Y = -1;

            bool update;

            while (true)
            {
                tmp_mouse_X = Mouse_X;
                tmp_mouse_Y = Mouse_Y;
                update      = false;

                Cairo.Save(MainContext);
                Cairo.Save(VideoContext);

                if (tmp_mouse_X != old_mouse_X || tmp_mouse_Y != old_mouse_Y)
                {
                    update = true;
                    Cairo.Rectangle(32, 32, old_mouse_Y, old_mouse_X, MainContext);
                    Cairo.Rectangle(32, 32, old_mouse_Y, old_mouse_X, VideoContext);
                    Cairo.Rectangle(32, 32, tmp_mouse_Y, tmp_mouse_X, VideoContext);
                }

                old_mouse_X = tmp_mouse_X;
                old_mouse_Y = tmp_mouse_Y;

                var queue = RedrawRects;
                Monitor.AcquireLock(ref RedrawRectsLock);
                while (queue.Count > 0)
                {
                    var rect = (Rect *)queue.Dequeue();

                    Cairo.Rectangle(rect->Height, rect->Width, rect->Y, rect->X, MainContext);
                    Cairo.Rectangle(rect->Height, rect->Width, rect->Y, rect->X, VideoContext);

                    Libc.free((uint)rect);

                    update = true;
                }
                Monitor.ReleaseLock(ref RedrawRectsLock);

                if (update)
                {
                    Cairo.Clip(MainContext);
                    var list = Stacking;
                    Monitor.AcquireLock(ref StackingLock);
                    int count = list.Count;
                    for (int index = 0; index < count; index++)
                    {
                        var win = list[index];
                        Cairo.Save(MainContext);
                        Cairo.Translate(win.Y, win.X, MainContext);
                        Cairo.SetSourceSurface(0, 0, win.Surface, MainContext);
                        Cairo.Paint(MainContext);
                        Cairo.Restore(MainContext);
                    }
                    Monitor.ReleaseLock(ref StackingLock);
                }

                if (update)
                {
                    Cairo.Clip(VideoContext);

                    Cairo.Translate(0, 0, VideoContext);
                    Cairo.SetOperator(Operator.Source, VideoContext);
                    Cairo.SetSourceSurface(0, 0, MainSurface, VideoContext);
                    Cairo.Paint(VideoContext);

                    Cairo.Translate(old_mouse_Y, old_mouse_X, VideoContext);
                    Cairo.SetOperator(Operator.Over, VideoContext);
                    Cairo.SetSourceSurface(0, 0, MouseSurface, VideoContext);
                    Cairo.Paint(VideoContext);
                }

                Cairo.Restore(MainContext);
                Cairo.Restore(VideoContext);

                Task.Switch();
            }
        }
Example #10
0
		protected override bool OnDrawn (Cairo.Context ctx)
		{
			ctx.SetSourceSurface (surface, 0, 0);
			ctx.Paint ();
			return false;
		}