Show
Ignore:
Timestamp:
05/14/09 17:34:15 (4 years ago)
Author:
robert
Message:

From Stephan Huber, "attached you'll find some bugfixes and enhancements for the Cocoa
implementation of GraoicsWindowCocoa?:

Enhancements/Bugfixes:

+ now it's possible to integrate osgViewer better into existing
cocoa-applications:
* create one or more NSOpenGLView(s) and add these to your window(s)
* create one or more NSWindows
* disable the integrated event-polling of osgViewer, and let the work be
done by Cocoa / NSApplicationRun. You'll have to run the osgViewer's
runloop in a separate thread

+ missing menu-event-handling implemented

+ added NSAutoReleasePools where necessary, this fixes some memory-leaks
+ fixed some crashes and thread-issues"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgViewer/api/Cocoa/GraphicsWindowCocoa

    r9879 r10208  
    2424#ifdef __OBJC__ 
    2525@class GraphicsWindowCocoaWindow; 
     26@class GraphicsWindowCocoaGLView; 
    2627@class NSOpenGLContext; 
    2728@class NSWindow; 
     29@class NSView; 
    2830#else 
     31class GraphicsWindowCocoaGLView; 
    2932class GraphicsWindowCocoaWindow; 
    3033class NSOpenGLContext; 
    3134class NSWindow; 
     35class NSView; 
    3236#endif 
    3337 
     
    4246{ 
    4347    public: 
    44         class Implementation; 
     48    class Implementation; 
    4549 
    4650        GraphicsWindowCocoa(osg::GraphicsContext::Traits* traits): 
     
    4852            _initialized(false), 
    4953            _realized(false), 
     54            _closeRequested(false), 
     55            _checkForEvents(true), 
    5056            _ownsWindow(true), 
    51             _currentCursor(RightArrowCursor) 
     57            _currentCursor(RightArrowCursor), 
     58            _window(NULL), 
     59            _context(NULL) 
    5260        { 
    5361            _traits = traits; 
     
    122130        { 
    123131            public: 
    124                 WindowData(NSWindow* window) 
    125                                 :       _window(window)  
    126                                 { 
    127                                 } 
    128                  
    129                 inline NSWindow* getNativeWindowRef() { return _window; } 
    130                                  
     132                enum Options { CreateOnlyView = 1, CheckForEvents = 2, PoseAsStandaloneApp = 4}; 
     133                WindowData(unsigned int options) 
     134                :    _createOnlyView(options & CreateOnlyView), 
     135                    _checkForEvents(options & CheckForEvents), 
     136                    _poseAsStandaloneApp(options & PoseAsStandaloneApp), 
     137                    _view(NULL) 
     138                { 
     139                } 
     140                             
     141                inline NSView* getCreatedNSView() { return _view; } 
     142                bool createOnlyView() const { return _createOnlyView; } 
     143                bool checkForEvents() const { return _checkForEvents; } 
     144                bool poseAsStandaloneApp() const { return _poseAsStandaloneApp; } 
     145             
     146            protected: 
     147                inline void setCreatedNSView(NSView* view) { _view = view; } 
     148             
    131149            private: 
    132                 NSWindow*    _window; 
    133                 bool         _installEventHandler; 
     150                bool         _createOnlyView, _checkForEvents, _poseAsStandaloneApp; 
     151                NSView*         _view; 
    134152             
     153            friend class GraphicsWindowCocoa; 
     154 
    135155        }; 
    136156         
     
    139159                 
    140160        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); 
     161         
     162        /** adapts a resize / move of the window, coords in global screen space */ 
     163        void adaptResize(int x, int y, int w, int h); 
    144164         
    145165    protected: 
     
    158178        bool            _realized; 
    159179        bool            _useWindowDecoration; 
    160         bool            _ownsWindow; 
    161180 
    162          
     181     
    163182          
    164183    private:         
    165184        
    166185         
    167         bool                            _closeRequested; 
    168         MouseCursor                     _currentCursor; 
    169                 GraphicsWindowCocoaWindow* _window; 
    170                 NSOpenGLContext*        _context; 
     186        bool                _closeRequested, _checkForEvents,_ownsWindow; 
     187        MouseCursor            _currentCursor; 
     188        GraphicsWindowCocoaWindow* _window; 
     189        GraphicsWindowCocoaGLView*    _view; 
     190        NSOpenGLContext*    _context; 
    171191}; 
    172192