On 03/06/13 09:08, Doug Parks wrote:
> I guess your idea of multiple sliders that are slaved together
> would be the best example.  When I say pages I mean different windows.
> What I have are three different windows that are able to control
> the same volume level.  I am trying to get the sliders to be able
> to affect on another so that if I change the slider on the first
> window it is reflected on the other two windows and if it changes
> on any window the impact is shown on the other two.

        Yep, common situation.

        What I would do is derive a VolumeKnob class that lets you
        assign a 'unique name' to it, eg. "Track 1".

        Have its constructor maintain a static array of pointers
        to instances of itself, and configure the widget's callback
        so that whenever the volume is adjusted, it walks the internal
        static array, and changes the value() of all VolumeKnob instances
        that have that same name. (Avoid changing the value of the instance
        that invoked the callback)

        So if you make three instances of VolumeKnob called "Track 1",
        and three other instances called "Track 2", an adjustment to any
        one of the "Track 1" volume knobs adjusts the others with that same
        name only.

        Then you can just instance the VolumeKnob all over the place,
        and the name is what connects them.

        It won't matter if the widgets are in the same window or different 
windows.

        I could make an example, but thinking the above might get you in
        the right direction.


PS. You can avoid recursion in the callback a number of ways:

        o By checking the pointers in the array against the widget
          that invoked the callback to make sure you don't change it

        o Don't change the volume's value if it's already at the
          correct value

        o Use a recursion flag; set the flag in the callback, and
          then when setting the value of each matching widget in the
          array, don't change the value if that widget's flag is set.
_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to