def drawRect(self, layer): self.getWidth() self.getColor() ascender = layer.ascender descender = layer.descender width = layer.width height = ascender - descender (left_width, right_width, top_width, bottom_width) = self.blindfoldWidth if not self.inverseBlindfold: for rect in [ # Left, right, top, bottom ((0, descender), (left_width, height)), ((width - right_width, descender), (right_width, height)), ((left_width, ascender - top_width), (width - left_width - right_width, top_width)), ((left_width, descender), (width - left_width - right_width, bottom_width)), ]: NSBezierPath.fillRect_(rect) else: rect = ((left_width, descender + bottom_width), (width - left_width - right_width, height - top_width - bottom_width)) NSBezierPath.fillRect_(rect)
def drawCentralArea(self, layer): '''Draw the central area (第二中心区域).''' spacing = self.centralAreaSpacing descender = layer.descender ascender = layer.ascender if not self.centralAreaRotateState: width = self.centralAreaWidth height = ascender - descender x_mid = layer.width * self.centralAreaPosition / 100 (x0, y0) = (x_mid - spacing / 2 - width / 2, descender) (x1, y1) = (x_mid + spacing / 2 - width / 2, descender) else: width = layer.width height = self.centralAreaWidth y_mid = descender + (ascender - descender) * self.centralAreaPosition / 100 (x0, y0) = (0, y_mid - spacing / 2 - height / 2) (x1, y1) = (0, y_mid + spacing / 2 - height / 2) # TODO: color color = NSColor.systemGrayColor().colorWithAlphaComponent_(0.2) color.set() NSBezierPath.fillRect_(((x0, y0), (width, height))) NSBezierPath.fillRect_(((x1, y1), (width, height)))
def drawRect_(self, rect): """ we raw the background gradient and graph outline then clip the inner rect and draw the bars """ bounds = self.bounds() # get our view bounds insetBounds = NSInsetRect(bounds, 2, 2) # set the inside ortion r = NSBezierPath.bezierPathWithRect_( bounds) # create a new bezier rect self.grad.drawInBezierPath_angle_(r, 90.0) # and draw gradient in it self.borderColor.set() # set border to white NSBezierPath.setDefaultLineWidth_(1.0) # set line width for outline NSBezierPath.strokeRect_(bounds) # draw outline NSBezierPath.clipRect_(insetBounds) # set the clipping path insetBounds.size.height -= 2 # leave room at the top (purely my personal asthetic if self.dataQueue: barRect = NSRect() # init the rect # find out the max value so we can scale the graph maxB = max(max(self.dataQueue), self.minHeigth or 1) # disable anti-aliasing since it looks bad shouldAA = NSGraphicsContext.currentContext().shouldAntialias() NSGraphicsContext.currentContext().setShouldAntialias_(False) # draw each bar barRect.origin.x = insetBounds.size.width - self.lineWidth + 2 for sample in reversed(self.dataQueue): # set drawing color if sample >= self.limit: self.lineColorAboveLimit.set() else: self.lineColor.set() barRect.origin.y = insetBounds.origin.y barRect.size.width = self.lineWidth barRect.size.height = ( (int(sample) * insetBounds.size.height) / maxB) NSBezierPath.fillRect_(barRect) barRect.origin.x = barRect.origin.x - self.lineWidth - self.lineSpacing NSGraphicsContext.currentContext().setShouldAntialias_(shouldAA)
def drawRect_(self, rect): """ we raw the background gradient and graph outline then clip the inner rect and draw the bars """ bounds = self.bounds() # get our view bounds insetBounds = NSInsetRect(bounds, 2, 2) # set the inside ortion r = NSBezierPath.bezierPathWithRect_(bounds) # create a new bezier rect self.grad.drawInBezierPath_angle_(r, 90.0) # and draw gradient in it self.borderColor.set() # set border to white NSBezierPath.setDefaultLineWidth_(1.0) # set line width for outline NSBezierPath.strokeRect_(bounds) # draw outline NSBezierPath.clipRect_(insetBounds) # set the clipping path insetBounds.size.height -= 2 # leave room at the top (purely my personal asthetic if self.dataQueue: barRect = NSRect() # init the rect # find out the max value so we can scale the graph maxB = max(max(self.dataQueue), self.minHeigth or 1) # disable anti-aliasing since it looks bad shouldAA = NSGraphicsContext.currentContext().shouldAntialias() NSGraphicsContext.currentContext().setShouldAntialias_(False) # draw each bar barRect.origin.x = insetBounds.size.width - self.lineWidth + 2 for sample in reversed(self.dataQueue): # set drawing color if sample >= self.limit: self.lineColorAboveLimit.set() else: self.lineColor.set() barRect.origin.y = insetBounds.origin.y barRect.size.width = self.lineWidth barRect.size.height = ((int(sample) * insetBounds.size.height) / maxB) NSBezierPath.fillRect_(barRect) barRect.origin.x = barRect.origin.x - self.lineWidth - self.lineSpacing NSGraphicsContext.currentContext().setShouldAntialias_(shouldAA)