root/OpenSceneGraph/trunk/src/osgViewer/DarwinUtils.h @ 10208

Revision 10208, 4.7 kB (checked in by robert, 5 years ago)

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"

  • Property svn:executable set to *
RevLine 
[9879]1/*
2 *  DarwinUtils.h
3 *  OpenSceneGraph
4 *
5 *  Created by Stephan Huber on 27.06.08.
6 *  Copyright 2008 Stephan Maximilian Huber, digital mind. All rights reserved.
7 *
8 */
9
10#ifdef __APPLE__
11 
12#ifndef DARWIN_UTILS_HEADER_
13#define DARWIN_UTILS_HEADER_
14
15#include <osg/DeleteHandler>
16#include <osg/GraphicsContext>
17#include <osgViewer/GraphicsWindow>
18#include <Carbon/Carbon.h>
19
20
21//#define USE_DARWIN_COCOA_IMPLEMENTATION 1
22//#define USE_DARWIN_CARBON_IMPLEMENTATION 1
23
24namespace osgDarwin {
25
26
27/** the MenubarController class checks all open windows if they intersect with the menubar / dock and hide the menubar/dock if necessary */
28class MenubarController : public osg::Referenced
29{
30
31    public:
[9895]32        class WindowAdapter : public osg::Referenced {
33           
34            public:
35                WindowAdapter() : osg::Referenced() {}
36               
37                virtual bool valid() = 0;
38                virtual void getWindowBounds(CGRect& rect) = 0;
39                virtual osgViewer::GraphicsWindow* getWindow() = 0;
40               
41            protected:
42                virtual ~WindowAdapter() {}
43        };
44       
[9879]45        MenubarController();       
46        static MenubarController* instance();
47       
48        void attachWindow(WindowAdapter* win);
49        void update();
50        void detachWindow(osgViewer::GraphicsWindow* win);
51       
52    private:
53        typedef std::list< osg::ref_ptr< WindowAdapter > > WindowList;
[9895]54        WindowList          _list;
55        bool                _menubarShown;
56        CGRect              _availRect;
57        CGRect              _mainScreenBounds;
58        OpenThreads::Mutex  _mutex;
[9879]59       
60};
61
62
63
64struct DarwinWindowingSystemInterface : public osg::GraphicsContext::WindowingSystemInterface
65{
66    public:
[9895]67        DarwinWindowingSystemInterface();
[9879]68
[9895]69        /** dtor */
70        ~DarwinWindowingSystemInterface();
[9879]71
[9895]72        /** @return a CGDirectDisplayID for a ScreenIdentifier */
73        CGDirectDisplayID getDisplayID(const osg::GraphicsContext::ScreenIdentifier& si);
[9879]74
[9895]75        /** @return count of attached screens */
76        virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si) ;
77
78        virtual void getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution);
79
80        virtual void enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, osg::GraphicsContext::ScreenSettingsList & resolutionList);
[10208]81       
82        virtual bool setScreenSettings (const osg::GraphicsContext::ScreenIdentifier & si, const osg::GraphicsContext::ScreenSettings & settings);
[9895]83
84        /** return the top left coord of a specific screen in global screen space */
85        void getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y);
86
[10208]87       
[9895]88
89        /** returns screen-ndx containing rect x,y,w,h */
90        unsigned int getScreenContaining(int x, int y, int w, int h);
[9879]91   
[9895]92    protected:
93   
[10208]94        /** implementation of setScreenResolution */
95        bool setScreenResolutionImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) ;
96
97        /** implementation of setScreenRefreshRate */
98        bool setScreenRefreshRateImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate);
99
100   
[9895]101        template<class PixelBufferImplementation, class GraphicsWindowImplementation>
102        osg::GraphicsContext* createGraphicsContextImplementation(osg::GraphicsContext::Traits* traits)
103        {
104            if (traits->pbuffer)
105            {
106                osg::ref_ptr<PixelBufferImplementation> pbuffer = new PixelBufferImplementation(traits);
107                if (pbuffer->valid()) return pbuffer.release();
108                else return 0;
109            }
110            else
111            {
112                osg::ref_ptr<GraphicsWindowImplementation> window = new GraphicsWindowImplementation(traits);
113                if (window->valid()) return window.release();
114                else return 0;
115            }
116        }
117   
118   
119    private:
[9879]120        CGDisplayCount        _displayCount;
121        CGDirectDisplayID*    _displayIds;
122
123
124};
125
126template <class WSI>
127struct RegisterWindowingSystemInterfaceProxy
128{
129    RegisterWindowingSystemInterfaceProxy()
130    {
131        osg::GraphicsContext::setWindowingSystemInterface(new WSI);
132    }
133
134    ~RegisterWindowingSystemInterfaceProxy()
135    {
136        if (osg::Referenced::getDeleteHandler())
137        {
138            osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0);
139            osg::Referenced::getDeleteHandler()->flushAll();
140        }
141
142        osg::GraphicsContext::setWindowingSystemInterface(0);
143    }
144};
145
146
147
148}
149
150#endif
151
[9895]152#endif // __APPLE__
Note: See TracBrowser for help on using the browser.