Exemplo n.º 1
0
    def render(self, rect, data):
        x, y, w, h = rect.get_data()

        if self.top is not None:
            size = self.top.get_minimum_size(data)
            self.top.render(datatypes.Rectangle(x, y + h - size.y, w, size.y),
                            data)
            h -= size.y + self.margin
        if self.bottom is not None:
            size = self.bottom.get_minimum_size(data)
            self.bottom.render(datatypes.Rectangle(x, y, w, size.y), data)
            y += size.y + self.margin
            h -= size.y + self.margin
        if self.right is not None:
            size = self.right.get_minimum_size(data)
            self.right.render(
                datatypes.Rectangle(x + w - size.x, y, size.x, h), data)
            w -= size.x + self.margin
        if self.left is not None:
            size = self.left.get_minimum_size(data)
            self.left.render(datatypes.Rectangle(x, y, size.x, h), data)
            w -= size.x + self.margin
            x += size.x + self.margin
        if self.center is not None:
            self.center.render(datatypes.Rectangle(x, y, w, h), data)
    def render(self, rect, data):
        # Find the biggest rectangle of our original aspect ratio,
        # that we can fit in the given rectangle at our target angle.

        # First find the upscale we got going from our element to our
        # rotated minimum size.
        base_ms = self.element.get_minimum_size(data)
        rotated_ms = self._calculate_ms_from_base(base_ms)

        # Find the scale of the rect we're given and the limiting scale
        scale_x = rect.w / rotated_ms.x if rotated_ms.x > 0 else 999999999.0
        scale_y = rect.h / rotated_ms.y if rotated_ms.y > 0 else 999999999.0
        scale = min(scale_x, scale_y)

        # Transform the base size by this scale
        hw = base_ms.x * 0.5 * scale
        hh = base_ms.y * 0.5 * scale

        # Thats the space we give to our child element.
        center = rect.center_middle
        c = data['output']
        with c:
            c.translate(center.x, center.y)
            c.rotate(self.angle / math.pi * 180.0)
            self.element.render(
                datatypes.Rectangle(-hw, -hh, hw * 2.0, hh * 2.0), data)
Exemplo n.º 3
0
    def render(self, rect, data):
        """Draws the managed element in the correct alignment."""
        # We can't use our get minimum size, because that enforces
        # the size limits.
        size = self.element.get_minimum_size(data)

        # Assume we're top left at our natural size.
        x = rect.x
        y = rect.y
        w = size.x
        h = size.y

        extra_width = rect.w - w
        extra_height = rect.h - h

        if self.horizontal_align == AlignLM.ALIGN_CENTER:
            x += extra_width * 0.5
        elif self.horizontal_align == AlignLM.ALIGN_RIGHT:
            x += extra_width
        elif self.horizontal_align == AlignLM.GROW_X:
            w = rect.w

        if self.vertical_align == AlignLM.ALIGN_MIDDLE:
            y += extra_height * 0.5
        elif self.vertical_align == AlignLM.ALIGN_BOTTOM:
            y += extra_height
        elif self.vertical_align == AlignLM.GROW_Y:
            h = rect.h

        self.element.render(datatypes.Rectangle(x, y, w, h), data)
 def render(self, rect, data):
     scale = self.scale
     c = data['output']
     with c:
         c.translate(rect.x, rect.y)
         c.scale(scale, scale)
         self.element.render(
             datatypes.Rectangle(0, 0, rect.x / scale, rect.y / scale),
             data)
 def render(self, rect, data):
     num_elements = len(self.elements)
     row_height = \
         (rect.h-self.margin*(num_elements-1)) / float(num_elements)
     y = rect.y
     for element in reversed(self.elements):
         if element is not None:
             element.render(
                 datatypes.Rectangle(rect.x, y, rect.w, row_height), data)
         y += row_height + self.margin
 def render(self, rect, data):
     """Draws the columns."""
     num_elements = len(self.elements)
     col_width = (rect.w - self.margin *
                  (num_elements - 1)) / float(num_elements)
     x = rect.x
     for element in self.elements:
         if element is not None:
             element.render(
                 datatypes.Rectangle(x, rect.y, col_width, rect.h), data)
         x += col_width + self.margin
    def render(self, rect, data):
        # Use an if statement - it is much easier.
        x, y, w, h = rect.get_data()
        c = data['output']

        with c:
            if self.angle == RotateLM.NORMAL:
                self.element.render(rect, data)
            else:
                c.translate(*rect.cm)
                c.rotate(self.angle * 90)

                if self.angle == RotateLM.ANGLE_180:
                    self.element.render(
                        datatypes.Rectangle(-w * 0.5, -h * 0.5, w, h), data)
                else:
                    assert (self.angle
                            in (RotateLM.ANGLE_90, RotateLM.ANGLE_270))
                    self.element.render(
                        datatypes.Rectangle(-h * 0.5, -w * 0.5, h, w), data)
