![[]](/images/special/trans.gif)
LibN2L-4 Library Code ReferenceClassesCompounds Files Members Method Index Full Reference cDisplayCommonImp.cppGo to the documentation of this file.00001 /************************************************************************ 00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library 00003 Copyright (C) 2003 Aaron Cameron 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 A copy of the GNU Lesser General Public License has been provided with 00020 this library in the file 'COPYING'. 00021 00022 Contact information for the author of this library has been provided 00023 with this library in the file 'AUTHOR'. 00024 ************************************************************************/ 00025 #include "cDisplayCommonImp.h" 00026 00027 #include "n2l/events.h" 00028 00029 #include "SDL.h" 00030 00031 namespace n2l 00032 { 00033 tBool cDisplayCommonImp::smDisplayExists = false; 00034 cDisplayCommonImp *cDisplayCommonImp::smCurrentDisplay = 0; 00035 00036 /**************************************************************************/ 00037 cDisplayCommonImp::cDisplayCommonImp() 00038 { 00039 smCurrentDisplay = this; 00040 mRGamma = 1.0; 00041 mGGamma = 1.0; 00042 mBGamma = 1.0; 00043 } 00044 00045 /**************************************************************************/ 00046 cDisplayCommonImp::~cDisplayCommonImp() 00047 { 00048 free(); 00049 smCurrentDisplay = 0; 00050 } 00051 00052 /**************************************************************************/ 00053 void cDisplayCommonImp::load( const cVfsNodeInterface & ) // iFile 00054 { 00055 // Displays currently support nothing, so there's no real need 00056 // to do anything except throw an exception 00057 throw cUnsupportedFileFormatException( "cDisplayCommonImp::load", 00058 "This display supports no file types" ); 00059 } 00060 00061 /**************************************************************************/ 00062 void cDisplayCommonImp::supportedFileFormats( 00063 tFileFormatList &oFormatList ) const 00064 { 00065 oFormatList.clear(); 00066 } 00067 00068 /**************************************************************************/ 00069 void cDisplayCommonImp::setWMTitle( const tString &iTitle ) 00070 { 00071 char *iconCaption; 00072 char *title; 00073 SDL_WM_GetCaption( &title, &iconCaption ); 00074 SDL_WM_SetCaption( iTitle.c_str(), iconCaption ); 00075 } 00076 00077 /**************************************************************************/ 00078 void cDisplayCommonImp::setWMIconCaption( const tString &iIconCaption ) 00079 { 00080 char *iconCaption; 00081 char *title; 00082 SDL_WM_GetCaption( &title, &iconCaption ); 00083 SDL_WM_SetCaption( title, iIconCaption.c_str() ); 00084 } 00085 00086 /**************************************************************************/ 00087 void cDisplayCommonImp::grabWMInput() 00088 { 00089 SDL_WM_GrabInput( SDL_GRAB_ON ); 00090 } 00091 00092 /**************************************************************************/ 00093 void cDisplayCommonImp::releaseWMInput() 00094 { 00095 SDL_WM_GrabInput( SDL_GRAB_OFF ); 00096 } 00097 00098 /**************************************************************************/ 00099 void cDisplayCommonImp::setMouseVisibility( const tBool iVisible ) 00100 { 00101 SDL_ShowCursor( tUbyte(iVisible) ); 00102 } 00103 00104 /**************************************************************************/ 00105 void cDisplayCommonImp::warpMouseLocation( const tVector2u &iNewPosition ) 00106 { 00107 SDL_WarpMouse( iNewPosition.x(), iNewPosition.y() ); 00108 } 00109 00110 /**************************************************************************/ 00111 void cDisplayCommonImp::centerMouse() 00112 { 00113 SDL_EventState( SDL_MOUSEMOTION, SDL_IGNORE ); 00114 SDL_WarpMouse( properties().size().x()/2,properties().size().y()/2 ); 00115 SDL_EventState( SDL_MOUSEMOTION, SDL_ENABLE ); 00116 } 00117 00118 /**************************************************************************/ 00119 const tString & cDisplayCommonImp::softDriver() const 00120 { 00121 static tString info; 00122 00123 char driverStr[1024]; 00124 SDL_version cVersion; 00125 SDL_VERSION( &cVersion ); 00126 const SDL_version *lVersion( SDL_Linked_Version() ); 00127 00128 // Get the info we want 00129 SDL_VideoDriverName( driverStr, 1024 ); 00130 const SDL_VideoInfo * const VideoInfo( SDL_GetVideoInfo() ); 00131 00132 info = "Soft Driver Info(\n\tComp:\tSDL "; 00133 info += asString(cVersion.major)+"."+ 00134 asString(cVersion.minor)+"."+ 00135 asString(cVersion.patch); 00136 info += "\n\tLinked:\t"; 00137 info += asString(lVersion->major)+"."+ 00138 asString(lVersion->minor)+"."+ 00139 asString(lVersion->patch); 00140 info += "\n\tDriver:\t"; 00141 info += driverStr; 00142 info += "\n\tWM Av:\t"; 00143 info += asString( VideoInfo->wm_available ); 00144 info += "\n\tMem:\t"; 00145 info += asString( VideoInfo->video_mem ); 00146 info += "\n)"; 00147 return info; 00148 } 00149 00150 /**************************************************************************/ 00151 const tFloat cDisplayCommonImp::aspect() const 00152 { 00153 return tFloat(properties().size().y())/properties().size().x(); 00154 } 00155 00156 /**************************************************************************/ 00157 const tFloat cDisplayCommonImp::fovYAspect() const 00158 { 00159 return tFloat(properties().size().x())/properties().size().y(); 00160 } 00161 00162 /**************************************************************************/ 00163 void cDisplayCommonImp::setGamma( const tFloat &iR, const tFloat &iG, 00164 const tFloat &iB ) 00165 { 00166 if (-1==SDL_SetGamma(iR,iG,iB)) 00167 throw cUnsupportedMethodException( "cDisplayCommonImp::setGamma", 00168 "Gamma controls not supported on this display" ); 00169 mRGamma = iR; 00170 mGGamma = iG; 00171 mBGamma = iB; 00172 } 00173 00174 /**************************************************************************/ 00175 void cDisplayCommonImp::getGamma( tFloat &oR, tFloat &oG, 00176 tFloat &oB ) const 00177 { 00178 oR = mRGamma; 00179 oG = mGGamma; 00180 oB = mBGamma; 00181 } 00182 00183 /**************************************************************************/ 00184 void cDisplayCommonImp::free() 00185 { 00186 if (empty()) return; 00187 cSurfaceCommonImp::free(); 00188 registerDisplayDestroyed(); 00189 } 00190 00191 /**************************************************************************/ 00192 const tBool cDisplayCommonImp::displayExists() 00193 { 00194 return smDisplayExists; 00195 } 00196 00197 /**************************************************************************/ 00198 void cDisplayCommonImp::registerDisplayDestroyed() 00199 { 00200 if (!displayExists()) 00201 throw cException( "cDisplayCommonImp::registerDisplayDestroyed", 00202 "No registered display exists to be destroyed!" ); 00203 smDisplayExists = false; 00204 cEventManager::mouseSystemDimensions( 0,0 ); 00205 } 00206 00207 /**************************************************************************/ 00208 void cDisplayCommonImp::registerDisplayCreated() 00209 { 00210 if (displayExists()) 00211 throw cException( "cDisplayCommonImp::registerDisplayCreated", 00212 "A display has already been created. This should have been " 00213 "caught by the display instance" ); 00214 smDisplayExists = true; 00215 // Set the resolution in the event manager so that it can 00216 // accurately map mouse events 00217 const SDL_Surface *const Screen( SDL_GetVideoSurface() ); 00218 if (!Screen) 00219 throw cException( "cDisplayCommonImp::registerDisplayCreated", 00220 "Registering a display but no Video surface was available?" ); 00221 cEventManager::mouseSystemDimensions( Screen->w, Screen->h ); 00222 } 00223 00224 /**************************************************************************/ 00225 void cDisplayCommonImp::assign( const cSurfaceInterface & ) // iSurface 00226 { 00227 throw cException( "cDisplayCommonImp::assign", 00228 "Call of a disabled method. This should never happen." ); 00229 } 00230 00231 00232 } // namespace |