Skip to content

Instantly share code, notes, and snippets.

@danielwestendorf
Created April 15, 2011 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielwestendorf/921125 to your computer and use it in GitHub Desktop.
Save danielwestendorf/921125 to your computer and use it in GitHub Desktop.
MacRuby Progress indicator example
class ProgressIndicator < NSView
attr_accessor :progressPercent
attr_accessor :parent
def mouseDown(event)
point = convertPoint(event.locationInWindow, fromView: nil)
click_x = point.x #this is the point where the mouse was clicked on the x axis
click_y = point.y #this is the point where the mouse was clicked on the y axis
end
def drawRect(rect)
borderWidth = 1 #set your border width here
x = bounds.origin.x
y = bounds.origin.y
width = bounds.size.width
height = bounds.size.height
NSColor.lightGrayColor.set #color for the inside
NSRectFill(bounds)
NSColor.darkGrayColor.set #color for the border
NSFrameRectWithWidth(bounds, borderWidth) #draw the border
@progressPercent ||= 0.00 #draw out to the current percent width 100.0 - 0.0
progressWidth = width * (@progressPercent * 0.01) #get the actual point you need to move out to
progressRect = NSRect.new([x,y],[progressWidth, height]) #fill in the progress
NSRectFill(progressRect)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment