aboutsummaryrefslogtreecommitdiff
path: root/js/panels/color/colortoolbar.reel/colortoolbar.js
blob: bf4d307f0499f8137fc2f179aa1d6a8b301b4244 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
</copyright> */

////////////////////////////////////////////////////////////////////////
//
var Montage = 			require("montage/core/core").Montage,
	Component = 		require("montage/ui/component").Component;
////////////////////////////////////////////////////////////////////////
//
exports.ColorToolbar = Montage.create(Component, {
	////////////////////////////////////////////////////////////////////
	//
	hasTemplate: {
        value: true
    },
    ////////////////////////////////////////////////////////////////////
    //Storing stroke (stores color in mode use to select color)
    _stroke: {
        enumerable: false,
        value: {colorMode: 'rgb', color: {r: 0, g: 0, b: 0, a: 1, css: 'rgb(0,0,0)', mode:'rgb', wasSetByCode: true, type: 'change'}, webGlColor: [0, 0, 0, 1]}
    },
    ////////////////////////////////////////////////////////////////////
    //
    stroke: {
    	enumerable: true,
        get: function() {
            return this._stroke;
        },
        set: function(value) {
        	if (value !== this._stroke) {
        		this._stroke = value;
        	}
        }
    },
    ////////////////////////////////////////////////////////////////////
    //Storing fill (stores color in mode use to select color)
    _fill: {
        enumerable: false,
        value: {colorMode: 'rgb', color: {r: 255, g: 255, b: 255, a: 1, css: 'rgb(255,255,255)', mode:'rgb', wasSetByCode: true, type: 'change'}, webGlColor: [1, 1, 1, 1]}
    },
    ////////////////////////////////////////////////////////////////////
    //
    fill: {
    	enumerable: true,
        get: function() {
            return this._fill;
        },
        set: function(value) {
        	if (value !== this._fill) {
        		this._fill = value;
        	}
        }
    },
    ////////////////////////////////////////////////////////////////////
    //
    prepareForDraw: {
    	enumerable: false,
    	value: function () {
    		//
    	}
    },
    ////////////////////////////////////////////////////////////////////
    //
    willDraw: {
    	enumerable: false,
    	value: function() {
    		//
    		var buttons = this.element.getElementsByTagName('button');
    		//
    		this.fill_btn = buttons [1];
    		this.stroke_btn = buttons[0];
    		//
    		this.fill_btn.props = {side: 'left', align: 'top', wheel: true, palette: true, gradient: false, image: false, nocolor: true, offset: 20};
    		this.stroke_btn.props = {side: 'left', align: 'top', wheel: true, palette: true, gradient: false, image: false, nocolor: true, offset: 20};
    	}
    },
    ////////////////////////////////////////////////////////////////////
    //
    draw: {
    	enumerable: false,
    	value: function() {
    		//
    		this.application.ninja.colorController.addButton('chip', this.fill_btn);
            this.application.ninja.colorController.addButton('chip', this.stroke_btn);
            //
            this.fill_btn.color('rgb', {wasSetByCode: true, type: 'change', color: {r: 255, g: 255, b: 255}, css: 'rgb(255,255,255)'});
            this.stroke_btn.color('rgb', {wasSetByCode: true, type: 'change', color: {r: 0, g: 0, b: 0}, css: 'rgb(0,0,0)'});
    	}
    },
    ////////////////////////////////////////////////////////////////////
    //
    didDraw: {
    	enumerable: false,
    	value: function() {

    		this.fill_btn.addEventListener('change', function (e) {
                this.fill = e._event;
                this.fill.webGlColor = this.application.ninja.colorController.colorModel.colorToWebGl(e._event.color);
            	this.application.ninja.colorController.colorModel.input = 'fill';

                var color = e._event.color;
            	if (e._event.colorMode !== 'nocolor' && color) {
            		color.wasSetByCode = false;
	            	color.type = 'change';
	            	color.mode = e._event.colorMode;
            		this.application.ninja.colorController.colorModel[e._event.colorMode] = color;
            	} else {
            		this.application.ninja.colorController.colorModel.applyNoColor(false);
            	}
            	this.application.ninja.colorController.colorModel.input = 'chip';
       		}.bind(this));

            this.stroke_btn.addEventListener('change', function (e) {
            	this.stroke = e._event;
                this.stroke.webGlColor = this.application.ninja.colorController.colorModel.colorToWebGl(e._event.color);
            	this.application.ninja.colorController.colorModel.input = 'stroke';

            	var color = e._event.color;
            	if (e._event.colorMode !== 'nocolor' && color) {
            		color.wasSetByCode = false;
            		color.type = 'change';
                    color.mode = e._event.colorMode;
            		this.application.ninja.colorController.colorModel[e._event.colorMode] = color;
           		} else {
           			this.application.ninja.colorController.colorModel.applyNoColor(false);
           		}
            	this.application.ninja.colorController.colorModel.input = 'chip';
            }.bind(this));
    	}
    }
    ////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////
});
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////