Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / API_Bilat_FreeGlut_Tools / INC / GLUTWindow.h
1 #ifndef GLUT_WINDOW_CUSTOMISER_A_H
2 #define GLUT_WINDOW_CUSTOMISER_A_H
3
4 #include "envFreeGlutTools.h"
5 #include "Panel_A.h"
6 #include "GLConfig.h"
7 #include "Displayable_A.h"
8 #include <thread> //requier compilation flags -std=c++0x
9 #include <string>
10
11 using std::string;
12 using std::thread;
13
14 #define DEFAULT_GLUT_DISPLAY_MODE GLUT_DOUBLE|GLUT_DEPTH|GLUT_RGBA
15
16 /**
17 * Etat d'une GLUTWindow
18 * A un instant t, elle ne peux avoir qu'un seul �tat, soit CREATED,RUNNING ou DESTROYED.
19 * L'�tat NOT_CREATED est utiliser � la construction de l'objet et fait office d'�tat "NULL" ou sans �tat
20 */
21 enum GLUT_WINDOW_CUSTOMISER_STATE
22 {
23 NOT_CREATED,
24 CREATED,
25 RUNNING,
26 DESTROYED
27 };
28
29 /**
30 * But :
31 * Permet de customiser une fenetre FreeGLUT.
32 *
33 * Note :
34 *
35 * Seul les methodes init et display sont obligatoire.
36 *
37 * Attention :
38 *
39 * la fonction idleFun est appel� de mani�re fr�n�tique ! A utiliser a vos risque et p�rile.
40 */
41 class CBI_FREEGLUT_TOOLS GLUTWindow: public Panel_A
42 {
43 public:
44 /*--------------------------------------*\
45 |* Constructor *|
46 \*-------------------------------------*/
47
48 GLUTWindow(Displayable_A* ptrDisplayable, string title, int width, int height, int pxFrame = 0, int pyFrame = 0, int glutDisplayMode =
49 DEFAULT_GLUT_DISPLAY_MODE);
50
51 /*--------------------------------------*\
52 |* Destructor *|
53 \*-------------------------------------*/
54
55 virtual ~GLUTWindow();
56
57 /*--------------------------------------*\
58 |* Callbacks *|
59 \*-------------------------------------*/
60
61 virtual void display(void);
62 virtual void release(void);
63 virtual void reshape(int w, int h);
64 virtual void mouseMoved(int x, int y);
65 virtual void mouseWheelChanged(int wheel, int direction, int x, int y);
66 virtual void mousePressed(int button, int state, int x, int y);
67 virtual void keyPressed(unsigned char key, int x, int y);
68 virtual void specialKeyPressed(int key, int x, int y);
69 virtual void closeWindow();
70
71 /**
72 * PostRendu est appeler apres GLUTWindowManager::runALL.
73 *
74 * Elle est dans son propre thread. (un thread par fen�tre).
75 *
76 * GLUTWindow ne stop pas le thread explicitement. Donc si il y a une boucle infinie, il faut utiliser l'etat de la fenetre comme crit�re d'arret.
77 *
78 * Par exemple
79 *
80 * isDestroyed
81 * isRunning
82 *
83 * Interuption du thread
84 *
85 * try
86 * {
87 * ....
88 * }
89 * catch (boost::thread_interrupted&)
90 * {
91 * ...
92 * }
93 */
94 virtual void postRendu();
95
96 /**
97 * Fonction appel� a chaque fois que glut n'a rien � faire dans la mainLoop.
98 * CaD s'il n'y a pas d'�venents utilisateur (souris,clavier,joystick,repaint,etc...)
99 */
100 virtual void idleFunc();
101
102 /*--------------------------------------*\
103 |* Methodes *|
104 \*-------------------------------------*/
105
106 /**
107 * Don't Use !
108 * Only used by GLUTWindowManagers !
109 * Will start the postRenduThread
110 */
111 void startWindow();
112
113 /**
114 * call display()
115 */
116 void repaint() const;
117
118 /*--------------------------------------*\
119 |* Get *|
120 \*-------------------------------------*/
121
122 int getFrameWidth(void) const;
123
124 int getFrameHeight(void) const;
125
126 int getFramePositionX(void) const;
127
128 int getFramePositionY(void) const;
129
130 int getGLUTDisplayMode(void) const;
131
132 unsigned int getGLUTWindowID(void) const;
133
134 string getTitle(void) const;
135
136 Displayable_A* getPtrDisplayable();
137
138 TextRenderer_A* getTextRenderer();
139
140 FontLoader_A* getFontLoader();
141
142 /*--------------------------------------*\
143 |* Is *|
144 \*-------------------------------------*/
145
146 bool isRunning() const;
147
148 bool isCreated() const;
149
150 bool isDestroyed() const;
151
152 bool isDisplaying() const;
153
154 /*--------------------------------------*\
155 |* Set *|
156 \*-------------------------------------*/
157
158 /**
159 * Don't Use !
160 * Only used by GLUTWindowManagers !
161 */
162 void setState(GLUT_WINDOW_CUSTOMISER_STATE state);
163
164 /*--------------------------------------*\
165 |* Private *|
166 \*-------------------------------------*/
167
168 private:
169 ModifierType getModifier();
170
171 void startThreadPostRendu();
172
173 /*--------------------------------------*\
174 |* Attributs *|
175 \*-------------------------------------*/
176
177 private:
178
179 // Input
180 Displayable_A* ptrDisplayable;
181 string title;
182 int pxFrame;
183 int pyFrame;
184 int width;
185 int height;
186 int glutDisplayMode;
187
188 //Tools
189 TextRenderer_A* ptrTextRenderer;
190 FontLoader_A* ptrFontLoader;
191 int lastFPS;
192 bool displaying;
193 GLUT_WINDOW_CUSTOMISER_STATE state;
194 unsigned int glutWindowId;
195
196 // Animation
197 thread threadPostRendu;
198 };
199
200 #endif