Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Colouring buttons

Engaged ,
Dec 03, 2017 Dec 03, 2017

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?

TOPICS
Actions and scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
People's Champ ,
Dec 03, 2017 Dec 03, 2017

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*/ }

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 03, 2017 Dec 03, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Dec 03, 2017 Dec 03, 2017

About the error. Please show what you wrote. I have no errors..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 03, 2017 Dec 03, 2017

As you wrote.  ' state ' is undefined.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Dec 04, 2017 Dec 04, 2017
LATEST

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 03, 2017 Dec 03, 2017

For "scriptListener" read "EventListener".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines