Пример #1
0
 def paint_children(self, ctx: Context):
     for child in self.children:
         ctx.save()
         ctx.translate(*child.position(Anchor.TOP_LEFT))
         ctx.rectangle(0, 0, *child.size)
         ctx.clip()
         child.paint(ctx)
         ctx.restore()
Пример #2
0
 def draw(self, context: cairo.Context, x: float, y: float, fxy: FixXY):
     if debug:
         context.set_source_rgb(1 if self.no_page_break else 0, 0, 0)
         context.rectangle(*fxy(x - 5, y), *fxy(2, 16))
         context.fill()
         context.set_source_rgb(0.5, 0.5, 0.5)
         context.rectangle(*fxy(self.indent + x, y),
                           *fxy(self.width, self.height))
         context.stroke()
Пример #3
0
    def paint_foreground(self, ctx: Context):
        if self.border_corner:
            draw_rounded_rectangle(ctx, Rectangle(ZERO_TOP_LEFT, self.size), self.border_corner)
            ctx.clip()

        self.paint_scale_background(ctx)

        if self.values:
            pos = 0.0
            for value in self.values:
                l_pos = pos
                pos += value[0] / self._total
                if value[1]:
                    ctx.set_source_rgba(*value[1])
                    if self.orientation == BarWidget.Orientation.HORIZONTAL_LEFT_TO_RIGHT:
                        ctx.rectangle(l_pos * self.width, 0, (pos - l_pos) * self.width, self.height)
                    elif self.orientation == BarWidget.Orientation.HORIZONTAL_RIGHT_TO_LEFT:
                        ctx.rectangle(self.width - l_pos * self.width, 0, self.width - (l_pos - pos) * self.width,
                                      self.height)
                    elif self.orientation == BarWidget.Orientation.VERTICAL_DOWN:
                        ctx.rectangle(0, l_pos * self.height, self.width, (pos - l_pos) * self.height)
                    elif self.orientation == BarWidget.Orientation.VERTICAL_UP:
                        ctx.rectangle(0, self.height - l_pos * self.height, self.width, (l_pos - pos) * self.height)
                    ctx.fill()

        self.paint_scale_foreground(ctx)

        if self.border:
            ctx.set_source_rgba(*self.border)
            ctx.set_line_width(self.border_width)
            draw_rounded_rectangle(ctx, Rectangle(ZERO_TOP_LEFT, self.size), self.border_corner)
            ctx.stroke()
Пример #4
0
    def draw_children(self, g: Graphics) -> None:
        ui = cast(ContainerUI, self.ui)

        (cx, cy, cw, ch) = ui.content_bounds(self).tuple

        g.save()

        g.rectangle(cx, cy, cw, ch)
        g.clip()

        try:
            # noinspection PyTypeChecker
            for child in self.children:
                child.draw(g)
        except BaseException as e:
            self.error_handler(e)

        g.restore()
Пример #5
0
    def draw(self, g: Graphics) -> None:
        if self.visible:
            g.save()

            (dx,
             dy) = self.parent.map(lambda p: p.location).value_or(Point(0, 0))
            (cx, cy, cw, ch) = self.ui.clip_bounds(self).tuple

            g.translate(dx, dy)
            g.rectangle(cx, cy, cw, ch)

            g.clip()

            try:
                self.draw_component(g)
            except BaseException as e:
                self.error_handler(e)

            g.restore()
Пример #6
0
 def draw(self, context: cairo.Context, x: float, y: float, fxy: FixXY):
     super().draw(context, x, y, fxy)
     if debug:
         context.set_source_rgb(1 if self.no_page_break else 0, 0, 0)
         context.rectangle(*fxy(x, y), *fxy(10, 10))
         context.fill()
Пример #7
0
 def paint_background(self, ctx: Context):
     """
     Renders the background of this widget. Is called by Widget.paint.
     """
     ctx.rectangle(0, 0, *self.size)
     ctx.fill()
Пример #8
0
    h = int(h_bg * (1 - y_offset))

    base_labels = board_info["variants"]["_base"]

    for variant_name, variant_info in board_info["variants"].items():
        if variant_name.startswith("_"):
            # skip "_base"
            continue

        # create canvas
        w_p = int(w * (1 + 2 * pad_sides))
        canvas = ImageSurface(bg.get_format(), w_p, h)
        ctx = Context(canvas)

        ctx.set_source_rgb(1, 1, 1)
        ctx.rectangle(0, 0, w_p, h)
        ctx.fill()

        ctx.set_source_surface(bg, (w_p - w) // 2, -h_bg * y_offset)
        ctx.rectangle((w_p - w) // 2, 0, w, h_bg)
        ctx.fill()

        # make B&W

        ctx.set_source_rgb(0.5, 0.5, 0.5)
        ctx.set_operator(OPERATOR_HSL_SATURATION)
        ctx.rectangle(0, 0, w_p, h)
        ctx.fill()

        if True:
            canvas.write_to_png(f"{board_name}_bg.png")