aboutsummaryrefslogtreecommitdiff
path: root/static/js/wpaint/plugins/shapes/src
diff options
context:
space:
mode:
authorLibravatar bai 2019-03-29 02:14:43 +0000
committerLibravatar bai 2019-03-29 02:14:43 +0000
commit95dfe14528663923ca2a88ec928f1d8d9df2402b (patch)
tree5bc88d1466957f1aa39043b056bde5c439648022 /static/js/wpaint/plugins/shapes/src
downloadweabot-95dfe14528663923ca2a88ec928f1d8d9df2402b.tar.gz
weabot-95dfe14528663923ca2a88ec928f1d8d9df2402b.tar.xz
weabot-95dfe14528663923ca2a88ec928f1d8d9df2402b.zip
Init
Diffstat (limited to 'static/js/wpaint/plugins/shapes/src')
-rw-r--r--static/js/wpaint/plugins/shapes/src/shapes.min.js1
-rw-r--r--static/js/wpaint/plugins/shapes/src/wPaint.menu.main.shapes.js207
2 files changed, 208 insertions, 0 deletions
diff --git a/static/js/wpaint/plugins/shapes/src/shapes.min.js b/static/js/wpaint/plugins/shapes/src/shapes.min.js
new file mode 100644
index 0000000..585aa85
--- /dev/null
+++ b/static/js/wpaint/plugins/shapes/src/shapes.min.js
@@ -0,0 +1 @@
+!function(){window.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.diamond=function(a,b,c,d){return a&&b&&c&&d?(this.beginPath(),this.moveTo(a+.5*c,b),this.lineTo(a,b+.5*d),this.lineTo(a+.5*c,b+d),this.lineTo(a+c,b+.5*d),this.lineTo(a+.5*c,b),this.closePath(),void 0):!0}),window.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.ellipse=function(a,b,c,d){if(!(a&&b&&c&&d))return!0;var e=.5522848,f=c/2*e,g=d/2*e,h=a+c,i=b+d,j=a+c/2,k=b+d/2;this.beginPath(),this.moveTo(a,k),this.bezierCurveTo(a,k-g,j-f,b,j,b),this.bezierCurveTo(j+f,b,h,k-g,h,k),this.bezierCurveTo(h,k+g,j+f,i,j,i),this.bezierCurveTo(j-f,i,a,k+g,a,k),this.closePath()}),window.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.hexagon=function(a,b,c,d){if(!(a&&b&&c&&d))return!0;var e=.225,f=1-e;this.beginPath(),this.moveTo(a+.5*c,b),this.lineTo(a,b+d*e),this.lineTo(a,b+d*f),this.lineTo(a+.5*c,b+d),this.lineTo(a+c,b+d*f),this.lineTo(a+c,b+d*e),this.lineTo(a+.5*c,b),this.closePath()}),window.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.pentagon=function(a,b,c,d){return a&&b&&c&&d?(this.beginPath(),this.moveTo(a+c/2,b),this.lineTo(a,b+.4*d),this.lineTo(a+.2*c,b+d),this.lineTo(a+.8*c,b+d),this.lineTo(a+c,b+.4*d),this.lineTo(a+c/2,b),this.closePath(),void 0):!0}),window.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundedRect=function(a,b,c,d,e){return a&&b&&c&&d?(e||(e=5),this.beginPath(),this.moveTo(a+e,b),this.lineTo(a+c-e,b),this.quadraticCurveTo(a+c,b,a+c,b+e),this.lineTo(a+c,b+d-e),this.quadraticCurveTo(a+c,b+d,a+c-e,b+d),this.lineTo(a+e,b+d),this.quadraticCurveTo(a,b+d,a,b+d-e),this.lineTo(a,b+e),this.quadraticCurveTo(a,b,a+e,b),this.closePath(),void 0):!0})}(); \ No newline at end of file
diff --git a/static/js/wpaint/plugins/shapes/src/wPaint.menu.main.shapes.js b/static/js/wpaint/plugins/shapes/src/wPaint.menu.main.shapes.js
new file mode 100644
index 0000000..1d4daeb
--- /dev/null
+++ b/static/js/wpaint/plugins/shapes/src/wPaint.menu.main.shapes.js
@@ -0,0 +1,207 @@
+(function ($) {
+ var img = 'plugins/shapes/img/icons-menu-main-shapes.png';
+
+ // extend menu
+ $.extend(true, $.fn.wPaint.menus.main.items, {
+ rectangle: {
+ group: 'shapes'
+ },
+ roundedRect: {
+ icon: 'activate',
+ group: 'shapes',
+ title: 'Rounded Rectangle',
+ img: img,
+ index: 0,
+ callback: function () { this.setMode('roundedRect'); }
+ },
+ square: {
+ icon: 'activate',
+ group: 'shapes',
+ title: 'Square',
+ img: img,
+ index: 1,
+ callback: function () { this.setMode('square'); }
+ },
+ roundedSquare: {
+ icon: 'activate',
+ group: 'shapes',
+ title: 'Rounded Square',
+ img: img,
+ index: 2,
+ callback: function () { this.setMode('roundedSquare'); }
+ },
+ diamond: {
+ icon: 'activate',
+ group: 'shapes',
+ title: 'Diamond',
+ img: img,
+ index: 4,
+ callback: function () { this.setMode('diamond'); }
+ },
+
+ ellipse: {
+ group: 'shapes2'
+ },
+ circle: {
+ icon: 'activate',
+ group: 'shapes2',
+ title: 'Circle',
+ img: img,
+ index: 3,
+ callback: function () { this.setMode('circle'); }
+ },
+ pentagon: {
+ icon: 'activate',
+ group: 'shapes2',
+ title: 'Pentagon',
+ img: img,
+ index: 5,
+ callback: function () { this.setMode('pentagon'); }
+ },
+ hexagon: {
+ icon: 'activate',
+ group: 'shapes2',
+ title: 'Hexagon',
+ img: img,
+ index: 6,
+ callback: function () { this.setMode('hexagon'); }
+ }
+ });
+
+ // extend functions
+ $.fn.wPaint.extend({
+ /****************************************
+ * roundedRect
+ ****************************************/
+ _drawRoundedRectDown: function (e) { this._drawShapeDown(e); },
+
+ _drawRoundedRectMove: function (e) {
+ this._drawShapeMove(e);
+
+ var radius = e.w > e.h ? e.h / e.w : e.w / e.h;
+
+ this.ctxTemp.roundedRect(e.x, e.y, e.w, e.h, Math.ceil(radius * (e.w * e.h * 0.001)));
+ this.ctxTemp.stroke();
+ this.ctxTemp.fill();
+ },
+
+ _drawRoundedRectUp: function (e) {
+ this._drawShapeUp(e);
+ this._addUndo();
+ },
+
+ /****************************************
+ * square
+ ****************************************/
+ _drawSquareDown: function (e) { this._drawShapeDown(e); },
+
+ _drawSquareMove: function (e) {
+ this._drawShapeMove(e);
+
+ var l = e.w > e.h ? e.h : e.w;
+
+ this.ctxTemp.rect(e.x, e.y, l, l);
+ this.ctxTemp.stroke();
+ this.ctxTemp.fill();
+ },
+
+ _drawSquareUp: function (e) {
+ this._drawShapeUp(e);
+ this._addUndo();
+ },
+
+ /****************************************
+ * roundedSquare
+ ****************************************/
+ _drawRoundedSquareDown: function (e) { this._drawShapeDown(e); },
+
+ _drawRoundedSquareMove: function (e) {
+ this._drawShapeMove(e);
+
+ var l = e.w > e.h ? e.h : e.w;
+
+ this.ctxTemp.roundedRect(e.x, e.y, l, l, Math.ceil(l * l * 0.001));
+ this.ctxTemp.stroke();
+ this.ctxTemp.fill();
+ },
+
+ _drawRoundedSquareUp: function (e) {
+ this._drawShapeUp(e);
+ this._addUndo();
+ },
+
+ /****************************************
+ * diamond
+ ****************************************/
+ _drawDiamondDown: function (e) { this._drawShapeDown(e); },
+
+ _drawDiamondMove: function (e) {
+ this._drawShapeMove(e);
+
+ this.ctxTemp.diamond(e.x, e.y, e.w, e.h);
+ this.ctxTemp.stroke();
+ this.ctxTemp.fill();
+ },
+
+ _drawDiamondUp: function (e) {
+ this._drawShapeUp(e);
+ this._addUndo();
+ },
+
+ /****************************************
+ * circle
+ ****************************************/
+ _drawCircleDown: function (e) { this._drawShapeDown(e); },
+
+ _drawCircleMove: function (e) {
+ this._drawShapeMove(e);
+
+ var l = e.w > e.h ? e.h : e.w;
+
+ this.ctxTemp.ellipse(e.x, e.y, l, l);
+ this.ctxTemp.stroke();
+ this.ctxTemp.fill();
+ },
+
+ _drawCircleUp: function (e) {
+ this._drawShapeUp(e);
+ this._addUndo();
+ },
+
+ /****************************************
+ * pentagon
+ ****************************************/
+ _drawPentagonDown: function (e) { this._drawShapeDown(e); },
+
+ _drawPentagonMove: function (e) {
+ this._drawShapeMove(e);
+
+ this.ctxTemp.pentagon(e.x, e.y, e.w, e.h);
+ this.ctxTemp.stroke();
+ this.ctxTemp.fill();
+ },
+
+ _drawPentagonUp: function (e) {
+ this._drawShapeUp(e);
+ this._addUndo();
+ },
+
+ /****************************************
+ * hexagon
+ ****************************************/
+ _drawHexagonDown: function (e) { this._drawShapeDown(e); },
+
+ _drawHexagonMove: function (e) {
+ this._drawShapeMove(e);
+
+ this.ctxTemp.hexagon(e.x, e.y, e.w, e.h);
+ this.ctxTemp.stroke();
+ this.ctxTemp.fill();
+ },
+
+ _drawHexagonUp: function (e) {
+ this._drawShapeUp(e);
+ this._addUndo();
+ }
+ });
+})(jQuery);