当前位置: 首页>>代码示例>>Python>>正文


Python Rect.inflate方法代码示例

本文整理汇总了Python中pygame.Rect.inflate方法的典型用法代码示例。如果您正苦于以下问题:Python Rect.inflate方法的具体用法?Python Rect.inflate怎么用?Python Rect.inflate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame.Rect的用法示例。


在下文中一共展示了Rect.inflate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
    def init (self):
        n_pads = pg.joystick.get_count()
        if n_pads == 0:
            img = 'nopads'
        elif n_pads == 1:
            img = '1pad'
        else:
            img = '2pads'

        gm_r = Rect((0, 0), self.graphics.size)
        frame = gm_r.inflate(*(-2 * w for w in conf.INTRO_FRAME_WIDTH))
        viewport = GraphicsManager(self.scheduler, frame.size)
        setup_bg(viewport, 1, self.scheduler)
        text = Graphic('intro-{0}.png'.format(img))
        viewport.add(text)
        text.align()
        self.graphics.add(
            util.tile_graphic(Graphic('solid.png'), gm_r, 1),
            viewport
        )
        viewport.align()

        for i in xrange(n_pads):
            pg.joystick.Joystick(i).init()
        self.evthandler.add((pg.KEYDOWN, pg.JOYBUTTONDOWN,
                             lambda: conf.GAME.switch_world(Level)))
开发者ID:ikn,项目名称:boom,代码行数:28,代码来源:level.py

示例2: bar

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
    def bar(self, surface, text, pos, w=300):
        rect = Rect(pos, (w, 60))
        draw.rect(surface, (0, 200, 200), rect)

        sf = font.SysFont('blah', 60, bold=False, italic=False)
        txt = sf.render(text, True, (0, 0, 0))
        surface.blit(txt, rect.inflate(-10, -10))
开发者ID:keltoff,项目名称:Demiurge,代码行数:9,代码来源:screen.py

示例3: Bomb

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
class Bomb(Sprite):
    width = 10
    height = 10
    color = 0,200,255
    fuse = 3000

    def __init__(self, pos):
        self.image = Surface((self.width, self.height))
        self.image.fill(self.color)

        self.rect = Rect(0,0,self.width, self.height)
        self.rect.center = pos

        self.time = fuse

    def update(self, dt):
        self.time -= dt
        step = self.time / 500

        if step % 2 == 0:
            color = 255,255,0
        else:
            color = 255,0,0

        self.image.fill(color, self.rect.inflate(-self.width/2, self.height/2))
开发者ID:HampshireCS,项目名称:cs143-Spring2012,代码行数:27,代码来源:shiphunt.py

示例4: get_aa_round_rect

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
def get_aa_round_rect(size, radius, color):
    surface = Surface(size, flags=SRCALPHA).convert_alpha()
    rect = Rect((0, 0), size)
    color = Color(*color)
    alpha = color.a
    color.a = 0
    rectangle = Surface(size, SRCALPHA)
    #here 5 is an arbitrary multiplier, we will just rescale later
    circle = Surface([min(size) * 5, min(size) * 5], SRCALPHA)
    draw.ellipse(circle, (0,0,0), circle.get_rect(), 0)
    circle = transform.smoothscale(circle, (2*radius, 2*radius))
    #now circle is just a small circle of radius
    #blit topleft circle:
    radius_rect = rectangle.blit(circle, (0, 0))
    #now radius_rect = Rect((0, 0), circle.size), rect=Rect((0, 0), size)
    #blit bottomright circle:
    radius_rect.bottomright = rect.bottomright #radius_rect is growing
    rectangle.blit(circle, radius_rect)
    #blit topright circle:
    radius_rect.topright = rect.topright
    rectangle.blit(circle, radius_rect)
    #blit bottomleft circle:
    radius_rect.bottomleft = rect.bottomleft
    rectangle.blit(circle, radius_rect)
    #black-fill of the internal rect
    rectangle.fill((0, 0, 0), rect.inflate(-radius_rect.w, 0))
    rectangle.fill((0, 0, 0), rect.inflate(0, -radius_rect.h))
    #fill with color using blend_rgba_max
    rectangle.fill(color, special_flags=BLEND_RGBA_MAX)
    #fill with alpha-withe using blend_rgba_min in order to make transparent
    #the
    rectangle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
    surface.blit(rectangle, rect.topleft)
    return surface
