示例#1
0
def update(rectangle=None):
    """ update(rectangle=None) -> None
    update(rectangle_list) -> None
    Update portions of the screen for software displays
    """
    check_video()

    screen = sdl.SDL_GetVideoSurface()
    if not screen:
        raise SDLError("Display mode not set")

    if (screen.flags & sdl.SDL_OPENGL):
        raise SDLError("Cannot update an OPENGL display")

    if not rectangle:
        sdl.SDL_UpdateRect(screen, 0, 0, 0, 0)
        return

    try:
        if hasattr(rectangle, '__iter__'):
            # it can either be a rect style 4-tuple or
            # a sequence of rects or rect styles
            try:
                int(rectangle[0])
                rects = (rectangle, )
            except (ValueError, TypeError):
                rects = rectangle
        else:
            rects = (rectangle, )

        if len(rects) == 1:
            rect = game_rect_from_obj(rects[0])
            if screen_crop_rect(rect, screen.w, screen.h):
                sdl.SDL_UpdateRect(screen, rect.x, rect.y, rect.w, rect.h)
            return

        rect_array = ffi.new('SDL_Rect[]', len(rects))
        count = 0
        for obj in rects:
            if not obj:
                continue
            rect = game_rect_from_obj(obj)
            if screen_crop_rect(rect, screen.w, screen.h):
                sdlrect = rect_array[count]
                sdlrect.x = rect.x
                sdlrect.y = rect.y
                sdlrect.w = rect.w
                sdlrect.h = rect.h
                count += 1

        sdl.SDL_UpdateRects(screen, count, rect_array)

    except (NotImplementedError, TypeError):
        raise ValueError(
            "update requires a rectstyle or sequence of recstyles")
示例#2
0
def update(rectangle=None):
    """ update(rectangle=None) -> None
    update(rectangle_list) -> None
    Update portions of the screen for software displays
    """
    check_video()

    screen = sdl.SDL_GetVideoSurface()
    if not screen:
        raise SDLError("Display mode not set")

    if (screen.flags & sdl.SDL_OPENGL):
        raise SDLError("Cannot update an OPENGL display")

    if not rectangle:
        sdl.SDL_UpdateRect(screen, 0, 0, 0, 0)
        return

    try:
        if hasattr(rectangle, '__iter__'):
            # it can either be a rect style 4-tuple or
            # a sequence of rects or rect styles
            try:
                int(rectangle[0])
                rects = (rectangle, )
            except (ValueError, TypeError):
                rects = rectangle
        else:
            rects = (rectangle, )

        if len(rects) == 1:
            rect = game_rect_from_obj(rects[0])
            if screen_crop_rect(rect, screen.w, screen.h):
                sdl.SDL_UpdateRect(screen, rect.x, rect.y, rect.w, rect.h)
            return

        rect_array = ffi.new('SDL_Rect[]', len(rects))
        count = 0
        for obj in rects:
            if not obj:
                continue
            rect = game_rect_from_obj(obj)
            if screen_crop_rect(rect, screen.w, screen.h):
                sdlrect = rect_array[count]
                sdlrect.x = rect.x
                sdlrect.y = rect.y
                sdlrect.w = rect.w
                sdlrect.h = rect.h
                count += 1

        sdl.SDL_UpdateRects(screen, count, rect_array)

    except (NotImplementedError, TypeError):
        raise ValueError("update requires a rectstyle or sequence of recstyles")
示例#3
0
    def subsurface(self, *rect):
        self.check_opengl()

        try:
            if hasattr(rect[0], '__iter__'):
                rect = game_rect_from_obj(rect[0])
            else:
                rect = game_rect_from_obj(rect)
        except TypeError:
            raise ValueError("not a valid rect style object")

        if (rect.x < 0 or rect.x + rect.w > self._c_surface.w or rect.y < 0 or
            rect.y + rect.h > self._c_surface.h):
            raise ValueError("subsurface rectangle outside surface area")
        with locked(self._c_surface):
            format = self._format
            pixeloffset = (rect.x * format.BytesPerPixel +
                           rect.y * self._c_surface.pitch)
            startpixel = ffi.cast("char*", self._c_surface.pixels) + pixeloffset
            surf = self._c_surface
            sub = sdl.SDL_CreateRGBSurfaceFrom(startpixel, rect.w, rect.h,
                                               format.BitsPerPixel, surf.pitch,
                                               format.Rmask, format.Gmask,
                                               format.Bmask, format.Amask)
        if not sub:
            raise SDLError.from_sdl_error()

        if format.BytesPerPixel == 1 and format.palette:
            sdl.SDL_SetPalette(sub, sdl.SDL_LOGPAL,
                               format.palette.colors, 0,
                               format.palette.ncolors);
        if surf.flags & sdl.SDL_SRCALPHA:
            sdl.SDL_SetAlpha(sub, surf.flags & sdl.SDL_SRCALPHA,
                             format.alpha);
        if surf.flags & sdl.SDL_SRCCOLORKEY:
            sdl.SDL_SetColorKey(sub, surf.flags & (sdl.SDL_SRCCOLORKEY |
                                                   sdl.SDL_RLEACCEL),
                                                   format.colorkey)
        subsurface = Surface._from_sdl_surface(sub)
        data = SubSurfaceData(self, pixeloffset, rect.x, rect.y)
        subsurface.subsurfacedata = data
        return subsurface
示例#4
0
    def subsurface(self, *rect):
        self.check_opengl()

        try:
            if hasattr(rect[0], '__iter__'):
                rect = game_rect_from_obj(rect[0])
            else:
                rect = game_rect_from_obj(rect)
        except TypeError:
            raise ValueError("not a valid rect style object")

        if (rect.x < 0 or rect.x + rect.w > self._c_surface.w or rect.y < 0 or
            rect.y + rect.h > self._c_surface.h):
            raise ValueError("subsurface rectangle outside surface area")
        with locked(self._c_surface):
            format = self._format
            pixeloffset = (rect.x * format.BytesPerPixel +
                           rect.y * self._c_surface.pitch)
            startpixel = ffi.cast("char*", self._c_surface.pixels) + pixeloffset
            surf = self._c_surface
            sub = sdl.SDL_CreateRGBSurfaceFrom(startpixel, rect.w, rect.h,
                                               format.BitsPerPixel, surf.pitch,
                                               format.Rmask, format.Gmask,
                                               format.Bmask, format.Amask)
        if not sub:
            raise SDLError.from_sdl_error()

        if format.BytesPerPixel == 1 and format.palette:
            sdl.SDL_SetPalette(sub, sdl.SDL_LOGPAL,
                               format.palette.colors, 0,
                               format.palette.ncolors);
        if surf.flags & sdl.SDL_SRCALPHA:
            sdl.SDL_SetAlpha(sub, surf.flags & sdl.SDL_SRCALPHA,
                             format.alpha);
        if surf.flags & sdl.SDL_SRCCOLORKEY:
            sdl.SDL_SetColorKey(sub, surf.flags & (sdl.SDL_SRCCOLORKEY |
                                                   sdl.SDL_RLEACCEL),
                                                   format.colorkey)
        subsurface = Surface._from_sdl_surface(sub)
        data = SubSurfaceData(self, pixeloffset, rect.x, rect.y)
        subsurface.subsurfacedata = data
        return subsurface