示例#1
0
 def background_parse(self, data):
     file = rw_from_object(io.BytesIO(data))
     # ^^^^ is a pure-python emulation, does not need cleanup.
     return _call(
         Mix_LoadWAV_RW, file, False,
         _check_error=lambda rv: not rv
     )
示例#2
0
 def background_parse(self, data):
     # Band-aid over some synchronization issues
     # https://github.com/ppb/pursuedpybear/issues/619
     while not any(query_spec()):
         time.sleep(0)
     file = rw_from_object(io.BytesIO(data))
     # ^^^^ is a pure-python emulation, does not need cleanup.
     return mix_call(Mix_LoadWAV_RW,
                     file,
                     False,
                     _check_error=lambda rv: not rv)
示例#3
0
    def background_parse(self, data):
        file = rw_from_object(io.BytesIO(data))
        # ^^^^ is a pure-python emulation, does not need cleanup.
        surface = img_call(IMG_Load_RW,
                           file,
                           False,
                           _check_error=lambda rv: not rv)

        sdl_call(SDL_SetSurfaceBlendMode,
                 surface,
                 SDL_BLENDMODE_BLEND,
                 _check_error=lambda rv: rv < 0)

        return surface
示例#4
0
 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
             )
示例#5
0
def load_font(manager, fp, cwd):
    """Loader for font files.

    :param manager: The resource manager
    :type manager: :class:`loaders.ResourceManager`

    :param fp: The file pointer
    :type fp: File

    :param cwd: The current working directory
    :type cwd: str

    :returns: Simply the bytes read from file
    :rtype: :class:`sdl2.SDL_RWops.`
    """
    from io import BytesIO
    from sdl2 import rw_from_object
    content = fp.read()
    return rw_from_object(BytesIO(content))
示例#6
0
def surface_to_pil(surf):
    bmp = io.BytesIO()
    sdl2.SDL_SaveBMP_RW(surf, sdl2.rw_from_object(bmp), False)
    return PIL.Image.open(bmp)
示例#7
0
文件: font.py 项目: sim1234/snowid
def get_font(size: int) -> sdl2.sdlttf.TTF_Font:
    if sdl2.sdlttf.TTF_WasInit() == 0 and sdl2.sdlttf.TTF_Init() != 0:
        raise sdl2.ext.SDLError()
    return sdl2.sdlttf.TTF_OpenFontRW(
        sdl2.rw_from_object(io.BytesIO(font_data)), 1, size)
示例#8
0
def fs_to_rwops(handle):
    return sdl2.rw_from_object(RWOpsWrapper(handle))