mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 05:02:34 +00:00
Button element (and its decendents) can now be disabled
This commit is contained in:
@@ -13,10 +13,10 @@ module CyberarmEngine
|
||||
@options = options
|
||||
@block = block
|
||||
|
||||
@focus = false
|
||||
@enabled = true
|
||||
@visible = true
|
||||
@tip = @options[:tip] || ""
|
||||
@focus = @options[:focus].nil? ? false : @options[:focus]
|
||||
@enabled = @options[:enabled].nil? ? true : @options[:enabled]
|
||||
@visible = @options[:visible].nil? ? true : @options[:visible]
|
||||
@tip = @options[:tip] || ""
|
||||
|
||||
@style = Style.new(options)
|
||||
|
||||
|
||||
@@ -37,7 +37,10 @@ module CyberarmEngine
|
||||
def enter(_sender)
|
||||
@focus = false unless window.button_down?(Gosu::MsLeft)
|
||||
|
||||
if @focus
|
||||
if !@enabled
|
||||
@style.background_canvas.background = default(:disabled, :background)
|
||||
@text.color = default(:disabled, :color)
|
||||
elsif @focus
|
||||
@style.background_canvas.background = default(:active, :background)
|
||||
@text.color = default(:active, :color)
|
||||
else
|
||||
@@ -50,9 +53,16 @@ module CyberarmEngine
|
||||
|
||||
def left_mouse_button(_sender, _x, _y)
|
||||
@focus = true
|
||||
@style.background_canvas.background = default(:active, :background)
|
||||
|
||||
unless @enabled
|
||||
@style.background_canvas.background = default(:disabled, :background)
|
||||
@text.color = default(:disabled, :color)
|
||||
else
|
||||
@style.background_canvas.background = default(:active, :background)
|
||||
@text.color = default(:active, :color)
|
||||
end
|
||||
|
||||
window.current_state.focus = self
|
||||
@text.color = default(:active, :color)
|
||||
|
||||
:handled
|
||||
end
|
||||
@@ -64,14 +74,19 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def clicked_left_mouse_button(_sender, _x, _y)
|
||||
@block.call(self) if @block
|
||||
@block.call(self) if @enabled && @block
|
||||
|
||||
:handled
|
||||
end
|
||||
|
||||
def leave(_sender)
|
||||
@style.background_canvas.background = default(:background)
|
||||
@text.color = default(:color)
|
||||
unless @enabled
|
||||
@style.background_canvas.background = default(:disabled, :background)
|
||||
@text.color = default(:disabled, :color)
|
||||
else
|
||||
@style.background_canvas.background = default(:background)
|
||||
@text.color = default(:color)
|
||||
end
|
||||
|
||||
:handled
|
||||
end
|
||||
@@ -83,6 +98,14 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def recalculate
|
||||
unless @enabled
|
||||
@style.background_canvas.background = default(:disabled, :background)
|
||||
@text.color = default(:disabled, :color)
|
||||
else
|
||||
@style.background_canvas.background = default(:background)
|
||||
@text.color = default(:color)
|
||||
end
|
||||
|
||||
if @image
|
||||
@width = 0
|
||||
@height = 0
|
||||
|
||||
@@ -19,7 +19,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def clicked_left_mouse_button(_sender, _x, _y)
|
||||
@block&.call(self)
|
||||
@block&.call(self) if @enabled
|
||||
|
||||
# return :handled
|
||||
end
|
||||
|
||||
@@ -82,6 +82,11 @@ module CyberarmEngine
|
||||
active: {
|
||||
color: Gosu::Color::BLACK,
|
||||
background: ["ffB23E41".to_i(16)]
|
||||
},
|
||||
|
||||
disabled: {
|
||||
color: Gosu::Color::GRAY,
|
||||
background: 0xff303030
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ module CyberarmEngine
|
||||
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)
|
||||
@show_cursor = false
|
||||
|
||||
super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable, borderless: borderless)
|
||||
super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable)
|
||||
$window = self
|
||||
@last_frame_time = Gosu.milliseconds - 1
|
||||
@current_frame_time = Gosu.milliseconds
|
||||
|
||||
Reference in New Issue
Block a user