def update
      return unless @enabled and @visible

      mouse_over = Mouse.over? @x, @y, @w, @h
      mouse_press = Mouse.button_pressed? :left
      mouse_rel = Mouse.button_released? :left

      if @state == :up
        if mouse_over
          @img_index = 1
          @state = :over
        else
          @img_index = 0
        end
      elsif @state == :over
        if not mouse_over
          @img_index = 0
          @state = :up
        elsif mouse_press
          @img_index = 2
          @state = :down
        else
          @img_index = 1
        end
      elsif @state == :down
        if not mouse_over
          @img_index = 0
          @state = :down_out
        elsif mouse_rel
          @img_index = 1
          @state = :over
          click
        else
          @img_index = 2
        end
      else # :down_out
        if mouse_over
          @img_index = 2
          @state = :down
        elsif mouse_rel
          @img_index = 0
          @state = :up
        else
          @img_index = 0
        end
      end
    end
def update
      return unless @enabled and @visible

      mouse_over = Mouse.over? @x, @y, @w, @h
      mouse_press = Mouse.button_pressed? :left
      mouse_rel = Mouse.button_released? :left

      if @state == :up
        if mouse_over
          @img_index = 1
          @state = :over
        else
          @img_index = 0
        end
      elsif @state == :over
        if not mouse_over
          @img_index = 0
          @state = :up
        elsif mouse_press
          @img_index = 2
          @state = :down
        else
          @img_index = 1
        end
      elsif @state == :down
        if not mouse_over
          @img_index = 0
          @state = :down_out
        elsif mouse_rel
          @img_index = 1
          @state = :over
          click
        else
          @img_index = 2
        end
      else # :down_out
        if mouse_over
          @img_index = 2
          @state = :down
        elsif mouse_rel
          @img_index = 0
          @state = :up
        else
          @img_index = 0
        end
      end
    end
Creates a button.

 Parameters:
 [x] The x-coordinate where the button will be drawn in the screen.
 [y] The y-coordinate where the button will be drawn in the screen.
 [font] The <code>Gosu::Font</code> object that will be used to draw the
        button text.
 [text] The button text. Can be +nil+ or empty.
 [img] A spritesheet containing four images in a column, representing,
       from top to bottom, the default state, the hover state (when the
       mouse is over the button), the pressed state (when the mouse
       button is down and the cursor is over the button) and the disabled
       state. If +nil+, the +width+ and +height+ parameters must be
       provided.
 [text_color] Color of the button text, in hexadecimal RRGGBB format.
 [disabled_text_color] Color of the button text, when it's disabled, in
                       hexadecimal RRGGBB format.
 [over_text_color] Color of the button text, when the cursor is over it
                   (hexadecimal RRGGBB).
 [down_text_color] Color of the button text, when it is pressed
                   (hexadecimal RRGGBB).
 [center_x] Whether the button text should be horizontally centered in its
            area (the area is defined by the image size, if an image is
            given, or by the +width+ and +height+ parameters, otherwise).
 [center_y] Whether the button text should be vertically centered in its
            area (the area is defined by the image size, if an image is
            given, or by the +width+ and +height+ parameters, otherwise).
 [margin_x] The x offset, from the button x-coordinate, to draw the text.
            This parameter is used only if +center+ is false.
 [margin_y] The y offset, from the button y-coordinate, to draw the text.
            This parameter is used only if +center+ is false.
 [width] Width of the button clickable area. This parameter is used only
         if +img+ is +nil+.
 [height] Height of the button clickable area. This parameter is used
          only if +img+ is +nil+.
 [params] An object containing any parameters you want passed to the
          +action+ block. When the button is clicked, the following is
          called:
            @action.call @params
          Note that this doesn't force you to declare a block that takes
          parameters.
 [retro] Whether the image should be loaded with the 'retro' option set
         (see +Gosu::Image+ for details). If the value is omitted, the
         +Res.retro_images+ value will be used.
 [scale_x] Horizontal scale to draw the component with.
 [scale_y] Vertical scale to draw the component with.
 [anchor] See parameter with the same name in <code>Panel#initialize</code> for details.
 [action] The block of code executed when the button is clicked (or by
          calling the +click+ method).

 *Obs.:* This method accepts named parameters, but +x+ and +y+ are
 mandatory (also, +img+ is mandatory when +width+ and +height+ are not
 provided, and vice-versa).
 Updates the button, checking the mouse movement and buttons to define
 the button state.