initial version
[lsystem3d.git] / src / renderingsurface.h
diff --git a/src/renderingsurface.h b/src/renderingsurface.h
new file mode 100644 (file)
index 0000000..d6e8f16
--- /dev/null
@@ -0,0 +1,173 @@
+// Copyright (C) 2006 Erik Dahlberg
+// 
+// This file is part of LSystem3d.
+// 
+// LSystem3D is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+// 
+// LSystem3D is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with LSystem3D; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+
+
+
+#ifndef RENDERINGSURFACE_H
+#define RENDERINGSURFACE_H
+
+#include "fx.h"
+#include "fx3d.h"
+
+#include "lindenmayersystem.h"
+
+
+
+/**
+ * The OpenGL rendering surface
+ */
+class RenderingSurface : public FXMainWindow
+{
+    // macro to set up class declaration
+    FXDECLARE(RenderingSurface)
+    
+public:
+
+    // message ID's
+    enum
+    {
+        ID_CANVAS = FXMainWindow::ID_LAST,
+        ID_LAST
+    };
+
+    /**
+     * Constructor
+     * @param application the FOX application object
+     * @param lsystem the Lindenmayer-system
+     */
+    RenderingSurface(FXApp *application, LindenmayerSystem *lsystem);
+
+    /**
+     * Create and initialize the window
+     */
+    void create();
+    
+    /**
+     * Initialize OpenGL
+     */
+    void initOpenGL();
+    
+    /**
+     * Force an update of the rendering surface
+     */
+    void draw();
+    
+    /**
+     * Called by the system when the left mouse button is pressed
+     * @param sender the sender object
+     * @param selector message type and id
+     * @param data event related data
+     * @return 
+     */
+    long onLeftMouseDown(FXObject *sender, FXSelector selector, void *data);
+    
+    /**
+     * Called by the system when the left mouse button is released
+     * @param sender the sender object
+     * @param selector message type and id
+     * @param data event related data
+     * @return 
+     */
+    long onLeftMouseUp(FXObject *sender, FXSelector selector, void *data);
+    
+    /**
+     * Called by the system when the middle mouse button is pressed
+     * @param sender the sender object
+     * @param selector message type and id
+     * @param data event related data
+     * @return 
+     */
+    long onMiddleMouseDown(FXObject *sender, FXSelector selector, void *data);
+    
+    /**
+     * Called by the system when the middle mouse button is released
+     * @param sender the sender object
+     * @param selector message type and id
+     * @param data event related data
+     * @return 
+     */
+    long onMiddleMouseUp(FXObject *sender, FXSelector selector, void *data);
+    
+    /**
+     * Called by the system when the right mouse button is pressed
+     * @param sender the sender object
+     * @param selector message type and id
+     * @param data event related data
+     * @return 
+     */
+    long onRightMouseDown(FXObject *sender, FXSelector selector, void *data);
+    
+    /**
+     * Called by the system when the right mouse button is released
+     * @param sender the sender object
+     * @param selector message type and id
+     * @param data event related data
+     * @return 
+     */
+    long onRightMouseUp(FXObject *sender, FXSelector selector, void *data);
+    
+    /**
+     * Called by the system when the mouse is moved
+     * @param sender the sender object
+     * @param selector message type and id
+     * @param data event related data
+     * @return 
+     */
+    long onMouseMove(FXObject *sender, FXSelector selector, void *data);
+    
+    /**
+     * Called by the system when the rendering surface needs a repaint
+     * @param sender the sender object
+     * @param selector message type and id
+     * @param data event related data
+     * @return 
+     */
+    long onRepaint(FXObject *sender, FXSelector selector, void *data);
+
+protected:
+    
+    /**
+     * Constructor
+     */
+    RenderingSurface() {}
+    
+private:
+    
+    FXGLVisual *_visual;    // Pixel format info
+    FXGLCanvas *_canvas;    // OpenGL-capable drawing area
+
+    LindenmayerSystem *_lsystem;    // The Lindenmayer System
+    
+    // Model position
+    double _modelX,
+           _modelY,
+           _modelZ;
+
+    // Model rotation
+    double _modelRotationY;
+            
+    // Mouse button status
+    bool _leftMouseDown,
+         _middleMouseDown,
+         _rightMouseDown;
+};
+
+
+
+#endif