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
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)
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)
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])
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)
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)
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])
def process_draw(self, gc: wx.GraphicsContext): gc.PushState() gc.Translate(self.x, self.y) if self.series is not None and len(self.series) > 1: gc.SetPen(self.pen) gc.StrokeLines(self.series) gc.PopState()
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)
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)
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)
def draw_background(self, gc: wx.GraphicsContext): """ Drawing a window background. Args: self: the Designer Window to initialize. gc (wx.GraphixContext): Graphics context to modify. """ gc.SetPen(wx.Pen(wx.BLACK)) gc.StrokeLineSegments(self.begin_points, self.end_points)
def process_draw(self, gc: wx.GraphicsContext): if len(self.pos): if self.sim.progress < self.sim.max: pos = self.pos[self.sim.progress - 1] else: pos = self.pos[-1] if pos > 1: starts = self.starts[:pos] ends = self.ends[:pos] gc.SetPen(wx.BLACK_DASHED_PEN) gc.StrokeLineSegments(starts, ends)
def render_gcode(self, cutcode: CutCode, gc: wx.GraphicsContext, x: int = 0, y: int = 0): """ Render scene information. """ if not len(cutcode): return gc.SetPen(self.gcode_pen) self.render_cutcode(cutcode, gc, x, y)
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)
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
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)
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)
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)
def draw_background(self, gc: wx.GraphicsContext): """ Drawing the gridlines background. """ gc.SetPen(wx.Pen(wx.BLACK)) gc.StrokeLineSegments(self.begin_points, self.end_points)
def process_draw(self, gc: wx.GraphicsContext): if self.series is not None and len(self.series) > 1: gc.SetPen(self.pen) gc.StrokeLines(self.series)
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)