// Client switches menu screen public void NSCSMS() { NSScreen oldScreen = CurrentScreen; NSScreen newScreen = (NSScreen)ez.Read1(); if (newScreen == NSScreen.Lobby) { CurrentRoom = null; SendRoomList(); SendRoomPlayers(); } else if (newScreen == NSScreen.Room) { List <User> users = CurrentRoom.Users; // find people waiting for synchronization List <User> usersToSendPacketTo = new List <User>(); foreach (User user in users) { if (user.SyncNeeded) { usersToSendPacketTo.Add(user); } } // send packet those people SendSongStartTo(usersToSendPacketTo.ToArray()); } CurrentScreen = newScreen; }
private static void PlatformSetPosition(int x, int y) { PrimaryWindow.MouseState.X = x; PrimaryWindow.MouseState.Y = y; var mousePt = NSEvent.CurrentMouseLocation; NSScreen currentScreen = null; foreach (var screen in NSScreen.Screens) { if (screen.Frame.Contains(mousePt)) { currentScreen = screen; break; } } var point = new PointF(x, Window.ClientBounds.Height - y); var windowPt = Window.ConvertPointToView(point, null); var screenPt = Window.Window.ConvertBaseToScreen(windowPt); var flippedPt = new PointF(screenPt.X, currentScreen.Frame.Size.Height - screenPt.Y); flippedPt.Y += currentScreen.Frame.Location.Y; CGSetLocalEventsSuppressionInterval(0.0); CGWarpMouseCursorPosition(flippedPt); CGSetLocalEventsSuppressionInterval(0.25); }
public void ShowAboutPanel(Foundation.NSObject sender) { // The strict chap 12 challenge solution. non-modal, no window controller for the about panel // so multiple about panels can be displayed // NSBundle.LoadNib("About", this); // aboutPanel.MakeKeyAndOrderFront(null); // Make about panel modal and position it in the center of the active window NSBundle.LoadNib("About", this); // Change BG color and posiiton aboutPanel.BackgroundColor = NSColor.White; if (NSApplication.SharedApplication.MainWindow != null) { var mainWindowFrame = NSApplication.SharedApplication.MainWindow.Frame; nfloat x = mainWindowFrame.X + mainWindowFrame.Width / 2 - aboutPanel.Frame.Width / 2; nfloat y = mainWindowFrame.Y + mainWindowFrame.Height / 2 - aboutPanel.Frame.Height / 2; aboutPanel.SetFrame(new CGRect(x, y, aboutPanel.Frame.Width, aboutPanel.Frame.Height), true); } else { NSScreen screen = NSScreen.MainScreen; aboutPanel.SetFrame(new CGRect(screen.Frame.Width / 2 - aboutPanel.Frame.Width / 2, screen.Frame.Height - aboutPanel.Frame.Height - 100, aboutPanel.Frame.Width, aboutPanel.Frame.Height), true); } // Stop modal when about panel closed. aboutPanel.WillClose += (object s, EventArgs e) => { Console.WriteLine("Window will close"); NSApplication.SharedApplication.StopModal(); }; // Show modal about panel NSApplication.SharedApplication.RunModalForWindow(aboutPanel); }
public override void WillFinishLaunching(NSNotification notification) { //NSWindow window = NSApplication. NSScreen screen = NSScreen.MainScreen; double Setheight = screen.Frame.Height * 0.7; double Setwidth = screen.Frame.Width * 0.8; NSApplication.SharedApplication.MainWindow.SetFrame(new CGRect(0, 0, Setwidth, Setheight), true); NSApplication.SharedApplication.MainWindow.Center(); }
public void MainScreenNotMainThread() { var called = new AutoResetEvent(false); NSScreen main = null; var backgroundThread = new Thread(() => { main = NSScreen.MainScreen; called.Set(); }); backgroundThread.Start(); Assert.IsTrue(called.WaitOne(1000), "called"); Assert.IsNotNull(main, "main screen"); }
private void StatusItemClicked(NSObject aSender) { if (iMainWindow.Window.IsVisible) { iXappController.MainPage.TrackPageVisibilityChange(false); // the window is already visible - another click hides it iMainWindow.Window.OrderOut(this); return; } // must set the application to be activated so it receives messages NSApplication.SharedApplication.ActivateIgnoringOtherApps(true); // position the window RectangleF statusItemFrame = NSApplication.SharedApplication.CurrentEvent.Window.Frame; RectangleF mainWindowFrame = iMainWindow.Window.Frame; // set the vertical position of the window - simple as menu bar is always at the top mainWindowFrame.Y = statusItemFrame.Y - mainWindowFrame.Height; // determine whether the window should be left or right justified wrt the status item NSScreen screen = NSApplication.SharedApplication.CurrentEvent.Window.Screen; if (screen != null) { if (statusItemFrame.Left + mainWindowFrame.Width < screen.Frame.Right) { // aligning the left edge of the main window with the left edge of the status item fits on screen mainWindowFrame.X = statusItemFrame.X; } else { // aligning the left edge of the main window with the left edge of the status item does not fit on screen // so it their right edges need to be aligned mainWindowFrame.X = statusItemFrame.Right - mainWindowFrame.Width; } } else { // don't know screen width - just align left edges mainWindowFrame.X = statusItemFrame.X; } iMainWindow.Window.SetFrame(mainWindowFrame, true); // show the window iMainWindow.ShowWindow(this); iMainWindow.Window.MakeKeyAndOrderFront(this); iXappController.MainPage.TrackPageVisibilityChange(true); }
CGRect screenResolution() { CGRect screenRect = new CGRect(0, 0, 0, 0); NSScreen[] screenArray = NSScreen.Screens; int screenCount = screenArray.Length; for (int index = 0; index < screenCount; index++) { NSScreen screen = screenArray[index]; screenRect = screen.VisibleFrame; } return(screenRect); }
public static CGSize DeviceDPI(this NSScreen screen) { var desc = screen.DeviceDescription; if (desc != null) { if (desc["NSDeviceResolution"] is NSValue value) { return(value.CGSizeValue); } } Debug.Assert(false, $"Failed to get screen resolution for '{screen.LocalizedName}'"); return(new CGSize(72, 72)); }
// UserInterface ui; public UserInterfaceWindow(UserInterface ui, RectangleF frame, NSScreen screen) : base(frame, NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable, NSBackingStore.Buffered, false, screen) { // this.ui = ui; var view = ui.View as NSView; if (view != null) { this.ContentView = view; } }
/// <summary> /// Sets mouse cursor's relative position to game-window. /// </summary> /// <param name="x">Relative horizontal position of the cursor.</param> /// <param name="y">Relative vertical position of the cursor.</param> public static void SetPosition(int x, int y) { UpdateStatePosition(x, y); #if (WINDOWS && DIRECTX) || DESKTOPGL || ANGLE // correcting the coordinate system // Only way to set the mouse position !!! var pt = Window.PointToScreen(new System.Drawing.Point(x, y)); #elif WINDOWS var pt = new System.Drawing.Point(0, 0); #endif #if DESKTOPGL || ANGLE OpenTK.Input.Mouse.SetPosition(pt.X, pt.Y); #elif WINDOWS SetCursorPos(pt.X, pt.Y); #elif MONOMAC var mousePt = NSEvent.CurrentMouseLocation; NSScreen currentScreen = null; foreach (var screen in NSScreen.Screens) { if (screen.Frame.Contains(mousePt)) { currentScreen = screen; break; } } var point = new PointF(x, Window.ClientBounds.Height - y); var windowPt = Window.ConvertPointToView(point, null); var screenPt = Window.Window.ConvertBaseToScreen(windowPt); var flippedPt = new PointF(screenPt.X, currentScreen.Frame.Size.Height - screenPt.Y); flippedPt.Y += currentScreen.Frame.Location.Y; CGSetLocalEventsSuppressionInterval(0.0); CGWarpMouseCursorPosition(flippedPt); CGSetLocalEventsSuppressionInterval(0.25); #elif WEB PrimaryWindow.MouseState.X = x; PrimaryWindow.MouseState.Y = y; #endif }
public override Xwt.Rectangle GetUsableMonitorGeometry(int screenNumber, int monitorNumber) { var screen = Gdk.Display.Default.GetScreen(screenNumber); Gdk.Rectangle ygeometry = screen.GetMonitorGeometry(monitorNumber); Gdk.Rectangle xgeometry = screen.GetMonitorGeometry(0); NSScreen nss = NSScreen.Screens[monitorNumber]; var visible = nss.VisibleFrame; var frame = nss.Frame; // Note: Frame and VisibleFrame rectangles are relative to monitor 0, but we need absolute // coordinates. visible.X += xgeometry.X; frame.X += xgeometry.X; // VisibleFrame.Y is the height of the Dock if it is at the bottom of the screen, so in order // to get the menu height, we just figure out the difference between the visibleFrame height // and the actual frame height, then subtract the Dock height. // // We need to swap the Y offset with the menu height because our callers expect the Y offset // to be from the top of the screen, not from the bottom of the screen. nfloat x, y, width, height; if (visible.Height <= frame.Height) { var dockHeight = visible.Y - frame.Y; var menubarHeight = (frame.Height - visible.Height) - dockHeight; height = frame.Height - menubarHeight - dockHeight; y = ygeometry.Y + menubarHeight; } else { height = frame.Height; y = ygeometry.Y; } // Takes care of the possibility of the Dock being positioned on the left or right edge of the screen. width = NMath.Min(visible.Width, frame.Width); x = NMath.Max(visible.X, frame.X); return(new Xwt.Rectangle((int)x, (int)y, (int)width, (int)height)); }
public override Gdk.Rectangle GetUsableMonitorGeometry(Gdk.Screen screen, int monitor_id) { Gdk.Rectangle geometry = screen.GetMonitorGeometry(0); NSScreen monitor = NSScreen.Screens[monitor_id]; RectangleF visible = monitor.VisibleFrame; RectangleF frame = monitor.Frame; // Note: Frame and VisibleFrame rectangles are relative to monitor 0, but we need absolute // coordinates. visible.X += geometry.X; visible.Y += geometry.Y; frame.X += geometry.X; frame.Y += geometry.Y; // VisibleFrame.Y is the height of the Dock if it is at the bottom of the screen, so in order // to get the menu height, we just figure out the difference between the visibleFrame height // and the actual frame height, then subtract the Dock height. // // We need to swap the Y offset with the menu height because our callers expect the Y offset // to be from the top of the screen, not from the bottom of the screen. float x, y, width, height; if (visible.Height <= frame.Height) { float dockHeight = visible.Y; float menubarHeight = (frame.Height - visible.Height) - dockHeight; height = frame.Height - menubarHeight - dockHeight; y = menubarHeight; } else { height = frame.Height; y = frame.Y; } // Takes care of the possibility of the Dock being positioned on the left or right edge of the screen. width = Math.Min(visible.Width, frame.Width); x = Math.Max(visible.X, frame.X); return(new Gdk.Rectangle((int)x, (int)y, (int)width, (int)height)); }
public void DeepScreenNotMainThread() { var called = new AutoResetEvent(false); NSScreen deepScreen = null; var screenCount = 0; var backgroundThread = new Thread(() => { screenCount = NSScreen.Screens.Length; deepScreen = NSScreen.DeepestScreen; called.Set(); }); backgroundThread.Start(); Assert.IsTrue(called.WaitOne(1000), "called"); if (screenCount > 1) { Assert.IsNotNull(deepScreen, "deep screen"); } else { Assert.Inconclusive("Only one screen detected."); } }
public void NSCSMS() { NSScreen oldScreen = CurrentScreen; NSScreen newScreen = (NSScreen)ez.Read1(); if (newScreen == NSScreen.Lobby) { CurrentRoom = null; SendRoomList(); SendRoomPlayers(); } CurrentScreen = newScreen; }
// Client switches menu screen public void NSCSMS() { NSScreen oldScreen = CurrentScreen; NSScreen newScreen = (NSScreen)ez.Read1(); if (newScreen == NSScreen.Lobby) { CurrentRoom = null; SendRoomList(); SendRoomPlayers(); } else if (newScreen == NSScreen.Room) { List<User> users = CurrentRoom.Users; // find people waiting for synchronization List<User> usersToSendPacketTo = new List<User>(); foreach (User user in users) { if (user.SyncNeeded) { usersToSendPacketTo.Add(user); } } // send packet those people SendSongStartTo(usersToSendPacketTo.ToArray()); } CurrentScreen = newScreen; }
public static byte[] grabScreenAsPNG(CGPoint containing) { // Grab screen // Mac stuff from http://stackoverflow.com/questions/18851247/screen-capture-on-osx-using-monomac NSScreen screen = NSScreen.MainScreen; if ((containing.X >= 0) && (containing.Y >= 0)) { int idx = 0; bool found = false; while (!found && (idx < NSScreen.Screens.Length)) { if (NSScreen.Screens[idx].Frame.Contains(containing)) { found = true; screen = NSScreen.Screens[idx]; } idx++; } } //System.Drawing.RectangleF bounds = new RectangleF(0,0,screen.Frame.GetMaxX(),screen.Frame.GetMaxY()); CGRect bounds = new CGRect((float)screen.Frame.GetMinX(), (float)screen.Frame.GetMinY(), (float)screen.Frame.GetMaxX(), (float)screen.Frame.GetMaxY()); //System.Drawing.Image si2; //NSImage si2; // CGImage screenImage = MonoMac.CoreGraphics.CGImage.ScreenImage(0,bounds); screenImage = ScreenImage2(0, bounds, CGWindowListOption.All, CGWindowImageOption.Default); #pragma warning disable XS0001 // Find usages of mono todo items /*using(NSBitmapImageRep imageRep = new NSBitmapImageRep(screenImage)) * { * NSDictionary properties = NSDictionary.FromObjectAndKey(new NSNumber(1.0), new NSString("NSImageCompressionFactor")); * using(NSData tiffData = imageRep.RepresentationUsingTypeProperties(NSBitmapImageFileType.Png, properties)) * { * * using (var ms = new MemoryStream()) * * { * tiffData.AsStream().CopyTo(ms); * si2 = NSImage.FromStream(ms); * //si2 = System.Drawing.Image.FromStream (ms, true); * } * } * }*/ NSBitmapImageRep si2 = new NSBitmapImageRep(screenImage); int newHeight = (int)((si2.Size.Height * imgWidth) / si2.Size.Width); CGSize destSize = new CGSize(imgWidth, newHeight); NSImage resized2 = new NSImage(destSize); resized2.LockFocus(); CGRect sz = new CGRect(0, 0, imgWidth, newHeight); //si2.DrawInRect(sz, new CGRect(0, 0, si2.Size.Width, si2.Size.Height), NSCompositingOperation.SourceOver, 1); si2.DrawInRect(sz); resized2.UnlockFocus(); resized2.Size = destSize; //Bitmap resized = new Bitmap(imgWidth, newHeight, PixelFormat.Format24bppRgb); //Graphics g = Graphics.FromImage (resized); //g.DrawImage (si2, 0, 0, imgWidth, newHeight); NSBitmapImageRep newRep = new NSBitmapImageRep(resized2.AsCGImage(ref sz, null, null)); NSData pngData = newRep.RepresentationUsingTypeProperties(NSBitmapImageFileType.Png); screenImage.Dispose(); byte[] result = null; result = pngData.ToArray(); //using (MemoryStream stream = new MemoryStream()) //{ // // // resized.Save(stream, ImageFormat.Png); // result = stream.ToArray(); //} return(result); }
public static CGPoint GdkPointForNSScreen (NSScreen screen) { return screenToGdk [screen]; }
public static CGPoint GdkPointForNSScreen(NSScreen screen) { return(screenToGdk [screen]); }
public void NSCSMS() { NSScreen oldScreen = CurrentScreen; NSScreen newScreen = (NSScreen)ez.Read1(); User[] lobbyusers = GetUsersInRoom(); foreach(User lobbyuser in lobbyusers) { lobbyuser.SendRoomList(); lobbyuser.SendRoomPlayers(); } if (newScreen == NSScreen.Lobby) { CurrentRoom = null; CurrentRoomRights = RoomRights.Player; CurrentScreen = newScreen; User[] roomusers = GetUsersInRoom(); foreach(User roomuser in roomusers) { roomuser.SendRoomList(); roomuser.SendRoomPlayers(); } } else { if (newScreen == NSScreen.Room) { SendSong(false); } // }else if (newScreen == NSScreen.Room) { // // find people waiting for synchronization // List<User> usersToSendPacketTo = new List<User>(); // foreach (User user in CurrentRoom.Users) { // if (user.SyncNeeded) { // usersToSendPacketTo.Add(user); // } // } // } else if (newScreen == NSScreen.Room) { // List<User> users = CurrentRoom.Users; // // find people waiting for synchronization // List<User> usersToSendPacketTo = new List<User>(); // foreach (User user in users) { // if (user.SyncNeeded) { // usersToSendPacketTo.Add(user); // } // } // // // send packet those people // SendSongStartTo(usersToSendPacketTo.ToArray()); CurrentScreen = newScreen; User[] usersinroom = GetUsersInRoom(); foreach (User user in usersinroom) { user.SendRoomPlayers(); } } }
public override Id InitWithContentRectStyleMaskBackingDeferScreen(NSRect aContentRect, NSWindowStyleMasks aWindowStyle, NSBackingStoreType aBufferingType, bool aDeferCreation, NSScreen aScreen) { // overridden to set NSBorderlessWindowMask for no title bar this.SendMessageSuper(ThisClass, "initWithContentRect:styleMask:backing:defer:screen:", aContentRect, NSWindowStyleMasks.NSBorderlessWindowMask, aBufferingType, aDeferCreation, aScreen); return(this); }
private static Rectangle GetScreenBounds(NSScreen screen) { var frame = screen.Frame; return(new Rectangle((int)frame.X, (int)frame.Y, (int)frame.Width, (int)frame.Height)); }
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)); }
public WindowWrapper(CGRect contentRect, NSWindowStyle aStyle, NSBackingStore bufferingType, bool deferCreation, NSScreen screen) : base(contentRect, aStyle, bufferingType, deferCreation, screen) { Initialize(); }
public AppStoreWindow(CGRect contentRect, NSWindowStyle aStyle, NSBackingStore bufferingType, bool deferCreation, NSScreen screen) : base(contentRect, aStyle, bufferingType, deferCreation, screen) { }
public override Boolean EnterFullscreenModeWithOptions(NSScreen screen, NSDictionary options) { return base.EnterFullscreenModeWithOptions (screen, options); }
internal GraphicsAdapter(UIScreen screen) { _screen = screen; }
public Display(NSScreen nativeScreen) { this.NativeScreen = nativeScreen; }