aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorValerio Virgillito2012-03-13 11:15:56 -0700
committerValerio Virgillito2012-03-13 11:15:56 -0700
commit91335d6572a611ecde7a71dbbfdb82bdb40f7e2b (patch)
treeb1218ee5607151ac62cbfd92d60062de5557d618 /js/tools
parentf6b958360d82854bdaf51848e7fd715d1f633179 (diff)
parent7b4b068cadc0af8ec7e930e1c2b429e945f96984 (diff)
downloadninja-91335d6572a611ecde7a71dbbfdb82bdb40f7e2b.tar.gz
Merge pull request #108 from pushkarjoshi/brushtool
Brushtool
Diffstat (limited to 'js/tools')
-rw-r--r--js/tools/BrushTool.js41
-rwxr-xr-xjs/tools/PenTool.js12
2 files changed, 49 insertions, 4 deletions
diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js
index 752aa2a3..4ce9976a 100644
--- a/js/tools/BrushTool.js
+++ b/js/tools/BrushTool.js
@@ -5,6 +5,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
5</copyright> */ 5</copyright> */
6 6
7var ShapeTool = require("js/tools/ShapeTool").ShapeTool; 7var ShapeTool = require("js/tools/ShapeTool").ShapeTool;
8var ShapesController = require("js/controllers/elements/shapes-controller").ShapesController;
8var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase; 9var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase;
9var defaultEventManager = require("montage/core/event/event-manager").defaultEventManager; 10var defaultEventManager = require("montage/core/event/event-manager").defaultEventManager;
10var Montage = require("montage/core/core").Montage; 11var Montage = require("montage/core/core").Montage;
@@ -69,12 +70,46 @@ exports.BrushTool = Montage.create(ShapeTool, {
69 if (this.application.ninja.colorController.colorToolbar.stroke.webGlColor){ 70 if (this.application.ninja.colorController.colorToolbar.stroke.webGlColor){
70 this._selectedBrushStroke.setStrokeColor(this.application.ninja.colorController.colorToolbar.stroke.webGlColor); 71 this._selectedBrushStroke.setStrokeColor(this.application.ninja.colorController.colorToolbar.stroke.webGlColor);
71 } 72 }
73 if (this.application.ninja.colorController.colorToolbar.fill.webGlColor){
74 this._selectedBrushStroke.setSecondStrokeColor(this.application.ninja.colorController.colorToolbar.fill.webGlColor);
75 }
72 //add this point to the brush stroke in case the user does a mouse up before doing a mouse move 76 //add this point to the brush stroke in case the user does a mouse up before doing a mouse move
73 var currMousePos = this._getUnsnappedPosition(event.pageX, event.pageY); 77 var currMousePos = this._getUnsnappedPosition(event.pageX, event.pageY);
74 this._selectedBrushStroke.addPoint(currMousePos); 78 this._selectedBrushStroke.addPoint(currMousePos);
75 79
76 //TODO get these values from the options 80 var strokeSize = 1;
77 this._selectedBrushStroke.setStrokeWidth(20); 81 if (this.options.strokeSize) {
82 strokeSize = ShapesController.GetValueInPixels(this.options.strokeSize.value, this.options.strokeSize.units);
83 }
84 this._selectedBrushStroke.setStrokeWidth(strokeSize);
85
86 var strokeHardness = 100;
87 if (this.options.strokeHardness){
88 strokeHardness = ShapesController.GetValueInPixels(this.options.strokeHardness.value, this.options.strokeHardness.units);
89 }
90 this._selectedBrushStroke.setStrokeHardness(strokeHardness);
91
92 var doSmoothing = false;
93 if (this.options.doSmoothing){
94 doSmoothing = this.options.doSmoothing;
95 }
96 this._selectedBrushStroke.setDoSmoothing(doSmoothing);
97
98 var useCalligraphic = false;
99 if (this.options.useCalligraphic){
100 useCalligraphic = this.options.useCalligraphic;
101 }
102 if (useCalligraphic) {
103 this._selectedBrushStroke.setStrokeUseCalligraphic(true);
104 var strokeAngle = 0;
105 if (this.options.strokeAngle){
106 strokeAngle= ShapesController.GetValueInPixels(this.options.strokeAngle.value, this.options.strokeAngle.units);
107 }
108 this._selectedBrushStroke.setStrokeAngle(Math.PI * -strokeAngle/180);
109 } else {
110 this._selectedBrushStroke.setStrokeUseCalligraphic(false);
111 }
112
78 } 113 }
79 NJevent("enableStageMove");//stageManagerModule.stageManager.enableMouseMove(); 114 NJevent("enableStageMove");//stageManagerModule.stageManager.enableMouseMove();
80 } //value: function (event) { 115 } //value: function (event) {
@@ -114,7 +149,7 @@ exports.BrushTool = Montage.create(ShapeTool, {
114 149
115 if (this._isDrawing) { 150 if (this._isDrawing) {
116 var currMousePos = this._getUnsnappedPosition(event.pageX, event.pageY); 151 var currMousePos = this._getUnsnappedPosition(event.pageX, event.pageY);
117 if (this._selectedBrushStroke && this._selectedBrushStroke.getNumPoints()<100){ 152 if (this._selectedBrushStroke && this._selectedBrushStroke.getNumPoints()<1000){
118 this._selectedBrushStroke.addPoint(currMousePos); 153 this._selectedBrushStroke.addPoint(currMousePos);
119 } 154 }
120 this.ShowCurrentBrushStrokeOnStage(); 155 this.ShowCurrentBrushStrokeOnStage();
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 71a91870..6897c003 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -278,6 +278,9 @@ exports.PenTool = Montage.create(ShapeTool, {
278 this.application.ninja.stage.clearDrawingCanvas(); 278 this.application.ninja.stage.clearDrawingCanvas();
279 this._hoveredAnchorIndex = -1; 279 this._hoveredAnchorIndex = -1;
280 280
281 //set the cursor to be the default cursor
282 this.application.ninja.stage.drawingCanvas.style.cursor = "auto";
283
281 if (this._isDrawing) { 284 if (this._isDrawing) {
282 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); 285 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY));
283 //go through the drawing toolbase to get the position of the mouse 286 //go through the drawing toolbase to get the position of the mouse
@@ -348,6 +351,14 @@ exports.PenTool = Montage.create(ShapeTool, {
348 var selAnchor = this._selectedSubpath.pickAnchor(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS); 351 var selAnchor = this._selectedSubpath.pickAnchor(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS);
349 if (selAnchor >=0) { 352 if (selAnchor >=0) {
350 this._hoveredAnchorIndex = selAnchor; 353 this._hoveredAnchorIndex = selAnchor;
354 } else {
355 //detect if the current mouse position will hit the path
356 var pathHitTestData = this._selectedSubpath.pathHitTest(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS);
357 if (pathHitTestData[0]!==-1){
358 //change the cursor
359 var cursor = "url('images/cursors/penAdd.png') 10 10,default";
360 this.application.ninja.stage.drawingCanvas.style.cursor = cursor;
361 }
351 } 362 }
352 } 363 }
353 } //else of if (this._isDrawing) { 364 } //else of if (this._isDrawing) {
@@ -356,7 +367,6 @@ exports.PenTool = Montage.create(ShapeTool, {
356 if (this._selectedSubpath){ 367 if (this._selectedSubpath){
357 this.DrawSubpathAnchors(this._selectedSubpath); 368 this.DrawSubpathAnchors(this._selectedSubpath);
358 } 369 }
359
360 }//value: function(event) 370 }//value: function(event)
361 },//HandleMouseMove 371 },//HandleMouseMove
362 372