Example #1
0
        // This method calls the game Initialize and BeginRun methods before it begins the game loop and starts
        // processing events for the game.
        public void Run()
        {
            _lastUpdate = DateTime.Now;

            // In an original XNA game the GraphicsDevice property is null during initialization
            // but before the Game's Initialize method is called the property is available so we can
            // only assume that it should be created somewhere in here.  We can not set the viewport
            // values correctly based on the Preferred settings which is causing some problems on some
            // Microsoft samples which we are not handling correctly.
            graphicsDeviceManager.CreateDevice();

            var manager = Services.GetService(typeof(IGraphicsDeviceManager)) as GraphicsDeviceManager;

            Microsoft.Xna.Framework.Graphics.Viewport _vp =
                new Microsoft.Xna.Framework.Graphics.Viewport();

            _vp.X      = 0;
            _vp.Y      = 0;
            _vp.Width  = manager.PreferredBackBufferWidth;
            _vp.Height = manager.PreferredBackBufferHeight;

            GraphicsDevice.Viewport = _vp;

            _initializing = true;

            // Moving the GraphicsDevice creation to here also modifies when GameComponents are being
            // initialized.
            // Use OpenGL context locking in delegate function
//			InitialiseGameComponentsDelegate initD = new InitialiseGameComponentsDelegate (InitializeGameComponents);
//
//			// Invoke on thread from the pool
//			initD.BeginInvoke (
//				delegate (IAsyncResult iar)
//				{
//					// We must have finished initialising, so set our flag appropriately
//					// So that we enter the Update loop
//					_initialized = true;
//					_initializing = false;
//				},
//			initD);

            InitializeGameComponents();
            _initialized  = true;
            _initializing = false;


            Initialize();

            _view.Run(FramesPerSecond / (FramesPerSecond * TargetElapsedTime.TotalSeconds));
            _mainWindow.MakeKeyAndOrderFront(_mainWindow);
        }
Example #2
0
        public void Run()
        {
            _lastUpdate = DateTime.Now;

            Initialize();

            _mainWindow.MakeKeyAndOrderFront(_mainWindow);

            _view.Run(FramesPerSecond / (FramesPerSecond * TargetElapsedTime.TotalSeconds));
            //_view.Run();

            /*TODO _view.MainContext = _view.EAGLContext;
             * _view.ShareGroup = _view.MainContext.ShareGroup;
             * _view.BackgroundContext = new MonoTouch.OpenGLES.EAGLContext(_view.ContextRenderingApi, _view.ShareGroup); */

            //Show the window
            //_mainWindow.MakeKeyWindow ();

            // Get the Accelerometer going
            // TODO Accelerometer.SetupAccelerometer();


            // Listen out for rotation changes
            // TODO ObserveDeviceRotation();
        }
Example #3
0
 public override void FinishedLaunching(NSObject notification)
 {
     window = new NSWindow(new RectangleF(50, 50, 400, 400), (NSWindowStyle)(1 | (1 << 1) | (1 << 2) | (1 << 3)), NSBackingStore.Buffered, false);
     window.MakeKeyAndOrderFront(this);
     //mainWindowController = new MainWindowController ();
     //mainWindowController.Window.MakeKeyAndOrderFront (this);
 }
Example #4
0
        public override void FinishedLaunching(MonoMac.Foundation.NSObject notification)
        {
            // Get the button
            var closeButton = CreateCloseButton();
            // Get size and create rectangle for the view
            var closeButtonSize = closeButton.Frame.Size;
            var closeButtonRect = new RectangleF(8, 8, closeButtonSize.Width, closeButtonSize.Height);

            // Apply the rectangle to the frame
            closeButton.Frame = closeButtonRect;
            // Attach an event to the button. When "Activated" / "Clicked" it will close the application.
            closeButton.Activated += (object sender, EventArgs e) => {
                NSApplication.SharedApplication.Terminate(closeButton);
            };

            // Creating the NSWindow object
            var window = new NSWindow(
                new RectangleF(0, 0, 400, 300), // Sets the size of the window
                NSWindowStyle.Titled,           // Style of the window
                NSBackingStore.Buffered,
                false
                )
            {
                // Adding a title
                Title = "MonoMacTest02 (Adding a button)"
            };

            // Add our button to the window
            // AddSubView expects an NSView object. All UI controls are derived from NSView, so we can add the 'closeButton' itself.
            window.ContentView.AddSubview(closeButton);
            window.CascadeTopLeftFromPoint(new PointF(20, 20));
            window.MakeKeyAndOrderFront(null);
        }
		public override void DidFinishLaunching (NSNotification notification)
		{
			var menu = new NSMenu ();

			var menuItem = new NSMenuItem ();
			menu.AddItem (menuItem);

			var appMenu = new NSMenu ();
			var quitItem = new NSMenuItem ("Quit", "q", (s, e) => NSApplication.SharedApplication.Terminate (menu));
			appMenu.AddItem (quitItem);

			menuItem.Submenu = appMenu;
			NSApplication.SharedApplication.MainMenu = menu;

			m_window = new NSWindow (
				new CGRect (0, 0, 1024, 720),
				NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.TexturedBackground,
				NSBackingStore.Buffered,
				false) {
				Title = "Bluebird WkBrowser",
				ReleasedWhenClosed = false,
				ContentMinSize = new CGSize (1024, 600),
				CollectionBehavior = NSWindowCollectionBehavior.FullScreenPrimary
			};
			m_window.Center ();
			m_window.MakeKeyAndOrderFront (null);

			var viewController = new ViewController ();
			m_window.ContentView = viewController.View;
			m_window.ContentViewController = viewController;
			viewController.View.Frame = m_window.ContentView.Bounds;
		}
