public Window(WindowOptions options) { if (Application.MainWindow != null) { throw new Lime.Exception("Attempt to set Application.MainWindow twice"); } Application.MainWindow = this; Active = true; fpsCounter = new FPSCounter(); input = new Input(); UnityApplicationDelegate.Instance.Updating += delta => { Input.Refresh(); RaiseUpdating(delta); AudioSystem.Update(); Input.TextInput = null; Input.CopyKeysState(); if (LastSize != ClientSize) { RaiseResized(false); LastSize = ClientSize; } }; UnityApplicationDelegate.Instance.Rendering += () => { RaiseRendering(); fpsCounter.Refresh(); }; UnityApplicationDelegate.Instance.Destroying += () => { RaiseClosed(); }; }
public Window(WindowOptions options) { if (Application.MainWindow != null) { throw new Lime.Exception("Attempt to set Application.MainWindow twice"); } Application.MainWindow = this; Input = new WindowInput(this); Active = true; AsyncRendering = options.AsyncRendering; fpsCounter = new FPSCounter(); ActivityDelegate.Instance.Paused += activity => { Active = false; RaiseDeactivated(); }; ActivityDelegate.Instance.Resumed += activity => { Active = true; RaiseActivated(); }; ActivityDelegate.Instance.GameView.Resize += (sender, e) => { RaiseResized(((ResizeEventArgs)e).DeviceRotated); }; PixelScale = Resources.System.DisplayMetrics.Density; if (AsyncRendering) { renderThread = new Thread(RenderLoop); renderThread.IsBackground = true; renderThread.Start(); } Application.WindowUnderMouse = this; var ccb = new ChoreographerCallback(); long prevFrameTime = Java.Lang.JavaSystem.NanoTime(); ccb.OnFrame += frameTimeNanos => { var delta = (float)((frameTimeNanos - prevFrameTime) / 1000000000d); prevFrameTime = frameTimeNanos; if (Active && ActivityDelegate.Instance.GameView.IsSurfaceCreated) { fpsCounter.Refresh(); Update(delta); if (AsyncRendering) { renderCompleted.WaitOne(); renderCompleted.Reset(); RaiseSync(); renderReady.Set(); } else { RaiseSync(); Render(); } } }; Choreographer.Instance.PostFrameCallback(ccb); }
public Window(WindowOptions options) { if (Application.MainWindow != null) { throw new Lime.Exception("Attempt to set Application.MainWindow twice"); } Application.MainWindow = this; Active = true; fpsCounter = new FPSCounter(); ActivityDelegate.Instance.Paused += activity => { Active = false; RaiseDeactivated(); }; ActivityDelegate.Instance.Resumed += activity => { Active = true; RaiseActivated(); }; ActivityDelegate.Instance.GameView.Resize += (sender, e) => { RaiseResized(((ResizeEventArgs)e).DeviceRotated); }; ActivityDelegate.Instance.GameView.RenderFrame += (sender, e) => { RaiseRendering(); fpsCounter.Refresh(); }; ActivityDelegate.Instance.GameView.UpdateFrame += (sender, e) => { RaiseUpdating((float)e.Time); }; PixelScale = Resources.System.DisplayMetrics.Density; }
public Window(WindowOptions options) { fpsCounter = new FPSCounter(); CreateNativeWindow(options); if (Application.MainWindow == null) { Application.MainWindow = this; } Application.Windows.Add(this); Input = new WindowInput(this); ClientSize = options.ClientSize; Title = options.Title; if (options.Visible) { Visible = true; } if (options.Centered) { Center(); } if (options.Type == WindowType.ToolTip) { window.Level = NSWindowLevel.Floating; } stopwatch = new Stopwatch(); stopwatch.Start(); }
public Window(WindowOptions options) { if (Application.MainWindow != null) { throw new Lime.Exception("Attempt to create a second window."); } Application.MainWindow = this; Active = true; AsyncRendering = options.AsyncRendering; Input = new WindowInput(this); uiWindow = new UIWindow(UIScreen.MainScreen.Bounds); // UIApplicationDelegate must has a Window reference. This is an Apple's requirement. AppDelegate.Instance.Window = uiWindow; UIViewController = new GameController(Application.Input); uiWindow.RootViewController = UIViewController; uiWindow.MakeKeyAndVisible(); AppDelegate.Instance.Activated += () => { // Run() creates OpenGL context UIView.Run(); UIViewController.LockDeviceOrientation = false; Active = true; AudioSystem.Active = true; RaiseActivated(); UIKit.UIViewController.AttemptRotationToDeviceOrientation(); }; AppDelegate.Instance.Deactivated += () => { UIView.Stop(); UIViewController.LockDeviceOrientation = true; AudioSystem.Active = false; RaiseDeactivated(); Active = false; }; AppDelegate.Instance.WillTerminateEvent += () => { RaiseClosed(); }; UIViewController.OnResize += (sender, e) => { RaiseResized(((ResizeEventArgs)e).DeviceRotated); }; UIView.RenderFrame += OnRenderFrame; UIView.UpdateFrame += OnUpdateFrame; display = new Display(UIScreen.MainScreen); Application.WindowUnderMouse = this; }
public Window(WindowOptions options) { Input = new Input(); fpsCounter = new FPSCounter(); CreateNativeWindow(options); if (Application.MainWindow == null) { Application.MainWindow = this; } Application.Windows.Add(this); ClientSize = options.ClientSize; Title = options.Title; if (options.Visible) { Visible = true; } if (options.Centered) { Center(); } stopwatch = new Stopwatch(); stopwatch.Start(); }
public Window(WindowOptions options) { if (Application.MainWindow != null && Application.RenderingBackend == RenderingBackend.ES20) { // ES20 doesn't allow multiple contexts for now, because of a bug in OpenTK throw new Lime.Exception("Attempt to create a second window for ES20 rendering backend. Use OpenGL backend instead."); } Input = new Input(); form = new Form(); using (var graphics = form.CreateGraphics()) { PixelScale = CalcPixelScale(graphics.DpiX); } if (options.Style == WindowStyle.Borderless) { borderStyle = FormBorderStyle.None; } else { borderStyle = options.FixedSize ? FormBorderStyle.FixedSingle : FormBorderStyle.Sizable; } form.FormBorderStyle = borderStyle; form.MaximizeBox = !options.FixedSize; if (options.MinimumDecoratedSize != Vector2.Zero) { MinimumDecoratedSize = options.MinimumDecoratedSize; } if (options.MaximumDecoratedSize != Vector2.Zero) { MaximumDecoratedSize = options.MaximumDecoratedSize; } glControl = CreateGLControl(); glControl.Dock = DockStyle.Fill; glControl.Paint += OnPaint; glControl.KeyDown += OnKeyDown; glControl.KeyUp += OnKeyUp; glControl.KeyPress += OnKeyPress; glControl.MouseDown += OnMouseDown; glControl.MouseUp += OnMouseUp; glControl.Resize += OnResize; glControl.MouseWheel += OnMouseWheel; form.Move += OnMove; form.Activated += OnActivated; form.Deactivate += OnDeactivate; form.FormClosing += OnClosing; form.FormClosed += OnClosed; active = Form.ActiveForm == form; if (options.UseTimer) { timer = new Timer { Interval = (int)(1000.0 / 65), Enabled = true, }; timer.Tick += OnTick; } else { VSync = options.VSync; glControl.MakeCurrent(); glControl.VSync = VSync; System.Windows.Forms.Application.Idle += OnTick; } form.Controls.Add(glControl); stopwatch = new Stopwatch(); stopwatch.Start(); if (options.Icon != null) { form.Icon = (Icon)options.Icon; } Cursor = MouseCursor.Default; Title = options.Title; ClientSize = options.ClientSize; if (options.Visible) { Visible = true; } if (options.Screen != null && options.Screen >= 0 && Screen.AllScreens.Length > options.Screen) { form.Location = GetCenter(Screen.AllScreens[options.Screen.Value].WorkingArea); } if (options.Centered) { Center(); } if (Application.MainWindow == null) { Application.MainWindow = this; Closing += reason => Application.DoExiting(); Closed += Application.DoExited; } else { Form.Owner = Application.MainWindow.Form; Form.StartPosition = FormStartPosition.CenterParent; } Application.Windows.Add(this); }
private void CreateNativeWindow(WindowOptions options) { var rect = new CGRect(0, 0, options.ClientSize.X, options.ClientSize.Y); View = new NSGameView(Input, rect, Platform.GraphicsMode.Default); NSWindowStyle style; if (options.Style == WindowStyle.Borderless) { style = NSWindowStyle.Borderless; } else if (options.Style == WindowStyle.Dialog) { style = NSWindowStyle.Titled; } else { style = NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable; } if (!options.FixedSize) { style |= NSWindowStyle.Resizable; } window = new NSWindow(rect, style, NSBackingStore.Buffered, false); var contentRect = window.ContentRectFor(rect); titleBarHeight = ((RectangleF)rect).Height - (float)contentRect.Height; if (options.MinimumDecoratedSize != Vector2.Zero) { MinimumDecoratedSize = options.MinimumDecoratedSize; } if (options.MaximumDecoratedSize != Vector2.Zero) { MaximumDecoratedSize = options.MaximumDecoratedSize; } window.Title = options.Title; window.WindowShouldClose += OnShouldClose; window.WillClose += OnWillClose; window.DidResize += (s, e) => { View.UpdateGLContext(); HandleResize(s, e); }; window.WillEnterFullScreen += (sender, e) => { shouldFixFullscreen = !window.StyleMask.HasFlag(NSWindowStyle.Resizable); if (shouldFixFullscreen) { window.StyleMask |= NSWindowStyle.Resizable; } windowedClientSize = ClientSize; }; window.WillExitFullScreen += (sender, e) => { ClientSize = windowedClientSize; }; window.DidExitFullScreen += (sender, e) => { if (shouldFixFullscreen) { window.StyleMask &= ~NSWindowStyle.Resizable; } }; window.DidBecomeKey += (sender, e) => { RaiseActivated(); }; window.DidResignKey += (sender, e) => { Input.ClearKeyState(); RaiseDeactivated(); }; #if MAC window.DidMove += HandleMove; #else window.DidMoved += HandleMove; #endif window.CollectionBehavior = NSWindowCollectionBehavior.FullScreenPrimary; window.ContentView = View; window.ReleasedWhenClosed = true; View.Update += Update; View.RenderFrame += HandleRenderFrame; View.FilesDropped += RaiseFilesDropped; }
public Window(WindowOptions options) { if (Application.MainWindow != null && Application.RenderingBackend == RenderingBackend.ES20) { // ES20 doesn't allow multiple contexts for now, because of a bug in OpenTK throw new Lime.Exception("Attempt to create a second window for ES20 rendering backend. Use OpenGL backend instead."); } if (options.UseTimer && options.AsyncRendering) { throw new Lime.Exception("Can't use both timer and async rendering"); } if (options.ToolWindow) { form = new ToolForm(); } else { form = new Form(); } Input = new WindowInput(this); using (var graphics = form.CreateGraphics()) { PixelScale = CalcPixelScale(graphics.DpiX); } if (options.Style == WindowStyle.Borderless) { borderStyle = FormBorderStyle.None; } else { borderStyle = options.FixedSize ? FormBorderStyle.FixedSingle : FormBorderStyle.Sizable; } form.FormBorderStyle = borderStyle; form.MaximizeBox = !options.FixedSize; if (options.MinimumDecoratedSize != Vector2.Zero) { MinimumDecoratedSize = options.MinimumDecoratedSize; } if (options.MaximumDecoratedSize != Vector2.Zero) { MaximumDecoratedSize = options.MaximumDecoratedSize; } renderControl = CreateRenderControl(Application.RenderingBackend); renderControl.CreateControl(); renderControl.UnbindContext(); renderControl.Dock = DockStyle.Fill; renderControl.Paint += OnPaint; renderControl.KeyDown += OnKeyDown; renderControl.KeyUp += OnKeyUp; renderControl.KeyPress += OnKeyPress; renderControl.MouseDown += OnMouseDown; renderControl.MouseUp += OnMouseUp; renderControl.Resize += OnResize; renderControl.MouseWheel += OnMouseWheel; renderControl.MouseEnter += (sender, args) => { Application.WindowUnderMouse = this; }; renderControl.MouseLeave += (sender, args) => { if (Application.WindowUnderMouse == this) { Application.WindowUnderMouse = null; } }; renderControl.BeforeBoundsChanged += WaitForRendering; form.Move += OnMove; form.Activated += OnActivated; form.Deactivate += OnDeactivate; form.FormClosing += OnClosing; form.FormClosed += OnClosed; form.Shown += OnShown; active = Form.ActiveForm == form; if (options.UseTimer) { timer = new System.Windows.Forms.Timer { Interval = (int)(1000.0 / 65), Enabled = true, }; timer.Tick += OnTick; } else { vSync = options.VSync; renderControl.VSync = vSync; System.Windows.Forms.Application.Idle += OnTick; } form.Controls.Add(renderControl); stopwatch = new Stopwatch(); stopwatch.Start(); if (options.Icon != null) { form.Icon = (System.Drawing.Icon)options.Icon; } Cursor = MouseCursor.Default; Title = options.Title; ClientSize = options.ClientSize; if (options.Visible) { Visible = true; } if (options.Screen != null && options.Screen >= 0 && Screen.AllScreens.Length > options.Screen) { form.Location = GetCenter(Screen.AllScreens[options.Screen.Value].WorkingArea); } if (options.Centered) { Center(); } if (Application.MainWindow == null) { Application.MainWindow = this; Closing += reason => Application.DoExiting(); Closed += Application.DoExited; } else { Form.Owner = Application.MainWindow.Form; Form.StartPosition = FormStartPosition.CenterParent; } AsyncRendering = options.AsyncRendering; if (AsyncRendering) { renderThreadTokenSource = new CancellationTokenSource(); renderThreadToken = renderThreadTokenSource.Token; renderThread = new Thread(RenderLoop); renderThread.IsBackground = true; renderThread.Start(); } Application.Windows.Add(this); }
private void CreateNativeWindow(WindowOptions options) { var rect = new CGRect(0, 0, options.ClientSize.X, options.ClientSize.Y); View = new NSGameView(Application.Input, rect, Platform.GraphicsMode.Default); NSWindowStyle style; if (options.Style == WindowStyle.Borderless) { style = NSWindowStyle.Borderless; } else if (options.Style == WindowStyle.Dialog) { style = NSWindowStyle.Titled | NSWindowStyle.Closable; } else { style = NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable; } if (!options.FixedSize) { style |= NSWindowStyle.Resizable; } window = new NSWindow(rect, style, NSBackingStore.Buffered, false); window.TabbingMode = (NSWindowTabbingMode)options.MacWindowTabbingMode; if (options.Style == WindowStyle.Dialog) { window.StandardWindowButton(NSWindowButton.MiniaturizeButton).Hidden = true; window.StandardWindowButton(NSWindowButton.ZoomButton).Hidden = true; } var contentRect = window.ContentRectFor(rect); titleBarHeight = ((RectangleF)rect).Height - (float)contentRect.Height; if (options.MinimumDecoratedSize != Vector2.Zero) { MinimumDecoratedSize = options.MinimumDecoratedSize; } if (options.MaximumDecoratedSize != Vector2.Zero) { MaximumDecoratedSize = options.MaximumDecoratedSize; } window.Title = options.Title; window.WindowShouldClose += OnShouldClose; window.WillClose += OnWillClose; window.DidResize += (s, e) => { needUpdateGLContext = true; HandleResize(s, e); }; window.WillEnterFullScreen += (sender, e) => { shouldFixFullscreen = !window.StyleMask.HasFlag(NSWindowStyle.Resizable); if (shouldFixFullscreen) { window.StyleMask |= NSWindowStyle.Resizable; } windowedClientSize = ClientSize; }; window.WillExitFullScreen += (sender, e) => { ClientSize = windowedClientSize; }; window.DidExitFullScreen += (sender, e) => { if (shouldFixFullscreen) { window.StyleMask &= ~NSWindowStyle.Resizable; } }; window.DidBecomeKey += (sender, e) => { RaiseActivated(); }; window.DidResignKey += (sender, e) => { // Clearing key state on deactivate is required so no keys will get stuck. // If, for some reason, you need to transfer key state between windows use InputSimulator to hack it. See docking implementation in Tangerine. Input.ClearKeyState(); RaiseDeactivated(); }; window.DidMove += HandleMove; NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.WillStartLiveResizeNotification, OnWillStartLiveResize); NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidEndLiveResizeNotification, OnDidEndLiveResize); window.CollectionBehavior = NSWindowCollectionBehavior.FullScreenPrimary; window.ContentView = View; View.Update += Update; View.RenderFrame += HandleRenderFrame; View.FilesDropped += RaiseFilesDropped; View.DidMouseEnter += () => { Application.WindowUnderMouse = this; }; View.DidMouseExit += () => { if (Application.WindowUnderMouse == this) { Application.WindowUnderMouse = null; } }; }