开发者ID:YannThorimbert,项目名称:Thorpy-1.5.2a,代码行数:36,代码来源:graphics.py

示例5: blit_borders_on

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
 def blit_borders_on(self, surface):
     rect = Rect((0, 0), self.size)
     for x in range(0, self.thick):
         r = rect.inflate(-x, -x)
         tc = get_top_coords(r)
         bc = get_bottom_coords(r)
         if self.pressed:
             lines(surface, self.dark, False, tc, 1)
             lines(surface, self.light, False, bc, 1)
         else:
             lines(surface, self.light, False, tc, 1)
             lines(surface, self.dark, False, bc, 1)
开发者ID:YannThorimbert,项目名称:ThorPy-1.0,代码行数:14,代码来源:classicframe.py

示例6: test_inflate__smaller

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
    def test_inflate__smaller( self ):
        "The inflate method inflates around the center of the rectangle"
        r = Rect( 2, 4, 6, 8 )
        r2 = r.inflate( -4, -6 )

        self.assertEqual( r.center, r2.center )        
        self.assertEqual( r.left+2, r2.left )
        self.assertEqual( r.top+3, r2.top )
        self.assertEqual( r.right-2, r2.right )
        self.assertEqual( r.bottom-3, r2.bottom )
        self.assertEqual( r.width-4, r2.width )
        self.assertEqual( r.height-6, r2.height )
开发者ID:CTPUG,项目名称:pygame_cffi,代码行数:14,代码来源:rect_test.py

示例7: test_inflate__larger

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
    def test_inflate__larger( self ):
        "The inflate method inflates around the center of the rectangle"
        r = Rect( 2, 4, 6, 8 )
        r2 = r.inflate( 4, 6 )

        self.assertEqual( r.center, r2.center )        
        self.assertEqual( r.left-2, r2.left )
        self.assertEqual( r.top-3, r2.top )
        self.assertEqual( r.right+2, r2.right )
        self.assertEqual( r.bottom+3, r2.bottom )
        self.assertEqual( r.width+4, r2.width )
        self.assertEqual( r.height+6, r2.height )
开发者ID:CTPUG,项目名称:pygame_cffi,代码行数:14,代码来源:rect_test.py

示例8: Level

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
class Level(object):
    initial_coins = 5
    song = "maintheme"

    def __init__(self, size):
        self.bounds = Rect((0, 0), size)
        self.bg_tile = load_image("grass")
        self.score_font = pygame.font.Font(None, 48)

    def draw_background(self, surf):
        tw, th = self.bg_tile.get_size()
        sw, sh = surf.get_size()

        for y in range(0, sh, th):
            for x in range(0, sw, tw):
                surf.blit(self.bg_tile, (x, y))

    def restart(self):
        self.score = 0
        self.player = Player()
        self.player.rect.center = self.bounds.center

        self.coins = CoinGroup(self.bounds)

        # create initial coins
        for i in range(self.initial_coins):
            self.coins.spawn()

        # start the background music
        play_song(self.song)

    def update(self, dt):
        self.player.update(dt)
        self.coins.update(dt)

        # lock player in bounds
        self.player.rect.clamp_ip(self.bounds)

        # collide player with coins
        if spritecollide(self.player, self.coins, True):
            self.score += 1

    def draw(self, surf):
        self.draw_background(surf)
        self.coins.draw(surf)
        surf.blit(self.player.image, self.player.rect)

        score = self.score_font.render(str(self.score), True, (0, 0, 0))
        rect = score.get_rect()
        rect.topright = self.bounds.inflate(-5, -5).topright
        surf.blit(score, rect)
开发者ID:HampshireCS,项目名称:cs143-Spring2012,代码行数:53,代码来源:level.py

