|
|
|
@ -73,6 +73,15 @@ class Button < UI |
|
|
|
|
@events = {} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def onclick |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# TODO: make this work |
|
|
|
|
# TODO: make this also work for KeyHooks |
|
|
|
|
def set_onclick(name, &block) |
|
|
|
|
self.class.send(:define_method, name, &block) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def hover? |
|
|
|
|
inx = window.mouse_x >= self.x && window.mouse_x <= self.x + self.width |
|
|
|
|
iny = window.mouse_y >= self.y - self.padding[:y] && window.mouse_y <= self.y + self.height + self.padding[:y] |
|
|
|
@ -82,14 +91,6 @@ class Button < UI |
|
|
|
|
self.selected = inx && iny |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def add_event(event_sym, method_ptr) |
|
|
|
|
self.events[event_sym] = method_ptr |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def onevent(event_sym, *args, **kwargs) |
|
|
|
|
self.events[event_sym].(*args, **kwargs) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def render |
|
|
|
|
sel = self.hover? ? :selected : :default |
|
|
|
|
self.draw_rect(0, 0, self.width, self.height, self.colors[:background][sel]) |
|
|
|
|