llviewerwindow.h

Go to the documentation of this file.
00001 
00032 //
00033 // A note about X,Y coordinates:
00034 //
00035 // X coordinates are in pixels, from the left edge of the window client area
00036 // Y coordinates are in pixels, from the BOTTOM edge of the window client area
00037 //
00038 // The Y coordinates therefore match OpenGL window coords, not Windows(tm) window coords.
00039 // If Y is from the top, the variable will be called "y_from_top"
00040 
00041 #ifndef LL_LLVIEWERWINDOW_H
00042 #define LL_LLVIEWERWINDOW_H
00043 
00044 #include "v3dmath.h"
00045 #include "v2math.h"
00046 #include "llwindow.h"
00047 #include "lltimer.h"
00048 #include "llstat.h"
00049 #include "llalertdialog.h"
00050 
00051 class LLView;
00052 class LLViewerObject;
00053 class LLUUID;
00054 class LLMouseHandler;
00055 class LLProgressView;
00056 class LLTool;
00057 class LLVelocityBar;
00058 class LLViewerWindow;
00059 class LLTextBox;
00060 class LLImageRaw;
00061 class LLHUDIcon;
00062 
00063 #define MAX_IMAGE_SIZE 6144 //6 * 1024, max snapshot image size 6144 * 6144
00064 
00065 class LLViewerWindow : public LLWindowCallbacks
00066 {
00067 public:
00068         //
00069         // CREATORS
00070         //
00071         LLViewerWindow(char* title, char* name, S32 x, S32 y, S32 width, S32 height, BOOL fullscreen, BOOL ignore_pixel_depth);
00072         virtual ~LLViewerWindow();
00073 
00074         void                    initGLDefaults();
00075         void                    initBase();
00076         void                    adjustRectanglesForFirstUse(const LLRect& full_window);
00077         void                    initWorldUI();
00078 
00079         //
00080         // LLWindowCallback interface implementation
00081         //
00082         /*virtual*/ BOOL handleTranslatedKeyDown(KEY key,  MASK mask, BOOL repeated);
00083         /*virtual*/ BOOL handleTranslatedKeyUp(KEY key,  MASK mask);
00084         /*virtual*/ void handleScanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key_level);
00085         /*virtual*/ BOOL handleUnicodeChar(llwchar uni_char, MASK mask);        // NOT going to handle extended 
00086         /*virtual*/ BOOL handleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
00087         /*virtual*/ BOOL handleMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
00088         /*virtual*/ BOOL handleCloseRequest(LLWindow *window);
00089         /*virtual*/ void handleQuit(LLWindow *window);
00090         /*virtual*/ BOOL handleRightMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
00091         /*virtual*/ BOOL handleRightMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
00092         /*virtual*/ BOOL handleMiddleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
00093         /*virtual*/ BOOL handleMiddleMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
00094         /*virtual*/ void handleMouseMove(LLWindow *window,  LLCoordGL pos, MASK mask);
00095         /*virtual*/ void handleMouseLeave(LLWindow *window);
00096         /*virtual*/ void handleResize(LLWindow *window,  S32 x,  S32 y);
00097         /*virtual*/ void handleFocus(LLWindow *window);
00098         /*virtual*/ void handleFocusLost(LLWindow *window);
00099         /*virtual*/ BOOL handleActivate(LLWindow *window, BOOL activated);
00100         /*virtual*/ BOOL handleActivateApp(LLWindow *window, BOOL activating);
00101         /*virtual*/ void handleMenuSelect(LLWindow *window,  S32 menu_item);
00102         /*virtual*/ BOOL handlePaint(LLWindow *window,  S32 x,  S32 y,  S32 width,  S32 height);
00103         /*virtual*/ void handleScrollWheel(LLWindow *window,  S32 clicks);
00104         /*virtual*/ BOOL handleDoubleClick(LLWindow *window,  LLCoordGL pos, MASK mask);
00105         /*virtual*/ void handleWindowBlock(LLWindow *window);
00106         /*virtual*/ void handleWindowUnblock(LLWindow *window);
00107         /*virtual*/ void handleDataCopy(LLWindow *window, S32 data_type, void *data);
00108         /*virtual*/ BOOL handleTimerEvent(LLWindow *window);
00109         /*virtual*/ BOOL handleDeviceChange(LLWindow *window);
00110 
00111 
00112 
00113         //
00114         // ACCESSORS
00115         //
00116         LLView*                 getRootView()           const   { return mRootView; }
00117 
00118         // Window in raw pixels as seen on screen.
00119         const LLRect&   getWindowRect()         const   { return mWindowRect; };
00120         S32                             getWindowDisplayHeight()        const;
00121         S32                             getWindowDisplayWidth() const;
00122 
00123         // Window in scaled pixels (via UI scale), use this for
00124         // UI elements checking size.
00125         const LLRect&   getVirtualWindowRect()          const   { return mVirtualWindowRect; };
00126         S32                             getWindowHeight()       const;
00127         S32                             getWindowWidth()        const;
00128 
00129         LLWindow*               getWindow()                     const   { return mWindow; }
00130         void*                   getPlatformWindow() const       { return mWindow->getPlatformWindow(); }
00131         void                    focusClient()           const   { return mWindow->focusClient(); };
00132 
00133         LLCoordGL               getLastMouse()          const   { return mLastMousePoint; }
00134         S32                             getLastMouseX()         const   { return mLastMousePoint.mX; }
00135         S32                             getLastMouseY()         const   { return mLastMousePoint.mY; }
00136         LLCoordGL               getCurrentMouse()               const   { return mCurrentMousePoint; }
00137         S32                             getCurrentMouseX()              const   { return mCurrentMousePoint.mX; }
00138         S32                             getCurrentMouseY()              const   { return mCurrentMousePoint.mY; }
00139         S32                             getCurrentMouseDX()             const   { return mCurrentMouseDelta.mX; }
00140         S32                             getCurrentMouseDY()             const   { return mCurrentMouseDelta.mY; }
00141         LLCoordGL               getCurrentMouseDelta()  const   { return mCurrentMouseDelta; }
00142         LLStat *                getMouseVelocityStat()          { return &mMouseVelocityStat; }
00143         BOOL                    getLeftMouseDown()      const   { return mLeftMouseDown; }
00144         BOOL                    getRightMouseDown()     const   { return mRightMouseDown; }
00145 
00146         LLUICtrl*               getTopCtrl() const;
00147         BOOL                    hasTopCtrl(LLView* view) const;
00148 
00149         void                    setupViewport(S32 x_offset = 0, S32 y_offset = 0);
00150         void                    setup3DRender();
00151         void                    setup2DRender();
00152 
00153         BOOL                    isPickPending()                         { return mPickPending; }
00154 
00155         LLVector3               mouseDirectionGlobal(const S32 x, const S32 y) const;
00156         LLVector3               mouseDirectionCamera(const S32 x, const S32 y) const;
00157 
00158         // Is window of our application frontmost?
00159         BOOL                    getActive() const                       { return mActive; }
00160 
00161         void                    getTargetWindow(BOOL& fullscreen, S32& width, S32& height) const;
00162                 // The 'target' is where the user wants the window to be. It may not be
00163                 // there yet, because we may be supressing fullscreen prior to login.
00164 
00165         const LLString& getInitAlert() { return mInitAlert; }
00166         
00167         //
00168         // MANIPULATORS
00169         //
00170         void                    saveLastMouse(const LLCoordGL &point);
00171 
00172         void                    setCursor( ECursorType c );
00173         void                    showCursor();
00174         void                    hideCursor();
00175         void                    moveCursorToCenter();                                                           // move to center of window
00176                                                                                                         
00177         void                    setShowProgress(const BOOL show);
00178         BOOL                    getShowProgress() const;
00179         void                    moveProgressViewToFront();
00180         void                    setProgressString(const LLString& string);
00181         void                    setProgressPercent(const F32 percent);
00182         void                    setProgressMessage(const LLString& msg);
00183         void                    setProgressCancelButtonVisible( BOOL b, const LLString&  label );
00184         LLProgressView *getProgressView() const;
00185 
00186         void                    updateObjectUnderCursor();
00187 
00188         BOOL                    handlePerFrameHover();                                                  // Once per frame, update UI based on mouse position
00189 
00190         BOOL                    handleKey(KEY key, MASK mask);
00191         void                    handleScrollWheel       (S32 clicks);
00192 
00193         // Hide normal UI when a logon fails, re-show everything when logon is attempted again
00194         void                    setNormalControlsVisible( BOOL visible );
00195     void            setMenuBackgroundColor(bool god_mode = false, bool dev_grid = false);
00196 
00197         // Handle the application becoming active (frontmost) or inactive
00198         //BOOL                  handleActivate(BOOL activate);
00199 
00200         void                    setKeyboardFocus(LLUICtrl* new_focus);          // new_focus = NULL to release the focus.
00201         LLUICtrl*               getKeyboardFocus();     
00202         BOOL                    hasKeyboardFocus( const LLUICtrl* possible_focus ) const;
00203         BOOL                    childHasKeyboardFocus( const LLView* parent ) const;
00204         
00205         void                    setMouseCapture(LLMouseHandler* new_captor);    // new_captor = NULL to release the mouse.
00206         LLMouseHandler* getMouseCaptor() const;
00207 
00208         void                    setTopCtrl(LLUICtrl* new_top); // set new_top = NULL to release top_view.
00209 
00210         void                    reshape(S32 width, S32 height);
00211         void                    sendShapeToSim();
00212 
00213         void                    draw();
00214 //      void                    drawSelectedObjects();
00215         void                    updateDebugText();
00216         void                    drawDebugText();
00217 
00218         static void             loadUserImage(void **cb_data, const LLUUID &uuid);
00219 
00220         static void             movieSize(S32 new_width, S32 new_height);
00221 
00222         typedef enum e_snapshot_type
00223         {
00224                 SNAPSHOT_TYPE_COLOR,
00225                 SNAPSHOT_TYPE_DEPTH,
00226                 SNAPSHOT_TYPE_OBJECT_ID
00227         } ESnapshotType;
00228 
00229         BOOL                    saveSnapshot(const LLString&  filename, S32 image_width, S32 image_height, BOOL show_ui = TRUE, BOOL do_rebuild = FALSE, ESnapshotType type = SNAPSHOT_TYPE_COLOR);
00230         BOOL                    rawSnapshot(LLImageRaw *raw, S32 image_width, S32 image_height, BOOL keep_window_aspect = TRUE, BOOL is_texture = FALSE,
00231                                                                 BOOL show_ui = TRUE, BOOL do_rebuild = FALSE, ESnapshotType type = SNAPSHOT_TYPE_COLOR, S32 max_size = MAX_IMAGE_SIZE );
00232         BOOL            thumbnailSnapshot(LLImageRaw *raw, S32 preview_width, S32 preview_height, BOOL show_ui, BOOL do_rebuild, ESnapshotType type) ;
00233         BOOL                saveImageNumbered(LLImageRaw *raw, const LLString& extension = LLString());
00234 
00235         void                    playSnapshotAnimAndSound();
00236         
00237         // draws selection boxes around selected objects, must call displayObjects first
00238         void                    renderSelections( BOOL for_gl_pick, BOOL pick_parcel_walls, BOOL for_hud );
00239         void                    performPick();
00240 
00241         void                    hitObjectOrLandGlobalAsync(S32 x, S32 y_from_bot, MASK mask, void (*callback)(S32 x, S32 y, MASK mask), BOOL pick_transparent = FALSE, BOOL pick_parcel_walls = FALSE);
00242         void                    hitObjectOrLandGlobalImmediate(S32 x, S32 y, void (*callback)(S32 x, S32 y, MASK mask), BOOL pick_transparent);
00243         
00244         void                    hitUIElementAsync(S32 x, S32 y_from_bot, MASK mask, void (*callback)(S32 x, S32 y, MASK mask));
00245         void                    hitUIElementImmediate(S32 x, S32 y, void (*callback)(S32 x, S32 y, MASK mask));
00246 
00247         LLViewerObject* getObjectUnderCursor(const F32 depth = 16.0f);
00248         
00249         // Returns a pointer to the last object hit
00250         LLViewerObject  *lastObjectHit();
00251         LLViewerObject  *lastNonFloraObjectHit();
00252 
00253         const LLVector3d& lastObjectHitOffset();
00254         const LLVector3d& lastNonFloraObjectHitOffset();
00255 
00256         // mousePointOnLand() returns true if found point
00257         BOOL                    mousePointOnLandGlobal(const S32 x, const S32 y, LLVector3d *land_pos_global);
00258         BOOL                    mousePointOnPlaneGlobal(LLVector3d& point, const S32 x, const S32 y, const LLVector3d &plane_point, const LLVector3 &plane_normal);
00259         LLVector3d              clickPointInWorldGlobal(const S32 x, const S32 y_from_bot, LLViewerObject* clicked_object) const;
00260         BOOL                    clickPointOnSurfaceGlobal(const S32 x, const S32 y, LLViewerObject *objectp, LLVector3d &point_global) const;
00261 
00262         // Prints window implementation details
00263         void                    dumpState();
00264 
00265         // Request display setting changes      
00266         void                    toggleFullscreen(BOOL show_progress);
00267 
00268         // handle shutting down GL and bringing it back up
00269         BOOL                    checkSettings();
00270         void                    restartDisplay(BOOL show_progress_bar);
00271         BOOL                    changeDisplaySettings(BOOL fullscreen, LLCoordScreen size, BOOL disable_vsync, BOOL show_progress_bar);
00272         BOOL                    getIgnoreDestroyWindow() { return mIgnoreActivate; }
00273         F32                             getDisplayAspectRatio() const;
00274         const LLVector2& getDisplayScale() const { return mDisplayScale; }
00275         void                    calcDisplayScale();
00276 
00277         void                    drawPickBuffer() const;
00278 
00279         LLAlertDialog* alertXml(const std::string& xml_filename,
00280                                   LLAlertDialog::alert_callback_t callback = NULL, void* user_data = NULL);
00281         LLAlertDialog* alertXml(const std::string& xml_filename, const LLString::format_map_t& args,
00282                                   LLAlertDialog::alert_callback_t callback = NULL, void* user_data = NULL);
00283         LLAlertDialog* alertXmlEditText(const std::string& xml_filename, const LLString::format_map_t& args,
00284                                                   LLAlertDialog::alert_callback_t callback, void* user_data,
00285                                                   LLAlertDialog::alert_text_callback_t text_callback, void *text_data,
00286                                                   const LLString::format_map_t& edit_args = LLString::format_map_t(),
00287                                                   BOOL draw_asterixes = FALSE);
00288 
00289         static bool alertCallback(S32 modal);
00290         
00291 #ifdef SABINRIG
00292         //Silly rig stuff
00293         void            printFeedback(); //RIG STUFF!
00294 #endif //SABINRIG
00295 
00296 private:
00297         void                    switchToolByMask(MASK mask);
00298         void                    destroyWindow();
00299         void                    drawMouselookInstructions();
00300         void                    stopGL(BOOL save_state = TRUE);
00301         void                    restoreGL(const LLString& progress_message = LLString::null);
00302         void                    initFonts(F32 zoom_factor = 1.f);
00303         
00304         void                    analyzeHit(
00305                                                 S32                             x,                              // input
00306                                                 S32                             y_from_bot,             // input
00307                                                 LLViewerObject* objectp,                // input
00308                                                 U32                             te_offset,              // input
00309                                                 LLUUID*                 hit_object_id_p,// output
00310                                                 S32*                    hit_face_p,             // output
00311                                                 LLVector3d*             hit_pos_p,              // output
00312                                                 BOOL*                   hit_land,               // output
00313                                                 F32*                    hit_u_coord,    // output
00314                                                 F32*                    hit_v_coord);   // output
00315 
00316         
00317 public:
00318         LLWindow*               mWindow;                                                // graphical window object
00319 
00320 protected:
00321         BOOL                    mActive;
00322         BOOL                    mWantFullscreen;
00323         BOOL                    mShowFullscreenProgress;
00324         LLRect                  mWindowRect;
00325         LLRect                  mVirtualWindowRect;
00326         LLView*                 mRootView;                                      // a view of size mWindowRect, containing all child views
00327         LLVector2               mDisplayScale;
00328 
00329         LLCoordGL               mCurrentMousePoint;                     // last mouse position in GL coords
00330         LLCoordGL               mLastMousePoint;                // Mouse point at last frame.
00331         LLCoordGL               mCurrentMouseDelta;             //amount mouse moved this frame
00332         LLStat                  mMouseVelocityStat;
00333         BOOL                    mLeftMouseDown;
00334         BOOL                    mRightMouseDown;
00335 
00336         LLProgressView  *mProgressView;
00337 
00338         LLTextBox*              mToolTip;
00339         BOOL                    mToolTipBlocked;                        // True after a key press or a mouse button event.  False once the mouse moves again.
00340         LLRect                  mToolTipStickyRect;                     // Once a tool tip is shown, it will stay visible until the mouse leaves this rect.
00341 
00342         BOOL                    mMouseInWindow;                         // True if the mouse is over our window or if we have captured the mouse.
00343         BOOL                    mFocusCycleMode;
00344 
00345         // Variables used for tool override switching based on modifier keys.  JC
00346         MASK                    mLastMask;                      // used to detect changes in modifier mask
00347         LLTool*                 mToolStored;            // the tool we're overriding
00348         BOOL                    mSuppressToolbox;       // sometimes hide the toolbox, despite
00349                                                                                 // having a camera tool selected
00350         BOOL                    mHideCursorPermanent;   // true during drags, mouselook
00351         LLCoordGL               mPickPoint;
00352         LLCoordGL               mPickOffset;
00353         MASK                    mPickMask;
00354         BOOL                    mPickPending;
00355         void                    (*mPickCallback)(S32 x, S32 y, MASK mask);
00356 
00357         LLString                mOverlayTitle;          // Used for special titles such as "Second Life - Special E3 2003 Beta"
00358 
00359         BOOL                    mIgnoreActivate;
00360         U8*                             mPickBuffer;
00361 
00362         LLString                mInitAlert;                     // Window / GL initialization requires an alert
00363         
00364         class LLDebugText* mDebugText; // Internal class for debug text
00365 
00366 protected:
00367         static char             sSnapshotBaseName[LL_MAX_PATH];         /* Flawfinder: ignore */
00368         static char             sSnapshotDir[LL_MAX_PATH];              /* Flawfinder: ignore */
00369 
00370         static char             sMovieBaseName[LL_MAX_PATH];            /* Flawfinder: ignore */
00371 };      
00372 
00373 class LLBottomPanel : public LLPanel
00374 {
00375 public:
00376         LLBottomPanel(const LLRect& rect);
00377         void setFocusIndicator(LLView * indicator);
00378         LLView * getFocusIndicator() { return mIndicator; }
00379         /*virtual*/ void draw();
00380 
00381         static void* createHUD(void* data);
00382         static void* createOverlayBar(void* data);
00383         static void* createToolBar(void* data);
00384 
00385 protected:
00386         LLView * mIndicator;
00387 };
00388 extern LLBottomPanel * gBottomPanel;
00389 
00390 void toggle_flying(void*);
00391 void toggle_first_person();
00392 void toggle_build(void*);
00393 void reset_viewer_state_on_sim(void);
00394 void update_saved_window_size(const LLString& control,S32 delta_width, S32 delta_height);
00395 //
00396 // Constants
00397 //
00398 
00399 
00400 //
00401 // Globals
00402 //
00403 
00404 extern LLVelocityBar*   gVelocityBar;
00405 extern LLViewerWindow*  gViewerWindow;
00406 
00407 extern LLFrameTimer             gMouseIdleTimer;                // how long has it been since the mouse last moved?
00408 extern LLFrameTimer             gAwayTimer;                             // tracks time before setting the avatar away state to true
00409 extern LLFrameTimer             gAwayTriggerTimer;              // how long the avatar has been away
00410 
00411 extern LLVector3d               gLastHitPosGlobal;
00412 extern LLVector3d               gLastHitObjectOffset;
00413 extern LLUUID                   gLastHitObjectID;
00414 extern S32                              gLastHitObjectFace;
00415 extern BOOL                             gLastHitLand;
00416 extern F32                              gLastHitUCoord;
00417 extern F32                              gLastHitVCoord;
00418 
00419 
00420 extern LLVector3d               gLastHitNonFloraPosGlobal;
00421 extern LLVector3d               gLastHitNonFloraObjectOffset;
00422 extern LLUUID                   gLastHitNonFloraObjectID;
00423 extern S32                              gLastHitNonFloraObjectFace;
00424 
00425 extern S32                              gLastHitUIElement;
00426 extern LLHUDIcon*               gLastHitHUDIcon;
00427 extern BOOL                             gLastHitParcelWall;
00428 extern BOOL                             gDebugSelect;
00429 extern BOOL                             gPickFaces;
00430 extern BOOL                             gPickTransparent;
00431 
00432 extern BOOL                             gDebugFastUIRender;
00433 extern S32 CHAT_BAR_HEIGHT; 
00434 
00435 extern BOOL                     gDisplayCameraPos;
00436 extern BOOL                     gDisplayWindInfo;
00437 extern BOOL                     gDisplayNearestWater;
00438 extern BOOL                     gDisplayFOV;
00439 
00440 #endif

Generated on Fri May 16 08:34:19 2008 for SecondLife by  doxygen 1.5.5