コード例 #1
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])
コード例 #2
0
ファイル: data.py プロジェクト: evilnose/PyRKViewer
    def do_paint(self, gc: wx.GraphicsContext, fill: wx.Colour, selected: bool):
        self._recompute(for_collision=False)
        rxn_color: wx.Colour
        # Draw bezier curve
        if selected:
            rxn_color = get_theme('selected_reaction_fill')
        else:
            rxn_color = fill

        pen = gc.CreatePen(wx.GraphicsPenInfo(rxn_color).Width(self.thickness))

        gc.SetPen(pen)
        # gc.StrokeLines([wx.Point2D(*(p * cstate.scale)) for p in self.bezier_points])
        path = gc.CreatePath()
        points = [p for p in (self.node_intersection,
                              self.handle.tip,
                              self.centroid_handle.tip,
                              self.real_center)]
        path.MoveToPoint(*points[0])
        if self.bezierCurves:
            path.AddCurveToPoint(*points[1], *points[2], *points[3])
        else:
            path.AddLineToPoint(*points[3])
        gc.StrokePath(path)

        if selected:
            assert self.node_intersection is not None
            self.handle.base = self.node_intersection

        # Draw arrow tip
        if not self.is_source:
            color = get_theme('handle_color') if selected else fill
            self.paint_arrow_tip(gc, color)
コード例 #3
0
ファイル: utils.py プロジェクト: nnguyen19/PyRKViewer
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)
コード例 #4
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)
コード例 #5
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)