Exemplo n.º 8
0
    def render(self, rect, data):
        if self.element is None: return

        size = self.element.get_minimum_size(data)
        extra_width = max(0, rect.w - size.x)
        extra_height = max(0, rect.h - size.y)

        self.element.render(
            datatypes.Rectangle(rect.x + self._margins[3] * extra_width,
                                rect.y + self._margins[2] * extra_height,
                                rect.w - extra_width, rect.h - extra_height),
            data)
Exemplo n.º 9
0
 def _render_jittered(
     self, rectangle, data, angle_jitter, x_jitter, y_jitter
     ):
     c = data['output']
     with c:
         c.translate(rectangle.center, rectangle.middle)
         c.translate(x_jitter, y_jitter)
         c.rotate(angle_jitter * 180.0 / math.pi)
         self.element.render(
             datatypes.Rectangle(
                 -rectangle.w*0.5, -rectangle.h*0.5,
                 rectangle.w, rectangle.h
                 ), data
             )
Exemplo n.º 10
0
    def render(self, rect, data):
        size = self.element.get_minimum_size(data)
        if size.x > rect.w or size.y > rect.h:
            # The object is too big, work out the minimum scaling
            scale = min(
                float(rect.w) / float(size.x),
                float(rect.h) / float(size.y))

            # Apply the scaling and render the output.
            c = data['output']
            with c:
                c.translate(rect.x, rect.y)
                c.scale(scale, scale)
                self.element.render(
                    datatypes.Rectangle(0, 0, rect.w / scale, rect.h / scale),
                    data)
        else:
            self.element.render(rect, data)
