[483] | 1 | dojo.provide("dojox.sketch.tests.FTHelper"); |
---|
| 2 | |
---|
| 3 | dojo.declare('dojox.sketch.tests.FTHelper',null,{ |
---|
| 4 | controlCss: "#dojox_sketch_Toolbar_0 .dijitButtonContents", |
---|
| 5 | canvas:'canvas', |
---|
| 6 | defaultDelay: 100, |
---|
| 7 | //controls: ['lead','single','double','underline','preexisting']; |
---|
| 8 | constructor: function(args){ |
---|
| 9 | this.controls=['lead','single','double','underline','preexisting']; |
---|
| 10 | if(args){ |
---|
| 11 | dojo.mixin(this,args); |
---|
| 12 | } |
---|
| 13 | }, |
---|
| 14 | selectShape: function(shape,delay){ |
---|
| 15 | delay=delay||this.defaultDelay; |
---|
| 16 | var i=dojo.indexOf(this.controls,shape); |
---|
| 17 | if(i<0){ |
---|
| 18 | throw Error('shape "'+shape+'" is not recognized'); |
---|
| 19 | } |
---|
| 20 | var buttons=dojo.query(this.controlCss); |
---|
| 21 | if(buttons.length<=i){ |
---|
| 22 | throw Error('Can not find button for shape "'+shape+'" on the toolbar'); |
---|
| 23 | } |
---|
| 24 | var button=buttons[i]; |
---|
| 25 | doh.robot.mouseMoveAt(button,delay); |
---|
| 26 | doh.robot.mouseClick({left:true},delay); |
---|
| 27 | }, |
---|
| 28 | drawShape: function(start,end,delay){ |
---|
| 29 | delay=delay||this.defaultDelay; |
---|
| 30 | if(!this.coords){ |
---|
| 31 | this.coords=dojo.coords(this.canvas); |
---|
| 32 | } |
---|
| 33 | end=end||start; |
---|
| 34 | doh.robot.mouseMove(this.coords.x+start.x,this.coords.y+start.y,delay,1); |
---|
| 35 | doh.robot.mousePress({left:1},delay); |
---|
| 36 | doh.robot.mouseMove(this.coords.x+end.x,this.coords.y+end.y,delay,1); |
---|
| 37 | doh.robot.mouseRelease({left:1},delay); |
---|
| 38 | }, |
---|
| 39 | click: function(args,delay){ |
---|
| 40 | delay=delay||this.defaultDelay; |
---|
| 41 | doh.robot.mouseMove(this.coords.x+args.x,this.coords.y+args.y,delay,1); |
---|
| 42 | doh.robot.mouseClick(args,delay); |
---|
| 43 | } |
---|
| 44 | }); |
---|