|
| 1 | +/* ************************************************************************ |
| 2 | +
|
| 3 | + qooxdoo - the new era of web development |
| 4 | +
|
| 5 | + http://qooxdoo.org |
| 6 | +
|
| 7 | + Copyright: |
| 8 | + 2020 Oetiker+Partner AG |
| 9 | +
|
| 10 | + License: |
| 11 | + MIT: https://opensource.org/licenses/MIT |
| 12 | + See the LICENSE file in the project's top-level directory for details. |
| 13 | +
|
| 14 | + Authors: |
| 15 | + * Tobi Oetiker <[email protected]> |
| 16 | + |
| 17 | +************************************************************************ */ |
| 18 | + |
| 19 | +qx.Class.define("qxl.demobrowser.demo.ui.ColorUtil", { |
| 20 | + extend: qx.application.Standalone, |
| 21 | + |
| 22 | + members: { |
| 23 | + main: function () { |
| 24 | + this.base(arguments); |
| 25 | + var gridLayout = new qx.ui.layout.Grid(10, 10); |
| 26 | + var c = this.grid = new qx.ui.container.Composite(gridLayout); |
| 27 | + var scroller = new qx.ui.container.Scroll(); |
| 28 | + scroller.add(c); |
| 29 | + var selector = new qx.ui.control.ColorSelector(); |
| 30 | + selector.addListener('changeValue',function(e){ |
| 31 | + this.baseRGB = e.getData(); |
| 32 | + this.updateSwat('scale'); |
| 33 | + this.updateSwat('adjust'); |
| 34 | + },this); |
| 35 | + c.add(selector, { row: 0, column: 0, colSpan: 6 }); |
| 36 | + this.map = { |
| 37 | + adjust: {}, |
| 38 | + scale: {} |
| 39 | + }; |
| 40 | + var row = 1; |
| 41 | + [ |
| 42 | + ['red',255], |
| 43 | + ['green',255], |
| 44 | + ['blue',255], |
| 45 | + ['hue',360], |
| 46 | + ['saturation',100], |
| 47 | + ['brightness',100], |
| 48 | + ['lightness',100], |
| 49 | + ['alpha',1], |
| 50 | + ].forEach(function(prop){ |
| 51 | + this.addSlider('adjust',prop[0],prop[1],0,row); |
| 52 | + if (prop[0] != 'hue') { |
| 53 | + this.addSlider('scale',prop[0],100,3,row); |
| 54 | + } |
| 55 | + row++; |
| 56 | + },this); |
| 57 | + |
| 58 | + this.swat = { |
| 59 | + adjust: new qx.ui.basic.Atom("qx.util.ColorUtil.adjust").set({ |
| 60 | + minHeight: 200, |
| 61 | + minWidth: 200 |
| 62 | + }), |
| 63 | + scale: new qx.ui.basic.Atom("qx.util.ColorUtil.scale").set({ |
| 64 | + minHeight: 200, |
| 65 | + minWidth: 200 |
| 66 | + }) |
| 67 | + }; |
| 68 | + c.add(this.swat.adjust,{row: row,column:0, colSpan: 3}); |
| 69 | + c.add(this.swat.scale,{row: row,column:3, colSpan: 3}); |
| 70 | + selector.set({ |
| 71 | + red: 50, |
| 72 | + green: 128, |
| 73 | + blue: 15 |
| 74 | + }); |
| 75 | + this.getRoot().add(scroller, { edge: 30 }); |
| 76 | + }, |
| 77 | + grid: null, |
| 78 | + map: null, |
| 79 | + swat: null, |
| 80 | + baseRGB: null, |
| 81 | + addSlider: function(type,key,range,offset,row) { |
| 82 | + this.grid.add(new qx.ui.basic.Label(key),{ |
| 83 | + row: row, column: offset}); |
| 84 | + var value = new qx.ui.basic.Label().set({ |
| 85 | + minWidth: 30 |
| 86 | + }); |
| 87 | + this.grid.add(value,{ |
| 88 | + row: row, column: offset+2}); |
| 89 | + |
| 90 | + var slider = new qx.ui.form.Slider().set({ |
| 91 | + minimum: -range, |
| 92 | + maximum: range, |
| 93 | + minWidth: 200 |
| 94 | + }); |
| 95 | + this.grid.add(slider,{ |
| 96 | + row: row, column:offset+1 |
| 97 | + }); |
| 98 | + slider.bind("value",value,"value"); |
| 99 | + slider.addListener('changeValue',function(e){ |
| 100 | + this.map[type][key] = e.getData(); |
| 101 | + this.updateSwat(type); |
| 102 | + },this); |
| 103 | + }, |
| 104 | + updateSwat: function(type) { |
| 105 | + this.swat[type].setBackgroundColor( |
| 106 | + qx.util.ColorUtil[type](this.baseRGB,this.map[type]) |
| 107 | + ); |
| 108 | + } |
| 109 | + } |
| 110 | +}); |
0 commit comments