class Equinox_Canvas
  $FAUX_CONSOLE_BG = Color.new(0, 0, 0, 192)
  $FAUX_CONSOLE = []
  FAUX_CONSOLE_TEST = [
    "Testing, testing", 
    "Is your refrigerator running?", 
    "Then you better go catch it!"
  ]
  
  def initialize
    @counter = 0
    @viewport = Viewport.new(0, 0, 640, 480)
    @bg = Sprite.new(@viewport)
    @bg.bitmap = Bitmap.new(640, 480)
    @bg.bitmap.fill_rect(0, 0, 640, 480, Color.new(0, 0, 0, 192))
    @contents = Sprite.new(@viewport)
    @contents.bitmap = Bitmap.new(640, 480)
    @contents.bitmap.font.color = Color.new(152, 43, 261, 255)
    
    @contents_changed = true
#    @title = Sprite.new(@viewport)
#    @title.bitmap = Bitmap.new(320, TITLE_MARGIN)
#    @title.bitmap.font.size = 40
#    @title.y = TITLE_TOP_MARGIN
#    @title.x = MARGIN
#    Language.register_text_sprite(self.class.name + "_title", @title)
#    @data_sprites = []

    @viewport.z = 9998

    self.visible = false
    @index = 0
    @fade_in = false
    @fade_out = false

    @transfer_player = nil
	  @visible = false
  end
  
  def toggle_vis
    if self.visible
      self.visible = false
    else
      $FAUX_CONSOLE = []
      @contents.bitmap.clear
      self.visible = true
      self.opacity = 255
    end
  end

  def dispose
    @viewport.dispose
    @bg.dispose
    @contents.dispose
  end

  def update
    if @visible
      @counter = 0
      if @contents_changed
        @contents.bitmap.clear
        draw_console_text
        @contents_changed = false
      end
    end
  end

  # Attributes
  def visible
    return @visible
  end
  def visible=(val)
    @viewport.visible = val
	  @visible = val
  end
  def opacity=(val)
    @bg.opacity = val
  end
  def opacity
    @bg.opacity
  end
  def contents_changed=(val)
    @contents_changed = val
  end
  def contents_changed
    @contents_changed
  end
  
  def draw_console_text
    _index = 0
    _padding_mult = 1
    
    if $FAUX_CONSOLE.length == 24
      _padding_mult = -1
    end
    
    #FAUX_CONSOLE_TEST.each do |console_line|
    $FAUX_CONSOLE.each do |console_line|
      break if _index >= 24
      @contents.bitmap.draw_text(4, 4 * _padding_mult + _index * 20, 640, 20, console_line)
      _index += 1
    end
  end
  
end
