def __init__(self, lcd, w, h, scale, title, pos=(sdl2.SDL_WINDOWPOS_CENTERED, sdl2.SDL_WINDOWPOS_CENTERED), hide_window=False): self.lcd = lcd self.width = w self.height = h self.mouse_hover_x = -1 self.mouse_hover_y = -1 self.mouse_x = -1 self.mouse_y = -1 self.scale = scale self.window = sdl2.SDL_CreateWindow( title, pos[0], pos[1], w*scale, h*scale, sdl2.SDL_WINDOW_RESIZABLE) self.buf, self.buf0, self.buf_p = make_buffer(w, h) self.sdlrenderer = sdl2.SDL_CreateRenderer(self.window, -1, sdl2.SDL_RENDERER_ACCELERATED) self.sdl_texture_buffer = sdl2.SDL_CreateTexture( self.sdlrenderer, sdl2.SDL_PIXELFORMAT_RGBA32, sdl2.SDL_TEXTUREACCESS_STATIC, w, h ) if hide_window: sdl2.SDL_HideWindow(self.window) else: sdl2.SDL_ShowWindow(self.window)
def init(self, hide_window): self._ticks = sdl2.SDL_GetTicks() # Should be less... https://wiki.libsdl.org/SDL_Init sdl2.SDL_Init(sdl2.SDL_INIT_EVERYTHING) self._window = sdl2.SDL_CreateWindow(b"PyBoy", sdl2.SDL_WINDOWPOS_CENTERED, sdl2.SDL_WINDOWPOS_CENTERED, self._scaledresolution[0], self._scaledresolution[1], sdl2.SDL_WINDOW_RESIZABLE) self._sdlrenderer = sdl2.SDL_CreateRenderer( self._window, -1, sdl2.SDL_RENDERER_ACCELERATED) self._sdltexturebuffer = sdl2.SDL_CreateTexture( self._sdlrenderer, sdl2.SDL_PIXELFORMAT_RGBA32, sdl2.SDL_TEXTUREACCESS_STATIC, COLS, ROWS) self.blank_screen() if hide_window: sdl2.SDL_HideWindow(self._window) else: sdl2.SDL_ShowWindow(self._window)
def quit(self): self.is_running = False # Give time for the other thread to end ti.sleep(0.05) # Destroy the SDL context sdl2.SDL_DestroyRenderer(self.renderer) sdl2.SDL_HideWindow(self.window) sdl2.SDL_DestroyWindow(self.window) sdl2.SDL_Quit()
def dispose(self): if self._window is not None: sdl2.SDL_HideWindow(self._window) if self._timer is not None: self._loop.destroy_timer(self._timer) self._timer = None if self._window is not None: sdl2.SDL_DestroyWindow(self._window) self._window = None if self._glcontext is not None: sdl2.SDL_GL_DeleteContext(self._glcontext) self._glcontext = None
def hide(self): sdl2.SDL_HideWindow(self._native_window) self.dispatch_event('on_hide')