Sha256: 90e42f5c10307fc9cb476a9ab59a6805591c47b2b652a06c380cf9d254ae495e

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

module CyberarmEngine
  class Button < Label
    def initialize(text, options = {}, block = nil)
      super(text, options, block)

      @background_canvas.background = default(:background)
    end

    def render
      draw_text
    end

    def draw_text
      @text.draw
    end

    def enter(sender)
      @focus = false unless window.button_down?(Gosu::MsLeft)

      if @focus
        @background_canvas.background = default(:active, :background)
        @text.color = default(:active, :color)
      else
        @background_canvas.background = default(:hover, :background)
        @text.color = default(:hover, :color)
      end
    end

    def left_mouse_button(sender, x, y)
      @focus = true
      @background_canvas.background = default(:active, :background)
      window.current_state.focus = self
      @text.color = default(:active, :color)
    end

    def released_left_mouse_button(sender,x, y)
      enter(sender)
    end

    def clicked_left_mouse_button(sender, x, y)
      @block.call(self) if @block
    end

    def leave(sender)
      @background_canvas.background = default(:background)
      @text.color = default(:color)
    end

    def blur(sender)
      @focus = false
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cyberarm_engine-0.7.1 lib/cyberarm_engine/ui/button.rb
cyberarm_engine-0.7.0 lib/cyberarm_engine/ui/button.rb
cyberarm_engine-0.6.0 lib/cyberarm_engine/ui/button.rb
cyberarm_engine-0.5.1 lib/cyberarm_engine/ui/button.rb
cyberarm_engine-0.5.0 lib/cyberarm_engine/ui/button.rb
cyberarm_engine-0.4.0 lib/cyberarm_engine/ui/button.rb
cyberarm_engine-0.3.0 lib/cyberarm_engine/ui/button.rb
cyberarm_engine-0.2.0 lib/cyberarm_engine/ui/button.rb
cyberarm_engine-0.1.0 lib/cyberarm_engine/ui/button.rb