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 drawRect_(self, rect): # self._layer.drawInFrame_(bounds) # used in Georgs GlyphView try: bounds = self.bounds() NSColor.textBackgroundColor().set() NSRectFill(bounds) scaleFactor = self._scaleFactor thisGlyph = self._layer.parent layerWidth = self._layer.width * scaleFactor descender = self._layer.glyphMetrics()[3] * scaleFactor ascender = self._layer.glyphMetrics()[1] * scaleFactor ## This order is important! Wont work the other way around. bezierPathOnly = self._layer.bezierPath # Path Only if bezierPathOnly is not None: bezierPathOnly = bezierPathOnly.copy() bezierPathWithComponents = self._layer.completeBezierPath # Path & Components bezierPathOpenWithComponents = self._layer.completeOpenBezierPath # Path & Components # Set the scale #-------------- scale = NSAffineTransform.transform() scale.translateXBy_yBy_((bounds.size.width - layerWidth) / 2.0, (bounds.size.height - ascender + descender) / 2.0 - descender) scale.scaleBy_(scaleFactor) # Draw only path in black #------------------------ if thisGlyph.export: pathColor = NSColor.textColor() componentColor = NSColor.secondaryLabelColor() else: pathColor = NSColor.orangeColor() componentColor = NSColor.orangeColor() if bezierPathWithComponents: bezierPathWithComponents.transformUsingAffineTransform_(scale) componentColor.set() # Draw components in gray bezierPathWithComponents.fill() if bezierPathOnly: pathColor.set() bezierPathOnly.transformUsingAffineTransform_(scale) bezierPathOnly.fill() if bezierPathOpenWithComponents: pathColor.set() bezierPathOpenWithComponents.transformUsingAffineTransform_(scale) bezierPathOpenWithComponents.stroke() # Draw non-exported glyphs in orange #----------------------------------- else: NSColor.orangeColor().set() bezierPathWithComponents.transformUsingAffineTransform_(scale) bezierPathWithComponents.fill() attributes = {} attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(14) attributes[NSForegroundColorAttributeName] = NSColor.secondaryLabelColor() thisLKG = thisGlyph.leftKerningGroup thisRKG = thisGlyph.rightKerningGroup if thisLKG is not None: String = NSAttributedString.alloc().initWithString_attributes_(thisLKG, attributes) String.drawAtPoint_alignment_((12, 5), 0) if thisRKG is not None: String = NSAttributedString.alloc().initWithString_attributes_(thisRKG, attributes) String.drawAtPoint_alignment_((bounds.size.width - 12, 5), 2) # AUTO-WIDTH LABEL #----------------- if self._layer.hasAlignedWidth(): attributes[NSForegroundColorAttributeName] = NSColor.lightGrayColor() attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(11) String = NSAttributedString.alloc().initWithString_attributes_("Auto-Width", attributes) String.drawAtPoint_alignment_((bounds.size.width / 2.0, 5), 1) except: print(traceback.format_exc())
def background(self, layer): # Check if the grid should be drawn currentController = self.controller.view().window().windowController() if currentController: tool = currentController.toolDrawDelegate() if (tool.isKindOfClass_(NSClassFromString("GlyphsToolText")) or tool.isKindOfClass_(NSClassFromString("GlyphsToolHand"))): return try: master = layer.parent.parent.masters[layer.layerId] except KeyError: return if master is None: return gx, gy, grid_type = getGrid(master) if gx == 0 or gy == 0: return if grid_type == "div": upm = layer.parent.parent.upm gx = upm / gx gy = upm / gy NSColor.lightGrayColor().set() NSBezierPath.setDefaultLineWidth_(0.6 / self.getScale()) max_x = int(layer.width // gx + 2) min_y = int(master.descender // gy) max_y = int(master.ascender // gy + 1) max_xx = max_x * gx min_yy = min_y * gy max_yy = max_y * gy for x in range(-1, max_x + 1): xx = gx * x NSBezierPath.strokeLineFromPoint_toPoint_(NSPoint(xx, min_yy), NSPoint(xx, max_yy)) for y in range(min_y, max_y + 1): yy = gy * y NSBezierPath.strokeLineFromPoint_toPoint_(NSPoint(-gx, yy), NSPoint(max_xx, yy)) # NSBezierPath.setDefaultLineWidth_(1.0/self.getScale()) s = int(round(12 / self.getScale())) s2 = s * 0.25 sel = int(round(13 / self.getScale())) for p in layer.paths: for n in p.nodes: if n.type != OFFCURVE: x = n.position.x y = n.position.y if n.selected: s1 = sel else: s1 = s if abs((abs(x) + 1) % gx - 1) < 0.5: NSBezierPath.strokeLineFromPoint_toPoint_( NSPoint(x - s2, y - s1), NSPoint(x - s2, y + s1)) NSBezierPath.strokeLineFromPoint_toPoint_( NSPoint(x + s2, y - s1), NSPoint(x + s2, y + s1)) if abs((abs(y) + 1) % gy - 1) < 0.5: NSBezierPath.strokeLineFromPoint_toPoint_( NSPoint(x - s1, y - s2), NSPoint(x + s1, y - s2)) NSBezierPath.strokeLineFromPoint_toPoint_( NSPoint(x - s1, y + s2), NSPoint(x + s1, y + s2))
blueColor = NSColor.blueColor() brownColor = NSColor.brownColor() clearColor = NSColor.clearColor() cyanColor = NSColor.cyanColor() darkGrayColor = getRGBA(80, 80, 80) darkGreyColor = darkGrayColor grayColor = NSColor.grayColor() greyColor = grayColor grayColor = NSColor.grayColor() greenColor = NSColor.greenColor() lightGreenColor = getRGBA(75, 211, 154) darkGreenColor = getRGBA(41, 120, 37) lightestGrayColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0.98, 0.98, 0.98, 1) lightestGreyColor = lightestGrayColor lightGrayColor = NSColor.lightGrayColor() lightGreyColor = lightGrayColor magentaColor = NSColor.magentaColor() orangeColor = NSColor.orangeColor() lightOrangeColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0.98, 0.81, 0.32, 1) purpleColor = NSColor.purpleColor() opaquePurpleColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 1, 0, 1, 0.3) redColor = NSColor.redColor() opaqueRedColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 0, 0, 0.3) whiteColor = NSColor.whiteColor() opaqueWhiteColor = getRGBA(255, 255, 255, 0.5) yellowColor = NSColor.yellowColor() # Interface presets.
def drawBackgroundForInactiveLayers(self, layer): try: self.drawTopsAndBottoms(layer, NSColor.lightGrayColor()) except Exception as e: self.logToConsole("drawBackgroundForInactiveLayers: %s" % str(e))
def drawRect_(self, rect): ## needs to be `drawRect_` -- nothing else bounds = self.bounds() # thisUPM = self._layer.parent.parent.upm scaleFactor = self._scaleFactor thisUPM = self._upm * scaleFactor rectX, rectY, rectWidth, rectHeight = 0, 0, thisUPM, thisUPM self.rect = rect # self._layer.drawInFrame_(bounds) # used in Georgs GlyphView try: layerWidth = self._layer.width * scaleFactor descender = self._layer.glyphMetrics()[3] * scaleFactor ## this order is important! Wont work the other way around try: # pre Glyphs 2.3 bezierPathOnly = self._layer.copy().bezierPath() # Path Only bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath() # Path & Components except: # Glyphs 2.3 bezierPathOnly = self._layer.copy().bezierPath # Path Only bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath # Path & Components scale = NSAffineTransform.transform() scale.translateXBy_yBy_( rectWidth/2 - (layerWidth / 2.0) + self._margin/2, -descender + self._margin/2 ) scale.scaleBy_( scaleFactor ) if bezierPathWithComponents: bezierPathWithComponents.transformUsingAffineTransform_( scale ) if bezierPathOnly: bezierPathOnly.transformUsingAffineTransform_( scale ) ## DRAW COMPONENTS IN GRAY NSColor.darkGrayColor().set() # lightGrayColor bezierPathWithComponents.fill() ## CHANGE COLOR FOR NON-EXPORTED GLYPHS thisGlyph = self._layer.parent if thisGlyph.export: NSColor.blackColor().set() ## DRAW ONLY PATH IN BLACK if bezierPathOnly: bezierPathOnly.fill() else: NSColor.orangeColor().set() bezierPathWithComponents.fill() # print self.bounds() ## AUTO-WIDTH LABEL if self._layer.hasAlignedWidth(): paragraphStyle = NSMutableParagraphStyle.alloc().init() paragraphStyle.setAlignment_(2) ## 0=L, 1=R, 2=C, 3=justified attributes = {} attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(10) attributes[NSForegroundColorAttributeName] = NSColor.lightGrayColor() attributes[NSParagraphStyleAttributeName] = paragraphStyle String = NSAttributedString.alloc().initWithString_attributes_("Auto-Width", attributes) # String.drawAtPoint_((rectWidth, 0)) NSColor.redColor().set() # NSRectFill(((0, 0), (self.rect.size.width, 15))) String.drawInRect_(((0, 0), (self.rect.size.width, 15))) except: # pass print traceback.format_exc()
def drawRect_(self, rect): ## must be `drawRect_` - nothing else bounds = self.bounds() scaleFactor = self._scaleFactor thisUPM = self._upm * scaleFactor # = self._layer.parent.parent.upm rectX, rectY, rectWidth, rectHeight = 0, 0, thisUPM, thisUPM self.rect = rect # self._layer.drawInFrame_(bounds) # used in Georgs GlyphView try: thisGlyph = self._layer.parent layerWidth = self._layer.width * scaleFactor descender = self._layer.glyphMetrics()[3] * scaleFactor # ## This order is important! Wont work the other way around. # try: # pre Glyphs 2.3 # bezierPathOnly = self._layer.copy().bezierPath() # Path Only # bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath() # Path & Components # except: # Glyphs 2.3 # bezierPathOnly = self._layer.copy().bezierPath # Path Only # bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath # Path & Components ## This order is important! Wont work the other way around. try: # Glyphs 2.3 bezierPathOnly = self._layer.copy().bezierPath # Path Only bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath # Path & Components except: # Glyphs 2.4 bezierPathOnly = self._layer.copy().bezierPath # Path Only bezierPathWithComponents = self._layer.completeBezierPath # Path & Components # Set the scale #-------------- scale = NSAffineTransform.transform() scale.translateXBy_yBy_( rectWidth/2 - (layerWidth / 2.0) + self._margin/2, -descender + self._margin/2 ) scale.scaleBy_( scaleFactor ) if bezierPathWithComponents: bezierPathWithComponents.transformUsingAffineTransform_( scale ) if bezierPathOnly: bezierPathOnly.transformUsingAffineTransform_( scale ) # Draw components in gray #------------------------ NSColor.darkGrayColor().set() # lightGrayColor bezierPathWithComponents.fill() # Draw only path in black #------------------------ if thisGlyph.export: NSColor.blackColor().set() if bezierPathOnly: bezierPathOnly.fill() # Draw non-exported glyphs in orange #----------------------------------- else: NSColor.orangeColor().set() bezierPathWithComponents.fill() # AUTO-WIDTH LABEL #----------------- if self._layer.hasAlignedWidth(): paragraphStyle = NSMutableParagraphStyle.alloc().init() paragraphStyle.setAlignment_(2) ## 0=L, 1=R, 2=C, 3=justified attributes = {} attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(10) attributes[NSForegroundColorAttributeName] = NSColor.lightGrayColor() attributes[NSParagraphStyleAttributeName] = paragraphStyle String = NSAttributedString.alloc().initWithString_attributes_("Auto-Width", attributes) # String.drawAtPoint_((rectWidth, 0)) NSColor.redColor().set() # NSRectFill(((0, 0), (self.rect.size.width, 15))) String.drawInRect_(((0, 0), (self.rect.size.width, 15))) except: pass # print traceback.format_exc()