macWindow.h
Engine/source/windowManager/mac/macWindow.h
Classes:
class
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _TORQUE_MACWINDOW_H_ 25#define _TORQUE_MACWINDOW_H_ 26 27#include "windowManager/platformWindow.h" 28#include "windowManager/mac/macWindowManager.h" 29#include "windowManager/mac/macCursorController.h" 30 31#ifndef _GFXTARGET_H_ 32#include "gfx/gfxTarget.h" 33#endif 34 35#ifndef _GFXSTRUCTS_H_ 36#include "gfx/gfxStructs.h" 37#endif 38 39class MacWindow : public PlatformWindow 40{ 41public: 42 virtual ~MacWindow(); 43 44 virtual GFXDevice *getGFXDevice() { return mDevice; } 45 virtual GFXWindowTarget *getGFXTarget() { return mTarget; } 46 virtual void _setVideoMode(const GFXVideoMode &mode); 47 virtual const GFXVideoMode &getVideoMode() { return mCurrentMode; } 48 49 virtual WindowId getWindowId() { return mWindowId; } 50 51 void setDisplay(CGDirectDisplayID display); 52 CGDirectDisplayID getDisplay() { return mDisplay; } 53 CGRect getMainDisplayBounds() { return mMainDisplayBounds; } 54 CGRect getDisplayBounds() { return mDisplayBounds; } 55 56 virtual bool clearFullscreen() 57 { 58 // TODO: properly drop out of full screen 59 return true; 60 } 61 virtual bool isFullscreen() { return mFullscreen; } 62 63 virtual PlatformWindow * getNextWindow() const; 64 65 virtual void setMouseLocked( bool enable ) 66 { 67 mShouldMouseLock = enable; 68 if(isFocused()) 69 _doMouseLockNow(); 70 } 71 virtual bool isMouseLocked() const { return mMouseLocked; } 72 virtual bool shouldLockMouse() const { return mShouldMouseLock; } 73 74 virtual bool setSize(const Point2I &newSize); 75 76 virtual void setClientExtent( const Point2I newExtent ); 77 virtual const Point2I getClientExtent(); 78 79 virtual void setBounds( const RectI &newBounds ); 80 virtual const RectI getBounds() const; 81 82 virtual void setPosition( const Point2I newPosition ); 83 virtual const Point2I getPosition(); 84 85 virtual void centerWindow(); 86 87 virtual Point2I clientToScreen( const Point2I& pos ); 88 virtual Point2I screenToClient( const Point2I& pos ); 89 90 virtual bool setCaption(const char *windowText); 91 virtual const char *getCaption() { return mTitle; } 92 93 virtual bool setType( S32 windowType ) { return true; } 94 95 virtual void minimize(); 96 virtual void maximize(); 97 virtual void restore(); 98 virtual bool isMinimized(); 99 virtual bool isMaximized(); 100 virtual void show(); 101 virtual void close(); 102 virtual void hide(); 103 virtual bool isOpen(); 104 virtual bool isVisible(); 105 106 virtual bool isFocused(); 107 virtual void setFocus(); 108 virtual void clearFocus(); 109 110 virtual void* getPlatformDrawable() const; 111 112 // TODO: These should be private, but GGMacView (an Obj-C class) needs access to these and we can't friend Obj-C classes 113 bool _skipNextMouseEvent() { return mSkipMouseEvents != 0; } 114 void _skipAnotherMouseEvent() { mSkipMouseEvents++; } 115 void _skippedMouseEvent() { mSkipMouseEvents--; } 116 117 /// Does the work of actually locking or unlocking the mouse, based on the 118 /// value of shouldLockMouse(). 119 /// 120 /// Disassociates the cursor movement from the mouse input and hides the mouse 121 /// when locking. Re-associates cursor movement with mouse input and shows the 122 /// mouse when unlocking. 123 /// 124 /// Returns true if we locked or unlocked the mouse. Returns false if the mouse 125 /// was already in the correct state. 126 void _doMouseLockNow(); 127 128 // Helper methods for doMouseLockNow 129 void _associateMouse(); 130 void _dissociateMouse(); 131 void _centerMouse(); 132 133 // For GGMacView 134 void _disassociateCocoaWindow(); 135 136 // Safari support methods 137 static void setSafariWindow(NSWindow *window, S32 x = 0, S32 y = 0, S32 width = 0, S32 height = 0); 138 static void hideBrowserWindow(bool hide); 139 140protected: 141 virtual void _setFullscreen(bool fullScreen); 142 143private: 144 friend class MacWindowManager; 145 friend class MacCursorController; 146 147 struct SafariWindowInfo 148 { 149 NSWindow* safariWindow; /* The Safari Browser Window */ 150 S32 x; /* Position of top left corner relative */ 151 S32 y; /* to a safari page. */ 152 U32 width; /* Maximum window size */ 153 U32 height; 154 }; 155 156 MacWindow(U32 windowId, const char* windowText, Point2I clientExtent); 157 158 void _initCocoaWindow(const char* windowText, Point2I clientExtent); 159 void setWindowId(U32 newid) { mWindowId = newid;} 160 void signalGainFocus(); 161 162 static SafariWindowInfo* sSafariWindowInfo; 163 static MacWindow* sInstance; 164 165 NSWindow* mCocoaWindow; 166 GFXDevice *mDevice; 167 GFXWindowTargetRef mTarget; 168 GFXVideoMode mCurrentMode; 169 170 MacWindow *mNextWindow; 171 172 bool mMouseLocked; 173 bool mShouldMouseLock; 174 175 const char* mTitle; 176 bool mMouseCaptured; 177 178 MacWindowManager* mOwningWindowManager; 179 U32 mSkipMouseEvents; 180 181 bool mFullscreen; 182 bool mShouldFullscreen; 183 NSDictionary* mDefaultDisplayMode; 184 185 void _onAppEvent(WindowId,S32); 186 187 CGDirectDisplayID mDisplay; 188 CGRect mDisplayBounds; 189 CGRect mMainDisplayBounds; 190}; 191 192#endif 193