Example #6
0
        static void Main(string[] args)
        {
            NSApplication.Init();
            NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular;

            var xPos       = NSScreen.MainScreen.Frame.Width / 2;      // NSWidth([[window screen] frame])/ 2 - NSWidth([window frame])/ 2;
            var yPos       = NSScreen.MainScreen.Frame.Height / 2;     // NSHeight([[window screen] frame])/ 2 - NSHeight([window frame])/ 2;
            var mainWindow = new NSWindow(new CGRect(xPos, yPos, 600, 368), NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable, NSBackingStore.Buffered, false)
            {
                ContentView = new SpaceView()
            };

            var space = new cpSpace {
                CollisionEnabled = true
            };

            #region Scene

            var example = new Game1(space);
            example.Initialize(mainWindow.ContentView);
            example.StartAsync(loop: true);

            #endregion

            mainWindow.Title = "Example Debug Xamarin.Mac";

            //mainWindow.MakeKeyWindow();
            mainWindow.MakeKeyAndOrderFront(null);
            NSApplication.SharedApplication.ActivateIgnoringOtherApps(true);
            NSApplication.SharedApplication.Run();
            //mainWindow.Dispose();
        }
    public static void Main(string[] args)
    {
        NSApplication.Init();
        Gtk.Application.Init();

        var gtkWindow = new Gtk.Window(Gtk.WindowType.Toplevel)
        {
            Title       = "GTK Window",
            Gravity     = Gdk.Gravity.Center,
            DefaultSize = new Gdk.Size(WindowWidth, WindowHeight),
            BorderWidth = Padding
        };

        gtkWindow.Add(new Gtk.Widget(gtk_ns_view_new(new NativeViewHost().Handle)));
        gtkWindow.ShowAll();

        var nativeWindow = new NSWindow(
            new CGRect(0, 0, WindowWidth, WindowHeight),
            NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable,
            NSBackingStore.Buffered,
            false)
        {
            Title       = "Native Window",
            ContentView = new NativeViewHost()
        };

        nativeWindow.Center();
        nativeWindow.MakeKeyAndOrderFront(null);

        var menuBar     = new NSMenu();
        var appMenuItem = new NSMenuItem();

        menuBar.AddItem(appMenuItem);

        var appMenu = new NSMenu();

        appMenu.AddItem(new NSMenuItem("Quit", new ObjCRuntime.Selector("terminate:"), "q"));
        appMenuItem.Submenu = appMenu;

        NSApplication.SharedApplication.Delegate         = new NSApplicationDelegate();
        NSApplication.SharedApplication.MainMenu         = menuBar;
        NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular;

        // Allow the native run loop to drive the app, and the GTK window
        // embedding a native view with a local event monitor will deliver
        // events as expected.
        // NSApplication.SharedApplication.Run();

        // Let GTK drive the app, dispatching to the native run loop as
        // necessary, and the native view with a local event monitor will
        // only deliver events when the mouse is within the view's frame.
        Gtk.Application.Run();
    }
Example #8
0
        static void Main(string[] args)
        {
            NSApplication.Init();
            NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular;

            AgentEnvirontment.Current.Initialize(new AgentDelegate(), new SoundPlayer());

            var xPos = NSScreen.MainScreen.Frame.Width / 2;
            var yPos = NSScreen.MainScreen.Frame.Height / 2;

            var mainWindow = new NSWindow(new CGRect(xPos, yPos, 200, 150), NSWindowStyle.Borderless, NSBackingStore.Buffered, false)
            {
                Title = "ClippySharp",

                IsOpaque        = false,
                BackgroundColor = NSColor.FromRgba(red: 1, green: 1, blue: 1f, alpha: 0.5f)
            };

            mainWindow.MovableByWindowBackground = true;

            var stackView = new NSStackView()
            {
                Orientation  = NSUserInterfaceLayoutOrientation.Vertical,
                Distribution = NSStackViewDistribution.Fill
            };

            mainWindow.ContentView = stackView;

            agentPopupButton = new NSPopUpButton();
            stackView.AddArrangedSubview(agentPopupButton);

            foreach (var item in AgentEnvirontment.Current.GetAgents())
            {
                agentPopupButton.AddItem(item);
            }

            animationPopupButton = new NSPopUpButton();
            stackView.AddArrangedSubview(animationPopupButton);

            agentView = new AgentView();
            stackView.AddArrangedSubview(agentView);

            agentPopupButton.Activated += AgentPopupButton_Activated;

            animationPopupButton.Activated += AnimationPopupButton_Activated;

            AgentPopupButton_Activated(null, null);

            mainWindow.MakeKeyAndOrderFront(null);
            NSApplication.SharedApplication.ActivateIgnoringOtherApps(true);
            NSApplication.SharedApplication.Run();
        }
Example #9
0
    partial void goFullScreen (NSObject sender)
    {
        isInFullScreenMode = true;

        // Pause the non-fullscreen view
        openGLView.StopAnimation ();

        RectangleF mainDisplayRect;
        RectangleF viewRect;

        // Create a screen-sized window on the display you want to take over
        // Note, mainDisplayRect has a non-zero origin if the key window is on a secondary display
        mainDisplayRect = NSScreen.MainScreen.Frame;

        fullScreenWindow = new NSWindow (mainDisplayRect, NSWindowStyle.Borderless, NSBackingStore.Buffered, true);

        // Set the window level to be above the menu bar
        fullScreenWindow.Level = NSWindowLevel.MainMenu + 1;

        // Perform any other window configuration you desire
        fullScreenWindow.IsOpaque = true;
        fullScreenWindow.HidesOnDeactivate = true;

        // Create a view with a double-buffered OpenGL context and attach it to the window
        // By specifying the non-fullscreen context as the shareContext, we automatically inherit the
        // OpenGL objects (textures, etc) it has defined
        viewRect = new RectangleF (0, 0, mainDisplayRect.Size.Width, mainDisplayRect.Size.Height);

        fullScreenView = new MyOpenGLView (viewRect, openGLView.OpenGLContext);
        fullScreenWindow.ContentView = fullScreenView;

        // Show the window
        fullScreenWindow.MakeKeyAndOrderFront (this);

        // Set the scene with the full-screen viewport and viewing transformation
        Scene.ResizeGLScene (viewRect);

        // Assign the view's MainController to self
        fullScreenView.MainController = this;

        if (!isAnimating)
        {
            // Mark the view as needing drawing to initalize its contents
            fullScreenView.NeedsDisplay = true;
        }
        else
        {
            // Start playing the animation
            fullScreenView.StartAnimation ();

        }
    }
        public override void DidFinishLaunching(NSNotification notification)
        {
            _window = new NSWindow(new CGRect(200, 200, 400, 700), NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled,
                                   NSBackingStore.Buffered, false, NSScreen.MainScreen);

            var setup = new Setup(this, _window);
            setup.Initialize();

            var startup = Mvx.Resolve<IMvxAppStart>();
            startup.Start();

            _window.MakeKeyAndOrderFront(this);
        }
