Created
April 15, 2011 04:06
-
-
Save danielwestendorf/921125 to your computer and use it in GitHub Desktop.
MacRuby Progress indicator example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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