PageRenderTime 47ms CodeModel.GetById 11ms app.highlight 30ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/llviewerwindow.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 511 lines | 352 code | 88 blank | 71 comment | 1 complexity | 575370677a75e0622e279c98035b72cb MD5 | raw file
  1/** 
  2 * @file llviewerwindow.h
  3 * @brief Description of the LLViewerWindow 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//
 28// A note about X,Y coordinates:
 29//
 30// X coordinates are in pixels, from the left edge of the window client area
 31// Y coordinates are in pixels, from the BOTTOM edge of the window client area
 32//
 33// The Y coordinates therefore match OpenGL window coords, not Windows(tm) window coords.
 34// If Y is from the top, the variable will be called "y_from_top"
 35
 36#ifndef LL_LLVIEWERWINDOW_H
 37#define LL_LLVIEWERWINDOW_H
 38
 39#include "v3dmath.h"
 40#include "v2math.h"
 41#include "llcursortypes.h"
 42#include "llwindowcallbacks.h"
 43#include "lltimer.h"
 44#include "llstat.h"
 45#include "llmousehandler.h"
 46#include "llhandle.h"
 47#include "llinitparam.h"
 48
 49#include <boost/function.hpp>
 50#include <boost/signals2.hpp>
 51#include <boost/scoped_ptr.hpp>
 52
 53
 54class LLView;
 55class LLViewerObject;
 56class LLUUID;
 57class LLProgressView;
 58class LLTool;
 59class LLVelocityBar;
 60class LLPanel;
 61class LLImageRaw;
 62class LLImageFormatted;
 63class LLHUDIcon;
 64class LLWindow;
 65class LLRootView;
 66class LLWindowListener;
 67class LLViewerWindowListener;
 68class LLPopupView;
 69
 70#define PICK_HALF_WIDTH 5
 71#define PICK_DIAMETER (2 * PICK_HALF_WIDTH + 1)
 72
 73class LLPickInfo
 74{
 75public:
 76	typedef enum
 77	{
 78		PICK_OBJECT,
 79		PICK_FLORA,
 80		PICK_LAND,
 81		PICK_ICON,
 82		PICK_PARCEL_WALL,
 83		PICK_INVALID
 84	} EPickType;
 85
 86public:
 87	LLPickInfo();
 88	LLPickInfo(const LLCoordGL& mouse_pos, 
 89		MASK keyboard_mask, 
 90		BOOL pick_transparent, 
 91		BOOL pick_surface_info,
 92		void (*pick_callback)(const LLPickInfo& pick_info));
 93
 94	void fetchResults();
 95	LLPointer<LLViewerObject> getObject() const;
 96	LLUUID getObjectID() const { return mObjectID; }
 97	bool isValid() const { return mPickType != PICK_INVALID; }
 98
 99	static bool isFlora(LLViewerObject* object);
100
101public:
102	LLCoordGL		mMousePt;
103	MASK			mKeyMask;
104	void			(*mPickCallback)(const LLPickInfo& pick_info);
105
106	EPickType		mPickType;
107	LLCoordGL		mPickPt;
108	LLVector3d		mPosGlobal;
109	LLVector3		mObjectOffset;
110	LLUUID			mObjectID;
111	S32				mObjectFace;
112	LLHUDIcon*		mHUDIcon;
113	LLVector3       mIntersection;
114	LLVector2		mUVCoords;
115	LLVector2       mSTCoords;
116	LLCoordScreen	mXYCoords;
117	LLVector3		mNormal;
118	LLVector3		mBinormal;
119	BOOL			mPickTransparent;
120	void		    getSurfaceInfo();
121
122private:
123	void			updateXYCoords();
124
125	BOOL			mWantSurfaceInfo;   // do we populate mUVCoord, mNormal, mBinormal?
126
127};
128
129static const U32 MAX_SNAPSHOT_IMAGE_SIZE = 6 * 1024; // max snapshot image size 6144 * 6144
130
131class LLViewerWindow : public LLWindowCallbacks
132{
133public:
134	//
135	// CREATORS
136	//
137	struct Params : public LLInitParam::Block<Params>
138	{
139		Mandatory<std::string>		title,
140									name;
141		Mandatory<S32>				x,
142									y,
143									width,
144									height,
145									min_width,
146									min_height;
147		Optional<bool>				fullscreen,
148									ignore_pixel_depth;
149
150		Params();
151	};
152
153	LLViewerWindow(const Params& p);
154	virtual ~LLViewerWindow();
155
156	void			shutdownViews();
157	void			shutdownGL();
158	
159	void			initGLDefaults();
160	void			initBase();
161	void			adjustRectanglesForFirstUse(const LLRect& window);
162	void            adjustControlRectanglesForFirstUse(const LLRect& window);
163	void			initWorldUI();
164	void			setUIVisibility(bool);
165	bool			getUIVisibility();
166
167	BOOL handleAnyMouseClick(LLWindow *window,  LLCoordGL pos, MASK mask, LLMouseHandler::EClickType clicktype, BOOL down);
168
169	//
170	// LLWindowCallback interface implementation
171	//
172	/*virtual*/ BOOL handleTranslatedKeyDown(KEY key,  MASK mask, BOOL repeated);
173	/*virtual*/ BOOL handleTranslatedKeyUp(KEY key,  MASK mask);
174	/*virtual*/ void handleScanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key_level);
175	/*virtual*/ BOOL handleUnicodeChar(llwchar uni_char, MASK mask);	// NOT going to handle extended 
176	/*virtual*/ BOOL handleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
177	/*virtual*/ BOOL handleMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
178	/*virtual*/ BOOL handleCloseRequest(LLWindow *window);
179	/*virtual*/ void handleQuit(LLWindow *window);
180	/*virtual*/ BOOL handleRightMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
181	/*virtual*/ BOOL handleRightMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
182	/*virtual*/ BOOL handleMiddleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
183	/*virtual*/ BOOL handleMiddleMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
184	/*virtual*/ LLWindowCallbacks::DragNDropResult handleDragNDrop(LLWindow *window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action, std::string data);
185				void handleMouseMove(LLWindow *window,  LLCoordGL pos, MASK mask);
186	/*virtual*/ void handleMouseLeave(LLWindow *window);
187	/*virtual*/ void handleResize(LLWindow *window,  S32 x,  S32 y);
188	/*virtual*/ void handleFocus(LLWindow *window);
189	/*virtual*/ void handleFocusLost(LLWindow *window);
190	/*virtual*/ BOOL handleActivate(LLWindow *window, BOOL activated);
191	/*virtual*/ BOOL handleActivateApp(LLWindow *window, BOOL activating);
192	/*virtual*/ void handleMenuSelect(LLWindow *window,  S32 menu_item);
193	/*virtual*/ BOOL handlePaint(LLWindow *window,  S32 x,  S32 y,  S32 width,  S32 height);
194	/*virtual*/ void handleScrollWheel(LLWindow *window,  S32 clicks);
195	/*virtual*/ BOOL handleDoubleClick(LLWindow *window,  LLCoordGL pos, MASK mask);
196	/*virtual*/ void handleWindowBlock(LLWindow *window);
197	/*virtual*/ void handleWindowUnblock(LLWindow *window);
198	/*virtual*/ void handleDataCopy(LLWindow *window, S32 data_type, void *data);
199	/*virtual*/ BOOL handleTimerEvent(LLWindow *window);
200	/*virtual*/ BOOL handleDeviceChange(LLWindow *window);
201
202	/*virtual*/ void handlePingWatchdog(LLWindow *window, const char * msg);
203	/*virtual*/ void handlePauseWatchdog(LLWindow *window);
204	/*virtual*/ void handleResumeWatchdog(LLWindow *window);
205	/*virtual*/ std::string translateString(const char* tag);
206	/*virtual*/ std::string translateString(const char* tag,
207					const std::map<std::string, std::string>& args);
208	
209	// signal on update of WorldView rect
210	typedef boost::function<void (LLRect old_world_rect, LLRect new_world_rect)> world_rect_callback_t;
211	typedef boost::signals2::signal<void (LLRect old_world_rect, LLRect new_world_rect)> world_rect_signal_t;
212	world_rect_signal_t mOnWorldViewRectUpdated;
213	boost::signals2::connection setOnWorldViewRectUpdated(world_rect_callback_t cb) { return mOnWorldViewRectUpdated.connect(cb); }
214
215	//
216	// ACCESSORS
217	//
218	LLRootView*			getRootView()		const;
219
220	// 3D world area in scaled pixels (via UI scale), use for most UI computations
221	LLRect			getWorldViewRectScaled() const;
222	S32				getWorldViewHeightScaled() const;
223	S32				getWorldViewWidthScaled() const;
224
225	// 3D world area, in raw unscaled pixels
226	LLRect			getWorldViewRectRaw() const		{ return mWorldViewRectRaw; }
227	S32 			getWorldViewHeightRaw() const;
228	S32 			getWorldViewWidthRaw() const;
229
230	// Window in scaled pixels (via UI scale), use for most UI computations
231	LLRect			getWindowRectScaled() const		{ return mWindowRectScaled; }
232	S32				getWindowHeightScaled() const;
233	S32				getWindowWidthScaled() const;
234
235	// Window in raw pixels as seen on screen.
236	LLRect			getWindowRectRaw() const		{ return mWindowRectRaw; }
237	S32				getWindowHeightRaw() const;
238	S32				getWindowWidthRaw() const;
239
240	LLWindow*		getWindow()			const	{ return mWindow; }
241	void*			getPlatformWindow() const;
242	void*			getMediaWindow() 	const;
243	void			focusClient()		const;
244
245	LLCoordGL		getLastMouse()		const	{ return mLastMousePoint; }
246	S32				getLastMouseX()		const	{ return mLastMousePoint.mX; }
247	S32				getLastMouseY()		const	{ return mLastMousePoint.mY; }
248	LLCoordGL		getCurrentMouse()		const	{ return mCurrentMousePoint; }
249	S32				getCurrentMouseX()		const	{ return mCurrentMousePoint.mX; }
250	S32				getCurrentMouseY()		const	{ return mCurrentMousePoint.mY; }
251	S32				getCurrentMouseDX()		const	{ return mCurrentMouseDelta.mX; }
252	S32				getCurrentMouseDY()		const	{ return mCurrentMouseDelta.mY; }
253	LLCoordGL		getCurrentMouseDelta()	const	{ return mCurrentMouseDelta; }
254	LLStat *		getMouseVelocityStat()		{ return &mMouseVelocityStat; }
255	BOOL			getLeftMouseDown()	const	{ return mLeftMouseDown; }
256	BOOL			getMiddleMouseDown()	const	{ return mMiddleMouseDown; }
257	BOOL			getRightMouseDown()	const	{ return mRightMouseDown; }
258
259	const LLPickInfo&	getLastPick() const { return mLastPick; }
260
261	void			setup2DViewport(S32 x_offset = 0, S32 y_offset = 0);
262	void			setup3DViewport(S32 x_offset = 0, S32 y_offset = 0);
263	void			setup3DRender();
264	void			setup2DRender();
265
266	LLVector3		mouseDirectionGlobal(const S32 x, const S32 y) const;
267	LLVector3		mouseDirectionCamera(const S32 x, const S32 y) const;
268	LLVector3       mousePointHUD(const S32 x, const S32 y) const;
269		
270
271	// Is window of our application frontmost?
272	BOOL			getActive() const			{ return mActive; }
273
274	const std::string&	getInitAlert() { return mInitAlert; }
275	
276	//
277	// MANIPULATORS
278	//
279	void			saveLastMouse(const LLCoordGL &point);
280
281	void			setCursor( ECursorType c );
282	void			showCursor();
283	void			hideCursor();
284	BOOL            getCursorHidden() { return mCursorHidden; }
285	void			moveCursorToCenter();								// move to center of window
286													
287	void			setShowProgress(const BOOL show);
288	BOOL			getShowProgress() const;
289	void			setProgressString(const std::string& string);
290	void			setProgressPercent(const F32 percent);
291	void			setProgressMessage(const std::string& msg);
292	void			setProgressCancelButtonVisible( BOOL b, const std::string& label = LLStringUtil::null );
293	LLProgressView *getProgressView() const;
294	void			revealIntroPanel();
295	void			setStartupComplete();
296
297	void			updateObjectUnderCursor();
298
299	void			updateUI();		// Once per frame, update UI based on mouse position, calls following update* functions
300	void				updateLayout();						
301	void				updateMouseDelta();		
302	void				updateKeyboardFocus();		
303
304	void			updateWorldViewRect(bool use_full_window=false);
305	LLView*			getToolBarHolder() { return mToolBarHolder.get(); }
306	LLView*			getHintHolder() { return mHintHolder.get(); }
307	LLView*			getLoginPanelHolder() { return mLoginPanelHolder.get(); }
308	BOOL			handleKey(KEY key, MASK mask);
309	void			handleScrollWheel	(S32 clicks);
310
311	// add and remove views from "popup" layer
312	void			addPopup(LLView* popup);
313	void			removePopup(LLView* popup);
314	void			clearPopups();
315
316	// Hide normal UI when a logon fails, re-show everything when logon is attempted again
317	void			setNormalControlsVisible( BOOL visible );
318	void			setMenuBackgroundColor(bool god_mode = false, bool dev_grid = false);
319
320	void			reshape(S32 width, S32 height);
321	void			sendShapeToSim();
322
323	void			draw();
324	void			updateDebugText();
325	void			drawDebugText();
326
327	static void		loadUserImage(void **cb_data, const LLUUID &uuid);
328
329	static void		movieSize(S32 new_width, S32 new_height);
330
331	// snapshot functionality.
332	// perhaps some of this should move to llfloatershapshot?  -MG
333	typedef enum
334	{
335		SNAPSHOT_TYPE_COLOR,
336		SNAPSHOT_TYPE_DEPTH
337	} ESnapshotType;
338	BOOL			saveSnapshot(const std::string&  filename, S32 image_width, S32 image_height, BOOL show_ui = TRUE, BOOL do_rebuild = FALSE, ESnapshotType type = SNAPSHOT_TYPE_COLOR);
339	BOOL			rawSnapshot(LLImageRaw *raw, S32 image_width, S32 image_height, BOOL keep_window_aspect = TRUE, BOOL is_texture = FALSE,
340								BOOL show_ui = TRUE, BOOL do_rebuild = FALSE, ESnapshotType type = SNAPSHOT_TYPE_COLOR, S32 max_size = MAX_SNAPSHOT_IMAGE_SIZE );
341	BOOL			thumbnailSnapshot(LLImageRaw *raw, S32 preview_width, S32 preview_height, BOOL show_ui, BOOL do_rebuild, ESnapshotType type) ;
342	BOOL			isSnapshotLocSet() const { return ! sSnapshotDir.empty(); }
343	void			resetSnapshotLoc() const { sSnapshotDir.clear(); }
344	BOOL		    saveImageNumbered(LLImageFormatted *image, bool force_picker = false);
345
346	// Reset the directory where snapshots are saved.
347	// Client will open directory picker on next snapshot save.
348	void resetSnapshotLoc();
349
350	void			playSnapshotAnimAndSound();
351	
352	// draws selection boxes around selected objects, must call displayObjects first
353	void			renderSelections( BOOL for_gl_pick, BOOL pick_parcel_walls, BOOL for_hud );
354	void			performPick();
355	void			returnEmptyPicks();
356
357	void			pickAsync(S32 x, S32 y_from_bot, MASK mask, void (*callback)(const LLPickInfo& pick_info), BOOL pick_transparent = FALSE);
358	LLPickInfo		pickImmediate(S32 x, S32 y, BOOL pick_transparent);
359	LLHUDIcon* cursorIntersectIcon(S32 mouse_x, S32 mouse_y, F32 depth,
360										   LLVector3* intersection);
361
362	LLViewerObject* cursorIntersect(S32 mouse_x = -1, S32 mouse_y = -1, F32 depth = 512.f,
363									LLViewerObject *this_object = NULL,
364									S32 this_face = -1,
365									BOOL pick_transparent = FALSE,
366									S32* face_hit = NULL,
367									LLVector3 *intersection = NULL,
368									LLVector2 *uv = NULL,
369									LLVector3 *normal = NULL,
370									LLVector3 *binormal = NULL,
371									LLVector3* start = NULL,
372									LLVector3* end = NULL);
373	
374	
375	// Returns a pointer to the last object hit
376	//LLViewerObject	*getObject();
377	//LLViewerObject  *lastNonFloraObjectHit();
378
379	//const LLVector3d& getObjectOffset();
380	//const LLVector3d& lastNonFloraObjectHitOffset();
381
382	// mousePointOnLand() returns true if found point
383	BOOL			mousePointOnLandGlobal(const S32 x, const S32 y, LLVector3d *land_pos_global);
384	BOOL			mousePointOnPlaneGlobal(LLVector3d& point, const S32 x, const S32 y, const LLVector3d &plane_point, const LLVector3 &plane_normal);
385	LLVector3d		clickPointInWorldGlobal(const S32 x, const S32 y_from_bot, LLViewerObject* clicked_object) const;
386	BOOL			clickPointOnSurfaceGlobal(const S32 x, const S32 y, LLViewerObject *objectp, LLVector3d &point_global) const;
387
388	// Prints window implementation details
389	void			dumpState();
390
391	// handle shutting down GL and bringing it back up
392	void			requestResolutionUpdate();
393	void			checkSettings();
394	void			restartDisplay(BOOL show_progress_bar);
395	BOOL			changeDisplaySettings(LLCoordScreen size, BOOL disable_vsync, BOOL show_progress_bar);
396	BOOL			getIgnoreDestroyWindow() { return mIgnoreActivate; }
397	F32				getWorldViewAspectRatio() const;
398	const LLVector2& getDisplayScale() const { return mDisplayScale; }
399	void			calcDisplayScale();
400	static LLRect 	calcScaledRect(const LLRect & rect, const LLVector2& display_scale);
401
402private:
403	bool                    shouldShowToolTipFor(LLMouseHandler *mh);
404	static bool onAlert(const LLSD& notify);
405
406	void			switchToolByMask(MASK mask);
407	void			destroyWindow();
408	void			drawMouselookInstructions();
409	void			stopGL(BOOL save_state = TRUE);
410	void			restoreGL(const std::string& progress_message = LLStringUtil::null);
411	void			initFonts(F32 zoom_factor = 1.f);
412	void			schedulePick(LLPickInfo& pick_info);
413	S32				getChatConsoleBottomPad(); // Vertical padding for child console rect, varied by bottom clutter
414	LLRect			getChatConsoleRect(); // Get optimal cosole rect.
415
416private:
417	LLWindow*		mWindow;						// graphical window object
418	bool			mActive;
419	bool			mUIVisible;
420
421	LLRect			mWindowRectRaw;				// whole window, including UI
422	LLRect			mWindowRectScaled;			// whole window, scaled by UI size
423	LLRect			mWorldViewRectRaw;			// area of screen for 3D world
424	LLRect			mWorldViewRectScaled;		// area of screen for 3D world scaled by UI size
425	LLRootView*		mRootView;					// a view of size mWindowRectRaw, containing all child views
426	LLVector2		mDisplayScale;
427
428	LLCoordGL		mCurrentMousePoint;			// last mouse position in GL coords
429	LLCoordGL		mLastMousePoint;		// Mouse point at last frame.
430	LLCoordGL		mCurrentMouseDelta;		//amount mouse moved this frame
431	LLStat			mMouseVelocityStat;
432	BOOL			mLeftMouseDown;
433	BOOL			mMiddleMouseDown;
434	BOOL			mRightMouseDown;
435
436	LLProgressView	*mProgressView;
437
438	LLFrameTimer	mToolTipFadeTimer;
439	LLPanel*		mToolTip;
440	std::string		mLastToolTipMessage;
441	LLRect			mToolTipStickyRect;			// Once a tool tip is shown, it will stay visible until the mouse leaves this rect.
442
443	BOOL			mMouseInWindow;				// True if the mouse is over our window or if we have captured the mouse.
444	BOOL			mFocusCycleMode;
445	typedef std::set<LLHandle<LLView> > view_handle_set_t;
446	view_handle_set_t mMouseHoverViews;
447
448	// Variables used for tool override switching based on modifier keys.  JC
449	MASK			mLastMask;			// used to detect changes in modifier mask
450	LLTool*			mToolStored;		// the tool we're overriding
451	BOOL			mHideCursorPermanent;	// true during drags, mouselook
452	BOOL            mCursorHidden;
453	LLPickInfo		mLastPick;
454	std::vector<LLPickInfo> mPicks;
455	LLRect			mPickScreenRegion; // area of frame buffer for rendering pick frames (generally follows mouse to avoid going offscreen)
456	LLTimer         mPickTimer;        // timer for scheduling n picks per second
457
458	std::string		mOverlayTitle;		// Used for special titles such as "Second Life - Special E3 2003 Beta"
459
460	BOOL			mIgnoreActivate;
461
462	std::string		mInitAlert;			// Window / GL initialization requires an alert
463
464	LLHandle<LLView> mWorldViewPlaceholder;	// widget that spans the portion of screen dedicated to rendering the 3d world
465	LLHandle<LLView> mToolBarHolder;		// container for toolbars
466	LLHandle<LLView> mHintHolder;			// container for hints
467	LLHandle<LLView> mLoginPanelHolder;		// container for login panel
468	LLPopupView*	mPopupView;			// container for transient popups
469	
470	class LLDebugText* mDebugText; // Internal class for debug text
471	
472	bool			mResDirty;
473	bool			mStatesDirty;
474	U32			mCurrResolutionIndex;
475
476	boost::scoped_ptr<LLWindowListener> mWindowListener;
477	boost::scoped_ptr<LLViewerWindowListener> mViewerWindowListener;
478
479	static std::string sSnapshotBaseName;
480	static std::string sSnapshotDir;
481
482	static std::string sMovieBaseName;
483	
484	// Object temporarily hovered over while dragging
485	LLPointer<LLViewerObject>	mDragHoveredObject;
486};
487
488//
489// Globals
490//
491
492extern LLViewerWindow*	gViewerWindow;
493
494extern LLFrameTimer		gAwayTimer;				// tracks time before setting the avatar away state to true
495extern LLFrameTimer		gAwayTriggerTimer;		// how long the avatar has been away
496
497extern LLViewerObject*  gDebugRaycastObject;
498extern LLVector3        gDebugRaycastIntersection;
499extern LLVector2        gDebugRaycastTexCoord;
500extern LLVector3        gDebugRaycastNormal;
501extern LLVector3        gDebugRaycastBinormal;
502extern S32				gDebugRaycastFaceHit;
503extern LLVector3		gDebugRaycastStart;
504extern LLVector3		gDebugRaycastEnd;
505
506extern BOOL			gDisplayCameraPos;
507extern BOOL			gDisplayWindInfo;
508extern BOOL			gDisplayFOV;
509extern BOOL			gDisplayBadge;
510
511#endif