Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
The problem and what you want is not quite clear for me .
Have you tried to do the function this way?
function customDraw(state)
{
if (!state.mouseOver) { /*do this*/ }
else { /*do that*/ }
}
Copy link to clipboard
Copied
The "problem" is that I don't understand why customDraw is invoked on mouseover.
what I want is to understand why.
Unfortunately, your code errors immediately on the 'if' statement.
Copy link to clipboard
Copied
About the error. Please show what you wrote. I have no errors..
Copy link to clipboard
Copied
As you wrote. ' state ' is undefined.
Copy link to clipboard
Copied
This is very strange. I have everything on the CS6 and CC2018 OK.
When I say "show what you wrote," I meant the entire text of the script, because bugs may be typed.
A couple of questions.
What OS version and photoshop?
Did you specify "state" as the first argument to the customDraw function?
Copy link to clipboard
Copied
For "scriptListener" read "EventListener".
Find more inspiration, events, and resources on the new Adobe Community
Explore Now