ExtendScript demonstrates simple ScriptUI Color Picker creation…
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 |
// Simple Color Picker SCRIPTUI // Script by Mehmet Sensoy function colorpicker (result_color) { var hexToRGB = function(hex) { var r = hex >> 16;var g = hex >> 8 & 0xFF;var b = hex & 0xFF; return [r, g, b]; }; var color_decimal = $.colorPicker(); $.writeln(color_decimal); var color_hexadecimal = color_decimal.toString(16); $.writeln(color_hexadecimal); var color_rgb = hexToRGB(parseInt(color_hexadecimal, 16)); $.writeln(color_rgb); var result_color = [color_rgb[0] / 255, color_rgb[1] / 255, color_rgb[2] / 255]; $.writeln(result_color); return result_color; return color_rgb; } function customDraw() { with( this ) { graphics.drawOSControl(); graphics.rectPath(0,0,size[0],size[1]); graphics.fillPath(fillBrush); if( text ) graphics.drawString(text,textPen,(size[0]-graphics.measureString (text,graphics.font,size[0])[0])/2,3,graphics.font); }} var w = new Window ("dialog"); var pnl =w.add('panel', undefined, 'Color Options'); var colorbutton1 = pnl.add('iconbutton', undefined, undefined, {name:'coloroption1', style: 'toolbutton'}); colorbutton1.size = [200,20]; colorbutton1.fillBrush = colorbutton1.graphics.newBrush( colorbutton1.graphics.BrushType.SOLID_COLOR, [0.5, 0.5, 0.5, 1] ); colorbutton1.text = "First Color"; colorbutton1.textPen = colorbutton1.graphics.newPen (colorbutton1.graphics.PenType.SOLID_COLOR,[1,1,1], 1); colorbutton1.onDraw = customDraw; var colorbutton2 = pnl.add('iconbutton', undefined, undefined, {name:'coloroption1', style: 'toolbutton'}); colorbutton2.size = [200,20]; colorbutton2.fillBrush = colorbutton2.graphics.newBrush( colorbutton2.graphics.BrushType.SOLID_COLOR, [0.5, 0.5, 0.5, 1] ); colorbutton2.text = "Second Color"; colorbutton2.textPen = colorbutton2.graphics.newPen (colorbutton2.graphics.PenType.SOLID_COLOR,[1,1,1], 1); colorbutton2.onDraw = customDraw; // ******************* COLOR BUTTONS ******************/// colorbutton1.onClick = function () { var newcolor1 = colorpicker (); colorbutton1.fillBrush = colorbutton1.graphics.newBrush( colorbutton1.graphics.BrushType.SOLID_COLOR,newcolor1); app.refresh(); colorbutton1.onDraw = customDraw; } colorbutton2.onClick = function () { var newcolor2 = colorpicker (); colorbutton2.fillBrush = colorbutton2.graphics.newBrush( colorbutton2.graphics.BrushType.SOLID_COLOR,newcolor2); app.refresh(); colorbutton2.onDraw = customDraw; } w.center(); w.show (); |
Leave a Reply
Want to join the discussion?Feel free to contribute!