@@ -14,25 +14,38 @@ angular.module('angular-ui-scribble',[])
14
14
'<li ng-if=\'mode=="erase"\'><button ng-click="setMode(\'pen\')">Pen</button></li>' +
15
15
'<li ng-if=\'mode!="streaming" && !isMobile\'><button ng-click="setBackground()">Background</button></li>' +
16
16
'<li ng-if=\'mode=="streaming" && !isMobile\'><button ng-click="screenshot()">Screenshot</button></li>' +
17
- '<li><input id ="selectBackground" type="file" accept="image/*" capture="camera"></lis>' +
17
+ '<li><input class ="selectBackground" type="file" accept="image/*" capture="camera"></lis>' +
18
18
'</ul>' +
19
- '<div class="scribble-canvas" height="200 " width="350 ">' +
20
- '<video ng-show=\'mode=="streaming"\' height="200 " width="380 " autoplay id ="videoFeed" style="z-index:2;"></video>' +
21
- '<canvas height="200 " width="380 " style="z-index:3;"></canvas>' +
22
- '<canvas ng-show=\'mode!="streaming"\' id="scribble-background" height="200 " width="380 " style="z-index:1;"></canvas>' +
19
+ '<div class="scribble-canvas" height="{{scribbleHeight}} " width="{{scribbleWidth}} ">' +
20
+ '<video ng-show=\'mode=="streaming"\' height="{{scribbleHeight}} " width="{{scribbleWidth}} " autoplay class ="videoFeed" style="z-index:2;"></video>' +
21
+ '<canvas class="scribble-board" height="{{scribbleHeight}} " width="{{scribbleWidth}} " style="z-index:3;"></canvas>' +
22
+ '<canvas class="scribble-background" ng-show=\'mode!="streaming"\' height="{{scribbleHeight}} " width="{{scribbleWidth}} " style="z-index:1;"></canvas>' +
23
23
'<button ng-if="signatureReady" ng-click="callbackBtn({signature: signaturePad.toDataURL()})">Done</button>' +
24
24
'</div>' +
25
25
'</div>' ,
26
26
controller : function ( $scope , $element , $attrs ) {
27
27
$scope . isMobile = false ; //TODO: detect mobile/desktop version
28
28
$scope . mode = 'pen' ;
29
29
$scope . signaturePad ;
30
+ $scope . scribbleHeight = 400 ;
31
+ $scope . scribbleWidth = 400 ;
30
32
31
- var canvas = $element . find ( 'canvas' ) [ 0 ] ;
33
+ var canvas = $element [ 0 ] . querySelector ( '.scribble-board' ) ;
32
34
var ctx = canvas . getContext ( '2d' ) ;
35
+
36
+ var canvasBackground = $element [ 0 ] . querySelector ( '.scribble-background' ) ;
37
+ var ctxBackground = canvasBackground . getContext ( '2d' ) ;
38
+
39
+ // Flip the screenshot {{{
40
+ //TODO: not flipping the screenshot
41
+ var reversed = false ;
42
+ // ctxBackground.translate(canvasBackground.width, 0);
43
+ // ctxBackground.scale(-1, 1);
44
+ // }}}
45
+
33
46
$scope . signaturePad = new SignaturePad ( canvas ) ;
34
47
35
- var video = document . querySelector ( '# videoFeed' ) ;
48
+ var video = $element [ 0 ] . querySelector ( '. videoFeed' ) ;
36
49
var videoStream ;
37
50
// check for getUserMedia support
38
51
navigator . getUserMedia = navigator . getUserMedia || navigator . webkitGetUserMedia ||
@@ -48,7 +61,8 @@ angular.module('angular-ui-scribble',[])
48
61
49
62
function handleVideo ( stream ) {
50
63
video . src = window . URL . createObjectURL ( stream ) ;
51
- videoStream = stream . getTracks ( ) [ 0 ] ;
64
+ streamOriginal = stream ;
65
+ videoStream = stream
52
66
}
53
67
54
68
function videoError ( ) { }
@@ -57,17 +71,18 @@ angular.module('angular-ui-scribble',[])
57
71
$scope . setMode ( 'pen' ) ;
58
72
if ( video . paused || video . ended ) console . log ( "no video" ) ; ;
59
73
if ( video . paused || video . ended ) return false ;
74
+ //TODO: hack to flip context only once {{{
75
+ if ( ! reversed ) {
76
+ reversed = true ;
77
+ ctxBackground . translate ( canvasBackground . width , 0 ) ;
78
+ ctxBackground . scale ( - 1 , 1 ) ;
79
+ }
80
+ // }}}
60
81
61
- var background = document . getElementById ( 'scribble-background' ) ;
62
- var backgroundCtx = background . getContext ( '2d' ) ;
63
- var width = background . width ;
64
- var height = background . height ;
65
-
66
- backgroundCtx . drawImage ( video , 0 , 0 , width , height ) ;
67
- videoStream . stop ( ) ;
82
+ ctxBackground . drawImage ( video , 0 , 0 , $scope . scribbleWidth , $scope . scribbleHeight ) ;
83
+ videoStream . getTracks ( ) [ 0 ] . stop ( ) ;
68
84
} ;
69
85
70
-
71
86
// Expose original signaturePad object
72
87
$scope . config . getSignaturePad = function ( ) {
73
88
return signaturePad ;
@@ -116,9 +131,8 @@ angular.module('angular-ui-scribble',[])
116
131
}
117
132
} ) ;
118
133
119
- // Background {{{
120
-
121
- var selectBackground = document . getElementById ( 'selectBackground' ) ;
134
+ // Background - mobile {{{
135
+ var selectBackground = $element [ 0 ] . querySelector ( '.selectBackground' )
122
136
var reader ;
123
137
124
138
selectBackground . addEventListener ( 'change' , function ( e ) {
@@ -133,17 +147,13 @@ angular.module('angular-ui-scribble',[])
133
147
} ) ;
134
148
135
149
function loadBackground ( dataUrl ) {
136
- var background = document . getElementById ( 'scribble-background' ) ;
137
- var backgroundCtx = background . getContext ( '2d' ) ;
138
150
var image = new Image ( ) ;
139
151
var ratio = window . devicePixelRatio || 1 ;
140
- var width = background . width ;
141
- var height = background . height ;
142
152
143
153
image . src = dataUrl ;
144
154
image . onload = function ( ) {
145
- backgroundCtx . clearRect ( 0 , 0 , canvas . width , canvas . height ) ;
146
- backgroundCtx . drawImage ( image , 0 , 0 , width , height ) ;
155
+ ctxBackground . clearRect ( 0 , 0 , canvas . width , canvas . height ) ;
156
+ ctxBackground . drawImage ( image , 0 , 0 , canvasBackground . width , canvasBackground . height ) ;
147
157
} ;
148
158
}
149
159
// }}}
0 commit comments