 #06/10/15
#==============================================================================
# Fake_Cursor 点滅しないカーソルを作成
#==============================================================================
class Window_Base < Window
  #--------------------------------------------------------------------------
  # ■ ウィンドウの更新
  #--------------------------------------------------------------------------
  alias hidesp_cursor_rect cursor_rect
  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
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの更新
  #--------------------------------------------------------------------------
  def update
    # □ショップのアイテム個数バグの修正
    if @number == 1
      self.cursor_rect.width = self.cursor_rect.width
    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
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの作成
  #--------------------------------------------------------------------------
  def make_cursor_icon(x,y)
    if @cursor_icon != nil && (@crs != @index or @index == nil)
      @cursor_icon.bitmap.clear
      x += self.cursor_rect.x + 16
      y += self.cursor_rect.y + 16
      w = self.cursor_rect.width
      h = self.cursor_rect.height
      skin = RPG::Cache.windowskin($game_system.windowskin_name)
      wsx,wsy,wwh,opa = 128,64,32,255
      # □カーソル画像の引き伸ばし描画（真中、左、右、上、下）
      @cursor_icon.bitmap.stretch_blt(Rect.new(x+2,y+2,w-4,h-4),skin,Rect.new(wsx+2,wsy+2,wwh-4,wwh-4),opa)
      @cursor_icon.bitmap.stretch_blt(Rect.new(x,y+2,2,h-4),skin,Rect.new(wsx,wsy+2,2,wwh-4),opa)
      @cursor_icon.bitmap.stretch_blt(Rect.new(x+w-2,y+2,2,h-4),skin,Rect.new(wsx+wwh-2,wsy+2,2,wwh-4),opa)
      @cursor_icon.bitmap.stretch_blt(Rect.new(x+2,y,w-4,2),skin,Rect.new(wsx+2,wsy,wwh-4,2),opa)
      @cursor_icon.bitmap.stretch_blt(Rect.new(x+2,y+h-2,w-4,2),skin,Rect.new(wsx+2,wsy+wwh-2,wwh-4,2),opa)
      # □カーソル画像の描画（左上、右上、左下、右下）
      @cursor_icon.bitmap.blt(x,y,skin,Rect.new(wsx,wsy,2,2),opa)
      @cursor_icon.bitmap.blt(x+w-2,y,skin,Rect.new(wsx+wwh-2,wsy,2,2),opa)
      @cursor_icon.bitmap.blt(x,y+h-2,skin,Rect.new(wsx,wsy+wwh-2,2,2),opa)
      @cursor_icon.bitmap.blt(x+w-2,y+h-2,skin,Rect.new(wsx+wwh-2,wsy+wwh-2,2,2),opa)
    end
  end
  #--------------------------------------------------------------------------
  # ■ カーソルウィンドウの削除
  #--------------------------------------------------------------------------
  alias hidesp_dispose dispose
  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