示例9: align_rect

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
def align_rect (rect, within, alignment = 0, pad = 0, offset = 0):
    """Align a rect within another rect.

align_rect(rect, within, alignment = 0, pad = 0, offset = 0) -> pos

:arg rect: the Pygame-style rect to align.
:arg within: the rect to align ``rect`` within.
:arg alignment: ``(x, y)`` alignment; each is ``< 0`` for left-/top-aligned,
                ``0`` for centred, ``> 0`` for right-/bottom-aligned.  Can be
                just one number to use on both axes.
:arg pad: ``(x, y)`` padding to leave around the inner edge of ``within``.  Can
          be negative to allow positioning outside of ``within``, and can be
          just one number to use on both axes.
:arg offset: ``(x, y)`` amounts to offset by after all other positioning; can
             be just one number to use on both axes.

:return: the position the top-left corner of the rect should be moved to for
         the wanted alignment.

"""
    pos = alignment
    pos = [pos, pos] if isinstance(pos, (int, float)) else list(pos)
    if isinstance(pad, (int, float)):
        pad = (pad, pad)
    if isinstance(offset, (int, float)):
        offset = (offset, offset)
    rect = Rect(rect)
    sz = rect.size
    within = Rect(within)
    within = list(within.inflate(-2 * pad[0], -2 * pad[1]))
    for axis in (0, 1):
        align = pos[axis]
        if align < 0:
            x = 0
        elif align == 0:
            x = (within[2 + axis] - sz[axis]) / 2.
        else: # align > 0
            x = within[2 + axis] - sz[axis]
        pos[axis] = ir(within[axis] + x + offset[axis])
    return pos
开发者ID:ikn,项目名称:o,代码行数:42,代码来源:util.py

示例10: align

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
    def align (self, pos = 0, pad = 0, offset = 0, rect = None):
        """Position this graphic within a rect.

align(pos = 0, pad = 0, offset = 0, rect = self.manager.surface.get_rect())
    -> self

:arg pos: ``(x, y)`` alignment; each is ``< 0`` for left-aligned, ``0`` for
          centred, ``> 0`` for right-aligned.  Can be just one number to use on
          both axes.
:arg pad: ``(x, y)`` padding to leave around the inner edge of ``rect``.  Can
          be negative to allow positioning outside of ``rect``, and can be just
          one number to use on both axes.
:arg offset: ``(x, y)`` amounts to offset by after all other positioning; can
             be just one number to use on both axes.
:arg rect: Pygame-style rect to align in.

"""
        pos = [pos, pos] if isinstance(pos, (int, float)) else list(pos)
        if isinstance(pad, (int, float)):
            pad = (pad, pad)
        if isinstance(offset, (int, float)):
            offset = (offset, offset)
        if rect is None:
            rect = self._manager.surface.get_rect()
        else:
            rect = Rect(rect)
        rect = rect.inflate(-2 * pad[0], -2 * pad[1])
        sz = self._rect[2:]
        for axis in (0, 1):
            align = pos[axis]
            if align < 0:
                x = 0
            elif align == 0:
                x = (rect[2 + axis] - sz[axis]) / 2.
            else: # align > 0
                x = rect[2 + axis] - sz[axis]
            pos[axis] = ir(rect[axis] + x + offset[axis])
        self.rect = (pos, sz)
        return self
开发者ID:Anstow,项目名称:TeamAwesome,代码行数:41,代码来源:gm.py

示例11: make_house

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
    def make_house(self, x, y, direction, width, depth):
        if random.random() > self.house_chance:
            return False

        # Get corners of house
        rect = Rect(x+2, y - width/2, depth, width)
        self.rotate_rect(rect, (x, y), -direction)
        door_pos = self.rotate((x+2, y), (x, y), -direction)
        path_pos = self.rotate((x+1, y), (x, y), -direction)

        # Make sure not out of bounds or overlapping something
        if rect.left < 0 or rect.right >= self.size or rect.top < 0 or rect.bottom >= self.size:
            return False
        points = self.get_rect(rect)
        if set(points) & self.occupied:
            return False

        # Place the terrain
        self.fill_rect(rect, road)
        self.outline(rect, wall)

        # Region name will get reset later
        region = Region('unoccupied house',
                        self.level,
                        self.get_rect(rect.inflate(-2,-2)))
        door = Door(door_pos, level=self.level, blocks=region)
        region.door = door
        region.path = path_pos

        self.houses.append(region)
        self.level.set_terrain(door_pos, floor)
        self.level.set_terrain(path_pos, road)

        self.occupied |= set(self.get_rect(rect))

        return True
