Sha256: 424bb1c0437ffc71c490f1a18e718499635d401e7fed1f5e500b034a05872655

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

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

      @style.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
        @style.background_canvas.background = default(:active, :background)
        @text.color = default(:active, :color)
      else
        @style.background_canvas.background = default(:hover, :background)
        @text.color = default(:hover, :color)
      end
    end

    def left_mouse_button(sender, x, y)
      @focus = true
      @style.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)
      @style.background_canvas.background = default(:background)
      @text.color = default(:color)
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cyberarm_engine-0.8.1 lib/cyberarm_engine/ui/button.rb
cyberarm_engine-0.8.0 lib/cyberarm_engine/ui/button.rb