示例#1
0
    def _horizontal_layout(self, x, y, blocks):
        ''' Position prototypes in a horizontal palette. '''
        offset = self._turtle_window.toolbar_offset
        max_w = 0

        for blk in blocks:
            if not blk.get_visibility():
                continue

            w, h = get_stack_width_and_height(blk)
            if y + h > PALETTE_HEIGHT + offset:
                x += int(max_w + 3)
                y = offset + 3
                max_w = 0

            (bx, by) = blk.spr.get_xy()
            dx = x - bx
            dy = y - by
            for g in find_group(blk):
                g.spr.move_relative((int(dx), int(dy)))
                g.spr.save_xy = g.spr.get_xy()
                self._float_palette(g.spr)
            y += int(h + 3)
            if w > max_w:
                max_w = w

        return x, y, max_w
示例#2
0
    def _horizontal_layout(self, x, y, blocks):
        ''' Position prototypes in a horizontal palette. '''
        offset = self._turtle_window.toolbar_offset
        max_w = 0

        for blk in blocks:
            if not blk.get_visibility():
                continue

            w, h = get_stack_width_and_height(blk)
            if y + h > PALETTE_HEIGHT + offset:
                x += int(max_w + 3)
                y = offset + 3
                max_w = 0

            (bx, by) = blk.spr.get_xy()
            dx = x - bx
            dy = y - by
            for g in find_group(blk):
                g.spr.move_relative((int(dx), int(dy)))
                g.spr.save_xy = g.spr.get_xy()
                self._float_palette(g.spr)
            y += int(h + 3)
            if w > max_w:
                max_w = w

        return x, y, max_w
示例#3
0
    def _vertical_layout(self, x, y, blocks):
        ''' Position prototypes in a vertical palette. '''
        row = []
        row_w = 0
        max_h = 0

        for blk in blocks:
            if not blk.get_visibility():
                continue

            w, h = get_stack_width_and_height(blk)
            if x + w > PALETTE_WIDTH:
                # Recenter row.
                dx = int((PALETTE_WIDTH - row_w) / 2)
                for r in row:
                    for g in find_group(r):
                        g.spr.move_relative((dx, 0))
                        g.spr.save_xy = (g.spr.save_xy[0] + dx,
                                         g.spr.save_xy[1])
                row = []
                row_w = 0
                x = 4
                y += int(max_h + 3)
                max_h = 0

            row.append(blk)
            row_w += (4 + w)

            (bx, by) = blk.spr.get_xy()
            dx = int(x - bx)
            dy = int(y - by)
            for g in find_group(blk):
                g.spr.move_relative((dx, dy))
                g.spr.save_xy = g.spr.get_xy()
                self._float_palette(g.spr)

            x += int(w + 4)
            if h > max_h:
                max_h = h

        # Recenter last row.
        dx = int((PALETTE_WIDTH - row_w) / 2)
        for r in row:
            for g in find_group(r):
                g.spr.move_relative((dx, 0))
                g.spr.save_xy = (g.spr.save_xy[0] + dx, g.spr.save_xy[1])

        return x, y, max_h
示例#4
0
    def _vertical_layout(self, x, y, blocks):
        ''' Position prototypes in a vertical palette. '''
        row = []
        row_w = 0
        max_h = 0

        for blk in blocks:
            if not blk.get_visibility():
                continue

            w, h = get_stack_width_and_height(blk)
            if x + w > PALETTE_WIDTH:
                # Recenter row.
                dx = int((PALETTE_WIDTH - row_w) / 2)
                for r in row:
                    for g in find_group(r):
                        g.spr.move_relative((dx, 0))
                        g.spr.save_xy = (g.spr.save_xy[0] + dx,
                                         g.spr.save_xy[1])
                row = []
                row_w = 0
                x = 4
                y += int(max_h + 3)
                max_h = 0

            row.append(blk)
            row_w += (4 + w)

            (bx, by) = blk.spr.get_xy()
            dx = int(x - bx)
            dy = int(y - by)
            for g in find_group(blk):
                g.spr.move_relative((dx, dy))
                g.spr.save_xy = g.spr.get_xy()
                self._float_palette(g.spr)

            x += int(w + 4)
            if h > max_h:
                max_h = h

        # Recenter last row.
        dx = int((PALETTE_WIDTH - row_w) / 2)
        for r in row:
            for g in find_group(r):
                g.spr.move_relative((dx, 0))
                g.spr.save_xy = (g.spr.save_xy[0] + dx, g.spr.save_xy[1])

        return x, y, max_h