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
->EnableEvents( new->window
, DWET_KEYDOWN
| DWET_KEYUP
|
159 DWET_BUTTONDOWN
| DWET_BUTTONUP
|
160 DWET_ENTER
| DWET_LEAVE
|
161 DWET_MOTION
| DWET_SIZE
);
164 new->req
.flags
|= WINDOW_REQUEST_SHOW
;
167 new->reshape
= GL_TRUE
;
168 new->visibility
= GL_TRUE
;
169 new->redisplay
= GL_TRUE
;
172 new->prev
= g_stack
->prev
;
173 g_stack
->prev
->next
= new;
186 __glutFindWindow( DFBWindowID id
)
190 for (cur
= g_stack
; cur
; cur
= cur
->next
) {
195 __glutFatalError( "Window %d not found", id
);
202 __glutSetWindow( __GlutWindow
*window
)
205 if (g_current
== window
)
207 g_current
->gl
->Unlock( g_current
->gl
);
211 window
->gl
->Lock( window
->gl
);
217 __glutHandleWindows( void )
219 __GlutWindow
*cur
= g_stack
;
222 __GlutWindow
*next
= cur
->next
;
224 if (cur
->window
&& cur
->req
.flags
) {
225 if (cur
== g_current
)
226 cur
->gl
->Unlock( cur
->gl
);
228 if (cur
->req
.flags
& WINDOW_REQUEST_DESTROY
) {
229 __glutDestroyWindow( cur
);
234 if (cur
->req
.flags
& WINDOW_REQUEST_POSITION
) {
235 cur
->window
->MoveTo( cur
->window
,
236 cur
->req
.x
, cur
->req
.y
);
239 if (cur
->req
.flags
& WINDOW_REQUEST_RESIZE
) {
240 cur
->window
->Resize( cur
->window
,
241 cur
->req
.w
, cur
->req
.h
);
242 cur
->reshape
= GL_TRUE
;
243 cur
->redisplay
= GL_TRUE
;
246 if (cur
->req
.flags
& WINDOW_REQUEST_RESTACK
) {
247 while (cur
->req
.z
> 0) {
248 if (cur
->req
.z
>= +1000) {
249 cur
->window
->RaiseToTop( cur
->window
);
254 cur
->window
->Raise( cur
->window
);
258 while (cur
->req
.z
< 0) {
259 if (cur
->req
.z
<= -1000) {
260 cur
->window
->LowerToBottom( cur
->window
);
265 cur
->window
->Lower( cur
->window
);
270 if (cur
->req
.flags
& WINDOW_REQUEST_SHOW
) {
271 cur
->window
->SetOpacity( cur
->window
, 0xff );
272 cur
->visible
= GL_TRUE
;
273 cur
->visibility
= GL_TRUE
;
275 else if (cur
->req
.flags
& WINDOW_REQUEST_HIDE
) {
276 cur
->window
->SetOpacity( cur
->window
, 0x00 );
277 cur
->visible
= GL_FALSE
;
278 cur
->visibility
= GL_TRUE
;
283 if (cur
== g_current
)
284 cur
->gl
->Lock( cur
->gl
);
287 if (cur
->reshape
&& reshape_func
) {
290 cur
->surface
->GetSize( cur
->surface
, &w
, &h
);
291 __glutSetWindow( cur
);
292 reshape_func( w
, h
);
295 if (cur
->visibility
&& visibility_func
) {
297 __glutSetWindow( cur
);
298 visibility_func( cur
->visible
? GLUT_VISIBLE
: GLUT_NOT_VISIBLE
);
301 if (cur
->redisplay
&& display_func
) {
303 __glutSetWindow( cur
);
307 cur
->reshape
= GL_FALSE
;
308 cur
->visibility
= GL_FALSE
;
309 cur
->redisplay
= GL_FALSE
;
317 __glutDestroyWindow( __GlutWindow
*window
)
319 __GlutWindow
*next
= window
->next
;
320 __GlutWindow
*prev
= window
->prev
;
322 __glutAssert( window
!= NULL
);
324 if (window
== g_current
)
326 if (window
== g_game
)
329 window
->gl
->Unlock( window
->gl
);
330 window
->gl
->Release( window
->gl
);
331 window
->surface
->Release( window
->surface
);
333 if (window
->window
) {
334 window
->window
->Destroy( window
->window
);
335 window
->window
->Release( window
->window
);
338 #if DIRECTFB_VERSION_CODE >= VERSION_CODE(0,9,26)
340 joystick
->DetachEventBuffer( joystick
, events
);
342 mouse
->DetachEventBuffer( mouse
, events
);
344 keyboard
->DetachEventBuffer( keyboard
, events
);
346 events
->Reset( events
);
354 g_stack
->prev
= prev
;
356 if (window
== g_stack
)
364 __glutDestroyWindows( void )
366 __GlutWindow
*cur
= g_stack
;
369 __GlutWindow
*next
= cur
->next
;
370 __glutDestroyWindow( cur
);
377 glutCreateWindow( const char *title
)
379 __GlutWindow
*window
;
381 if (getenv( "__GLUT_GAME_MODE" ))
382 return glutEnterGameMode();
384 glutInit( NULL
, NULL
);
386 window
= __glutCreateWindow( GL_FALSE
);
390 __glutSetWindow( window
);
391 glutSetCursor( GLUT_CURSOR_INHERIT
);
398 glutCreateSubWindow( int win
, int x
, int y
, int width
, int height
)
405 glutDestroyWindow( int win
)
409 for (cur
= g_stack
; cur
; cur
= cur
->next
) {
410 if (cur
->id
== win
) {
412 cur
->window
->Destroy( cur
->window
);
414 cur
->req
.flags
|= WINDOW_REQUEST_DESTROY
;
422 glutPostRedisplay( void )
425 g_current
->redisplay
= GL_TRUE
;
430 glutPostWindowRedisplay( int win
)
434 for (cur
= g_stack
; cur
; cur
= cur
->next
) {
435 if (cur
->id
== win
) {
436 cur
->redisplay
= GL_TRUE
;
444 glutSwapBuffers( void )
447 g_current
->gl
->Unlock( g_current
->gl
);
448 g_current
->surface
->Flip( g_current
->surface
, NULL
, 0 );
449 g_current
->gl
->Lock( g_current
->gl
);
455 glutGetWindow( void )
457 return (g_current
) ? g_current
->id
: 0;
462 glutSetWindow( int win
)
466 if (g_current
&& g_current
->id
== win
)
469 for (cur
= g_stack
; cur
; cur
= cur
->next
) {
470 if (cur
->id
== win
) {
471 __glutSetWindow( cur
);
479 glutSetWindowTitle( const char *title
)
485 glutSetIconTitle( const char *title
)
491 glutFullScreen( void )
493 if (g_current
&& !g_game
) {
494 DFBDisplayLayerConfig config
;
496 primary
->GetConfiguration( primary
, &config
);
498 g_current
->req
.flags
|= WINDOW_REQUEST_POSITION
|
499 WINDOW_REQUEST_RESIZE
|
500 WINDOW_REQUEST_RESTACK
;
501 g_current
->req
.x
= 0;
502 g_current
->req
.y
= 0;
503 g_current
->req
.w
= config
.width
;
504 g_current
->req
.h
= config
.height
;
505 g_current
->req
.z
= 1000;
511 glutPositionWindow( int x
, int y
)
513 if (g_current
&& !g_game
) {
514 g_current
->req
.flags
|= WINDOW_REQUEST_POSITION
;
515 g_current
->req
.x
= x
;
516 g_current
->req
.y
= y
;
522 glutReshapeWindow( int width
, int height
)
524 if (g_current
&& !g_game
) {
525 g_current
->req
.flags
|= WINDOW_REQUEST_RESIZE
;
526 g_current
->req
.w
= width
;
527 g_current
->req
.h
= height
;
533 glutPopWindow( void )
535 if (g_current
&& !g_game
) {
536 g_current
->req
.flags
|= WINDOW_REQUEST_RESTACK
;
543 glutPushWindow( void )
545 if (g_current
&& !g_game
) {
546 g_current
->req
.flags
|= WINDOW_REQUEST_RESTACK
;
553 glutIconifyWindow( void )
559 glutShowWindow( void )
561 if (g_current
&& !g_game
) {
562 g_current
->req
.flags
|= WINDOW_REQUEST_SHOW
;
563 g_current
->req
.flags
&= ~WINDOW_REQUEST_HIDE
;
569 glutHideWindow( void )
571 if (g_current
&& !g_game
) {
572 g_current
->req
.flags
|= WINDOW_REQUEST_HIDE
;
573 g_current
->req
.flags
&= ~WINDOW_REQUEST_SHOW
;