Let me show you why the Adjuster demo didn't work. See
the callback at the bottom.
See if you can figure out why casting the thing to a Box*
showed the Box's name being the hex value of it's X dimension.
That is if you got that far. ;-) Enjoy!!
---------------- adjuster.cxx
*#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/Adjuster.h>
#include <fltk/Button.h>
#include <stdlib.h>
#include <stdio.h>
fltk::Adjuster* a1;
fltk::Adjuster* a2;
fltk::Group* b1; // a no-click button
fltk::Group* b2; // a no-click button
void adjcb(fltk::Adjuster* a, void* v);
int main(int argc, char** argv)
{
fltk::Window* w;
w = new fltk::Window(325, 105, "fltk::Adjuster");
w->begin();
{
// We'll play with two adjusters and two widgets to
// show the values.
char buf1[32] = {0};
char buf2[32] = {0};
a1 = new fltk::Adjuster(90, 32, 67, 25);
a1->callback((fltk::Callback*)adjcb, (void*)(&b1));
fltk::Adjuster* a2 = new fltk::Adjuster(280, 10, 24, 75);
a2->set_vertical();
a2->callback((fltk::Callback*)adjcb, (void*)(&b2));
// we will use a group as a label display but we'll give
// it a read/write buffer we can update with Adjuster
// outputs. Basically it's a button that doesn't 'click'.
b1 = new fltk::Group(20, 32, 70, 25, buf1);
// and by the time we're done decorating it, you'd never
// know it was just a Group. :-)
b1->box(fltk::DOWN_BOX);
b1->color((fltk::Color)0xffffff00);
b1->align(fltk::ALIGN_INSIDE);
// and another one.
b2 = new fltk::Group(208, 32, 70, 25, buf2);
b2->box(fltk::DOWN_BOX);
b2->color((fltk::Color)0xffffff00);
b2->align(fltk::ALIGN_INSIDE);
}
w->end();
w->show();
fltk::run();
return 0;
}
// Here's the callback
void adjcb(fltk::Adjuster* a, void* v)
{
// Cast the group pointer to a button so we can write to
// the label. Both descend from Widget, that is their
// structs 'look' similar, so we can use button's
// features on the common struct fields.
fltk::Button* b = *(fltk::Button**)v;
// we made sure to put writable memory in the group label
// so we can write to it.
char* text = (char*)b->label();
// let the adjuster format its own output into the buffer
a->format(text);
// and re-assign the rext to the group's label.
b->label(text);
// and be sure the new text appears in the next flush.
b->redraw();
fltk::flush();
}
----------------
*
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs