lib/cyberarm_engine/ui/elements/button.rb in cyberarm_engine-0.15.0 vs lib/cyberarm_engine/ui/elements/button.rb in cyberarm_engine-0.16.0

- old
+ new

@@ -1,18 +1,18 @@ module CyberarmEngine class Element - class Button < Label + class Button < TextBlock def initialize(text_or_image, options = {}, block = nil) @image = nil @scale_x = 1 @scale_y = 1 @image = text_or_image if text_or_image.is_a?(Gosu::Image) super(text_or_image, options, block) - @style.background_canvas.background = default(:background) + @style.background_canvas.background = @style.background end def render if @image draw_image @@ -35,26 +35,36 @@ end def enter(_sender) @focus = false unless window.button_down?(Gosu::MsLeft) - if @focus - @style.background_canvas.background = default(:active, :background) - @text.color = default(:active, :color) + if !@enabled + @style.background_canvas.background = @style.disabled[:background] + @text.color = @style.disabled[:color] + elsif @focus + @style.background_canvas.background = @style.active[:background] + @text.color = @style.active[:color] else - @style.background_canvas.background = default(:hover, :background) - @text.color = default(:hover, :color) + @style.background_canvas.background = @style.hover[:background] + @text.color = @style.hover[:color] end :handled end def left_mouse_button(_sender, _x, _y) @focus = true - @style.background_canvas.background = default(:active, :background) + + unless @enabled + @style.background_canvas.background = @style.disabled[:background] + @text.color = @style.disabled[:color] + else + @style.background_canvas.background = @style.active[:background] + @text.color = @style.active[:color] + end + window.current_state.focus = self - @text.color = default(:active, :color) :handled end def released_left_mouse_button(sender, _x, _y) @@ -62,18 +72,23 @@ :handled 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 = @style.disabled[:background] + @text.color = @style.disabled[:color] + else + @style.background_canvas.background = @style.background + @text.color = @style.color + end :handled end def blur(_sender) @@ -81,9 +96,17 @@ :handled end def recalculate + unless @enabled + @style.background_canvas.background = @style.disabled[:background] + @text.color = @style.disabled[:color] + else + @style.background_canvas.background = @style.background + @text.color = @style.color + end + if @image @width = 0 @height = 0 _width = dimensional_size(@style.image_width, :width)