#==============================================================================
# ■ Cursor_Icon_type2 vol.3.90
# 07/09/07
#==============================================================================
module HIDE_CURSOR
  # ■左右に動く幅のループ(アニメーション)
  ACT_ANIM = [1,2,3,4,3,2,1,0]
  # ■カーソルアニメーション速度(0以上　大=遅い)
  ACT_SPEED = 2
  # ■カーソル停止時にブレンドする色
  NEG_COLORE = Color.new(0,0,0,80)
  # ■カーソル停止アニメーションの許可フラグ[true/false]
  NEG_ANIM = false
  # ■カーソルアイコン画像
  ICON = "cursor"
  # ■デフォルトカーソルを使う[true/false]
  DEFAULT = false
end
#==============================================================================
# ■ Window_Base < Window
#==============================================================================
class Window_Base < Window
  #--------------------------------------------------------------------------
  # ■ ウィンドウの更新
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_cursor2_rect cursor_rect;end
  def cursor_rect=(cursor_rect)
    if HIDE_CURSOR::DEFAULT
      super
    end
    if self.cursor_rect.width == 0 or self.cursor_rect.height == 0 or 
      @index == -1 or self.visible == false
      # □カーソルの開放
      dispose_cursor2_icon
    else
      if @csr2_icon == nil or @csr2_icon.disposed?
        # □カーソルウィンドウの作成
        make_cursor2_icon_window(self.x,self.y,self.width,self.height)
      end
      # □カーソルの更新
      update_cursor2_icon
    end
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの停止
  #--------------------------------------------------------------------------
  def active=(active)
    unless @csr2_icon == nil or @csr2_icon.disposed?
      if active
        @csr2_icon.color = Color.new(0,0,0,0)
      else
        @csr2_icon.color = @csr2_negcolor
        unless HIDE_CURSOR::NEG_ANIM
          @csr2_icon.viewport.ox = 0
          @csr2_count = 0
        end
      end
    end
    super
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの更新
  #--------------------------------------------------------------------------
  def update
    # □ショップのアイテム個数バグの修正
    if @number == 1
      self.cursor_rect.width = self.cursor_rect.width
    end
    if @csr2_icon != nil && @csr2_icon.disposed? == false
      #…………………………………………………………………………………………………
      # ■カーソルアニメの開始
      #…………………………………………………………………………………………………
      if self.active or (! self.active && HIDE_CURSOR::NEG_ANIM)
        if @csr2_count == nil
          @csr2_icon.viewport.z = self.z + 3
          @csr2_count = 0
        end
        #…………………………………………………………………………………………………
        # ■カーソルアニメの開始
        #…………………………………………………………………………………………………
        @csr2_icon.viewport.ox = @csr2_animas[@csr2_count/@csr2_speed]
        @csr2_count += 1
        if @csr2_count == @csr2_animas.size*@csr2_speed
          @csr2_count = 0
        end
      end
    end
    @csr2_index = @index
    super
  end
  #--------------------------------------------------------------------------
  # ■ X座標の更新
  #--------------------------------------------------------------------------
  def x=(x)
    make_cursor2_icon_window(x,self.y,self.width,self.height)
    super
  end
  #--------------------------------------------------------------------------
  # ■ Y座標の更新
  #--------------------------------------------------------------------------
  def y=(y)
    make_cursor2_icon_window(self.x,y,self.width,self.height)
    super
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの開放
  #--------------------------------------------------------------------------
  def dispose_cursor2_icon
    if @csr2_icon != nil
      if @csr2_icon.bitmap != nil
        @csr2_icon.bitmap.dispose
      end
      @csr2_icon.viewport.dispose
      @csr2_icon.dispose
      @csr2_icon = nil
      @csr2_index = nil
    end
  end
  #--------------------------------------------------------------------------
  # ■ カーソルウィンドウの作成
  #--------------------------------------------------------------------------
  def make_cursor2_icon_window(x,y,w,h)
    # □カーソルの開放
    dispose_cursor2_icon
    @csr2_index = nil
    if w == 0 or h == 0 or self.cursor_rect == Rect.new(0,0,0,0)
      return
    end
    @csr2pic = RPG::Cache.windowskin(HIDE_CURSOR::ICON)
    if @column_max != nil
      w = (w/@column_max)*(@column_max-1)+@csr2pic.width+4
    end
    @csr2_icon = Sprite.new(Viewport.new(x,y + (@csr2pic.height / 2),w,h-32))
    @csr2_icon.bitmap = Bitmap.new(@csr2pic.width,@csr2pic.height)
    @csr2_icon.viewport.z = self.z + 3
    ##@csr2_icon.viewport.color = Color.new(255,255,255,40)
    @csr2_icon.bitmap.blt(0,0,@csr2pic,Rect.new(0,0,@csr2pic.width,@csr2pic.height))
    @csr2_animas = HIDE_CURSOR::ACT_ANIM
    @csr2_speed = HIDE_CURSOR::ACT_SPEED
    @csr2_negcolor = HIDE_CURSOR::NEG_COLORE
    # □カーソルの更新
    update_cursor2_icon
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの更新
  #--------------------------------------------------------------------------
  def update_cursor2_icon
    if @csr2_icon != nil && (@csr2_index != @index or @index == nil)
      @csr2_icon.x = self.cursor_rect.x
      @csr2_icon.y = self.cursor_rect.y
    end
  end
  #--------------------------------------------------------------------------
  # ■ カーソルウィンドウの削除
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_cursor2_dispose dispose;end
  def dispose
    dispose_cursor2_icon
    super
  end
  #--------------------------------------------------------------------------
  # ■ カーソルウィンドウの可視化
  #--------------------------------------------------------------------------
  def visible=(visible)
    if visible == false
      dispose_cursor2_icon
    end
    super
  end
end