From 830b011d94d728882286d72e129f7405134957c7 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 1 Feb 2012 17:05:07 -0800 Subject: Updated color code in the PI to go through element mediator. Signed-off-by: Nivesh Rajbhandari --- js/models/color-model.js | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'js/models/color-model.js') diff --git a/js/models/color-model.js b/js/models/color-model.js index b06281f8..2c86422f 100644 --- a/js/models/color-model.js +++ b/js/models/color-model.js @@ -562,7 +562,44 @@ exports.ColorModel = Montage.create(Component, { //Returning RGB object return {r: Math.round(r * 255), g: Math.round(g * 255), b: Math.round(b * 255)}; } - } + }, + //////////////////////////////////////////////////////////////////// + //Returns WebGL color array in [r, g, b, a] format where the values are [0,1] given a color object + colorToWebGl: { + enumerable: true, + value: function (color) { + var temp; + if (color) { + if(color.l !== undefined) { + temp = this.hslToRgb(color.h/360, color.s/100, color.l/100); + } else if (color.r !== undefined) { + temp = color; + } + temp.a = color.a; + } + //WebGL uses array + if (temp) { + return [temp.r/255, temp.g/255, temp.b/255, temp.a]; + } else { + return null; + } + } + }, + //////////////////////////////////////////////////////////////////// + //Returns CSS string given a WebGL color array in [r, g, b, a] format where the values are [0,1] + webGlToCss: { + enumerable: true, + value: function (color) { + if(color && (color.length === 4)) + { + return 'rgba(' + color[0]*255 + ', ' + color[1]*255 + ', ' + color[2]*255 + ', ' + color[3] +')'; + } + else + { + return null; + } + } + } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// -- cgit v1.2.3