PageRenderTime 777ms CodeModel.GetById 594ms app.highlight 10ms RepoModel.GetById 171ms app.codeStats 0ms

/indra/newview/llpanelsnapshotinventory.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 109 lines | 62 code | 15 blank | 32 comment | 1 complexity | 6b7dfb693644da617e156cab33949786 MD5 | raw file
  1/** 
  2 * @file llpanelsnapshotinventory.cpp
  3 * @brief The panel provides UI for saving snapshot as an inventory texture.
  4 *
  5 * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2011, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llcombobox.h"
 30#include "lleconomy.h"
 31#include "llsidetraypanelcontainer.h"
 32#include "llspinctrl.h"
 33
 34#include "llfloatersnapshot.h" // FIXME: replace with a snapshot storage model
 35#include "llpanelsnapshot.h"
 36#include "llviewercontrol.h" // gSavedSettings
 37
 38/**
 39 * The panel provides UI for saving snapshot as an inventory texture.
 40 */
 41class LLPanelSnapshotInventory
 42:	public LLPanelSnapshot
 43{
 44	LOG_CLASS(LLPanelSnapshotInventory);
 45
 46public:
 47	LLPanelSnapshotInventory();
 48	/*virtual*/ BOOL postBuild();
 49	/*virtual*/ void onOpen(const LLSD& key);
 50
 51private:
 52	/*virtual*/ void updateCustomResControls(); ///< Show/hide custom resolution controls (spinners and checkbox)
 53	/*virtual*/ std::string getWidthSpinnerName() const		{ return "inventory_snapshot_width"; }
 54	/*virtual*/ std::string getHeightSpinnerName() const	{ return "inventory_snapshot_height"; }
 55	/*virtual*/ std::string getAspectRatioCBName() const	{ return "inventory_keep_aspect_check"; }
 56	/*virtual*/ std::string getImageSizeComboName() const	{ return "texture_size_combo"; }
 57	/*virtual*/ std::string getImageSizePanelName() const	{ return LLStringUtil::null; }
 58	/*virtual*/ void updateControls(const LLSD& info);
 59
 60	void onSend();
 61};
 62
 63static LLRegisterPanelClassWrapper<LLPanelSnapshotInventory> panel_class("llpanelsnapshotinventory");
 64
 65LLPanelSnapshotInventory::LLPanelSnapshotInventory()
 66{
 67	mCommitCallbackRegistrar.add("Inventory.Save",		boost::bind(&LLPanelSnapshotInventory::onSend,		this));
 68	mCommitCallbackRegistrar.add("Inventory.Cancel",	boost::bind(&LLPanelSnapshotInventory::cancel,		this));
 69}
 70
 71// virtual
 72BOOL LLPanelSnapshotInventory::postBuild()
 73{
 74	getChild<LLSpinCtrl>(getWidthSpinnerName())->setAllowEdit(FALSE);
 75	getChild<LLSpinCtrl>(getHeightSpinnerName())->setAllowEdit(FALSE);
 76	getChild<LLUICtrl>(getAspectRatioCBName())->setVisible(FALSE); // we don't keep aspect ratio for inventory textures
 77	return LLPanelSnapshot::postBuild();
 78}
 79
 80// virtual
 81void LLPanelSnapshotInventory::onOpen(const LLSD& key)
 82{
 83	getChild<LLUICtrl>("hint_lbl")->setTextArg("[UPLOAD_COST]", llformat("%d", LLGlobalEconomy::Singleton::getInstance()->getPriceUpload()));
 84	LLPanelSnapshot::onOpen(key);
 85}
 86
 87// virtual
 88void LLPanelSnapshotInventory::updateCustomResControls()
 89{
 90	LLComboBox* combo = getChild<LLComboBox>(getImageSizeComboName());
 91	S32 selected_idx = combo->getFirstSelectedIndex();
 92	const bool show = selected_idx == (combo->getItemCount() - 1); // Custom selected
 93
 94	getChild<LLUICtrl>(getWidthSpinnerName())->setVisible(show);
 95	getChild<LLUICtrl>(getHeightSpinnerName())->setVisible(show);
 96}
 97
 98// virtual
 99void LLPanelSnapshotInventory::updateControls(const LLSD& info)
100{
101	const bool have_snapshot = info.has("have-snapshot") ? info["have-snapshot"].asBoolean() : true;
102	getChild<LLUICtrl>("save_btn")->setEnabled(have_snapshot);
103}
104
105void LLPanelSnapshotInventory::onSend()
106{
107	LLFloaterSnapshot::saveTexture();
108	LLFloaterSnapshot::postSave();
109}