platformWindowMgr.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 _PLATFORM_PLATFORMWINDOWMGR_H_
  23. #define _PLATFORM_PLATFORMWINDOWMGR_H_
  24. #include "math/mRect.h"
  25. #include "core/util/journal/journaledSignal.h"
  26. #include "windowManager/platformWindow.h"
  27. // Global macro
  28. #define WindowManager PlatformWindowManager::get()
  29. /// Abstract representation of a manager for native OS windows.
  30. ///
  31. /// The PlatformWindowManager interface provides a variety of methods for querying
  32. /// the current desktop configuration, as well as allocating and retrieving
  33. /// existing windows. It may also manage application-level event handling.
  34. class PlatformWindowManager
  35. {
  36. // Generator for window IDs.
  37. S32 mIdSource;
  38. protected:
  39. /// Get the next available window Id
  40. inline S32 getNextId() { return mIdSource++; }
  41. public:
  42. /// Get Global Singleton
  43. static PlatformWindowManager *get();
  44. PlatformWindowManager() : mIdSource(0) {};
  45. virtual ~PlatformWindowManager()
  46. {
  47. }
  48. static void processCmdLineArgs(const S32 argc, const char **argv);
  49. /// Return the extents in window coordinates of the primary desktop
  50. /// area. On a single monitor system this is just the display extents.
  51. /// On a multimon system this is the primary monitor (which Torque should
  52. /// launch on).
  53. virtual RectI getPrimaryDesktopArea() = 0;
  54. /// Retrieve the currently set desktop bit depth
  55. /// @return The current desktop bit depth, or -1 if an error occurred
  56. virtual S32 getDesktopBitDepth() = 0;
  57. /// Retrieve the currently set desktop resolution
  58. /// @return The current desktop bit depth, or Point2I(-1,-1) if an error occurred
  59. virtual Point2I getDesktopResolution() = 0;
  60. // Build out the monitor list.
  61. virtual void buildMonitorsList() {}
  62. // Find the first monitor index that matches the given name. The actual match
  63. // algorithm depends on the implementation. Provides a default value of -1 to
  64. // indicate no match.
  65. virtual S32 findFirstMatchingMonitor(const char* name) { return -1; }
  66. // Retrieve the number of monitors. Provides a default count of 0 for systems that
  67. // don't provide information on connected monitors.
  68. virtual U32 getMonitorCount() { return 0; }
  69. // Get the name of the requested monitor. Provides a default of "" for platorms
  70. // that do not provide information on connected monitors.
  71. virtual const char* getMonitorName(U32 index) { return ""; }
  72. // Get the requested monitor's rectangular region.
  73. virtual RectI getMonitorRect(U32 index) { return RectI(0, 0, 0, 0); }
  74. // Get the requested monitor's rectangular region.
  75. // Use this function to get the usable desktop area represented by a display,
  76. // with the primary display located at 0,0.
  77. virtual RectI getMonitorUsableRect(U32 index) { return RectI(0, 0, 0, 0); }
  78. // Retrieve the number of display modes available on a monitor. Provides a default
  79. // count of 0 for systems that don't provide information on connected monitors.
  80. virtual U32 getMonitorModeCount(U32 monitorIndex) { return 0; }
  81. // Gets a display mode for a specific monitor. Provides a default of "" for platorms
  82. // that do not provide information on connected monitors.
  83. virtual const String getMonitorMode(U32 monitorIndex, U32 modeIndex) { return String::EmptyString; }
  84. // Gets the current desktop display mode for a specific monitor. Provides a default
  85. // of "" for platorms that do not provide information on connected monitors.
  86. virtual const String getMonitorDesktopMode(U32 monitorIndex) { return String::EmptyString; }
  87. /// Populate a vector with all monitors and their extents in window space.
  88. virtual void getMonitorRegions(Vector<RectI> &regions) = 0;
  89. /// Create a new window, appropriate for the specified device and mode.
  90. ///
  91. /// @return Pointer to the new window.
  92. virtual PlatformWindow *createWindow(GFXDevice *device, const GFXVideoMode &mode) = 0;
  93. /// Populate a list with references to all the windows created from this manager.
  94. virtual void getWindows(VectorPtr<PlatformWindow*> &windows) = 0;
  95. /// Get the window that currently has the input focus or NULL.
  96. virtual PlatformWindow* getFocusedWindow() = 0;
  97. /// Get a window from a device ID.
  98. ///
  99. /// @return The window associated with the specified ID, or NULL if no
  100. /// match was found.
  101. virtual PlatformWindow *getWindowById(WindowId id)=0;
  102. /// Get the first window in the window list
  103. ///
  104. /// @return The first window in the list, or NULL if no windows found
  105. virtual PlatformWindow *getFirstWindow()=0;
  106. /// Set the parent window
  107. ///
  108. /// This can be used to render in a child window.
  109. virtual void setParentWindow(void* newParent) = 0;
  110. /// Get the parent window
  111. virtual void* getParentWindow() = 0;
  112. /// This method cues the appearance of that window ("lowering the curtain").
  113. virtual void lowerCurtain()=0;
  114. /// @see lowerCurtain
  115. ///
  116. /// This method removes the curtain window.
  117. virtual void raiseCurtain()=0;
  118. /// This method indicates to created windows to show as normal.
  119. virtual void setDisplayWindow(bool set){}
  120. private:
  121. /// Process command line arguments from StandardMainLoop. This is done to
  122. /// allow web plugin functionality, where we are passed platform-specific
  123. /// information allowing us to set ourselves up in the web browser,
  124. /// to occur in a platform-neutral way.
  125. virtual void _processCmdLineArgs(const S32 argc, const char **argv)=0;
  126. };
  127. /// Global function to allocate a new platform window manager.
  128. ///
  129. /// This returns an instance of the appropriate window manager for the current OS.
  130. ///
  131. /// Depending on situation (for instance, if we are a web plugin) we may
  132. /// need to get the window manager from somewhere else.
  133. PlatformWindowManager *CreatePlatformWindowManager();
  134. #endif