public override void DrawRect(RectangleF dirtyRect)
            {
                NSGraphicsContext nsgctxt = NSGraphicsContext.CurrentContext;

                nsgctxt.SaveGraphicsState();
                try {
                    var cg = nsgctxt.GraphicsPort;
                    cg.SetFillColor(new CGColor(0.25f, 1f));
                    cg.FillRect(dirtyRect);
                }
                finally {
                    nsgctxt.RestoreGraphicsState();
                }
                base.DrawRect(dirtyRect);
            }
            public override void DrawBackgrounn(RectangleF dirtyRect)
            {
                base.DrawBackgrounn(dirtyRect);
                NSGraphicsContext nsgctxt = NSGraphicsContext.CurrentContext;

                nsgctxt.SaveGraphicsState();
                try {
                    var     cg = nsgctxt.GraphicsPort;
                    float[] comps;
                    this.CustomBackgroundColor.GetComponents(out comps);
                    cg.SetFillColor(comps);
                    cg.FillRect(dirtyRect);
                }
                finally {
                    nsgctxt.RestoreGraphicsState();
                }
                //base.DrawRect (dirtyRect);
            }
Beispiel #3
0
 public void SaveState()
 {
     context.SaveGraphicsState();
 }
Beispiel #4
0
        internal static INativeContex GetCGContextForView(IntPtr handle)
        {
//			IntPtr context = IntPtr.Zero;
            NSView focusWindow = null;
            // JV - je to OK??
            //NSObject whoWrapper = NSObject.Lookup (handle);
            NSObject whoWrapper    = MonoMac.ObjCRuntime.Runtime.GetNSObject(handle);
            NSView   viewWrapper   = whoWrapper as NSView;
            NSWindow windowWrapper = null;

            if (null == viewWrapper)
            {
                windowWrapper = whoWrapper as NSWindow;
            }
            else
            {
                windowWrapper = viewWrapper.Window;
            }

            IntPtr            window = windowWrapper.Handle;
            NSGraphicsContext gcw    = null;

            if (handle == IntPtr.Zero || window == IntPtr.Zero)
            {
                // FIXME: Can we actually get a CGContextRef for the desktop?  this makes context IntPtr.Zero
                gcw = NSApplication.SharedApplication.Context;
//				context = gcw.graphicsPort();

                var desktop_bounds = NSRect.Empty;
                // NSScreen.mainScreen () returns the screen the the user is currently interacting with.
                // To get the screen identified by CGMainDisplayID (), get the 0th element of this array.
                NSScreen[] screens = NSScreen.Screens;

                if (null != screens && 0 < screens.Length)
                {
                    NSScreen screenWrap = screens[0];
                    desktop_bounds = screenWrap.Frame;
                }

                return(new CocoaContext(focusWindow, gcw, (int)desktop_bounds.Width,
                                        (int)desktop_bounds.Height));
            }

            if (null != viewWrapper && viewWrapper != NSView.FocusView())
            {
                if (!viewWrapper.LockFocusIfCanDraw())
                {
                    return(null);
                }

                focusWindow = viewWrapper;
            }

            gcw = windowWrapper.GraphicsContext;
            gcw.SaveGraphicsState();
//			context = gcw.graphicsPort();

//			NSRect winRect = windowWrapper.frame();
//			QDRect window_bounds = new QDRect (winRect.Top, winRect.Left, winRect.Bottom, winRect.Right);

            var vuRect = windowWrapper.Frame;

            if (null != viewWrapper)
            {
                vuRect = viewWrapper.Bounds;
                vuRect = viewWrapper.ConvertRectToView(vuRect, null);
            }
//			Rect view_bounds = new Rect (vuRect.origin.x, vuRect.origin.y, vuRect.size.width, vuRect.size.height);

            if (vuRect.Height < 0)
            {
                vuRect.Height = 0;
            }
            if (vuRect.Width < 0)
            {
                vuRect.Width = 0;
            }

//ASSUMPTION! lockFocus did the translating and clipping.
//ASSUMPTION! The NSView isFlipped.
//			CGContextTranslateCTM (context, view_bounds.origin.x, (window_bounds.bottom - window_bounds.top) - (view_bounds.origin.y + view_bounds.size.height));
//
//			// Create the original rect path and clip to it
//			Rect rc_clip = new Rect (0, 0, view_bounds.size.width, view_bounds.size.height);
//
//
//			Rectangle [] clip_rectangles = (Rectangle []) hwnd_delegate.DynamicInvoke (new object [] {handle});
//			if (clip_rectangles != null && clip_rectangles.Length > 0) {
//				int length = clip_rectangles.Length;
//
//				CGContextBeginPath (context);
//				CGContextAddRect (context, rc_clip);
//
//				for (int i = 0; i < length; i++) {
//					CGContextAddRect (context, new Rect (clip_rectangles [i].X, view_bounds.size.height - clip_rectangles [i].Y - clip_rectangles [i].Height, clip_rectangles [i].Width, clip_rectangles [i].Height));
//				}
//				CGContextClosePath (context);
//				CGContextEOClip (context);
//#if DEBUG_CLIPPING
//				if (clip_rectangles.Length >= debug_threshold) {
//					CGContextSetRGBFillColor (context, red, green, blue, 0.5f);
//					CGContextFillRect (context, rc_clip);
//					CGContextFlush (context);
//					System.Threading.Thread.Sleep (500);
//					if (red == 1.0f) { red = 0.0f; blue = 1.0f; }
//					else if (blue == 1.0f) { blue = 0.0f; green = 1.0f; }
//					else if (green == 1.0f) { green = 0.0f; red = 1.0f; }
//				}
//#endif
//			} else {
//				CGContextBeginPath (context);
//				CGContextAddRect (context, rc_clip);
//				CGContextClosePath (context);
//				CGContextClip (context);
//			}

            return(new CocoaContext(focusWindow, gcw, (int)vuRect.Width, (int)vuRect.Height));
        }
