Sha256: fd541955d81307a56d038e8a031c1f101f02d49fadf9e2e7f85bfb92a4bf5a07

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

module CyberarmEngine
  class Element
    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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cyberarm_engine-0.10.2 lib/cyberarm_engine/ui/elements/button.rb
cyberarm_engine-0.10.1 lib/cyberarm_engine/ui/elements/button.rb
cyberarm_engine-0.10.0 lib/cyberarm_engine/ui/elements/button.rb
cyberarm_engine-0.9.0 lib/cyberarm_engine/ui/elements/button.rb