Main Page | Namespace List | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

Gui.cc

Go to the documentation of this file.
00001 /*
00002  * Gui class
00003  * by hackervalley@free.fr
00004  * http://hackervalley.free.fr
00005  * May 2004
00006  * this program is licensed under the GPL.
00007  */
00008 
00009 #include "Gui.hh"
00010 
00011 using namespace FE;
00012 using namespace std;
00013 
00014 // Constructor
00015 
00016 Gui::Gui ()
00017 {
00018 // initialize static windows
00019         mainWindow = NULL;
00020         mainMenuBar = NULL;
00021         glWindow = NULL;
00022         statusBar = NULL;
00023         geoBar = NULL;
00024         aboutWindow = NULL;
00025 
00026         width = 800;
00027         height = 600;
00028 
00029         // Set Fltk theme
00030         Fl::scheme ("plastic");
00031 
00032 }
00033 
00034 Gui::~Gui ()
00035 {
00036         delete mainWindow;
00037         delete mainMenuBar;
00038         delete glWindow;
00039         delete statusBar;
00040         delete geoBar;
00041         delete aboutWindow;
00042 }
00043 
00044 // Callbacks
00045 // File Menu
00046 void
00047 Gui::open_cb(Fl_Widget *w, void *data)
00048 {
00049         Gui *o = (Gui *) data;
00050         o->open_cb2(w, data);
00051 }
00052 
00053 void
00054 Gui::open_cb2(Fl_Widget *, void *)
00055 {
00056         char *openfile = NULL;
00057         openfile = fl_file_chooser("Open File","*.geo", "");
00058          if (openfile != NULL) { glWindow->engine->WorkFilename = openfile;}
00059          
00060          glWindow->engine->OpenFile(openfile);
00061 }
00062 
00063 void
00064 Gui::saveas_cb(Fl_Widget *w, void *data)
00065 {
00066         Gui *o = (Gui *) data;
00067         o->saveas_cb2(w, data);
00068 }
00069 
00070 void
00071 Gui::saveas_cb2(Fl_Widget *, void *)
00072 {
00073         char *savefile;
00074         savefile = NULL;
00075         savefile = fl_file_chooser("Save File As","*.geo", "");
00076          if (savefile != NULL) { glWindow->engine->WorkFilename = savefile;}
00077          
00078          glWindow->engine->SaveFile(savefile);
00079 }
00080 
00081 void
00082 Gui::file_quit_cb (Fl_Widget *, void *)
00083 {
00084         exit (0);
00085 }
00086 
00087 // Help Menu
00088 void
00089 Gui::help_about_cb (Fl_Widget * w, void *data)
00090 {
00091         Gui *o = (Gui *) data;
00092         o->help_about_cb2 (w, data);
00093 }
00094 
00095 void
00096 Gui::help_about_cb2 (Fl_Widget * w, void *)
00097 {
00098         create_about_window ();
00099 }
00100 
00101 // geoBar callback
00102 void
00103 Gui::create_Vertex_cb (Fl_Widget * w, void *data)
00104 {
00105         Gui *o = (Gui *) data;
00106         o->create_Vertex_cb2 ();
00107 }
00108 
00109 void
00110 Gui::create_Vertex_cb2 ()
00111 {
00112         glWindow->createvertex = true;
00113 }
00114 
00115 
00116 void
00117 Gui::create_main_window ()
00118 {
00119         if (mainWindow)
00120         {
00121                 mainWindow->show ();
00122                 return;
00123         }
00124 
00125         mainWindow = new Fl_Window (width, height, "FE");
00126 
00127         // Define resizable limits
00128         mainWindow->size_range (width, height, 0, 0, 0, 0, 0);
00129 
00130         mainWindow->begin ();
00131 
00132         // mainMenuBar
00133         mainMenuBar = new Fl_Menu_Bar (0, 0, mainWindow->w (), 30);
00134 
00135         Fl_Menu_Item menutable[] = {
00136                 {"&File", FL_ALT + 'f', 0, 0, FL_SUBMENU}
00137                 ,
00138                 {"&Open", FL_ALT + 'O', (Fl_Callback *)open_cb, (void *) this}
00139                 ,
00140                 {"&Save As", FL_ALT + 's', (Fl_Callback *)saveas_cb, (void *) this,  FL_MENU_DIVIDER}
00141                 ,
00142                 {"&Quit", FL_ALT + 'q', (Fl_Callback *) file_quit_cb, 0,
00143                  FL_MENU_DIVIDER}
00144                 ,
00145                 {0}
00146                 ,
00147                 {"&Help", FL_ALT + 'h', 0, 0, FL_SUBMENU}
00148                 ,
00149                 {"&About", FL_ALT + 'a', (Fl_Callback *) help_about_cb,
00150                  (void *) this},
00151                 {0},
00152                 {0}
00153         };
00154 
00155         mainMenuBar->copy (menutable);
00156 
00157         // statusBar
00158         statusBar =
00159                 new Fl_Group (mainWindow->x (), mainWindow->h () - 30,
00160                               mainWindow->w (), 30, "StatusBar");
00161 
00162         statusBar->begin ();
00163         Fl_Box *statusBox =
00164                 new Fl_Box (statusBar->x (), statusBar->y (), statusBar->w (),
00165                             statusBar->h (), NULL);
00166         statusBox->box (FL_DOWN_BOX);
00167         statusBox->align (FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
00168         statusBox->label ("Status Box");
00169         statusBar->end ();
00170 
00171         // geoBar
00172         geoBar = new Fl_Group (mainWindow->w () - 30, mainWindow->y () + 30,
00173                                30, mainWindow->h () - 60, NULL);
00174 
00175         geoBar->begin ();
00176 
00177         Fl_Box *geoBox =
00178                 new Fl_Box (geoBar->x (), geoBar->y (), 30, geoBar->h (),
00179                             NULL);
00180         geoBox->box (FL_DOWN_BOX);
00181         geoBox->align (FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
00182 
00183         Fl_Button *createVertex =
00184                 new Fl_Button (geoBox->x (), geoBox->y (), 30, 30, "Pt");
00185         createVertex->callback ((Fl_Callback *) create_Vertex_cb,
00186                                 (void *) this);
00187 
00188         // Create additional box for the group who consume resize
00189         Fl_Box *additionalBox =
00190                 new Fl_Box (geoBar->x (), geoBox->y () + 220, geoBar->w (),
00191                             60, NULL);
00192         geoBar->resizable (additionalBox);
00193 
00194         geoBar->end ();
00195 
00196         // glWindow
00197         glWindow = new OpenGLWindow (mainWindow->x (), mainWindow->y () + 30,
00198                                      mainWindow->w () - 30,
00199                                      mainWindow->h () - 60, "OpenGL Window");
00200 
00201         // Make resizable group
00202         mainWindow->add (glWindow);
00203         mainWindow->resizable (glWindow);
00204 
00205         mainWindow->end ();
00206 
00207         mainWindow->show ();
00208 
00209 }
00210 
00211 void
00212 Gui::OK_cb (Fl_Widget * w, void *data)
00213 {
00214         Fl_Window *o = (Fl_Window *) data;
00215         o->hide ();
00216 }
00217 
00218 void
00219 Gui::create_about_window ()
00220 {
00221         if (aboutWindow)
00222         {
00223                 aboutWindow->show ();
00224                 return;
00225         }
00226 
00227         aboutWindow = new Fl_Window (200, 200, "About FE");
00228 
00229         aboutWindow->begin ();
00230 
00231         Fl_Multiline_Output *AboutOutput;
00232         AboutOutput = new Fl_Multiline_Output (0, 0, 200, 170, "AboutOutput");
00233 
00234         AboutOutput->
00235                 value
00236                 ("\n Finite Element\n\n under GPL\n\n http://hackervalley.free.fr");
00237         AboutOutput->align (FL_ALIGN_CENTER);
00238 
00239         Fl_Return_Button *ReturnButton;
00240         ReturnButton = new Fl_Return_Button (70, 170, 60, 30, "OK");
00241 
00242         ReturnButton->callback ((Fl_Callback *) OK_cb,
00243                                 ReturnButton->parent ());
00244 
00245         aboutWindow->end ();
00246 
00247         aboutWindow->show ();
00248 }
00249 
00250 
00251 
00252 int
00253 Gui::run ()
00254 {
00255         return Fl::run ();
00256 }

Generated on Sat Aug 7 18:49:02 2004 for FE by doxygen 1.3.6-20040222