def drawRect_(self, rect): gradient = NSGradient.alloc().initWithColors_([ NSColor.colorWithDeviceRed_green_blue_alpha_( 121 / 256.0, 121 / 256.0, 121 / 256.0, 1), NSColor.colorWithDeviceRed_green_blue_alpha_( 111 / 256.0, 111 / 256.0, 111 / 256.0, 1) ]) gradient.drawInRect_angle_(rect, 90.0) NSView.drawRect_(self, rect)
def initWithFrame_(self, frame): """ basic constructor for views. here we init colors and gradients """ self = super(CBGraphView, self).initWithFrame_(frame) if self: self.gradientGray = NSColor.colorWithCalibratedRed_green_blue_alpha_(50/255.0, 50/255.0, 50/255.0, 1.0) self.lineColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(33/255.0, 104/255.0, 198/255.0, 1.0) self.lineColorAboveLimit = NSColor.redColor() self.borderColor = NSColor.whiteColor() self.grad = NSGradient.alloc().initWithStartingColor_endingColor_(NSColor.blackColor(), self.gradientGray) self.grad.retain() return self
def initWithFrame_(self, frame): """ basic constructor for views. here we init colors and gradients """ self = objc.super(CBGraphView, self).initWithFrame_(frame) if self: self.gradientGray = NSColor.colorWithCalibratedRed_green_blue_alpha_( 50 / 255.0, 50 / 255.0, 50 / 255.0, 1.0) self.lineColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 33 / 255.0, 104 / 255.0, 198 / 255.0, 1.0) self.lineColorAboveLimit = NSColor.redColor() self.borderColor = NSColor.whiteColor() self.grad = NSGradient.alloc().initWithStartingColor_endingColor_( NSColor.blackColor(), self.gradientGray) self.grad.retain() return self
def drawRect_(self, rect): gradient = NSGradient.alloc().initWithColors_( [NSColor.colorWithDeviceRed_green_blue_alpha_(121/256.0, 121/256.0, 121/256.0, 1), NSColor.colorWithDeviceRed_green_blue_alpha_(111/256.0, 111/256.0, 111/256.0, 1)]) gradient.drawInRect_angle_(rect, 90.0) NSView.drawRect_(self, rect)
def drawRect_(self, rect): r = self.bounds() r.size.width -= 0.5 r.size.height += 4 if self.draggedOut: NSColor.colorWithDeviceWhite_alpha_(0.4, 1.0).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(r, 5, 5) path.fill() else: if self == self.switcher.activeItem(): NSColor.controlColor().set() else: NSColor.colorWithDeviceWhite_alpha_(0.6, 1.0).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(r, 5, 5) path.fill() NSColor.colorWithDeviceRed_green_blue_alpha_(0.3, 0.3, 0.3, 1.0).set() path.stroke() if self.badgeLabel and not self.mouseInside and not self.busyIndicator and not self.composing: # draw the number in redbadge indicator gradient = NSGradient.alloc().initWithStartingColor_endingColor_( NSColor.colorWithDeviceRed_green_blue_alpha_(0.9, 0.2, 0.2, 1), NSColor.colorWithDeviceRed_green_blue_alpha_(1.0, 0.2, 0.2, 1)) size = self.badgeLabel.size() size.width += 4 if size.width < 12: size.width = 12 bez = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(NSMakeRect(3, 5, size.width, 12), 6, 6) gradient.drawInBezierPath_angle_(bez, 90+45) self.badgeLabel.drawInRect_(NSMakeRect(3, 5, size.width, 12)) if not self.mouseInside and not self.busyIndicator and self.composing: rect = NSZeroRect.copy() rect.size = self.composeIcon.size() self.composeIcon.drawAtPoint_fromRect_operation_fraction_(NSMakePoint(1, 3), rect, NSCompositeSourceOver, 1) if not self.busyIndicator and self.screen_sharing_active: rect = NSZeroRect.copy() rect.size = self.screenIcon.size() self.screenIcon.drawAtPoint_fromRect_operation_fraction_(NSMakePoint(17, 3), rect, NSCompositeSourceOver, 1) if not self.draggedOut: shadow = NSShadow.alloc().init() shadow.setShadowOffset_(NSMakeSize(0, -1)) if self == self.switcher.activeItem(): shadow.setShadowColor_(NSColor.whiteColor()) else: shadow.setShadowColor_(NSColor.colorWithDeviceWhite_alpha_(0.7, 1.0)) para = NSParagraphStyle.defaultParagraphStyle().mutableCopy() para.setLineBreakMode_(NSLineBreakByTruncatingTail) para.setAlignment_(NSCenterTextAlignment) attribs = NSDictionary.dictionaryWithObjectsAndKeys_(NSFont.systemFontOfSize_(11), NSFontAttributeName, shadow, NSShadowAttributeName, para, NSParagraphStyleAttributeName) rect = self.bounds() rect.origin.y -= 3 rect.origin.x += 20 rect.origin.x = rect.origin.x + 12 if self.screen_sharing_active else rect.origin.x rect.size.width -= 46 rect.size.width = rect.size.width - 12 if self.screen_sharing_active else rect.size.width self.label.drawInRect_withAttributes_(rect, attribs)
def drawRect_(self, rect): r = self.bounds() r.size.width -= 0.5 r.size.height += 4 if self.draggedOut: NSColor.colorWithDeviceWhite_alpha_(0.4, 1.0).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( r, 5, 5) path.fill() else: if self == self.switcher.activeItem(): NSColor.controlColor().set() else: NSColor.colorWithDeviceWhite_alpha_(0.6, 1.0).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( r, 5, 5) path.fill() NSColor.colorWithDeviceRed_green_blue_alpha_(0.3, 0.3, 0.3, 1.0).set() path.stroke() if self.badgeLabel and not self.mouseInside and not self.busyIndicator and not self.composing: # draw the number in redbadge indicator gradient = NSGradient.alloc().initWithStartingColor_endingColor_( NSColor.colorWithDeviceRed_green_blue_alpha_(0.9, 0.2, 0.2, 1), NSColor.colorWithDeviceRed_green_blue_alpha_(1.0, 0.2, 0.2, 1)) size = self.badgeLabel.size() size.width += 4 if size.width < 12: size.width = 12 bez = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( NSMakeRect(3, 5, size.width, 12), 6, 6) gradient.drawInBezierPath_angle_(bez, 90 + 45) self.badgeLabel.drawInRect_(NSMakeRect(3, 5, size.width, 12)) if not self.mouseInside and not self.busyIndicator and self.composing: rect = NSZeroRect.copy() rect.size = self.composeIcon.size() self.composeIcon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint(1, 3), rect, NSCompositeSourceOver, 1) if not self.busyIndicator and self.screen_sharing_active: rect = NSZeroRect.copy() rect.size = self.screenIcon.size() self.screenIcon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint(17, 3), rect, NSCompositeSourceOver, 1) if not self.draggedOut: shadow = NSShadow.alloc().init() shadow.setShadowOffset_(NSMakeSize(0, -1)) if self == self.switcher.activeItem(): shadow.setShadowColor_(NSColor.whiteColor()) else: shadow.setShadowColor_( NSColor.colorWithDeviceWhite_alpha_(0.7, 1.0)) para = NSParagraphStyle.defaultParagraphStyle().mutableCopy() para.setLineBreakMode_(NSLineBreakByTruncatingTail) para.setAlignment_(NSCenterTextAlignment) attribs = NSDictionary.dictionaryWithObjectsAndKeys_( NSFont.systemFontOfSize_(11), NSFontAttributeName, shadow, NSShadowAttributeName, para, NSParagraphStyleAttributeName) rect = self.bounds() rect.origin.y -= 3 rect.origin.x += 20 rect.origin.x = rect.origin.x + 12 if self.screen_sharing_active else rect.origin.x rect.size.width -= 46 rect.size.width = rect.size.width - 12 if self.screen_sharing_active else rect.size.width self.label.drawInRect_withAttributes_(rect, attribs)
def setBackgroundGradientStart_andEnd_(self, startColor, endColor): """ let user change the gradient colors """ self.grad.release() self.grad = NSGradient.alloc().initWithStartingColor_endingColor_( startColor, endColor) self.grad.retain()
def setBackgroundGradientStart_andEnd_(self, startColor, endColor): """ let user change the gradient colors """ self.grad.release() self.grad = NSGradient.alloc().initWithStartingColor_endingColor_(startColor, endColor) self.grad.retain()