コード例 #1
0
    def scrollbar_rect(self):
        # Get the distance between the scroll buttons (d)
        sub = self.scroll_up_rect().bottom
        t = self.scroll_down_rect().top
        d = t - sub
        # Get the total row number (n).
        n = self.num_items() / getattr(getattr(self, 'parent', None), 'num_cols', lambda: 1)()
        # Get the displayed row number (v)
        v = self.num_rows()
        if n:
            s = float(d) / n
        else:
            s = 0
        h = s * v
        if type(h) == float:
            if h - int(h) > 0:
                h += 1

        top = max(sub, sub + (s * self.scroll) + self.scroll_rel)
        r = Rect(0, top, self.scroll_button_size, h)
        m = self.margin
        r.right = self.width - m
        r.bottom = min(r.bottom, t)
        r.inflate_ip(-4, -4)
        if r.h < 1:
            r.h = int(h)
        return r
コード例 #2
0
 def delta(self, rect: pg.Rect) -> pg.Rect:
     rect = rect.copy()
     rect.x = ceil(rect.x * self.dz + self.dx)
     rect.y = ceil(rect.y * self.dz + self.dy)
     rect.w = ceil(rect.w * self.dz)
     rect.h = ceil(rect.h * self.dz)
     return rect
コード例 #3
0
    def world_to_screen_rect(self, rect: pg.Rect, is_world=True, clip=True):
        rect = rect.copy()
        if is_world:
            rect.x -= self.position[0]
            rect.y -= self.position[1]
        rect.x *= self.scale
        rect.y *= self.scale
        rect.w *= self.scale
        rect.h *= self.scale

        if self.cam_alignment[0] == self.ALIGNMENT_RIGHT:
            rect.x += self.display_port.x
        elif self.cam_alignment[0] == self.ALIGNMENT_CENTER:
            rect.x += self.display_port.x + (self.display_port.w // 2)
        elif self.cam_alignment[0] == self.ALIGNMENT_LEFT:
            rect.x += self.display_port.x + self.display_port.w
        if self.cam_alignment[1] == self.ALIGNMENT_BOTTOM:
            rect.y += self.display_port.y
        elif self.cam_alignment[1] == self.ALIGNMENT_CENTER:
            rect.y += self.display_port.y + (self.display_port.h // 2)
        elif self.cam_alignment[1] == self.ALIGNMENT_TOP:
            rect.y += self.display_port.y + self.display_port.h

        if clip:
            if rect.x < self.display_port.x:
                difference = self.display_port.x - rect.x
                rect.x += difference
                rect.w -= difference
            if rect.x + rect.w > self.display_port.x + self.display_port.w:
                difference = (rect.x + rect.w) - (self.display_port.x + self.display_port.w)
                rect.w -= difference

            if rect.y < self.display_port.y:
                difference = self.display_port.y - rect.y
                rect.y += difference
                rect.h -= difference
            if rect.y + rect.h > self.display_port.y + self.display_port.h:
                difference = (rect.y + rect.h) - (self.display_port.y + self.display_port.h)
                rect.h -= difference

            rect.w = max(rect.w, 0)
            rect.h = max(rect.h, 0)

        return rect
コード例 #4
0
def scale_rect(rectangle: pygame.Rect, scale=2):
    rectangle.x = rectangle.x * scale
    rectangle.y = rectangle.y * scale
    rectangle.w = rectangle.w * scale
    rectangle.h = rectangle.h * scale
    return rectangle