コード例 #1
0
ファイル: display.py プロジェクト: vavilon/pygame_cffi
def mode_ok(size, flags=0, depth=None):
    """ mode_ok(size, flags=0, depth=0) -> depth
    Pick the best color depth for a display mode
    """
    w, h = size
    if depth is None:
        depth = sdl.SDL_GetVideoInfo().vfmt.BitsPerPixel
    return sdl.SDL_VideoModeOK(w, h, depth, flags)
コード例 #2
0
ファイル: display.py プロジェクト: vavilon/pygame_cffi
def list_modes(depth=None, flags=sdl.SDL_FULLSCREEN):
    """ list_modes(depth=0, flags=pygame.FULLSCREEN) -> list
    Get list of available fullscreen modes
    """
    check_video()

    format = ffi.new('SDL_PixelFormat*')
    if depth is None:
        format.BitsPerPixel = sdl.SDL_GetVideoInfo().vfmt.BitsPerPixel
    else:
        format.BitsPerPixel = depth

    rects = sdl.SDL_ListModes(format, flags)
    if rects == ffi.NULL:
        return []

    counter = 0
    rect = rects[0]
    sizes = []
    while rect != ffi.NULL:
        sizes.append((rect.w, rect.h))
        counter += 1
        rect = rects[counter]
    return sizes
コード例 #3
0
    def __init__(self, size, flags=0, depth=0, masks=None):
        w, h = unpack_rect(size)

        if isinstance(depth, Surface):
            if masks:
                raise ValueError(
                    "cannot pass surface for depth and color masks")
            surface = depth
            depth = 0
        else:
            surface = None
            depth = int(depth)

        if depth and masks:
            Rmask, Gmask, Bmask, Amask = masks
            bpp = depth

        elif surface is None:
            if depth:
                bpp = depth
                Rmask, Gmask, Bmask, Amask = \
                    self._get_default_masks(bpp, False)
            elif sdl.SDL_GetVideoSurface():
                pix = sdl.SDL_GetVideoSurface().format
                bpp = pix.BitsPerPixel
                Amask = pix.Amask
                Rmask = pix.Rmask
                Gmask = pix.Gmask
                Bmask = pix.Bmask
            elif sdl.SDL_WasInit(sdl.SDL_INIT_VIDEO):
                pix = sdl.SDL_GetVideoInfo().vfmt
                bpp = pix.BitsPerPixel
                Amask = pix.Amask
                Rmask = pix.Rmask
                Gmask = pix.Gmask
                Bmask = pix.Bmask
            else:
                bpp = 32
                Rmask, Gmask, Bmask, Amask = \
                    self._get_default_masks(32, False)
            # the alpha mask might be different - must update
            if flags & sdl.SDL_SRCALPHA:
                Rmask, Gmask, Bmask, Amask = \
                    self._get_default_masks(bpp, True)

        # depth argument was a Surface object
        else:
            pix = surface._c_surface.format
            bpp = pix.BitsPerPixel
            if flags & sdl.SDL_SRCALPHA:
                Rmask, Gmask, Bmask, Amask = \
                    self._get_default_masks(bpp, True)
            else:
                Amask = pix.Amask
                Rmask = pix.Rmask
                Gmask = pix.Gmask
                Bmask = pix.Bmask

        self._c_surface = sdl.SDL_CreateRGBSurface(flags, w, h, bpp, Rmask,
                                                   Gmask, Bmask, Amask)
        self._format = self._c_surface.format
        self._w = self._c_surface.w
        self._h = self._c_surface.h

        if not self._c_surface:
            raise SDLError.from_sdl_error()

        if masks:
            """
            Confirm the surface was created correctly (masks were valid).
            Also ensure that 24 and 32 bit surfaces have 8 bit fields
            (no losses).
            """
            format = self._format
            Rmask = (0xFF >> format.Rloss) << format.Rshift
            Gmask = (0xFF >> format.Gloss) << format.Gshift
            Bmask = (0xFF >> format.Bloss) << format.Bshift
            Amask = (0xFF >> format.Aloss) << format.Ashift
            bad_loss = format.Rloss or format.Gloss or format.Bloss
            if flags & sdl.SDL_SRCALPHA:
                bad_loss = bad_loss or format.Aloss
            else:
                bad_loss = bad_loss or format.Aloss != 8
            if (format.Rmask != Rmask or format.Gmask != Gmask
                    or format.Bmask != Bmask or format.Amask != Amask
                    or (format.BytesPerPixel >= 3 and bad_loss)):
                # Note: don't free _c_surface here. It will
                # be done in __del__.
                raise ValueError("Invalid mask values")
コード例 #4
0
ファイル: display.py プロジェクト: vavilon/pygame_cffi
def Info():
    """ Info() -> VideoInfo
    Create a video display information object
    """
    check_video()
    return VidInfo(sdl.SDL_GetVideoInfo())
コード例 #5
0
ファイル: display.py プロジェクト: tazjel/pygame_cffi
    # pygame does this, so it's possibly a good idea
    sdl.SDL_PumpEvents()

    global _display_surface
    _display_surface = SurfaceNoFree._from_sdl_surface(c_surface)
    # TODO: set icon stuff
    return _display_surface


def mode_ok((w, h), flags=0, depth=None):
    """ mode_ok(size, flags=0, depth=0) -> depth
    Pick the best color depth for a display mode
    """
    if depth is None:
        depth = sdl.SDL_GetVideoInfo().vfmt.BitsPerPixel
    return sdl.SDL_VideoModeOK(w, h, depth, flags)


def list_modes(depth=None, flags=sdl.SDL_FULLSCREEN):
    """ list_modes(depth=0, flags=pygame.FULLSCREEN) -> list
    Get list of available fullscreen modes
    """
    check_video()

    format = ffi.new('SDL_PixelFormat*')
    if depth is None:
        format.BitsPerPixel = sdl.SDL_GetVideoInfo().vfmt.BitsPerPixel
    else:
        format.BitsPerPixel = depth