示例#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);
        }