2 * Copyright (C) 2006 Claudio Ciccani <klan@users.sf.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 /*****************************************************************************/
30 static __GlutWindow
*g_stack
= NULL
;
32 /*****************************************************************************/
36 __glutCreateWindow( GLboolean fullscreen
)
42 new = calloc( 1, sizeof(__GlutWindow
) );
44 __glutFatalError( "out of memory" );
49 DFBDisplayLayerConfig config
;
50 DFBDisplayLayerConfigFlags fail
= 0;
52 config
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
|
54 config
.width
= g_width
;
55 config
.height
= g_height
;
57 if (g_display_mode
& GLUT_DOUBLE
)
58 config
.buffermode
= DLBM_BACKVIDEO
;
60 config
.buffermode
= DLBM_FRONTONLY
;
63 config
.flags
|= DLCONF_PIXELFORMAT
;
67 config
.pixelformat
= DSPF_RGB332
;
70 config
.pixelformat
= DSPF_ARGB1555
;
73 config
.pixelformat
= DSPF_RGB16
;
77 config
.pixelformat
= DSPF_RGB32
;
80 config
.flags
&= ~DLCONF_PIXELFORMAT
;
85 primary
->TestConfiguration( primary
, &config
, &fail
);
86 config
.flags
&= ~fail
;
87 primary
->SetConfiguration( primary
, &config
);
89 ret
= primary
->GetSurface( primary
, &new->surface
);
91 DirectFBError( "IDirectFBDisplayLayer::GetSurface()", ret
);
96 ret
= new->surface
->GetGL( new->surface
, &new->gl
);
98 DirectFBError( "IDirectFBSurface::GetGL()", ret
);
99 new->surface
->Release( new->surface
);
104 events
->Reset( events
);
106 keyboard
->AttachEventBuffer( keyboard
, events
);
108 mouse
->AttachEventBuffer( mouse
, events
);
110 joystick
->AttachEventBuffer( joystick
, events
);
112 new->visible
= GL_TRUE
;
115 DFBWindowDescription dsc
;
117 dsc
.flags
= DWDESC_CAPS
| DWDESC_POSX
| DWDESC_POSY
|
118 DWDESC_WIDTH
| DWDESC_HEIGHT
;
119 dsc
.caps
= DWCAPS_NONE
;
123 dsc
.height
= g_height
;
125 if (g_display_mode
& GLUT_DOUBLE
)
126 dsc
.caps
|= DWCAPS_DOUBLEBUFFER
;
127 if (g_display_mode
& GLUT_ALPHA
)
128 dsc
.caps
|= DWCAPS_ALPHACHANNEL
;
130 ret
= primary
->CreateWindow( primary
, &dsc
, &new->window
);
132 DirectFBError( "IDirectFBDisplayLayer::CreateWindow()", ret
);
137 new->window
->GetID( new->window
, &new->wid
);
139 ret
= new->window
->GetSurface( new->window
, &new->surface
);
141 DirectFBError( "IDirectFBWindow::GetSurface()", ret
);
142 new->window
->Release( new->window
);
147 ret
= new->surface
->GetGL( new->surface
, &new->gl
);
149 DirectFBError( "IDirectFBSurface::GetGl()", ret
);
150 new->surface
->Release( new->surface
);
151 new->window
->Release( new->window
);
156 new->window
->AttachEventBuffer( new->window
, events
);
157 /* enable only handled events */
158 new->window
->DisableEvents( new->window
, DWET_ALL
);
159 new->window
->EnableEvents( new->window
, DWET_KEYDOWN
| DWET_KEYUP
|
160 DWET_BUTTONDOWN
| DWET_BUTTONUP
|
161 DWET_ENTER
| DWET_LEAVE
|
162 DWET_MOTION
| DWET_SIZE
);
165 new->req
.flags
|= WINDOW_REQUEST_SHOW
;
168 new->reshape
= GL_TRUE
;
169 new->visibility
= GL_TRUE
;
170 new->redisplay
= GL_TRUE
;
173 new->prev
= g_stack
->prev
;
174 g_stack
->prev
->next
= new;
187 __glutFindWindow( DFBWindowID id
)
191 for (cur
= g_stack
; cur
; cur
= cur
->next
) {
196 __glutFatalError( "Window %d not found", id
);
203 __glutSetWindow( __GlutWindow
*window
)
206 if (g_current
== window
)
208 g_current
->gl
->Unlock( g_current
->gl
);
212 window
->gl
->Lock( window
->gl
);
218 __glutHandleWindows( void )
220 __GlutWindow
*cur
= g_stack
;
223 __GlutWindow
*next
= cur
->next
;
225 if (cur
->window
&& cur
->req
.flags
) {
226 if (cur
== g_current
)
227 cur
->gl
->Unlock( cur
->gl
);
229 if (cur
->req
.flags
& WINDOW_REQUEST_DESTROY
) {
230 __glutDestroyWindow( cur
);
235 if (cur
->req
.flags
& WINDOW_REQUEST_POSITION
) {
236 cur
->window
->MoveTo( cur
->window
,
237 cur
->req
.x
, cur
->req
.y
);
240 if (cur
->req
.flags
& WINDOW_REQUEST_RESIZE
) {
241 cur
->window
->Resize( cur
->window
,
242 cur
->req
.w
, cur
->req
.h
);
243 cur
->reshape
= GL_TRUE
;
244 cur
->redisplay
= GL_TRUE
;
247 if (cur
->req
.flags
& WINDOW_REQUEST_RESTACK
) {
248 while (cur
->req
.z
> 0) {
249 if (cur
->req
.z
>= +1000) {
250 cur
->window
->RaiseToTop( cur
->window
);
255 cur
->window
->Raise( cur
->window
);
259 while (cur
->req
.z
< 0) {
260 if (cur
->req
.z
<= -1000) {
261 cur
->window
->LowerToBottom( cur
->window
);
266 cur
->window
->Lower( cur
->window
);
271 if (cur
->req
.flags
& WINDOW_REQUEST_SHOW
) {
272 cur
->window
->SetOpacity( cur
->window
, 0xff );
273 cur
->visible
= GL_TRUE
;
274 cur
->visibility
= GL_TRUE
;
276 else if (cur
->req
.flags
& WINDOW_REQUEST_HIDE
) {
277 cur
->window
->SetOpacity( cur
->window
, 0x00 );
278 cur
->visible
= GL_FALSE
;
279 cur
->visibility
= GL_TRUE
;
284 if (cur
== g_current
)
285 cur
->gl
->Lock( cur
->gl
);
288 if (cur
->reshape
&& reshape_func
) {
291 cur
->surface
->GetSize( cur
->surface
, &w
, &h
);
292 __glutSetWindow( cur
);
293 reshape_func( w
, h
);
296 if (cur
->visibility
&& visibility_func
) {
298 __glutSetWindow( cur
);
299 visibility_func( cur
->visible
? GLUT_VISIBLE
: GLUT_NOT_VISIBLE
);
302 if (cur
->redisplay
&& display_func
) {
304 __glutSetWindow( cur
);
308 cur
->reshape
= GL_FALSE
;
309 cur
->visibility
= GL_FALSE
;
310 cur
->redisplay
= GL_FALSE
;
318 __glutDestroyWindow( __GlutWindow
*window
)
320 __GlutWindow
*next
= window
->next
;
321 __GlutWindow
*prev
= window
->prev
;
323 __glutAssert( window
!= NULL
);
325 if (window
== g_current
)
327 if (window
== g_game
)
330 window
->gl
->Unlock( window
->gl
);
331 window
->gl
->Release( window
->gl
);
332 window
->surface
->Release( window
->surface
);
334 if (window
->window
) {
335 #if DIRECTFB_VERSION_CODE >= VERSION_CODE(0,9,26)
336 window
->window
->DetachEventBuffer( window
->window
, events
);
338 window
->window
->Destroy( window
->window
);
340 window
->window
->Release( window
->window
);
343 #if DIRECTFB_VERSION_CODE >= VERSION_CODE(0,9,26)
345 joystick
->DetachEventBuffer( joystick
, events
);
347 mouse
->DetachEventBuffer( mouse
, events
);
349 keyboard
->DetachEventBuffer( keyboard
, events
);
351 events
->Reset( events
);
359 g_stack
->prev
= prev
;
361 if (window
== g_stack
)
369 __glutDestroyWindows( void )
371 __GlutWindow
*cur
= g_stack
;
374 __GlutWindow
*next
= cur
->next
;
375 __glutDestroyWindow( cur
);
382 glutCreateWindow( const char *title
)
384 __GlutWindow
*window
;
386 if (getenv( "__GLUT_GAME_MODE" ))
387 return glutEnterGameMode();
389 glutInit( NULL
, NULL
);
391 window
= __glutCreateWindow( GL_FALSE
);
395 __glutSetWindow( window
);
396 glutSetCursor( GLUT_CURSOR_INHERIT
);
403 glutCreateSubWindow( int win
, int x
, int y
, int width
, int height
)
410 glutDestroyWindow( int win
)
414 for (cur
= g_stack
; cur
; cur
= cur
->next
) {
415 if (cur
->id
== win
) {
417 cur
->window
->Destroy( cur
->window
);
419 cur
->req
.flags
|= WINDOW_REQUEST_DESTROY
;
427 glutPostRedisplay( void )
430 g_current
->redisplay
= GL_TRUE
;
435 glutPostWindowRedisplay( int win
)
439 for (cur
= g_stack
; cur
; cur
= cur
->next
) {
440 if (cur
->id
== win
) {
441 cur
->redisplay
= GL_TRUE
;
449 glutSwapBuffers( void )
452 g_current
->gl
->Unlock( g_current
->gl
);
453 g_current
->surface
->Flip( g_current
->surface
, NULL
, 0 );
454 g_current
->gl
->Lock( g_current
->gl
);
460 glutGetWindow( void )
462 return (g_current
) ? g_current
->id
: 0;
467 glutSetWindow( int win
)
471 if (g_current
&& g_current
->id
== win
)
474 for (cur
= g_stack
; cur
; cur
= cur
->next
) {
475 if (cur
->id
== win
) {
476 __glutSetWindow( cur
);
484 glutSetWindowTitle( const char *title
)
490 glutSetIconTitle( const char *title
)
496 glutFullScreen( void )
498 if (g_current
&& !g_game
) {
499 DFBDisplayLayerConfig config
;
501 primary
->GetConfiguration( primary
, &config
);
503 g_current
->req
.flags
|= WINDOW_REQUEST_POSITION
|
504 WINDOW_REQUEST_RESIZE
|
505 WINDOW_REQUEST_RESTACK
;
506 g_current
->req
.x
= 0;
507 g_current
->req
.y
= 0;
508 g_current
->req
.w
= config
.width
;
509 g_current
->req
.h
= config
.height
;
510 g_current
->req
.z
= 1000;
516 glutPositionWindow( int x
, int y
)
518 if (g_current
&& !g_game
) {
519 g_current
->req
.flags
|= WINDOW_REQUEST_POSITION
;
520 g_current
->req
.x
= x
;
521 g_current
->req
.y
= y
;
527 glutReshapeWindow( int width
, int height
)
529 if (g_current
&& !g_game
) {
530 g_current
->req
.flags
|= WINDOW_REQUEST_RESIZE
;
531 g_current
->req
.w
= width
;
532 g_current
->req
.h
= height
;
538 glutPopWindow( void )
540 if (g_current
&& !g_game
) {
541 g_current
->req
.flags
|= WINDOW_REQUEST_RESTACK
;
548 glutPushWindow( void )
550 if (g_current
&& !g_game
) {
551 g_current
->req
.flags
|= WINDOW_REQUEST_RESTACK
;
558 glutIconifyWindow( void )
564 glutShowWindow( void )
566 if (g_current
&& !g_game
) {
567 g_current
->req
.flags
|= WINDOW_REQUEST_SHOW
;
568 g_current
->req
.flags
&= ~WINDOW_REQUEST_HIDE
;
574 glutHideWindow( void )
576 if (g_current
&& !g_game
) {
577 g_current
->req
.flags
|= WINDOW_REQUEST_HIDE
;
578 g_current
->req
.flags
&= ~WINDOW_REQUEST_SHOW
;