Report abuse

Copyright (C) 2006 by Han Dao


			
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#This program is a map editor.
#You can contract the author at wikipediankiba@gmail.com
class Mouse_input
  include Rubygame::Sprites::Sprite
  def initialize
    super
    #The mouse take an image instead of a plain back cursor
    @image
    @rect
    #mouse position
    @pos = [0,0]
  end
  def name name
    @image, @rect = load_image(name)
  end
  def load_image name
  #Highly modifiled form of chimp.rb from Rubygame library's samples section which is currently commented out.
  #Code may be public domain or LGPL. Orginated from http://pygame.org
    image = Rubygame::Image.load(name)
    return image, Rubygame::Rect.new(0,0,*image.size)
  end
  #Checking if any of the rect collide
  def check rect
    count = 0
    rect.each do |rect|
      count +=1
      if @rect.collide_rect?(rect)
        return count
      end
    end
    return false
  end
  def pos tell
    case tell
      when Rubygame::MouseMotionEvent
        @pos = tell.pos
    end
  end
  def update
    #Move the mouse
    @rect.midtop = @pos
  end
  def undraw(dest, background)
        background.blit(dest,@rect,@rect)
    end

end