Changeset 9852

Show
Ignore:
Timestamp:
03/04/09 11:25:40 (5 years ago)
Author:
shuber
Message:

improved multi-monitor-support for GraphicsWindowCocoa?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/branches/osg-cocoa-dev/src/osgViewer/GraphicsWindowCocoa.mm

    r9845 r9852  
    141141 
    142142 
     143std::ostream& operator<<(std::ostream& os, const NSRect& rect)  
     144{ 
     145        os << rect.origin.x << "/" << rect.origin.y << " " << rect.size.width << "x" << rect.size.height; 
     146        return os; 
     147} 
     148 
    143149// ---------------------------------------------------------------------------------------------------------- 
    144150// Cocoa uses a coordinate system where its origin is in the bottom left corner,  
     
    148154// ---------------------------------------------------------------------------------------------------------- 
    149155 
    150 static NSRect convertFromQuartzCoordinates(osgViewer::GraphicsWindowCocoa* win,const NSRect& rect)   
    151 { 
    152     NSRect frame = [[win->getWindow() screen] frame]; 
    153      
     156static NSRect convertFromQuartzCoordinates(const NSRect& rect)   
     157{ 
     158    NSRect frame = [[[NSScreen screens] objectAtIndex: 0] frame]; 
    154159    float y = frame.size.height - rect.origin.y - rect.size.height; 
    155     return NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height); 
    156 } 
    157  
    158 static NSRect convertToQuartzCoordinates(osgViewer::GraphicsWindowCocoa* win,const NSRect& rect) 
    159 { 
    160     NSRect frame = [[win->getWindow() screen] frame]; 
     160        NSRect converted = NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height); 
     161         
     162        // std::cout << "converting from Quartz " << rect << " to " << converted << " using screen rect " << frame << std::endl; 
     163         
     164    return converted; 
     165} 
     166 
     167static NSRect convertToQuartzCoordinates(const NSRect& rect) 
     168{ 
     169    NSRect frame = [[[NSScreen screens] objectAtIndex: 0] frame]; 
    161170     
    162171    float y = frame.size.height - (rect.origin.y + rect.size.height); 
    163     return NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height); 
     172        NSRect converted = NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height); 
     173         
     174        // std::cout << "converting To Quartz   " << rect << " to " << converted << " using screen rect " << frame << std::endl; 
     175         
     176    return converted; 
    164177} 
    165178 
     
    714727     
    715728    // convert to quartz-coordinate-system 
    716     bounds = convertToQuartzCoordinates(_win, bounds); 
     729    bounds = convertToQuartzCoordinates(bounds); 
    717730     
    718731    // std::cout << "windowdidmove: " << bounds.origin.x << " " << bounds.origin.y << " " << bounds.size.width << " " << bounds.size.height << std::endl; 
     
    753766    { 
    754767        NSRect nsrect = [_win->getWindow() frame]; 
    755         nsrect = convertToQuartzCoordinates(_win.get(), nsrect); 
     768        nsrect = convertToQuartzCoordinates(nsrect); 
    756769         
    757770        rect.origin.x = nsrect.origin.x; 
     
    823836            style |= NSResizableWindowMask; 
    824837    } 
    825      
     838         
    826839    DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface()); 
    827840    int screenLeft(0), screenTop(0); 
     
    842855    } 
    843856     
    844     rect = convertFromQuartzCoordinates(this,  rect); 
     857    rect = convertFromQuartzCoordinates(rect); 
    845858    [_window setFrameOrigin: rect.origin]; 
    846859          
     
    10941107    
    10951108    NSRect rect = NSMakeRect(x,y,width, height); 
    1096     rect = convertFromQuartzCoordinates(this, rect); 
     1109    rect = convertFromQuartzCoordinates(rect); 
    10971110     
    10981111    [_window setFrame: [NSWindow frameRectForContentRect: rect styleMask: [_window styleMask]] display: YES];