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