From d56be1f1751f66bff09f0d223ed4712974e69e09 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 7 Feb 2012 12:31:48 -0800 Subject: EXP-1181 WIP as a designer I would like to specify default floater positions using realtive coordinates refactored LLCoord code to be templated, ultimately to support arbitrary conversions --- indra/llmath/llcoord.h | 74 ++++++-------------------------- indra/llrender/llfontgl.cpp | 40 +++++------------ indra/llrender/llfontgl.h | 5 ++- indra/llui/llaccordionctrltab.cpp | 2 +- indra/llui/llfloater.h | 3 ++ indra/llui/llmenugl.cpp | 2 +- indra/llui/llscrolllistitem.cpp | 2 +- indra/llui/llscrolllistitem.h | 2 +- indra/llui/lltoolbar.cpp | 2 +- indra/llui/llui.cpp | 9 ++-- indra/llui/llview.cpp | 6 +-- indra/llwindow/llwindowcallbacks.cpp | 2 - indra/llwindow/llwindowcallbacks.h | 2 +- indra/llwindow/llwindowwin32.cpp | 2 +- indra/newview/llappviewerwin32.cpp | 3 +- indra/newview/llnetmap.h | 2 +- indra/newview/llpanelprimmediacontrols.h | 2 +- indra/newview/llpopupview.cpp | 2 +- indra/newview/llviewercamera.h | 2 +- indra/newview/llviewerwindow.cpp | 14 +++--- 20 files changed, 55 insertions(+), 123 deletions(-) diff --git a/indra/llmath/llcoord.h b/indra/llmath/llcoord.h index 706ad92787..c0623e6d1f 100644 --- a/indra/llmath/llcoord.h +++ b/indra/llmath/llcoord.h @@ -27,79 +27,31 @@ #define LL_LLCOORD_H // A two-dimensional pixel value +template class LLCoord { public: - S32 mX; - S32 mY; + typedef LLCoord self_t; + VALUE_TYPE mX; + VALUE_TYPE mY; LLCoord(): mX(0), mY(0) {} LLCoord(S32 x, S32 y): mX(x), mY(y) {} - virtual ~LLCoord() - {} - - virtual void set(S32 x, S32 y) { mX = x; mY = y; } -}; + void set(S32 x, S32 y) { mX = x; mY = y;} + bool operator==(const self_t& other) const { return mX == other.mX && mY == other.mY; } + bool operator!=(const self_t& other) const { return !(*this == other); } -// GL coordinates start in the client region of a window, -// with left, bottom = 0, 0 -class LLCoordGL : public LLCoord -{ -public: - LLCoordGL() : LLCoord() - {} - LLCoordGL(S32 x, S32 y) : LLCoord(x, y) - {} - bool operator==(const LLCoordGL& other) const { return mX == other.mX && mY == other.mY; } - bool operator!=(const LLCoordGL& other) const { return !(*this == other); } }; -//bool operator ==(const LLCoordGL& a, const LLCoordGL& b); - -// Window coords include things like window borders, -// menu regions, etc. -class LLCoordWindow : public LLCoord -{ -public: - LLCoordWindow() : LLCoord() - {} - LLCoordWindow(S32 x, S32 y) : LLCoord(x, y) - {} - bool operator==(const LLCoordWindow& other) const { return mX == other.mX && mY == other.mY; } - bool operator!=(const LLCoordWindow& other) const { return !(*this == other); } -}; +struct LL_COORD_TYPE_GL {}; +struct LL_COORD_TYPE_WINDOW {}; +struct LL_COORD_TYPE_SCREEN {}; - -// Screen coords start at left, top = 0, 0 -class LLCoordScreen : public LLCoord -{ -public: - LLCoordScreen() : LLCoord() - {} - LLCoordScreen(S32 x, S32 y) : LLCoord(x, y) - {} - bool operator==(const LLCoordScreen& other) const { return mX == other.mX && mY == other.mY; } - bool operator!=(const LLCoordScreen& other) const { return !(*this == other); } -}; - -class LLCoordFont : public LLCoord -{ -public: - F32 mZ; - - LLCoordFont() : LLCoord(), mZ(0.f) - {} - LLCoordFont(S32 x, S32 y, F32 z = 0) : LLCoord(x,y), mZ(z) - {} - - void set(S32 x, S32 y) { LLCoord::set(x,y); mZ = 0.f; } - void set(S32 x, S32 y, F32 z) { mX = x; mY = y; mZ = z; } - bool operator==(const LLCoordFont& other) const { return mX == other.mX && mY == other.mY; } - bool operator!=(const LLCoordFont& other) const { return !(*this == other); } -}; - +typedef LLCoord LLCoordGL; +typedef LLCoord LLCoordWindow; +typedef LLCoord LLCoordScreen; #endif diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp index 6e6d02177d..fccbf37a8d 100644 --- a/indra/llrender/llfontgl.cpp +++ b/indra/llrender/llfontgl.cpp @@ -56,8 +56,9 @@ std::string LLFontGL::sAppDir; LLColor4 LLFontGL::sShadowColor(0.f, 0.f, 0.f, 1.f); LLFontRegistry* LLFontGL::sFontRegistry = NULL; -LLCoordFont LLFontGL::sCurOrigin; -std::vector LLFontGL::sOriginStack; +LLCoordGL LLFontGL::sCurOrigin; +F32 LLFontGL::sCurDepth; +std::vector > LLFontGL::sOriginStack; const F32 EXT_X_BEARING = 1.f; const F32 EXT_Y_BEARING = 0.f; @@ -68,20 +69,6 @@ const F32 PIXEL_CORRECTION_DISTANCE = 0.01f; const F32 PAD_UVY = 0.5f; // half of vertical padding between glyphs in the glyph texture const F32 DROP_SHADOW_SOFT_STRENGTH = 0.3f; -static F32 llfont_round_x(F32 x) -{ - //return llfloor((x-LLFontGL::sCurOrigin.mX)/LLFontGL::sScaleX+0.5f)*LLFontGL::sScaleX+LLFontGL::sCurOrigin.mX; - //return llfloor(x/LLFontGL::sScaleX+0.5f)*LLFontGL::sScaleY; - return x; -} - -static F32 llfont_round_y(F32 y) -{ - //return llfloor((y-LLFontGL::sCurOrigin.mY)/LLFontGL::sScaleY+0.5f)*LLFontGL::sScaleY+LLFontGL::sCurOrigin.mY; - //return llfloor(y+0.5f); - return y; -} - LLFontGL::LLFontGL() { } @@ -177,18 +164,11 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons gGL.loadUIIdentity(); - //gGL.translateUI(floorf(sCurOrigin.mX*sScaleX), floorf(sCurOrigin.mY*sScaleY), sCurOrigin.mZ); - - // this code snaps the text origin to a pixel grid to start with - //F32 pixel_offset_x = llround((F32)sCurOrigin.mX) - (sCurOrigin.mX); - //F32 pixel_offset_y = llround((F32)sCurOrigin.mY) - (sCurOrigin.mY); - //gGL.translateUI(-pixel_offset_x, -pixel_offset_y, 0.f); - LLVector2 origin(floorf(sCurOrigin.mX*sScaleX), floorf(sCurOrigin.mY*sScaleY)); - // Depth translation, so that floating text appears 'inworld' - // and is correclty occluded. - gGL.translatef(0.f,0.f,sCurOrigin.mZ); + // Depth translation, so that floating text appears 'in-world' + // and is correctly occluded. + gGL.translatef(0.f,0.f,sCurDepth); S32 chars_drawn = 0; S32 i; @@ -1134,22 +1114,22 @@ void LLFontGL::renderQuad(LLVector3* vertex_out, LLVector2* uv_out, LLColor4U* c { S32 index = 0; - vertex_out[index] = LLVector3(llfont_round_x(screen_rect.mRight), llfont_round_y(screen_rect.mTop), 0.f); + vertex_out[index] = LLVector3(screen_rect.mRight, screen_rect.mTop, 0.f); uv_out[index] = LLVector2(uv_rect.mRight, uv_rect.mTop); colors_out[index] = color; index++; - vertex_out[index] = LLVector3(llfont_round_x(screen_rect.mLeft), llfont_round_y(screen_rect.mTop), 0.f); + vertex_out[index] = LLVector3(screen_rect.mLeft, screen_rect.mTop, 0.f); uv_out[index] = LLVector2(uv_rect.mLeft, uv_rect.mTop); colors_out[index] = color; index++; - vertex_out[index] = LLVector3(llfont_round_x(screen_rect.mLeft), llfont_round_y(screen_rect.mBottom), 0.f); + vertex_out[index] = LLVector3(screen_rect.mLeft, screen_rect.mBottom, 0.f); uv_out[index] = LLVector2(uv_rect.mLeft, uv_rect.mBottom); colors_out[index] = color; index++; - vertex_out[index] = LLVector3(llfont_round_x(screen_rect.mRight), llfont_round_y(screen_rect.mBottom), 0.f); + vertex_out[index] = LLVector3(screen_rect.mRight, screen_rect.mBottom, 0.f); uv_out[index] = LLVector2(uv_rect.mRight, uv_rect.mBottom); colors_out[index] = color; } diff --git a/indra/llrender/llfontgl.h b/indra/llrender/llfontgl.h index 9d7e2891e3..74bdbb43e7 100644 --- a/indra/llrender/llfontgl.h +++ b/indra/llrender/llfontgl.h @@ -186,8 +186,9 @@ public: static std::string getFontPathLocal(); static std::string getFontPathSystem(); - static LLCoordFont sCurOrigin; - static std::vector sOriginStack; + static LLCoordGL sCurOrigin; + static F32 sCurDepth; + static std::vector > sOriginStack; static LLColor4 sShadowColor; diff --git a/indra/llui/llaccordionctrltab.cpp b/indra/llui/llaccordionctrltab.cpp index 7a5f9f9fd6..c025cd7939 100644 --- a/indra/llui/llaccordionctrltab.cpp +++ b/indra/llui/llaccordionctrltab.cpp @@ -976,7 +976,7 @@ void LLAccordionCtrlTab::drawChild(const LLRect& root_rect,LLView* child) gGL.matrixMode(LLRender::MM_MODELVIEW); LLUI::pushMatrix(); { - LLUI::translate((F32)child->getRect().mLeft, (F32)child->getRect().mBottom, 0.f); + LLUI::translate((F32)child->getRect().mLeft, (F32)child->getRect().mBottom); child->draw(); } diff --git a/indra/llui/llfloater.h b/indra/llui/llfloater.h index 59b35d206f..1eb8c964f9 100644 --- a/indra/llui/llfloater.h +++ b/indra/llui/llfloater.h @@ -82,6 +82,9 @@ namespace LLInitParam }; } +struct LL_COORD_FLOATER; + +typedef LLCoord LLCoordFloater; class LLFloater : public LLPanel, public LLInstanceTracker { diff --git a/indra/llui/llmenugl.cpp b/indra/llui/llmenugl.cpp index 3e547efd97..1284231e52 100644 --- a/indra/llui/llmenugl.cpp +++ b/indra/llui/llmenugl.cpp @@ -3425,7 +3425,7 @@ void LLMenuHolderGL::draw() LLUI::pushMatrix(); { - LLUI::translate((F32)item_rect.mLeft, (F32)item_rect.mBottom, 0.f); + LLUI::translate((F32)item_rect.mLeft, (F32)item_rect.mBottom); selecteditem->getMenu()->drawBackground(selecteditem, interpolant); selecteditem->draw(); } diff --git a/indra/llui/llscrolllistitem.cpp b/indra/llui/llscrolllistitem.cpp index d95752e31c..5a1e96ab03 100644 --- a/indra/llui/llscrolllistitem.cpp +++ b/indra/llui/llscrolllistitem.cpp @@ -138,7 +138,7 @@ void LLScrollListItem::draw(const LLRect& rect, const LLColor4& fg_color, const LLUI::pushMatrix(); { - LLUI::translate((F32) cur_x, (F32) rect.mBottom, 0.0f); + LLUI::translate((F32) cur_x, (F32) rect.mBottom); cell->draw( fg_color, highlight_color ); } diff --git a/indra/llui/llscrolllistitem.h b/indra/llui/llscrolllistitem.h index 611df729b4..13655b5873 100644 --- a/indra/llui/llscrolllistitem.h +++ b/indra/llui/llscrolllistitem.h @@ -33,10 +33,10 @@ #include "v4color.h" #include "llinitparam.h" #include "llscrolllistcell.h" +#include "llcoord.h" #include -class LLCoordGL; class LLCheckBoxCtrl; class LLResizeBar; class LLScrollListCtrl; diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index 9b31a6449d..81ea0ebf0c 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -827,7 +827,7 @@ void LLToolBar::draw() // rect may have shifted during layout LLUI::popMatrix(); LLUI::pushMatrix(); - LLUI::translate((F32)getRect().mLeft, (F32)getRect().mBottom, 0.f); + LLUI::translate((F32)getRect().mLeft, (F32)getRect().mBottom); // Position the caret LLIconCtrl* caret = getChild("caret"); diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp index 6b74c5a6be..931b696c90 100644 --- a/indra/llui/llui.cpp +++ b/indra/llui/llui.cpp @@ -1688,21 +1688,22 @@ void LLUI::translate(F32 x, F32 y, F32 z) gGL.translateUI(x,y,z); LLFontGL::sCurOrigin.mX += (S32) x; LLFontGL::sCurOrigin.mY += (S32) y; - LLFontGL::sCurOrigin.mZ += z; + LLFontGL::sCurDepth += z; } //static void LLUI::pushMatrix() { gGL.pushUIMatrix(); - LLFontGL::sOriginStack.push_back(LLFontGL::sCurOrigin); + LLFontGL::sOriginStack.push_back(std::make_pair(LLFontGL::sCurOrigin, LLFontGL::sCurDepth)); } //static void LLUI::popMatrix() { gGL.popUIMatrix(); - LLFontGL::sCurOrigin = *LLFontGL::sOriginStack.rbegin(); + LLFontGL::sCurOrigin = LLFontGL::sOriginStack.back().first; + LLFontGL::sCurDepth = LLFontGL::sOriginStack.back().second; LLFontGL::sOriginStack.pop_back(); } @@ -1712,7 +1713,7 @@ void LLUI::loadIdentity() gGL.loadUIIdentity(); LLFontGL::sCurOrigin.mX = 0; LLFontGL::sCurOrigin.mY = 0; - LLFontGL::sCurOrigin.mZ = 0; + LLFontGL::sCurDepth = 0.f; } //static diff --git a/indra/llui/llview.cpp b/indra/llui/llview.cpp index e1ee0a5b14..1a62fe75fc 100644 --- a/indra/llui/llview.cpp +++ b/indra/llui/llview.cpp @@ -1106,7 +1106,7 @@ void LLView::drawChildren() { LLUI::pushMatrix(); { - LLUI::translate((F32)viewp->getRect().mLeft, (F32)viewp->getRect().mBottom, 0.f); + LLUI::translate((F32)viewp->getRect().mLeft, (F32)viewp->getRect().mBottom); // flag the fact we are in draw here, in case overridden draw() method attempts to remove this widget viewp->mInDraw = true; viewp->draw(); @@ -1159,7 +1159,7 @@ void LLView::drawDebugRect() if (getUseBoundingRect()) { - LLUI::translate((F32)mBoundingRect.mLeft - (F32)mRect.mLeft, (F32)mBoundingRect.mBottom - (F32)mRect.mBottom, 0.f); + LLUI::translate((F32)mBoundingRect.mLeft - (F32)mRect.mLeft, (F32)mBoundingRect.mBottom - (F32)mRect.mBottom); } LLRect debug_rect = getUseBoundingRect() ? mBoundingRect : mRect; @@ -1231,7 +1231,7 @@ void LLView::drawChild(LLView* childp, S32 x_offset, S32 y_offset, BOOL force_dr gGL.matrixMode(LLRender::MM_MODELVIEW); LLUI::pushMatrix(); { - LLUI::translate((F32)childp->getRect().mLeft + x_offset, (F32)childp->getRect().mBottom + y_offset, 0.f); + LLUI::translate((F32)childp->getRect().mLeft + x_offset, (F32)childp->getRect().mBottom + y_offset); childp->draw(); } LLUI::popMatrix(); diff --git a/indra/llwindow/llwindowcallbacks.cpp b/indra/llwindow/llwindowcallbacks.cpp index c2705bbf74..9712ae1d91 100644 --- a/indra/llwindow/llwindowcallbacks.cpp +++ b/indra/llwindow/llwindowcallbacks.cpp @@ -28,8 +28,6 @@ #include "llwindowcallbacks.h" -#include "llcoord.h" - // // LLWindowCallbacks // diff --git a/indra/llwindow/llwindowcallbacks.h b/indra/llwindow/llwindowcallbacks.h index 8572b442f1..7da5959700 100644 --- a/indra/llwindow/llwindowcallbacks.h +++ b/indra/llwindow/llwindowcallbacks.h @@ -26,7 +26,7 @@ #ifndef LLWINDOWCALLBACKS_H #define LLWINDOWCALLBACKS_H -class LLCoordGL; +#include "llcoord.h" class LLWindow; class LLWindowCallbacks diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp index 67d1a168e6..a245986433 100644 --- a/indra/llwindow/llwindowwin32.cpp +++ b/indra/llwindow/llwindowwin32.cpp @@ -3328,7 +3328,7 @@ void LLWindowWin32::setLanguageTextInput( const LLCoordGL & position ) LLWinImm::setCompositionWindow( himc, &ime_form ); - sWinIMEWindowPosition.set( win_pos.mX, win_pos.mY ); + sWinIMEWindowPosition = win_pos; } LLWinImm::releaseContext(mWindowHandle, himc); diff --git a/indra/newview/llappviewerwin32.cpp b/indra/newview/llappviewerwin32.cpp index 647ace7ee3..6931b55c4c 100644 --- a/indra/newview/llappviewerwin32.cpp +++ b/indra/newview/llappviewerwin32.cpp @@ -30,7 +30,8 @@ #include "llmemtype.h" -#include "llwindowwin32.cpp" // *FIX: for setting gIconResource. +#include "llwindowwin32.h" // *FIX: for setting gIconResource. +#include "llgl.h" #include "res/resource.h" // *FIX: for setting gIconResource. #include //_O_APPEND diff --git a/indra/newview/llnetmap.h b/indra/newview/llnetmap.h index 20fcee0814..1f7e7d68c6 100644 --- a/indra/newview/llnetmap.h +++ b/indra/newview/llnetmap.h @@ -33,9 +33,9 @@ #include "v3dmath.h" #include "v4color.h" #include "llpointer.h" +#include "llcoord.h" class LLColor4U; -class LLCoordGL; class LLImageRaw; class LLViewerTexture; class LLFloaterMap; diff --git a/indra/newview/llpanelprimmediacontrols.h b/indra/newview/llpanelprimmediacontrols.h index 66956181f2..eeb433e306 100644 --- a/indra/newview/llpanelprimmediacontrols.h +++ b/indra/newview/llpanelprimmediacontrols.h @@ -30,9 +30,9 @@ #include "llpanel.h" #include "llviewermedia.h" #include "llnotificationptr.h" +#include "llcoord.h" class LLButton; -class LLCoordWindow; class LLIconCtrl; class LLLayoutStack; class LLProgressBar; diff --git a/indra/newview/llpopupview.cpp b/indra/newview/llpopupview.cpp index 9fbb67a63a..08829c1184 100644 --- a/indra/newview/llpopupview.cpp +++ b/indra/newview/llpopupview.cpp @@ -83,7 +83,7 @@ void LLPopupView::draw() LLUI::pushMatrix(); { - LLUI::translate( (F32) screen_x, (F32) screen_y, 0.f); + LLUI::translate( (F32) screen_x, (F32) screen_y); popup->draw(); } LLUI::popMatrix(); diff --git a/indra/newview/llviewercamera.h b/indra/newview/llviewercamera.h index cc3395115b..184033de42 100644 --- a/indra/newview/llviewercamera.h +++ b/indra/newview/llviewercamera.h @@ -32,8 +32,8 @@ #include "llstat.h" #include "lltimer.h" #include "m4math.h" +#include "llcoord.h" -class LLCoordGL; class LLViewerObject; // This rotation matrix moves the default OpenGL reference frame diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index 5730a55a9b..0de2545596 100644 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -27,9 +27,6 @@ #include "llviewerprecompiledheaders.h" #include "llviewerwindow.h" -#if LL_WINDOWS -#pragma warning (disable : 4355) // 'this' used in initializer list: yes, intentionally -#endif // system library includes #include @@ -49,7 +46,6 @@ #include "llviewquery.h" #include "llxmltree.h" #include "llslurl.h" -//#include "llviewercamera.h" #include "llrender.h" #include "llvoiceclient.h" // for push-to-talk button handling @@ -1538,14 +1534,14 @@ LLViewerWindow::LLViewerWindow(const Params& p) mResDirty(false), mStatesDirty(false), mCurrResolutionIndex(0), + mProgressView(NULL) +{ // gKeyboard is still NULL, so it doesn't do LLWindowListener any good to // pass its value right now. Instead, pass it a nullary function that // will, when we later need it, return the value of gKeyboard. // boost::lambda::var() constructs such a functor on the fly. - mWindowListener(new LLWindowListener(this, boost::lambda::var(gKeyboard))), - mViewerWindowListener(new LLViewerWindowListener(this)), - mProgressView(NULL) -{ + mWindowListener.reset(new LLWindowListener(this, boost::lambda::var(gKeyboard))); + mViewerWindowListener.reset(new LLViewerWindowListener(this)); LLNotificationChannel::buildChannel("VW_alerts", "Visible", LLNotificationFilters::filterBy(&LLNotification::getType, "alert")); LLNotificationChannel::buildChannel("VW_alertmodal", "Visible", LLNotificationFilters::filterBy(&LLNotification::getType, "alertmodal")); @@ -2362,7 +2358,7 @@ void LLViewerWindow::draw() gGL.matrixMode(LLRender::MM_MODELVIEW); LLUI::pushMatrix(); - LLUI::translate( (F32) screen_x, (F32) screen_y, 0.f); + LLUI::translate( (F32) screen_x, (F32) screen_y); top_ctrl->draw(); LLUI::popMatrix(); } -- cgit v1.2.3