diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/tools/EyedropperTool.js | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/tools/EyedropperTool.js')
-rw-r--r-- | js/tools/EyedropperTool.js | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/js/tools/EyedropperTool.js b/js/tools/EyedropperTool.js new file mode 100644 index 00000000..795753d2 --- /dev/null +++ b/js/tools/EyedropperTool.js | |||
@@ -0,0 +1,152 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage/core/core").Montage, | ||
8 | ElementsMediator = require("js/mediators/element-mediator").ElementMediator, | ||
9 | |||
10 | toolBase = require("js/tools/ToolBase").toolBase; | ||
11 | |||
12 | exports.EyedropperTool = Montage.create(toolBase, { | ||
13 | |||
14 | _isMouseDown: { value: false }, | ||
15 | _previousColor: { value: null}, | ||
16 | _color: { value: null}, | ||
17 | |||
18 | Configure: { | ||
19 | value: function ( doActivate ) | ||
20 | { | ||
21 | if (doActivate) | ||
22 | { | ||
23 | NJevent("enableStageMove"); | ||
24 | } | ||
25 | else | ||
26 | { | ||
27 | NJevent("disableStageMove"); | ||
28 | } | ||
29 | } | ||
30 | }, | ||
31 | |||
32 | HandleLeftButtonDown: { | ||
33 | value : function ( event ) { | ||
34 | this._isMouseDown = true; | ||
35 | this._previousColor = | ||
36 | this.application.ninja.colorController[this.application.ninja.colorController.colorModel.input].css; | ||
37 | |||
38 | this._updateColorFromPoint(event); | ||
39 | } | ||
40 | }, | ||
41 | |||
42 | HandleMouseMove: { | ||
43 | value : function (event) | ||
44 | { | ||
45 | if(this._escape) | ||
46 | { | ||
47 | this._isMouseDown = false; | ||
48 | this._escape = false; | ||
49 | } | ||
50 | if(this._isMouseDown) | ||
51 | { | ||
52 | this._updateColorFromPoint(event); | ||
53 | } | ||
54 | } | ||
55 | }, | ||
56 | |||
57 | HandleLeftButtonUp: { | ||
58 | value : function (event) { | ||
59 | { | ||
60 | this._isMouseDown = false; | ||
61 | |||
62 | if(this._escape) | ||
63 | { | ||
64 | this._escape = false; | ||
65 | } | ||
66 | |||
67 | this._updateColor(this._color); | ||
68 | |||
69 | this._color = null; | ||
70 | } | ||
71 | } | ||
72 | }, | ||
73 | |||
74 | HandleEscape: { | ||
75 | value: function(event) { | ||
76 | if(this._color && this._color.value) | ||
77 | { | ||
78 | var color = this.application.ninja.colorController.getColorObjFromCss(this._previousColor); | ||
79 | |||
80 | if (color && color.value) { | ||
81 | color.value.wasSetByCode = true; | ||
82 | color.value.type = 'change'; | ||
83 | if (color.value.a) { | ||
84 | this.application.ninja.colorController.colorModel.alpha = {value: color.value.a, | ||
85 | wasSetByCode: true, | ||
86 | type: 'change'}; | ||
87 | } | ||
88 | this.application.ninja.colorController.colorModel[color.mode] = color.value; | ||
89 | this._color = null; | ||
90 | } | ||
91 | } | ||
92 | this._escape = true; | ||
93 | } | ||
94 | }, | ||
95 | |||
96 | _updateColorFromPoint: { | ||
97 | value : function (event) { | ||
98 | var obj = this.application.ninja.stage.GetElement(event); | ||
99 | if (obj) | ||
100 | { | ||
101 | // TODO - figure out if user clicked on a border - for now, just get fill | ||
102 | var c = ElementsMediator.getColor(obj, true); | ||
103 | if(c) | ||
104 | { | ||
105 | var color = this.application.ninja.colorController.getColorObjFromCss(c); | ||
106 | if (color && color.value) { | ||
107 | color.value.wasSetByCode = true; | ||
108 | color.value.type = 'changing'; | ||
109 | if (color.value.a) { | ||
110 | this.application.ninja.colorController.colorModel.alpha = {value: color.value.a, | ||
111 | wasSetByCode: true, | ||
112 | type: 'changing'}; | ||
113 | } | ||
114 | this.application.ninja.colorController.colorModel[color.mode] = color.value; | ||
115 | this._color = color; | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | } | ||
120 | }, | ||
121 | |||
122 | _updateColor: { | ||
123 | value: function(color) { | ||
124 | if (color && color.value) { | ||
125 | var input = this.application.ninja.colorController.colorModel.input; | ||
126 | |||
127 | if(input === "fill") | ||
128 | { | ||
129 | this.application.ninja.colorController.colorToolbar.fill_btn.color(color.mode, color.value); | ||
130 | } | ||
131 | else | ||
132 | { | ||
133 | this.application.ninja.colorController.colorToolbar.stroke_btn.color(color.mode, color.value); | ||
134 | } | ||
135 | |||
136 | // Updating color chips will set the input type to "chip", so set it back here. | ||
137 | this.application.ninja.colorController.colorModel.input = input; | ||
138 | |||
139 | color.value.wasSetByCode = true; | ||
140 | color.value.type = 'change'; | ||
141 | if (color.value.a) { | ||
142 | this.application.ninja.colorController.colorModel.alpha = {value: color.value.a, | ||
143 | wasSetByCode: true, | ||
144 | type: 'change'}; | ||
145 | } | ||
146 | this.application.ninja.colorController.colorModel[color.mode] = color.value; | ||
147 | this._previousColor = color.value.css; | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | |||
152 | }); \ No newline at end of file | ||