예제 #1
0
        internal static IntPtr Instantiate(NativeWindow window)
        {
            window.nativePointer = SDLI.SDL_CreateWindow(window.title, window.Location.X, window.Location.Y, window.Size.Width, window.Size.Height, (SDL_WINDOW)window.Style);
            window.renderer      = new Renderer(window.nativePointer, window.Size.Width, window.Size.Height);
            EventPump.Instance.RendererUpdate(window.renderer.Update);

            return(window.nativePointer);
        }
예제 #2
0
        internal void Start(ISDLNative hwnd)
        {
            Start(hwnd.SdlSystem);

            if (SDLI.SDL_WasInit(hwnd.SdlSystem) == hwnd.SdlSystem)
            {
                sdlHwnd = hwnd;
                PollEvents(sdlHwnd.Start);
            }
        }
예제 #3
0
        internal bool TrySetWindowState(WindowState windowState, out CharPointer errMessage)
        {
            errMessage = CharPointer.Null;
            bool success = false;

            if (State != windowState)
            {
                switch (windowState)
                {
                case WindowState.FullScreen:
                    SDLI.SDL_MaximizeWindow(nativePointer);
                    success = SDLI.SDL_SetWindowFullscreen(nativePointer, (uint)windowState) == SUCCESS;

                    break;

                case WindowState.Maximized:
                    SDLI.SDL_MaximizeWindow(nativePointer);
                    success = true;

                    break;

                case WindowState.Desktop:

                    break;

                case WindowState.Windowed:
                default:
                    // restore (??) window

                    break;
                }
            }
            else
            {
                // custom message
                errMessage = $"window state already set: {State}";

                return(false);
            }

            if (!success)
            {
                errMessage = SDLI.SDL_GetError;
            }
            else
            {
                State = windowState;
            }

            return(errMessage == CharPointer.Null);
        }
예제 #4
0
        public void Dispose( )
        {
            if (sdlHwnd != null)
            {
                SDLI.SDL_QuitSubSystem(sdlHwnd.SdlSystem);
            }
            else
            {
                SDLI.SDL_QuitSubSystem(SDL_INIT.TIMER);
            }

            SDLI.SDL_Quit();
            sdlHwnd?.Dispose();
        }
예제 #5
0
        /// <summary>
        /// EventPump will only function with one system - TIMER or VIDEO or AUDIO, etc.
        /// Can be stopped and restarted with a different system although the effects of
        /// doing so needs to be fully discovered.
        /// </summary>
        /// <param name="system"></param>
        internal void Start(uint system = SDL_INIT.TIMER)
        {
            if (sdlHwnd == null || SDLI.SDL_WasInit(system) != sdlHwnd.SdlSystem)
            {
                // changing SDL system initialization
                SDLI.SDL_Quit();

                SDLI.SDL_Init(system);
            }

            if (!IsRunning && system == SDL_INIT.TIMER)
            {
                PollEvents();
            }
        }
예제 #6
0
        void ISDLNative.Start(EventPump eventPump)
        {
            if (SDLI.SDL_WasInit(sdlSystem) != sdlSystem)
            {
                // TODO: set error condition
            }

            eventPump.EventPumpStateChanged += EventPumpStateChanged;

            configure?.Invoke();
            nativePointer = SDLI.SDL_CreateWindow(title, location.X, location.Y, size.Width, size.Height, (SDL_WINDOW)Style);
            renderer      = new Renderer(nativePointer, size.Width, size.Height);
            eventPump.RendererUpdate(renderer.Update);

            isInitialized = true;
            initialized?.Invoke(isInitialized);
        }
예제 #7
0
        private void Dispose(bool disposing)
        {
            if (!isDisposed)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                }

                // free unmanaged resources (unmanaged objects) and override a finalizer below.
                SDLI.SDL_DestroyWindow(nativePointer);

                // TODO: set large fields to null.

                isDisposed = true;
            }
        }
예제 #8
0
 internal void SetBackground(byte red, byte green, byte blue, byte alpha)
 {
     SDLI.SDL_SetRenderDrawColor(renderer, red, green, blue, alpha);
 }
예제 #9
0
 public void Update( )
 {
     SDLI.SDL_RenderClear(renderer);
     SDLI.SDL_RenderCopy(renderer, texture, IntPtr.Zero, IntPtr.Zero);
     SDLI.SDL_RenderPresent(renderer);
 }
예제 #10
0
 internal Renderer(IntPtr windowPointer, int width, int height)
 {
     renderer = SDLI.SDL_CreateRenderer(windowPointer, -1, SDL_RENDERERMODES.ACCELERATED);
     surface  = IntPtr.Zero; // SDLI.SDL_CreateRGBSurface(0, width, height, 32, 255, 0, 0, 0);
     texture  = SDLI.SDL_CreateTextureFromSurface(renderer, surface);
 }
예제 #11
0
 /// <summary>
 /// Use when SDL resource needs to be freed
 /// </summary>
 public void Free( )
 {
     SDLI.SDL_Free(pointer);
 }