Update Button to use evnts

This commit is contained in:
2019-03-01 11:48:54 -06:00
parent 8664c90de7
commit 21904ae6fe
4 changed files with 52 additions and 39 deletions

View File

@@ -9,45 +9,32 @@ module CyberarmEngine
@text.draw
end
def mouse_over?; false; end
def enter(sender)
@background = @options[:interactive_hover_background]
@text.color = @options[:interactive_active_stroke]
end
def leave(sender)
@background = @options[:interactive_background]
@text.color = @options[:interactive_stroke]
end
def clicked_left_mouse_button(sender, x, y)
@block.call if block
end
def draw_button
$window.draw_rect(relative_x, relative_y, width, height, @options[:element_background], @z+1)
if mouse_over? && $window.button_down?(Gosu::MsLeft)
@background ||= @options[:interactive_background]
$window.draw_rect(
relative_x + @options[:interactive_border_size],
relative_y + @options[:interactive_border_size],
width - (@options[:interactive_border_size]*2),
height- (@options[:interactive_border_size]*2),
@options[:interactive_active_background],
@background,
@z+2
)
@text.color = @options[:interactive_active_stroke]
elsif mouse_over?
$window.draw_rect(
relative_x + @options[:interactive_border_size],
relative_y + @options[:interactive_border_size],
width - (@options[:interactive_border_size]*2),
height- (@options[:interactive_border_size]*2),
@options[:interactive_hover_background],
@z+2
)
# show_tooltip
@text.color = @options[:interactive_stroke]
else
$window.draw_rect(
relative_x + @options[:interactive_border_size],
relative_y + @options[:interactive_border_size],
width - (@options[:interactive_border_size]*2),
height- (@options[:interactive_border_size]*2),
@options[:interactive_background],
@z+2
)
@text.color = @options[:interactive_stroke]
end
end
end
end

View File

@@ -8,7 +8,6 @@ module CyberarmEngine
def initialize(options = {}, block = nil)
super
# @current_position = Vector.new(@x, @y)
@origin_x, @origin_x = @x, @x
@origin_width, @origin_height = @width, @height
@@ -105,7 +104,7 @@ module CyberarmEngine
def position_on_current_line(element)
element.x = @current_position.x
element.y = @current_position.y
@current_position.x += element.width
@current_position.x += element.outer_width
@current_position.x = @x if @current_position.x >= max_width
end
@@ -113,7 +112,7 @@ module CyberarmEngine
def move_to_next_line(element)
element.x = @current_position.x
element.y = @current_position.y
@current_position.y += element.height
@current_position.y += element.outer_height
end
end
end

View File

@@ -88,6 +88,14 @@ module CyberarmEngine
@height + (@padding * 2)
end
def outer_width
width + (@margin * 2)
end
def outer_height
height + (@margin * 2)
end
def relative_x
@x# + @margin
end

View File

@@ -73,11 +73,30 @@ module CyberarmEngine
end
def redirect_mouse_button(button)
@mouse_over.publish(:"#{button}_mouse_button", window.mouse_x, window.mouse_y) if @mouse_over
if @focus && @mouse_over != @focus
@focus.publish(:blur)
@focus = nil
end
if @mouse_over
@mouse_down_position[button] = Vector.new(window.mouse_x, window.mouse_y)
@mouse_down_on[button] = @mouse_over
@mouse_over.publish(:"#{button}_mouse_button", window.mouse_x, window.mouse_y)
else
@mouse_down_position[button] = nil
@mouse_down_on[button] = nil
end
end
def redirect_released_mouse_button(button)
@mouse_over.publish(:"released_#{button}_mouse_button", window.mouse_x, window.mouse_y) if @mouse_over
@mouse_over.publish(:"clicked_#{button}_mouse_button", window.mouse_x, window.mouse_y) if @mouse_over == @mouse_down_on[button]
p @mouse_over.class, @mouse_down_on[button].class
@mouse_down_position[button] = nil
@mouse_down_on[button] = nil
end
def redirect_holding_mouse_button(button)