Changeset 9870

Show
Ignore:
Timestamp:
03/09/09 10:39:55 (4 years ago)
Author:
shuber
Message:

Fix for multiple windows on different screens. the coords of windows are now local to the screen, as in other implementations.

Location:
OpenSceneGraph/branches/osg-cocoa-dev
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/branches/osg-cocoa-dev/include/osgViewer/api/Cocoa/GraphicsWindowCocoa

    r9836 r9870  
    139139                 
    140140        void setVSync(bool f); 
     141                 
     142                /** adapts a resize / move of the window, coords in global screen space */ 
     143                void adaptResize(int x, int y, int w, int h); 
    141144         
    142145    protected: 
  • OpenSceneGraph/branches/osg-cocoa-dev/src/osgViewer/DarwinUtils.h

    r9845 r9870  
    8989        virtual bool setScreenRefreshRate(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate); 
    9090         
     91         
     92        /** returns screen-ndx containing rect x,y,w,h */ 
     93        unsigned int getScreenContaining(int x, int y, int w, int h); 
     94         
    9195        protected: 
    9296         
  • OpenSceneGraph/branches/osg-cocoa-dev/src/osgViewer/DarwinUtils.mm

    r9845 r9870  
    295295} 
    296296 
    297          
    298  
    299  
    300  
    301  
    302  
    303  
    304 } 
     297 
     298unsigned int DarwinWindowingSystemInterface::getScreenContaining(int x, int y, int w, int h) 
     299{ 
     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} 
  • OpenSceneGraph/branches/osg-cocoa-dev/src/osgViewer/GraphicsWindowCocoa.mm

    r9852 r9870  
    731731    // std::cout << "windowdidmove: " << bounds.origin.x << " " << bounds.origin.y << " " << bounds.size.width << " " << bounds.size.height << std::endl; 
    732732    
    733     _win->resized(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height); 
    734     _win->getEventQueue()->windowResize(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height, _win->getEventQueue()->getTime()); 
     733    _win->adaptResize(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height); 
     734    //_win->getEventQueue()->windowResize(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height, _win->getEventQueue()->getTime()); 
    735735    _win->requestRedraw(); 
    736736    _inDidMove = false; 
     
    840840    int screenLeft(0), screenTop(0); 
    841841    if (wsi) { 
    842          
    843842        wsi->getScreenTopLeft((*_traits), screenLeft, screenTop); 
    844         _traits->y += screenTop; 
    845         _traits->x += screenLeft; 
    846     } 
    847      
    848         NSRect rect = NSMakeRect(_traits->x, _traits->y, _traits->width, _traits->height); 
     843    } 
     844     
     845        NSRect rect = NSMakeRect(_traits->x + screenLeft, _traits->y + screenTop, _traits->width, _traits->height); 
    849846     
    850847        _window = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO]; 
     
    10931090void GraphicsWindowCocoa::resizedImplementation(int x, int y, int width, int height) 
    10941091{ 
     1092        std::cout << "resized implementation" << x << " " << y << " " << width << " " << height << std::endl;  
    10951093        GraphicsContext::resizedImplementation(x, y, width, height); 
    1096      
     1094    
    10971095    [_context update]; 
    10981096    MenubarController::instance()->update(); 
    1099 } 
     1097        getEventQueue()->windowResize(x,y,width, height, getEventQueue()->getTime()); 
     1098} 
     1099 
     1100 
    11001101 
    11011102 
     
    11051106bool GraphicsWindowCocoa::setWindowRectangleImplementation(int x, int y, int width, int height) 
    11061107{ 
    1107     
    1108     NSRect rect = NSMakeRect(x,y,width, height); 
     1108        DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface()); 
     1109    int screenLeft(0), screenTop(0); 
     1110    if (wsi) { 
     1111        wsi->getScreenTopLeft((*_traits), screenLeft, screenTop); 
     1112    } 
     1113 
     1114 
     1115    NSRect rect = NSMakeRect(x+screenLeft,y+screenTop,width, height); 
    11091116    rect = convertFromQuartzCoordinates(rect); 
    11101117     
     
    11161123} 
    11171124 
     1125 
     1126// ---------------------------------------------------------------------------------------------------------- 
     1127//  
     1128// ---------------------------------------------------------------------------------------------------------- 
     1129 
     1130void GraphicsWindowCocoa::adaptResize(int x, int y, int w, int h) 
     1131{ 
     1132 
     1133        DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface()); 
     1134    int screenLeft(0), screenTop(0); 
     1135    if (wsi) { 
     1136                 
     1137                // get the screen containing the window 
     1138                unsigned int screenNdx = wsi->getScreenContaining(x,y,w,h); 
     1139                 
     1140                // update traits 
     1141                _traits->screenNum = screenNdx; 
     1142                 
     1143                // get top left of screen 
     1144        wsi->getScreenTopLeft((*_traits), screenLeft, screenTop); 
     1145    } 
     1146         
     1147        resized(x-screenLeft,y-screenTop,w,h); 
     1148} 
    11181149 
    11191150