PageRenderTime 48ms CodeModel.GetById 9ms app.highlight 34ms 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
  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
 27#ifndef LL_LLWINDOWSDL_H
 28#define LL_LLWINDOWSDL_H
 29
 30// Simple Directmedia Layer (http://libsdl.org/) implementation of LLWindow class
 31
 32#include "llwindow.h"
 33#include "lltimer.h"
 34
 35#include "SDL/SDL.h"
 36#include "SDL/SDL_endian.h"
 37
 38#if LL_X11
 39// get X11-specific headers for use in low-level stuff like copy-and-paste support
 40#include "SDL/SDL_syswm.h"
 41#endif
 42
 43// AssertMacros.h does bad things.
 44#undef verify
 45#undef check
 46#undef require
 47
 48
 49class LLWindowSDL : public LLWindow
 50{
 51public:
 52	/*virtual*/ void show();
 53	/*virtual*/ void hide();
 54	/*virtual*/ void close();
 55	/*virtual*/ BOOL getVisible();
 56	/*virtual*/ BOOL getMinimized();
 57	/*virtual*/ BOOL getMaximized();
 58	/*virtual*/ BOOL maximize();
 59	/*virtual*/ void minimize();
 60	/*virtual*/ void restore();
 61	/*virtual*/ BOOL getFullscreen();
 62	/*virtual*/ BOOL getPosition(LLCoordScreen *position);
 63	/*virtual*/ BOOL getSize(LLCoordScreen *size);
 64	/*virtual*/ BOOL getSize(LLCoordWindow *size);
 65	/*virtual*/ BOOL setPosition(LLCoordScreen position);
 66	/*virtual*/ BOOL setSizeImpl(LLCoordScreen size);
 67	/*virtual*/ BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp = NULL);
 68	/*virtual*/ BOOL setCursorPosition(LLCoordWindow position);
 69	/*virtual*/ BOOL getCursorPosition(LLCoordWindow *position);
 70	/*virtual*/ void showCursor();
 71	/*virtual*/ void hideCursor();
 72	/*virtual*/ void showCursorFromMouseMove();
 73	/*virtual*/ void hideCursorUntilMouseMove();
 74	/*virtual*/ BOOL isCursorHidden();
 75	/*virtual*/ void updateCursor();
 76	/*virtual*/ void captureMouse();
 77	/*virtual*/ void releaseMouse();
 78	/*virtual*/ void setMouseClipping( BOOL b );
 79	/*virtual*/	void setMinSize(U32 min_width, U32 min_height, bool enforce_immediately = true);
 80
 81	/*virtual*/ BOOL isClipboardTextAvailable();
 82	/*virtual*/ BOOL pasteTextFromClipboard(LLWString &dst);
 83	/*virtual*/ BOOL copyTextToClipboard(const LLWString & src);
 84
 85	/*virtual*/ BOOL isPrimaryTextAvailable();
 86	/*virtual*/ BOOL pasteTextFromPrimary(LLWString &dst);
 87	/*virtual*/ BOOL copyTextToPrimary(const LLWString & src);
 88 
 89	/*virtual*/ void flashIcon(F32 seconds);
 90	/*virtual*/ F32 getGamma();
 91	/*virtual*/ BOOL setGamma(const F32 gamma); // Set the gamma
 92	/*virtual*/ U32 getFSAASamples();
 93	/*virtual*/ void setFSAASamples(const U32 samples);
 94	/*virtual*/ BOOL restoreGamma();			// Restore original gamma table (before updating gamma)
 95	/*virtual*/ ESwapMethod getSwapMethod() { return mSwapMethod; }
 96	/*virtual*/ void processMiscNativeEvents();
 97	/*virtual*/ void gatherInput();
 98	/*virtual*/ void swapBuffers();
 99
