Skip to main content
raxby
Inspiring
August 30, 2016
Answered

slider can not drag to preview

  • August 30, 2016
  • 3 replies
  • 1859 views

When this script run,i cant preview the effect by dragging the slider,just click the slider can work.

Thanks for helping me!

var box = new Window('dialog', "blur");  

box.panel = box.add('panel', undefined, "Gaussian Blur"); 

box.panel.group = box.panel.add('group', undefined ); 

box.panel.group.orientation='row'; 

box.panel.group.text1 = box.panel.group.add('statictext', undefined, "radius:"); 

var slider = box.panel.group.add("slider",undefined, 9, 0, 255);

var value = box.panel.group.add('edittext', undefined, "9"); 

box.panel.group2 = box.panel.add('group', undefined ); 

box.panel.group2.orientation='row'; 

box.panel.group2.okBtn = box.panel.group2.add('button',undefined, "ok", {name:'ok'});

box.panel.group2.closeBtn = box.panel.group2.add('button',undefined, "cancel", {name:'cancel'}); 

slider.onChanging = function () {

value.text = slider.value;

var r = value.text;

blur(r);

app.refresh();

  }

value.onChanging = function () {

slider.value = value.text;

var r = slider.value;

blur(r);

app.refresh();

    }

box.panel.group2.okBtn.onClick = function(){ 

  slider.onChanging(); 

  box.close();

}

box.panel.group2.closeBtn.onClick = function(){

  box.close(); 

box.center();

box.show()

function  blur(r){ 

var idGsnB = charIDToTypeID( "GsnB" );

    var desc14 = new ActionDescriptor();

    var idRds = charIDToTypeID( "Rds " );

    var idPxl = charIDToTypeID( "#Pxl" );

    desc14.putUnitDouble( idRds, idPxl, r );

executeAction( idGsnB, desc14, DialogModes.NO ); 

    }

This topic has been closed for replies.
Correct answer DBarranca

Couple of problems here.

1. you should differentiate onChange and onChanging in the sliders callbacks:

slider.onChange = function() {

    blur(slider.value);

    app.refresh();

}

slider.onChanging = function() {

    value.text = slider.value;

}

When dragging the slider, only the text value needs to be updated, while on slider release (i.e. onChange) the blur is eventually applied.

2. You're stacking blur rounds – i.e. if you drag to 50 then drag back to 20, you're applying a 50px blur, then a 20px blur on top of it! You need to save the history state and get back to it before applying any subsequent blur.

Hope this helps,

Davide Barranca

---

htrmlpanelsbook.com

3 replies

raxby
raxbyAuthor
Inspiring
September 5, 2016

yes,it's right,i found it in scriptUI.The "onChange" callback after the position of the indicator is changed.But thank you all the same!

DBarranca
DBarrancaCorrect answer
Legend
September 1, 2016

Couple of problems here.

1. you should differentiate onChange and onChanging in the sliders callbacks:

slider.onChange = function() {

    blur(slider.value);

    app.refresh();

}

slider.onChanging = function() {

    value.text = slider.value;

}

When dragging the slider, only the text value needs to be updated, while on slider release (i.e. onChange) the blur is eventually applied.

2. You're stacking blur rounds – i.e. if you drag to 50 then drag back to 20, you're applying a 50px blur, then a 20px blur on top of it! You need to save the history state and get back to it before applying any subsequent blur.

Hope this helps,

Davide Barranca

---

htrmlpanelsbook.com

JJMack
Community Expert
Community Expert
August 30, 2016

You may be able to do what you want if  you back up in history to before applying the blur then applying the new blur setting. Perhaps create a snapshot and blur the snapshot. You would be better off creating a smart object layer and add a smart gaussian blur filter the user can adjust IMO. Or add the gaussian blur as an interactive step turn on the dialog.

JJMack
raxby
raxbyAuthor
Inspiring
August 31, 2016

Thank you for your reply.But i am confused is  why the slider coundn't be drag and move ,when i add "app.refresh()" in "Slider.onChanging".

JJMack
Community Expert
Community Expert
August 31, 2016

I did not look at that I do not know ScriptUI. I do know if you keep on blurring a layer or selection it will just keep getting blurrier and blurrier you will see no preview just the after blur effect. Most likely the delay app.refresh() imposes prevents scriptUI from being responsive with on change. It is being interlocked by the wait app.refresh(); does.

JJMack