This seems like something that should be easy enough to do, but I have been 
pulling my hair out and banging my head against the wall for ours trying to get 
it to work.

Imagine this, I want to have a matrix of input boxes that correspond to an 
array of double in my program. When the user enters data into the input box 
(Fl_Input) the callback function fires.

The callback function is where I'm stuck. Its entire purpose is to read the 
incoming value and store it to an array. Since my callback has to be static 
(right!?, is there a way to make a non-static callback function? another 
topic...) I pass a pointer to my UI object which contains the array that I want 
to update. So here is my code. Is seg faults on the callback.

Is it possible to do what I want?

Thanks.

//Create the UI objects
Fl_Input* m_afiltermatrix[9];
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++){   //FLT_WIDTH and height are 
integers that equal 3
   m_afiltermatrix[i]->user_data((void*)(this));
   m_afiltermatrix[i]->callback(updateFilterKernel);
   m_afiltermatrix[i]->value("0");
   m_afiltermatrix[i]->when(FL_WHEN_CHANGED);
}

//Callback function
//------------------------------------------------
// Update the filterKernal array with values in UI inputs
//------------------------------------------------
void ImpressionistUI::updateFilterKernel(Fl_Widget* o, void* v)
{
 //int fltsize = FLT_WIDTH*FLT_HEIGHT;
 Fl_Input** tmpfiltermatrix;
 double* tmpfilterkernel;
 ImpressionistUI* pUI=((ImpressionistUI *)(o->user_data()));
 tmpfilterkernel = ( pUI->filterKernel );     //the UI class references this 
and the arra on the next line
 tmpfiltermatrix = ( pUI->m_afiltermatrix );
 for(int i = 0; i < FLT_WIDTH*FLT_HEIGHT; i++){
   tmpfilterkernel[i] = atof( tmpfiltermatrix[i]->value() );  //SEG FAULT!!?
   //printf("%d -- %f\n\n", i, ((Fl_Input*)(pUI->fldivideby)) );
 }
 //((ImpressionistUI*)(o->user_data()))->filterKernel[i]
}

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to