Show
Ignore:
Timestamp:
03/11/09 11:34:29 (4 years ago)
Author:
robert
Message:

Converted tabs to four spaces

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgViewer/DarwinUtils.mm

    r9879 r9895  
    1818static inline CGRect toCGRect(NSRect nsRect) 
    1919{ 
    20         CGRect cgRect; 
    21  
    22         cgRect.origin.x = nsRect.origin.x; 
    23         cgRect.origin.y = nsRect.origin.y; 
    24         cgRect.size.width = nsRect.size.width; 
    25         cgRect.size.height = nsRect.size.height; 
    26  
    27         return cgRect; 
     20    CGRect cgRect; 
     21 
     22    cgRect.origin.x = nsRect.origin.x; 
     23    cgRect.origin.y = nsRect.origin.y; 
     24    cgRect.size.width = nsRect.size.width; 
     25    cgRect.size.height = nsRect.size.height; 
     26 
     27    return cgRect; 
    2828} 
    2929 
    3030 
    3131MenubarController::MenubarController() 
    32 :       osg::Referenced(),  
     32:    osg::Referenced(),  
    3333    _list(),  
    3434    _menubarShown(false), 
    3535    _mutex()  
    3636{ 
    37         // the following code will query the system for the available rect on the main-display (typically the displaying showing the menubar + the dock 
    38  
    39         NSRect rect = [[[NSScreen screens] objectAtIndex: 0] visibleFrame]; 
    40         _availRect = toCGRect(rect); 
    41          
    42         // now we need the rect of the main-display including the menubar and the dock 
    43         _mainScreenBounds = CGDisplayBounds( CGMainDisplayID() ); 
    44  
    45  
    46         // NSRect 0/0 is bottom/left, _mainScreenBounds 0/0 is top/left 
    47         _availRect.origin.y = _mainScreenBounds.size.height - _availRect.size.height - _availRect.origin.y; 
    48          
    49                  
    50         // hide the menubar initially 
    51         SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); 
     37    // the following code will query the system for the available rect on the main-display (typically the displaying showing the menubar + the dock 
     38 
     39    NSRect rect = [[[NSScreen screens] objectAtIndex: 0] visibleFrame]; 
     40    _availRect = toCGRect(rect); 
     41     
     42    // now we need the rect of the main-display including the menubar and the dock 
     43    _mainScreenBounds = CGDisplayBounds( CGMainDisplayID() ); 
     44 
     45 
     46    // NSRect 0/0 is bottom/left, _mainScreenBounds 0/0 is top/left 
     47    _availRect.origin.y = _mainScreenBounds.size.height - _availRect.size.height - _availRect.origin.y; 
     48     
     49         
     50    // hide the menubar initially 
     51    SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); 
    5252} 
    5353 
     
    9090    unsigned int windowsIntersectingMainScreen = 0; 
    9191    for(WindowList::iterator i = _list.begin(); i != _list.end(); ) { 
    92                 WindowAdapter* wi = (*i).get(); 
     92        WindowAdapter* wi = (*i).get(); 
    9393        if (wi->valid()) { 
    9494            CGRect windowBounds; 
    95                         wi->getWindowBounds(windowBounds); 
    96                          
    97                         if (CGRectIntersectsRect(_mainScreenBounds, windowBounds)) 
     95            wi->getWindowBounds(windowBounds); 
     96             
     97            if (CGRectIntersectsRect(_mainScreenBounds, windowBounds)) 
    9898            { 
    9999                ++windowsIntersectingMainScreen; 
    100100                // osg::notify(osg::ALWAYS) << "testing rect " << windowBounds.origin.x << "/" << windowBounds.origin.y << " " << windowBounds.size.width << "x" << windowBounds.size.height << std::endl; 
    101                                 // osg::notify(osg::ALWAYS) << "against      " << _availRect.origin.x << "/" << _availRect.origin.y << " " << _availRect.size.width << "x" << _availRect.size.height << std::endl; 
     101                // osg::notify(osg::ALWAYS) << "against      " << _availRect.origin.x << "/" << _availRect.origin.y << " " << _availRect.size.width << "x" << _availRect.size.height << std::endl; 
    102102                // the window intersects the main-screen, does it intersect with the menubar/dock? 
    103103                if (((_availRect.origin.y > _mainScreenBounds.origin.y) && (_availRect.origin.y > windowBounds.origin.y)) || 
     
    133133static double getDictDouble (CFDictionaryRef refDict, CFStringRef key) 
    134134{ 
    135         double value; 
    136         CFNumberRef number_value = (CFNumberRef) CFDictionaryGetValue(refDict, key); 
    137         if (!number_value) // if can't get a number for the dictionary 
    138                 return -1;  // fail 
    139         if (!CFNumberGetValue(number_value, kCFNumberDoubleType, &value)) // or if cant convert it 
    140                 return -1; // fail 
    141         return value; // otherwise return the long value 
     135    double value; 
     136    CFNumberRef number_value = (CFNumberRef) CFDictionaryGetValue(refDict, key); 
     137    if (!number_value) // if can't get a number for the dictionary 
     138        return -1;  // fail 
     139    if (!CFNumberGetValue(number_value, kCFNumberDoubleType, &value)) // or if cant convert it 
     140        return -1; // fail 
     141    return value; // otherwise return the long value 
    142142} 
    143143 
     
    145145static long getDictLong(CFDictionaryRef refDict, CFStringRef key)        // const void* key? 
    146146{ 
    147         long value = 0; 
    148         CFNumberRef number_value = (CFNumberRef)CFDictionaryGetValue(refDict, key);  
    149         if (!number_value) // if can't get a number for the dictionary 
    150                 return -1;  // fail 
    151         if (!CFNumberGetValue(number_value, kCFNumberLongType, &value)) // or if cant convert it 
    152                 return -1; // fail 
    153         return value; 
     147    long value = 0; 
     148    CFNumberRef number_value = (CFNumberRef)CFDictionaryGetValue(refDict, key);  
     149    if (!number_value) // if can't get a number for the dictionary 
     150        return -1;  // fail 
     151    if (!CFNumberGetValue(number_value, kCFNumberLongType, &value)) // or if cant convert it 
     152        return -1; // fail 
     153    return value; 
    154154} 
    155155 
     
    158158/** ctor, get a list of all attached displays */ 
    159159DarwinWindowingSystemInterface::DarwinWindowingSystemInterface() : 
    160         _displayCount(0), 
    161         _displayIds(NULL) 
    162 { 
    163         ProcessSerialNumber sn = { 0, kCurrentProcess }; 
    164         TransformProcessType(&sn,kProcessTransformToForegroundApplication); 
    165         SetFrontProcess(&sn); 
    166          
    167         if( CGGetActiveDisplayList( 0, NULL, &_displayCount ) != CGDisplayNoErr ) 
    168                 osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: could not get # of screens" << std::endl; 
    169                  
    170         _displayIds = new CGDirectDisplayID[_displayCount]; 
    171         if( CGGetActiveDisplayList( _displayCount, _displayIds, &_displayCount ) != CGDisplayNoErr ) 
    172                 osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: CGGetActiveDisplayList failed" << std::endl; 
    173          
    174         } 
     160    _displayCount(0), 
     161    _displayIds(NULL) 
     162{ 
     163    ProcessSerialNumber sn = { 0, kCurrentProcess }; 
     164    TransformProcessType(&sn,kProcessTransformToForegroundApplication); 
     165    SetFrontProcess(&sn); 
     166     
     167    if( CGGetActiveDisplayList( 0, NULL, &_displayCount ) != CGDisplayNoErr ) 
     168        osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: could not get # of screens" << std::endl; 
     169         
     170    _displayIds = new CGDirectDisplayID[_displayCount]; 
     171    if( CGGetActiveDisplayList( _displayCount, _displayIds, &_displayCount ) != CGDisplayNoErr ) 
     172        osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: CGGetActiveDisplayList failed" << std::endl; 
     173     
     174    } 
    175175 
    176176/** dtor */ 
    177177DarwinWindowingSystemInterface::~DarwinWindowingSystemInterface() 
    178178{ 
    179         if (osg::Referenced::getDeleteHandler()) 
    180         { 
    181                 osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0); 
    182                 osg::Referenced::getDeleteHandler()->flushAll(); 
    183         } 
    184  
    185         if (_displayIds) delete[] _displayIds; 
    186         _displayIds = NULL; 
     179    if (osg::Referenced::getDeleteHandler()) 
     180    { 
     181        osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0); 
     182        osg::Referenced::getDeleteHandler()->flushAll(); 
     183    } 
     184 
     185    if (_displayIds) delete[] _displayIds; 
     186    _displayIds = NULL; 
    187187} 
    188188 
    189189/** @return a CGDirectDisplayID for a ScreenIdentifier */ 
    190190CGDirectDisplayID DarwinWindowingSystemInterface::getDisplayID(const osg::GraphicsContext::ScreenIdentifier& si) { 
    191         if (si.screenNum < static_cast<int>(_displayCount)) 
    192                 return _displayIds[si.screenNum]; 
    193         else { 
    194                 osg::notify(osg::WARN) << "GraphicsWindowCarbon :: invalid screen # " << si.screenNum << ", returning main-screen instead" << std::endl; 
    195                 return _displayIds[0]; 
    196         } 
     191    if (si.screenNum < static_cast<int>(_displayCount)) 
     192        return _displayIds[si.screenNum]; 
     193    else { 
     194        osg::notify(osg::WARN) << "GraphicsWindowCarbon :: invalid screen # " << si.screenNum << ", returning main-screen instead" << std::endl; 
     195        return _displayIds[0]; 
     196    } 
    197197} 
    198198 
     
    200200unsigned int DarwinWindowingSystemInterface::getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si)  
    201201{ 
    202         return _displayCount; 
     202    return _displayCount; 
    203203} 
    204204 
    205205void DarwinWindowingSystemInterface::getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution) 
    206206{ 
    207         CGDirectDisplayID id = getDisplayID(si); 
    208         resolution.width = CGDisplayPixelsWide(id); 
    209         resolution.height = CGDisplayPixelsHigh(id); 
    210         resolution.colorDepth = CGDisplayBitsPerPixel(id); 
    211         resolution.refreshRate = getDictDouble (CGDisplayCurrentMode(id), kCGDisplayRefreshRate);        // Not tested 
    212         if (resolution.refreshRate<0) resolution.refreshRate = 0; 
     207    CGDirectDisplayID id = getDisplayID(si); 
     208    resolution.width = CGDisplayPixelsWide(id); 
     209    resolution.height = CGDisplayPixelsHigh(id); 
     210    resolution.colorDepth = CGDisplayBitsPerPixel(id); 
     211    resolution.refreshRate = getDictDouble (CGDisplayCurrentMode(id), kCGDisplayRefreshRate);        // Not tested 
     212    if (resolution.refreshRate<0) resolution.refreshRate = 0; 
    213213} 
    214214 
     
    241241/** return the top left coord of a specific screen in global screen space */ 
    242242void DarwinWindowingSystemInterface::getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y) { 
    243         CGRect bounds = CGDisplayBounds( getDisplayID(si) ); 
    244         x = static_cast<int>(bounds.origin.x); 
    245         y = static_cast<int>(bounds.origin.y); 
    246          
    247         // osg::notify(osg::DEBUG_INFO) << "topleft of screen " << si.screenNum <<" " << bounds.origin.x << "/" << bounds.origin.y << std::endl; 
     243    CGRect bounds = CGDisplayBounds( getDisplayID(si) ); 
     244    x = static_cast<int>(bounds.origin.x); 
     245    y = static_cast<int>(bounds.origin.y); 
     246     
     247    // osg::notify(osg::DEBUG_INFO) << "topleft of screen " << si.screenNum <<" " << bounds.origin.x << "/" << bounds.origin.y << std::endl; 
    248248} 
    249249 
     
    253253bool DarwinWindowingSystemInterface::setScreenResolution(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height)  
    254254{  
    255         CGDirectDisplayID displayID = getDisplayID(screenIdentifier); 
    256          
    257         // add next line and on following line replace hard coded depth and refresh rate 
    258         CGRefreshRate refresh =  getDictDouble (CGDisplayCurrentMode(displayID), kCGDisplayRefreshRate);   
    259         CFDictionaryRef display_mode_values = 
    260                 CGDisplayBestModeForParametersAndRefreshRate( 
    261                                                 displayID,  
    262                                                 CGDisplayBitsPerPixel(displayID),  
    263                                                 width, height,   
    264                                                 refresh,   
    265                                                 NULL); 
    266  
    267                                                                            
    268         CGDisplaySwitchToMode(displayID, display_mode_values);     
    269         return true;  
     255    CGDirectDisplayID displayID = getDisplayID(screenIdentifier); 
     256     
     257    // add next line and on following line replace hard coded depth and refresh rate 
     258    CGRefreshRate refresh =  getDictDouble (CGDisplayCurrentMode(displayID), kCGDisplayRefreshRate);   
     259    CFDictionaryRef display_mode_values = 
     260        CGDisplayBestModeForParametersAndRefreshRate( 
     261                        displayID,  
     262                        CGDisplayBitsPerPixel(displayID),  
     263                        width, height,   
     264                        refresh,   
     265                        NULL); 
     266 
     267                                       
     268    CGDisplaySwitchToMode(displayID, display_mode_values);     
     269    return true;  
    270270} 
    271271 
    272272/** implementation of setScreenRefreshRate */ 
    273273bool DarwinWindowingSystemInterface::setScreenRefreshRate(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate) {  
    274          
    275         boolean_t  success(false); 
    276         unsigned width, height; 
    277         getScreenResolution(screenIdentifier, width, height); 
    278          
    279         CGDirectDisplayID displayID = getDisplayID(screenIdentifier); 
    280          
    281         // add next line and on following line replace hard coded depth and refresh rate 
    282         CFDictionaryRef display_mode_values = 
    283                 CGDisplayBestModeForParametersAndRefreshRate( 
    284                                                 displayID,  
    285                                                 CGDisplayBitsPerPixel(displayID),  
    286                                                 width, height,   
    287                                                 refreshRate,   
    288                                                 &success); 
    289  
    290                                                                            
    291         if (success) 
    292                 CGDisplaySwitchToMode(displayID, display_mode_values);     
    293                  
    294         return (success != 0); 
     274     
     275    boolean_t  success(false); 
     276    unsigned width, height; 
     277    getScreenResolution(screenIdentifier, width, height); 
     278     
     279    CGDirectDisplayID displayID = getDisplayID(screenIdentifier); 
     280     
     281    // add next line and on following line replace hard coded depth and refresh rate 
     282    CFDictionaryRef display_mode_values = 
     283        CGDisplayBestModeForParametersAndRefreshRate( 
     284                        displayID,  
     285                        CGDisplayBitsPerPixel(displayID),  
     286                        width, height,   
     287                        refreshRate,   
     288                        &success); 
     289 
     290                                       
     291    if (success) 
     292        CGDisplaySwitchToMode(displayID, display_mode_values);     
     293         
     294    return (success != 0); 
    295295} 
    296296 
     
    298298unsigned int DarwinWindowingSystemInterface::getScreenContaining(int x, int y, int w, int h) 
    299299{ 
    300         CGRect rect = CGRectMake(x,y,w,h); 
    301         for(unsigned int i = 0; i < _displayCount; ++i) { 
    302                 CGRect bounds = CGDisplayBounds( getDisplayID(i) ); 
    303                 if (CGRectIntersectsRect(bounds, rect)) { 
    304                         return i; 
    305                 } 
    306         } 
    307          
    308         return 0; 
    309 } 
    310  
    311  
    312  
    313  
    314  
    315  
    316 } 
     300    CGRect rect = CGRectMake(x,y,w,h); 
     301    for(unsigned int i = 0; i < _displayCount; ++i) { 
     302        CGRect bounds = CGDisplayBounds( getDisplayID(i) ); 
     303        if (CGRectIntersectsRect(bounds, rect)) { 
     304            return i; 
     305        } 
     306    } 
     307     
     308    return 0; 
     309} 
     310 
     311 
     312 
     313 
     314 
     315 
     316}