Finally got it working thanks to your help. Incredible. I can't thank you
enough. You example is exactly what I needed.
The seg fault issue turned out to be in this line
>>//Create the UI objects
>>Fl_Input* m_afiltermatrix[9];
since I also had this line in the .h file
Fl_Input* m_afiltermatrix[FLT_WIDTH*FLT_HEIGHT];
I guess something was getting wiped out here. Anyhow here is my working code
snippet:
//------------------------------------------------
// Update the filterKernal array with values in UI inputs
//------------------------------------------------
void ImpressionistUI::updateFilterKernel(Fl_Widget* o, void* v)
{
((ImpressionistUI *)(v))->updateFilterKernel_i();
}
//------------------------------------------------
// Update the filterKernal array with values in UI inputs
//------------------------------------------------
void ImpressionistUI::updateFilterKernel_i()
{
for(int i = 0; i < FLT_WIDTH*FLT_HEIGHT; i++){
filterKernel[i] = atof( m_afiltermatrix[i]->value() );
);
}
}
m_filterKernal = new Fl_Window(250, 250, "Filter Kernal");
m_filterKernal->user_data((void*)(this)); // record self to
be used by static callback functions
m_afiltermatrix[0] = new Fl_Input(40, 40, 50, 25, "");
m_afiltermatrix[1] = new Fl_Input(95, 40, 50, 25, "");
m_afiltermatrix[2] = new Fl_Input(150, 40, 50, 25, "");
m_afiltermatrix[3] = new Fl_Input(40, 70, 50, 25, "");
m_afiltermatrix[4] = new Fl_Input(95, 70, 50, 25, "");
m_afiltermatrix[5] = new Fl_Input(150, 70, 50, 25, "");
m_afiltermatrix[6] = new Fl_Input(40, 100, 50, 25, "");
m_afiltermatrix[7] = new Fl_Input(95, 100, 50, 25, "");
m_afiltermatrix[8] = new Fl_Input(150, 100, 50, 25, "");
for(int i = 0; i < FLT_WIDTH*FLT_HEIGHT; i++){
//m_afiltermatrix[i]->user_data((void*)(this));
m_afiltermatrix[i]->callback(updateFilterKernel,
(void*)this);
m_afiltermatrix[i]->value("0");
m_afiltermatrix[i]->when(FL_WHEN_CHANGED);
}
> I'd do it this way (below).
>
> Didn't try to debug your code, as problem might be elsewhere in code.
> In your callback, instead of using o->userdata(), use 'v', as that's
> your userdata in a simple form.
>
> To debug your segfaults, print the value of 'pUI' and tmpfiltermatrix[i]
> before atof() line, since one of them is probably NULL or wild.
>
> Yes your callback needs to be static, but as shown below, you can
> have static callback invoke non-static callback by dereferencing your UI*
> so that your non-static callback can then have free reign over your class.
>
> When you run the following, the Fl_Input's will show the data[] array's
> values,
> and when you make changes to any field, the data[] array is modified, and
> entire
> data array printed to stdout so that you can see it change.
>
> * * *
>
> #include <stdio.h>
> #include <FL/Fl.H>
> #include <FL/Fl_Window.H>
> #include <FL/Fl_Input.H>
> #include <FL/fl_message.H>
> //
> // Demonstrate using Fl_Input's to manage an array
> // erco 10/09/05
> //
> class MyUI : public Fl_Window {
> int data[10]; // integer data to be managed
> Fl_Input *in[10]; // array of Fl_Input widgets
>
> // Nonstatic callback
> void HandleInput() {
> for ( int i=0; i<10; i++ ) {
> if ( sscanf(in[i]->value(), "%d", &data[i]) != 1 ) { //
> assign input string to data array element
> fl_message("The string '%s' for input #%d is not an integer",
> in[i]->value(), i);
> }
> // Print modified data array to screen so we can see it
> printf("data[%d] is now %d\n", i, data[i]);
> }
> printf("---\n");
> }
>
> // Raw callback
> static void HandleInput_CB(Fl_Widget *w, void *v) {
> MyUI *ui = (MyUI*)v; // userdata is pointer to class
> ui->HandleInput(); // invoke non-static callback
> }
>
> public:
> // CONSTRUCTOR
> MyUI(int W,int H) : Fl_Window(W,H) {
> // initialize array, create input widgets and assign each an item in
> array
> char label[80];
> char val[80];
> for ( int i=0; i<10; i++ ) {
> data[i] = i * 100; // initialize
> data array to some values
> sprintf(val, "%d", data[i]); // string
> version of data value for Fl_Input
> sprintf(label, "Item %d:", i); // label of
> Fl_Input that includes index#
> in[i] = new Fl_Input(100,10+i*30,100,25); // create input
> widget, save
> in[i]->copy_label(label); // label it
> with item# for clarity
> in[i]->callback(HandleInput_CB, (void*)this); // assign
> callback too data element
> in[i]->value(val); // initialize
> input field to data[]'s value
> in[i]->when(FL_WHEN_CHANGED);
> }
> }
> };
> int main() {
> MyUI win(300, 500);
> win.show();
> return(Fl::run());
> }
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk