예제 #1
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,
                 ))
         ellipse = Circle((x1 + x0) / 2.0, (y1 + y0) / 2.0,
                          abs(self.p1 - self.p2) / 2)
         t = Path(ellipse)
         bbox = t.bbox()
         if bbox is not None:
             gc.DrawEllipse(bbox[0], bbox[1], bbox[2] - bbox[0],
                            bbox[3] - bbox[1])
예제 #2
0
 def process_draw(self, gc: wx.GraphicsContext):
     if self.point_series:
         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,
                 ))
         points = list(self.point_series)
         if self.mouse_position is not None:
             points.append(self.mouse_position)
         points.append(points[0])
         gc.DrawLines(points)
예제 #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
    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
예제 #5
0
    def draw_points(self, gc: wx.GraphicsContext, points: List[Vec2],
                    radius: float):
        """
        Drawing points for arrow.

        Args: 
            self: the Designer Window to initialize.
            gc (wx.GraphixContext): Graphics context to modify.
            points (List[Vect2]): Points to be drawn in form of a list.
            radius (float): radius for the points.

        """
        gc.SetPen(wx.Pen(wx.BLACK, 2))
        gc.SetBrush(wx.Brush(wx.BLACK, wx.BRUSHSTYLE_FDIAGONAL_HATCH))
        plotted = [p * self.csize for p in points]  # points to be plotted
        if self.dragging:
            assert self.hover_idx != -1 and self.dragged_point is not None
            plotted[self.hover_idx] = self.dragged_point

        gc.DrawLines([wx.Point2D(*p)
                      for p in plotted] + [wx.Point2D(*plotted[0])])
        for i, p in enumerate(plotted):
            if self.dragging and i == self.hover_idx:
                continue
            if i == 3:
                # the last point is the tip, so draw it in a different color
                gc.SetPen(wx.BLACK_PEN)
                gc.SetBrush(wx.BLACK_BRUSH)
            else:
                gc.SetPen(self.handle_pen)
                gc.SetBrush(self.handle_brush)
            self.draw_point(gc, p, radius)

        # Draw the hover point
        if self.hover_idx != -1:
            point = self.dragged_point if self.dragging else plotted[
                self.hover_idx]
            assert self.hover_idx >= 0 and self.hover_idx < 4
            assert point is not None
            gc.SetPen(self.hl_handle_pen)
            gc.SetBrush(self.hl_handle_brush)
            self.draw_point(gc, point, radius)

            if self.dragging:
                assert self.dragged_point is not None
                drop_point = self.projected_landing(self.dragged_point)
                gc.SetPen(self.phantom_pen)
                gc.SetBrush(self.phantom_brush)
                self.draw_point(gc, drop_point, radius)
예제 #6
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)
예제 #7
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)
예제 #8
0
파일: data.py 프로젝트: evilnose/PyRKViewer
 def paint_arrow_tip(self, gc: wx.GraphicsContext, fill: wx.Colour):
     assert len(self.arrow_adjusted_coords) == 4, \
         "Arrow adjusted coords is not of length 4: {}".format(self.arrow_adjusted_coords)
     gc.SetPen(gc.CreatePen(wx.GraphicsPenInfo(fill)))
     gc.SetBrush(wx.Brush(fill))
     gc.DrawLines([wx.Point2D(*(coord))
                   for coord in self.arrow_adjusted_coords])
예제 #9
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()
예제 #10
0
 def draw_brush(self, gc: wx.GraphicsContext):
     gc.SetBrush(self.brush_fill)
     gc.DrawEllipse(
         self.pos.real - self.tool_size / 2.0,
         self.pos.imag - self.tool_size / 2.0,
         self.tool_size,
         self.tool_size,
     )
예제 #11
0
 def process_draw(self, gc: wx.GraphicsContext):
     if self.path:
         gc.SetPen(self.pen)
         gc.SetBrush(wx.TRANSPARENT_BRUSH)
         path = Path(self.path)
         if self.mouse_position is not None:
             if self.c0:
                 path.smooth_cubic(self.c0, self.mouse_position)
             else:
                 path.line(self.mouse_position)
         gpath = self.render.make_path(gc, path)
         gc.DrawPath(gpath)
         del gpath
예제 #12
0
    def do_paint(self, gc: wx.GraphicsContext):
        self.bezier.do_paint(gc, self.reaction.fill_color, self.selected)

        # draw centroid
        color = theme[
            'handle_color'] if self.selected else self.reaction.fill_color
        pen = wx.Pen(color)
        brush = wx.Brush(color)
        gc.SetPen(pen)
        gc.SetBrush(brush)
        radius = settings['reaction_radius'] * cstate.scale
        center = self.bezier.centroid * cstate.scale - Vec2.repeat(radius)
        gc.DrawEllipse(center.x, center.y, radius * 2, radius * 2)
예제 #13
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,
              corner_radius: float = 0):
    """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.
        corner_radius: The corner radius of the rounded rectangle. Defaults to 0.
    """
    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.DrawRoundedRectangle(x, y, width, height, corner_radius)
예제 #14
0
파일: data.py 프로젝트: evilnose/PyRKViewer
def paint_handle(gc: wx.GraphicsContext, base: Vec2, handle: Vec2, hovering: bool):
    """Paint the handle as given by its base and tip positions, highlighting it if hovering."""
    c = get_theme('highlighted_handle_color') if hovering else get_theme('handle_color')
    brush = wx.Brush(c)
    pen = gc.CreatePen(wx.GraphicsPenInfo(c))

    gc.SetPen(pen)

    # Draw handle lines
    gc.StrokeLine(*base, *handle)

    # Draw handle circles
    gc.SetBrush(brush)
    gc.DrawEllipse(handle.x - HANDLE_RADIUS, handle.y - HANDLE_RADIUS,
                   2 * HANDLE_RADIUS, 2 * HANDLE_RADIUS)
예제 #15
0
    def process_draw(self, gc: wx.GraphicsContext):
        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)
        gc.SetBrush(wx.RED_BRUSH)
        gc.DrawEllipse(self.track_object[0], self.track_object[1], 5000, 5000)
        if self.last_position:
            gc.DrawEllipse(self.last_position[0], self.last_position[1], 5000,
                           5000)

        if self.series is not None and len(self.series) > 1:
            gc.SetPen(self.pen)
            gc.StrokeLines(self.series)
예제 #16
0
    def do_paint(self, gc: wx.GraphicsContext):
        """Paint the handle as given by its base and tip positions, highlighting it if hovering."""
        assert self.data.base is not None
        c = theme['highlighted_handle_color'] if self.hovering else theme[
            'handle_color']
        brush = wx.Brush(c)
        pen = gc.CreatePen(wx.GraphicsPenInfo(c))

        sbase = self.data.base * cstate.scale
        stip = self.data.tip * cstate.scale

        gc.SetPen(pen)

        # Draw handle lines
        gc.StrokeLine(*sbase, *stip)

        # Draw handle circles
        gc.SetBrush(brush)
        gc.DrawEllipse(stip.x - BezierHandle.HANDLE_RADIUS,
                       stip.y - BezierHandle.HANDLE_RADIUS,
                       2 * BezierHandle.HANDLE_RADIUS,
                       2 * BezierHandle.HANDLE_RADIUS)
예제 #17
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
예제 #18
0
 def process_draw(self, gc: wx.GraphicsContext):
     if self.text is not None:
         gc.SetPen(self.pen)
         gc.SetBrush(wx.TRANSPARENT_BRUSH)
         gc.DrawText(self.text.text, self.x, self.y)