////////////////////////////////////////////// 
//           SoundOutTheBox xyPad           // 
//  Copyright © SoundOutTheBox 2012-2013    // 
//           License-CC-BY-NC-ND            // 
////////////////////////////////////////////// 
(function(g){g.widget("mui.xyPad",{options:{publicVariables:{Name:{value:"no name",type:"StringData",dynamic:!1},Left:{value:0,type:"IntegerData",dynamic:!1},Top:{value:0,type:"IntegerData",dynamic:!1},Width:{value:200,type:"IntegerData",dynamic:!1},Height:{value:200,type:"IntegerData",dynamic:!1},X:{value:0,type:"IntegerData",write:!0,dynamic:!0},Y:{value:0,type:"IntegerData",write:!0,dynamic:!0},Min:{value:-100,type:"IntegerData",dynamic:!1},Max:{value:100,type:"IntegerData",dynamic:!1},FrontColor:{value:"000,128,255",
type:"StringData",subtype:"Color",dynamic:!1},BackGroundColor:{value:"200,200,200",type:"StringData",subtype:"Color",dynamic:!1},FrameWidth:{value:5,type:"IntegerData",dynamic:!1},FrameColor:{value:"080,080,080",type:"StringData",subtype:"Color",dynamic:!1},DisplayInput:{value:["no","yes"],type:"EnumData",defaultvalue:"yes",dynamic:!1},TextColor:{value:"080,080,080",type:"StringData",subtype:"Color",dynamic:!1},TextFont:{value:"Tahoma, 12",type:"StringData",dynamic:!1},Visible:{value:["no","yes"],
type:"EnumData",defaultvalue:"yes",write:!0,dynamic:!0}},privateVariables:{pageNumber:0,motifType:0,userScreen:0,lastXChange:0,lastYChange:0,fieldsetElement:null,padDivElement:null,inputXElement:null,inputYElement:null,font:null},config:{main:"xyPad.js",description:"xyPad can be used to define the position x-y of a device as a pan-tilt controller.",author:"SoundOutTheBox",version:"1.0.0.0.Final",dependencies:["./js/jquery.xyPad.js"],widgetID:"93656996956f689a696a9b6661926f66696d6b6563669c659163689760996998",widgetPackages:["626a6c6b916e66956b679f6161976a66696a63676a646b6665939b6896686a68"]}},
_create:function(){var b=this,a=b.element;b.options.privateVariables.font=new goFont;a.mousedown(function(){WEBPANEL.setCaptureObject(b,b.element.get(0))})},keydownFromWebPanel:function(){},updateStatusFromKeyEvent:function(b){var a=this.options.privateVariables.inputElement;(b>=37&&b<=40||b===13)&&this.setValue(a[0].value,!1)},_init:function(){},_destroy:function(){},_setOption:function(){g.Widget.prototype._setOption.apply(this,arguments)},_render:function(){var b=this,a=b.options.publicVariables,
c=b.options.privateVariables,d=b.element,f=a.FrameWidth.value,e=a.Top.value,h=a.Height.value,i=a.Left.value,j=a.Width.value,l=a.BackGroundColor.value,m=a.FrameColor.value,k=a.TextColor.value;console.log("_render()  object="+a.Name);d.disableSelection();d.css({position:"absolute",left:i+"px",top:e+"px",width:j+"px",height:h+"px",backgroundColor:m,color:k,zIndex:10});d.addClass("dynamicObject");i+=f;e+=f;j-=f*2;h-=f*2;f=g("<div />");f.css({position:"absolute",left:i+"px",top:e+"px",width:j+"px",height:h+
"px",backgroundColor:l,overflow:"hidden"});e=g('<fieldset data-width="'+j+'" data-height="'+h+'"> <legend>XY Pad</legend> </fieldset>');h=g('<input name="x" value=0>');i=g('<input name="x" value=0>');e.append("x : ");h.appendTo(e);e.append(" y : ");i.appendTo(e);b.options.privateVariables.inputXElement=h;b.options.privateVariables.inputYElement=i;e.appendTo(f);b.options.privateVariables.fieldsetElement=e;f.appendTo(d);b.options.privateVariables.padDivElement=f;d=UTIL.getDirectoryByScriptFileName("jquery.xyPad.js")+
"jquery.xyPad.js";WEBPANEL.addFile(d,function(a){a.options.privateVariables.fieldsetElement.xy({min:b.options.publicVariables.Min.value,max:b.options.publicVariables.Max.value,fgColor:b.options.publicVariables.FrontColor.value,bgColor:b.options.publicVariables.BackGroundColor.value,displayInput:b.options.publicVariables.DisplayInput.value!=="no"?!0:!1,change:function(b){a.setXY(parseInt(b[0],10),parseInt(b[1],10),!1)},draw:function(){a.setXY(a.options.privateVariables.inputXElement.val(),a.options.privateVariables.inputYElement.val(),
!1)}});a.options.privateVariables.inputXElement.css({color:k,fontFamily:c.font._name,fontSize:c.font._height+"pt",fontStyle:c.font._italic===!1?"normal":"italic",fontWeight:c.font._bold===!1?"normal":"bold",textDecoration:c.font._underline!==!1?"underline":c.font._strikeOut===!1?"none":"line-through"});a.options.privateVariables.inputYElement.css({color:k,fontFamily:c.font._name,fontSize:c.font._height+"pt",fontStyle:c.font._italic===!1?"normal":"italic",fontWeight:c.font._bold===!1?"normal":"bold",
textDecoration:c.font._underline!==!1?"underline":c.font._strikeOut===!1?"none":"line-through"});a.options.privateVariables.fieldsetElement.css({fontFamily:c.font._name,fontSize:c.font._height+"pt",fontStyle:c.font._italic===!1?"normal":"italic",fontWeight:c.font._bold===!1?"normal":"bold",textDecoration:c.font._underline!==!1?"underline":c.font._strikeOut===!1?"none":"line-through"});a.options.privateVariables.fieldsetElement.css({marginTop:"-"+(a.options.privateVariables.fieldsetElement.height()+
10)+"px"})},b);b.setVisible(a.Visible.value)},readFromXML:function(b){var a=this.options.publicVariables,c=this.options.privateVariables,b=g(b);a.Name.value=UTIL.getStringAttr(b,"Name",a.Name.value);a.X.value=UTIL.getIntAttr(b,"X",a.X.value);a.Y.value=UTIL.getIntAttr(b,"Y",a.Y.value);a.Min.value=UTIL.getIntAttr(b,"Min",a.Min.value);a.Max.value=UTIL.getIntAttr(b,"Max",a.Max.value);a.FrontColor.value=UTIL.getColorAttr(b,"FrontColor",a.FrontColor.value);a.BackGroundColor.value=UTIL.getColorAttr(b,"BackGroundColor",
a.BackGroundColor.value);a.FrameWidth.value=UTIL.getIntAttr(b,"FrameWidth",a.FrameWidth.value);a.FrameColor.value=UTIL.getColorAttr(b,"FrameColor",a.FrameColor.value);a.DisplayInput.value=UTIL.getStringAttr(b,"DisplayInput",a.DisplayInput.value);a.TextColor.value=UTIL.getColorAttr(b,"TextColor",a.TextColor.value);a.TextFont.value=UTIL.getStringAttr(b,"TextFont",a.TextFont.value);a.Visible.value=UTIL.getStringAttr(b,"Visible",a.Visible.value);c.font.readFromText(a.TextFont.value);UTIL.readPositionFromXML(b,
a)},internalSetXY:function(b,a,c){var d=this.options.publicVariables;if(b!==d.X.value)d.X.value=b,c?this._trigger("propertyChange",null,Object({name:this.options.publicVariables.X.value+".X",property:"X",value:d.X.value})):(this.options.privateVariables.inputXElement.val(b).trigger("change"),this.options.privateVariables.inputXElement.attr("value",b));if(a!==d.Y.value)d.Y.value=a,c?this._trigger("propertyChange",null,Object({name:this.options.publicVariables.Y.value+".Y",property:"Y",value:d.Y.value})):
(this.options.privateVariables.inputYElement.val(a).trigger("change"),this.options.privateVariables.inputYElement.attr("value",a))},setXY:function(b,a,c){var d=this.options.publicVariables;privateVariables=this.options.privateVariables;currentDate=new Date;iCurrentTimeMs=currentDate.getTime();iDeltaXMs=iCurrentTimeMs-privateVariables.lastXChange;iDeltaYMs=iCurrentTimeMs-privateVariables.lastYChange;sendToClient=c===!1||c===void 0;if(c){if(console.log("setStatus object="+d.X.value+" value="+b+" delta="+
iDeltaXMs+" BEFORE"),console.log("setStatus object="+d.Y.value+" value="+a+" delta="+iDeltaYMs+" BEFORE"),iDeltaXMs<250&&iDeltaYMs<250){console.log("setStatus object="+d.X.value+" value="+b+" delta="+iDeltaXMs+" IGNORED");console.log("setStatus object="+d.Y.value+" value="+a+" delta="+iDeltaYMs+" IGNORED");return}}else privateVariables.lastXChange=iCurrentTimeMs;this.internalSetXY(b,a,sendToClient)},setVisible:function(b){var a=this.options.publicVariables,c=this.element;if(b!==a.Visible.value)a.Visible.value=
b;a.Visible.value!=="no"?UTIL.setOpacity(c,1):UTIL.setOpacity(c,0)},onPropertyChange:function(b,a){switch(b){case "X":this.setXY(a,this.options.publicVariables.Y.value,!0);break;case "Y":this.setXY(this.options.publicVariables.X.value,a,!0);break;case "Visible":this.setVisible(a)}},onReleaseCapture:function(){}})})(jQuery);