开发者ID:fish-face,项目名称:agutaywusyg,代码行数:38,代码来源:village.py

示例12: draw

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
 def draw(self):
     surface = Surface(self.size, flags=SRCALPHA).convert_alpha()
     rect = Rect((0, 0), self.size)
     color = Color(*self.color)
     alpha = color.a
     color.a = 0
     rectangle = Surface(rect.size, SRCALPHA)
     #ex: [h*3, h*3]
     circle = Surface([min(rect.size) * 5] * 2, SRCALPHA)
     draw.ellipse(circle, (0, 0, 0), circle.get_rect(), 0)
     #ex: [h*0.5, h*.05]
     circle = transform.smoothscale(circle,
                                    [int(self.radius_value)] * 2)
     #now circle is just a small circle of radius self.radius*h (for example)
     #blit topleft circle:
     radius = rectangle.blit(circle, (0, 0))
     #now radius = Rect((0, 0), circle.size), rect=Rect((0, 0), self.size)
     #blit bottomright circle:
     radius.bottomright = rect.bottomright #radius is growing
     rectangle.blit(circle, radius)
     #blit topright circle:
     radius.topright = rect.topright
     rectangle.blit(circle, radius)
     #blit bottomleft circle:
     radius.bottomleft = rect.bottomleft
     rectangle.blit(circle, radius)
     #black-fill of the internal rect
     rectangle.fill((0, 0, 0), rect.inflate(-radius.w, 0))
     rectangle.fill((0, 0, 0), rect.inflate(0, -radius.h))
     #fill with color using blend_rgba_max
     rectangle.fill(color, special_flags=BLEND_RGBA_MAX)
     #fill with alpha-withe using blend_rgba_min in order to make transparent
     #the
     rectangle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
     surface.blit(rectangle, rect.topleft)
     return surface
开发者ID:YannThorimbert,项目名称:ThorPy-1.0,代码行数:38,代码来源:roundrect.py

