예제 #1
0
    def process_draw(self, gc: wx.GraphicsContext):
        gc.SetBrush(self.background_brush)
        gc.DrawRectangle(self.left, self.top, self.right, self.bottom)

        gc.SetBrush(self.lacking_brush)
        gc.SetPen(self.lacking_pen)
        gc.DrawLines([(self.start_x, self.start_y), (self.end_x, self.end_y)])
        for idx, value in enumerate(self.values):
            amount = self.value_to_position(value)

            tx = amount * (self.end_x - self.start_x) + self.start_x
            ty = amount * (self.end_y - self.start_y) + self.start_y
            gc.SetBrush(self.selected_brush)
            gc.SetPen(self.selected_pen)
            gc.DrawLines([(self.start_x, self.start_y), (tx, ty)])
            gc.DrawEllipse(tx - BLIP_RADIUS / 2, ty - BLIP_RADIUS / 2,
                           BLIP_RADIUS, BLIP_RADIUS)
            if self.moving and self.seeker == idx:
                gc.SetBrush(self.moving_brush)
                gc.DrawEllipse(
                    tx - MOVE_RADIUS / 2,
                    ty - MOVE_RADIUS / 2,
                    MOVE_RADIUS,
                    MOVE_RADIUS,
                )
        if self.seeker != -1:
            try:
                gc.DrawText(
                    f"{self.values[self.seeker]:.2f}",
                    self.start_x,
                    self.start_y,
                )
            except IndexError:
                pass
예제 #2
0
    def process_draw(self, gc: wx.GraphicsContext):
        # Draw Box
        gc.SetBrush(wx.TRANSPARENT_BRUSH)
        gc.SetPen(self.checkline_pen)
        gc.DrawRectangle(self.left, self.top, self.right - self.left,
                         self.bottom - self.top)
        if self.value:
            # Draw Check
            gc.SetPen(self.checkline_pen)
            check = [(0.2, 0.5), (0.4, 0.75), (0.8, 0.2)]
            for i in range(len(check)):
                x, y = check[i]
                check[i] = towards(self.left, self.right,
                                   x), towards(self.top, self.bottom, y)
            gc.DrawLines(check)

        if self.text:
            height = self.bottom - self.top
            width = self.right - self.left
            text_size = height * 3.0 / 4.0  # px to pt conversion
            try:
                self.font.SetFractionalPointSize(text_size)
            except AttributeError:
                self.font.SetPointSize(int(text_size))
            gc.SetFont(self.font, self.font_color)
            gc.DrawText(self.text, self.right + width * self._text_gap,
                        self.top)
예제 #3
0
 def process_draw(self, gc: wx.GraphicsContext):
     if self.p1 is not None and self.p2 is not None:
         x0 = min(self.p1.real, self.p2.real)
         y0 = min(self.p1.imag, self.p2.imag)
         x1 = max(self.p1.real, self.p2.real)
         y1 = max(self.p1.imag, self.p2.imag)
         if self.scene.context.elements.default_stroke is None:
             self.pen.SetColour(wx.BLUE)
         else:
             self.pen.SetColour(
                 wx.Colour(
                     swizzlecolor(
                         self.scene.context.elements.default_stroke)))
         gc.SetPen(self.pen)
         if self.scene.context.elements.default_fill is None:
             gc.SetBrush(wx.TRANSPARENT_BRUSH)
         else:
             gc.SetBrush(
                 wx.Brush(
                     wx.Colour(
                         swizzlecolor(
                             self.scene.context.elements.default_fill)),
                     wx.BRUSHSTYLE_SOLID,
                 ))
         gc.DrawRectangle(x0, y0, x1 - x0, y1 - y0)
예제 #4
0
파일: scene.py 프로젝트: meerk40t/meerk40t
    def draw(self, gc: wx.GraphicsContext):
        if not self.message:
            return
        alpha = 255
        if self.countdown <= 20:
            alpha = int(self.countdown * 12.5)
        self.set_alpha(alpha)

        width = self.right - self.left
        height = self.bottom - self.top
        text_size = height

        while self.text_height > height or self.text_width > width:
            # If we do not fit in the box, decrease size
            text_size *= 0.9
            try:
                self.font.SetFractionalPointSize(text_size)
            except AttributeError:
                self.font.SetPointSize(int(text_size))
            gc.SetFont(self.font, self.font_color)
            self.text_width, self.text_height = gc.GetTextExtent(self.message)
        if text_size == height:
            gc.SetFont(self.font, self.font_color)
        gc.SetPen(self.pen)
        gc.SetBrush(self.brush)
        gc.DrawRectangle(self.left, self.top, self.right - self.left,
                         self.bottom - self.top)

        toast_x = self.left + (width - self.text_width) / 2.0
        toast_y = self.top
        gc.DrawText(self.message, toast_x, toast_y)
예제 #5
0
 def process_draw(self, gc: wx.GraphicsContext):
     gc.PushState()
     if self.background_brush is not None:
         gc.SetBrush(self.background_brush)
         gc.DrawRectangle(self.left, self.right, self.width, self.height)
     gc.DrawBitmap(self.bitmap, self.left, self.top, self.width,
                   self.height)
     gc.PopState()
