2 * This script refer to:
5 * Availability: https://github.com/szimek/signature_pad
9 * @class Roo.bootstrap.BezierSignature
10 * @extends Roo.bootstrap.Component
11 * Bootstrap BezierSignature class
14 * Create a new BezierSignature
15 * @param {Object} config The config object
18 Roo.bootstrap.BezierSignature = function(config){
19 Roo.bootstrap.BezierSignature.superclass.constructor.call(this, config);
22 Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component, {
25 * @cfg(float or function) Radius of a single dot.
30 * @cfg(float) Minimum width of a line. Defaults to 0.5.
35 * @cfg(float) Maximum width of a line. Defaults to 2.5.
40 * @cfg(integer) Draw the next point at most once per every x milliseconds. Set it to 0 to turn off throttling. Defaults to 16.
45 * @cfg(integer) Add the next point only if the previous one is farther than x pixels. Defaults to 5.
50 * @cfg(string) Color used to clear the background. Can be any color format accepted by context.fillStyle. Defaults to "rgba(0,0,0,0)" (transparent black). Use a non-transparent color e.g. "rgb(255,255,255)" (opaque white) if you'd like to save signatures as JPEG images.
52 backgroundColor: 'rgba(0,0,0,0)',
55 * @cfg(string) Color used to draw the lines. Can be any color format accepted by context.fillStyle. Defaults to "black".
60 * @cfg(float) Weight used to modify new velocity based on the previous velocity. Defaults to 0.7.
62 velocityFilterWeight: 0.7,
65 * @cfg(function) Callback when stroke begin.
70 * @cfg(function) Callback when stroke end.
75 function Point(x, y, time) {
78 this.time = time || Date.now();
80 Point.prototype.distanceTo = function (start) {
81 return Math.sqrt(Math.pow(this.x - start.x, 2) + Math.pow(this.y - start.y, 2));
83 Point.prototype.equals = function (other) {
84 return this.x === other.x && this.y === other.y && this.time === other.time;
86 Point.prototype.velocityFrom = function (start) {
87 return this.time !== start.time
88 ? this.distanceTo(start) / (this.time - start.time)
94 Bezier: (function () {
95 function Bezier(startPoint, control2, control1, endPoint, startWidth, endWidth) {
96 this.startPoint = startPoint;
97 this.control2 = control2;
98 this.control1 = control1;
99 this.endPoint = endPoint;
100 this.startWidth = startWidth;
101 this.endWidth = endWidth;
103 Bezier.fromPoints = function (points, widths) {
104 var c2 = this.calculateControlPoints(points[0], points[1], points[2]).c2;
105 var c3 = this.calculateControlPoints(points[1], points[2], points[3]).c1;
106 return new Bezier(points[1], c2, c3, points[2], widths.start, widths.end);
108 Bezier.calculateControlPoints = function (s1, s2, s3) {
109 var dx1 = s1.x - s2.x;
110 var dy1 = s1.y - s2.y;
111 var dx2 = s2.x - s3.x;
112 var dy2 = s2.y - s3.y;
113 var m1 = { x: (s1.x + s2.x) / 2.0, y: (s1.y + s2.y) / 2.0 };
114 var m2 = { x: (s2.x + s3.x) / 2.0, y: (s2.y + s3.y) / 2.0 };
115 var l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
116 var l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
117 var dxm = m1.x - m2.x;
118 var dym = m1.y - m2.y;
119 var k = l2 / (l1 + l2);
120 var cm = { x: m2.x + dxm * k, y: m2.y + dym * k };
121 var tx = s2.x - cm.x;
122 var ty = s2.y - cm.y;
124 c1: new Point(m1.x + tx, m1.y + ty),
125 c2: new Point(m2.x + tx, m2.y + ty)
128 Bezier.prototype.length = function () {
133 for (var i = 0; i <= steps; i += 1) {
135 var cx = this.point(t, this.startPoint.x, this.control1.x, this.control2.x, this.endPoint.x);
136 var cy = this.point(t, this.startPoint.y, this.control1.y, this.control2.y, this.endPoint.y);
140 length += Math.sqrt(xdiff * xdiff + ydiff * ydiff);
147 Bezier.prototype.point = function (t, start, c1, c2, end) {
148 return (start * (1.0 - t) * (1.0 - t) * (1.0 - t))
149 + (3.0 * c1 * (1.0 - t) * (1.0 - t) * t)
150 + (3.0 * c2 * (1.0 - t) * t * t)
156 getAutoCreate : function()
158 var cls = 'roo-signature';
161 cls += ' ' + this.cls;
170 cls: 'roo-signature-body',
174 cls: 'roo-signature-body-canvas'
184 initEvents: function()
186 Roo.bootstrap.BezierSignature.superclass.initEvents.call(this);
187 // assign all object in here...
192 // form cannot detect...