def draw(self, scale): controlSoftColor = self.controlSoftColor controlStrongColor = self.controlStrongColor if self._roundedGlyph is not None: self._roundedGlyph.drawPreview(scale, styleFill=False, showNodes=False, strokeWidth=2, strokeColor=controlStrongColor) for point in self.roundablePoints: x, y = point.x, point.y (cx, cy), r = self.getControlPoint(point) controlSoftColor.set() controlStrongColor.setStroke() radiusCircle = NSBezierPath.bezierPathWithOvalInRect_( ((x - r, y - r), (r * 2, r * 2))) radiusCircle.fill() radiusCircle.setLineWidth_(scale) radiusCircle.stroke() controlStrongColor.set() cor = 12 * scale controlDot = NSBezierPath.bezierPathWithOvalInRect_( ((cx - cor, cy - cor), (cor * 2, cor * 2))) controlDot.fill() if point.labels['cornerRadius']: fill(1) fontSize(9 * scale) _r = str(r) textBox(_r, (cx - cor, cy - (cor * 1.5), cor * 2, cor * 2), align='center')
def draw(self, scale): controlSoftColor = self.controlSoftColor controlStrongColor = self.controlStrongColor if self._roundedGlyph is not None: self._roundedGlyph.drawPreview( scale, styleFill=False, showNodes=False, strokeWidth=2, strokeColor=controlStrongColor ) for point in self.roundablePoints: x, y = point.x, point.y (cx, cy), r = self.getControlPoint(point) controlSoftColor.set() controlStrongColor.setStroke() radiusCircle = NSBezierPath.bezierPathWithOvalInRect_(((x - r, y - r), (r * 2, r * 2))) radiusCircle.fill() radiusCircle.setLineWidth_(scale) radiusCircle.stroke() controlStrongColor.set() cor = 12 * scale controlDot = NSBezierPath.bezierPathWithOvalInRect_(((cx - cor, cy - cor), (cor * 2, cor * 2))) controlDot.fill() if point.labels["cornerRadius"]: fill(1) fontSize(9 * scale) _r = str(r) textBox(_r, (cx - cor, cy - (cor * 1.5), cor * 2, cor * 2), align="center")
def drawRect_(self, rect): NSColor.whiteColor().set() NSRectFill(self.bounds()) origin = (self.center[0] - self.radius, self.center[1] - self.radius) size = (2 * self.radius, 2 * self.radius) dotRect = (origin, size) self.color.set() NSBezierPath.bezierPathWithOvalInRect_(dotRect).fill()
def drawRect_(self, rect): NSColor.whiteColor().set() NSRectFill(self.bounds()) origin = (self.center[0]-self.radius, self.center[1]-self.radius) size = (2 * self.radius, 2 * self.radius) dotRect = (origin, size) self.color.set() NSBezierPath.bezierPathWithOvalInRect_(dotRect).fill()
def DrawTableLines(list, colour, thickness): global myDialog for i, point in enumerate(list): try: drawline(list[i][1]*mm, list[i][2]*mm, list[i+1][1]*mm, list[i+1][2]*mm, colour, thickness, None) except: pass NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(colour[0], colour[1], colour[2], colour[3], 1).set() Rect = NSMakeRect(point[1]*mm-(thickness), point[2]*mm-(thickness), thickness*2, thickness*2) NSBezierPath.bezierPathWithOvalInRect_(Rect).fill() if Glyphs.boolDefaults["com_yanone_Autopsy_drawpointsvalues"]: DrawText(pdffont['Regular'], pointsvaluefontsize, glyphcolour, point[1]*mm + (thickness/6+1)*mm, point[2]*mm - (thickness/6+2.5)*mm, str(int(round(point[0]))))
def setPixel(self, event, dragging=False): if self.data is None: return False try: editView = self.editViewController().graphicView() except: return False layer = editView.activeLayer() try: master = layer.parent.parent.masters[layer.layerId] except KeyError: return False if master is None: return False # Get location of click in font coordinates Loc = editView.getActiveLocation_(event) loc_pixel = ((Loc.x - self.rect.origin.x) / self.pixel_size, (Loc.y - self.rect.origin.y) / self.pixel_size / self.pixel_ratio) if self.prev_location != loc_pixel: x, y = loc_pixel current = NSGraphicsContext.currentContext() context = NSGraphicsContext.graphicsContextWithBitmapImageRep_( self.data) if context is None: self.prev_location = loc_pixel print("Could not get context in setPixel") return False NSGraphicsContext.saveGraphicsState() NSGraphicsContext.setCurrentContext_(context) if self.erase: NSColor.whiteColor().set() else: NSColor.blackColor().set() effective_size = self.pen_size / self.pixel_size if dragging and self.prev_location is not None: px, py = self.prev_location path = NSBezierPath.alloc().init() path.setLineCapStyle_(NSRoundLineCapStyle) path.setLineWidth_(effective_size) # path.strokeLineFromPoint_toPoint_(x, y, x + self.pen_size, y + self.pen_size) path.moveToPoint_((px, py)) path.lineToPoint_((x, y)) path.stroke() self.needs_save = True else: half = effective_size / 2 rect = NSMakeRect(x - half, y - half, effective_size, effective_size) path = NSBezierPath.bezierPathWithOvalInRect_(rect) path.fill() self.needs_save = True # For rectangular pens: # NSBezierPath.fillRect_(rect) NSGraphicsContext.setCurrentContext_(current) NSGraphicsContext.restoreGraphicsState() self.prev_location = loc_pixel return True
def extensionIconPlaceholder(self): width = 200 height = 200 image = NSImage.alloc().initWithSize_((width, height)) image.lockFocus() path = NSBezierPath.bezierPathWithOvalInRect_( ((0, 0), (width, height))) color1 = NSColor.disabledControlTextColor() color1.set() path.fill() image.unlockFocus() return image
def DrawTableLines(list, colour, thickness): global myDialog for i, point in enumerate(list): try: drawline(list[i][1] * mm, list[i][2] * mm, list[i + 1][1] * mm, list[i + 1][2] * mm, colour, thickness, None) except: pass NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_( colour[0], colour[1], colour[2], colour[3], 1).set() Rect = NSMakeRect(point[1] * mm - (thickness), point[2] * mm - (thickness), thickness * 2, thickness * 2) NSBezierPath.bezierPathWithOvalInRect_(Rect).fill() if Glyphs.boolDefaults["com_yanone_Autopsy_drawpointsvalues"]: DrawText(pdffont['Regular'], pointsvaluefontsize, glyphcolour, point[1] * mm + (thickness / 6 + 1) * mm, point[2] * mm - (thickness / 6 + 2.5) * mm, str(int(round(point[0]))))
def animateOneFrame(self): # choose a random point. (x, y), (fw, fh) = self.frame() x, y = randrange(0.0, fw), randrange(0.0, fw) ballSize = randrange(10.0, 90.0) path = NSBezierPath.bezierPathWithOvalInRect_(((x, y), (ballSize, ballSize))) # make a random color. randomColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(random(), random(), random(), random()) # set it. randomColor.set() # draw a new ball. path.fill()
def foreground(self, layer): try: self.mouse_position = self.editViewController().graphicView( ).getActiveLocation_(Glyphs.currentEvent()) except: # self.logToConsole("foreground: mouse_position: %s" % str(e)) self.mouse_position = None return if self.mouse_position is not None: # Draw a preview circle at the mouse position x, y = self.mouse_position rect = NSMakeRect(x - self.pen_size / 2, y - self.pen_size * self.pixel_ratio / 2, self.pen_size, self.pen_size * self.pixel_ratio) path = NSBezierPath.bezierPathWithOvalInRect_(rect) path.setLineWidth_(1) if self.erase: NSColor.redColor().set() else: NSColor.lightGrayColor().set() path.stroke()
def _drawDirtyStateImage(value): if value: imageName = "defconAppKitFontListDirtyStateTrue" else: imageName = "defconAppKitFontListDirtyStateFalse" image = NSImage.imageNamed_(imageName) if image is None: # make the image width = 13 height = 17 image = NSImage.alloc().initWithSize_((width, height)) image.lockFocus() # draw if dirty if value: rect = ((2, 4), (9, 9)) path = NSBezierPath.bezierPathWithOvalInRect_(rect) path.addClip() # colors color1 = NSColor.colorWithCalibratedRed_green_blue_alpha_( 1.0, 0.1, 0.1, 1) color2 = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0.5, 0.0, 0.0, 1) # fill color1.set() path.fill() # shadow try: gradient = NSGradient.alloc().initWithColors_([color1, color2]) gradient.drawInBezierPath_angle_(path, -90) except NameError: pass # stroke color2.set() path.setLineWidth_(2) path.stroke() image.unlockFocus() image.setName_(imageName) image = NSImage.imageNamed_(imageName) return image
def _drawDirtyStateImage(value): if value: imageName = "defconAppKitFontListDirtyStateTrue" else: imageName = "defconAppKitFontListDirtyStateFalse" image = NSImage.imageNamed_(imageName) if image is None: # make the image width = 13 height = 17 image = NSImage.alloc().initWithSize_((width, height)) image.lockFocus() # draw if dirty if value: rect = ((2, 4), (9, 9)) path = NSBezierPath.bezierPathWithOvalInRect_(rect) path.addClip() # colors color1 = NSColor.colorWithCalibratedRed_green_blue_alpha_(1.0, 0.1, 0.1, 1) color2 = NSColor.colorWithCalibratedRed_green_blue_alpha_(0.5, 0.0, 0.0, 1) # fill color1.set() path.fill() # shadow try: gradient = NSGradient.alloc().initWithColors_([color1, color2]) gradient.drawInBezierPath_angle_(path, -90) except NameError: pass # stroke color2.set() path.setLineWidth_(2) path.stroke() image.unlockFocus() image.setName_(imageName) image = NSImage.imageNamed_(imageName) return image
def _ns_oval_path(self, ns_rect): ns_path = NSBezierPath.bezierPathWithOvalInRect_(ns_rect) ns_path.setLineWidth_(self._pensize) return ns_path
def oval(x, y, width, height): # draws an oval drawPath(NSBezierPath.bezierPathWithOvalInRect_(NSMakeRect(x, y, width, height)))
from AppKit import NSBezierPath, NSFont, NSApplication # Force NSApp initialisation. NSApplication.sharedApplication().activateIgnoringOtherApps_(0) p1 = NSBezierPath.bezierPathWithOvalInRect_(((0, 0), (100, 100))) p2 = NSBezierPath.bezierPathWithOvalInRect_(((40, 40), (100, 100))) # Outside of bounding box p3 = NSBezierPath.bezierPathWithOvalInRect_(((110, 0), (100, 100))) # In bounding box, doesn't intersect p4 = NSBezierPath.bezierPathWithOvalInRect_(((72, 72), (100, 100))) from cPolymagic import * print intersects(p1, p4) f = NSFont.fontWithName_size_("Helvetica", 72) fp1 = NSBezierPath.bezierPath() fp1.moveToPoint_((100, 100)) fp1.appendBezierPathWithGlyph_inFont_(68, f) fp2 = NSBezierPath.bezierPath() fp2.moveToPoint_((110, 100)) fp2.appendBezierPathWithGlyph_inFont_(68, f) print intersects(fp1, fp2)
from AppKit import NSBezierPath, NSFont, NSApplication # Force NSApp initialisation. NSApplication.sharedApplication().activateIgnoringOtherApps_(0) p1 = NSBezierPath.bezierPathWithOvalInRect_(((0, 0), (100, 100))) p2 = NSBezierPath.bezierPathWithOvalInRect_(((40, 40), (100, 100))) # Outside of bounding box p3 = NSBezierPath.bezierPathWithOvalInRect_(((110, 0), (100, 100))) # In bounding box, doesn't intersect p4 = NSBezierPath.bezierPathWithOvalInRect_(((72, 72), (100, 100))) from cPolymagic import * print intersects(p1, p4) f = NSFont.fontWithName_size_("Helvetica", 72) fp1 = NSBezierPath.bezierPath() fp1.moveToPoint_((100, 100)) fp1.appendBezierPathWithGlyph_inFont_(68, f) fp2 = NSBezierPath.bezierPath() fp2.moveToPoint_((110, 100)) fp2.appendBezierPathWithGlyph_inFont_(68, f) print intersects(fp1, fp2) # Some other thing inside of the function perhaps?
def drawDot(self, point, colorDots): widthP = int(self.w.ptThickness.get()) / self.scale rect = NSMakeRect(point[0]-widthP, point[1]-widthP, widthP * 2, widthP * 2) path = NSBezierPath.bezierPathWithOvalInRect_(rect) colorDots.set() path.fill()
def oval(x, y, width, height): # draws an oval drawPath( NSBezierPath.bezierPathWithOvalInRect_(NSMakeRect(x, y, width, height)))