text: function bHive(t){this.setStageDimensions(t.width,t.height),this.setStageObject(t.domobject),this.init(),t.hasOwnProperty("backgroundColor")&&this.setStageColor(t.backgroundColor),t.hasOwnProperty("globalCompositeOperation")&&this.setGlobalComposite(t.globalCompositeOperation)}bHive.fn=bHive.prototype={stageTarget:null,stageObject:null,stage2d:null,undef:"undefined",defGA:1,_objects:[],_events:[],_radians:Math.PI/180,_mouseX:0,_mouseY:0,_stageHeight:320,_stageWidth:256,_frameRate:33,_initialisedAt:null,_loopIdent:null,_loopFunction:null,_gfxLibrary:[],_gfxErrorCount:0,_gfxLoaded:0,_ready:!1,_globalCompositeOperation:"source-over",init:function(){this.stageObject=document.createElement("canvas"),this.stage2d=this.stageObject.getContext("2d"),this.stageObject.height=this.sh=this._stageHeight,this.stageObject.width=this.sw=this._stageWidth,this.stage2d.globalAlpha=this.defGA;var e,i,s,n,o,h,t=this;addListener(this.stageObject,"mousemove",(e=t,function(t){e.mouseMover(t)}),!0),addListener(this.stageObject,"click",(i=t,function(t){i.mouseClick(t)}),!0),addListener(this.stageObject,"mousedown",(s=t,function(t){s.mouseDown(t)}),!0),addListener(this.stageObject,"mouseup",(n=t,function(t){n.mouseUp(t)}),!0),addListener(window,"keydown",(o=t,function(t){o.keyDown(t,o)}),!0),addListener(window,"keyup",(h=t,function(t){h.keyUp(t,h)}),!0),this.attachStage(),this._initialisedAt=new Date},addEventListener:function(t,e){this._events[t]=e},sizeof:function(t){var e=0,i=/function (.{1,})\(/;for(var s in t)result=i.exec(t[s].constructor.toString()),null!=result&&"Array"==result[1]?e+=this.sizeof(t[s]):e++;return e},KeyEvent:function(t){this.keyCode=t.keyCode?t.keyCode:t.which,this.altKey=!!t.altKey,this.altLeft=!!t.altLeft,this.ctrlKey=!!t.ctrlKey,this.ctrlLeft=!!t.ctrlLeft,this.shiftKey=!!t.shiftKey,this.shiftLeft=!!t.shiftLeft},mainController:function(){var t;this.stage2d.clearRect(0,0,this._stageWidth,this._stageHeight),"function"==typeof this._loopFunction&&this._loopFunction.call(this),this._loopIdent=setTimeout((t=this,function(){t.mainController()}),this._frameRate)},mouseMover:function(t){t=new MouseEvent(t);var e=getPosition(this.stageObject);this._mouseX=t.x-e[0],this._mouseY=t.y-e[1]},mouseClick:function(t){for(var e in t=new MouseEvent(t),xIn=yIn=!1,typeof this._events.onclick!=this.undef&&this._events.onclick.apply(this,[{x:this._mouseX,y:this._mouseY}]),this._objects){var i=this._objects[e];i instanceof bHive.Clip&&(this._mouseX>i.x&&this._mouseX<i.x+i.width()&&(xIn=!0),this._mouseY>i.y&&this._mouseY<i.y+i.height()&&(yIn=!0),xIn&&yIn&&"function"==typeof i.events.onclick&&i.events.onclick({x:this._mouseX,y:this._mouseY,src:i}))}},mouseDown:function(t){for(var e in t=new MouseEvent(t),xIn=yIn=!1,typeof this._events.mousedown!=this.undef&&this._events.mousedown.apply(this,[{x:this._mouseX,y:this._mouseY}]),this._objects){var i=this._objects[e];i instanceof bHive.Clip&&(this._mouseX>i.x&&this._mouseX<i.x+i.width()&&(xIn=!0),this._mouseY>i.y&&this._mouseY<i.y+i.height()&&(yIn=!0),xIn&&yIn&&"function"==typeof i.events.onclick&&i.events.mousedown({x:this._mouseX,y:this._mouseY,src:i}))}},mouseUp:function(t){for(var e in t=new MouseEvent(t),xIn=yIn=!1,typeof this._events.mouseup!=this.undef&&this._events.mouseup.apply(this,[{x:this._mouseX,y:this._mouseY}]),this._objects){var i=this._objects[e];i instanceof bHive.Clip&&(this._mouseX>i.x&&this._mouseX<i.x+i.width()&&(xIn=!0),this._mouseY>i.y&&this._mouseY<i.y+i.height()&&(yIn=!0),xIn&&yIn&&"function"==typeof i.events.onclick&&i.events.mouseup({x:this._mouseX,y:this._mouseY,src:i}))}},keyDown:function(t,e){for(var i in this.engine=e,t=new this.engine.KeyEvent(t),typeof this._events.onkeydown!=this.undef&&this._events.onkeydown.apply(this,[t]),this._objects){var s=this._objects[i];s instanceof bHive.Clip&&"function"==typeof s.events.onkeydown&&s.events.onkeydown(t)}},keyUp:function(t,e){for(var i in this.engine=e,t=new this.engine.KeyEvent(t),typeof this._events.onkeyup!=this.undef&&this._events.onkeyup.apply(this,[t]),this._objects){var s=this._objects[i];s instanceof bHive.Clip&&"function"==typeof s.events.onkeyup&&s.events.onkeyup(t)}},setStageDimensions:function(t,e){this._stageHeight=e,this._stageWidth=t},setStageColor:function(t){this._stageColor=t,this.stageObject.style.backgroundColor=t},setGlobalComposite:function(t){this._globalCompositeOperation=t,this.stage2d.globalCompositeOperation=t},setStageObject:function(t){if("string"==typeof t){var e=document.getElementById(t);e!==this.undef&&(this.stageTarget=e)}else this.stageTarget=t},attachStage:function(){this.stageTarget.appendChild(this.stageObject)},storeObject:function(t){var e=this._objects.length;return this._objects.push(t),this._objects[e]},createClip:function(t){return this.storeObject(new bHive.Clip(t,this))},createBitmap:function(t){return this.storeObject(new bHive.Bitmap(t,this))},createLine:function(t){return this.storeObject(new bHive.Line(t,this))},createText:function(t){return this.storeObject(new bHive.Text(t,this))},createShape:function(t){return this.storeObject(new bHive.Shape(t,this))},theLoop:function(t){var e;this._loopFunction=t,this._loopIdent=setTimeout((e=this,function(){e.mainController()}),this._frameRate)},getRotatedSize:function(t){return radians=2*Math.PI*t.rotation/360,cosine=Math.cos(radians),sine=Math.sin(radians),objNH=t.image.naturalHeight,objNW=t.image.naturalWidth,point1_x=-objNH*sine,point1_y=objNH*cosine,point2_x=objNW*cosine-objNH*sine,point2_y=objNH*cosine+objNW*sine,point3_x=objNW*cosine,point3_y=objNW*sine,minx=Math.min(0,Math.min(point1_x,Math.min(point2_x,point3_x))),miny=Math.min(0,Math.min(point1_y,Math.min(point2_y,point3_y))),maxx=Math.max(point1_x,Math.max(point2_x,point3_x)),maxy=Math.max(point1_y,Math.max(point2_y,point3_y)),rotwidth=Math.round(maxx-minx),rotheight=Math.round(maxy-miny),{width:rotwidth,height:rotheight}},hex2RGBa:function(t,e){var i,s=g=b=0;return 100<e?e=100:e<0&&(e=0),i=e/100,3==(t="#"==t.charAt(0)?t.substring(1,t.length):t).length?(s=parseInt(t.substring(0,1)+t.substring(0,1),16),g=parseInt(t.substring(1,2)+t.substring(1,2),16),b=parseInt(t.substring(2,3)+t.substring(2,3),16)):(s=parseInt(t.substring(0,2),16),g=parseInt(t.substring(2,4),16),b=parseInt(t.substring(4,6),16)),"rgba("+s+", "+g+", "+b+", "+i+")"}},bHive.Bitmap=function(t,e){var i;for(var s in this.engine=e,this.events=[],t)this[s]=t[s];this.image=new Image,this.image.src=this.src,this.image.onload=(i=this,function(){typeof i.events.onload!=i.engine.undef&&i.events.onload()})},bHive.Bitmap.prototype={engine:null,src:"",image:null,events:null,x:0,y:0,registration_x:0,registration_y:0,rotation:0,visible:!0,alpha:100,x_scale:100,y_scale:100,addEventListener:function(t,e){this.events[t]=e},draw:function(t,e){if(t=typeof t==this.engine.undef?0:t,e=typeof e==this.engine.undef?0:e,typeof this.parent!=this.engine.undef?(pA=this.parent.alpha,A=this.alpha,pA<100?(newGA=pA,A<100&&(percentage=pA*(A/100),newGA=pA-percentage),this.engine.stage2d.globalAlpha=Math.abs(newGA)/100):A<100&&(this.engine.stage2d.globalAlpha=A/100)):this.alpha<100&&(this.engine.stage2d.globalAlpha=this.alpha/100),iW=this.image.naturalWidth,iH=this.image.naturalHeight,typeof this.parent!=this.engine.undef?(100!=this.x_scale&&(iW*=this.x_scale/100),100!=this.parent.x_scale&&(iW*=this.parent.x_scale/100)):100!=this.x_scale&&(iW=this.iW*(this.x_scale/100)),typeof this.parent!=this.engine.undef?(100!=this.x_scale&&(iH*=this.y_scale/100),100!=this.parent.x_scale&&(iH*=this.parent.y_scale/100)):100!=this.y_scale&&(iH*=this.y_scale/100),0!=this.rotation){this.engine.stage2d.save();var i=t+this.x,s=e+this.y;360<this.rotation&&(this.rotation=0),this.engine.stage2d.translate(i,s),this.engine.stage2d.rotate(this.rotation*this.engine._radians),this.engine.stage2d.drawImage(this.image,-1*this.registration_x,-1*this.registration_y,iW,iH),this.engine.stage2d.restore()}else this.engine.stage2d.drawImage(this.image,t+this.x,e+this.y,iW,iH);this.alpha<100&&(this.engine.stage2d.globalAlpha=this.engine.defGA)}},bHive.Clip=function(t,e){for(var i in this.engine=e,this._childObjects=[],this.events=[],t)this[i]=t[i]},bHive.Clip.prototype={id:null,events:null,visible:!0,_childObjects:null,alpha:100,x:0,y:0,x_scale:100,y_scale:100,addEventListener:function(t,e){this.events[t]=e},add:function(t){this._childObjects.push(t);t.parent=this},draw:function(t,e){if(t=typeof t==this.engine.undef?0:t,e=typeof e==this.engine.undef?0:e,this.visible)for(var i in this._childObjects)this._childObjects[i].draw(t+this.x,e+this.y)},point:function(t,e,i){i=2*Math.PI*i/360;return[t*Math.cos(i)+e*Math.sin(i),e*Math.cos(i)-t*Math.sin(i)]},width:function(){var t=[];if(0<this._childObjects.length){for(var e in this._childObjects){var i=this._childObjects[e];i instanceof bHive.Bitmap?0<i.rotation?(rotatedDimensions=engine.getRotatedSize(i),t.push(rotatedDimensions.width+i.x)):t.push(i.image.naturalWidth+i.x):i instanceof bHive.Clip&&i.visible&&t.push(i.width()+i.x)}return Math.max.apply(0,t)}return 0},height:function(){var t=[];if(0<this._childObjects.length){for(var e in this._childObjects){var i=this._childObjects[e];i instanceof bHive.Bitmap?0<i.rotation?(rotatedDimensions=engine.getRotatedSize(i),t.push(rotatedDimensions.height+i.y)):t.push(i.image.naturalHeight+i.y):i instanceof bHive.Clip&&t.push(i.height()+i.y)}return Math.max.apply(0,t)}return 0}},bHive.Line=function(t,e){for(var i in this.engine=e,t)this[i]=t[i]},bHive.Line.prototype={weight:1,cap:"butt",corner:"miter",start:null,end:null,visible:!0,draw:function(){if(this.start instanceof Array)x1=this.start[0],y1=this.start[1];else if("string"==typeof this.start)switch(this.start){case"mouse":x1=this.engine._mouseX,y1=this.engine._mouseY}else this.start instanceof Object&&(x1=this.start.x,y1=this.start.y);if(this.end instanceof Array)x2=this.end[0],y2=this.end[1];else if("string"==typeof this.end)switch(this.end){case"mouse":x2=this.engine._mouseX,y2=this.engine._mouseY}else this.start instanceof Object&&(x2=this.end.x,y2=this.end.y);this.engine.stage2d.save(),this.engine.stage2d.beginPath(),this.engine.stage2d.lineWidth=this.weight,this.engine.stage2d.lineCap=this.cap,this.engine.stage2d.lineJoin=this.corner,this.engine.stage2d.moveTo(x1,y1),this.engine.stage2d.lineTo(x2,y2),this.engine.stage2d.stroke(),this.engine.stage2d.restore()}},bHive.Text=function(t,e){for(var i in this.engine=e,t)this[i]=t[i]},bHive.Text.prototype={text:null,x:0,y:0,align:"top",color:"rgb(0, 0, 0, 0)",visible:!0,draw:function(t,e){t=typeof t==this.engine.undef?0:t,e=typeof e==this.engine.undef?0:e,this.engine.stage2d.textBaseline=this.align,this.engine.stage2d.fillStyle=this.color,this.engine.stage2d.fillText(this.text,t+this.x,e+this.y)}},bHive.Shape=function(t,e){for(var i in this.engine=e,t)this[i]=t[i]},bHive.Shape.prototype={shape:"square",style:"filled",x:0,y:0,width:0,height:0,radius:0,backgroundColor:"rgba(0, 0, 0, 1)",strokeColor:"rgba(0, 0, 0, 1)",strokeWeight:1,alpha:100,draw:function(){var t=this.engine.stage2d,e=-1!=this.backgroundColor.indexOf("rgba")||-1!=this.backgroundColor.indexOf("rgb")?this.backgroundColor:this.engine.hex2RGBa(this.backgroundColor,this.alpha);switch(this.shape){case"square":t.save(),"filled"==this.style?(t.fillStyle=e,t.fillRect(this.x,this.y,this.width,this.height)):(t.lineWidth=1,t.strokeStyle=this.engine.hex2RGBa(this.backgroundColor,this.alpha),t.strokeRect(this.x,this.y,this.width,this.height)),t.restore();break;case"circle":t.save(),"filled"==this.style?(t.beginPath(),t.fillStyle=e,t.arc(this.x,this.y,this.radius,0,2*Math.PI,!0),t.fill()):(t.beginPath(),t.strokeStyle=this.engine.hex2RGBa(this.strokeColor,this.alpha),t.arc(this.x,this.y,this.radius,0,2*Math.PI,!0),t.stroke()),t.restore()}}};