Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00039 #include "GHOST_DisplayManager.h" 00040 #include "GHOST_Debug.h" 00041 00042 00043 GHOST_DisplayManager::GHOST_DisplayManager( 00044 void) 00045 : m_settingsInitialized(false) 00046 { 00047 } 00048 00049 00050 GHOST_DisplayManager::~GHOST_DisplayManager(void) 00051 { 00052 } 00053 00054 00055 GHOST_TSuccess 00056 GHOST_DisplayManager::initialize( 00057 void) 00058 { 00059 GHOST_TSuccess success; 00060 if (!m_settingsInitialized) { 00061 success = initializeSettings(); 00062 m_settingsInitialized = true; 00063 } 00064 else { 00065 success = GHOST_kSuccess; 00066 } 00067 return success; 00068 } 00069 00070 00071 GHOST_TSuccess 00072 GHOST_DisplayManager::getNumDisplays( 00073 GHOST_TUns8& /*numDisplays*/) const 00074 { 00075 // Don't know if we have a display... 00076 return GHOST_kFailure; 00077 } 00078 00079 00080 GHOST_TSuccess 00081 GHOST_DisplayManager::getNumDisplaySettings( 00082 GHOST_TUns8 display, 00083 GHOST_TInt32& numSettings) const 00084 { 00085 GHOST_TSuccess success; 00086 00087 GHOST_ASSERT(m_settingsInitialized, "GHOST_DisplayManager::getNumDisplaySettings(): m_settingsInitialized=false"); 00088 GHOST_TUns8 numDisplays; 00089 success = getNumDisplays(numDisplays); 00090 if (success == GHOST_kSuccess) { 00091 if (display < numDisplays) { 00092 numSettings = m_settings[display].size(); 00093 } 00094 else { 00095 success = GHOST_kFailure; 00096 } 00097 } 00098 return success; 00099 } 00100 00101 00102 GHOST_TSuccess 00103 GHOST_DisplayManager::getDisplaySetting( 00104 GHOST_TUns8 display, 00105 GHOST_TInt32 index, 00106 GHOST_DisplaySetting& setting) const 00107 { 00108 GHOST_TSuccess success; 00109 00110 GHOST_ASSERT(m_settingsInitialized, "GHOST_DisplayManager::getNumDisplaySettings(): m_settingsInitialized=false"); 00111 GHOST_TUns8 numDisplays; 00112 success = getNumDisplays(numDisplays); 00113 if (success == GHOST_kSuccess) { 00114 if (display < numDisplays && ((GHOST_TUns8)index < m_settings[display].size())) { 00115 setting = m_settings[display][index]; 00116 } 00117 else { 00118 success = GHOST_kFailure; 00119 } 00120 } 00121 return success; 00122 } 00123 00124 00125 GHOST_TSuccess 00126 GHOST_DisplayManager::getCurrentDisplaySetting( 00127 GHOST_TUns8 /*display*/, 00128 GHOST_DisplaySetting& /*setting*/) const 00129 { 00130 return GHOST_kFailure; 00131 } 00132 00133 00134 GHOST_TSuccess 00135 GHOST_DisplayManager::setCurrentDisplaySetting( 00136 GHOST_TUns8 /*display*/, 00137 const GHOST_DisplaySetting& /*setting*/) 00138 { 00139 return GHOST_kFailure; 00140 } 00141 00142 00143 GHOST_TSuccess 00144 GHOST_DisplayManager::findMatch( 00145 GHOST_TUns8 display, 00146 const GHOST_DisplaySetting& setting, 00147 GHOST_DisplaySetting& match) const 00148 { 00149 GHOST_TSuccess success = GHOST_kSuccess; 00150 GHOST_ASSERT(m_settingsInitialized, "GHOST_DisplayManager::findMatch(): m_settingsInitialized=false"); 00151 00152 int criteria[4] = { setting.xPixels, setting.yPixels, setting.bpp, setting.frequency }; 00153 int capabilities[4]; 00154 double field, score; 00155 double best = 1e12; // A big number 00156 int found = 0; 00157 00158 // Look at all the display modes 00159 for (int i = 0; (i < (int)m_settings[display].size()); i++) { 00160 // Store the capabilities of the display device 00161 capabilities[0] = m_settings[display][i].xPixels; 00162 capabilities[1] = m_settings[display][i].yPixels; 00163 capabilities[2] = m_settings[display][i].bpp; 00164 capabilities[3] = m_settings[display][i].frequency; 00165 00166 // Match against all the fields of the display settings 00167 score = 0; 00168 for (int j = 0; j < 4; j++) { 00169 field = capabilities[j] - criteria[j]; 00170 score += field * field; 00171 } 00172 00173 if (score < best) { 00174 found = i; 00175 best = score; 00176 } 00177 } 00178 00179 match = m_settings[display][found]; 00180 00181 GHOST_PRINT("GHOST_DisplayManager::findMatch(): settings of match:\n"); 00182 GHOST_PRINT(" setting.xPixels=" << match.xPixels << "\n"); 00183 GHOST_PRINT(" setting.yPixels=" << match.yPixels << "\n"); 00184 GHOST_PRINT(" setting.bpp=" << match.bpp << "\n"); 00185 GHOST_PRINT(" setting.frequency=" << match.frequency << "\n"); 00186 00187 return success; 00188 } 00189 00190 00191 GHOST_TSuccess 00192 GHOST_DisplayManager::initializeSettings( 00193 void) 00194 { 00195 GHOST_TUns8 numDisplays; 00196 GHOST_TSuccess success = getNumDisplays(numDisplays); 00197 if (success == GHOST_kSuccess) { 00198 for (GHOST_TUns8 display = 0; (display < numDisplays) && (success == GHOST_kSuccess); display++) { 00199 GHOST_DisplaySettings displaySettings; 00200 m_settings.push_back(displaySettings); 00201 GHOST_TInt32 numSettings; 00202 success = getNumDisplaySettings(display, numSettings); 00203 if (success == GHOST_kSuccess) { 00204 GHOST_TInt32 index; 00205 GHOST_DisplaySetting setting; 00206 for (index = 0; (index < numSettings) && (success == GHOST_kSuccess); index++) { 00207 success = getDisplaySetting(display, index, setting); 00208 m_settings[display].push_back(setting); 00209 } 00210 } 00211 else { 00212 break; 00213 } 00214 } 00215 } 00216 return success; 00217 }