Beispiel #5
0
        public override void DrawRect(NSRect aRect)
        {
            // calculate the number of tick intervals since the hourglass was shown
            NSDate dateNow      = NSDate.DateWithTimeIntervalSinceNow(0);
            double timeElapsed  = dateNow.TimeIntervalSinceReferenceDate - iTimeShown;
            int    numIntervals = (int)(timeElapsed / 0.06);

            // save graphics state for restoring later
            NSGraphicsContext context = NSGraphicsContext.CurrentContext;

            context.SaveGraphicsState();

            // apply transforms to rotate the foreground image
            NSImage bkgd = Properties.Resources.IconHourglass;
            NSImage frgd = Properties.Resources.IconHourglass2;

            NSAffineTransform xform1 = new NSAffineTransform();

            xform1.TranslateXByYBy(Bounds.Width * 0.5f, Bounds.Height * 0.5f);
            xform1.Concat();

            NSAffineTransform xform2 = new NSAffineTransform();

            xform2.RotateByDegrees(-45.0f * (numIntervals % 8));
            xform2.Concat();

            bool scale = Bounds.Width < frgd.Size.width || Bounds.Height < frgd.Size.height;
            NSAffineTransform xform3 = null;

            if (scale)
            {
                float scaleX = Bounds.Width / frgd.Size.width;
                float scaleY = Bounds.Height / frgd.Size.height;
                float ratio  = scaleX > scaleY ? scaleX : scaleY;
                xform3 = new NSAffineTransform();
                xform3.ScaleBy(ratio);
                xform3.Concat();
            }

            NSAffineTransform xform4 = new NSAffineTransform();

            xform4.TranslateXByYBy(-frgd.Size.width * 0.5f, -frgd.Size.height * 0.5f);
            xform4.Concat();


            // draw background and foreground
            bkgd.DrawAtPointFromRectOperationFraction(Bounds.origin, NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f);
            frgd.DrawAtPointFromRectOperationFraction(Bounds.origin, NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f);

            // clean up
            xform1.Release();
            xform2.Release();
            if (scale)
            {
                xform3.Release();
            }
            xform4.Release();
            context.RestoreGraphicsState();

            // schedule another timer event
            this.PerformSelectorWithObjectAfterDelay(ObjectiveCRuntime.Selector("timerUpdate"), null, 0.06);
        }