public GraphicsHandler(NSView view)
		{
			this.view = view;
			graphicsContext = NSGraphicsContext.FromWindow(view.Window);
			graphicsContext = graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true);
			disposeContext = true;
			Control = graphicsContext.GraphicsPort;

			view.PostsFrameChangedNotifications = true;
			AddObserver(NSView.FrameChangedNotification, FrameDidChange, view);

			// if control is in a scrollview, we need to trap when it's scrolled as well
			var parent = view.Superview;
			while (parent != null)
			{
				var scroll = parent as NSScrollView;
				if (scroll != null)
				{
					scroll.ContentView.PostsBoundsChangedNotifications = true;
					AddObserver(NSView.BoundsChangedNotification, FrameDidChange, scroll.ContentView);
				}
				parent = parent.Superview;
			}

			SetDefaults();
			InitializeContext(view.IsFlipped);
		}
 public override CGImage AsCGImage(ref RectangleF proposedDestRect, NSGraphicsContext referenceContext, NSDictionary hints)
 {
     return base.AsCGImage (ref proposedDestRect, referenceContext, hints);
 }
        private Graphics(NSGraphicsContext context)
        {
            var gc = context;

            if (gc.IsFlipped)
                gc = NSGraphicsContext.FromGraphicsPort (gc.GraphicsPort, false);

            // testing for now
            //			var attribs = gc.Attributes;
            //			attribs = NSScreen.MainScreen.DeviceDescription;
            //			NSValue asdf = (NSValue)attribs["NSDeviceResolution"];
            //			var size = asdf.SizeFValue;
            // ----------------------
            screenScale = 1;
            nativeObject = gc;

            isFlipped = gc.IsFlipped;

            InitializeContext(gc.GraphicsPort);
        }
 public static Graphics FromContext(NSGraphicsContext context)
 {
     return new Graphics (context);
 }
Exemple #5
0
		public void CreateFromImage(Bitmap image)
		{
			var handler = image.Handler as BitmapHandler;
			SourceImage = image;
#if OSX
			var rep = handler.Control.Representations().OfType<NSBitmapImageRep>().FirstOrDefault();
			if (rep.BitsPerPixel != 32)
			{
				// CoreGraphics only supports drawing to 32bpp, create a new 32-bpp image and copy back when disposed or flushed.
				DrawingImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRgb);
				handler = DrawingImage.Handler as BitmapHandler;
				rep = handler.Control.Representations().OfType<NSBitmapImageRep>().FirstOrDefault();
			}
			graphicsContext = NSGraphicsContext.FromBitmap(rep);

			graphicsContext = graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true);
			disposeContext = true;
			Control = graphicsContext.GraphicsPort;
			PointsPerPixel = (float)(rep.PixelsWide / handler.Control.Size.Width);
#elif IOS
			var cgimage = handler.Control.CGImage;
			Control = new CGBitmapContext(handler.Data.MutableBytes, cgimage.Width, cgimage.Height, cgimage.BitsPerComponent, cgimage.BytesPerRow, cgimage.ColorSpace, cgimage.BitmapInfo);
			PointsPerPixel = (float)(cgimage.Width / handler.Control.Size.Width);
#endif

			height = image.Size.Height;
			SetDefaults();
			InitializeContext(true);
			if (DrawingImage != null && SourceImage != null)
			{
				// draw source image onto context, when source is incompatible for CoreGraphics drawing.
				DrawImage(SourceImage, 0, 0);
			}
		}
Exemple #6
0
		public GraphicsHandler(NSView view, NSGraphicsContext graphicsContext, float height, bool flipped)
		{
			DisplayView = view;
			this.height = height;
			this.graphicsContext = flipped != graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true);
			Control = this.graphicsContext.GraphicsPort;
			SetDefaults();
			InitializeContext(!flipped);
		}
Exemple #7
0
			public override CGImage AsCGImage(ref CGRect proposedDestRect, NSGraphicsContext context, NSDictionary hints)
			{
				return Rep.AsCGImage(ref proposedDestRect, context, hints);
			}
Exemple #8
0
		public void CreateFromImage(Bitmap image)
		{
			var handler = image.Handler as BitmapHandler;
#if OSX
			var rep = handler.Control.Representations().OfType<NSBitmapImageRep>().FirstOrDefault();
			graphicsContext = NSGraphicsContext.FromBitmap(rep);
			graphicsContext = graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true);
			disposeContext = true;
			Control = graphicsContext.GraphicsPort;
			scale = (float)(rep.PixelsWide / handler.Control.Size.Width);
#elif IOS
			var cgimage = handler.Control.CGImage;
			Control = new CGBitmapContext(handler.Data.MutableBytes, cgimage.Width, cgimage.Height, cgimage.BitsPerComponent, cgimage.BytesPerRow, cgimage.ColorSpace, cgimage.BitmapInfo);
			scale = cgimage.Width / handler.Control.Size.Width;
#endif

			height = image.Size.Height;
			SetDefaults();
			InitializeContext(true);
		}