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/models/color-model.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/models/color-model.js')
-rw-r--r-- | js/models/color-model.js | 567 |
1 files changed, 567 insertions, 0 deletions
diff --git a/js/models/color-model.js b/js/models/color-model.js new file mode 100644 index 00000000..7e5fee1f --- /dev/null +++ b/js/models/color-model.js | |||
@@ -0,0 +1,567 @@ | |||
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 | //////////////////////////////////////////////////////////////////////// | ||
8 | // | ||
9 | var Montage = require("montage/core/core").Montage, | ||
10 | Component = require("montage/ui/component").Component; | ||
11 | //////////////////////////////////////////////////////////////////////// | ||
12 | // | ||
13 | exports.ColorModel = Montage.create(Component, { | ||
14 | //////////////////////////////////////////////////////////////////// | ||
15 | // | ||
16 | hasTemplate: { | ||
17 | enumerable: false, | ||
18 | value: false | ||
19 | }, | ||
20 | //////////////////////////////////////////////////////////////////// | ||
21 | //HSV Value of current color selected | ||
22 | _gradient: { | ||
23 | enumerable: false, | ||
24 | value: null | ||
25 | }, | ||
26 | //////////////////////////////////////////////////////////////////// | ||
27 | //HSV Value of current color selected | ||
28 | gradient: { | ||
29 | enumerable: true, | ||
30 | get: function() { | ||
31 | return this._gradient; | ||
32 | }, | ||
33 | set: function(value) { | ||
34 | this._gradient = value; | ||
35 | //Updating color selected (converting to all modes) | ||
36 | this.updateColorSelected('gradient', value); | ||
37 | } | ||
38 | }, | ||
39 | //////////////////////////////////////////////////////////////////// | ||
40 | //HSV Value of current color selected | ||
41 | _hsv: { | ||
42 | enumerable: false, | ||
43 | value: null | ||
44 | }, | ||
45 | //////////////////////////////////////////////////////////////////// | ||
46 | //HSV Value of current color selected | ||
47 | hsv: { | ||
48 | enumerable: true, | ||
49 | get: function() { | ||
50 | return this._hsv; | ||
51 | }, | ||
52 | set: function(value) { | ||
53 | this._hsv = value; | ||
54 | //Updating color selected (converting to all modes) | ||
55 | this.updateColorSelected('hsv', value); | ||
56 | } | ||
57 | }, | ||
58 | //////////////////////////////////////////////////////////////////// | ||
59 | //RGB Value of current color selected | ||
60 | _rgb: { | ||
61 | enumerable: false, | ||
62 | value: null | ||
63 | }, | ||
64 | //////////////////////////////////////////////////////////////////// | ||
65 | //RGB Value of current color selected | ||
66 | rgb: { | ||
67 | enumerable: true, | ||
68 | get: function() { | ||
69 | return this._rgb; | ||
70 | }, | ||
71 | set: function(value) { | ||
72 | this._rgb = value; | ||
73 | //Updating color selected (converting to all modes) | ||
74 | this.updateColorSelected('rgb', value); | ||
75 | } | ||
76 | }, | ||
77 | //////////////////////////////////////////////////////////////////// | ||
78 | //HSL Value of current color selected | ||
79 | _hsl: { | ||
80 | enumerable: false, | ||
81 | value: null | ||
82 | }, | ||
83 | //////////////////////////////////////////////////////////////////// | ||
84 | //HSL Value of current color selected | ||
85 | hsl: { | ||
86 | enumerable: true, | ||
87 | get: function() { | ||
88 | return this._hsl; | ||
89 | }, | ||
90 | set: function(value) { | ||
91 | this._hsl = value; | ||
92 | //Updating color selected (converting to all modes) | ||
93 | this.updateColorSelected('hsl', value); | ||
94 | } | ||
95 | }, | ||
96 | //////////////////////////////////////////////////////////////////// | ||
97 | //HEX Value of current color selected | ||
98 | _hex: { | ||
99 | numerable: false, | ||
100 | value: null | ||
101 | }, | ||
102 | //////////////////////////////////////////////////////////////////// | ||
103 | //HEX Value of current color selected | ||
104 | hex: { | ||
105 | enumerable: true, | ||
106 | get: function() { | ||
107 | return this._hex; | ||
108 | }, | ||
109 | set: function(value) { | ||
110 | this._hex = value; | ||
111 | //Updating color selected (converting to all modes) | ||
112 | this.updateColorSelected('hex', value); | ||
113 | } | ||
114 | }, | ||
115 | //////////////////////////////////////////////////////////////////// | ||
116 | //ALPHA Value of current color selected | ||
117 | _alpha: { | ||
118 | enumerable: false, | ||
119 | value: {value: 1, type: 'change', wasSetByCode: true} | ||
120 | }, | ||
121 | //////////////////////////////////////////////////////////////////// | ||
122 | //ALPHA Value of current color selected | ||
123 | alpha: { | ||
124 | enumerable: true, | ||
125 | get: function() { | ||
126 | return this._alpha; | ||
127 | }, | ||
128 | set: function(value) { | ||
129 | value.value = Math.ceil(value.value*100)/100; | ||
130 | this._alpha = value; | ||
131 | // | ||
132 | if (this.rgb || this.hsl) { | ||
133 | this._dispatchChangeEvent('alpha', value); | ||
134 | } | ||
135 | } | ||
136 | }, | ||
137 | //////////////////////////////////////////////////////////////////// | ||
138 | //Input (fill or stroke) Value of current color selected | ||
139 | _input: { | ||
140 | enumerable: false, | ||
141 | value: 'fill' | ||
142 | }, | ||
143 | //////////////////////////////////////////////////////////////////// | ||
144 | //Input Value of current color selected | ||
145 | input: { | ||
146 | enumerable: true, | ||
147 | get: function() { | ||
148 | return this._input; | ||
149 | }, | ||
150 | set: function(value) { | ||
151 | this._input = value; | ||
152 | //Dispatching change event | ||
153 | this._dispatchChangeEvent('input', value); | ||
154 | } | ||
155 | }, | ||
156 | //////////////////////////////////////////////////////////////////// | ||
157 | //Color mode of current color selected | ||
158 | _mode: { | ||
159 | enumerable: false, | ||
160 | value: null | ||
161 | }, | ||
162 | //////////////////////////////////////////////////////////////////// | ||
163 | //Color mode of current color selected | ||
164 | mode: { | ||
165 | enumerable: true, | ||
166 | get: function() { | ||
167 | return this._mode; | ||
168 | }, | ||
169 | set: function(value) { | ||
170 | this._mode = value; | ||
171 | //Dispatching change event | ||
172 | this._dispatchChangeEvent('mode', value); | ||
173 | } | ||
174 | }, | ||
175 | //////////////////////////////////////////////////////////////////// | ||
176 | //Stroke Color Value of current color selected | ||
177 | _stroke: { | ||
178 | enumerable: false, | ||
179 | value: null | ||
180 | }, | ||
181 | //////////////////////////////////////////////////////////////////// | ||
182 | //Stroke Color Value of current color selected | ||
183 | stroke: { | ||
184 | enumerable: true, | ||
185 | get: function() { | ||
186 | return this._stroke; | ||
187 | }, | ||
188 | set: function(value) { | ||
189 | this._stroke = value; | ||
190 | } | ||
191 | }, | ||
192 | //////////////////////////////////////////////////////////////////// | ||
193 | //Fill Color Value of current color selected | ||
194 | _fill: { | ||
195 | enumerable: false, | ||
196 | value: null | ||
197 | }, | ||
198 | //////////////////////////////////////////////////////////////////// | ||
199 | //Fill Color Value of current color selected | ||
200 | fill: { | ||
201 | enumerable: true, | ||
202 | get: function() { | ||
203 | return this._fill; | ||
204 | }, | ||
205 | set: function(value) { | ||
206 | this._fill = value; | ||
207 | } | ||
208 | }, | ||
209 | //////////////////////////////////////////////////////////////////// | ||
210 | //History Value array of current color selected | ||
211 | colorHistory: { | ||
212 | enumerable: false, | ||
213 | value: {stroke: [{m: 'rgb', c: {r: 0, g: 0, b: 0}, a: 1}, {m: 'rgb', c: {r: 0, g: 0, b: 0}, a: 1}], fill: [{m: 'rgb', c: {r: 0, g: 0, b: 0}, a: 1}, {m: 'rgb', c: {r: 0, g: 0, b: 0}, a: 1}]} | ||
214 | }, | ||
215 | //////////////////////////////////////////////////////////////////// | ||
216 | //History Value array of current color selected | ||
217 | _addColorHistory: { | ||
218 | enumerable: true, | ||
219 | value: function(input, mode, color, alpha) { | ||
220 | //TODO: Add limit | ||
221 | if (this.colorHistory[input.toLowerCase()].length > 1) { | ||
222 | if (this.colorHistory[input.toLowerCase()][this.colorHistory[input.toLowerCase()].length-1].c !== color || this.colorHistory[input.toLowerCase()][this.colorHistory[input.toLowerCase()].length-1].a !== alpha.value) { | ||
223 | this.colorHistory[input.toLowerCase()].push({m: mode, c: color, a: alpha.value}); | ||
224 | } | ||
225 | } else { | ||
226 | this.colorHistory[input.toLowerCase()].push({m: mode, c: color, a: alpha.value}); | ||
227 | } | ||
228 | } | ||
229 | }, | ||
230 | //////////////////////////////////////////////////////////////////// | ||
231 | // | ||
232 | applyNoColor: { | ||
233 | enumerable: true, | ||
234 | value: function () { | ||
235 | // | ||
236 | var nocolor = {}; | ||
237 | nocolor.wasSetByCode = true; | ||
238 | nocolor.type = 'change'; | ||
239 | this.updateColorSelected('nocolor', nocolor); | ||
240 | } | ||