platformWindowMgr.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. /// Populate a vector with all monitors and their extents in window space.
  75. virtual void getMonitorRegions(Vector<RectI> &regions) = 0;
  76. /// Create a new window, appropriate for the specified device and mode.
  77. ///
  78. /// @return Pointer to the new window.
  79. virtual PlatformWindow *createWindow(GFXDevice *device, const GFXVideoMode &mode) = 0;
  80. /// Populate a list with references to all the windows created from this manager.
  81. virtual void getWindows(VectorPtr<PlatformWindow*> &windows) = 0;
  82. /// Get the window that currently has the input focus or NULL.
  83. virtual PlatformWindow* getFocusedWindow() = 0;
  84. /// Get a window from a device ID.
  85. ///
  86. /// @return The window associated with the specified ID, or NULL if no
  87. /// match was found.
  88. virtual PlatformWindow *getWindowById(WindowId id)=0;
  89. /// Get the first window in the window list
  90. ///
  91. /// @return The first window in the list, or NULL if no windows found
  92. virtual PlatformWindow *getFirstWindow()=0;
  93. /// Set the parent window
  94. ///
  95. /// This can be used to render in a child window.
  96. virtual void setParentWindow(void* newParent) = 0;
  97. /// Get the parent window
  98. virtual void* getParentWindow() = 0;
  99. /// This method cues the appearance of that window ("lowering the curtain").
  100. virtual void lowerCurtain()=0;
  101. /// @see lowerCurtain
  102. ///
  103. /// This method removes the curtain window.
  104. virtual void raiseCurtain()=0;
  105. /// This method indicates to created windows to show as normal.
  106. virtual void setDisplayWindow(bool set){}
  107. private:
  108. /// Process command line arguments from StandardMainLoop. This is done to
  109. /// allow web plugin functionality, where we are passed platform-specific
  110. /// information allowing us to set ourselves up in the web browser,
  111. /// to occur in a platform-neutral way.
  112. virtual void _processCmdLineArgs(const S32 argc, const char **argv)=0;
  113. };
  114. /// Global function to allocate a new platform window manager.
  115. ///
  116. /// This returns an instance of the appropriate window manager for the current OS.
  117. ///
  118. /// Depending on situation (for instance, if we are a web plugin) we may
  119. /// need to get the window manager from somewhere else.
  120. PlatformWindowManager *CreatePlatformWindowManager();
  121. #endif