class Button
Attributes
image[RW]
imageOver[RW]
posX[RW]
posY[RW]
Public Class Methods
new(x,y,img,imgOver,act,g)
click to toggle source
# File lib/button.rb, line 3 def initialize (x,y,img,imgOver,act,g) #position @posX = x @posY = y @image = img #image @actualImage = img #image to show @imageOver = imgOver #hover image @action = act #lambda with action @buttonWidth = @image.width.to_f #button image width @buttonHeight = @image.height.to_f #button image height @game = g #gosu game window end
Public Instance Methods
clicked()
click to toggle source
# File lib/button.rb, line 26 def clicked #if is cursor over button make action in lamdba if isHovering @action.call end end
draw()
click to toggle source
# File lib/button.rb, line 40 def draw #draw button @actualImage.draw(@posX, @posY, 2) end
isHovering()
click to toggle source
# File lib/button.rb, line 16 def isHovering #is cursor hovering over this stone x = @game.mouse_x y = @game.mouse_y if x >= @posX && x <= (@posX + @buttonWidth) && y >= @posY && y <= @posY + @buttonHeight true else false end end
update()
click to toggle source
# File lib/button.rb, line 32 def update #set image based on if is cursor hovering over it if isHovering @actualImage = @imageOver else @actualImage = @image end end