Adonthell 0.4
|
00001 /* 00002 $Id: screen.cc,v 1.21 2004/10/25 06:55:01 ksterker Exp $ 00003 00004 Copyright (C) 1999/2000/2001/2004 Alexandre Courbot 00005 Part of the Adonthell Project http://adonthell.linuxgames.com 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details. 00013 */ 00014 00015 /** 00016 * @file screen.cc 00017 * @author Alexandre Courbot <alexandrecourbot@linuxgames.com> 00018 * 00019 * @brief Defines the screen class. 00020 * 00021 * 00022 */ 00023 00024 #include "screen.h" 00025 #include <iostream> 00026 #ifndef __BEOS__ 00027 #include <sstream> 00028 #endif 00029 00030 using namespace std; 00031 00032 00033 surface screen::display; 00034 u_int8 screen::bytes_per_pixel_ = 0; 00035 u_int32 screen::trans = 0; 00036 bool screen::fullscreen_ = false; 00037 bool screen::dblmode; 00038 00039 void screen::set_video_mode (u_int16 nl, u_int16 nh, u_int8 depth, bool dbl, bool fscreen) 00040 { 00041 u_int8 bpp; 00042 u_int32 SDL_flags = SDL_SWSURFACE; 00043 u_int8 emulated = depth; 00044 00045 if (fscreen) 00046 { 00047 SDL_flags |= SDL_FULLSCREEN; 00048 fullscreen_ = true; 00049 } 00050 00051 dblmode = dbl; 00052 00053 if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) 00054 { 00055 fprintf (stderr, "couldn't init display: %s\n", SDL_GetError ()); 00056 exit (1); 00057 } 00058 00059 // Default video depth if none chosen. 00060 if (!depth) depth = 16; 00061 00062 if (dblmode) 00063 bpp = SDL_VideoModeOK (nl << 1, nh << 1, depth, SDL_flags); 00064 else 00065 bpp = SDL_VideoModeOK (nl, nh, depth, SDL_flags); 00066 00067 if ((emulated) && (bpp) && (bpp != depth)) bpp = depth; 00068 00069 switch (bpp) 00070 { 00071 case 0: 00072 fprintf (stderr, "Video mode %dx%d unavailable. Exiting.. \n", nl, 00073 nh); 00074 exit (1); 00075 break; 00076 default: 00077 bytes_per_pixel_ = bpp / 8; 00078 break; 00079 } 00080 display.set_dbl_mode (dbl); 00081 display.set_length (nl); 00082 display.set_height (nh); 00083 00084 // surface destructor musn't free the screen surface 00085 display.not_screen = false; 00086 00087 if (dblmode) 00088 { 00089 nl = nl << 1; 00090 nh = nh << 1; 00091 } 00092 00093 display.vis = SDL_SetVideoMode (nl, nh, bpp, SDL_flags); 00094 if (display.vis == NULL) 00095 { 00096 fprintf (stderr, "error: %s\n", SDL_GetError ()); 00097 exit (1); 00098 } 00099 00100 // Setting up transparency color 00101 trans = SDL_MapRGB (display.vis->format, 0xFF, 0x00, 0xFF); 00102 00103 // Setting up the window title 00104 SDL_WM_SetCaption ("Adonthell", NULL); 00105 00106 // Turn off SDL cursor 00107 SDL_ShowCursor (0); 00108 } 00109 00110 void screen::show () 00111 { 00112 SDL_Flip (display.vis); 00113 } 00114 00115 string screen::info () 00116 { 00117 #ifndef __BEOS__ 00118 const SDL_VideoInfo * vi = SDL_GetVideoInfo (); 00119 ostringstream temp; 00120 00121 const int driver_name_length = 500; 00122 char drv_name[driver_name_length]; 00123 00124 temp << "Video information: \n" 00125 << "Video driver used: " << SDL_VideoDriverName(drv_name, driver_name_length) << endl 00126 << "Internal game depth: " << bytes_per_pixel_ * 8 << endl 00127 << "Can create hardware surfaces: " << (vi->hw_available ? "Yes" : "No") << endl 00128 << "Window manager available: " << (vi->wm_available ? "Yes" : "No") << endl 00129 << "Hardware blits accelerated: " << (vi->blit_hw ? "Yes" : "No") << endl 00130 << "Colorkey hardware blits accelerated: " << (vi->blit_hw_CC ? "Yes" : "No") << endl 00131 << "Alpha hardware blits accelerated: " << (vi->blit_hw_A ? "Yes" : "No") << endl 00132 << "Software blits accelerated: " << (vi->blit_sw ? "Yes" : "No") << endl 00133 << "Colorkey software blits accelerated: " << (vi->blit_sw_CC ? "Yes" : "No") << endl 00134 << "Alpha software blits accelerated: " << (vi->blit_sw_A ? "Yes" : "No") << endl 00135 << "Color fill blits accelerated: " << (vi->blit_fill ? "Yes" : "No") << endl 00136 << "Total video memory available: " << vi->video_mem << " Kb" << endl 00137 << "Using double size: " << (dblmode ? "Yes" : "No") << endl 00138 << "Fullscreen: " << (fullscreen_ ? "Yes" : "No") << endl 00139 << ends; 00140 00141 string ret = temp.str (); 00142 #else 00143 string ret = "Sorry, not available under BeOS\n"; 00144 #endif // __BEOS__ 00145 00146 return ret; 00147 } 00148 00149 bool screen::set_fullscreen (bool m) 00150 { 00151 if (fullscreen_ != m) 00152 { 00153 int r = SDL_WM_ToggleFullScreen(display.vis); 00154 if (r) fullscreen_ = m; 00155 return r; 00156 } 00157 return 0; 00158 } 00159 00160 void screen::transition (u_int16 i) 00161 { 00162 display.fillrect (0, 0, i, screen::height (), 0); 00163 display.fillrect (screen::length () - i, 0, i, screen::height (), 0); 00164 display.fillrect (0, 0, screen::length (), i, 0); 00165 display.fillrect (0, screen::height () - i, screen::length (), i, 0); 00166 }