def _background(self): with _freetype_lock: return ttf_call( TTF_RenderUTF8_Blended, self.font.load(), self.txt.encode('utf-8'), SDL_Color(*self.color), _check_error=lambda rv: not rv )
def __enter__(self): super().__enter__() img_call(IMG_Init, IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF) ttf_call(TTF_Init, _check_error=lambda rv: rv == -1) self.window = ctypes.POINTER(SDL_Window)() self.renderer = ctypes.POINTER(SDL_Renderer)() sdl_call( SDL_CreateWindowAndRenderer, self.resolution[0], # Width self.resolution[1], # Height 0, # Flags # SDL_WINDOW_ALLOW_HIGHDPI - Allow the renderer to work in HiDPI natively ctypes.byref(self.window), ctypes.byref(self.renderer), _check_error=lambda rv: rv < 0) # NOTE: It looks like SDL_RENDERER_PRESENTVSYNC will cause SDL_RenderPresent() to block? sdl_call(SDL_SetWindowTitle, self.window, self.window_title.encode('utf-8'))
def _background(self): self._file = rw_from_object(io.BytesIO(self._data.load())) # We have to keep the file around because freetype doesn't load # everything at once, resulting in segfaults. with _freetype_lock: # Doing this so that we "refcount" the FT_Library internal to SDL_ttf # (TTF_CloseFont is often called after system cleanup) ttf_call(TTF_Init, _check_error=lambda rv: rv == -1) if self.index is None: return ttf_call( TTF_OpenFontRW, self._file, False, self.size, _check_error=lambda rv: not rv ) else: return ttf_call( TTF_OpenFontIndexRW, self._file, False, self.size, self.index, _check_error=lambda rv: not rv )
def __exit__(self, *exc): sdl_call(SDL_DestroyRenderer, self.renderer) sdl_call(SDL_DestroyWindow, self.window) ttf_call(TTF_Quit) img_call(IMG_Quit) super().__exit__(*exc)