Exemplo n.º 11
0
    def render(self, rect, data):
        size = self.element.get_minimum_size(data)

        # The object is too big, work out the minimum scaling
        scale = min(1,
                    float(rect.w) / float(size.x),
                    float(rect.h) / float(size.y))
        extra_width = rect.w - size.x * scale
        extra_height = rect.h - size.y * scale

        # Apply the scaling and render the output.
        c = data['output']
        with c:
            c.translate(rect.x + extra_width * 0.5,
                        rect.y + extra_height * 0.5)
            if scale < 1.0:
                c.scale(scale, scale)
            self.element.render(datatypes.Rectangle(0, 0, size.x, size.y),
                                data)
    def render(self, rect, data):
        """
        Displays the elements according to the align properties.
        """
        # Make sure we're aligned correctly
        if self.horizontal_align not in VerticalLM._VALID_ALIGN_HORIZONTAL:
            raise ValueError('Horizontal align is not valid.')
        if self.vertical_align not in VerticalLM._VALID_ALIGN_VERTICAL:
            raise ValueError('Vertical align is not valid.')

        # Work out the extra height we have to distribute
        extra_height = rect.h - self.get_minimum_size(data).y
        num_elements = len(self.elements)
        if num_elements == 0:
            return
        elif num_elements > 1:
            per_margin = 1.0 / float(num_elements - 1)
        else:
            per_margin = 0.0
        per_element = 1.0 / float(num_elements)

        # Work out the starting y coordinate
        y = rect.y
        if self.vertical_align == VerticalLM.ALIGN_MIDDLE:
            y = rect.y + extra_height * 0.5
        elif self.vertical_align == VerticalLM.ALIGN_TOP:
            y = rect.y + extra_height

        # Render each child element
        for element in reversed(self.elements):
            size = element.get_minimum_size(data)

            # Work out the x-coordinates
            if self.horizontal_align == VerticalLM.ALIGN_LEFT:
                x = rect.x
                w = size.x
            elif self.horizontal_align == VerticalLM.ALIGN_CENTER:
                x = rect.center - size.x * 0.5
                w = size.x
            elif self.horizontal_align == VerticalLM.ALIGN_RIGHT:
                x = rect.right - size.x
                w = size.x
            else:
                assert self.horizontal_align == VerticalLM.ALIGN_GROW
                x = rect.x
                w = rect.w

            # Work out the y-coordinates
            if self.vertical_align in VerticalLM._ALIGN_SIMPLE_SET:
                h = size.y
                next_y = y + size.y + self.margin
            elif self.vertical_align == VerticalLM.ALIGN_EQUAL_SPACING:
                h = size.y
                next_y = y + size.y + self.margin + extra_height * per_margin
            else:
                assert self.vertical_align == VerticalLM.ALIGN_EQUAL_GROWTH
                h = size.y + extra_height * per_element
                next_y = y + h + self.margin

            # Render and move on.
            element.render(datatypes.Rectangle(x, y, w, h), data)
            y = next_y
    def render(self, rect, data):
        """Displays the elements according to the align properties."""

        # Make sure we're aligned correctly
        if self.horizontal_align not in HorizontalLM._VALID_ALIGN_HORIZONTAL:
            raise ValueError('Horizontal align is not valid.')
        if self.vertical_align not in HorizontalLM._VALID_ALIGN_VERTICAL:
            raise ValueError('Vertical align is not valid.')

        # Work out the extra width we have to distribute
        extra_width = rect.w - self.get_minimum_size(data).x
        num_elements = len(self.elements)
        if num_elements == 0:
            return
        elif num_elements > 1:
            per_margin = 1.0 / float(num_elements - 1)
        else:
            per_margin = 0.0
        per_element = 1.0 / float(num_elements)

        # Work out the starting x coordinate
        x = rect.x
        if self.horizontal_align == HorizontalLM.ALIGN_CENTER:
            x = rect.x + extra_width * 0.5
        elif self.horizontal_align == HorizontalLM.ALIGN_RIGHT:
            x = rect.x + extra_width

        # Render each child element
        for element in self.elements:
            size = element.get_minimum_size(data)

            # Work out the y-coordinates
            if self.vertical_align == HorizontalLM.ALIGN_TOP:
                y = rect.top - size.y
                h = size.y
            elif self.vertical_align == HorizontalLM.ALIGN_MIDDLE:
                y = rect.middle - size.y * 0.5
                h = size.y
            elif self.vertical_align == HorizontalLM.ALIGN_BOTTOM:
                y = rect.y
                h = size.y
            else:
                assert self.vertical_align == HorizontalLM.ALIGN_GROW
                y = rect.y
                h = rect.h

            # Work out the x-coordinates
            if self.horizontal_align in HorizontalLM._ALIGN_SIMPLE_SET:
                w = size.x
                next_x = x + size.x + self.margin
            elif self.horizontal_align == HorizontalLM.ALIGN_EQUAL_SPACING:
                w = size.x
                next_x = x + size.x + self.margin + extra_width * per_margin
            else:
                assert self.horizontal_align == HorizontalLM.ALIGN_EQUAL_GROWTH
                w = size.x + extra_width * per_element
                next_x = x + w + self.margin

            # Render and move on.
            element.render(datatypes.Rectangle(x, y, w, h), data)
            x = next_x
Exemplo n.º 14
0
 def render(self, rectangle, data):
     rect = datatypes.Rectangle(
         rectangle.x, rectangle.y,
         self.size.x, self.size.y
         )
     self.element.render(rect, data)
Exemplo n.º 15
0
 def render(self, rect, data):
     self.element.render(
         datatypes.Rectangle(rect.x + rect.w * self.left,
                             rect.y + rect.h * self.bottom,
                             rect.w * (1.0 - self.left - self.right),
                             rect.h * (1.0 - self.bottom - self.top)), data)
Exemplo n.º 16
0
 def render(self, rect, data):
     self.element.render(
         datatypes.Rectangle(rect.x + self.left, rect.y + self.bottom,
                             rect.w - self.left - self.right,
                             rect.h - self.bottom - self.top), data)