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

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

Changed private: to protected: to fix build issue under OSX

  • 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:
[11207]93
94        virtual void _init();
95
[10208]96        /** implementation of setScreenResolution */
97        bool setScreenResolutionImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) ;
98
99        /** implementation of setScreenRefreshRate */
100        bool setScreenRefreshRateImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate);
101
102   
[9895]103        template<class PixelBufferImplementation, class GraphicsWindowImplementation>
104        osg::GraphicsContext* createGraphicsContextImplementation(osg::GraphicsContext::Traits* traits)
105        {
106            if (traits->pbuffer)
107            {
108                osg::ref_ptr<PixelBufferImplementation> pbuffer = new PixelBufferImplementation(traits);
109                if (pbuffer->valid()) return pbuffer.release();
110                else return 0;
111            }
112            else
113            {
114                osg::ref_ptr<GraphicsWindowImplementation> window = new GraphicsWindowImplementation(traits);
115                if (window->valid()) return window.release();
116                else return 0;
117            }
118        }
[11207]119
[11273]120    protected:
121
[11207]122        bool                  _initialized;
[9879]123        CGDisplayCount        _displayCount;
124        CGDirectDisplayID*    _displayIds;
125
126
127};
128
129template <class WSI>
130struct RegisterWindowingSystemInterfaceProxy
131{
132    RegisterWindowingSystemInterfaceProxy()
133    {
134        osg::GraphicsContext::setWindowingSystemInterface(new WSI);
135    }
136
137    ~RegisterWindowingSystemInterfaceProxy()
138    {
139        if (osg::Referenced::getDeleteHandler())
140        {
141            osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0);
142            osg::Referenced::getDeleteHandler()->flushAll();
143        }
144
145        osg::GraphicsContext::setWindowingSystemInterface(0);
146    }
147};
148
149
150
151}
152
153#endif
154
[9895]155#endif // __APPLE__
Note: See TracBrowser for help on using the browser.