mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 13:12:34 +00:00
Update Button to use evnts
This commit is contained in:
@@ -9,45 +9,32 @@ module CyberarmEngine
|
|||||||
@text.draw
|
@text.draw
|
||||||
end
|
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
|
def draw_button
|
||||||
$window.draw_rect(relative_x, relative_y, width, height, @options[:element_background], @z+1)
|
$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(
|
$window.draw_rect(
|
||||||
relative_x + @options[:interactive_border_size],
|
relative_x + @options[:interactive_border_size],
|
||||||
relative_y + @options[:interactive_border_size],
|
relative_y + @options[:interactive_border_size],
|
||||||
width - (@options[:interactive_border_size]*2),
|
width - (@options[:interactive_border_size]*2),
|
||||||
height- (@options[:interactive_border_size]*2),
|
height- (@options[:interactive_border_size]*2),
|
||||||
@options[:interactive_active_background],
|
@background,
|
||||||
@z+2
|
@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
|
end
|
||||||
end
|
end
|
||||||
@@ -8,7 +8,6 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def initialize(options = {}, block = nil)
|
def initialize(options = {}, block = nil)
|
||||||
super
|
super
|
||||||
# @current_position = Vector.new(@x, @y)
|
|
||||||
|
|
||||||
@origin_x, @origin_x = @x, @x
|
@origin_x, @origin_x = @x, @x
|
||||||
@origin_width, @origin_height = @width, @height
|
@origin_width, @origin_height = @width, @height
|
||||||
@@ -105,7 +104,7 @@ module CyberarmEngine
|
|||||||
def position_on_current_line(element)
|
def position_on_current_line(element)
|
||||||
element.x = @current_position.x
|
element.x = @current_position.x
|
||||||
element.y = @current_position.y
|
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
|
@current_position.x = @x if @current_position.x >= max_width
|
||||||
end
|
end
|
||||||
@@ -113,7 +112,7 @@ module CyberarmEngine
|
|||||||
def move_to_next_line(element)
|
def move_to_next_line(element)
|
||||||
element.x = @current_position.x
|
element.x = @current_position.x
|
||||||
element.y = @current_position.y
|
element.y = @current_position.y
|
||||||
@current_position.y += element.height
|
@current_position.y += element.outer_height
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -88,6 +88,14 @@ module CyberarmEngine
|
|||||||
@height + (@padding * 2)
|
@height + (@padding * 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def outer_width
|
||||||
|
width + (@margin * 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
def outer_height
|
||||||
|
height + (@margin * 2)
|
||||||
|
end
|
||||||
|
|
||||||
def relative_x
|
def relative_x
|
||||||
@x# + @margin
|
@x# + @margin
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -73,11 +73,30 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def redirect_mouse_button(button)
|
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
|
end
|
||||||
|
|
||||||
def redirect_released_mouse_button(button)
|
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(:"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
|
end
|
||||||
|
|
||||||
def redirect_holding_mouse_button(button)
|
def redirect_holding_mouse_button(button)
|
||||||
|
|||||||
Reference in New Issue
Block a user