示例13: generate

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
    def generate(self):
        # Fill with grass
        self.fill_rect(-self.width/2-self.turret_project-10,
                               -self.turret_project-10,
                               self.width+2*(self.turret_project+10),
                               self.height+2*(self.turret_project+10), grass)
        # Calculate valid space for buildings
        quad = Rect(-self.width/2+self.wallwidth+1, self.wallwidth,
                        self.width-self.wallwidth*2-1, self.height-self.wallwidth*2)
        self.interior_space = set(self.get_rect(quad.inflate(2, 2)))
        self.fixed_rooms = []

        # Draw outer walls
        self.fourwalls(self.width,
                       self.height,
                       self.turretsize,
                       self.wallwidth,
                       self.turret_project,
                       self.gatesize,
                       self.gatehouse_project,
                       4)

        # Keep dimensions
        k_gs = (self.gatesize + 2) % 4 if self.gatesize != 2 else 4

        if self.height < 75:
            keep_style = KEEP_SIDE
        else:
            keep_style = random.choice(KEEP_STYLES)

        if keep_style == KEEP_CENTRE:
            k_w = (random.randint(int(self.width*0.3), int(self.width*0.5))/2)*2 + k_gs
            k_h = random.randint(int(self.height*0.3), int(self.height*0.5))
            k_x, k_y = 0, (self.height-k_h)/2
            side = 0
        elif keep_style == KEEP_SIDE:
            k_w = (random.randint(int(self.width*0.4), int(self.width*0.6))/2)*2 + k_gs
            k_h = random.randint(int(self.height*0.4), int(self.height*0.6))
            side = random.choice((-1, 1))
            k_x, k_y = (self.width-k_w)/2*side, (self.height-k_h)


        # Draw keep
        self.translate(k_x, k_y)

        self.fourwalls(k_w, k_h,
                       self.turretsize,
                       self.wallwidth+1,
                       self.turret_project,
                       k_gs, 0, 4)

        self.translate(-k_x, -k_y)

        path_to_keep = self.get_path(0, 1, k_x, k_y, self.gatesize, k_gs)
        for p in path_to_keep:
            self.draw(p, path)

        self.expand(path_to_keep, 2)
        self.interior_space -= set(path_to_keep)

        margin = 6
        if keep_style == KEEP_CENTRE:
            around_keep = Rect(-k_w/2-(self.wallwidth+margin), self.height/2-k_h/2-self.wallwidth-margin,
                               k_w+(self.wallwidth+margin)*2, k_h+(self.wallwidth+margin)*2)
            self.interior_space -= set(self.get_rect(around_keep))
        elif keep_style == KEEP_SIDE:
            if side == -1:
                left = -self.width/2+self.wallwidth
                width = k_w + margin
            else:
                left = self.width/2-self.wallwidth-k_w-margin
                width = k_w + margin
            around_keep = Rect(left, self.height/2-self.wallwidth-margin,
                               width, self.height)
            self.interior_space -= set(self.get_rect(around_keep))

        # Pick alternative entrance
        if keep_style == KEEP_CENTRE:
            alt_entrance_side = random.choice((LEFT, DOWN, RIGHT))
            if alt_entrance_side == LEFT:
                exit_room = (-k_w/2, self.height/2)
                exit_room_space = Rect(-k_w/2-9, self.height/2-5, 10, 10)
            elif alt_entrance_side == RIGHT:
                exit_room = (k_w/2+1, self.height/2)
                exit_room_space = Rect(k_w/2, self.height/2-5, 10, 10)
            elif alt_entrance_side == DOWN:
                exit_room = (0, self.height/2 + k_h/2+1)
                exit_room_space = Rect(-5, self.height/2 + k_h/2, 10, 10)
        elif keep_style == KEEP_SIDE:
            if side == -1:
                exit_room = (-self.width/2+k_w+1, self.height - k_h/2)
                exit_room_space = Rect(-self.width/2+k_w+1, self.height - k_h/2 - 5, 10, 10)
            else:
                exit_room = (self.width/2-k_w, self.height - k_h/2)
                exit_room_space = Rect(self.width/2-k_w-9, self.height - k_h/2 - 5, 10, 10)
        self.interior_space |= set(self.get_rect(exit_room_space))

        # Creaee buildings
        entrance_room = (self.gatesize/2+3, 10)
        graph = BuildingGraph([entrance_room, exit_room], self.fixed_rooms, self.interior_space, 10, 1)
#.........这里部分代码省略.........
开发者ID:fish-face,项目名称:agutaywusyg,代码行数:103,代码来源:castle.py

示例14: Game

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
class Game(Application):
    title = "Splodey Fun Times"
    max_ships = 400

    

    def __init__(self):
        pygame.init()
        #self.screen_size = pygame.display.list_modes()[0]

        Application.__init__(self)
        #pygame.display.toggle_fullscreen()    


        self.ships = ShipGroup(self.max_ships)
        self.xplos = ExplosionGroup()

        self.screen_bounds = bounds = self.screen.get_rect()

        dc_height = 40
        self.dc_font = pygame.font.Font(None, 30)
        self.dc_bounds = Rect(0, bounds.height - dc_height, bounds.width, dc_height)

        self.game_bounds = Rect(0, 0, bounds.width, bounds.height - dc_height)

        spawn_area = self.game_bounds.inflate(-self.game_bounds.width/4, -self.game_bounds.height/4)
        self.spawners = [
            TieSpawner(1000, self.ships, self.game_bounds, spawn_area),
            YWingSpawner(2000, self.ships, self.game_bounds)
        ]
        self.detonator = Detonator(self.game_bounds, self.xplos)

        for spawner in self.spawners:
            spawner.spawn()


        Ship.death_count = DeathCount()
        self.current_weapon = MiniExplosionsWeapon(self)

    def on_quit(self):
        Ship.death_count.write()

    def handle_event(self, event):
        pos = pygame.mouse.get_pos()

        if event.type == MOUSEBUTTONDOWN and event.button == 1:
            self.current_weapon.primarydown(pos)
        elif event.type == MOUSEBUTTONDOWN and event.button == 3:
            self.current_weapon.secondarydown(pos)
        elif event.type == MOUSEBUTTONUP and event.button == 1:
            self.current_weapon.primaryup(pos)
        elif event.type == MOUSEBUTTONUP and event.button == 3:
            self.current_weapon.secondaryup(pos)


    def update(self):
        dt = min(200, self.clock.get_time()) # cap dt

        # update all the spawners
        for spawner in self.spawners:
            spawner.update(dt)

        # update ships
        self.ships.update(dt)
        self.xplos.update(dt)

        self.xplos.explode_ships(self.ships)

        self.detonator.update(dt)

        if len(self.xplos) == 0:
            Ship.death_count.write()

    def draw(self, screen):
        screen.fill((0,0,0))
        self.ships.draw(screen)
        self.xplos.draw(screen)

        # hud
        screen.fill((40,40,40), self.dc_bounds)

        # death count
        msg = format_int(Ship.death_count.val()) + " dead"
        text = self.dc_font.render(msg, True, (255,255,255), (40,40,40))
        loc = text.get_rect()
        loc.centery = self.dc_bounds.centery
        loc.right = self.dc_bounds.right - 10
        screen.blit(text, loc)