Example #11
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            var window     = new NSWindow(new CGRect(0, 0, 500, 500), NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable, NSBackingStore.Buffered, false);
            var scrollView = new NSScrollView();

            scrollView.BackgroundColor = NSColor.Blue;
            window.ContentView         = scrollView;
            window.Center();
            window.MakeKeyAndOrderFront(this);

            var liteHtmlWindow = new LiteHtmlSharp.Mac.LiteHtmlWindowHelper(window, window.Frame, LiteHtmlSharp.IncludedMasterCss.CssString);

            liteHtmlWindow.LiteHtmlView.LoadHtml(SampleHtml);
        }
		partial void goFullScreen (NSObject sender)
		{
			isInFullScreenMode = true;

			// Pause the non-fullscreen view
			openGLView.StopAnimation ();

			CGRect mainDisplayRect;
			CGRect viewRect;

			// Create a screen-sized window on the display you want to take over
			// Note, mainDisplayRect has a non-zero origin if the key window is on a secondary display
			mainDisplayRect = NSScreen.MainScreen.Frame;

			fullScreenWindow = new NSWindow (mainDisplayRect, NSWindowStyle.Borderless, NSBackingStore.Buffered, true);

			// Set the window level to be above the menu bar
			fullScreenWindow.Level = NSWindowLevel.MainMenu + 1;

			// Perform any other window configuration you desire
			fullScreenWindow.IsOpaque = true;
			fullScreenWindow.HidesOnDeactivate = true;

			// Create a view with a double-buffered OpenGL context and attach it to the window
			// By specifying the non-fullscreen context as the shareContext, we automatically inherit the 
			// OpenGL objects (textures, etc) it has defined
			viewRect = new CGRect (0, 0, mainDisplayRect.Size.Width, mainDisplayRect.Size.Height);

			fullScreenView = new MyOpenGLView (viewRect, openGLView.OpenGLContext);
			fullScreenWindow.ContentView = fullScreenView;

			// Show the window
			fullScreenWindow.MakeKeyAndOrderFront (this);

			// Set the scene with the full-screen viewport and viewing transformation
			Scene.ResizeGLScene (viewRect);

			// Assign the view's MainController to self
			fullScreenView.MainController = this;

			if (!isAnimating) {
				// Mark the view as needing drawing to initalize its contents
				fullScreenView.NeedsDisplay = true;
			} else {
				// Start playing the animation
				fullScreenView.StartAnimation ();

			}
		}
Example #13
0
        public void Dispose()
        {
            if (keyWindow != null)
            {
                if (keyWindow.CanBecomeKeyWindow)
                {
                    keyWindow.MakeKeyAndOrderFront(null);
                }

                if (firstResponder != null && firstResponder.AcceptsFirstResponder())
                {
                    keyWindow.MakeFirstResponder(firstResponder);
                }
            }
        }
Example #14
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            var flags  = NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Resizable | NSWindowStyle.FullSizeContentView;
            var window = new NSWindow(new CGRect(x: 0, y: 0, width: 480, height: 300), flags, NSBackingStore.Buffered, deferCreation: false);

            window.WillClose += delegate {
                window.ContentView = NSTextField.CreateLabel("CLOSING");
                GC.Collect();
            };
            window.Center();

            window.ContentView = new NSHostingView(new ClickButton());

            window.MakeKeyAndOrderFront(this);
        }
Example #15
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            _window = new NSWindow(new CGRect(200, 200, 400, 700), NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled,
                                   NSBackingStore.Buffered, false, NSScreen.MainScreen);

            var setup = new Setup(this, _window);

            setup.Initialize();

            var startup = Mvx.Resolve <IMvxAppStart>();

            startup.Start();

            _window.MakeKeyAndOrderFront(this);
        }
Example #16
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            window = new NSWindow(new CGRect(0, 0, 300, 300), NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Resizable | NSWindowStyle.Titled, NSBackingStore.Retained, false);

            var squeeze        = new SqueezeNet();
            var buf            = new CVPixelBuffer(227, 227, CVPixelFormatType.CV32BGRA);
            var classification = squeeze.GetPrediction(buf, out var error);

            Console.WriteLine($"Classification: {classification} Error: {error}");

            var size = window.Frame.Size;
            var loc  = new CGPoint((NSScreen.MainScreen.Frame.Width - size.Width) / 2, (NSScreen.MainScreen.Frame.Height - size.Height) / 2);

            window.SetFrameOrigin(loc);
            window.MakeKeyAndOrderFront(null);
        }
Example #17
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            window = new NSWindow(new CGRect(0, 0, 300, 300), NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Resizable | NSWindowStyle.Titled, NSBackingStore.Retained, false);

            SCNScene scene   = SCNScene.FromFile("art.scnassets/scene.scn");
            SCNView  scnView = new SCNView(window.ContentView.Bounds);

            scnView.Scene = scene;
            window.ContentView.AddSubview(scnView);

            var size = window.Frame.Size;
            var loc  = new CGPoint((NSScreen.MainScreen.Frame.Width - size.Width) / 2, (NSScreen.MainScreen.Frame.Height - size.Height) / 2);

            window.SetFrameOrigin(loc);
            window.MakeKeyAndOrderFront(null);
        }
    public override void FinishedLaunching(NSObject notification)
    {
        view = new MyView(new RectangleF(10, 10, 200, 200));

        text = new NSTextField(new RectangleF(44, 32, 232, 31))
        {
            StringValue = "Hello Mono Mac!"
        };

        window = new NSWindow(new RectangleF(50, 50, 400, 400), (NSWindowStyle)(1 | (1 << 1) | (1 << 2) | (1 << 3)), 0, false);
        window.ContentView.AddSubview(text);
        window.ContentView.AddSubview(view);



        window.MakeKeyAndOrderFront(this);
    }
