

function Focus(args){

this.superClass=container;
this.superClass({
visible_p:!false,
translate:[0,0,100],
rotation:[0,0,1,0],
components:[]
});
this.color=(args&&args.color)?args.color:Focus.prototype.color;
this.loaded_image=[];
var line_img=Focus.prototype.IMG_PATH+"focus_line.png";
var angle_img=Focus.prototype.IMG_PATH+"focus_angle.png";
if(args&&args.bold){
line_img=Focus.prototype.IMG_PATH+"focus_line_b.png";
angle_img=Focus.prototype.IMG_PATH+"focus_angle_b.png";}
this.components.push(
new gimage({width:1920,height:16,src:line_img,
draw_type:DIRECT,rotation:[0,0,0,1],color:this.color,
onload:this.onload,onerror:this.onload}),
new gimage({width:1920,height:16,src:line_img,
draw_type:DIRECT,rotation:[90,0,0,1],color:this.color,
onload:Focus.prototype.NULL_FUNCTION,}),
new gimage({width:1920,height:16,src:line_img,
draw_type:DIRECT,rotation:[180,0,0,1],color:this.color,
onload:Focus.prototype.NULL_FUNCTION,}),
new gimage({width:1920,height:16,src:line_img,
draw_type:DIRECT,rotation:[-90,0,0,1],color:this.color,
onload:Focus.prototype.NULL_FUNCTION,}),
new gimage({width:16,height:16,src:angle_img,
draw_type:DIRECT,rotation:[-90,0,0,1],color:this.color,
onload:this.onload,onerror:this.onload}),
new gimage({width:16,height:16,src:angle_img,
draw_type:DIRECT,rotation:[0,0,0,1],color:this.color,
onload:Focus.prototype.NULL_FUNCTION,}),
new gimage({width:16,height:16,src:angle_img,
draw_type:DIRECT,rotation:[90,0,0,1],color:this.color,
onload:Focus.prototype.NULL_FUNCTION,}),
new gimage({width:16,height:16,src:angle_img,
draw_type:DIRECT,rotation:[-180,0,0,1],color:this.color,
onload:Focus.prototype.NULL_FUNCTION,}),
this.arrow=new container({visible_p:false})
);};
Focus.prototype=new container({});
Focus.prototype.NULL_FUNCTION=function(){};
Focus.prototype.ANIMATION_TIME_INTERVAL=40;
Focus.prototype.IMG_PATH=IMG_PATH;
Focus.prototype.loaded_image=[];Focus.prototype.onload=function(){
return;Focus.prototype.loaded_image.push(true);
if(Focus.prototype.loaded_image.length==2){
this.visible_p=true;
Focus.prototype.loaded_image=[];}
};
Focus.prototype.width=0;
Focus.prototype.height=0;
Focus.prototype.color=COL_FCS;
Focus.prototype.arrow=null;
Focus.prototype.setSize=function(w,h){
w=Math.floor(w);
h=Math.floor(h);
this.width=w;
this.height=h;
if(h<0){
this.height=-6;
this.setPositionModeH(true);
this.setSizePositionMode(this.width,this.height);}else if(w<0){
this.width=-6;
this.setPositionModeV(true);
this.setSizePositionMode(this.width,this.height);}else{
this.setPositionModeH(false);
this.setPositionModeV(false);
this.components[0].width=w-14;
this.components[2].width=w-14;
this.components[1].width=h-14;
this.components[3].width=h-14;
this.components[0].translate[1]=h/2+1;
this.components[2].translate[1]=-h/2-1;
this.components[1].translate[0]=-w/2-1;
this.components[3].translate[0]=w/2+1;
this.components[0+4].translate[1]=h/2+1;
this.components[2+4].translate[1]=-h/2-1;
this.components[1+4].translate[0]=-w/2-1;
this.components[3+4].translate[0]=w/2+1;

this.components[0+4].translate[0]=w/2+1;
this.components[2+4].translate[0]=-w/2-1;
this.components[1+4].translate[1]=h/2+1;
this.components[3+4].translate[1]=-h/2-1;}
};
Focus.prototype.setPositionModeH=function(b){
if((b==true)&&(this.arrow.components.length==0)){
this.arrow.components.push(
new gimage({src:Focus.prototype.IMG_PATH+"focus_arrow.png",
color:this.color,
width:18,height:38}),
new gimage({src:Focus.prototype.IMG_PATH+"focus_arrow.png",
rotation:[180,0,0,1],
color:this.color,
width:18,height:38})
);}
this.arrow.visible_p=b;
this.components[0+4].visible_p=!b;
this.components[1+4].visible_p=!b;
this.components[2+4].visible_p=!b;
this.components[3+4].visible_p=!b;
this.components[1].visible_p=!b;
this.components[3].visible_p=!b;
this.components[0].visible_p=true;
this.components[2].visible_p=true;};
Focus.prototype.setPositionModeV=function(b){
this.arrow.visible_p=false;
this.components[0+4].visible_p=!b;
this.components[1+4].visible_p=!b;
this.components[2+4].visible_p=!b;
this.components[3+4].visible_p=!b;
this.components[0].visible_p=!b;
this.components[2].visible_p=!b;
this.components[1].visible_p=true;
this.components[3].visible_p=true;
this.components[1].height=16;
this.components[3].height=16;};
Focus.prototype.setSizePositionMode=function(w,h){
if(this.arrow.components.length!=0){
this.arrow.components[0].translate[0]=-(w+18-2)/2;
this.arrow.components[1].translate[0]=(w+18-2)/2-1;}
if(h<0){
this.components[0].width=w;
this.components[2].width=w;
this.components[0].translate[1]=h/2+1;
this.components[2].translate[1]=-h/2-1;}else if(w<0){
this.components[1].width=h+16;
this.components[3].width=h+16;
this.components[1].translate[0]=5;
this.components[3].translate[0]=-5;
this.components[1].height=26;
this.components[3].height=26;}
};
Focus.prototype.setShow=function(b){
this.visible_p=b;};
Focus.prototype.isShow=function(){
return this.visible_p;};
(function(obj,functions){
for(var name in functions){
if(typeof obj[name]=="undefined"){
obj[name]=functions[name];}else if(typeof obj[name]!="function"){
throw new Error("Cannot apply \""+name+"\" function to: "+obj);}else{
}
}
})(Focus.prototype,
{
getSize:function(){
if((this.width==undefined)||(this.height==undefined)){
throw new Error("[GraphicsLib.getSize()] cannot find \"width\" and \"height\".\n"+this);}
return [this.width,this.height];},
setPosition:function(axis,val){
this.translate[axis]=val;},
getPosition:function(axis){
return this.translate[axis];},
setTranslate:function(x,y,z){
this.translate[0]=x;
this.translate[1]=y;
this.translate[2]=z;},
getTranslate:function(){
return this.translate;},
setAngle:function(angle){
if(this.rotation==undefined){
throw new Error("[GraphicsLib] cannot find \"rotation\".");}
if(typeof angle=="number"){
this.rotation[0]=angle;}
},
getAngle:function(){
if(this.rotation==undefined){
throw new Error("[GraphicsLib] cannot find \"rotation\".");}
return this.rotation[0];},
setPivot:function(x,y,z){
if(this.rotation==undefined){
throw new Error("[GraphicsLib] cannot find \"rotation\".");}
this.rotation[1]=x;
this.rotation[2]=y;
this.rotation[3]=z;},
getPivot:function(){
if(this.rotation==undefined){
throw new Error("[GraphicsLib] cannot find \"rotation\".");}
return [
this.rotation[1],
this.rotation[2],
this.rotation[3],
];},
setAlpha:function(alpha){
if(this.color==undefined){
throw new Error("[GraphicsLib] cannot find \"color\".");}
},
getAlpha:function(){
if(this.color==undefined){
throw new Error("[GraphicsLib] cannot find \"color\".");}
return this.color[3];},

moveTo:function(pos,size,angle,speed,func){
if(SU_IS_SLOW_ANIM){
delete_timer(this);
force_redraw();
var obj=this;
var count=0;
obj.setTranslate(pos[0],pos[1],pos[2]);
if(size!=null){
obj.setSize(size[0],size[1]);}
if(angle!=null)obj.setAngle(angle);

if(!func)return;
try{func(obj,count);}catch(e){console.log(e.message);}
return;}
delete_timer(this);

var p=this.getTranslate();
var d=[pos[0]-p[0],
pos[1]-p[1],
pos[2]-p[2]];
d=d.map(function(val){return Math.abs(val);});
var _size=this.getSize();var _angle=this.getAngle();
var is_finish=function(val,index,me){
return (Math.abs(pos[index]-val)<=2);13
};
var distance=Math.sqrt(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]);
var timer_func=function(obj,count){
force_redraw();
p=obj.getTranslate();
obj.setTranslate(p[0]+(pos[0]-p[0])*0.6,
p[1]+(pos[1]-p[1])*0.6,
p[2]+(pos[2]-p[2])*0.6);
if(size!=null){
var pp=obj.getTranslate();
var dd=[pos[0]-pp[0],pos[1]-pp[1],pos[2]-pp[2]];
var dist=Math.sqrt(dd[0]*dd[0]+dd[1]*dd[1]+dd[2]*dd[2]);
obj.setSize((_size[0]-size[0])*dist/distance+size[0],
(_size[1]-size[1])*dist/distance+size[1],
(_size[2]-size[2])*dist/distance+size[2]);}
if(angle!=null){
var a=obj.getAngle();
obj.setAngle(a+((angle||0)-a)/2);}
if(obj.getTranslate().every(is_finish)){
delete_timer(obj);

obj.setTranslate(pos[0],pos[1],pos[2]);
if(size!=null){
obj.setSize(size[0],size[1]);}
if(angle!=null)obj.setAngle(angle);
try{func(obj,count);}catch(e){}
return true;}else{
return false;}
};
if(timer_func(this,0)==false){
append_timer(this,this.ANIMATION_TIME_INTERVAL,timer_func);}
},



transparentTo:function(alpha,msec,func){
delete_timer(this);
var max_cnt=Math.ceil(msec/AnimationLib.TIME_INTERVAL);
var _alpha=this.getAlpha();
var dal=(alpha-_alpha)/max_cnt;
var timer_func=function(obj,count){
force_redraw();
obj.setAlpha(
Math.ceil(_alpha+dal*(count+1))
);
if((count+1)>=max_cnt){
delete_timer(obj);
obj.setAlpha(alpha);
try{func(obj,count);}catch(e){}
return true;}else{
return false;}
};
if(timer_func(this,0)==false){
append_timer(this,AnimationLib.TIME_INTERVAL,timer_func);}
},
stopAnimation:function(){
delete_timer(this);},
}
);
