platformMacCarb.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _PLATFORMMACCARB_H_
  23. #define _PLATFORMMACCARB_H_
  24. /// NOTE: Placing system headers before Torque's platform.h will work around the Torque-Redefines-New problems.
  25. #include <Carbon/Carbon.h>
  26. #include <CoreServices/CoreServices.h>
  27. #include "platform/platform.h"
  28. #include "math/mMath.h"
  29. #include "gfx/gl/ggl/ggl.h"
  30. #define __gl_h_
  31. #include <AGL/agl.h>
  32. class MacCarbPlatState
  33. {
  34. public:
  35. GDHandle hDisplay;
  36. CGDirectDisplayID cgDisplay;
  37. bool captureDisplay;
  38. bool fadeWindows;
  39. WindowPtr appWindow;
  40. char appWindowTitle[256];
  41. WindowGroupRef torqueWindowGroup;
  42. bool quit;
  43. AGLContext ctx;
  44. bool ctxNeedsUpdate;
  45. S32 desktopBitsPixel;
  46. S32 desktopWidth;
  47. S32 desktopHeight;
  48. U32 currentTime;
  49. bool isFullScreen;
  50. U32 osVersion;
  51. TSMDocumentID tsmDoc;
  52. bool tsmActive;
  53. U32 firstThreadId;
  54. void* alertSemaphore;
  55. S32 alertHit;
  56. DialogRef alertDlg;
  57. EventQueueRef mainEventQueue;
  58. MRandomLCG platRandom;
  59. bool mouseLocked;
  60. bool backgrounded;
  61. U32 sleepTicks;
  62. Point2I windowSize;
  63. U32 appReturn;
  64. U32 argc;
  65. char** argv;
  66. U32 lastTimeTick;
  67. MacCarbPlatState();
  68. };
  69. /// Global singleton that encapsulates a lot of mac platform state & globals.
  70. extern MacCarbPlatState platState;
  71. /// @name Misc Mac Plat Functions
  72. /// Functions that are used by multiple files in the mac plat, but too trivial
  73. /// to require their own header file.
  74. /// @{
  75. /// Fills gGLState with info about this gl renderer's capabilities.
  76. void getGLCapabilities(void);
  77. /// Creates a new mac window, of a particular size, centered on the screen.
  78. /// If a fullScreen window is requested, then the window is created without
  79. /// decoration, in front of all other normal windows AND BEHIND asian text input methods.
  80. /// This path to a fullScreen window allows asian text input methods to work
  81. /// in full screen mode, because it avoids capturing the display.
  82. WindowPtr MacCarbCreateOpenGLWindow( GDHandle hDevice, U32 width, U32 height, bool fullScreen );
  83. /// Asnychronously fade a window into existence, and set menu bar visibility.
  84. /// The fading can be turned off via the preference $pref::mac::fadeWindows.
  85. /// It also sends itself to the main thread if it is called on any other thread.
  86. void MacCarbFadeInWindow( WindowPtr window );
  87. /// Asnychronously fade a window out of existence. The window will be destroyed
  88. /// when the fade is complete.
  89. /// The fading can be turned off via the preference $pref::mac::fadeWindows.
  90. /// It also sends itself to the main thread if it is called on any other thread.
  91. void MacCarbFadeAndReleaseWindow( WindowPtr window );
  92. /// Translates a Mac keycode to a Torque keycode
  93. U8 TranslateOSKeyCode(U8 vcode);
  94. /// @}
  95. /// @name Misc Mac Plat constants
  96. /// @{
  97. /// earlier versions of OSX don't have these convinience macros, so manually stick them here.
  98. #ifndef IntToFixed
  99. #define IntToFixed(a) ((Fixed)(a) <<16)
  100. #define FixedToInt(a) ((short)(((Fixed)(a) + fixed1/2) >> 16))
  101. #endif
  102. /// window level constants
  103. const U32 kTAlertWindowLevel = CGShieldingWindowLevel() - 1;
  104. const U32 kTUtilityWindowLevel = CGShieldingWindowLevel() - 2;
  105. const U32 kTFullscreenWindowLevel = CGShieldingWindowLevel() - 3;
  106. /// mouse wheel sensitivity factor
  107. const S32 kTMouseWheelMagnificationFactor = 25;
  108. /// Torque Menu Command ID
  109. const U32 kHICommandTorque = 'TORQ';
  110. /// @}
  111. //-----------------------------------------------------------------------------
  112. // Platform Menu Data
  113. //-----------------------------------------------------------------------------
  114. class PlatformPopupMenuData
  115. {
  116. public:
  117. // We assign each new menu item an arbitrary integer tag.
  118. static S32 getTag()
  119. {
  120. static S32 lastTag = 'TORQ';
  121. return ++lastTag;
  122. }
  123. MenuRef mMenu;
  124. S32 tag;
  125. PlatformPopupMenuData()
  126. {
  127. mMenu = NULL;
  128. tag = getTag();
  129. }
  130. ~PlatformPopupMenuData()
  131. {
  132. if(mMenu)
  133. CFRelease(mMenu);
  134. mMenu = NULL;
  135. }
  136. };
  137. #endif //_PLATFORMMACCARB_H_