Page 1 of 1

Set the thumbPosition in Windows

Posted: Thu Apr 21, 2011 10:01 am
by hutchfx
I have a project with two sliders (scrollBar buttons), where the combined value of the two can't exceed 100. I've put this in the script of each (with the proper button name of course):

Code: Select all

on mouseStillDown
   if ((the thumbPosition of me) + (the thumbPosition of scrollbar "minRandom")) ≥ 100 then
      set the thumbPosition of scrollBar "minRandom" to (99 - the thumbPosition of me)
   end if
end mouseStillDown
It works just fine on the Mac, but when I compile the project as an executable, and run it on a Windows machine, it does not change the thumb position of the the other slider.

Can someone confirm or deny that "set the thumbPosition" does not work in Windows?

Thanks!

Hutch

Re: Set the thumbPosition in Windows

Posted: Thu Apr 21, 2011 12:08 pm
by Klaus
Hi Hutch,

no idea why this should not work on Windows!?

But "mousestilldown" is not the most effective way (not to say a very inefficient way) to do what you want to!
Try the "scrollbardrag" message instead:

Code: Select all

on scrollbardrag tValue
   if (tValue + (the thumbPosition of scrollbar "minRandom")) ≥ 100 then
      set the thumbPosition of scrollBar "minRandom" to (99 - tValue)
   end if
end scrollbardrag
EDIT!
On the second look I see that you use the Mac-Only ≥ sign!
This does not work on Windows at all, since it does not get correctly translated to the Windows character encoding!
Use >= ( and <> and <=) for crossplatform compatibility!

Nevertheless try the "scrollbardrag" message instead, also on the Mac :D

Best

Klaus

Re: Set the thumbPosition in Windows

Posted: Thu Apr 21, 2011 2:12 pm
by bn
Hi Hutch and Klaus,

Klaus spotted the problem, bravo. He proposed to use scrollbarDrag instead of mouseStilldown. That is what I would also do. There is one caveat. When you set the thumbposition of a scrollbar you trigger a scrollBarDrag message which in the case of the two interdependent scrollbars backfires a possible scrollbarDrag message to the sender. If you lock messages this does not happen. In this specific case it is not a problem since it is leveled out and not noticed. In other cases it might be a source of unwanted effects.

To illustrate the point:

scrollbar "MinRandom"

Code: Select all

on scrollbardrag tValue
      if (tValue + (the thumbPosition of scrollbar "maxRandom")) >= 100 then
      --lock messages
      set the thumbPosition of scrollBar "maxRandom" to (99 - tValue) -- note the random here
      end if
end scrollbardrag
scrollbar "MaxRandom"

Code: Select all

on scrollbardrag tValue
      if (tValue + (the thumbPosition of scrollbar "minRandom")) >= 100 then
      --lock messages
      set the thumbPosition of scrollBar "minRandom" to random(100)
      end if
end scrollbardrag
Now drag scrollbar "MaxRandom", see what happens and then unblock the lock messages command in "maxRandom" and it works as expected.

Got me a couple of times that by setting a thumbposition the scrollbarDrag message is triggered.

in short: if you set the thumbposition of a scrollbar that has a "on scrollbarDrag" handler make shure you lock messages unless you specifically want the "on scrollbarDrag" handler to fire.

Kind regards

Bernd

Re: Set the thumbPosition in Windows

Posted: Sat Apr 23, 2011 8:27 pm
by hutchfx
Klaus,

Wow... good eye! Thanks for spotting the greater-than-or-equal-to problem. I changed that, and it works as it should.

Klaus and Bernd,

Thanks for the heads up on "scrollbarDrag". I had seen it in the dictionary, but "mouseUp" was working well enough so I hadn't changed it. I didn't realize that "mouseUp" would be less efficient. At your suggestion I edited my project. It appears that updates generated by scroll bar movement are smoother. :)

BTW... I've posted the project in the "driverNames in Windows" topic. It simply spits out serial commands to an Arduino board running the DmxSimple library to talk to DMX controlled fans.

Thanks!

Hutch