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

Generated on Thu Jul 1 06:09:35 2010 for Second Life Viewer by  doxygen 1.4.7