Minor cleanup.
authorspixx <spixx>
Sun, 26 Nov 2006 14:26:34 +0000 (14:26 +0000)
committerspixx <spixx>
Sun, 26 Nov 2006 14:26:34 +0000 (14:26 +0000)
Handle close button events.

src/renderingsurface.cpp

index d01ffe6d02c89dec3567fb3326b39bc058b72bfc..b027e48430228acb7a23d1f3ba50d85e05187167 100644 (file)
@@ -39,7 +39,8 @@ FXDEFMAP(RenderingSurface) RenderingSurfaceMap[] =
     FXMAPFUNC(SEL_RIGHTBUTTONPRESS,    RenderingSurface::ID_CANVAS, RenderingSurface::onRightMouseDown),
     FXMAPFUNC(SEL_RIGHTBUTTONRELEASE,  RenderingSurface::ID_CANVAS, RenderingSurface::onRightMouseUp),
     FXMAPFUNC(SEL_MOTION,              RenderingSurface::ID_CANVAS, RenderingSurface::onMouseMove),
-    FXMAPFUNC(SEL_PAINT,               RenderingSurface::ID_CANVAS, RenderingSurface::onRepaint)
+    FXMAPFUNC(SEL_PAINT,               RenderingSurface::ID_CANVAS, RenderingSurface::onRepaint),
+    FXMAPFUNC(SEL_CLOSE,               0,                           RenderingSurface::onQuit)
 };
 
 // macro to set up class implementation
@@ -49,12 +50,11 @@ FXIMPLEMENT(RenderingSurface, FXMainWindow, RenderingSurfaceMap, ARRAYNUMBER(Ren
 
 /**
  * Constructor
- * @param application the FOX application object
- * @param lsystem the Lindenmayer-system
+ * @param application the application object
  */
-RenderingSurface::RenderingSurface(FXApp *application, LindenmayerSystem *lsystem) : FXMainWindow(application, "LSystem3D", NULL, NULL, DECOR_ALL, 100, 100, 800, 800)
+RenderingSurface::RenderingSurface(FXApp *application) : FXMainWindow(application, "LSystem3D", NULL, NULL, DECOR_ALL, 100, 100, 800, 800)
 {
-    _lsystem = lsystem;
+    _lsystem = NULL;
     
     _modelX =   0.0;
     _modelY =   0.0;
@@ -75,6 +75,16 @@ RenderingSurface::RenderingSurface(FXApp *application, LindenmayerSystem *lsyste
 
 
 
+/**
+ * Destructor
+ */
+RenderingSurface::~RenderingSurface()
+{
+    delete _visual;
+}
+
+
+
 /**
  * Create and initialize the window
  */
@@ -85,6 +95,7 @@ void RenderingSurface::create()
     
     // set up OpenGL
     _canvas->makeCurrent();
+    
     initOpenGL();
     
     // make the window appear
@@ -302,9 +313,35 @@ long RenderingSurface::onRepaint(FXObject *sender, FXSelector selector, void *da
     glRotatef(_modelRotationY, 0.0, 1.0, 0.0);
     
     // render model
-    _lsystem->getModel()->draw();
-        
+    _lsystem->render();
     
     // make it appear
     _canvas->swapBuffers();
 }
+
+
+
+/**
+ * Called by the system when the close button is pressed
+ * @param sender the sender object
+ * @param selector message type and id
+ * @param data event related data
+ * @return 
+ */
+long RenderingSurface::onQuit(FXObject *sender, FXSelector selector, void *data)
+{
+    getApp()->exit(0);
+    
+    return 1;
+}
+
+
+
+/**
+ * Set current L-system generator
+ * @param lsystem the L-system generator
+ */
+void RenderingSurface::setLSystem(LindenmayerSystem *lsystem)
+{
+    _lsystem = lsystem;
+}