diff options
author | Valerio Virgillito | 2012-03-13 11:15:56 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-03-13 11:15:56 -0700 |
commit | 91335d6572a611ecde7a71dbbfdb82bdb40f7e2b (patch) | |
tree | b1218ee5607151ac62cbfd92d60062de5557d618 /js/tools/BrushTool.js | |
parent | f6b958360d82854bdaf51848e7fd715d1f633179 (diff) | |
parent | 7b4b068cadc0af8ec7e930e1c2b429e945f96984 (diff) | |
download | ninja-91335d6572a611ecde7a71dbbfdb82bdb40f7e2b.tar.gz |
Merge pull request #108 from pushkarjoshi/brushtool
Brushtool
Diffstat (limited to 'js/tools/BrushTool.js')
-rw-r--r-- | js/tools/BrushTool.js | 41 |
1 files changed, 38 insertions, 3 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 | ||
7 | var ShapeTool = require("js/tools/ShapeTool").ShapeTool; | 7 | var ShapeTool = require("js/tools/ShapeTool").ShapeTool; |
8 | var ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; | ||
8 | var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase; | 9 | var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase; |
9 | var defaultEventManager = require("montage/core/event/event-manager").defaultEventManager; | 10 | var defaultEventManager = require("montage/core/event/event-manager").defaultEventManager; |
10 | var Montage = require("montage/core/core").Montage; | 11 | var 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(); |