开发者ID:HampshireCS,项目名称:cs143-Spring2012,代码行数:90,代码来源:shiphunt.py

示例15: Window

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import inflate [as 别名]
class Window(pygame.sprite.Sprite):

    def __init__(self, x, y, width, height):
        pygame.sprite.Sprite.__init__(self)
        self.image = Surface((width, height)).convert(32, pygame.RLEACCEL)
        self._windowskin = None
        self.rect = Rect(x, y, width, height)
        self.selected_rect = None
        self.widgets = []
        
    @property
    def offset(self):
        return 16

    @property
    def screen_pos(self):
        pos = self.rect.topleft
        return (pos[0] + self.offset, pos[1] + self.offset)
    
    @property
    def font(self):
        if not hasattr(self, '_font'):
            self._font = pygame.font.Font(None, 24)
        return self._font
    @font.setter
    def font(self, value):
        self._font = value
        
    def create_contents(self):
        w, h = self.rect.inflate(-2*self.offset, -2*self.offset).size
        self.contents = Surface((w, h)).convert_alpha()
        self.font_color = (255,255,255)

    def draw_text(self, x, y, text):
        bmp = self.font.render(text, 1, self.font_color)
        self.contents.blit(bmp, (x,y))

    def draw_selected(self, destsurf):
        if self.selected_rect:
            rect = self.selected_rect.move(self.rect.topleft)
            selected_surf = destsurf.subsurface(rect)
            pygame.transform.scale(self._select_src, self.selected_rect.size,
                                   selected_surf)
            
    @property
    def windowskin(self):
        return self._windowskin

    @windowskin.setter
    def windowskin(self, value):
        self._windowskin = value
        self._background = self._windowskin.subsurface(0,0,64,64)
        self._cadre = self._windowskin.subsurface(64,0,64,64)
        self._select_src = self._windowskin.subsurface(64,64,32,32)
        w, h = self.rect.size
        pygame.transform.scale(self._background, (w, h), self.image)
        #draw the four corners on the window
        for src, dest in [[(0, 0), (0,0)],
                     [(48, 0), (w-16, 0)],
                     [(0, 48), (0, h-16)],
                     [(48, 48), (w-16, h-16)]]:
            src_rect = Rect(src, (16, 16))
            dest_rect = Rect(dest, (16, 16))
            self.image.blit(self._cadre.subsurface(src_rect), dest)

    def draw(self, destsurf):
        destsurf.blit(self.image, self.rect)
        self.draw_selected(destsurf)
        destsurf.blit(self.contents, self.rect.move(self.offset, self.offset),
                                      self.contents_src)
        
    def add_widget(self, widget):
        self.widgets.append(widget)
        widget.parent = self
        widget.parent_offset = self.offset

    @property
    def contents_size(self):
        width, height = self.rect.inflate(-2*self.offset, -2*self.offset).size
        return width, height
    @property
    def contents_rect(self):
        "return the visible rect of contents"
        return self.rect.inflate(-2*self.offset, -2*self.offset)
    @property
    def contents_src(self):
        return self.contents.get_rect()
开发者ID:Clarabel,项目名称:PyIsoX3,代码行数:89,代码来源:_windowbase.py


注:本文中的pygame.Rect.inflate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。