1c7ebff77251ee9bd8d5290b7372b17305c3107b
[lsystem3d.git] / src / renderingsurface.h
1 // Copyright (C) 2006 Erik Dahlberg
2 //
3 // This file is part of LSystem3D.
4 //
5 // LSystem3D is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // LSystem3D is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with LSystem3D; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
22 #ifndef RENDERINGSURFACE_H
23 #define RENDERINGSURFACE_H
24
25 #include "fx.h"
26 #include "fx3d.h"
27
28 #include "lindenmayersystem.h"
29
30
31
32 /**
33 * The OpenGL rendering surface
34 */
35 class RenderingSurface : public FXMainWindow
36 {
37 // macro to set up class declaration
38 FXDECLARE(RenderingSurface)
39
40 public:
41
42 // message ID's
43 enum
44 {
45 ID_CANVAS = FXMainWindow::ID_LAST,
46 ID_LAST
47 };
48
49
50 /**
51 * Constructor
52 * @param application the application object
53 */
54 RenderingSurface(FXApp *application);
55
56 /**
57 * Destructor
58 */
59 virtual ~RenderingSurface();
60
61
62 /**
63 * Create and initialize the window
64 */
65 virtual void create();
66
67 /**
68 * Initialize OpenGL
69 */
70 void initOpenGL();
71
72 /**
73 * Force an update of the rendering surface
74 */
75 void draw();
76
77
78 /**
79 * Called by the system when the left mouse button is pressed
80 * @param sender the sender object
81 * @param selector message type and id
82 * @param data event related data
83 * @return
84 */
85 long onLeftMouseDown(FXObject *sender, FXSelector selector, void *data);
86
87 /**
88 * Called by the system when the left mouse button is released
89 * @param sender the sender object
90 * @param selector message type and id
91 * @param data event related data
92 * @return
93 */
94 long onLeftMouseUp(FXObject *sender, FXSelector selector, void *data);
95
96 /**
97 * Called by the system when the middle mouse button is pressed
98 * @param sender the sender object
99 * @param selector message type and id
100 * @param data event related data
101 * @return
102 */
103 long onMiddleMouseDown(FXObject *sender, FXSelector selector, void *data);
104
105 /**
106 * Called by the system when the middle mouse button is released
107 * @param sender the sender object
108 * @param selector message type and id
109 * @param data event related data
110 * @return
111 */
112 long onMiddleMouseUp(FXObject *sender, FXSelector selector, void *data);
113
114 /**
115 * Called by the system when the right mouse button is pressed
116 * @param sender the sender object
117 * @param selector message type and id
118 * @param data event related data
119 * @return
120 */
121 long onRightMouseDown(FXObject *sender, FXSelector selector, void *data);
122
123 /**
124 * Called by the system when the right mouse button is released
125 * @param sender the sender object
126 * @param selector message type and id
127 * @param data event related data
128 * @return
129 */
130 long onRightMouseUp(FXObject *sender, FXSelector selector, void *data);
131
132 /**
133 * Called by the system when the mouse is moved
134 * @param sender the sender object
135 * @param selector message type and id
136 * @param data event related data
137 * @return
138 */
139 long onMouseMove(FXObject *sender, FXSelector selector, void *data);
140
141 /**
142 * Called by the system when the rendering surface needs a repaint
143 * @param sender the sender object
144 * @param selector message type and id
145 * @param data event related data
146 * @return
147 */
148 long onRepaint(FXObject *sender, FXSelector selector, void *data);
149
150 /**
151 * Called by the system when the close button is pressed
152 * @param sender the sender object
153 * @param selector message type and id
154 * @param data event related data
155 * @return
156 */
157 long onQuit(FXObject *sender, FXSelector selector, void *data);
158
159
160 /**
161 * Set current L-system generator
162 * @param lsystem the L-system generator
163 */
164 void setLSystem(LindenmayerSystem *lsystem);
165
166 protected:
167
168 /**
169 * Constructor
170 */
171 RenderingSurface() {}
172
173
174 FXGLVisual *_visual; // Pixel format info
175 FXGLCanvas *_canvas; // OpenGL-capable drawing area
176
177 LindenmayerSystem *_lsystem; // The Lindenmayer system generator
178
179
180 // Model position
181 double _modelX,
182 _modelY,
183 _modelZ;
184
185 // Model rotation
186 double _modelRotationY;
187
188 // Mouse button status
189 bool _leftMouseDown,
190 _middleMouseDown,
191 _rightMouseDown;
192 };
193
194
195
196 #endif