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 do_paint(self, gc: wx.GraphicsContext): if self.gfont is None or self.font_scale != cstate.scale: self.font_scale = cstate.scale font = wx.Font(wx.FontInfo(10 * cstate.scale)) self.gfont = gc.CreateFont(font, wx.BLACK) gc.SetFont(self.gfont) s_aligned_rect = self.node.s_rect.aligned() aligned_border_width = max( even_round(self.node.border_width * cstate.scale), 2) width, height = s_aligned_rect.size draw_rect( gc, s_aligned_rect, fill=self.node.fill_color, border=self.node.border_color, border_width=aligned_border_width, ) # draw text tw, th, _, _ = gc.GetFullTextExtent( self.node.id_) # optimize by caching? tx = (width - tw) / 2 ty = (height - th) / 2 gc.DrawText(self.node.id_, self.node.s_position.x + tx, self.node.s_position.y + ty)
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 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 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() 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()
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, )
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 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.cam.frame_bitmap is None: font = wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD) gc.SetFont(font, wx.BLACK) if self.cam.camera is None: gc.DrawText( _("Camera backend failure...\nCannot attempt camera connection." ), 0, 0, ) else: gc.DrawText(_("Fetching Frame..."), 0, 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
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 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): # 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_point(self, gc: wx.GraphicsContext, point: Vec2, radius: float): """ Drawing a single point. Args: gc: Graphics context to modify. point: Point to be drawn. radius: Radius of the point. """ gc.DrawEllipse(*(point - Vec2.repeat(radius / 2)), radius, radius)
def process_draw(self, gc: wx.GraphicsContext): """ Draws the current widget, simply a bitmap. @param gc: @return: """ self.left = self.widget.x + self.widget.r_major - self.width/2 self.top = self.widget.y - self.height/2 self.right = self.left + self.size self.bottom = self.top + self.size gc.DrawBitmap(self.bitmap, self.left, self.top , self.width, self.height)
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 draw_point(self, gc: wx.GraphicsContext, point: Vec2, radius: float): """ Drawing a single point. Args: self: the Designer Window to initialize. gc (wx.GraphixContext): Graphics context to modify. point (Vect2): Point to be drawn. radius (float): radius for the point. """ gc.DrawEllipse(*(point - Vec2.repeat(radius / 2)), radius, 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 render_cutcode(self, cutcode: CutCode, gc: wx.GraphicsContext, x: int = 0, y: int = 0): last_point = None p = gc.CreatePath() for cut in cutcode: start = cut.start() end = cut.end() if last_point != start: p.MoveToPoint(start[0] + x, start[1] + y) if isinstance(cut, LineCut): p.AddLineToPoint(end[0] + x, end[1] + y) elif isinstance(cut, QuadCut): p.AddQuadCurveToPoint(cut.control[0] + x, cut.control[1] + y, end[0] + x, end[1] + y) elif isinstance(cut, CubicCut): p.AddCurveToPoint( cut.control1[0] + x, cut.control1[1] + y, cut.control2[0] + x, cut.control2[1] + y, end[0] + x, end[1] + y, ) elif isinstance(cut, RasterCut): image = cut.image try: matrix = Matrix(image.transform) except AttributeError: matrix = Matrix() step = cut.settings.raster_step matrix.post_scale(step, step) matrix.post_translate(x, y) gc.PushState() gc.ConcatTransform( wx.GraphicsContext.CreateMatrix(gc, ZMatrix(matrix))) cache = None cache_id = -1 try: cache = cut.cache cache_id = cut.cache_id except AttributeError: pass if cache_id != id(image.image): cache = None if cache is None: # max_allowed = 2048 cut.c_width, cut.c_height = image.image.size cut.cache = self.make_thumbnail(image.image) cut.cache_id = id(image.image) gc.DrawBitmap(cut.cache, 0, 0, cut.c_width, cut.c_height) gc.PopState() last_point = end gc.StrokePath(p) del p
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_points(self, gc: wx.GraphicsContext, points: List[Vec2], radius: float): """ Drawing points for arrow. Args: gc: The Graphics context to modify. points: The points to be drawn, in counterclockwise order, with the last point being the tip. radius: The radius of 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 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): 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): gc.PushState() gc.DrawBitmap(self.bitmap, self.left, self.top, self.width, self.height) gc.PopState()
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)