예제 #1
0
 /// <summary>
 /// Given a SDL Handle of a SDL window, retrieve the corresponding managed object. If object
 /// was already garbage collected, we will also clean up <see cref="InternalWindows"/>.
 /// </summary>
 /// <param name="w">SDL Handle of the window we are looking for</param>
 /// <returns></returns>
 private static Window WindowFromSdlHandle(Silk.NET.SDL.Window *w)
 {
     lock (InternalWindows)
     {
         WeakReference <Window> weakRef;
         if (InternalWindows.TryGetValue((IntPtr)w, out weakRef))
         {
             Window ctrl;
             if (weakRef.TryGetTarget(out ctrl))
             {
                 return(ctrl);
             }
             else
             {
                 // Window does not exist anymore in our code. Clean `InternalWindows'.
                 InternalWindows.Remove((IntPtr)w);
                 return(null);
             }
         }
         else
         {
             return(null);
         }
     }
 }
예제 #2
0
파일: Window.cs 프로젝트: Alan-love/xenko
        /// <summary>
        /// Initializes a new instance of the <see cref="Window"/> class with <paramref name="title"/> as the title of the Window.
        /// </summary>
        /// <param name="title">Title of the window, see Text property.</param>
        public unsafe Window(string title)
        {
            WindowFlags flags = WindowFlags.WindowAllowHighdpi;

#if STRIDE_GRAPHICS_API_OPENGL
            flags |= WindowFlags.WindowOpengl;
#elif STRIDE_GRAPHICS_API_VULKAN
            flags |= WindowFlags.WindowVulkan;
#endif
#if STRIDE_PLATFORM_ANDROID || STRIDE_PLATFORM_IOS
            flags |= WindowFlags.WindowBorderless | WindowFlags.WindowFullscreen | WindowFlags.WindowShown;
#else
            flags |= WindowFlags.WindowHidden | WindowFlags.WindowResizable;
#endif
            // Create the SDL window and then extract the native handle.
            sdlHandle = SDL.CreateWindow(title, Sdl.WindowposUndefined, Sdl.WindowposUndefined, 640, 480, (uint)flags);

#if STRIDE_PLATFORM_ANDROID || STRIDE_PLATFORM_IOS
            GraphicsAdapter.DefaultWindow = sdlHandle;
#endif

            if (sdlHandle == null)
            {
                throw new Exception("Cannot allocate SDL Window: " + SDL.GetErrorS());
            }

            SysWMInfo info = default;
            SDL.GetVersion(&info.Version);
            if (!SDL.GetWindowWMInfo(sdlHandle, &info))
            {
                throw new Exception("Cannot get Window information: " + SDL.GetErrorS());
            }

            if (Core.Platform.Type == Core.PlatformType.Windows)
            {
                Handle = info.Info.Win.Hwnd;
            }
            else if (Core.Platform.Type == Core.PlatformType.Linux)
            {
                Handle  = (IntPtr)info.Info.X11.Window;
                Display = (IntPtr)info.Info.X11.Display;
            }
            else if (Core.Platform.Type == Core.PlatformType.Android)
            {
                Handle  = (IntPtr)info.Info.Android.Window;
                Surface = (IntPtr)info.Info.Android.Surface;
            }
            else if (Core.Platform.Type == Core.PlatformType.macOS)
            {
                Handle = (IntPtr)info.Info.Cocoa.Window;
            }
            Application.RegisterWindow(this);
            Application.ProcessEvents();
        }
예제 #3
0
파일: Window.cs 프로젝트: Alan-love/xenko
        /// <summary>
        /// Dispose of current Window.
        /// </summary>
        /// <param name="disposing">If <c>false</c> we are being called from the Finalizer.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (sdlHandle != null)
            {
                if (disposing)
                {
                    // Dispose managed state (managed objects).
                    Disposed?.Invoke(this, EventArgs.Empty);
                    Application.UnregisterWindow(this);
                }

                // Free unmanaged resources (unmanaged objects) and override a finalizer below.
                SDL.DestroyWindow(sdlHandle);
                sdlHandle = null;
                Handle    = IntPtr.Zero;
            }
        }