1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005 |
- /**
- * @file lltexturectrl.cpp
- * @author Richard Nelson, James Cook
- * @brief LLTextureCtrl class implementation including related functions
- *
- * $LicenseInfo:firstyear=2002&license=viewergpl$
- *
- * Copyright (c) 2002-2009, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- #include "llviewerprecompiledheaders.h"
- #include "lltexturectrl.h"
- #include "llassetstorage.h"
- #include "llavatarappearancedefines.h"
- #include "llbutton.h"
- #include "llcheckboxctrl.h"
- #include "lldraghandle.h"
- #include "llgl.h"
- #include "llpermissions.h"
- #include "llradiogroup.h"
- #include "llrender.h"
- #include "llresizehandle.h"
- #include "llscrolllistctrl.h"
- #include "lltextbox.h"
- #include "llsaleinfo.h"
- #include "lltrans.h"
- #include "lluictrlfactory.h"
- #include "llagent.h"
- #include "llfloaterimagepreview.h"
- #include "llfloaterinventory.h"
- #include "llfolderview.h"
- #include "llinventorymodel.h"
- #include "llinventorymodelfetch.h"
- #include "lllocalbitmaps.h"
- #include "llpreviewtexture.h"
- //MK
- #include "mkrlinterface.h"
- //mk
- #include "llselectmgr.h"
- #include "lltool.h"
- #include "lltoolmgr.h"
- #include "lltoolpipette.h"
- #include "llviewercontrol.h"
- #include "llviewerinventory.h"
- #include "llviewerobject.h"
- #include "llviewertexturelist.h"
- #include "llviewerwindow.h"
- using namespace LLAvatarAppearanceDefines;
- constexpr S32 CLOSE_BTN_WIDTH = 100;
- constexpr S32 SMALL_BTN_WIDTH = 64;
- constexpr S32 TEX_PICKER_MIN_WIDTH = (HPAD + CLOSE_BTN_WIDTH + HPAD +
- CLOSE_BTN_WIDTH + HPAD +
- SMALL_BTN_WIDTH + HPAD +
- SMALL_BTN_WIDTH + HPAD +
- 30 + RESIZE_HANDLE_WIDTH * 2);
- constexpr S32 TEX_PICKER_MIN_HEIGHT = 290;
- constexpr S32 FOOTER_HEIGHT = 100;
- constexpr S32 BORDER_PAD = HPAD;
- constexpr S32 TEXTURE_INVENTORY_PADDING = 30;
- constexpr F32 CONTEXT_CONE_IN_ALPHA = 0.f;
- constexpr F32 CONTEXT_CONE_OUT_ALPHA = 1.f;
- constexpr F32 CONTEXT_FADE_TIME = 0.08f;
- ///////////////////////////////////////////////////////////////////////////////
- // LLFloaterTexturePicker class
- ///////////////////////////////////////////////////////////////////////////////
- class LLFloaterTexturePicker final : public LLFloater
- {
- protected:
- LOG_CLASS(LLFloaterTexturePicker);
- public:
- LLFloaterTexturePicker(LLTextureCtrl* owner,
- const LLRect& rect,
- const std::string& label,
- PermissionMask immediate_filter_perm_mask,
- PermissionMask non_immediate_filter_perm_mask,
- bool can_apply_immediately,
- bool allow_local_texture,
- bool bake_texture_enabled,
- LLViewerFetchedTexture* texp);
- ~LLFloaterTexturePicker() override {}
- // LLView overrides
- bool handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
- EDragAndDropType cargo_type, void* cargo_data,
- EAcceptance* accept, std::string& tooltip) override;
- void draw() override;
- bool handleKeyHere(KEY key, MASK mask) override;
- // LLFloater overrides
- bool postBuild() override;
- void onClose(bool app_quitting) override;
- void setImageID(const LLUUID& image_asset_id);
- void updateImageStats();
- LL_INLINE const LLUUID& getAssetID() { return mImageAssetID; }
- const LLUUID& findItemID(const LLUUID& asset_id, bool copyable_only);
- void setCanApplyImmediately(bool b);
- void setLocalTextureEnabled(bool b);
- void setBakeTextureEnabled(bool enabled);
- LL_INLINE void setDirty(bool b) { mIsDirty = b; }
- LL_INLINE bool isDirty() const override { return mIsDirty; }
- void setActive(bool active);
- LL_INLINE LLTextureCtrl* getOwner() const { return mOwner; }
- LL_INLINE void setOwner(LLTextureCtrl* owner) { mOwner = owner; }
- void stopUsingPipette();
- PermissionMask getFilterPermMask();
- void updateFilterPermMask();
- void setImmediateFilterPermMask(PermissionMask mask);
- void commitIfImmediateSet();
- private:
- static void onBtnSetToDefault(void* userdata);
- static void onBtnSelect(void* userdata);
- static void onBtnCancel(void* userdata);
- static void onBtnPipette(void* userdata);
- static void onBtnBlank(void* userdata);
- static void onBtnInvisible(void* userdata);
- static void onBtnNone(void* userdata);
- static void onBtnClear(void* userdata);
- static void onBtnAdd(void* userdata);
- static void onBtnRemove(void* userdata);
- static void onBtnUpload(void* userdata);
- static void onSelectionChange(LLFolderView* folderp, bool user_action,
- void* userdata);
- static void onApplyImmediateCheck(LLUICtrl* ctrlp, void* userdata);
- static void onBakeTextureSelect(LLUICtrl* ctrlp, void* userdata);
- static void onSearchEdit(const std::string& search_string, void* userdata);
- static void onTextureSelect(const LLTextureEntry& te, void* userdata);
- static void onModeSelect(LLUICtrl*, void* userdata);
- static void onLocalScrollCommit(LLUICtrl*, void* userdata);
- static void onDragHandleClicked(S32 x, S32 y, void* userdata);
- protected:
- LLPointer<LLViewerFetchedTexture> mTexturep;
- // What to show if currently selected texture is null:
- LLPointer<LLViewerFetchedTexture> mFallbackImagep;
- LLTextureCtrl* mOwner;
- LLTextBox* mTentativeLabel;
- LLTextBox* mResolutionLabel;
- LLButton* mPipetteButton;
- LLButton* mSelectButton;
- LLButton* mDefaultButton;
- LLButton* mNoneButton;
- LLButton* mBlankButton;
- LLButton* mInvisibleButton;
- LLButton* mAddButton;
- LLButton* mRemoveButton;
- LLButton* mUploadButton;
- LLCheckBoxCtrl* mApplyImmediatelyCheck;
- LLComboBox* mBakeTextureCombo;
- LLSearchEditor* mSearchEdit;
- LLInventoryPanel* mInventoryPanel;
- LLRadioGroup* mModeSelector;
- LLScrollListCtrl* mLocalScrollCtrl;
- LLUUID mBlankImageAssetID;
- LLUUID mInvisibleImageAssetID;
- // Currently selected texture
- LLUUID mImageAssetID;
- // Used when the asset id has no corresponding texture in the user's
- // inventory:
- LLUUID mSpecialCurrentImageAssetID;
- LLUUID mOriginalImageAssetID;
- std::string mLabel;
- std::string mPendingName;
- S32 mLastBitmapsListVersion;
- F32 mContextConeOpacity;
- LLSaveFolderState mSavedFolderState;
- PermissionMask mImmediateFilterPermMask;
- PermissionMask mNonImmediateFilterPermMask;
- bool mIsDirty;
- bool mActive;
- bool mCanApplyImmediately;
- bool mNoCopyTextureSelected;
- bool mBakeTextureEnabled;
- };
- LLFloaterTexturePicker::LLFloaterTexturePicker(LLTextureCtrl* owner,
- const LLRect& rect,
- const std::string& label,
- PermissionMask immediate_filter_perm_mask,
- PermissionMask non_immediate_filter_perm_mask,
- bool can_apply_immediately,
- bool allow_local_texture,
- bool bake_texture_enabled,
- LLViewerFetchedTexture* texp)
- : LLFloater("texture picker", rect, "Pick: " + label, true,
- TEX_PICKER_MIN_WIDTH, TEX_PICKER_MIN_HEIGHT),
- mOwner(owner),
- mImageAssetID(owner->getImageAssetID()),
- mBlankImageAssetID(owner->getBlankImageAssetID()),
- mInvisibleImageAssetID(gSavedSettings.getString("UIImgInvisibleUUID")),
- mOriginalImageAssetID(owner->getImageAssetID()),
- mLabel(label),
- mIsDirty(false),
- mActive(true),
- mImmediateFilterPermMask(immediate_filter_perm_mask),
- mNonImmediateFilterPermMask(non_immediate_filter_perm_mask),
- mNoCopyTextureSelected(false),
- mCanApplyImmediately(can_apply_immediately),
- mBakeTextureEnabled(false),
- mFallbackImagep(texp),
- mContextConeOpacity(0.f),
- mLastBitmapsListVersion(-1)
- {
- LLUICtrlFactory::getInstance()->buildFloater(this,
- "floater_texture_ctrl.xml");
- mTentativeLabel = getChild<LLTextBox>("Multiple");
- mResolutionLabel = getChild<LLTextBox>("unknown");
- mDefaultButton = getChild<LLButton>("Default");
- mDefaultButton->setClickedCallback(onBtnSetToDefault, this);
- mNoneButton = getChild<LLButton>("None");
- mNoneButton->setClickedCallback(onBtnNone, this);
- mBlankButton = getChild<LLButton>("Blank");
- mBlankButton->setClickedCallback(onBtnBlank, this);
- mInvisibleButton = getChild<LLButton>("Invisible");
- mInvisibleButton->setClickedCallback(onBtnInvisible, this);
- mAddButton = getChild<LLButton>("Add");
- mAddButton->setClickedCallback(onBtnAdd, this);
- mRemoveButton = getChild<LLButton>("Remove");
- mRemoveButton->setClickedCallback(onBtnRemove, this);
- mRemoveButton->setEnabled(false);
- mUploadButton = getChild<LLButton>("Upload");
- mUploadButton->setClickedCallback(onBtnUpload, this);
- mUploadButton->setEnabled(false);
- mModeSelector = getChild<LLRadioGroup>("mode_selection");
- mModeSelector->setCommitCallback(onModeSelect);
- mModeSelector->setCallbackUserData(this);
- mLocalScrollCtrl = getChild<LLScrollListCtrl>("l_name_list");
- mLocalScrollCtrl->setCommitCallback(onLocalScrollCommit);
- mLocalScrollCtrl->setCallbackUserData(this);
- mLocalScrollCtrl->setCommitOnSelectionChange(true);
- mSearchEdit = getChild<LLSearchEditor>("inventory search editor");
- mSearchEdit->setSearchCallback(onSearchEdit, this);
- // Initialize before mInventoryPanel, since mApplyImmediatelyCheck is used
- // in getFilterPermMask() that we call to set the inventory panel filter
- // permission mask. HB
- mApplyImmediatelyCheck = getChild<LLCheckBoxCtrl>("apply_immediate_check");
- mApplyImmediatelyCheck->set(mCanApplyImmediately &&
- gSavedSettings.getBool("ApplyTextureImmediately"));
- mApplyImmediatelyCheck->setEnabled(mCanApplyImmediately);
- mApplyImmediatelyCheck->setCommitCallback(onApplyImmediateCheck);
- mApplyImmediatelyCheck->setCallbackUserData(this);
- mInventoryPanel = getChild<LLInventoryPanel>("inventory panel");
- U32 filter_types = 0x0;
- filter_types |= 0x1 << LLInventoryType::IT_TEXTURE;
- filter_types |= 0x1 << LLInventoryType::IT_SNAPSHOT;
- mInventoryPanel->setFilterTypes(filter_types);
- mInventoryPanel->setFilterPermMask(getFilterPermMask());
- mInventoryPanel->setFilterPermMask(mImmediateFilterPermMask);
- mInventoryPanel->setSelectCallback(onSelectionChange, this);
- mInventoryPanel->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
- mInventoryPanel->setAllowMultiSelect(false);
- // Store this filter as the default one
- mInventoryPanel->getRootFolder()->getFilter()->markDefault();
- mInventoryPanel->openDefaultFolderForType(LLAssetType::AT_TEXTURE);
- // Do not put keyboard focus on selected item, because the selection
- // callback will assume that this was user input:
- mInventoryPanel->setSelection(findItemID(mImageAssetID, false),
- TAKE_FOCUS_NO);
- mBakeTextureCombo = getChild<LLComboBox>("bake_texture_combo");
- mBakeTextureCombo->setCommitCallback(onBakeTextureSelect);
- mBakeTextureCombo->setCallbackUserData(this);
- mPipetteButton = getChild<LLButton>("Pipette");
- mPipetteButton->setClickedCallback(onBtnPipette, this);
- childSetAction("Cancel", LLFloaterTexturePicker::onBtnCancel, this);
- mSelectButton = getChild<LLButton>("Select");
- mSelectButton->setClickedCallback(onBtnSelect, this);
- // Update permission filter once UI is fully initialized
- updateFilterPermMask();
- setCanMinimize(false);
- mSavedFolderState.setApply(false);
- LLDragHandle* drag_handle = getDragHandle();
- if (drag_handle)
- {
- drag_handle->setClickedCallback(onDragHandleClicked, this);
- }
- setLocalTextureEnabled(allow_local_texture);
- setBakeTextureEnabled(bake_texture_enabled);
- }
- //virtual
- bool LLFloaterTexturePicker::postBuild()
- {
- if (!mLabel.empty())
- {
- std::string pick = getString("pick title");
- setTitle(pick + mLabel);
- }
- return true;
- }
- //virtual
- void LLFloaterTexturePicker::onClose(bool app_quitting)
- {
- if (mOwner)
- {
- mOwner->onFloaterClose();
- }
- stopUsingPipette();
- destroy();
- }
- //virtual
- void LLFloaterTexturePicker::draw()
- {
- if (mOwner)
- {
- // Draw cone of context pointing back to texture swatch
- LLRect owner_rect;
- mOwner->localRectToOtherView(mOwner->getLocalRect(), &owner_rect,
- this);
- LLRect local_rect = getLocalRect();
- if (gFocusMgr.childHasKeyboardFocus(this) &&
- mOwner->isInVisibleChain() && mContextConeOpacity > 0.001f)
- {
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- LLGLEnable(GL_CULL_FACE);
- gGL.begin(LLRender::TRIANGLE_STRIP);
- {
- F32 alpha_in = CONTEXT_CONE_IN_ALPHA * mContextConeOpacity;
- F32 alpha_out = CONTEXT_CONE_OUT_ALPHA * mContextConeOpacity;
- gGL.color4f(0.f, 0.f, 0.f, alpha_out);
- gGL.vertex2i(local_rect.mLeft, local_rect.mTop);
- gGL.color4f(0.f, 0.f, 0.f, alpha_in);
- gGL.vertex2i(owner_rect.mLeft, owner_rect.mTop);
- gGL.color4f(0.f, 0.f, 0.f, alpha_out);
- gGL.vertex2i(local_rect.mRight, local_rect.mTop);
- gGL.color4f(0.f, 0.f, 0.f, alpha_in);
- gGL.vertex2i(owner_rect.mRight, owner_rect.mTop);
- gGL.color4f(0.f, 0.f, 0.f, alpha_out);
- gGL.vertex2i(local_rect.mRight, local_rect.mBottom);
- gGL.color4f(0.f, 0.f, 0.f, alpha_in);
- gGL.vertex2i(owner_rect.mRight, owner_rect.mBottom);
- gGL.color4f(0.f, 0.f, 0.f, alpha_out);
- gGL.vertex2i(local_rect.mLeft, local_rect.mBottom);
- gGL.color4f(0.f, 0.f, 0.f, alpha_in);
- gGL.vertex2i(owner_rect.mLeft, owner_rect.mBottom);
- gGL.color4f(0.f, 0.f, 0.f, alpha_out);
- gGL.vertex2i(local_rect.mLeft, local_rect.mTop);
- gGL.color4f(0.f, 0.f, 0.f, alpha_in);
- gGL.vertex2i(owner_rect.mLeft, owner_rect.mTop);
- }
- gGL.end();
- }
- }
- F32 opacity = 0.f;
- if (gFocusMgr.childHasMouseCapture(getDragHandle()))
- {
- static LLCachedControl<F32> picker_opacity(gSavedSettings,
- "PickerContextOpacity");
- opacity = picker_opacity;
- }
- mContextConeOpacity =
- lerp(mContextConeOpacity, opacity,
- LLCriticalDamp::getInterpolant(CONTEXT_FADE_TIME));
- updateImageStats();
- // If we are inactive, gray out "apply immediate" checkbox
- mSelectButton->setEnabled(mActive);
- mPipetteButton->setEnabled(mActive);
- mPipetteButton->setValue(gToolMgr.isCurrentTool(&gToolPipette));
- // RN: reset search bar to reflect actual search query (all caps, for
- // example)
- mSearchEdit->setText(mInventoryPanel->getFilterSubString());
- if (mOwner)
- {
- mTexturep = NULL;
- if (mImageAssetID.notNull())
- {
- if (LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
- {
- LLViewerObject* obj =
- gSelectMgr.getSelection()->getFirstObject();
- if (obj)
- {
- LLViewerTexture* baked_tex =
- obj->getBakedTextureForMagicId(mImageAssetID);
- if (baked_tex)
- {
- mTexturep = baked_tex->asFetched();
- }
- }
- }
- if (mTexturep.isNull())
- {
- mTexturep =
- LLViewerTextureManager::getFetchedTexture(mImageAssetID,
- FTT_DEFAULT,
- true,
- LLGLTexture::BOOST_PREVIEW);
- }
- }
- else if (mFallbackImagep.notNull())
- {
- mTexturep = mFallbackImagep;
- }
- if (mTentativeLabel)
- {
- mTentativeLabel->setVisible(false);
- }
- const LLUUID& default_id = mOwner->getDefaultImageAssetID();
- mDefaultButton->setEnabled(default_id.notNull() &&
- mImageAssetID != default_id);
- mBlankButton->setEnabled(mImageAssetID != mBlankImageAssetID);
- mInvisibleButton->setEnabled(mOwner->getAllowInvisibleTexture() &&
- mImageAssetID != mInvisibleImageAssetID);
- mNoneButton->setEnabled(mOwner->getAllowNoTexture() &&
- mImageAssetID.notNull());
- // Fill-up the local bitmap list if needed
- if (mLastBitmapsListVersion != LLLocalBitmap::getBitmapListVersion())
- {
- mLastBitmapsListVersion = LLLocalBitmap::getBitmapListVersion();
- mLocalScrollCtrl->clearRows();
- const LLLocalBitmap::list_t& bitmaps = LLLocalBitmap::getBitmapList();
- if (!bitmaps.empty())
- {
- for (LLLocalBitmap::list_t::const_iterator
- iter = bitmaps.begin(), end = bitmaps.end();
- iter != end; ++iter)
- {
- LLLocalBitmap* bitmap = *iter;
- if (!bitmap) continue; // Paranoia
- LLSD element;
- element["id"] = bitmap->getTrackingID();
- element["columns"][0]["column"] = "unit_name";
- element["columns"][0]["type"] = "text";
- element["columns"][0]["value"] = bitmap->getShortName();
- mLocalScrollCtrl->addElement(element);
- }
- }
- }
- LLFloater::draw();
- if (isMinimized())
- {
- return;
- }
- // Border
- LLRect border(BORDER_PAD,
- getRect().getHeight() - LLFLOATER_HEADER_SIZE - BORDER_PAD,
- TEX_PICKER_MIN_WIDTH / 2 - TEXTURE_INVENTORY_PADDING - HPAD - BORDER_PAD,
- BORDER_PAD + FOOTER_HEIGHT + getRect().getHeight() - TEX_PICKER_MIN_HEIGHT);
- gl_rect_2d(border, LLColor4::black, false);
- // Interior
- LLRect interior = border;
- interior.stretch(-1);
- if (mTexturep)
- {
- if (mTexturep->getComponents() == 4)
- {
- gl_rect_2d_checkerboard(interior);
- }
- F32 width = interior.getWidth();
- F32 height = interior.getHeight();
- gl_draw_scaled_image(interior.mLeft, interior.mBottom,
- width, height, mTexturep);
- // Pump the priority
- mTexturep->addTextureStats(width * height);
- // Draw Tentative Label over the image
- if (mOwner->getTentative() && !mIsDirty)
- {
- mTentativeLabel->setVisible(true);
- drawChild(mTentativeLabel);
- }
- }
- else
- {
- gl_rect_2d(interior, LLColor4::grey);
- // Draw X
- gl_draw_x(interior, LLColor4::black);
- }
- }
- }
- //virtual
- bool LLFloaterTexturePicker::handleDragAndDrop(S32 x, S32 y, MASK mask,
- bool drop,
- EDragAndDropType cargo_type,
- void* cargo_data,
- EAcceptance* accept,
- std::string& tooltip_msg)
- {
- //MK
- if (gRLenabled && gRLInterface.mContainsShowinv)
- {
- *accept = ACCEPT_NO;
- return true;
- }
- //mk
- #if LL_MESH_ASSET_SUPPORT
- if (cargo_type == DAD_TEXTURE || cargo_type == DAD_MESH)
- #else
- if (cargo_type == DAD_TEXTURE)
- #endif
- {
- LLInventoryItem* item = (LLInventoryItem*)cargo_data;
- const LLPermissions& perms = item->getPermissions();
- PermissionMask item_perm_mask = 0;
- if (perms.allowCopyBy(gAgentID))
- {
- item_perm_mask = PERM_COPY;
- }
- if (perms.allowModifyBy(gAgentID))
- {
- item_perm_mask |= PERM_MODIFY;
- }
- if (perms.allowTransferBy(gAgentID))
- {
- item_perm_mask |= PERM_TRANSFER;
- }
- PermissionMask filter_perm_mask = getFilterPermMask();
- if ((item_perm_mask & filter_perm_mask) == filter_perm_mask)
- {
- if (drop)
- {
- setImageID(item->getAssetUUID());
- commitIfImmediateSet();
- }
- *accept = ACCEPT_YES_SINGLE;
- }
- else
- {
- *accept = ACCEPT_NO;
- }
- }
- else
- {
- *accept = ACCEPT_NO;
- }
- LL_DEBUGS("UserInput") << "dragAndDrop handled by LLFloaterTexturePicker "
- << getName() << LL_ENDL;
- return true;
- }
- //virtual
- bool LLFloaterTexturePicker::handleKeyHere(KEY key, MASK mask)
- {
- LLFolderView* root_folder = mInventoryPanel->getRootFolder();
- if (root_folder && mSearchEdit)
- {
- if (mSearchEdit->hasFocus() && mask == MASK_NONE &&
- (key == KEY_RETURN || key == KEY_DOWN))
- {
- if (!root_folder->getCurSelectedItem())
- {
- LLFolderViewItem* itemp =
- root_folder->getItemByID(gInventory.getRootFolderID());
- if (itemp)
- {
- root_folder->setSelection(itemp, false, false);
- mSelectButton->setEnabled(true);
- }
- else
- {
- mSelectButton->setEnabled(false);
- }
- }
- root_folder->scrollToShowSelection();
- // Move focus to inventory proper
- root_folder->setFocus(true);
- // Treat this as a user selection of the first filtered result
- commitIfImmediateSet();
- return true;
- }
- if (root_folder->hasFocus() && key == KEY_UP)
- {
- mSearchEdit->focusFirstItem(true);
- }
- }
- return LLFloater::handleKeyHere(key, mask);
- }
- void LLFloaterTexturePicker::setImageID(const LLUUID& image_id)
- {
- if (!mActive || mImageAssetID == image_id)
- {
- return;
- }
- mNoCopyTextureSelected = false;
- mIsDirty = true;
- mImageAssetID = image_id;
- S32 mode = mModeSelector->getSelectedIndex();
- if (LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
- {
- if (mBakeTextureEnabled && mode != 2)
- {
- mModeSelector->setSelectedIndex(2, 0);
- onModeSelect((LLUICtrl*)mModeSelector, this);
- }
- }
- else
- {
- if (mode == 2)
- {
- mModeSelector->setSelectedIndex(0, 0);
- onModeSelect((LLUICtrl*)mModeSelector, this);
- }
- LLUUID item_id = findItemID(mImageAssetID, false);
- if (item_id.isNull())
- {
- mInventoryPanel->getRootFolder()->clearSelection();
- }
- else
- {
- LLInventoryItem* itemp = gInventory.getItem(image_id);
- if (itemp && !itemp->getPermissions().allowCopyBy(gAgentID))
- {
- // No-copy texture
- mApplyImmediatelyCheck->set(false);
- mNoCopyTextureSelected = true;
- }
- mInventoryPanel->setSelection(item_id, TAKE_FOCUS_NO);
- }
- }
- }
- void LLFloaterTexturePicker::setActive(bool active)
- {
- if (!active && mPipetteButton->getValue().asBoolean())
- {
- stopUsingPipette();
- }
- mActive = active;
- }
- void LLFloaterTexturePicker::setCanApplyImmediately(bool b)
- {
- mCanApplyImmediately = b;
- if (!mCanApplyImmediately)
- {
- mApplyImmediatelyCheck->set(false);
- }
- mApplyImmediatelyCheck->setEnabled(mCanApplyImmediately);
- updateFilterPermMask();
- }
- void LLFloaterTexturePicker::setLocalTextureEnabled(bool b)
- {
- mModeSelector->setIndexEnabled(1, b);
- }
- void LLFloaterTexturePicker::setBakeTextureEnabled(bool b)
- {
- bool changed = b != mBakeTextureEnabled;
- mBakeTextureEnabled = b;
- mModeSelector->setIndexEnabled(2, b);
- S32 mode = mModeSelector->getSelectedIndex();
- if (!b && mode == 2)
- {
- mModeSelector->setSelectedIndex(0, 0);
- }
- if (changed && b && mode != 2 &&
- LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
- {
- mModeSelector->setSelectedIndex(2, 0);
- }
- onModeSelect((LLUICtrl*)mModeSelector, this);
- }
- void LLFloaterTexturePicker::stopUsingPipette()
- {
- if (gToolMgr.isCurrentTool(&gToolPipette))
- {
- gToolMgr.clearTransientTool();
- }
- }
- void LLFloaterTexturePicker::updateImageStats()
- {
- if (mTexturep.notNull())
- {
- // RN: have we received header data for this image ?
- if (mTexturep->getFullWidth() > 0 && mTexturep->getFullHeight() > 0)
- {
- std::string formatted_dims = llformat("%d x %d",
- mTexturep->getFullWidth(),
- mTexturep->getFullHeight());
- mResolutionLabel->setTextArg("[DIMENSIONS]", formatted_dims);
- }
- else
- {
- mResolutionLabel->setTextArg("[DIMENSIONS]",
- std::string("[? x ?]"));
- }
- }
- else
- {
- mResolutionLabel->setTextArg("[DIMENSIONS]", std::string(""));
- }
- }
- const LLUUID& LLFloaterTexturePicker::findItemID(const LLUUID& asset_id,
- bool copyable_only)
- {
- LLViewerInventoryCategory::cat_array_t cats;
- LLViewerInventoryItem::item_array_t items;
- LLAssetIDMatches asset_id_matches(asset_id);
- gInventory.collectDescendentsIf(LLUUID::null, cats, items,
- LLInventoryModel::INCLUDE_TRASH,
- asset_id_matches);
- S32 count = items.size();
- if (count > 0)
- {
- // Search for copyable version first
- for (S32 i = 0; i < count; ++i)
- {
- LLInventoryItem* itemp = items[i];
- LLPermissions item_permissions = itemp->getPermissions();
- if (item_permissions.allowCopyBy(gAgentID, gAgent.getGroupID()))
- {
- return itemp->getUUID();
- }
- }
- // Otherwise just return first instance, unless copyable requested
- if (!copyable_only)
- {
- return items[0]->getUUID();
- }
- }
- return LLUUID::null;
- }
- PermissionMask LLFloaterTexturePicker::getFilterPermMask()
- {
- return mApplyImmediatelyCheck->get() ? mImmediateFilterPermMask
- : mNonImmediateFilterPermMask;
- }
- void LLFloaterTexturePicker::commitIfImmediateSet()
- {
- if (!mNoCopyTextureSelected && mOwner)
- {
- if (mCanApplyImmediately && mApplyImmediatelyCheck->get())
- {
- mOwner->onFloaterCommit(LLTextureCtrl::TEXTURE_CHANGE);
- }
- }
- }
- //static
- void LLFloaterTexturePicker::onBtnSetToDefault(void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (self)
- {
- if (self->mOwner)
- {
- self->setImageID(self->mOwner->getDefaultImageAssetID());
- }
- self->mSelectButton->setEnabled(true);
- self->commitIfImmediateSet();
- }
- }
- //static
- void LLFloaterTexturePicker::onBtnBlank(void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (self)
- {
- self->mSelectButton->setEnabled(true);
- self->setImageID(self->mBlankImageAssetID);
- self->commitIfImmediateSet();
- }
- }
- //static
- void LLFloaterTexturePicker::onBtnInvisible(void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (self)
- {
- self->mSelectButton->setEnabled(true);
- self->setImageID(self->mInvisibleImageAssetID);
- self->commitIfImmediateSet();
- }
- }
- //static
- void LLFloaterTexturePicker::onBtnNone(void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (self)
- {
- self->mSelectButton->setEnabled(true);
- self->setImageID(LLUUID::null);
- self->commitIfImmediateSet();
- }
- }
- //static
- void LLFloaterTexturePicker::onBtnCancel(void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (self)
- {
- self->setImageID(self->mOriginalImageAssetID);
- if (self->mOwner)
- {
- self->mOwner->onFloaterCommit(LLTextureCtrl::TEXTURE_CANCEL);
- }
- self->mIsDirty = false;
- self->close();
- }
- }
- //static
- void LLFloaterTexturePicker::onBtnSelect(void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (self)
- {
- if (self->mOwner)
- {
- LLUUID local_id, tracking_id;
- if (self->mLocalScrollCtrl->getVisible() &&
- !self->mLocalScrollCtrl->getAllSelected().empty())
- {
- tracking_id = self->mLocalScrollCtrl->getCurrentID();
- local_id = LLLocalBitmap::getWorldID(tracking_id);
- }
- self->mOwner->onFloaterCommit(LLTextureCtrl::TEXTURE_SELECT,
- local_id, tracking_id);
- }
- self->close();
- }
- }
- //static
- void LLFloaterTexturePicker::onBtnPipette(void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (self)
- {
- bool pipette_active = self->mPipetteButton->getValue().asBoolean();
- pipette_active = !pipette_active;
- if (pipette_active)
- {
- gToolPipette.setSelectCallback(onTextureSelect, self);
- gToolMgr.setTransientTool(&gToolPipette);
- }
- else
- {
- gToolMgr.clearTransientTool();
- }
- }
- }
- //static
- void LLFloaterTexturePicker::onSelectionChange(LLFolderView* folderp,
- bool user_action, void* data)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)data;
- if (!self || !folderp) return;
- bool can_select = false;
- const LLFolderView::selected_items_t& items = folderp->getSelectedItems();
- if (items.size())
- {
- LLFolderViewItem* first_itemp = items.front();
- LLInventoryItem* itemp =
- gInventory.getItem(first_itemp->getListener()->getUUID());
- self->mNoCopyTextureSelected = false;
- if (itemp)
- {
- can_select = true;
- if (!itemp->getPermissions().allowCopyBy(gAgentID))
- {
- self->mNoCopyTextureSelected = true;
- }
- self->mImageAssetID = itemp->getAssetUUID();
- self->mIsDirty = true;
- if (user_action)
- {
- // Only commit intentional selections, not implicit ones
- self->commitIfImmediateSet();
- }
- }
- }
- self->mSelectButton->setEnabled(can_select);
- }
- //static
- void LLFloaterTexturePicker::onModeSelect(LLUICtrl*, void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (!self) return;
- S32 mode = self->mModeSelector->getSelectedIndex();
- bool inventory = mode == 0;
- bool local = mode == 1;
- bool bakes = mode == 2;
- self->mDefaultButton->setVisible(inventory);
- self->mBlankButton->setVisible(inventory);
- self->mNoneButton->setVisible(inventory);
- self->mInvisibleButton->setVisible(inventory);
- self->mPipetteButton->setVisible(inventory);
- self->mSearchEdit->setVisible(inventory);
- self->mPipetteButton->setVisible(inventory);
- self->mInventoryPanel->setVisible(inventory);
- self->mAddButton->setVisible(local);
- self->mRemoveButton->setVisible(local);
- self->mUploadButton->setVisible(local);
- self->mLocalScrollCtrl->setVisible(local);
- self->mBakeTextureCombo->setVisible(bakes);
- if (bakes)
- {
- self->stopUsingPipette();
- const LLUUID& image_id = self->mImageAssetID;
- S32 idx = -1;
- if (image_id == IMG_USE_BAKED_HEAD)
- {
- idx = 0;
- }
- else if (image_id == IMG_USE_BAKED_UPPER)
- {
- idx = 1;
- }
- else if (image_id == IMG_USE_BAKED_LOWER)
- {
- idx = 2;
- }
- else if (image_id == IMG_USE_BAKED_HAIR)
- {
- idx = 3;
- }
- else if (image_id == IMG_USE_BAKED_EYES)
- {
- idx = 4;
- }
- else if (image_id == IMG_USE_BAKED_SKIRT)
- {
- idx = 5;
- }
- else if (image_id == IMG_USE_BAKED_LEFTARM)
- {
- idx = 6;
- }
- else if (image_id == IMG_USE_BAKED_LEFTLEG)
- {
- idx = 7;
- }
- else if (image_id == IMG_USE_BAKED_AUX1)
- {
- idx = 8;
- }
- else if (image_id == IMG_USE_BAKED_AUX2)
- {
- idx = 9;
- }
- else if (image_id == IMG_USE_BAKED_AUX3)
- {
- idx = 10;
- }
- self->mBakeTextureCombo->setSelectedByValue(idx, true);
- self->mSelectButton->setEnabled(true);
- }
- }
- //static
- void LLFloaterTexturePicker::onBtnAdd(void* userdata)
- {
- LLLocalBitmap::addUnits();
- }
- //static
- void LLFloaterTexturePicker::onBtnRemove(void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (!self) return;
- std::vector<LLScrollListItem*> selected_items =
- self->mLocalScrollCtrl->getAllSelected();
- if (!selected_items.empty())
- {
- for (std::vector<LLScrollListItem*>::iterator
- iter = selected_items.begin(), end = selected_items.end();
- iter != end; ++iter)
- {
- LLScrollListItem* list_item = *iter;
- if (list_item)
- {
- LLUUID id = list_item->getUUID();
- LLLocalBitmap::delUnit(id);
- }
- }
- self->mRemoveButton->setEnabled(false);
- self->mUploadButton->setEnabled(false);
- }
- }
- //static
- void LLFloaterTexturePicker::onBtnUpload(void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (self)
- {
- std::vector<LLScrollListItem*> items =
- self->mLocalScrollCtrl->getAllSelected();
- for (std::vector<LLScrollListItem*>::iterator
- iter = items.begin(), end = items.end();
- iter != end; ++iter)
- {
- LLScrollListItem* list_item = *iter;
- if (list_item)
- {
- LLUUID tracking_id = list_item->getUUID();
- std::string filename = LLLocalBitmap::getFilename(tracking_id);
- new LLFloaterImagePreview(filename);
- }
- }
- }
- }
- //static
- void LLFloaterTexturePicker::onLocalScrollCommit(LLUICtrl*, void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (!self) return;
- uuid_vec_t ids = self->mLocalScrollCtrl->getSelectedIDs();
- S32 items = ids.size();
- bool has_selection = items > 0;
- bool has_one_selection = items == 1;
- self->mRemoveButton->setEnabled(has_selection);
- self->mUploadButton->setEnabled(has_selection);
- self->mSelectButton->setEnabled(has_one_selection);
- if (has_one_selection && self->mOwner)
- {
- const LLUUID& inworld_id = LLLocalBitmap::getWorldID(ids[0]);
- self->mOwner->setImageAssetID(inworld_id);
- if (self->mCanApplyImmediately && self->mApplyImmediatelyCheck->get())
- {
- self->mOwner->onFloaterCommit(LLTextureCtrl::TEXTURE_CHANGE,
- inworld_id, ids[0]);
- }
- }
- }
- //static
- void LLFloaterTexturePicker::onApplyImmediateCheck(LLUICtrl* ctrlp,
- void* user_data)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)user_data;
- LLCheckBoxCtrl* checkp = (LLCheckBoxCtrl*)ctrlp;
- if (self && checkp)
- {
- gSavedSettings.setBool("ApplyTextureImmediately", checkp->get());
- self->updateFilterPermMask();
- self->commitIfImmediateSet();
- }
- }
- //static
- void LLFloaterTexturePicker::onBakeTextureSelect(LLUICtrl* ctrlp,
- void* user_data)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)user_data;
- LLComboBox* combop = (LLComboBox*)ctrlp;
- if (!self || !combop) return;
- LLUUID image_id = self->mOwner->getDefaultImageAssetID();
- S32 type = combop->getValue().asInteger();
- switch (type)
- {
- case 0: image_id = IMG_USE_BAKED_HEAD; break;
- case 1: image_id = IMG_USE_BAKED_UPPER; break;
- case 2: image_id = IMG_USE_BAKED_LOWER; break;
- case 3: image_id = IMG_USE_BAKED_HAIR; break;
- case 4: image_id = IMG_USE_BAKED_EYES; break;
- case 5: image_id = IMG_USE_BAKED_SKIRT; break;
- case 6: image_id = IMG_USE_BAKED_LEFTARM; break;
- case 7: image_id = IMG_USE_BAKED_LEFTLEG; break;
- case 8: image_id = IMG_USE_BAKED_AUX1; break;
- case 9: image_id = IMG_USE_BAKED_AUX2; break;
- case 10: image_id = IMG_USE_BAKED_AUX3; break;
- default: break;
- }
- self->setImageID(image_id);
- self->mSelectButton->setEnabled(true);
- self->commitIfImmediateSet();
- }
- void LLFloaterTexturePicker::updateFilterPermMask()
- {
- mInventoryPanel->setFilterPermMask(getFilterPermMask());
- }
- void LLFloaterTexturePicker::setImmediateFilterPermMask(PermissionMask mask)
- {
- // Do not re-apply the same mask: it would cause an useless inventory
- // re-filtering. HB
- if (mImmediateFilterPermMask != mask)
- {
- mImmediateFilterPermMask = mask;
- mInventoryPanel->setFilterPermMask(mask);
- }
- }
- void LLFloaterTexturePicker::onSearchEdit(const std::string& search_string,
- void* user_data)
- {
- LLFloaterTexturePicker* picker = (LLFloaterTexturePicker*)user_data;
- if (!picker) return;
- std::string upper_case_search_string = search_string;
- LLStringUtil::toUpper(upper_case_search_string);
- if (upper_case_search_string.empty())
- {
- if (picker->mInventoryPanel->getFilterSubString().empty())
- {
- // current filter and new filter empty, do nothing
- return;
- }
- picker->mSavedFolderState.setApply(true);
- picker->mInventoryPanel->getRootFolder()->applyFunctorRecursively(picker->mSavedFolderState);
- // Add folder with current item to list of previously opened folders
- LLOpenFoldersWithSelection opener;
- picker->mInventoryPanel->getRootFolder()->applyFunctorRecursively(opener);
- picker->mInventoryPanel->getRootFolder()->scrollToShowSelection();
- }
- else if (picker->mInventoryPanel->getFilterSubString().empty())
- {
- // First letter in search term, save existing folder open state
- if (!picker->mInventoryPanel->getRootFolder()->isFilterModified())
- {
- picker->mSavedFolderState.setApply(false);
- picker->mInventoryPanel->getRootFolder()->applyFunctorRecursively(picker->mSavedFolderState);
- }
- }
- picker->mInventoryPanel->setFilterSubString(upper_case_search_string);
- }
- //static
- void LLFloaterTexturePicker::onTextureSelect(const LLTextureEntry& te,
- void* data)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)data;
- if (!self) return;
- LLUUID inventory_item_id = self->findItemID(te.getID(), true);
- if (inventory_item_id.notNull())
- {
- gToolPipette.setResult(true, "");
- self->setImageID(te.getID());
- self->mNoCopyTextureSelected = false;
- LLInventoryItem* itemp = gInventory.getItem(inventory_item_id);
- if (itemp && !itemp->getPermissions().allowCopyBy(gAgentID))
- {
- // No-copy texture
- self->mNoCopyTextureSelected = true;
- }
- self->commitIfImmediateSet();
- self->mSelectButton->setEnabled(true);
- }
- else
- {
- self->mSelectButton->setEnabled(false);
- gToolPipette.setResult(false, self->getString("not_in_inventory"));
- }
- }
- void LLFloaterTexturePicker::onDragHandleClicked(S32 x, S32 y, void* userdata)
- {
- LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (!self || !self->mTexturep || self->mImageAssetID.isNull() ||
- LLPreview::show(self->mImageAssetID))
- {
- return;
- }
- // Only react if the mouse pointer is within the preview area
- const LLRect& rect = self->getRect();
- LLRect preview_area(BORDER_PAD,
- rect.getHeight() - LLFLOATER_HEADER_SIZE - BORDER_PAD,
- TEX_PICKER_MIN_WIDTH / 2 - TEXTURE_INVENTORY_PADDING -
- HPAD - BORDER_PAD,
- BORDER_PAD + FOOTER_HEIGHT + rect.getHeight() -
- TEX_PICKER_MIN_HEIGHT);
- if (preview_area.pointInRect(x, y))
- {
- S32 left, top;
- gFloaterViewp->getNewFloaterPosition(&left, &top);
- LLRect rect = gSavedSettings.getRect("PreviewTextureRect");
- rect.translate(left - rect.mLeft, top - rect.mTop);
- std::string title = "Texture preview";
- LLPreviewTexture* preview = new LLPreviewTexture(title, rect, title,
- self->mImageAssetID,
- false);
- preview->setNotCopyable();
- preview->childSetText("desc", title);
- preview->childSetEnabled("desc", false);
- preview->setFocus(true);
- }
- }
- ///////////////////////////////////////////////////////////////////////////////
- // LLTextureCtrl class
- ///////////////////////////////////////////////////////////////////////////////
- static const std::string LL_TEXTURE_CTRL_TAG = "texture_picker";
- static LLRegisterWidget<LLTextureCtrl> r(LL_TEXTURE_CTRL_TAG);
- LLTextureCtrl::LLTextureCtrl(const std::string& name,
- const LLRect& rect,
- const std::string& label,
- const LLUUID& image_id,
- const LLUUID& default_image_id,
- const std::string& default_image_name)
- : LLUICtrl(name, rect, true, NULL, NULL, FOLLOWS_LEFT | FOLLOWS_TOP),
- mDragCallback(NULL),
- mDropCallback(NULL),
- mOnCancelCallback(NULL),
- mOnCloseCallback(NULL),
- mOnSelectCallback(NULL),
- mBorderColor(LLUI::sDefaultHighlightLight),
- mImageAssetID(image_id),
- mDefaultImageAssetID(default_image_id),
- mDefaultImageName(default_image_name),
- mBlankImageAssetID(gSavedSettings.getString("UIImgWhiteUUID")),
- mDisplayRatio(0.f),
- mLabel(label),
- mAllowNoTexture(false),
- mAllowInvisibleTexture(false),
- mAllowLocalTexture(true),
- mBakeTextureEnabled(false),
- mImmediateFilterPermMask(PERM_NONE),
- mNonImmediateFilterPermMask(PERM_NONE),
- mCanApplyImmediately(false),
- mValid(true),
- mDirty(false),
- mEnabled(true),
- mCaptionAlwaysEnabled(false),
- mShowLoadingPlaceholder(true)
- {
- mCaption = new LLTextBox(label,
- LLRect(0, gBtnHeightSmall, getRect().getWidth(), 0),
- label, LLFontGL::getFontSansSerifSmall());
- mCaption->setFollows(FOLLOWS_LEFT | FOLLOWS_RIGHT | FOLLOWS_BOTTOM);
- addChild(mCaption);
- S32 image_top = getRect().getHeight();
- S32 image_bottom = gBtnHeightSmall;
- S32 image_middle = (image_top + image_bottom) / 2;
- S32 line_height =
- ll_roundp(LLFontGL::getFontSansSerifSmall()->getLineHeight());
- mTentativeLabel = new LLTextBox(std::string("Multiple"),
- LLRect(0, image_middle + line_height / 2,
- getRect().getWidth(),
- image_middle - line_height / 2),
- std::string("Multiple"),
- LLFontGL::getFontSansSerifSmall());
- mTentativeLabel->setHAlign(LLFontGL::HCENTER);
- mTentativeLabel->setFollowsAll();
- addChild(mTentativeLabel);
- LLRect border_rect(0, getRect().getHeight(), getRect().getWidth(), 0);
- border_rect.mBottom += gBtnHeightSmall;
- mBorder = new LLViewBorder(std::string("border"), border_rect,
- LLViewBorder::BEVEL_IN);
- mBorder->setFollowsAll();
- addChild(mBorder);
- setEnabled(true); // For the tooltip
- mLoadingPlaceholderString = LLTrans::getWString("texture_loading");
- }
- //virtual
- LLTextureCtrl::~LLTextureCtrl()
- {
- closeFloater();
- }
- //virtual
- const std::string& LLTextureCtrl::getTag() const
- {
- return LL_TEXTURE_CTRL_TAG;
- }
- //virtual
- LLXMLNodePtr LLTextureCtrl::getXML(bool save_children) const
- {
- LLXMLNodePtr node = LLUICtrl::getXML();
- node->setName(LL_TEXTURE_CTRL_TAG);
- node->createChild("label", true)->setStringValue(getLabel());
- node->createChild("default_image_name", true)->setStringValue(getDefaultImageName());
- node->createChild("allow_no_texture", true)->setBoolValue(mAllowNoTexture);
- node->createChild("allow_invisible_texture", true)->setBoolValue(mAllowInvisibleTexture);
- node->createChild("can_apply_immediately", true)->setBoolValue(mCanApplyImmediately);
- return node;
- }
- LLView* LLTextureCtrl::fromXML(LLXMLNodePtr node, LLView* parent,
- LLUICtrlFactory* factory)
- {
- std::string name = LL_TEXTURE_CTRL_TAG;
- node->getAttributeString("name", name);
- LLRect rect;
- createRect(node, rect, parent);
- std::string label;
- node->getAttributeString("label", label);
- std::string image_id("");
- node->getAttributeString("image", image_id);
- std::string default_image_id("");
- node->getAttributeString("default_image", default_image_id);
- std::string default_image_name("Default");
- node->getAttributeString("default_image_name", default_image_name);
- bool allow_no_texture = false;
- node->getAttributeBool("allow_no_texture", allow_no_texture);
- bool allow_invisible_texture = false;
- node->getAttributeBool("allow_invisible_texture", allow_invisible_texture);
- bool can_apply_immediately = false;
- node->getAttributeBool("can_apply_immediately", can_apply_immediately);
- bool can_use_bakes = false;
- node->getAttributeBool("can_use_bakes", can_use_bakes);
- if (label.empty())
- {
- label.assign(node->getValue());
- }
- LLTextureCtrl* self = new LLTextureCtrl(name, rect, label,
- LLUUID(image_id),
- LLUUID(default_image_id),
- default_image_name);
- self->setAllowNoTexture(allow_no_texture);
- self->setAllowInvisibleTexture(allow_invisible_texture);
- self->setCanApplyImmediately(can_apply_immediately);
- self->setBakeTextureEnabled(can_use_bakes);
- self->initFromXML(node, parent);
- return self;
- }
- void LLTextureCtrl::setCaption(const std::string& caption)
- {
- mCaption->setText(caption);
- }
- void LLTextureCtrl::setCanApplyImmediately(bool b)
- {
- mCanApplyImmediately = b;
- LLFloaterTexturePicker* floaterp =
- (LLFloaterTexturePicker*)mFloaterHandle.get();
- if (floaterp)
- {
- floaterp->setCanApplyImmediately(b);
- }
- }
- void LLTextureCtrl::setBakeTextureEnabled(bool b)
- {
- mBakeTextureEnabled = b;
- LLFloaterTexturePicker* floaterp =
- (LLFloaterTexturePicker*)mFloaterHandle.get();
- if (floaterp)
- {
- floaterp->setBakeTextureEnabled(b);
- }
- }
- void LLTextureCtrl::setImmediateFilterPermMask(PermissionMask mask)
- {
- mImmediateFilterPermMask = mask;
- LLFloaterTexturePicker* floaterp =
- (LLFloaterTexturePicker*)mFloaterHandle.get();
- if (floaterp)
- {
- floaterp->setImmediateFilterPermMask(mask);
- }
- }
- //virtual
- void LLTextureCtrl::setVisible(bool visible)
- {
- if (!visible)
- {
- closeFloater();
- }
- LLUICtrl::setVisible(visible);
- }
- //virtual
- void LLTextureCtrl::setEnabled(bool enabled)
- {
- mEnabled = enabled;
- LLFloaterTexturePicker* floaterp =
- (LLFloaterTexturePicker*)mFloaterHandle.get();
- if (floaterp)
- {
- if (!enabled)
- {
- // *TODO: would be better to keep floater open and show disabled
- // state.
- closeFloater();
- }
- floaterp->setActive(enabled);
- }
- LLView::setEnabled(true);
- mCaption->setEnabled(enabled || mCaptionAlwaysEnabled);
- }
- void LLTextureCtrl::setValid(bool valid)
- {
- mValid = valid;
- if (!valid)
- {
- LLFloaterTexturePicker* pickerp =
- (LLFloaterTexturePicker*)mFloaterHandle.get();
- if (pickerp)
- {
- pickerp->setActive(false);
- }
- }
- }
- void LLTextureCtrl::setFallbackImageName(const std::string& image_name)
- {
- mFallbackImagep =
- LLViewerTextureManager::getFetchedTextureFromFile(image_name,
- MIPMAP_YES,
- LLGLTexture::BOOST_PREVIEW,
- LLViewerTexture::LOD_TEXTURE);
- }
- //virtual
- void LLTextureCtrl::clear()
- {
- setImageAssetID(LLUUID::null);
- }
- void LLTextureCtrl::setLabel(const std::string& label)
- {
- mLabel = label;
- mCaption->setText(label);
- }
- void LLTextureCtrl::showPicker(bool take_focus)
- {
- LLFloater* floaterp = mFloaterHandle.get();
- // Show the dialog
- if (floaterp)
- {
- floaterp->open();
- }
- else
- {
- if (!mLastFloaterLeftTop.mX && !mLastFloaterLeftTop.mY)
- {
- gFloaterViewp->getNewFloaterPosition(&mLastFloaterLeftTop.mX,
- &mLastFloaterLeftTop.mY);
- }
- LLRect rect = gSavedSettings.getRect("TexturePickerRect");
- rect.translate(mLastFloaterLeftTop.mX - rect.mLeft,
- mLastFloaterLeftTop.mY - rect.mTop);
- floaterp = new LLFloaterTexturePicker(this, rect, mLabel,
- mImmediateFilterPermMask,
- mNonImmediateFilterPermMask,
- mCanApplyImmediately,
- mAllowLocalTexture,
- mBakeTextureEnabled,
- mFallbackImagep.get());
- mFloaterHandle = floaterp->getHandle();
- if (gFloaterViewp)
- {
- LLFloater* parentp = gFloaterViewp->getParentFloater(this);
- if (parentp)
- {
- parentp->addDependentFloater(floaterp);
- }
- }
- floaterp->open();
- }
- if (take_focus)
- {
- floaterp->setFocus(true);
- }
- }
- void LLTextureCtrl::closeFloater()
- {
- LLFloaterTexturePicker* floaterp =
- (LLFloaterTexturePicker*)mFloaterHandle.get();
- if (floaterp)
- {
- floaterp->setOwner(NULL);
- floaterp->close();
- }
- }
- //virtual
- bool LLTextureCtrl::handleHover(S32 x, S32 y, MASK mask)
- {
- gWindowp->setCursor(UI_CURSOR_HAND);
- return true;
- }
- //virtual
- bool LLTextureCtrl::handleMouseDown(S32 x, S32 y, MASK mask)
- {
- if (!LLUICtrl::handleMouseDown(x, y , mask))
- {
- return false;
- }
- if (mEnabled)
- {
- showPicker(false);
- // Ensure textures default folder is loaded
- const LLUUID& tex_folder_id =
- gInventory.findCategoryUUIDForType(LLFolderType::FT_TEXTURE);
- LLInventoryModelFetch::getInstance()->start(tex_folder_id);
- }
- else if (mImageAssetID.notNull() && !LLPreview::show(mImageAssetID))
- {
- // There is no preview, so make a new one
- S32 left, top;
- gFloaterViewp->getNewFloaterPosition(&left, &top);
- LLRect rect = gSavedSettings.getRect("PreviewTextureRect");
- rect.translate(left - rect.mLeft, top - rect.mTop);
- std::string title = "Texture Preview";
- LLPreviewTexture* preview = new LLPreviewTexture(title, rect, title,
- mImageAssetID, false);
- preview->setNotCopyable();
- preview->childSetText("desc", title);
- preview->childSetEnabled("desc", false);
- preview->setFocus(true);
- }
- return true;
- }
- void LLTextureCtrl::onFloaterClose()
- {
- LLFloaterTexturePicker* floaterp =
- (LLFloaterTexturePicker*)mFloaterHandle.get();
- if (floaterp)
- {
- if (mOnCloseCallback)
- {
- mOnCloseCallback(this, mCallbackUserData);
- }
- floaterp->setOwner(NULL);
- mLastFloaterLeftTop.set(floaterp->getRect().mLeft,
- floaterp->getRect().mTop);
- }
- mFloaterHandle.markDead();
- }
- void LLTextureCtrl::onFloaterCommit(ETexturePickOp op, const LLUUID& id,
- const LLUUID& tracking_id)
- {
- LLFloaterTexturePicker* floaterp =
- (LLFloaterTexturePicker*)mFloaterHandle.get();
- if (floaterp && getEnabled())
- {
- mLocalTrackingID = tracking_id;
- mDirty = (op != TEXTURE_CANCEL);
- if (floaterp->isDirty() || id.notNull())
- {
- setTentative(false);
- if (id.notNull())
- {
- mImageItemID = id;
- mImageAssetID = id;
- }
- else
- {
- mImageItemID = floaterp->findItemID(floaterp->getAssetID(),
- false);
- LL_DEBUGS("TextureCtrl") << "mImageItemID: " << mImageItemID
- << LL_ENDL;
- mImageAssetID = floaterp->getAssetID();
- LL_DEBUGS("TextureCtrl") << "mImageAssetID: " << mImageAssetID
- << LL_ENDL;
- }
- if (op == TEXTURE_SELECT && mOnSelectCallback)
- {
- mOnSelectCallback(this, mCallbackUserData);
- }
- else if (op == TEXTURE_CANCEL && mOnCancelCallback)
- {
- mOnCancelCallback(this, mCallbackUserData);
- }
- else
- {
- onCommit();
- }
- }
- }
- }
- void LLTextureCtrl::setImageAssetID(const LLUUID& asset_id)
- {
- if (mImageAssetID != asset_id)
- {
- mImageItemID.setNull();
- mLocalTrackingID.setNull();
- mImageAssetID = asset_id;
- LLFloaterTexturePicker* floaterp =
- (LLFloaterTexturePicker*)mFloaterHandle.get();
- if (floaterp && getEnabled())
- {
- floaterp->setImageID(asset_id);
- floaterp->setDirty(false);
- }
- }
- }
- //virtual
- bool LLTextureCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
- EDragAndDropType cargo_type,
- void* cargo_data, EAcceptance* accept,
- std::string& tooltip_msg)
- {
- // This downcast may be invalid, but if the second test below returns true,
- // then the cast was valid, and we can perform the third test without
- // problem.
- LLInventoryItem* item = (LLInventoryItem*)cargo_data;
- if (getEnabled() &&
- #if LL_MESH_ASSET_SUPPORT
- (cargo_type == DAD_TEXTURE || cargo_type == DAD_MESH) &&
- #else
- cargo_type == DAD_TEXTURE &&
- #endif
- allowDrop(item))
- {
- if (drop)
- {
- if (doDrop(item))
- {
- // This removes the 'Multiple' overlay, since there is now only
- // one texture selected.
- setTentative(false);
- onCommit();
- }
- }
- *accept = ACCEPT_YES_SINGLE;
- }
- else
- {
- *accept = ACCEPT_NO;
- }
- LL_DEBUGS("UserInput") << "dragAndDrop handled by LLTextureCtrl "
- << getName() << LL_ENDL;
- return true;
- }
- //virtual
- void LLTextureCtrl::draw()
- {
- mBorder->setKeyboardFocusHighlight(hasFocus());
- if (!mValid)
- {
- mTexturep = NULL;
- }
- else if (mImageAssetID.notNull())
- {
- LLPointer<LLViewerFetchedTexture> texture = NULL;
- if (LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
- {
- LLViewerObject* obj = gSelectMgr.getSelection()->getFirstObject();
- if (obj)
- {
- LLViewerTexture* baked_tex =
- obj->getBakedTextureForMagicId(mImageAssetID);
- if (baked_tex)
- {
- texture = baked_tex->asFetched();
- }
- }
- }
- if (texture.notNull())
- {
- mTexturep = texture;
- }
- else
- {
- mTexturep =
- LLViewerTextureManager::getFetchedTexture(mImageAssetID,
- FTT_DEFAULT, true,
- LLGLTexture::BOOST_PREVIEW,
- LLViewerTexture::LOD_TEXTURE);
- }
- mTexturep->forceToSaveRawImage(0);
- }
- else if (mFallbackImagep.notNull())
- {
- // Show fallback image.
- mTexturep = mFallbackImagep;
- }
- else // mImageAssetID.notNull()
- {
- mTexturep = NULL;
- }
- // Border
- LLRect border(0, getRect().getHeight(), getRect().getWidth(),
- gBtnHeightSmall);
- gl_rect_2d(border, mBorderColor, false);
- // Interior
- LLRect interior = border;
- interior.stretch(-1);
- if (mTexturep)
- {
- bool draw_checker_board = mTexturep->getComponents() == 4;
- if (draw_checker_board)
- {
- gl_rect_2d_checkerboard(interior);
- }
- F32 left = interior.mLeft;
- F32 bottom = interior.mBottom;
- F32 width = interior.getWidth();
- F32 height = interior.getHeight();
- // Pump the priority
- mTexturep->addTextureStats(width * height);
- if (mDisplayRatio > 0.f &&
- !is_approx_zero(mDisplayRatio - width / height))
- {
- if (!draw_checker_board)
- {
- // Draw a black background that will show as thick strips
- // around the resized picture.
- gl_rect_2d(interior, LLColor4::black);
- }
- F32 proportion = mDisplayRatio * height / width;
- if (proportion < 1.f)
- {
- left += (width - width * proportion) * 0.5f;
- width *= proportion;
- }
- else
- {
- bottom += (height - height / proportion) * 0.5f;
- height /= proportion;
- }
- }
- gl_draw_scaled_image(left, bottom, width, height, mTexturep);
- }
- else
- {
- gl_rect_2d(interior, LLColor4::grey);
- // Draw X
- gl_draw_x(interior, LLColor4::black);
- }
- mTentativeLabel->setVisible(mTexturep.notNull() && getTentative());
- // 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())
- {
- static LLFontGL* sans = LLFontGL::getFontSansSerif();
- static LLFontGL* large = LLFontGL::getFontSansSerifLarge();
- LLFontGL* font = interior.getWidth() < 128 ? sans : large;
- font->render(mLoadingPlaceholderString, 0,
- llfloor(interior.mLeft + 4), llfloor(interior.mTop - 20),
- LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE,
- LLFontGL::DROP_SHADOW);
- }
- LLUICtrl::draw();
- }
- bool LLTextureCtrl::allowDrop(LLInventoryItem* item)
- {
- const LLPermissions& perms = item->getPermissions();
- PermissionMask item_perm_mask = 0;
- if (perms.allowCopyBy(gAgentID))
- {
- item_perm_mask = PERM_COPY;
- }
- if (perms.allowModifyBy(gAgentID))
- {
- item_perm_mask |= PERM_MODIFY;
- }
- if (perms.allowTransferBy(gAgentID))
- {
- item_perm_mask |= PERM_TRANSFER;
- }
- // Never allow to apply no-copy textures by dropping them: the drop code
- // would delete the texture from the inventory... HB
- PermissionMask filter_perm_mask = PERM_COPY;
- filter_perm_mask |= mCanApplyImmediately ? mImmediateFilterPermMask
- : mNonImmediateFilterPermMask;
- if ((item_perm_mask & filter_perm_mask) != filter_perm_mask)
- {
- return false;
- }
- if (!mDragCallback)
- {
- return true;
- }
- return mDragCallback(this, item, mCallbackUserData);
- }
- bool LLTextureCtrl::doDrop(LLInventoryItem* item)
- {
- if (!mDropCallback)
- {
- // No callback installed, so just set the image ids and carry on.
- setImageAssetID(item->getAssetUUID());
- mImageItemID = item->getUUID();
- return true;
- }
- // Call callback; if it returns true, we return true, and therefore the
- // commit is called above.
- return mDropCallback(this, item, mCallbackUserData);
- }
- //virtual
- bool LLTextureCtrl::handleUnicodeCharHere(llwchar uni_char)
- {
- if (uni_char == ' ')
- {
- showPicker(true);
- return true;
- }
- return LLUICtrl::handleUnicodeCharHere(uni_char);
- }
- //virtual
- void LLTextureCtrl::setValue(const LLSD& value)
- {
- setImageAssetID(value.asUUID());
- }
- //virtual
- LLSD LLTextureCtrl::getValue() const
- {
- return LLSD(getImageAssetID());
- }
|