comparison src/video/bwindow/SDL_sysvideo.cc @ 114:dabc453ce7f7

Now returns an error if unable to open audio on BeOS Fixed bugs in fullscreen/windowed mode changes, removed duplicated code.
author Sam Lantinga <slouken@lokigames.com>
date Fri, 20 Jul 2001 20:07:53 +0000
parents 74212992fb08
children 7be1046c4a68
comparison
equal deleted inserted replaced
113:e21ac1dd30f1 114:dabc453ce7f7
355 } else { 355 } else {
356 return false; 356 return false;
357 } 357 }
358 } 358 }
359 359
360 static int BE_ToggleFullScreen(_THIS, int fullscreen) 360 static int BE_SetFullScreen(_THIS, SDL_Surface *screen, int fullscreen)
361 { 361 {
362 bool needs_unlock, is_fullscreen; 362 int was_fullscreen;
363 bool needs_unlock;
363 BScreen bscreen; 364 BScreen bscreen;
364 BRect bounds; 365 BRect bounds;
365 display_mode mode; 366 display_mode mode;
366 int width, height, bpp; 367 int width, height, bpp;
367 368
369 /* Set the fullscreen mode */
370 was_fullscreen = SDL_Win->IsFullScreen();
368 SDL_Win->SetFullScreen(fullscreen); 371 SDL_Win->SetFullScreen(fullscreen);
369 is_fullscreen = SDL_Win->IsFullScreen(); 372 fullscreen = SDL_Win->IsFullScreen();
370 373
371 if(!((is_fullscreen && fullscreen) || 374 width = screen->w;
372 (!is_fullscreen && !fullscreen))) { 375 height = screen->h;
373 /* Modeswitch failed */
374 return 0;
375 }
376
377 if(is_fullscreen) _this->screen->flags |= SDL_FULLSCREEN;
378 else _this->screen->flags &= ~SDL_FULLSCREEN;
379
380 width = _this->screen->w;
381 height = _this->screen->h;
382 376
383 /* Set the appropriate video mode */ 377 /* Set the appropriate video mode */
384 if ( fullscreen ) { 378 if ( fullscreen ) {
385 bpp = _this->screen->format->BitsPerPixel; 379 bpp = screen->format->BitsPerPixel;
386 bscreen.GetMode(&mode); 380 bscreen.GetMode(&mode);
387 if ( (bpp != ColorSpaceToBitsPerPixel(mode.space)) || 381 if ( (bpp != ColorSpaceToBitsPerPixel(mode.space)) ||
388 (width != mode.virtual_width) || 382 (width != mode.virtual_width) ||
389 (height != mode.virtual_height)) { 383 (height != mode.virtual_height)) {
390 if(BE_FindClosestFSMode(_this, width, height, bpp, &mode)) { 384 if(BE_FindClosestFSMode(_this, width, height, bpp, &mode)) {
392 /* This simply stops the next resize event from being 386 /* This simply stops the next resize event from being
393 * sent to the SDL handler. 387 * sent to the SDL handler.
394 */ 388 */
395 SDL_Win->InhibitResize(); 389 SDL_Win->InhibitResize();
396 } else { 390 } else {
397 _this->screen->flags &= ~SDL_FULLSCREEN; 391 fullscreen = 0;
392 SDL_Win->SetFullScreen(fullscreen);
398 } 393 }
399 } 394 }
400 395 }
401 } else { 396 if ( ! fullscreen ) {
402 bscreen.SetMode(&saved_mode); 397 bscreen.SetMode(&saved_mode);
403 } 398 }
404 399
405 if ( SDL_Win->Lock() ) { 400 if ( SDL_Win->Lock() ) {
406 int xoff, yoff; 401 int xoff, yoff;
407 if ( SDL_Win->Shown() ) { 402 if ( SDL_Win->Shown() ) {
408 needs_unlock = 1; 403 needs_unlock = 1;
409 SDL_Win->Hide(); 404 SDL_Win->Hide();
410 } else { 405 } else {
411 needs_unlock = 0; 406 needs_unlock = 0;
412 } 407 }
413 /* This resizes the window and view area, but inhibits resizing of 408 /* This resizes the window and view area, but inhibits resizing
414 * the BBitmap due to the InhibitResize call above. Thus the bitmap 409 * of the BBitmap due to the InhibitResize call above. Thus the
415 * (pixel data) never changes. 410 * bitmap (pixel data) never changes.
416 */ 411 */
417 SDL_Win->ResizeTo(width, height); 412 SDL_Win->ResizeTo(width, height);
418 bounds = bscreen.Frame(); 413 bounds = bscreen.Frame();
419 /* Calculate offsets - used either to center window (windowed mode) 414 /* Calculate offsets - used either to center window
420 * or to set drawing offsets (fullscreen mode) 415 * (windowed mode) or to set drawing offsets (fullscreen mode)
421 */ 416 */
422 xoff = (bounds.IntegerWidth() - _this->screen->w)/2; 417 xoff = (bounds.IntegerWidth() - width)/2;
423 yoff = (bounds.IntegerHeight() - _this->screen->h)/2; 418 yoff = (bounds.IntegerHeight() - height)/2;
424 if(fullscreen) { 419 printf("Setting X/Y offset: %d/%d\n", xoff, yoff);
420 if ( fullscreen ) {
425 /* Set offset for drawing */ 421 /* Set offset for drawing */
426 SDL_Win->SetXYOffset(xoff, yoff); 422 SDL_Win->SetXYOffset(xoff, yoff);
427 } else { 423 } else {
428 /* Center window and reset the drawing offset */ 424 /* Center window and reset the drawing offset */
429 SDL_Win->MoveTo(xoff > 0 ? (float)xoff : 0.0,
430 yoff > 0 ? (float)yoff : 0.0);
431 SDL_Win->SetXYOffset(0, 0); 425 SDL_Win->SetXYOffset(0, 0);
426 }
427 if ( ! needs_unlock || was_fullscreen ) {
428 /* Center the window the first time */
429 SDL_Win->MoveTo(xoff > 0 ? (float)xoff : 0.0f,
430 yoff > 0 ? (float)yoff : 0.0f);
432 } 431 }
433 SDL_Win->Show(); 432 SDL_Win->Show();
434 433
435 /* Unlock the window manually after the first Show() */ 434 /* Unlock the window manually after the first Show() */
436 if ( needs_unlock ) { SDL_Win->Unlock(); } 435 if ( needs_unlock ) {
436 SDL_Win->Unlock();
437 }
438 }
439
440 /* Set the fullscreen flag in the screen surface */
441 if ( fullscreen ) {
442 screen->flags |= SDL_FULLSCREEN;
443 } else {
444 screen->flags &= ~SDL_FULLSCREEN;
437 } 445 }
438 return(1); 446 return(1);
447 }
448
449 static int BE_ToggleFullScreen(_THIS, int fullscreen)
450 {
451 return BE_SetFullScreen(_this, _this->screen, fullscreen);
439 } 452 }
440 453
441 /* FIXME: check return values and cleanup here */ 454 /* FIXME: check return values and cleanup here */
442 SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current, 455 SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current,
443 int width, int height, int bpp, Uint32 flags) 456 int width, int height, int bpp, Uint32 flags)
444 { 457 {
445 BScreen bscreen; 458 BScreen bscreen;
446 display_mode mode;
447 BBitmap *bbitmap; 459 BBitmap *bbitmap;
448 BRect bounds; 460 BRect bounds;
449 int needs_unlock;
450 int xoff = 0, yoff = 0;
451
452 /* Set the appropriate video mode */
453 if ( flags & SDL_FULLSCREEN ) {
454 bscreen.GetMode(&mode);
455 if ( (bpp != ColorSpaceToBitsPerPixel(mode.space)) ||
456 (width != mode.virtual_width) ||
457 (height != mode.virtual_height) ) {
458 if(BE_FindClosestFSMode(_this, width, height, bpp, &mode)) {
459 bscreen.SetMode(&mode);
460 xoff = (mode.virtual_width - width)/2;
461 yoff = (mode.virtual_height - height)/2;
462 } else {
463 flags &= ~SDL_FULLSCREEN;
464 }
465 }
466 } else {
467 if ( current->flags & SDL_FULLSCREEN ) {
468 bscreen.SetMode(&saved_mode);
469 }
470 }
471 461
472 /* Create the view for this window */ 462 /* Create the view for this window */
473 if ( SDL_Win->CreateView(flags) < 0 ) { 463 if ( SDL_Win->CreateView(flags) < 0 ) {
474 return(NULL); 464 return(NULL);
475 } 465 }
476 466
477 /* Set offsets */
478 SDL_Win->SetXYOffset(xoff, yoff);
479
480 current->flags = 0; /* Clear flags */ 467 current->flags = 0; /* Clear flags */
481 current->w = width; 468 current->w = width;
482 current->h = height; 469 current->h = height;
483 if ( flags & SDL_FULLSCREEN ) {
484 SDL_Win->SetFullScreen(1);
485 current->flags |= SDL_FULLSCREEN;
486 } else {
487 SDL_Win->SetFullScreen(0);
488 }
489 SDL_Win->SetType(B_TITLED_WINDOW); 470 SDL_Win->SetType(B_TITLED_WINDOW);
490 if ( flags & SDL_NOFRAME ) { 471 if ( flags & SDL_NOFRAME ) {
491 current->flags |= SDL_NOFRAME; 472 current->flags |= SDL_NOFRAME;
492 SDL_Win->SetLook(B_NO_BORDER_WINDOW_LOOK); 473 SDL_Win->SetLook(B_NO_BORDER_WINDOW_LOOK);
493 } else { 474 } else {
521 current->pixels = (void *)bbitmap->Bits(); 502 current->pixels = (void *)bbitmap->Bits();
522 SDL_Win->SetBitmap(bbitmap); 503 SDL_Win->SetBitmap(bbitmap);
523 _this->UpdateRects = BE_NormalUpdate; 504 _this->UpdateRects = BE_NormalUpdate;
524 } 505 }
525 506
526 /* Hide the window for resizing */ 507 /* Set the correct fullscreen mode */
527 if ( SDL_Win->Lock() ) { 508 BE_SetFullScreen(_this, current, flags & SDL_FULLSCREEN ? 1 : 0);
528 if ( SDL_Win->Shown() ) {
529 needs_unlock = 1;
530 SDL_Win->Hide();
531 } else {
532 needs_unlock = 0;
533 }
534
535 /* Resize, but only if the window is different size than
536 * before. Otherwise it jumps funnily when the user resizes.
537 */
538 bounds = SDL_Win->Bounds();
539 if((int)bounds.Width() != width ||
540 (int)bounds.Height() != height) {
541 SDL_Win->ResizeTo(width, height);
542 bounds = bscreen.Frame();
543 SDL_Win->MoveTo((bounds.Width()-width)/2,
544 (bounds.Height()-height)/2);
545 }
546 SDL_Win->Show();
547
548 /* Unlock the window manually after the first Show() */
549 if ( needs_unlock ) {
550 SDL_Win->Unlock();
551 }
552 }
553 509
554 /* We're done */ 510 /* We're done */
555 return(current); 511 return(current);
556 } 512 }
557 513