#==============================================================================
# ■ Cursor_Icon_type1 vol,1.30
# 08/02/08
#==============================================================================
module HIDE_CURSOR
  # ■カーソルアイコン画像
  ICON = "cursor"
  # ■デフォルトカーソルを使う[true/false]
  DEFAULT = false
end
#==============================================================================
# ■ Window_Base < Window
#==============================================================================
class Window_Base < Window
  #--------------------------------------------------------------------------
  # ■ ウィンドウの更新
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_cursor_rect cursor_rect;end
  def cursor_rect=(cursor_rect)
    if self.cursor_rect.width == 0 or self.cursor_rect.height == 0 or 
      @index == -1 or self.visible == false
      # □カーソルウィンドウの削除
      break_cursor_icon_window
    else
      if @cursor_icon == nil or @cursor_icon.disposed?
        # □カーソルウィンドウの作成
        make_cursor_icon_window
      end
      # □カーソルの作成
      make_cursor_icon(self.x,self.y)
    end
    if HIDE_CURSOR::DEFAULT
      super
    end
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの更新
  #--------------------------------------------------------------------------
  def update
    # □ショップのアイテム個数バグの修正
    if @number == 1 or self.cursor_rect.width == 32
      self.cursor_rect.width = self.cursor_rect.width
    end
    if @cursor_icon != nil && @cursor_icon.disposed? == false
      # □カーソルアニメの開始
      if self.active == true
        if @co == nil
          @cursor_icon.z = self.z + 3
          @co = 0
        end
        case @co
        when 2,14
          @cursor_icon.x = 1
        when 4,12
          @cursor_icon.x = 2
        when 6,10
          @cursor_icon.x = 3
        when 8
          @cursor_icon.x = 4
        when 0,16
          @cursor_icon.x = 0
          @co = 0
        end
        @co += 1
      # □カーソルアニメの停止
      elsif (self.active == false or @index == 0) && @co != nil
        @cursor_icon.x = 0
        @co = nil
      end
    end
    @crs = @index
    super
  end
  #--------------------------------------------------------------------------
  # ■ X座標の更新
  #--------------------------------------------------------------------------
  def x=(x)
    break_cursor_icon_window
    make_cursor_icon(x,self.y)
    super
  end
  #--------------------------------------------------------------------------
  # ■ Y座標の更新
  #--------------------------------------------------------------------------
  def y=(y)
    break_cursor_icon_window
    make_cursor_icon(self.x,y)
    super
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの削除
  #--------------------------------------------------------------------------
  def break_cursor_icon_window
    if @cursor_icon != nil
      if @cursor_icon.bitmap != nil
        @cursor_icon.bitmap.clear
      else
        @cursor_icon.dispose
      end
    end
    @crs = nil
  end
  #--------------------------------------------------------------------------
  # ■ カーソルウィンドウの作成
  #--------------------------------------------------------------------------
  def make_cursor_icon_window
    @crs = nil
    @cursor_icon = Sprite.new
    @cursor_icon.bitmap = Bitmap.new(640,480)
    @cursor_icon.z = self.z + 3
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの作成
  #--------------------------------------------------------------------------
  def make_cursor_icon(x,y)
    if @cursor_icon != nil && (@crs != @index or @index == nil)
      crb = RPG::Cache.windowskin(HIDE_CURSOR::ICON)
      x += self.cursor_rect.x - (crb.width / 2)
      y += self.cursor_rect.y + (crb.height / 2)
      @cursor_icon.bitmap.clear
      @cursor_icon.bitmap.blt(x+16,y,crb,Rect.new(0,0,crb.width, crb.height))
    end
  end
  #--------------------------------------------------------------------------
  # ■ カーソルウィンドウの削除
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_dispose dispose;end
  def dispose
    super
    if @cursor_icon != nil
      @cursor_icon.dispose
    end
  end
  #--------------------------------------------------------------------------
  # ■ カーソルウィンドウの可視化
  #--------------------------------------------------------------------------
  def visible=(visible)
    super
    if visible == false
      if @cursor_icon != nil
        @cursor_icon.dispose
      end
    end
  end
end