////////////////////////////////////////////// 
//           SoundOutTheBox knob            // 
//  Copyright © SoundOutTheBox 2012-2013    // 
//           License-CC-BY-NC-ND            // 
////////////////////////////////////////////// 
(function(d){d.widget("mui.knob",{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},Value:{value:0,type:"IntegerData",write:!0,dynamic:!0},Min:{value:0,type:"IntegerData",dynamic:!1},Max:{value:100,type:"IntegerData",dynamic:!1},DisplayReadOnly:{value:["no","yes"],type:"EnumData",defaultvalue:"no",
dynamic:!1},DisplayInput:{value:["no","yes"],type:"EnumData",defaultvalue:"no",dynamic:!1},Cursor:{value:0,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},Thickness:{value:0.3,type:"RealData",dynamic:!1},AngleOffset:{value:0,type:"IntegerData",dynamic:!1},AngleArc:{value:360,type:"IntegerData",dynamic:!1},Visible:{value:["no","yes"],type:"EnumData",defaultvalue:"yes",
write:!0,dynamic:!0}},privateVariables:{pageNumber:0,motifType:0,userScreen:0,lastClick:0,inputElement:null},config:{main:"knob.js",description:"Different kind of knob can be drawn. This Widget provides many options like 'ReadOnly', 'DisplayInput', 'Min', 'Max'...",author:"SoundOutTheBox",version:"1.0.0.0.Final",dependencies:["./js/jquery.knob.js"],widgetID:"92696a656299699e69996a346194966a6b97666f9a6d643793626a97989a646b",widgetPackages:["626a666b936b67996c6b9961619764666b67646b6b6865666593956898656b6c"]}},_create:function(){var a=this;a.element.mousedown(function(){WEBPANEL.setCaptureObject(a,
a.element.get(0))})},keydownFromWebPanel:function(a){this.updateStatusFromKeyEvent(a.which)},updateStatusFromKeyEvent:function(a){var b=this.options.privateVariables.inputElement;(a>=37&&a<=40||a===13)&&this.setValue(b[0].value,!1)},_init:function(){},_destroy:function(){},_setOption:function(){d.Widget.prototype._setOption.apply(this,arguments)},_render:function(){var a=this.options.publicVariables,b=this.element,c=a.Top.value,e=a.Left.value,f=a.Width.value,g=a.DisplayInput.value,h=a.Value.value,
i=a.Min.value,j=a.Max.value,k=a.DisplayReadOnly.value,l=a.Cursor.value,m=a.FrontColor.value,n=a.BackGroundColor.value,o=a.Thickness.value,p=a.AngleOffset.value,q=a.AngleArc.value;console.log("_render()  object="+a.Name);b.disableSelection();b.css({position:"absolute",left:e+"px",top:c+"px",zIndex:10});b.addClass("dynamicObject");c=d("<input/>");c.css({position:"absolute"});c.attr("value",h);c.attr("data-min",i);c.attr("data-max",j);k!=="yes"?c.attr("data-readOnly",0):c.attr("data-readOnly",1);c.attr("data-fgColor",
m);c.attr("data-bgColor",n);c.attr("data-width",f);g!=="yes"?c.attr("data-displayInput",0):c.attr("data-displayInput",1);c.attr("data-cursor",l);c.attr("data-thickness",o);c.attr("data-angleOffset",p);c.attr("data-angleArc",q);c.appendTo(b);this.options.privateVariables.inputElement=c;b=UTIL.getDirectoryByScriptFileName("jquery.knob.js")+"jquery.knob.js";WEBPANEL.addFile(b,function(a){a.options.privateVariables.inputElement.knob({change:function(b){a.setValue(b,!1)},release:function(b){a.setValue(b,
!1)},cancel:function(){}})},this);this.setVisible(a.Visible.value)},readFromXML:function(a){var b=this.options.publicVariables,a=d(a);b.Name.value=UTIL.getStringAttr(a,"Name",b.Name.value);b.Value.value=UTIL.getIntAttr(a,"Value",b.Value.value);b.Min.value=UTIL.getIntAttr(a,"Min",b.Min.value);b.Max.value=UTIL.getIntAttr(a,"Max",b.Max.value);b.DisplayReadOnly.value=UTIL.getStringAttr(a,"DisplayReadOnly",b.DisplayReadOnly.value);b.DisplayInput.value=UTIL.getStringAttr(a,"DisplayInput",b.DisplayInput.value);
b.Cursor.value=UTIL.getIntAttr(a,"Cursor",b.Cursor.value);b.FrontColor.value=UTIL.getColorAttr(a,"FrontColor",b.FrontColor.value);b.BackGroundColor.value=UTIL.getColorAttr(a,"BackGroundColor",b.BackGroundColor.value);b.Thickness.value=UTIL.getRealAttr(a,"Thickness",b.Thickness.value);b.AngleOffset.value=UTIL.getIntAttr(a,"AngleOffset",b.AngleOffset.value);b.AngleArc.value=UTIL.getIntAttr(a,"AngleArc",b.AngleArc.value);b.Visible.value=UTIL.getStringAttr(a,"Visible",b.Visible.value);UTIL.readPositionFromXML(a,
b)},internalSetValue:function(a,b){var c=this.options.publicVariables;if(a!==c.Value.value)c.Value.value=a,this.options.privateVariables.inputElement.val(a).trigger("change"),b&&this._trigger("propertyChange",null,Object({name:this.options.publicVariables.Name.value+".Value",property:"Value",value:c.Value.value})),this.options.privateVariables.inputElement.attr("value",a)},setValue:function(a,b){var c=this.options.publicVariables;privateVariables=this.options.privateVariables;iValue=parseInt(a,10);
currentDate=new Date;iCurrentTimeMs=currentDate.getTime();iDeltaMs=iCurrentTimeMs-privateVariables.lastClick;sendToClient=b===!1||b===void 0;if(b){if(console.log("setStatus object="+c.Name.value+" value="+iValue+" delta="+iDeltaMs+" BEFORE"),iDeltaMs<250){console.log("setStatus object="+c.Name.value+" value="+iValue+" delta="+iDeltaMs+" IGNORED");return}}else privateVariables.lastClick=iCurrentTimeMs;this.internalSetValue(iValue,sendToClient)},setVisible:function(a){var b=this.options.publicVariables,
c=this.element;if(a!==b.Visible.value)b.Visible.value=a;b.Visible.value!=="no"?UTIL.setOpacity(c,1):UTIL.setOpacity(c,0)},onPropertyChange:function(a,b){switch(a){case "Value":this.setValue(b,!0);break;case "Visible":this.setVisible(b)}},onReleaseCapture:function(){}})})(jQuery);
