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); }
internal void Start(ISDLNative hwnd) { Start(hwnd.SdlSystem); if (SDLI.SDL_WasInit(hwnd.SdlSystem) == hwnd.SdlSystem) { sdlHwnd = hwnd; PollEvents(sdlHwnd.Start); } }
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); }
public void Dispose( ) { if (sdlHwnd != null) { SDLI.SDL_QuitSubSystem(sdlHwnd.SdlSystem); } else { SDLI.SDL_QuitSubSystem(SDL_INIT.TIMER); } SDLI.SDL_Quit(); sdlHwnd?.Dispose(); }
/// <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(); } }
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); }
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; } }
internal void SetBackground(byte red, byte green, byte blue, byte alpha) { SDLI.SDL_SetRenderDrawColor(renderer, red, green, blue, alpha); }
public void Update( ) { SDLI.SDL_RenderClear(renderer); SDLI.SDL_RenderCopy(renderer, texture, IntPtr.Zero, IntPtr.Zero); SDLI.SDL_RenderPresent(renderer); }
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); }
/// <summary> /// Use when SDL resource needs to be freed /// </summary> public void Free( ) { SDLI.SDL_Free(pointer); }