SL-19134 Thumbnail ctrl
LLIconCtrl stores icons indefinitely which is undesired for fairly large and expected to be numerous thumbnails, LLTextureCtrl is tied to texture picker and has a number of limitations (already processes clicks, enforces label area). Intent behind LLThumbnailCtrl is to bridge the gap - to not store texture indefinitely and to allow further customisation.master
parent
7a99ce16d1
commit
3ecfeda2fd
|
|
@ -604,6 +604,7 @@ set(viewer_SOURCE_FILES
|
|||
lltextureinfodetails.cpp
|
||||
lltexturestats.cpp
|
||||
lltextureview.cpp
|
||||
llthumbnailctrl.cpp
|
||||
lltoast.cpp
|
||||
lltoastalertpanel.cpp
|
||||
lltoastgroupnotifypanel.cpp
|
||||
|
|
@ -1236,6 +1237,7 @@ set(viewer_HEADER_FILES
|
|||
lltextureinfodetails.h
|
||||
lltexturestats.h
|
||||
lltextureview.h
|
||||
llthumbnailctrl.h
|
||||
lltoast.h
|
||||
lltoastalertpanel.h
|
||||
lltoastgroupnotifypanel.h
|
||||
|
|
|
|||
|
|
@ -0,0 +1,204 @@
|
|||
/**
|
||||
* @file llthumbnailctrl.cpp
|
||||
* @brief LLThumbnailCtrl base class
|
||||
*
|
||||
* $LicenseInfo:firstyear=2023&license=viewerlgpl$
|
||||
* Second Life Viewer Source Code
|
||||
* Copyright (C) 2023, Linden Research, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation;
|
||||
* version 2.1 of the License only.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
#include "llviewerprecompiledheaders.h"
|
||||
|
||||
#include "llthumbnailctrl.h"
|
||||
|
||||
#include "linden_common.h"
|
||||
#include "llagent.h"
|
||||
#include "lluictrlfactory.h"
|
||||
#include "lluuid.h"
|
||||
#include "lltrans.h"
|
||||
#include "llviewborder.h"
|
||||
#include "llviewertexture.h"
|
||||
#include "llviewertexturelist.h"
|
||||
#include "llwindow.h"
|
||||
|
||||
static LLDefaultChildRegistry::Register<LLThumbnailCtrl> r("thumbnail");
|
||||
|
||||
LLThumbnailCtrl::Params::Params()
|
||||
: border("border")
|
||||
, border_color("border_color")
|
||||
, image_name("image_name")
|
||||
, border_visible("show_visible", false)
|
||||
, interactable("interactable", false)
|
||||
, show_loading("show_loading", true)
|
||||
{}
|
||||
|
||||
LLThumbnailCtrl::LLThumbnailCtrl(const LLThumbnailCtrl::Params& p)
|
||||
: LLUICtrl(p)
|
||||
, mBorderColor(p.border_color())
|
||||
, mBorderVisible(p.border_visible())
|
||||
, mInteractable(p.interactable())
|
||||
, mShowLoadingPlaceholder(p.show_loading())
|
||||
, mPriority(LLGLTexture::BOOST_PREVIEW)
|
||||
{
|
||||
mLoadingPlaceholderString = LLTrans::getString("texture_loading");
|
||||
|
||||
LLRect border_rect = getLocalRect();
|
||||
LLViewBorder::Params vbparams(p.border);
|
||||
vbparams.name("border");
|
||||
vbparams.rect(border_rect);
|
||||
mBorder = LLUICtrlFactory::create<LLViewBorder> (vbparams);
|
||||
addChild(mBorder);
|
||||
|
||||
if (p.image_name.isProvided())
|
||||
{
|
||||
setValue(p.image_name());
|
||||
}
|
||||
}
|
||||
|
||||
LLThumbnailCtrl::~LLThumbnailCtrl()
|
||||
{
|
||||
mTexturep = nullptr;
|
||||
mImagep = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void LLThumbnailCtrl::draw()
|
||||
{
|
||||
LLRect draw_rect = getLocalRect();
|
||||
|
||||
if (mBorderVisible)
|
||||
{
|
||||
mBorder->setKeyboardFocusHighlight(hasFocus());
|
||||
|
||||
gl_rect_2d( draw_rect, mBorderColor.get(), FALSE );
|
||||
draw_rect.stretch( -1 );
|
||||
}
|
||||
|
||||
// If we're in a focused floater, don't apply the floater's alpha to the texture.
|
||||
const F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency();
|
||||
if( mTexturep )
|
||||
{
|
||||
if( mTexturep->getComponents() == 4 )
|
||||
{
|
||||
gl_rect_2d_checkerboard( draw_rect, alpha );
|
||||
}
|
||||
|
||||
//LLRectf uv_rect(0, 0, draw_rect.getWidth()/32.f, draw_rect.getHeight()/32.f);
|
||||
gl_draw_scaled_image( draw_rect.mLeft, draw_rect.mBottom, draw_rect.getWidth(), draw_rect.getHeight(), mTexturep, UI_VERTEX_COLOR % alpha);
|
||||
//mTexturep->addTextureStats( (F32)(draw_rect.getWidth() * draw_rect.getHeight()) );
|
||||
|
||||
mTexturep->setKnownDrawSize(draw_rect.getWidth(), draw_rect.getHeight());
|
||||
}
|
||||
else if( mImagep.notNull() )
|
||||
{
|
||||
mImagep->draw(getLocalRect(), UI_VERTEX_COLOR % alpha );
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_rect_2d( draw_rect, LLColor4::grey % alpha, TRUE );
|
||||
|
||||
// Draw X
|
||||
gl_draw_x( draw_rect, LLColor4::black );
|
||||
}
|
||||
|
||||
// Show "Loading..." string on the top left corner while this texture is loading.
|
||||
// Using the discard level, do not show the string if the texture is almost but not
|
||||
// fully loaded.
|
||||
if (mTexturep.notNull()
|
||||
&& mShowLoadingPlaceholder
|
||||
&& !mTexturep->isFullyLoaded())
|
||||
{
|
||||
U32 v_offset = 25;
|
||||
LLFontGL* font = LLFontGL::getFontSansSerif();
|
||||
|
||||
// Don't show as loaded if the texture is almost fully loaded (i.e. discard1) unless god
|
||||
if ((mTexturep->getDiscardLevel() > 1) || gAgent.isGodlike())
|
||||
{
|
||||
font->renderUTF8(
|
||||
mLoadingPlaceholderString,
|
||||
0,
|
||||
llfloor(draw_rect.mLeft+3),
|
||||
llfloor(draw_rect.mTop-v_offset),
|
||||
LLColor4::white,
|
||||
LLFontGL::LEFT,
|
||||
LLFontGL::BASELINE,
|
||||
LLFontGL::DROP_SHADOW);
|
||||
}
|
||||
}
|
||||
|
||||
LLUICtrl::draw();
|
||||
}
|
||||
|
||||
// virtual
|
||||
// value might be a string or a UUID
|
||||
void LLThumbnailCtrl::setValue(const LLSD& value)
|
||||
{
|
||||
LLSD tvalue(value);
|
||||
if (value.isString() && LLUUID::validate(value.asString()))
|
||||
{
|
||||
//RN: support UUIDs masquerading as strings
|
||||
tvalue = LLSD(LLUUID(value.asString()));
|
||||
}
|
||||
|
||||
LLUICtrl::setValue(tvalue);
|
||||
|
||||
mImageAssetID = LLUUID::null;
|
||||
mTexturep = nullptr;
|
||||
mImagep = nullptr;
|
||||
|
||||
if (tvalue.isUUID())
|
||||
{
|
||||
mImageAssetID = tvalue.asUUID();
|
||||
// Should it support baked textures?
|
||||
mTexturep = LLViewerTextureManager::getFetchedTexture(mImageAssetID, FTT_DEFAULT, MIPMAP_YES, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
|
||||
|
||||
mTexturep->setBoostLevel(mPriority);
|
||||
mTexturep->forceToSaveRawImage(0);
|
||||
|
||||
S32 desired_draw_width = mTexturep->getWidth();
|
||||
S32 desired_draw_height = mTexturep->getHeight();
|
||||
|
||||
mTexturep->setKnownDrawSize(desired_draw_width, desired_draw_height);
|
||||
}
|
||||
else if (tvalue.isString())
|
||||
{
|
||||
mImagep = LLUI::getUIImage(tvalue.asString(), LLGLTexture::BOOST_UI);
|
||||
if (mImagep)
|
||||
{
|
||||
LLViewerFetchedTexture* texture = dynamic_cast<LLViewerFetchedTexture*>(mImagep->getImage().get());
|
||||
if(texture)
|
||||
{
|
||||
mImageAssetID = texture->getID();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOL LLThumbnailCtrl::handleHover(S32 x, S32 y, MASK mask)
|
||||
{
|
||||
if (mInteractable && getEnabled())
|
||||
{
|
||||
getWindow()->setCursor(UI_CURSOR_HAND);
|
||||
return TRUE;
|
||||
}
|
||||
return LLUICtrl::handleHover(x, y, mask);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* @file llthumbnailctrl.h
|
||||
* @brief LLThumbnailCtrl base class
|
||||
*
|
||||
* $LicenseInfo:firstyear=2023&license=viewerlgpl$
|
||||
* Second Life Viewer Source Code
|
||||
* Copyright (C) 2023 Linden Research, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation;
|
||||
* version 2.1 of the License only.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
#ifndef LL_LLTHUMBNAILCTRL_H
|
||||
#define LL_LLTHUMBNAILCTRL_H
|
||||
|
||||
#include "llui.h"
|
||||
#include "lluictrl.h"
|
||||
#include "llviewborder.h" // for params
|
||||
|
||||
class LLUICtrlFactory;
|
||||
class LLUUID;
|
||||
class LLViewerFetchedTexture;
|
||||
|
||||
//
|
||||
// Classes
|
||||
//
|
||||
|
||||
//
|
||||
class LLThumbnailCtrl
|
||||
: public LLUICtrl
|
||||
{
|
||||
public:
|
||||
struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
|
||||
{
|
||||
Optional<LLViewBorder::Params> border;
|
||||
Optional<LLUIColor> border_color;
|
||||
Optional<std::string> image_name;
|
||||
Optional<bool> border_visible;
|
||||
Optional<bool> interactable;
|
||||
Optional<bool> show_loading;
|
||||
|
||||
Params();
|
||||
};
|
||||
protected:
|
||||
LLThumbnailCtrl(const Params&);
|
||||
friend class LLUICtrlFactory;
|
||||
|
||||
public:
|
||||
virtual ~LLThumbnailCtrl();
|
||||
|
||||
virtual void draw() override;
|
||||
|
||||
virtual void setValue(const LLSD& value ) override;
|
||||
|
||||
virtual BOOL handleHover(S32 x, S32 y, MASK mask) override;
|
||||
|
||||
private:
|
||||
S32 mPriority;
|
||||
bool mBorderVisible;
|
||||
bool mInteractable;
|
||||
bool mShowLoadingPlaceholder;
|
||||
std::string mLoadingPlaceholderString;
|
||||
LLUUID mImageAssetID;
|
||||
LLViewBorder* mBorder;
|
||||
LLUIColor mBorderColor;
|
||||
|
||||
LLPointer<LLViewerFetchedTexture> mTexturep;
|
||||
LLPointer<LLUIImage> mImagep;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue