Exemple #1
0
        /// <summary>
        /// Creates a new window and attaches it to the current context.
        /// </summary>
        /// <param name="caption">The window's caption text.</param>
        /// <param name="x">The x-coordinate at which to position the window's top-left corner.</param>
        /// <param name="y">The y-coordinate at which to position the window's top-left corner.</param>
        /// <param name="width">The width of the window's client area in pixels.</param>
        /// <param name="height">The height of the window's client area in pixels.</param>
        /// <param name="flags">A set of WindowFlags values indicating how to create the window.</param>
        /// <returns>The Ultraviolet window that was created.</returns>
        public IUltravioletWindow Create(String caption, Int32 x, Int32 y, Int32 width, Int32 height, WindowFlags flags = WindowFlags.None)
        {
            var sdlflags = SDL_WindowFlags.OPENGL;

            if (Ultraviolet.SupportsHighDensityDisplayModes)
            {
                sdlflags |= SDL_WindowFlags.ALLOW_HIGHDPI;
            }

            if ((flags & WindowFlags.Resizable) == WindowFlags.Resizable)
            {
                sdlflags |= SDL_WindowFlags.RESIZABLE;
            }

            if ((flags & WindowFlags.Borderless) == WindowFlags.Borderless)
            {
                sdlflags |= SDL_WindowFlags.BORDERLESS;
            }

            if ((flags & WindowFlags.Hidden) == WindowFlags.Hidden)
            {
                sdlflags |= SDL_WindowFlags.HIDDEN;
            }
            else
            {
                sdlflags |= SDL_WindowFlags.SHOWN;
            }

            var sdlptr = SDL.CreateWindow(caption ?? String.Empty, x, y, width, height, sdlflags);

            if (sdlptr == IntPtr.Zero)
            {
                throw new SDL2Exception();
            }

            var win = new OpenGLUltravioletWindow(Ultraviolet, sdlptr);

            windows.Add(win);

            Ultraviolet.Messages.Subscribe(win, SDL2UltravioletMessages.SDLEvent);

            OnWindowCreated(win);

            return(win);
        }
        /// <summary>
        /// Creates a new Ultraviolet window from the specified native window and attaches it to the current context.
        /// </summary>
        /// <param name="ptr">A pointer that represents the native window to attach to the context.</param>
        /// <returns>The Ultraviolet window that was created.</returns>
        public IUltravioletWindow CreateFromNativePointer(IntPtr ptr)
        {
            var sdlptr = SDL.CreateWindowFrom(ptr);

            if (sdlptr == IntPtr.Zero)
            {
                throw new SDL2Exception();
            }

            var win = new OpenGLUltravioletWindow(Ultraviolet, sdlptr);

            windows.Add(win);

            Ultraviolet.Messages.Subscribe(win, SDL2UltravioletMessages.SDLEvent);

            OnWindowCreated(win);

            return(win);
        }