예제 #6
0
def draw_rect(gc: wx.GraphicsContext, rect: Rect, *, fill: Optional[wx.Colour] = None,
              border: Optional[wx.Colour] = None, border_width: float = 1,
              fill_style=wx.BRUSHSTYLE_SOLID, border_style=wx.PENSTYLE_SOLID):
    """Draw a rectangle with the given graphics context.

    Either fill or border must be specified to avoid drawing an entirely transparent rectangle.

    Args:
        gc: The graphics context.
        rect: The rectangle to draw.
        fill: If specified, the fill color of the rectangle.
        border: If specified, the border color of the rectangle.
        border_width: The width of the borders. Defaults to 1. This cannot be 0 when border
            is specified.
    """
    assert not(fill is None and border is None), \
        "Both 'fill' and 'border' are None, but at least one of them should be provided"

    assert not (border is not None and border_width == 0), \
        "'border_width' cannot be 0 when 'border' is specified"

    x, y = rect.position
    width, height = rect.size

    pen: wx.Pen
    brush: wx.Brush
    # set up brush and pen if applicable
    if fill is not None:
        brush = gc.CreateBrush(wx.Brush(fill, fill_style))
    else:
        brush = wx.TRANSPARENT_BRUSH
    if border is not None:
        pen = gc.CreatePen(wx.GraphicsPenInfo(border).Width(border_width).Style(border_style))
    else:
        pen = wx.TRANSPARENT_PEN

    gc.SetPen(pen)
    gc.SetBrush(brush)

    # draw rect
    gc.DrawRectangle(x, y, width, height)
예제 #7
0
    def draw_cutcode(self,
                     cutcode: CutCode,
                     gc: wx.GraphicsContext,
                     x: int = 0,
                     y: int = 0):
        """
        Draw cutcode object into wxPython graphics code.

        This code accepts x,y offset values. The cutcode laser offset can be set with a
        command with the rest of the cutcode remaining the same. So drawing the cutcode
        requires knowing what, if any offset is currently being applied.

        @param cutcode: flat cutcode object to draw.
        @param gc: wx.graphics context
        @param x: offset in x direction
        @param y: offset in y direction
        @return:
        """
        p = None
        last_point = None
        color = None
        for cut in cutcode:
            c = cut.line_color
            if c is not color:
                color = c
                last_point = None
                if p is not None:
                    gc.StrokePath(p)
                    del p
                p = gc.CreatePath()
                self.set_pen(gc, c, width=7.0, alpha=127)
            start = cut.start
            end = cut.end
            if p is None:
                p = gc.CreatePath()
            if last_point != start:
                p.MoveToPoint(start[0] + x, start[1] + y)
            if isinstance(cut, LineCut):
                # Standard line cut. Applies to path object.
                p.AddLineToPoint(end[0] + x, end[1] + y)
            elif isinstance(cut, QuadCut):
                # Standard quadratic bezier cut
                p.AddQuadCurveToPoint(cut.c()[0] + x,
                                      cut.c()[1] + y, end[0] + x, end[1] + y)
            elif isinstance(cut, CubicCut):
                # Standard cubic bezier cut
                p.AddCurveToPoint(
                    cut.c1()[0] + x,
                    cut.c1()[1] + y,
                    cut.c2()[0] + x,
                    cut.c2()[1] + y,
                    end[0] + x,
                    end[1] + y,
                )
            elif isinstance(cut, RasterCut):
                # Rastercut object.
                image = cut.image
                gc.PushState()
                matrix = Matrix.scale(cut.step_x, cut.step_y)
                matrix.post_translate(cut.offset_x + x,
                                      cut.offset_y + y)  # Adjust image xy
                gc.ConcatTransform(
                    wx.GraphicsContext.CreateMatrix(gc, ZMatrix(matrix)))
                try:
                    cache = cut.cache
                    cache_id = cut.cache_id
                except AttributeError:
                    cache = None
                    cache_id = -1
                if cache_id != id(image):
                    # Cached image is invalid.
                    cache = None
                if cache is None:
                    # No valid cache. Generate.
                    cut.c_width, cut.c_height = image.size
                    try:
                        cut.cache = self.make_thumbnail(image, maximum=5000)
                    except (MemoryError, RuntimeError):
                        cut.cache = None
                    cut.cache_id = id(image)
                if cut.cache is not None:
                    # Cache exists and is valid.
                    gc.DrawBitmap(cut.cache, 0, 0, cut.c_width, cut.c_height)
                else:
                    # Image was too large to cache, draw a red rectangle instead.
                    gc.SetBrush(wx.RED_BRUSH)
                    gc.DrawRectangle(0, 0, cut.c_width, cut.c_height)
                    gc.DrawBitmap(icons8_image_50.GetBitmap(), 0, 0,
                                  cut.c_width, cut.c_height)
                gc.PopState()
            elif isinstance(cut, RawCut):
                pass
            elif isinstance(cut, PlotCut):
                p.MoveToPoint(start[0] + x, start[1] + y)
                for px, py, pon in cut.plot:
                    if pon == 0:
                        p.MoveToPoint(px + x, py + y)
                    else:
                        p.AddLineToPoint(px + x, py + y)
            elif isinstance(cut, DwellCut):
                pass
            elif isinstance(cut, WaitCut):
                pass
            elif isinstance(cut, InputCut):
                pass
            elif isinstance(cut, OutputCut):
                pass
            last_point = end
        if p is not None:
            gc.StrokePath(p)
            del p