Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

Colouring buttons

$
0
0

Via a button I n a dialog box, I invoke the colorPicker.  I want to have the button background recoloured to match the selected colour (a la the foreground/background colours tool icon in PS).

 

Over on the InDesign Scipting forum there is a very old threat (C2009, IRRC) about colouring buttons (background and text).  Dirk Beker posted the following code:

 

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 dlg = new Window('dialog', 'Test');

var pnl = dlg.add('panel', undefined, 'My Panel');

var btn = pnl.add('button', undefined, 'My Button', {name:'ok'});

var btn2 = pnl.add('iconbutton', undefined, undefined, {name:'orange', style: 'toolbutton'});

btn2.size = [200,20];

btn2.fillBrush = btn2.graphics.newBrush( btn2.graphics.BrushType.SOLID_COLOR, [1, 0.7, 0, 0.5] );

btn2.text = "Hello, Harbs";

btn2.textPen = btn2.graphics.newPen (btn2.graphics.PenType.SOLID_COLOR,[0,0.5,0,1], 1);

btn2.onDraw = customDraw;

dlg.show();

 

This seems to work in PS CC2019 (under Win10 and High Sierra) but sometimes the background colour isn't updated and sometimes there is a (variable) delay before the colour changes.  I can (almost) live with that.

 

What puzzles me is why ' customDraw() ' appears to be invoked on mouseover - every time.  There is no scriptListener running, and nothing set anywhere - that I can determine - which might explain this behaviour.

 

Any thoughts, please?


Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>