コード例 #1
0
        /// <summary>
        /// Creates a new SDL_Window with the given renderer attached.
        /// </summary>
        /// <param name="renderer">The renderer to attach to this window.</param>
        /// <param name="createInfo">The creation parameters to use when building this window.</param>
        internal SimpleSDLWindow(IRenderer renderer, WindowCreateInfo createInfo)
        {
            if (SDL_Init(SDL_INIT_VIDEO) != 0)
            {
                throw new Exception("SDL_Init error: " + SDL_GetError());
            }

            InitForRenderer(renderer);

            var windowFlags = WindowCreationFlags(createInfo);

            if (createInfo.Fullscreen)
            {
                // without this, clicking off the window (eg, to another monitor) will minimize and cause positioning issues
                SDL_SetHint("SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS", "0");
            }

            Window = SDL_CreateWindow(createInfo.Title, createInfo.XPos, createInfo.YPos, createInfo.Width, createInfo.Height, windowFlags);
            if (Window == IntPtr.Zero)
            {
                SDL_Quit();
                throw new Exception("Failed to create window: " + SDL_GetError());
            }

            if (createInfo.TransparentColor != null)
            {
                var colorKey = CreateColorKey(createInfo.TransparentColor[0], createInfo.TransparentColor[1], createInfo.TransparentColor[2]);
                MakeTransparent(colorKey);
            }

            renderer.AttachToWindow(this);
        }
コード例 #2
0
        /// <summary>
        /// Creates a window configured for use with the specified renderer.
        /// </summary>
        /// <param name="renderer">The renderer to use with this window.</param>
        /// <param name="createInfo">The <see cref="WindowCreateInfo"/> specifying the details of window creation.</param>
        /// <returns></returns>
        public static SimpleSDLWindow CreateForRenderer(IRenderer renderer, WindowCreateInfo createInfo)
        {
            switch (renderer.Type)
            {
            case RendererFactory.RendererBackend.OpenGL3:
                return(new SDLWindowGL(renderer, createInfo));

            default:
                return(new SimpleSDLWindow(renderer, createInfo));
            }
        }
コード例 #3
0
        /// <summary>
        /// Return the set of window flags necessary to create a window matching what is requested in <paramref name="createInfo"/>
        /// </summary>
        /// <param name="createInfo">The requested creation parameters for the window.</param>
        /// <returns>The full set of SDL_WindowFlags to use when creating this window.</returns>
        protected virtual SDL_WindowFlags WindowCreationFlags(WindowCreateInfo createInfo)
        {
            var flags = SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI | SDL_WindowFlags.SDL_WINDOW_HIDDEN;

            if (createInfo.Fullscreen)
            {
                flags |= SDL_WindowFlags.SDL_WINDOW_BORDERLESS | SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WindowFlags.SDL_WINDOW_SKIP_TASKBAR;
            }

            // Transparent windows are neat but almost certainly don't work as intended unless they are forced to remain on top of everything
            // also don't show the window in the taskbar since this is functioning as an overlay
            if (createInfo.TransparentColor != null)
            {
                flags |= SDL_WindowFlags.SDL_WINDOW_ALWAYS_ON_TOP | SDL_WindowFlags.SDL_WINDOW_SKIP_TASKBAR;
            }

            return(flags);
        }
コード例 #4
0
ファイル: SDLWindowGL.cs プロジェクト: lmcintyre/ImGuiScene
        /// <summary>
        /// Return the set of window flags necessary to create a window matching what is requested in <paramref name="createInfo"/>
        /// </summary>
        /// <param name="createInfo">The requested creation parameters for the window.</param>
        /// <returns>The full set of SDL_WindowFlags to use when creating this window.</returns>
        protected override SDL_WindowFlags WindowCreationFlags(WindowCreateInfo createInfo)
        {
            var flags = base.WindowCreationFlags(createInfo) | SDL_WindowFlags.SDL_WINDOW_OPENGL;

            if (createInfo.Fullscreen && createInfo.TransparentColor != null)
            {
                // OpenGL seemingly can't render transparent fullscreen windows, regardless of window styles
                // However, borderless 'regular' windows that just happen to be the same size as the screen will work
                // ...except in SDL, where it appears to detect that and make it 'real' fullscreen, so instead we have
                // to reduce the size by 1 pixel

                flags &= ~SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;

                // TODO: proper monitor detection
                SDL_GetCurrentDisplayMode(0, out SDL_DisplayMode mode);

                createInfo.XPos   = 0;
                createInfo.YPos   = 0;
                createInfo.Width  = mode.w - 1;
                createInfo.Height = mode.h - 1;
            }

            return(flags);
        }
コード例 #5
0
ファイル: SDLWindowGL.cs プロジェクト: lmcintyre/ImGuiScene
 internal SDLWindowGL(IRenderer renderer, WindowCreateInfo createInfo) : base(renderer, createInfo)
 {
 }