//--------------------------------------
//			   PowerUI
//
//		For documentation or 
//	if you have any issues, visit
//		powerUI.kulestar.com
//
//	Copyright © 2013 Kulestar Ltd
//		  www.kulestar.com
//--------------------------------------

using System;
using BinaryIO;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;


namespace Gif{

	/// <summary>
	/// A text block in a GIF stream.
	/// </summary>
	public class PlainTextBlock : GifBlock{
		
		public const int HeaderSize = 0X0C;
		
		public int XOffset;
		public int YOffset;
		public int Width;
		public int Height;
		public byte CharacterCellWidth;
		public byte CharacterCellHeight;
		public byte ForegroundColorIndex;
		public byte BgColorIndex;
		
		/// <summary>The text itself.</summary>
		public List<string> TextSet;
		
		
		public override void Load(Reader reader){
			
			int blockSize = reader.ReadByte();
			
			if(blockSize != HeaderSize){
				throw new Exception("A text block had the wrong size in a GIF stream.");
			}
			
			// Not sure why the "plain text" block appears to be the largest extension
			// but, uh, look! Cats!
			XOffset = reader.ReadInt16();
			YOffset = reader.ReadInt16();
			Width = reader.ReadInt16();
			Height = reader.ReadInt16();
			CharacterCellWidth = (byte)reader.ReadByte();
			CharacterCellHeight = (byte)reader.ReadByte();
			ForegroundColorIndex = (byte)reader.ReadByte();
			BgColorIndex =(byte)reader.ReadByte();
			
			int nextFlag=reader.ReadByte();
			TextSet=new List<string>();
			
			while(nextFlag!=0){
				
				blockSize=nextFlag;
				string data=reader.ReadString(blockSize);
				TextSet.Add(data);
				nextFlag=reader.ReadByte();
				
			}
			
		}
		
	}
	
}