5 Replies Latest reply on Sep 4, 2016 8:42 PM by ling54k

    slider can not drag to preview

    ling54k Level 1

      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 ); 

          }

       

        • 1. Re: slider can not drag to preview
          JJMack Most Valuable Participant

          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.

          • 2. Re: slider can not drag to preview
            ling54k Level 1

            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".

            • 3. Re: slider can not drag to preview
              JJMack Most Valuable Participant

              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.

              • 4. Re: slider can not drag to preview
                DBarranca Level 4

                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

                • 5. Re: slider can not drag to preview
                  ling54k Level 1

                  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!