PageRenderTime 20ms CodeModel.GetById 5ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llwindow/llwindowsdl.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 229 lines | 147 code | 41 blank | 41 comment | 0 complexity | 302ba252b2aa17a41c1268e8bc220b74 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llwindowsdl.h
  3. * @brief SDL implementation of LLWindow class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLWINDOWSDL_H
  27. #define LL_LLWINDOWSDL_H
  28. // Simple Directmedia Layer (http://libsdl.org/) implementation of LLWindow class
  29. #include "llwindow.h"
  30. #include "lltimer.h"
  31. #include "SDL/SDL.h"
  32. #include "SDL/SDL_endian.h"
  33. #if LL_X11
  34. // get X11-specific headers for use in low-level stuff like copy-and-paste support
  35. #include "SDL/SDL_syswm.h"
  36. #endif
  37. // AssertMacros.h does bad things.
  38. #undef verify
  39. #undef check
  40. #undef require
  41. class LLWindowSDL : public LLWindow
  42. {
  43. public:
  44. /*virtual*/ void show();
  45. /*virtual*/ void hide();
  46. /*virtual*/ void close();
  47. /*virtual*/ BOOL getVisible();
  48. /*virtual*/ BOOL getMinimized();
  49. /*virtual*/ BOOL getMaximized();
  50. /*virtual*/ BOOL maximize();
  51. /*virtual*/ void minimize();
  52. /*virtual*/ void restore();
  53. /*virtual*/ BOOL getFullscreen();
  54. /*virtual*/ BOOL getPosition(LLCoordScreen *position);
  55. /*virtual*/ BOOL getSize(LLCoordScreen *size);
  56. /*virtual*/ BOOL getSize(LLCoordWindow *size);
  57. /*virtual*/ BOOL setPosition(LLCoordScreen position);
  58. /*virtual*/ BOOL setSizeImpl(LLCoordScreen size);
  59. /*virtual*/ BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp = NULL);
  60. /*virtual*/ BOOL setCursorPosition(LLCoordWindow position);
  61. /*virtual*/ BOOL getCursorPosition(LLCoordWindow *position);
  62. /*virtual*/ void showCursor();
  63. /*virtual*/ void hideCursor();
  64. /*virtual*/ void showCursorFromMouseMove();
  65. /*virtual*/ void hideCursorUntilMouseMove();
  66. /*virtual*/ BOOL isCursorHidden();
  67. /*virtual*/ void updateCursor();
  68. /*virtual*/ void captureMouse();
  69. /*virtual*/ void releaseMouse();
  70. /*virtual*/ void setMouseClipping( BOOL b );
  71. /*virtual*/ void setMinSize(U32 min_width, U32 min_height, bool enforce_immediately = true);
  72. /*virtual*/ BOOL isClipboardTextAvailable();
  73. /*virtual*/ BOOL pasteTextFromClipboard(LLWString &dst);
  74. /*virtual*/ BOOL copyTextToClipboard(const LLWString & src);
  75. /*virtual*/ BOOL isPrimaryTextAvailable();
  76. /*virtual*/ BOOL pasteTextFromPrimary(LLWString &dst);
  77. /*virtual*/ BOOL copyTextToPrimary(const LLWString & src);
  78. /*virtual*/ void flashIcon(F32 seconds);
  79. /*virtual*/ F32 getGamma();
  80. /*virtual*/ BOOL setGamma(const F32 gamma); // Set the gamma
  81. /*virtual*/ U32 getFSAASamples();
  82. /*virtual*/ void setFSAASamples(const U32 samples);
  83. /*virtual*/ BOOL restoreGamma(); // Restore original gamma table (before updating gamma)
  84. /*virtual*/ ESwapMethod getSwapMethod() { return mSwapMethod; }
  85. /*virtual*/ void processMiscNativeEvents();
  86. /*virtual*/ void gatherInput();
  87. /*virtual*/ void swapBuffers();
  88. /*virtual*/ void delayInputProcessing() { };
  89. // handy coordinate space conversion routines
  90. /*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordWindow *to);
  91. /*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordScreen *to);
  92. /*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordGL *to);
  93. /*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordWindow *to);
  94. /*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordGL *to);
  95. /*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordScreen *to);
  96. /*virtual*/ LLWindowResolution* getSupportedResolutions(S32 &num_resolutions);
  97. /*virtual*/ F32 getNativeAspectRatio();
  98. /*virtual*/ F32 getPixelAspectRatio();
  99. /*virtual*/ void setNativeAspectRatio(F32 ratio) { mOverrideAspectRatio = ratio; }
  100. /*virtual*/ void beforeDialog();
  101. /*virtual*/ void afterDialog();
  102. /*virtual*/ BOOL dialogColorPicker(F32 *r, F32 *g, F32 *b);
  103. /*virtual*/ void *getPlatformWindow();
  104. /*virtual*/ void bringToFront();
  105. /*virtual*/ void spawnWebBrowser(const std::string& escaped_url, bool async);
  106. static std::vector<std::string> getDynamicFallbackFontList();
  107. // Not great that these are public, but they have to be accessible
  108. // by non-class code and it's better than making them global.
  109. #if LL_X11
  110. Window mSDL_XWindowID;
  111. Display *mSDL_Display;
  112. #endif
  113. void (*Lock_Display)(void);
  114. void (*Unlock_Display)(void);
  115. #if LL_GTK
  116. // Lazily initialize and check the runtime GTK version for goodness.
  117. static bool ll_try_gtk_init(void);
  118. #endif // LL_GTK
  119. #if LL_X11
  120. static Window get_SDL_XWindowID(void);
  121. static Display* get_SDL_Display(void);
  122. #endif // LL_X11
  123. protected:
  124. LLWindowSDL(LLWindowCallbacks* callbacks,
  125. const std::string& title, int x, int y, int width, int height, U32 flags,
  126. BOOL fullscreen, BOOL clearBg, BOOL disable_vsync, BOOL use_gl,
  127. BOOL ignore_pixel_depth, U32 fsaa_samples);
  128. ~LLWindowSDL();
  129. /*virtual*/ BOOL isValid();
  130. /*virtual*/ LLSD getNativeKeyData();
  131. void initCursors();
  132. void quitCursors();
  133. void moveWindow(const LLCoordScreen& position,const LLCoordScreen& size);
  134. // Changes display resolution. Returns true if successful
  135. BOOL setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh);
  136. // Go back to last fullscreen display resolution.
  137. BOOL setFullscreenResolution();
  138. BOOL shouldPostQuit() { return mPostQuit; }
  139. protected:
  140. //
  141. // Platform specific methods
  142. //
  143. // create or re-create the GL context/window. Called from the constructor and switchContext().
  144. BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync);
  145. void destroyContext();
  146. void setupFailure(const std::string& text, const std::string& caption, U32 type);
  147. void fixWindowSize(void);
  148. U32 SDLCheckGrabbyKeys(SDLKey keysym, BOOL gain);
  149. BOOL SDLReallyCaptureInput(BOOL capture);
  150. //
  151. // Platform specific variables
  152. //
  153. U32 mGrabbyKeyFlags;
  154. int mReallyCapturedCount;
  155. SDL_Surface * mWindow;
  156. std::string mWindowTitle;
  157. double mOriginalAspectRatio;
  158. BOOL mNeedsResize; // Constructor figured out the window is too big, it needs a resize.
  159. LLCoordScreen mNeedsResizeSize;
  160. F32 mOverrideAspectRatio;
  161. F32 mGamma;
  162. U32 mFSAASamples;
  163. int mSDLFlags;
  164. SDL_Cursor* mSDLCursors[UI_CURSOR_COUNT];
  165. int mHaveInputFocus; /* 0=no, 1=yes, else unknown */
  166. int mIsMinimized; /* 0=no, 1=yes, else unknown */
  167. friend class LLWindowManager;
  168. private:
  169. #if LL_X11
  170. void x11_set_urgent(BOOL urgent);
  171. BOOL mFlashing;
  172. LLTimer mFlashTimer;
  173. #endif //LL_X11
  174. U32 mKeyScanCode;
  175. U32 mKeyVirtualKey;
  176. SDLMod mKeyModifiers;
  177. };
  178. class LLSplashScreenSDL : public LLSplashScreen
  179. {
  180. public:
  181. LLSplashScreenSDL();
  182. virtual ~LLSplashScreenSDL();
  183. /*virtual*/ void showImpl();
  184. /*virtual*/ void updateImpl(const std::string& mesg);
  185. /*virtual*/ void hideImpl();
  186. };
  187. S32 OSMessageBoxSDL(const std::string& text, const std::string& caption, U32 type);
  188. #endif //LL_LLWINDOWSDL_H