Hi everybody,

I'm trying to use fltk within a mex file of matlab. Here you can use
normal c++ in matlab. In stead of of a "int main()" function you of to
define a "void mexFunction(....)". Because of the void, I can't call
"return Fl::run();" at the end. In stead of this I wrote just
"Fl::run(); return;".

The problem with this is, that after returning (to matlab!) my window is
not closed. Does anybody know what could be the problem? How can I
destroy all windows, widgets manually?

My code:

#include <iostream>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Output.H>
#include <math.h>
#include "mex.h"

class SimpleWindow : public Fl_Window{
 
public:
  SimpleWindow(int w, int h, const char* title );
  virtual ~SimpleWindow();
  Fl_Button* calculate;
  Fl_Button* quit;
  Fl_Output* result;
  
private:
  static void cb_calculate(Fl_Widget*, void*);
  inline void cb_calculate_i();
 
  static void cb_quit(Fl_Widget*, void*);
  inline void cb_quit_i();
};



  void mexFunction( int nlhs, mxArray *plhs[],
                int nrhs, const mxArray *prhs[] ){

   SimpleWindow win(300,200,"SimpleWindow");
  
   Fl::run();
   return;

  }




//----------------------------------------------------

SimpleWindow::SimpleWindow(int w, int h, const char*
title):Fl_Window(w,h,title){
  
   begin();
      calculate = new Fl_Button( 10, 150, 70, 30, "C&alculate");
      calculate->callback( cb_calculate, this );
   
      quit = new Fl_Button(100, 150, 70, 30, "&Quit");
      quit->callback(cb_quit, this);
 
      result = new Fl_Output(50, 100, 140, 30, "Result:");
   end();
   resizable(this);
   show();
}

//----------------------------------------------------

SimpleWindow::~SimpleWindow(){
  mexPrintf("SimpleWindow::~SimpleWindow()\n");
  //  Fl_Window::~Fl_Window();
}

//----------------------------------------------------

void SimpleWindow::cb_calculate(Fl_Widget* o, void* v) {
 
   SimpleWindow* T=(SimpleWindow*)v;
   T->cb_calculate_i();
  
   // or just the one line below
  //( (SimpleWindow*)v )->cb_copy_i();
}


void SimpleWindow::cb_calculate_i() {

   result->value("test");
}

//----------------------------------------------------

void SimpleWindow::cb_quit(Fl_Widget* , void* v) {

   ( (SimpleWindow*)v )->cb_quit_i();
}


void SimpleWindow::cb_quit_i() {

  hide();

}

//----------------------------------------------------



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

Reply via email to