Slider OnChange property **SOLVED**

Started by migrator, Tue 22/11/2016 22:32:21

Previous topic - Next topic

migrator

Hi! I'm wrote a custom save/load routine with screenshots. I use a slider to move it up and down but, now, I want to be able to use the mouse wheel too.

I wrote this little code to check the funcionality.

GUIControl *pgcOverGUIControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
   //If there's a GUI control
   if (pgcOverGUIControl != null){
      //Check if a Slider
      Slider *pslSlider = pgcOverGUIControl.AsSlider;
      if (pslSlider != null){
         //If a Slider, Check if the mousewheel was used.
         if (button == eMouseWheelSouth){
            pslSlider.Value --;
         } else if (button == eMouseWheelNorth){
            pslSlider.Value ++;
         }
      }
   }

Now the Slider changes with the mousewheel, but that change don't runs the OnChange event of the Slider.

What I have to do to make the OnChange event of the Slider will be launched?

Thanks

Crimson Wizard

#1
OnChange event is not triggered when you modify value in script, but you may call event handler yourself.
Since you get any slider from mouse position, you cannot call particular's slider handle right away, but firstly, you could use one handler for all sliders if that is convenient for you (since handler takes control pointer as parameter), or secondly, you may write a function that would choose what to do depending on which slider was modified, for example:
Code: ags

function OnAnySliderChange(Slider *pslSlider)
{
   // do something to any slider
   // or find out which slider's handler to call
   if (pslSlider == sldSomeSlider)
      sldSomeSlider_OnChange(pslSlider);
   else if (pslSlider == sldAnotherSlider)
      sldAnotherSlider_OnChange(pslSlider);
   // and so on
}


<...>
if (button == eMouseWheelSouth){
   pslSlider.Value --;
   OnAnySliderChange(pslSlider);
} else if (button == eMouseWheelNorth){
   pslSlider.Value ++;
   OnAnySliderChange(pslSlider);
}


migrator

Thanks Crimson Wizard, it works fine.

And, this way, it's possible to optimize all the Sliders changes in only one function.


SMF spam blocked by CleanTalk