100	/*virtual*/ void delayInputProcessing() { };
101
102	// handy coordinate space conversion routines
103	/*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordWindow *to);
104	/*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordScreen *to);
105	/*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordGL *to);
106	/*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordWindow *to);
107	/*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordGL *to);
108	/*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordScreen *to);
109
110	/*virtual*/ LLWindowResolution* getSupportedResolutions(S32 &num_resolutions);
111	/*virtual*/ F32	getNativeAspectRatio();
112	/*virtual*/ F32 getPixelAspectRatio();
113	/*virtual*/ void setNativeAspectRatio(F32 ratio) { mOverrideAspectRatio = ratio; }
114
115	/*virtual*/ void beforeDialog();
116	/*virtual*/ void afterDialog();
117
118	/*virtual*/ BOOL dialogColorPicker(F32 *r, F32 *g, F32 *b);
119
120	/*virtual*/ void *getPlatformWindow();
121	/*virtual*/ void bringToFront();
122
123	/*virtual*/ void spawnWebBrowser(const std::string& escaped_url, bool async);
124	
125	static std::vector<std::string> getDynamicFallbackFontList();
126
127	// Not great that these are public, but they have to be accessible
128	// by non-class code and it's better than making them global.
129#if LL_X11
130	Window mSDL_XWindowID;
131	Display *mSDL_Display;
132#endif
133	void (*Lock_Display)(void);
134	void (*Unlock_Display)(void);
135
136#if LL_GTK
137	// Lazily initialize and check the runtime GTK version for goodness.
138	static bool ll_try_gtk_init(void);
139#endif // LL_GTK
140
141#if LL_X11
142	static Window get_SDL_XWindowID(void);
143	static Display* get_SDL_Display(void);
144#endif // LL_X11	
145
146protected:
147	LLWindowSDL(LLWindowCallbacks* callbacks,
148		const std::string& title, int x, int y, int width, int height, U32 flags,
149		BOOL fullscreen, BOOL clearBg, BOOL disable_vsync, BOOL use_gl,
150		BOOL ignore_pixel_depth, U32 fsaa_samples);
151	~LLWindowSDL();
152
153	/*virtual*/ BOOL	isValid();
154	/*virtual*/ LLSD    getNativeKeyData();
155
156	void	initCursors();
157	void	quitCursors();
158	void	moveWindow(const LLCoordScreen& position,const LLCoordScreen& size);
159
160	// Changes display resolution. Returns true if successful
161	BOOL	setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh);
162
163	// Go back to last fullscreen display resolution.
164	BOOL	setFullscreenResolution();
165
166	BOOL	shouldPostQuit() { return mPostQuit; }
167
168protected:
169	//
170	// Platform specific methods
171	//
172
173	// create or re-create the GL context/window.  Called from the constructor and switchContext().
174	BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync);
175	void destroyContext();
176	void setupFailure(const std::string& text, const std::string& caption, U32 type);
177	void fixWindowSize(void);
178	U32 SDLCheckGrabbyKeys(SDLKey keysym, BOOL gain);
179	BOOL SDLReallyCaptureInput(BOOL capture);
180
181	//
182	// Platform specific variables
183	//
184	U32             mGrabbyKeyFlags;
185	int			mReallyCapturedCount;
186	SDL_Surface *	mWindow;
187	std::string mWindowTitle;
188	double		mOriginalAspectRatio;
189	BOOL		mNeedsResize;		// Constructor figured out the window is too big, it needs a resize.
190	LLCoordScreen   mNeedsResizeSize;
191	F32			mOverrideAspectRatio;
192	F32		mGamma;
193	U32		mFSAASamples;
194
195	int		mSDLFlags;
196
197	SDL_Cursor*	mSDLCursors[UI_CURSOR_COUNT];
198	int             mHaveInputFocus; /* 0=no, 1=yes, else unknown */
199	int             mIsMinimized; /* 0=no, 1=yes, else unknown */
200
201	friend class LLWindowManager;
202
203private:
204#if LL_X11
205	void x11_set_urgent(BOOL urgent);
206	BOOL mFlashing;
207	LLTimer mFlashTimer;
208#endif //LL_X11
209	
210	U32 mKeyScanCode;
211        U32 mKeyVirtualKey;
212	SDLMod mKeyModifiers;
213};
214
215
216class LLSplashScreenSDL : public LLSplashScreen
217{
218public:
219	LLSplashScreenSDL();
220	virtual ~LLSplashScreenSDL();
221
222	/*virtual*/ void showImpl();
223	/*virtual*/ void updateImpl(const std::string& mesg);
224	/*virtual*/ void hideImpl();
225};
226
227S32 OSMessageBoxSDL(const std::string& text, const std::string& caption, U32 type);
228
229#endif //LL_LLWINDOWSDL_H