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
/**
* 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;
+/**
+ * Destructor
+ */
+RenderingSurface::~RenderingSurface()
+{
+ delete _visual;
+}
+
+
+
/**
* Create and initialize the window
*/
// set up OpenGL
_canvas->makeCurrent();
+
initOpenGL();
// make the window appear
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;
+}