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

OpenGLWindow.cc

Go to the documentation of this file.
00001 /*
00002  * OpenGLWindow 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 "OpenGLWindow.hh"
00010 
00011 #include <iostream>
00012 
00013 using namespace FE;
00014 using namespace std;
00015 
00016 OpenGLWindow::~OpenGLWindow()
00017 {
00018         delete engine;  
00019 }
00020 
00021 void
00022 OpenGLWindow::draw ()
00023 {
00024 // the valid() property may be used to avoid reinitializing your
00025 // GL transformation for each redraw:
00026         if (!valid ())
00027         {
00028                 glMatrixMode (GL_PROJECTION);
00029                 glLoadIdentity ();
00030                 glViewport (0, 0, w (), h ());
00031                 glFrustum (-1, 1, -1, 1, -2, 100);
00032 
00033                 glMatrixMode (GL_MODELVIEW);
00034                 glLoadIdentity ();
00035                 gluLookAt (0.0, 0.0, 8.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
00036 
00037                 glColor3f (1.0, 1.0, 1.0);
00038                 glPointSize (3.0);
00039                 
00040         }
00041 
00042         glMatrixMode (GL_MODELVIEW);
00043         glLoadIdentity ();
00044 
00045         glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00046 
00047         glPushMatrix ();
00048 
00049         // Display Opengl informations
00050         engine->draw ();
00051         
00052         // Display select rectangle
00053         if ( engine->StateDrawRectangle == true) engine->drawRectangle (engine->x0, engine->y0, engine->x1 , engine->y1);
00054                 
00055         // Display Move Line
00056         if (engine->StateMove == true ) engine->DrawMoveLine(engine->x0, engine->y0, engine->x1 , engine->y1);
00057 
00058         glPopMatrix ();
00059 }
00060 
00061 
00062 int
00063 OpenGLWindow::handle (int event)
00064 {
00065         int x = Fl::event_x (), y = Fl::event_y ();
00066 
00067         switch (event)
00068         {
00069                         
00070         case FL_MOVE:
00071                 cout << "X: " << x << " Y: " << y << endl;
00072                 return(1);
00073                 break;
00074 
00075         case FL_PUSH:
00076                         // Left Mouse Button
00077                 if (Fl::event_button () == 1)
00078                 {
00079                 /* rectangle selection */
00080                 /* Assign corner of rectangle selection */
00081                 engine->x0 = x;
00082                 engine->y0 = y;
00083                 engine->x1 = x;
00084                 engine->y1 = y;
00085                 engine->StateDrawRectangle = true;
00086                 if ( valid() )  redraw ();
00087                                         
00088                 if (createvertex == true)
00089                         {
00090                                 engine->createvertex (x, y);
00091                                 createvertex = false;
00092                                 if ( valid() )  redraw ();
00093                         }
00094 
00095                         else
00096                         {
00097                                 engine->selectvertex (x, y);
00098                                 if ( valid() )  redraw ();
00099                         }
00100                         
00101                 }
00102                 
00103                         // Right Mouse Button
00104                 if (Fl::event_button () == 3)
00105                 {
00106                         /* Move */
00107                 engine->x0 = x;
00108                 engine->y0 = y;
00109                 engine->x1 = x;
00110                 engine->y1 = y;
00111                 engine->StateMove = true;
00112                 if ( valid() )  redraw ();
00113                 }
00114                 
00115                 return(1);
00116                 break;
00117                 
00118         case FL_DRAG:
00119                 // Left Mouse Button
00120                 if (Fl::event_button () == 1)
00121                 {
00122                 /* Assign second corner of rectangle selection */
00123                 engine->x1 = x; 
00124                 engine->y1 = y;
00125                 
00126                 if ( valid() )  redraw ();
00127                 }
00128                 
00129                 // Right Mouse Button
00130                 if (Fl::event_button () == 3)
00131                 {
00132                 /* Move */
00133                 engine->x1 = x; 
00134                 engine->y1 = y;
00135                 
00136                 if ( valid() )  redraw ();
00137                 }
00138                 
00139                 return(1);
00140                 break;
00141                 
00142         case FL_RELEASE:
00143                 // Left Mouse Button
00144                 if (Fl::event_button () == 1)
00145                 {
00146                         engine->StateDrawRectangle = false;
00147                         engine->RectangleSelectVertex (engine->x0, engine->y0, engine->x1 , engine->y1);
00148                         if ( valid() )  redraw ();
00149                 }
00150                 
00151                 // Right Mouse Button
00152                 if (Fl::event_button () == 3)
00153                 {
00154                         engine->StateMove = false;
00155                         engine->MoveSelected (engine->x0, engine->y0, engine->x1 , engine->y1);
00156                         if ( valid() )  redraw ();
00157                 }
00158                 
00159                 return(1);
00160                 break;
00161 
00162         // To handle keyboard we return(1) 
00163         case FL_FOCUS:
00164         case FL_UNFOCUS:
00165                 return(1);
00166                                 
00167         case FL_KEYUP:
00168                 switch (Fl::event_key ())
00169                 {
00170                 case FL_Delete:
00171                         cout << "Delete " << endl;
00172                         engine->DeleteSelectVertex();
00173                         if ( valid() )  redraw ();
00174                         }
00175                 return(1);
00176                 break;
00177         /*                      
00178         default:
00179                 if ( valid() )  redraw ();
00180         */
00181         }
00182         return(Fl_Gl_Window::handle (event));
00183 
00184 }

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