public override void ShowSystemWindow(SystemWindow systemWindow) { if (platformWindow == null) { glfwPlatformWindow = new GlfwPlatformWindow { WindowProvider = this }; platformWindow = glfwPlatformWindow; } base.ShowSystemWindow(systemWindow); systemWindow.PlatformWindow = glfwPlatformWindow; }
private void Show() { // Glfw.WindowHint(Hint.Decorated, false); var config = AggContext.Config.GraphicsMode; Glfw.WindowHint(Hint.Samples, config.FSAASamples); Glfw.WindowHint(Hint.Visible, false); // this line causing crash on windows tablet Glfw.WindowHint(Hint.CocoaRetinaFrameBuffer, true); var screenSize = Glfw.PrimaryMonitor.WorkArea; // Create window if (aggSystemWindow.Maximized) { aggSystemWindow.Width = screenSize.Width; aggSystemWindow.Height = screenSize.Height - screenSize.Y; } glfwWindow = Glfw.CreateWindow((int)aggSystemWindow.Width, (int)aggSystemWindow.Height, aggSystemWindow.Title, GLFW.Monitor.None, Window.None); Glfw.MakeContextCurrent(glfwWindow); // Effectively enables VSYNC by setting to 1. Glfw.SwapInterval(1); aggSystemWindow.PlatformWindow = this; Glfw.SetWindowSizeLimits(glfwWindow, (int)aggSystemWindow.MinimumSize.X, (int)aggSystemWindow.MinimumSize.Y, -1, -1); if (aggSystemWindow.Maximized) { // TODO: make this right Glfw.SetWindowPosition(glfwWindow, 0, 0); Glfw.MaximizeWindow(glfwWindow); } else if (aggSystemWindow.InitialDesktopPosition == new Point2D(-1, -1)) { // Find center position based on window and monitor sizes var x = (screenSize.Width - (int)aggSystemWindow.Width) / 2; var y = (screenSize.Height - (int)aggSystemWindow.Height) / 2; Glfw.SetWindowPosition(glfwWindow, x, y); } else { Glfw.SetWindowPosition(glfwWindow, (int)aggSystemWindow.InitialDesktopPosition.x, (int)aggSystemWindow.InitialDesktopPosition.y); } staticThis = this; Glfw.SetWindowSizeCallback(glfwWindow, (a, b, c) => staticThis.SizeCallback(a, b, c)); Glfw.SetWindowMaximizeCallback(glfwWindow, (a, b) => staticThis.MaximizeCallback(a, b)); Glfw.SetWindowIconifyCallback(glfwWindow, (a, b) => staticThis.IconifyCallback(a, b)); // Set a key callback Glfw.SetKeyCallback(glfwWindow, (a, b, c, d, e) => staticThis.KeyCallback(a, b, c, d, e)); Glfw.SetCharCallback(glfwWindow, (a, b) => staticThis.CharCallback(a, b)); Glfw.SetCursorPositionCallback(glfwWindow, (a, b, c) => staticThis.CursorPositionCallback(a, b, c)); Glfw.SetMouseButtonCallback(glfwWindow, (a, b, c, d) => staticThis.MouseButtonCallback(a, b, c, d)); Glfw.SetScrollCallback(glfwWindow, (a, b, c) => staticThis.ScrollCallback(a, b, c)); Glfw.SetCloseCallback(glfwWindow, (a) => staticThis.CloseCallback(a)); Glfw.SetDropCallback(glfwWindow, (a, b, c) => staticThis.DropCallback(a, b, c)); var applicationIcon = StaticData.Instance.LoadIcon("application.png"); if (applicationIcon != null) { Glfw.SetWindowIcon(glfwWindow, 2, new Image[] { ConvertImageBufferToImage(applicationIcon), ConvertImageBufferToImage(applicationIcon.CreateScaledImage(16, 16)) }); } // set the gl renderer to the GLFW specific one rather than the OpenTk one var glfwGl = new GlfwGL(); GL.Instance = glfwGl; Glfw.ShowWindow(glfwWindow); while (!Glfw.WindowShouldClose(glfwWindow)) { // Poll for OS events and swap front/back buffers Glfw.PollEvents(); ConditionalDrawAndRefresh(aggSystemWindow); // keep the event thread running UiThread.InvokePendingActions(); // the mac does not report maximize changes correctly var maximized = Glfw.GetWindowAttribute(glfwWindow, WindowAttribute.Maximized); if (maximized != aggSystemWindow.Maximized) { aggSystemWindow.Maximized = maximized; } Thread.Sleep(1); } }