0

I've got a NSStatusBar item I'm drawing an (variable depending on user settings) image onto. After the image is set, I draw a simple rectangle/bezierpath over the image to indicate a sort of progress. The progress/rect seems like it isn't updating, but when I change the color of the fill, you can see that it draws that properly, but the "progress rect" with the original color still exists behind it. Here is what I've got:

button.image = nil  // resetting this seems like it would also clear it out?
var img : NSImage
let perc = Int(cPerc)

if round == true {
    img = NSImage(named: "round")!
} else {
    img = NSImage(named: "square")!
}

button.image = img

let frame = CGRect(x: 0, y: 0, width: 25, height: 15)   // main button icon frame

drawInnerRect(frame: frame, cperc: self.curPerc, attr: atr) // draw the inside bezierpath
button.needsDisplay = true  // should update the drawing???
...


func drawInnerRect(frame frame: NSRect, cperc : NSNumber, attr: NSDictionary)
{
    let fillColor = attr.valueForKey("fill") as! NSColor

    statusItem.button!.image?.lockFocus()

        let per = ((cperc.doubleValue / 100.0) * 17.0)
        let rectanglePath = NSBezierPath(rect: NSMakeRect(frame.minX+2, frame.minY+2, CGFloat(per), 8))

        NSColor.clearColor().set()  // trying to use this *should* reset the rect fill??
        rectanglePath.fill()

        fillColor.setFill()
        rectanglePath.fill()

    statusItem.button!.image?.unlockFocus()
}

This is my first post on here, be gentle...

Andre
  • 1
  • 1
  • Welcome to SO. First of all, is this for OS X or iOS? Second, in which method is the first lines of code placed? – d00dle Oct 15 '15 at 06:22
  • Apologies for the late reply. This is OS X. The first bit (calling code) is in a function that's periodically called to update the button's image/text. There's no other manipulation of the image anywhere else. – Andre Oct 23 '15 at 22:25

0 Answers0