Example #19
0
        public override void FinishedLaunching(NSObject notification)
        {
            var appName = NSProcessInfo.ProcessInfo.ProcessName;

            CreateMenu(appName);

            var window = new NSWindow(
                new RectangleF(0, 0, 400, 300),
                NSWindowStyle.Titled,
                NSBackingStore.Buffered,
                false)
            {
                Title = appName
            };

            window.CascadeTopLeftFromPoint(new PointF(20, 20));
            window.MakeKeyAndOrderFront(null);
        }
        public override void FinishedLaunching(NSObject notification)
        {
            _window = new NSWindow(new RectangleF(200, 200, 400, 400), NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled,
                                   NSBackingStore.Buffered, false, NSScreen.MainScreen);

            var presenter = new MvxMacViewPresenter(this, _window);
            var setup     = new Setup(this, presenter);

            setup.Initialize();

            var startup = Mvx.Resolve <IMvxAppStart> ();

            startup.Start();

            _window.MakeKeyAndOrderFront(this);

            return;
        }
Example #21
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            // Borrow window from the main storyboard
            _window            = NSApplication.SharedApplication.Windows.First();
            _window.WillClose += (sender, e) =>
            {
                NSApplication.SharedApplication.Terminate(this);
            };

            var setup = new Setup(this, _window);

            setup.Initialize();

            var startup = Mvx.Resolve <IMvxAppStart>();

            startup.Start();

            _window.MakeKeyAndOrderFront(this);
        }
Example #22
0
        public NSWindow GetMainWindow()
        {
            if (ClientSessionUri.SessionKind == ClientSessionKind.LiveInspection)
            {
                return(NSApplication.SharedApplication.MainWindow ??
                       NSApplication.SharedApplication.Windows?.FirstOrDefault());
            }

            if (workbookMainWindow == null)
            {
                string xmDisplayName = null;
                switch (Identity.AgentType)
                {
                case AgentType.MacNet45:
                    xmDisplayName = "Full Profile";
                    break;

                case AgentType.MacMobile:
                    xmDisplayName = "Modern Profile";
                    break;

                default:
                    throw new NotImplementedException($"AgentType.{Identity.AgentType}");
                }

                workbookMainWindow = new NSWindow {
                    Title     = $"Workbook Main Window - {xmDisplayName}",
                    StyleMask = NSWindowStyle.Resizable |
                                NSWindowStyle.Closable |
                                NSWindowStyle.Miniaturizable |
                                NSWindowStyle.Titled
                };

                workbookMainWindow.SetContentSize(new CGSize(500, 400));
            }

            workbookMainWindow.BecomeMainWindow();
            workbookMainWindow.MakeKeyAndOrderFront(null);

            return(workbookMainWindow);
        }
Example #23
0
        public static void ShowInWindow(this NSView view)
        {
            var window = new NSWindow(
                new CGRect(0, 0, 200, 200),
                NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable,
                NSBackingStore.Buffered,
                false
                );

            if (view.Superview != null)
            {
                view.RemoveFromSuperview();
            }

            window.ContentView.AddSubview(view);

            window.ContentView.AddConstraints(FillHorizontal(view, false));
            window.ContentView.AddConstraints(FillVertical(view, false));

            window.MakeKeyAndOrderFront(view);
        }
		public override void DidFinishLaunching(NSNotification notification)
		{
			Window = new NSWindow(new CGRect(0, 0, 400, 300),
					  NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable,
					  NSBackingStore.Buffered, false, NSScreen.MainScreen);        // how big?
			Window.Title = "TipCalc";
			Window.WillClose += (sender, e) =>
			{
				NSApplication.SharedApplication.Terminate(this);
			};

			var presenter = new MvxMacViewPresenter(this, Window);

			var setup = new Setup(this, presenter);
			setup.Initialize();

			var startup = Mvx.Resolve<IMvxAppStart>();
			startup.Start();

			Window.MakeKeyAndOrderFront(this);
		}
Example #25
0
        public void showServerLogs()
        {
            if (_logViewController == null)
            {
                _logViewController = Storyboard.InstantiateControllerWithIdentifier("LogViewController") as LogViewController;

                var frame     = _logViewController.View.Bounds;
                var styleMask = NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Borderless;
                var rect      = NSWindow.ContentRectFor(frame, styleMask);

                var keyWindowFrame = NSApplication.SharedApplication.KeyWindow.Frame;
                rect.X = keyWindowFrame.X + keyWindowFrame.Width;
                rect.Y = keyWindowFrame.Y + keyWindowFrame.Height - rect.Height;

                _logViewWindow       = new NSWindow(rect, styleMask, NSBackingStore.Buffered, false);
                _logViewWindow.Title = "Hugo Server Logs";
                _logViewWindow.ContentViewController = _logViewController;
                _logViewWindow.ReleasedWhenClosed    = false;
            }

            _logViewWindow.MakeKeyAndOrderFront(_logViewWindow);
        }
        public override void DidFinishLaunching(NSNotification notification)
        {
            Window = new NSWindow(new CGRect(0, 0, 400, 300),
                                  NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable,
                                  NSBackingStore.Buffered, false, NSScreen.MainScreen);                // how big?
            Window.Title      = "TipCalc";
            Window.WillClose += (sender, e) =>
            {
                NSApplication.SharedApplication.Terminate(this);
            };

            var presenter = new MvxMacViewPresenter(this, Window);

            var setup = new Setup(this, presenter);

            setup.Initialize();

            var startup = Mvx.Resolve <IMvxAppStart>();

            startup.Start();

            Window.MakeKeyAndOrderFront(this);
        }
Example #27
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            var initialWindowSize = new CGRect(0, 0, 375, 667);
            var windowStyle       = NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Miniaturizable | NSWindowStyle.Closable;

            _control = new UnoGLView(initialWindowSize);
            _window  = new NSWindow(
                initialWindowSize,
                windowStyle,
                NSBackingStore.Buffered,
                false)
            {
                Title       = GetAssemblyTitle(),
                ContentView = _control
            };

            _window.MakeKeyAndOrderFront(_control);
            _control.Initialize();

            LoadApplication();
            Uno.Platform2.Internal.Application.Start();
            _control.Run(60.0);
        }
Example #28
0
        static void Main(string[] args)
        {
            NSApplication.Init();
            NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular;

            var xPos       = NSScreen.MainScreen.Frame.Width / 2;  // NSWidth([[window screen] frame])/ 2 - NSWidth([window frame])/ 2;
            var yPos       = NSScreen.MainScreen.Frame.Height / 2; // NSHeight([[window screen] frame])/ 2 - NSHeight([window frame])/ 2;
            var mainWindow = new MacAccInspectorWindow(new CGRect(xPos, yPos, 300, 368), NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable, NSBackingStore.Buffered, false);

            var stackView = new NSStackView()
            {
                Orientation = NSUserInterfaceLayoutOrientation.Vertical
            };

            mainWindow.ContentView = stackView;
            stackView.AddArrangedSubview(new NSTextField {
                StringValue = "123"
            });

            stackView.AddArrangedSubview(new NSTextField {
                StringValue = "45"
            });
            stackView.AddArrangedSubview(new NSTextField {
                StringValue = "345"
            });
            var button = new NSButton {
                Title = "Press to show a message"
            };

            stackView.AddArrangedSubview(button);

            var hotizontalView = new NSStackView()
            {
                Orientation = NSUserInterfaceLayoutOrientation.Horizontal
            };

            hotizontalView.AddArrangedSubview(new NSTextField()
            {
                StringValue = "test"
            });

            stackView.AddArrangedSubview(hotizontalView);

            button.Activated += (sender, e) => {
                var alert = new NSAlert();
                alert.MessageText     = "You clicked the button!!!";
                alert.InformativeText = "Are you sure!?";
                alert.AddButton("OK!");
                alert.RunModal();
            };

            var button2 = new NSButton {
                Title = "Opens Localized text"
            };

            button2.Activated += (sender, e) => {
                var window = new NSWindow()
                {
                    StyleMask = NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable
                };
                var stack = NativeViewHelper.CreateHorizontalStackView();
                var label = NativeViewHelper.CreateLabel("hello");
                stack.AddArrangedSubview(label);
                window.ContentView = stack;
                window.WillClose  += (sender1, e1) =>
                {
                    window.Dispose();
                };
                window.MakeKeyAndOrderFront(mainWindow);
            };
            stackView.AddArrangedSubview(button2);
            button2.HeightAnchor.ConstraintEqualToConstant(100).Active = true;;

            mainWindow.Title = "Example Debug Xamarin.Mac";

            //mainWindow.MakeKeyWindow();
            mainWindow.MakeKeyAndOrderFront(null);
            NSApplication.SharedApplication.ActivateIgnoringOtherApps(true);
            NSApplication.SharedApplication.Run();
            //mainWindow.Dispose();
        }
