> No, Stan meant that you should make an array of Control*
>
> What he is doing here (which is probably not obvious to a C programmer!)
> is making a class "Slider" that derives from both "Fl_Slider" *and* from
> his new "Control" class - so, in principle, you can point to a "Slider"
> widget using any of "Slider", "Control" or "Fl_Slider" as the pointer
> type.
>
> Now, in his "Control" class, he's declared all the methods as virtual,
> so if you call any of those methods, the C++ runtime will search for the
> equivalent method in the *actual* class and execute that.
>
> So what you do is create a Slider class based on Fl_Slider and Control.
> A Dial class based on Fl_Dial and Control.
> A Button class based on Fl_Button and Control...
> Etc...
>
> Then, you make an array of Control* to hold them all, but when you call
>
> (Control*)->set_value(...);
>
> The code will seek out the *actual* class of the widget and call it's
> set_value method.
> Which is probably what you want to do.
Yes. I was adventures and just tried it yesterday with an container of Control*
and indeed i was able to call get_value and set_value on it. Thank you for
making it clearer to me why that works. :)
> By extension, you can probably put a widget ID mechanism in via the
> Control base class to track your widgets, if you need that over and
> above the array index.
Yeah, I did that too :)
class Control
{
public:
virtual void set_value(int) = 0;
virtual int get_value() const = 0;
static void cb(Control*, void*); // callback gets id
};
extern Control* control[]; // control container
class Slider : public Fl_Slider, public Control
{
public:
Slider(int x, int y, int w, int h, char const* label = 0)
: Fl_Slider(x, y, w, h, label)
{
;
}
void id(int v) // id handling
{
callback((Fl_Callback*)cb, (void*)v); // callback gets id
control[v] = this; // reference in control container
}
void set_value(int v)
{
Fl::lock();
value(v);
redraw();
Fl::awake();
Fl::unlock();
}
int get_value() const
{
return (int)value();
}
};
In FLUID i can now just use my Slider class (and others) and add o->id(131); as
extra code. Then in my main UI class i just do eg
mainWindow->begin();
mgrp = new mainGrp(0, 0, 430, 200, NULL);
mainWindow->end();
channelWindow->begin();
... and so on
where mainGrp is some Group with Sliders etc, nicely arranged in FLUID.
Works very well, until now. :)
Jan
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk