On 03/06/13 09:47, Greg Ercolano wrote:

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

        I lied. Made one anyway; wanted to see it work.
        Implemented pretty much exactly as described..

------------------------------------------------------------------------------------
#include <string.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Slider.H>
#include <vector>

// Demonstrate how to connect volume knobs to each other by name - erco 1.0 
03/06/13

// CLASS TO HANDLE CONNECTING VOLUME KNOBS
class VolumeKnob : public Fl_Slider {
    static void Adjust_CB(Fl_Widget *w, void *data);
public:
    VolumeKnob(int X,int Y,int W,int H, const char *L=0);
    ~VolumeKnob();
};

static std::vector<VolumeKnob*> G_knobs;                // global array of all 
vol knob instances

// HANDLE VOLUME ADJUSTMENT
void VolumeKnob::Adjust_CB(Fl_Widget *w, void *data) {
    VolumeKnob *knob = (VolumeKnob*)data;
    printf("KNOB '%s' CHANGED: %.2f\n", knob->label(), knob->value());
    // Real work here: cause current knob's value to affect others
    for ( unsigned t=0; t<G_knobs.size(); t++ ) {                               
// walk all knobs created so far
        if ( knob == G_knobs[t] ) continue;                                     
// skip ourself
        if ( strcmp(G_knobs[t]->label(), knob->label()) != 0 ) continue;        
// skip knobs of different name
        G_knobs[t]->value(knob->value());                                       
// adjust other knob of same name
    }
}

// CTOR
VolumeKnob::VolumeKnob(int X,int Y,int W,int H, const char 
*L):Fl_Slider(X,Y,W,H,L) {
    type(FL_VERT_NICE_SLIDER);          // type of slider
    align(FL_ALIGN_BOTTOM);             // (labels on bottom)
    selection_color(FL_RED);            // nicer looking knob
    callback(Adjust_CB, (void*)this);   // setup callback
    G_knobs.push_back(this);            // save pointer to self
}

// DTOR
VolumeKnob::~VolumeKnob() {
    // Remove from our global array
    for ( unsigned t=0; t<G_knobs.size(); t++ ) {
        if ( G_knobs[t] == this ) {
            G_knobs.erase(G_knobs.begin()+t);   // stl, why u so fugly
            break;
        }
    }
}

int main(int argc, char* argv[]) {
    Fl::scheme("gtk+");
    Fl_Window *w1 = new Fl_Window(0,0,100,120,"Win #1");
    w1->begin();
      new VolumeKnob(10+0 ,10,20,80,"T1");
      new VolumeKnob(10+30,10,20,80,"T2");
      new VolumeKnob(10+60,10,20,80,"T3");
    w1->end();
    w1->show();

    Fl_Window *w2 = new Fl_Window(200,0,100,120,"Win #2");
    w2->begin();
      new VolumeKnob(10+0 ,10,20,80,"T1");
      new VolumeKnob(10+30,10,20,80,"T2");
      new VolumeKnob(10+60,10,20,80,"T3");
    w2->end();
    w2->show();

    return Fl::run();
}
------------------------------------------------------------------------------------
_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to