
function Toolbar(focus_moveto){
this.superClass=container;
this.superClass({
components:[
this.background_solid=new gbox({visible_p:false,
color:COL_BASE,
width:this.width,height:this.height}),
this.background=new gbox({visible_p:true,color:COL_BASE_A,
width:this.width,height:this.height}),
this.under_line=new gbox({width:1920,height:2,color:COL_BORDER_ONBASE,
translate:[0,-this.height*0.5+3-3,0],}),
this.screen_name=new gtext({width:460,height:48,color:COL_TEXT_ONBASE,
align:LEFT,font_size:40,
translate:[-32*1.5-412*2+460*0.5,-3,0],omitter:"...",}),
this.buttons=new container({
visible_p:false,
translate:[0,this.height,0],
components:[
new gbox({color:COL_BASE_A,
width:this.width,height:this.height,visible_p:false,}),
]
}),
]
});
this._point=null;
this.focus_moveto=focus_moveto;
this.cursor=0;if(system.locale.language.substr(0,5)!="ja-JP"){
this.btn_list=[
new this.Button(1920*0.5-1210,300,2),
new this.Button(1920*0.5-940,240,2),
new this.Button(1920*0.5-720,200,1),
new this.Button(1920*0.5-520,200,1),
new this.Button(1920*0.5-320,200,1),
new this.Button(1920*0.5-120,200,1),
];}else{
this.btn_list=[
new this.Button(1920*0.5-1222,268,2),
new this.Button(1920*0.5-968,240,2),
new this.Button(1920*0.5-758,180,1),
new this.Button(1920*0.5-578,180,1),
new this.Button(1920*0.5-364,248,1),
new this.Button(1920*0.5-120-8,224,1),
];}
this.buttons.components.push.apply(this.buttons.components,this.btn_list);};
Toolbar.prototype.IMG_PATH=IMG_PATH;
Toolbar.prototype.width=1920;Toolbar.prototype.height=62;
Toolbar.prototype.cursor=null;Toolbar.prototype.background=null;Toolbar.prototype.buttons=null;Toolbar.prototype.btn_list=null;Toolbar.prototype.focus_moveto=function(){console.log("No function to move focus.");};
Toolbar.prototype.setShowButtons=function(b){
if(b==true){
this.background.visible_p=b;
this.buttons.visible_p=b;
this.under_line.visible_p=b;
this.screen_name.visible_p=b;
this.buttons.translate[1]=0;}else{
this.background.visible_p=b;
this.buttons.translate[1]=this.height;
this.buttons.visible_p=b;this.under_line.visible_p=b;
this.screen_name.visible_p=b;}
};
Toolbar.prototype.setBadge=function(badge_list){
if(!badge_list)return;
for(var i=0;i<badge_list.length&&i<this.btn_list.length;i++){
if(!isNumber(badge_list[i]))continue;
this.btn_list[i].badge.visible_p=(badge_list[i]>0);
if(badge_list[i]>1){
setf_text(this.btn_list[i].badge_cnt,(badge_list[i]).toString());}else{
setf_text(this.btn_list[i].badge_cnt,"");}
}
};
Toolbar.prototype.isShowButtons=function(){
return this.buttons.visible_p;};
Toolbar.prototype.editButtons=function(b0,b1,b2,b3,b4,b5){

for(var i=0;(i<arguments.length)&&(i<this.btn_list.length);i++){
this.btn_list[i].setImage(arguments[i]&&arguments[i].image);
this.btn_list[i].setColorBox(arguments[i]&&arguments[i].colorbox);
this.btn_list[i].setText(arguments[i]&&arguments[i].title);
this.btn_list[i].setVoice(arguments[i]&&arguments[i].voice);
this.btn_list[i].setAction(arguments[i]&&arguments[i].action);
this.btn_list[i].setInvisible(arguments[i]&&arguments[i].invisible);
if(!isString(arguments[i]&&arguments[i].title)){
this.btn_list[i].setInvisible(true);}
}
};
Toolbar.prototype.setScreenName=function(name){
if(!isString(name)){
name="";}
if(this.screen_name.text!=name){
setf_text(this.screen_name,name);}
};
Toolbar.prototype.setSolid=function(b){
this.background_solid.visible_p=b;};
Toolbar.prototype.onFocus=function(b,keysym,point){
if(keysym){if(b==true){
HOME.HomeSoundPlay(0);
switch(keysym){
case TXK_LEFT:
this.cursor=this.btn_list.length-1;
break;
default:
this.curosr=0;}
this.correctFocus();
this.voicePlay();}else{
return true;}
}else if(point){if(b==true){
HOME.HomeSoundPlay(0);
var button=this._getButton(point.x,point.y);
if(button==null)return false;
this.cursor=button;
this._point=this.cursor;
this.correctFocus();
this.voicePlay();
return true;}else {
return true;}
}
};
Toolbar.prototype.freeResource=function(b){
};
Toolbar.prototype.key_hook=function(updown,keysym){
if(updown!=KEY_PRESS)return false;
switch(keysym){
case TXK_RIGHT:
for(var i=this.cursor+1;i<this.btn_list.length;i++){
if(!this.btn_list[i].isInvisible()){
this.cursor=i;
this.correctFocus();
HOME.HomeSoundPlay(0);
this.voicePlay();
return true;}
}
return false;
case TXK_LEFT:
for(var i=this.cursor-1;i>=0;i--){
if(!this.btn_list[i].isInvisible()){
this.cursor=i;
this.correctFocus();
HOME.HomeSoundPlay(0);
this.voicePlay();
return true;}
}
return false;
case TXK_ENTER:
try{
this.btn_list[this.cursor].action();
return true;}catch(e){
return false;}
default:
}
return false;};
Toolbar.prototype._getButtonArea=function (){
if(system.locale.language.substr(0,5)!="ja-JP"){
return [
{"x":1920*0.5-1210,"y":0,"w":300,"h":this.height,},
{"x":1920*0.5-940,"y":0,"w":240,"h":this.height,},
{"x":1920*0.5-720,"y":0,"w":200,"h":this.height,},
{"x":1920*0.5-520,"y":0,"w":200,"h":this.height,},
{"x":1920*0.5-320,"y":0,"w":200,"h":this.height,},
{"x":1920*0.5-120,"y":0,"w":200,"h":this.height,}
];}else {
return [
{"x":1920*0.5-1222,"y":0,"w":268,"h":this.height,},
{"x":1920*0.5-968,"y":0,"w":240,"h":this.height,},
{"x":1920*0.5-758,"y":0,"w":180,"h":this.height,},
{"x":1920*0.5-578,"y":0,"w":180,"h":this.height,},
{"x":1920*0.5-364,"y":0,"w":248,"h":this.height,},
{"x":1920*0.5-128,"y":0,"w":224,"h":this.height,}
];}
};
Toolbar.prototype._getButton=function (x,y){
var button_area=this._getButtonArea();
var my_len=button_area.length;
for(var i=0;i<my_len;i++){
var pobj=button_area[i];
if(((pobj.x-pobj.w*0.5)<=x)&&(x<=(pobj.x+pobj.w*0.5))
&&((pobj.y-pobj.h*0.5)<=y)&&(y<=(pobj.y+pobj.h*0.5))){
return i;}
}
return;}
Toolbar.prototype.point_hook=function(type,id,x,y,screenX,screenY){
switch(type){
case "touchstart":
this.onFocus(true,null,{"x":x,"y":y});
return true;
break;
case "touchmove":
break;
case "touchend":
if(this._point!=null){
try{
var button=this._getButton(x,y);
if((button==null)||(button!=this.cursor))return false;
this._point=null;
this.btn_list[this.cursor].action();
return true;}catch(e){};}
break;
case "touchcancel":
this._point=null;
break;
default:break;}
return false;};
Toolbar.prototype.correctFocus=function(){
var btn=this.btn_list[this.cursor];
this.focus_moveto(btn.getPosition(),btn.getSize(),0,40,null);};
Toolbar.prototype.voicePlay=function(){
var btn=this.btn_list[this.cursor];
VoicePlay(btn.voice);};
Toolbar.prototype.setEditMode=function(b){

};
Toolbar.prototype.isEditMode=function(){
if(this.background.color[0]!=255){
return true;}else{
return false;}
};
Toolbar.prototype.setButtonEnabled=function(index,b){
this.btn_list[index].setEnable(b);};
Toolbar.prototype.Button=function(x,w,type){
this.superClass=container;
this.width=w;
this.superClass({
translate:[x,-4,0],
components:[
this.background=new gimage({width:this.width,height:this.height,draw_type:DIRECT,
src:"",visible_p:false,}),
this.image=new gimage({width:this.height-18,height:this.height-18,draw_type:DIRECT,
translate:[-this.width*0.5+this.height*0.5+6,0,0],}),
this.border=new gbox({width:this.height-18,height:~~((this.height-18)*30/42),
round_enable:true,round_width:2,round_height:2,
visible_p:false,color:COL_BTN_BORDER,
translate:[-this.width*0.5+this.height*0.5+6,0,0],}),
this.box=new gbox({width:this.height-18-2,height:~~((this.height-18-2)*30/42),
round_enable:true,round_width:2,round_height:2,
visible_p:false,
translate:[-this.width*0.5+this.height*0.5+6,0,0],}),
this.image=new gimage({width:this.height-18,height:this.height-18,draw_type:DIRECT,
translate:[-this.width*0.5+this.height*0.5+6,0,0],}),
this.text=new gtextbox({text:"",width:this.width-24,height:this.height,
color:this.DISABLE_TEXT_COLOR,valign:MIDDLE,align:CENTER,
translate:[10,2,0],}),
this.badge=new gimage({width:this.height-18,height:this.height-18,draw_type:DIRECT,
src:IMG_PATH+"badge_r_small.png",visible_p:false,
translate:[-this.width*0.5+this.height*0.5-6*2,12,0],}),
this.badge_cnt=new gtext({width:this.height-18,height:this.height-18,align:CENTER,
color:COL_TEXT_ONBASE,
translate:[-this.width*0.5+this.height*0.5-6*2,14,0],}),
]
});
if(type==2){
this.image.draw_type=INSCRIBED;
this.image.width=78;}
};
Toolbar.prototype.Button.prototype.IMG_PATH=IMG_PATH;
Toolbar.prototype.Button.prototype.width=200;
Toolbar.prototype.Button.prototype.height=52;
Toolbar.prototype.Button.prototype.background=null;Toolbar.prototype.Button.prototype.text=null;Toolbar.prototype.Button.prototype.voice=null;
Toolbar.prototype.Button.prototype.action=function(){};Toolbar.prototype.Button.prototype.invisible=false;
Toolbar.prototype.Button.prototype.ENABLE_TEXT_COLOR=COL_TEXT_ONBASE;
Toolbar.prototype.Button.prototype.DISABLE_TEXT_COLOR=COL_WIDGET_SUB;
Toolbar.prototype.Button.prototype.setText=function(text){
if(!isString(text)){
setf_text(this.text,"");
this.setEnable(false);
return;}
this.setEnable(true);
if(get_text_font_height(this.text,text)>this.height)
this.text.font_size=20;
setf_text(this.text,text);};
Toolbar.prototype.Button.prototype.setVoice=function(voice_text){
this.voice=voice_text;};
Toolbar.prototype.Button.prototype.setAction=function(action_func){
this.action=action_func;};
Toolbar.prototype.Button.prototype.setImage=function(src){
if(src){
this.image.visible_p=true;
this.image.src=src;
this.image.translate[0]=-this.width*0.5+this.image.width*0.5+10;
this.text.translate[0]=this.image.width*0.5+10;
this.text.width=this.width-this.image.width-24;
this.text.align=LEFT;}else {
this.image.visible_p=false;
if(!this.box.visible_p)
this.text.translate[0]=0;}
};
Toolbar.prototype.Button.prototype.setColorBox=function(col){
if(col){
this.border.visible_p=true;
this.box.visible_p=true;
this.box.color=col;
this.border.translate[0]=-this.width*0.5+this.border.width*0.5+10;
this.box.translate[0]=this.border.translate[0];
this.text.translate[0]=this.border.width*0.5+10;
this.text.width=this.width-this.border.width-24;
this.text.align=LEFT;}else {
this.border.visible_p=false;
this.box.visible_p=false;
if(!this.image.visible_p)
this.text.translate[0]=0;}
};
Toolbar.prototype.Button.prototype.setInvisible=function(b){
this.invisible=(b===true);};
Toolbar.prototype.Button.prototype.isInvisible=function(){
return this.invisible;};
Toolbar.prototype.Button.prototype.setEnable=function(b){
if(b==true){
this.text.color=this.ENABLE_TEXT_COLOR;}else{
this.text.color=this.DISABLE_TEXT_COLOR;}
};
Toolbar.prototype.Button.prototype.getPosition=function(){
return this.translate;};
Toolbar.prototype.Button.prototype.getSize=function(){
return [this.width-4,this.height];};
