/// <summary> /// Queries GLFW to get the client area of the monitor. /// </summary> private unsafe void GetClientArea() { GLFW.GetMonitorPos(HandleAsPtr, out int x, out int y); var videoMode = GLFW.GetVideoMode(HandleAsPtr); ClientArea = new Box2i(x, y, x + videoMode->Width, y + videoMode->Height); }
/// <summary> /// Queries GLFW to get the client area of the monitor. /// </summary> private unsafe void GetClientArea() { GLFW.GetMonitorPos(_handle, out int x, out int y); var videoMode = GLFW.GetVideoMode(_handle); ClientArea = new Rectangle(x, y, videoMode->Width, videoMode->Height); }
private static void SetUpMonitorData() { ImGuiPlatformIOPtr platformIO = ImGui.GetPlatformIO(); var platformMonitors = new List <ImGuiPlatformMonitor>(); { Monitor *[] monitors = GLFW.GetMonitors(); for (int i = 0; i < monitors.Length; i++) { Monitor * monitor = monitors[i]; ImGuiPlatformMonitor m = new ImGuiPlatformMonitor(); var vidMode = GLFW.GetVideoMode(monitor); GLFW.GetMonitorPos(monitor, out int x, out int y); m.MainPos = m.WorkPos = new Vector2(x, y); m.MainSize = m.WorkSize = new Vector2(vidMode->Width, vidMode->Height); GLFW.GetMonitorContentScale(monitor, out float xScale, out float yScale); m.DpiScale = xScale; platformMonitors.Add(m); } } _monitorData = platformMonitors.ToArray(); _monitorDataPin = GCHandle.Alloc(_monitorData, GCHandleType.Pinned); var platformMonitorsPtrs = new ImGuiPlatformMonitorPtr[_monitorData.Length]; for (int i = 0; i < _monitorData.Length; i++) { fixed(ImGuiPlatformMonitor *ptr = &_monitorData[i]) { platformMonitorsPtrs[i] = new ImGuiPlatformMonitorPtr(ptr); } } _monitorPtrData = platformMonitorsPtrs; _monitorPtrDataPin = GCHandle.Alloc(_monitorPtrData, GCHandleType.Pinned); _monitorsPtrVector = new ImVector <ImGuiPlatformMonitor>(_monitorPtrData.Length, _monitorPtrData.Length, _monitorDataPin.AddrOfPinnedObject()); { ImGuiPlatformIO *ptr = platformIO; ImVector v = Unsafe.As <ImVector <ImGuiPlatformMonitor>, ImVector>(ref _monitorsPtrVector); ptr->Monitors = v; } }
// glfwGetWindowMonitor only works for fullscreen windows. // Picks the monitor with the top-left corner of the window. private Monitor *MonitorForWindow(Window *window) { GLFW.GetWindowPos(window, out var winPosX, out var winPosY); var monitors = GLFW.GetMonitorsRaw(out var count); for (var i = 0; i < count; i++) { var monitor = monitors[i]; GLFW.GetMonitorPos(monitor, out var monPosX, out var monPosY); var videoMode = GLFW.GetVideoMode(monitor); var box = Box2i.FromDimensions(monPosX, monPosY, videoMode->Width, videoMode->Height); if (box.Contains(winPosX, winPosY)) { return(monitor); } } // Fallback return(GLFW.GetPrimaryMonitor()); }
private Window *CreateGlfwWindowForRenderer( GLContextSpec?spec, WindowCreateParameters parameters, Window *contextShare, Window *ownerWindow) { GLFW.WindowHint(WindowHintString.X11ClassName, "RobustToolbox"); GLFW.WindowHint(WindowHintString.X11InstanceName, "RobustToolbox"); GLFW.WindowHint(WindowHintBool.ScaleToMonitor, true); if (spec == null) { // No OpenGL context requested. GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.NoApi); } else { var s = spec.Value; #if DEBUG GLFW.WindowHint(WindowHintBool.OpenGLDebugContext, true); #endif GLFW.WindowHint(WindowHintInt.ContextVersionMajor, s.Major); GLFW.WindowHint(WindowHintInt.ContextVersionMinor, s.Minor); GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, s.Profile != GLContextProfile.Compatibility); GLFW.WindowHint(WindowHintBool.SrgbCapable, true); switch (s.Profile) { case GLContextProfile.Compatibility: GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Any); GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlApi); break; case GLContextProfile.Core: GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core); GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlApi); break; case GLContextProfile.Es: GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Any); GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlEsApi); break; } GLFW.WindowHint(WindowHintContextApi.ContextCreationApi, s.CreationApi == GLContextCreationApi.Egl ? ContextApi.EglContextApi : ContextApi.NativeContextApi); #if !FULL_RELEASE if (s.CreationApi == GLContextCreationApi.Egl && !_eglLoaded && OperatingSystem.IsWindows()) { // On non-published builds (so, development), GLFW can't find libEGL.dll // because it'll be in runtimes/<rid>/native/ instead of next to the actual executable. // We manually preload the library here so that GLFW will find it when it does its thing. NativeLibrary.TryLoad( "libEGL.dll", typeof(Clyde).Assembly, DllImportSearchPath.SafeDirectories, out _); _eglLoaded = true; } #endif } Monitor *monitor = null; if (parameters.Monitor != null && _winThreadMonitors.TryGetValue(parameters.Monitor.Id, out var monitorReg)) { monitor = monitorReg.Ptr; var mode = GLFW.GetVideoMode(monitor); // Set refresh rate to monitor's so that GLFW doesn't manually select one. GLFW.WindowHint(WindowHintInt.RefreshRate, mode->RefreshRate); } else { GLFW.WindowHint(WindowHintInt.RefreshRate, -1); } GLFW.WindowHint(WindowHintBool.Visible, false); GLFW.WindowHint(WindowHintInt.RedBits, 8); GLFW.WindowHint(WindowHintInt.GreenBits, 8); GLFW.WindowHint(WindowHintInt.BlueBits, 8); GLFW.WindowHint(WindowHintInt.AlphaBits, 8); GLFW.WindowHint(WindowHintInt.StencilBits, 8); var window = GLFW.CreateWindow( parameters.Width, parameters.Height, parameters.Title, parameters.Fullscreen ? monitor : null, contextShare); // Check if window failed to create. if (window == null) { return(null); } if (parameters.Maximized) { GLFW.GetMonitorPos(monitor, out var x, out var y); GLFW.SetWindowPos(window, x, y); GLFW.MaximizeWindow(window); } if ((parameters.Styles & OSWindowStyles.NoTitleOptions) != 0) { if (OperatingSystem.IsWindows()) { var hWnd = (HWND)GLFW.GetWin32Window(window); DebugTools.Assert(hWnd != HWND.NULL); Windows.SetWindowLongPtrW( hWnd, GWL.GWL_STYLE, // Cast to long here to work around a bug in rider with nint bitwise operators. (nint)((long)Windows.GetWindowLongPtrW(hWnd, GWL.GWL_STYLE) & ~WS.WS_SYSMENU)); } else { _sawmill.Warning("OSWindowStyles.NoTitleOptions not implemented on this platform"); } } if (ownerWindow != null) { if (OperatingSystem.IsWindows()) { var hWnd = (HWND)GLFW.GetWin32Window(window); var ownerHWnd = (HWND)GLFW.GetWin32Window(ownerWindow); DebugTools.Assert(hWnd != HWND.NULL); Windows.SetWindowLongPtrW( hWnd, GWLP.GWLP_HWNDPARENT, ownerHWnd); } else { _sawmill.Warning("owner windows not implemented on this platform"); } if (parameters.StartupLocation == WindowStartupLocation.CenterOwner) { // TODO: Maybe include window frames in size calculations here? // Figure out frame sizes of both windows. GLFW.GetWindowPos(ownerWindow, out var ownerX, out var ownerY); GLFW.GetWindowSize(ownerWindow, out var ownerW, out var ownerH); // Re-fetch this in case DPI scaling is changing it I guess. GLFW.GetWindowSize(window, out var thisW, out var thisH); GLFW.SetWindowPos(window, ownerX + (ownerW - thisW) / 2, ownerY + (ownerH - thisH) / 2); } } if (parameters.Visible) { GLFW.ShowWindow(window); } return(window); }
private Window *CreateGlfwWindowForRenderer( Renderer r, WindowCreateParameters parameters, Window *contextShare) { #if DEBUG GLFW.WindowHint(WindowHintBool.OpenGLDebugContext, true); #endif GLFW.WindowHint(WindowHintString.X11ClassName, "SS14"); GLFW.WindowHint(WindowHintString.X11InstanceName, "SS14"); if (r == Renderer.OpenGL33) { GLFW.WindowHint(WindowHintInt.ContextVersionMajor, 3); GLFW.WindowHint(WindowHintInt.ContextVersionMinor, 3); GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, true); GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlApi); GLFW.WindowHint(WindowHintContextApi.ContextCreationApi, ContextApi.NativeContextApi); GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core); GLFW.WindowHint(WindowHintBool.SrgbCapable, true); } else if (r == Renderer.OpenGL31) { GLFW.WindowHint(WindowHintInt.ContextVersionMajor, 3); GLFW.WindowHint(WindowHintInt.ContextVersionMinor, 1); GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, false); GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlApi); GLFW.WindowHint(WindowHintContextApi.ContextCreationApi, ContextApi.NativeContextApi); GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Any); GLFW.WindowHint(WindowHintBool.SrgbCapable, true); } else if (r == Renderer.OpenGLES2) { GLFW.WindowHint(WindowHintInt.ContextVersionMajor, 2); GLFW.WindowHint(WindowHintInt.ContextVersionMinor, 0); GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, true); GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlEsApi); // GLES2 is initialized through EGL to allow ANGLE usage. // (It may be an idea to make this a configuration cvar) GLFW.WindowHint(WindowHintContextApi.ContextCreationApi, ContextApi.EglContextApi); GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Any); GLFW.WindowHint(WindowHintBool.SrgbCapable, false); if (!_eglLoaded && OperatingSystem.IsWindows()) { // On non-published builds (so, development), GLFW can't find libEGL.dll // because it'll be in runtimes/<rid>/native/ instead of next to the actual executable. // We manually preload the library here so that GLFW will find it when it does its thing. NativeLibrary.TryLoad( "libEGL.dll", typeof(Clyde).Assembly, DllImportSearchPath.SafeDirectories, out _); _eglLoaded = true; } } Monitor *monitor = null; if (parameters.Monitor != null && _winThreadMonitors.TryGetValue(parameters.Monitor.Id, out var monitorReg)) { monitor = monitorReg.Ptr; } GLFW.WindowHint(WindowHintBool.Visible, false); var window = GLFW.CreateWindow( parameters.Width, parameters.Height, parameters.Title, parameters.Fullscreen ? monitor : null, contextShare); // Check if window failed to create. if (window == null) { return(null); } if (parameters.Maximized) { GLFW.GetMonitorPos(monitor, out var x, out var y); GLFW.SetWindowPos(window, x, y); GLFW.MaximizeWindow(window); } if (parameters.Visible) { GLFW.ShowWindow(window); } return(window); }
private Window *CreateGlfwWindowForRenderer( Renderer r, WindowCreateParameters parameters, Window *contextShare) { #if DEBUG GLFW.WindowHint(WindowHintBool.OpenGLDebugContext, true); #endif GLFW.WindowHint(WindowHintString.X11ClassName, "SS14"); GLFW.WindowHint(WindowHintString.X11InstanceName, "SS14"); if (r == Renderer.OpenGL33) { GLFW.WindowHint(WindowHintInt.ContextVersionMajor, 3); GLFW.WindowHint(WindowHintInt.ContextVersionMinor, 3); GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, true); GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlApi); GLFW.WindowHint(WindowHintContextApi.ContextCreationApi, ContextApi.NativeContextApi); GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core); GLFW.WindowHint(WindowHintBool.SrgbCapable, true); } else if (r == Renderer.OpenGL31) { GLFW.WindowHint(WindowHintInt.ContextVersionMajor, 3); GLFW.WindowHint(WindowHintInt.ContextVersionMinor, 1); GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, false); GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlApi); GLFW.WindowHint(WindowHintContextApi.ContextCreationApi, ContextApi.NativeContextApi); GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Any); GLFW.WindowHint(WindowHintBool.SrgbCapable, true); } else if (r == Renderer.OpenGLES2) { GLFW.WindowHint(WindowHintInt.ContextVersionMajor, 2); GLFW.WindowHint(WindowHintInt.ContextVersionMinor, 0); GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, true); GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlEsApi); // GLES2 is initialized through EGL to allow ANGLE usage. // (It may be an idea to make this a configuration cvar) GLFW.WindowHint(WindowHintContextApi.ContextCreationApi, ContextApi.EglContextApi); GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Any); GLFW.WindowHint(WindowHintBool.SrgbCapable, false); } Monitor *monitor = null; if (parameters.Monitor != null && _winThreadMonitors.TryGetValue(parameters.Monitor.Id, out var monitorReg)) { monitor = monitorReg.Ptr; } GLFW.WindowHint(WindowHintBool.Visible, false); var window = GLFW.CreateWindow( parameters.Width, parameters.Height, parameters.Title, parameters.Fullscreen ? monitor : null, contextShare); // Check if window failed to create. if (window == null) { return(null); } if (parameters.Maximized) { GLFW.GetMonitorPos(monitor, out var x, out var y); GLFW.SetWindowPos(window, x, y); GLFW.MaximizeWindow(window); } if (parameters.Visible) { GLFW.ShowWindow(window); } return(window); }