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);
25 * When a Brick is click
26 * @param {Roo.bootstrap.Brick} this
27 * @param {Roo.EventObject} e
33 Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component, {
36 * @cfg(float or function) Radius of a single dot.
41 * @cfg(float) Minimum width of a line. Defaults to 0.5.
46 * @cfg(float) Maximum width of a line. Defaults to 2.5.
51 * @cfg(integer) Draw the next point at most once per every x milliseconds. Set it to 0 to turn off throttling. Defaults to 16.
56 * @cfg(integer) Add the next point only if the previous one is farther than x pixels. Defaults to 5.
61 * @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.
63 backgroundColor: 'rgba(0,0,0,0)',
66 * @cfg(string) Color used to draw the lines. Can be any color format accepted by context.fillStyle. Defaults to "black".
71 * @cfg(float) Weight used to modify new velocity based on the previous velocity. Defaults to 0.7.
73 velocityFilterWeight: 0.7,
76 * @cfg(function) Callback when stroke begin.
81 * @cfg(function) Callback when stroke end.
86 function Point(x, y, time) {
89 this.time = time || Date.now();
91 Point.prototype.distanceTo = function (start) {
92 return Math.sqrt(Math.pow(this.x - start.x, 2) + Math.pow(this.y - start.y, 2));
94 Point.prototype.equals = function (other) {
95 return this.x === other.x && this.y === other.y && this.time === other.time;
97 Point.prototype.velocityFrom = function (start) {
98 return this.time !== start.time
99 ? this.distanceTo(start) / (this.time - start.time)
105 Bezier: (function () {
106 function Bezier(startPoint, control2, control1, endPoint, startWidth, endWidth) {
107 this.startPoint = startPoint;
108 this.control2 = control2;
109 this.control1 = control1;
110 this.endPoint = endPoint;
111 this.startWidth = startWidth;
112 this.endWidth = endWidth;
114 Bezier.fromPoints = function (points, widths) {
115 var c2 = this.calculateControlPoints(points[0], points[1], points[2]).c2;
116 var c3 = this.calculateControlPoints(points[1], points[2], points[3]).c1;
117 return new Bezier(points[1], c2, c3, points[2], widths.start, widths.end);
119 Bezier.calculateControlPoints = function (s1, s2, s3) {
120 var dx1 = s1.x - s2.x;
121 var dy1 = s1.y - s2.y;
122 var dx2 = s2.x - s3.x;
123 var dy2 = s2.y - s3.y;
124 var m1 = { x: (s1.x + s2.x) / 2.0, y: (s1.y + s2.y) / 2.0 };
125 var m2 = { x: (s2.x + s3.x) / 2.0, y: (s2.y + s3.y) / 2.0 };
126 var l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
127 var l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
128 var dxm = m1.x - m2.x;
129 var dym = m1.y - m2.y;
130 var k = l2 / (l1 + l2);
131 var cm = { x: m2.x + dxm * k, y: m2.y + dym * k };
132 var tx = s2.x - cm.x;
133 var ty = s2.y - cm.y;
135 c1: new Point(m1.x + tx, m1.y + ty),
136 c2: new Point(m2.x + tx, m2.y + ty)
139 Bezier.prototype.length = function () {
144 for (var i = 0; i <= steps; i += 1) {
146 var cx = this.point(t, this.startPoint.x, this.control1.x, this.control2.x, this.endPoint.x);
147 var cy = this.point(t, this.startPoint.y, this.control1.y, this.control2.y, this.endPoint.y);
151 length += Math.sqrt(xdiff * xdiff + ydiff * ydiff);
158 Bezier.prototype.point = function (t, start, c1, c2, end) {
159 return (start * (1.0 - t) * (1.0 - t) * (1.0 - t))
160 + (3.0 * c1 * (1.0 - t) * (1.0 - t) * t)
161 + (3.0 * c2 * (1.0 - t) * t * t)
167 getAutoCreate : function()
169 var cls = 'roo-signature';
172 cls += ' ' + this.cls;
181 cls: 'roo-signature-body',
185 cls: 'roo-signature-footer'
195 initEvents: function()
197 // assign all object in here...
202 // form cannot detect...