#==============================================================================
# ** Sprite_Picture
#------------------------------------------------------------------------------
#  This sprite is used to display the picture.It observes the Game_Character
#  class and automatically changes sprite conditions.
#==============================================================================

class Sprite_Picture < Sprite
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     viewport : viewport
  #     picture  : picture (Game_Picture)
  #--------------------------------------------------------------------------
  def initialize(viewport, picture)
    super(viewport)
    @picture = picture
    RPG::Mod.exec_hooks("hooks/Sprite_Picture/init", binding)
    update
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    if self.bitmap != nil
      self.bitmap.dispose
    end
    super
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If picture file name is different from current one
    if @picture_name != @picture.name
      # Remember file name to instance variables
      @picture_name = @picture.name
      # If file name is not empty
      if @picture_name != ""
        # Get picture graphic
        self.bitmap = RPG::Cache.picture(@picture_name)
        if Settings[:debug_picture_names]
          self.bitmap.draw_text(0, 0, 500, 20, @picture_name)
        end
        if @picture_name == "cg_desktop_no_effects"
          self.shader = Shader::CRT
        else
          self.shader = Shader::Sprite
        end
      end
    end
    # If file name is empty
    if @picture_name == ""
      # Set sprite to invisible
      self.visible = false
      return
    end
    # Set sprite to visible
    self.visible = true
    # Set transfer starting point
    if @picture.origin == 0
      self.ox = 0
      self.oy = 0
      # Set sprite coordinates
      self.x = @picture.x
      self.y = @picture.y
    else
      self.ox = self.bitmap.width / 2
      self.oy = self.bitmap.height / 2
      # Set sprite coordinates
      self.x = Graphics.width / 2 + @picture.x
      self.y = Graphics.height / 2 + @picture.y
    end
    self.z = @picture.number
    # Set zoom rate, opacity level, and blend method
    self.zoom_x = @picture.zoom_x / 100.0
    self.zoom_y = @picture.zoom_y / 100.0
    self.opacity = @picture.opacity
    self.blend_type = @picture.blend_type
    # Set rotation angle and color tone
    self.angle = @picture.angle
    self.tone = @picture.tone

    @picture.width = self.width * self.zoom_x
    @picture.height = self.height * self.zoom_y
  end
end