Example #29
0
        public void DialogShouldAllowAttachingToNativeWindow()
        {
            bool passed = false;
            var  ev     = new ManualResetEvent(false);

            Invoke(() =>
            {
                var nswindow = new NSWindow(new CGRect(100, 100, 300, 300), NSWindowStyle.Titled, NSBackingStore.Buffered, false);
                nswindow.ReleasedWhenClosed = false;

                var showDialog = new Button {
                    Text = "Show Attached Dialog"
                };
                showDialog.Click += (sender, e) =>
                {
                    var dlg         = new Dialog();
                    dlg.DisplayMode = DialogDisplayMode.Attached;

                    var closeButton = new Button {
                        Text = "Close"
                    };
                    closeButton.Click += (sender2, e2) => dlg.Close();

                    dlg.Content = new StackLayout
                    {
                        Padding = 10,
                        Spacing = 10,
                        Items   =
                        {
                            "This should show as attached",
                            closeButton
                        }
                    };

                    dlg.ShowModal(showDialog);
                };

                var passButton = new Button {
                    Text = "Pass"
                };
                passButton.Click += (sender, e) =>
                {
                    passed = true;
                    nswindow.Close();
                    ev.Set();
                };
                var failButton = new Button {
                    Text = "Fail"
                };
                failButton.Click += (sender, e) =>
                {
                    passed = false;
                    nswindow.Close();
                    ev.Set();
                };

                var panel = new StackLayout
                {
                    Items =
                    {
                        new Panel {
                            Padding = 20, Content = showDialog
                        },
                        TableLayout.Horizontal(failButton, passButton)
                    }
                };

                nswindow.ContentView = panel.ToNative(true);

                var parentWindow = panel.ParentWindow;

                nswindow.MakeKeyAndOrderFront(nswindow);
            });
            ev.WaitOne();
            Assert.IsTrue(passed);
        }
Example #30
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            // Handle CMD-Q
            NSMenu mainMenu = NSApplication.SharedApplication.MainMenu = new NSMenu("Exception marshaling");

            mainMenu.AddItem("Sub", new ObjCRuntime.Selector("sub"), "S");
            var subMenu = new NSMenu("Sub");
            var quit    = new NSMenuItem("Quit", (sender, e) => {
                NSApplication.SharedApplication.Terminate(this);
            });

            quit.Enabled                   = true;
            quit.KeyEquivalent             = "q";
            quit.KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask;
            subMenu.AddItem(quit);
            mainMenu.AutoEnablesItems = false;
            mainMenu.SetSubmenu(subMenu, mainMenu.ItemAt(0));

            // Create main window and its UI
            window       = new NSWindow(new CGRect(0, 0, 500, 500), NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable, NSBackingStore.Buffered, true);
            window.Title = "Exception marshaling";

            var protoCell = new NSButtonCell();

            protoCell.SetButtonType(NSButtonType.Radio);

            var cellSize      = new CGSize(300, 25);
            var boxSize       = new CGSize(300, 400);
            var managedBox    = new NSBox(new CGRect(new CGPoint(0, 0), boxSize));
            var objectiveCBox = new NSBox(new CGRect(new CGPoint(managedBox.Frame.Right, managedBox.Frame.Y), boxSize));

            var throwManagedException = new NSButton(new CGRect((boxSize.Width - 200) / 2, 0, 200, cellSize.Height));

            throwManagedException.Title = "Throw managed exception";

            var marshalManagedModeMatrix = new NSMatrix(new CGRect(0, 0, managedBox.Frame.Width, cellSize.Height * 6 + 10), NSMatrixMode.Radio, protoCell, 6, 1);

            marshalManagedModeMatrix.Cells [0].Title = "None";
            marshalManagedModeMatrix.Cells [1].Title = "Default";
            marshalManagedModeMatrix.Cells [2].Title = "Unwind native code";
            marshalManagedModeMatrix.Cells [3].Title = "Throw Objective-C exception";
            marshalManagedModeMatrix.Cells [4].Title = "Abort";
            marshalManagedModeMatrix.Cells [5].Title = "Disable";
            marshalManagedModeMatrix.CellSize        = cellSize;

            var marshalManagedMode = new NSBox(new CGRect(0, throwManagedException.Frame.Bottom + 20, marshalManagedModeMatrix.Frame.Width, marshalManagedModeMatrix.Frame.Height + cellSize.Height));

            marshalManagedMode.Title = "Marshaling mode";
            marshalManagedMode.AddSubview(marshalManagedModeMatrix);

            var threadManagedMatrix = new NSMatrix(new CGRect(0, 0, managedBox.Frame.Width, cellSize.Height * 3 + 10), NSMatrixMode.Radio, protoCell, 3, 1);

            threadManagedMatrix.Cells [0].Title = "Main thread";
            threadManagedMatrix.Cells [1].Title = "Background thread";
            threadManagedMatrix.Cells [2].Title = "Threadpool thread";
            threadManagedMatrix.CellSize        = cellSize;

            var threadManaged = new NSBox(new CGRect(new CGPoint(0, marshalManagedMode.Frame.Bottom + 20), new CGSize(threadManagedMatrix.Frame.Width, threadManagedMatrix.Frame.Height + cellSize.Height)));

            threadManaged.Title = "Thread";
            threadManaged.AddSubview(threadManagedMatrix);

            var marshalObjectiveCModeMatrix = new NSMatrix(marshalManagedModeMatrix.Frame, NSMatrixMode.Radio, protoCell, 6, 1);

            marshalObjectiveCModeMatrix.Cells [0].Title = "None";
            marshalObjectiveCModeMatrix.Cells [1].Title = "Default";
            marshalObjectiveCModeMatrix.Cells [2].Title = "Unwind managed code";
            marshalObjectiveCModeMatrix.Cells [3].Title = "Throw managed exception";
            marshalObjectiveCModeMatrix.Cells [4].Title = "Abort";
            marshalObjectiveCModeMatrix.Cells [5].Title = "Disable";
            marshalObjectiveCModeMatrix.CellSize        = cellSize;

            var marshalObjectiveCMode = new NSBox(marshalManagedMode.Frame);

            marshalObjectiveCMode.Title = "Marshaling mode";
            marshalObjectiveCMode.AddSubview(marshalObjectiveCModeMatrix);

            var threadObjectiveCMatrix = new NSMatrix(threadManagedMatrix.Frame, threadManagedMatrix.Mode, threadManagedMatrix.Prototype, threadManagedMatrix.Rows, threadManagedMatrix.Columns);

            threadObjectiveCMatrix.Cells [0].Title = "Main thread";
            threadObjectiveCMatrix.Cells [1].Title = "Background thread";
            threadObjectiveCMatrix.Cells [2].Title = "Threadpool thread";
            threadObjectiveCMatrix.CellSize        = cellSize;

            var threadObjectiveC = new NSBox(threadManaged.Frame);

            threadObjectiveC.Title = "Thread";
            threadObjectiveC.AddSubview(threadObjectiveCMatrix);

            var throwObjectiveCException = new NSButton(throwManagedException.Frame);

            throwObjectiveCException.Title = "Throw Objective-C exception";

            managedBox.Title = "Managed exception";
            managedBox.AddSubview(throwManagedException);
            managedBox.AddSubview(threadManaged);
            managedBox.AddSubview(marshalManagedMode);
            managedBox.Frame = new CGRect(managedBox.Frame.X, managedBox.Frame.Y, managedBox.Frame.Width, threadManaged.Frame.Bottom + cellSize.Height);
            //managedBox.SetBoundsSize (new CGSize (managedBox.Bounds.Width, threadManaged.Frame.Bottom));
            window.ContentView.AddSubview(managedBox);

            objectiveCBox.Title = "Objective-C exception";
            objectiveCBox.AddSubview(throwObjectiveCException);
            objectiveCBox.AddSubview(threadObjectiveC);
            objectiveCBox.AddSubview(marshalObjectiveCMode);
            objectiveCBox.Frame = new CGRect(objectiveCBox.Frame.Location, managedBox.Frame.Size);
            window.ContentView.AddSubview(objectiveCBox);

            var windowContentSize = new CGSize(managedBox.Frame.Width + objectiveCBox.Frame.Width, Math.Max(managedBox.Frame.Height, objectiveCBox.Frame.Height));

            window.SetContentSize(windowContentSize);
            window.ContentMinSize = windowContentSize;
            window.Center();
            window.MakeKeyAndOrderFront(window);

            Action setModes = () => {
                if (marshalManagedModeMatrix.SelectedRow == 0)
                {
                    Exceptions.ManagedExceptionMode = null;
                }
                else
                {
                    Exceptions.ManagedExceptionMode = (MarshalManagedExceptionMode)(int)marshalManagedModeMatrix.SelectedRow - 1;
                }
                if (marshalObjectiveCModeMatrix.SelectedRow == 0)
                {
                    Exceptions.ObjectiveCExceptionMode = null;
                }
                else
                {
                    Exceptions.ObjectiveCExceptionMode = (MarshalObjectiveCExceptionMode)(int)marshalObjectiveCModeMatrix.SelectedRow - 1;
                }
            };

            throwObjectiveCException.Activated += (sender, e) => {
                setModes();
                Exceptions.ThrowObjectiveCException((ThreadMode)(int)threadObjectiveCMatrix.SelectedRow);
            };
            throwManagedException.Activated += (sender, e) => {
                setModes();
                Exceptions.ThrowManagedException((ThreadMode)(int)threadManagedMatrix.SelectedRow);
            };
        }
Example #31
0
 public void Activate()
 {
     window.MakeKeyAndOrderFront(window);
 }