let newtextcolor=[255,255,255,255,255,255];

function SetFontColorNew(r1,g1,b1,r2,g2,b2){
//RGB for top, then RGB for bottom
	newtextcolor=[r1,g1,b1,r2,g2,b2];
}

task DrawTextNew(string,font,x,y,angle,xsize,ysize,layer,align,alpha){
//string: the string to write
//font: what image file to use
//x,y,angle: obvious
//size: default 1, multiplies the size by that amount
//layer: what layer to draw it on
//align: 1 is left-justified, -1 is right-justified, 0 is centered
//align currently does not work
//alpha: obvious

	let obj = Obj_Create(OBJ_EFFECT);
	let ii=0;
	let midx=0;
	let miny=0;
	let string2=[];

	Obj_SetPosition(obj,x,y-8);
	Obj_SetSpeed      (obj, 0);
	ObjEffect_SetAngle(obj, 0,0,angle);
	ObjEffect_SetTexture(obj,font);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_SetLayer(obj,layer);
	ObjEffect_CreateVertex(obj,length(string)*6);
	ObjEffect_SetRenderState(obj,ALPHA);
	ObjEffect_SetScale(obj,xsize,ysize);

	let char=0;
	let CharSpace = 0;
	let LastCharSpace = 0;
	ascent(ii in 0..length(string)){
		char=ToNumber(string[ii])*32;
		midx+= LastCharSpace/2+CharSpace/2;
	
		ObjEffect_SetVertexXY(obj,(ii*6)  ,midx,0);
		ObjEffect_SetVertexXY(obj,(ii*6)+1,midx,0);
		ObjEffect_SetVertexXY(obj,(ii*6)+2,midx+32,0);
		ObjEffect_SetVertexXY(obj,(ii*6)+3,midx,32);
		ObjEffect_SetVertexXY(obj,(ii*6)+4,midx+32,32);
		ObjEffect_SetVertexXY(obj,(ii*6)+5,midx+32,32);
	
		ObjEffect_SetVertexUV(obj,(ii*6)  ,char,0);
		ObjEffect_SetVertexUV(obj,(ii*6)+1,char,0);
		ObjEffect_SetVertexUV(obj,(ii*6)+2,char+32,0);
		ObjEffect_SetVertexUV(obj,(ii*6)+3,char,32);
		ObjEffect_SetVertexUV(obj,(ii*6)+4,char+32,32);
		ObjEffect_SetVertexUV(obj,(ii*6)+5,char+32,32);

		ObjEffect_SetVertexColor(obj,(ii*6)  ,alpha,newtextcolor[0],newtextcolor[1],newtextcolor[2]);
		ObjEffect_SetVertexColor(obj,(ii*6)+1,alpha,newtextcolor[0],newtextcolor[1],newtextcolor[2]);
		ObjEffect_SetVertexColor(obj,(ii*6)+2,alpha,newtextcolor[0],newtextcolor[1],newtextcolor[2]);
		ObjEffect_SetVertexColor(obj,(ii*6)+3,alpha,newtextcolor[3],newtextcolor[4],newtextcolor[5]);
		ObjEffect_SetVertexColor(obj,(ii*6)+4,alpha,newtextcolor[3],newtextcolor[4],newtextcolor[5]);
		ObjEffect_SetVertexColor(obj,(ii*6)+5,alpha,newtextcolor[3],newtextcolor[4],newtextcolor[5]);
		
		LastCharSpace = CharSpace;
    }
    loop(2){yield;}
    Obj_Delete(obj);
	
	

	function ToNumber(character){

	//ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,!?()'"-~


		let ret=0;
		alternative(character)
			case('A') {ret=0;CharSpace=20;} case('B') {ret=1;CharSpace=20;} case('C') {ret=2;CharSpace=20;} case('D') {ret=3;CharSpace=20;}
			case('E') {ret=4;CharSpace=20;} case('F') {ret=5;CharSpace=20;} case('G') {ret=6;CharSpace=20;} case('H') {ret=7;CharSpace=20;}
			case('I') {ret=8;CharSpace=14;} case('J') {ret=9;CharSpace=20;} case('K') {ret=10;CharSpace=20;} case('L') {ret=11;CharSpace=20;}
			case('M') {ret=12;CharSpace=20;} case('N') {ret=13;CharSpace=20;} case('O') {ret=14;CharSpace=20;} case('P') {ret=15;CharSpace=20;}
			case('Q') {ret=16;CharSpace=20;} case('R') {ret=17;CharSpace=20;} case('S') {ret=18;CharSpace=20;} case('T') {ret=19;CharSpace=16;}
			case('U') {ret=20;CharSpace=20;} case('V') {ret=21;CharSpace=20;} case('W') {ret=22;CharSpace=20;} case('X') {ret=23;CharSpace=20;}
			case('Y') {ret=24;CharSpace=20;} case('Z') {ret=25;CharSpace=20;}

			case('a') {ret=26;CharSpace=20;} case('b') {ret=27;CharSpace=20;} case('c') {ret=28;CharSpace=18;} case('d') {ret=29;CharSpace=20;}
			case('e') {ret=30;CharSpace=20;} case('f') {ret=31;CharSpace=14;} case('g') {ret=32;CharSpace=20;} case('h') {ret=33;CharSpace=20;}
			case('i') {ret=34;CharSpace=12;} case('j') {ret=35;CharSpace=14;} case('k') {ret=36;CharSpace=20;} case('l') {ret=37;CharSpace=12;}
			case('m') {ret=38;CharSpace=20;} case('n') {ret=39;CharSpace=20;} case('o') {ret=40;CharSpace=20;} case('p') {ret=41;CharSpace=20;}
			case('q') {ret=42;CharSpace=20;} case('r') {ret=43;CharSpace=20;} case('s') {ret=44;CharSpace=20;} case('t') {ret=45;CharSpace=12;}
			case('u') {ret=46;CharSpace=20;} case('v') {ret=47;CharSpace=20;} case('w') {ret=48;CharSpace=20;} case('x') {ret=49;CharSpace=20;}
			case('y') {ret=50;CharSpace=16;} case('z') {ret=51;CharSpace=20;}
			
			case('0') {ret=52;CharSpace=20;} case('1') {ret=53;CharSpace=16;} case('2') {ret=54;CharSpace=20;} case('3') {ret=55;CharSpace=24;}
			case('4') {ret=56;CharSpace=20;} case('5') {ret=57;CharSpace=20;} case('6') {ret=58;CharSpace=20;} case('7') {ret=59;CharSpace=20;}
			case('8') {ret=60;CharSpace=20;} case('9') {ret=61;CharSpace=20;} 

			case('.') {ret=62;CharSpace=10;} case(',') {ret=63;CharSpace=10;} case('!') {ret=64;CharSpace=12;} case('?') {ret=65;CharSpace=18;} 
			case('(') {ret=66;CharSpace=14;} case(')') {ret=67;CharSpace=14;} case('\') {ret=68;CharSpace=18;} case('/') {ret=69;CharSpace=14;} 
			case('-') {ret=70;CharSpace=24;} case('~') {ret=71;CharSpace=20;} case('+') {ret=72;CharSpace=24;}
			
			others {ret=-1;CharSpace=15;}

		
		return ret;
	}
}