|
|
|
@ -74,10 +74,20 @@ class Button < UI |
|
|
|
|
def hover? |
|
|
|
|
inx = window.mouse_x >= self.x && window.mouse_x <= self.x + self.width + self.padding[:x] |
|
|
|
|
iny = window.mouse_y >= self.y && window.mouse_y <= self.y + self.height + self.padding[:y] |
|
|
|
|
# doing `n in (a..b).to....` is too slow |
|
|
|
|
# hence the ugly syntax above |
|
|
|
|
|
|
|
|
|
self.selected = inx && iny |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def method_ptr=(self, new_ptr) |
|
|
|
|
# TODO: make a method pointer for button presses etc |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def onclick(id) |
|
|
|
|
self.method_ptr.call(id, *args, **kwargs) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def render |
|
|
|
|
sel = self.hover? ? :selected : :default |
|
|
|
|
self.draw_rect(0, 0, self.width, self.height, self.colors[:background][sel]) |
|
|
|
|