summaryrefslogtreecommitdiff
path: root/indra/newview/llfloateroutfitphotopreview.cpp
blob: 6c39db730c33c40b0f86a3d0a2661d6a9c24368f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/** 
 * @file llfloateroutfitphotopreview.cpp
 * @brief LLFloaterOutfitPhotoPreview class implementation
 *
 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, 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 "llwindow.h"

#include "llfloateroutfitphotopreview.h"

#include "llagent.h"
#include "llappearancemgr.h"
#include "llbutton.h"
#include "llcombobox.h"
#include "llfilepicker.h"
#include "llfloaterreg.h"
#include "llimagetga.h"
#include "llimagepng.h"
#include "llinventory.h"
#include "llinventorymodel.h"
#include "llnotificationsutil.h"
#include "llresmgr.h"
#include "lltrans.h"
#include "lltextbox.h"
#include "lltextureview.h"
#include "llui.h"
#include "llviewerinventory.h"
#include "llviewertexture.h"
#include "llviewertexturelist.h"
#include "lluictrlfactory.h"
#include "llviewerwindow.h"
#include "lllineeditor.h"

const S32 MAX_OUTFIT_PHOTO_WIDTH = 256;
const S32 MAX_OUTFIT_PHOTO_HEIGHT = 256;

const S32 CLIENT_RECT_VPAD = 4;

LLFloaterOutfitPhotoPreview::LLFloaterOutfitPhotoPreview(const LLSD& key)
	: LLPreview(key),
	  mUpdateDimensions(TRUE),
	  mImage(NULL),
	  mOutfitID(LLUUID()),
	  mImageOldBoostLevel(LLGLTexture::BOOST_NONE),
	  mExceedLimits(FALSE)
{
	updateImageID();
}

LLFloaterOutfitPhotoPreview::~LLFloaterOutfitPhotoPreview()
{
	LLLoadedCallbackEntry::cleanUpCallbackList(&mCallbackTextureList) ;

	if (mImage.notNull())
	{
		mImage->setBoostLevel(mImageOldBoostLevel);
		mImage = NULL;
	}
}

// virtual
BOOL LLFloaterOutfitPhotoPreview::postBuild()
{
	getChild<LLButton>("ok_btn")->setClickedCallback(boost::bind(&LLFloaterOutfitPhotoPreview::onOkBtn, this));
	getChild<LLButton>("cancel_btn")->setClickedCallback(boost::bind(&LLFloaterOutfitPhotoPreview::onCancelBtn, this));

	return LLPreview::postBuild();
}

void LLFloaterOutfitPhotoPreview::draw()
{
	updateDimensions();
	
	LLPreview::draw();

	if (!isMinimized())
	{
		LLGLSUIDefault gls_ui;
		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
		
		const LLRect& border = mClientRect;
		LLRect interior = mClientRect;
		interior.stretch( -PREVIEW_BORDER_WIDTH );

		// ...border
		gl_rect_2d( border, LLColor4(0.f, 0.f, 0.f, 1.f));
		gl_rect_2d_checkerboard( interior );

		if ( mImage.notNull() )
		{
			// Draw the texture
			gGL.diffuseColor3f( 1.f, 1.f, 1.f );
			gl_draw_scaled_image(interior.mLeft,
								interior.mBottom,
								interior.getWidth(),
								interior.getHeight(),
								mImage);

			// Pump the texture priority
			F32 pixel_area = (F32)(interior.getWidth() * interior.getHeight() );
			mImage->addTextureStats( pixel_area );

			S32 int_width = interior.getWidth();
			S32 int_height = interior.getHeight();
			mImage->setKnownDrawSize(int_width, int_height);
		}
	} 

}

// virtual
void LLFloaterOutfitPhotoPreview::reshape(S32 width, S32 height, BOOL called_from_parent)
{
	LLPreview::reshape(width, height, called_from_parent);

	LLRect dim_rect(getChildView("dimensions")->getRect());

	S32 horiz_pad = 2 * (LLPANEL_BORDER_WIDTH + PREVIEW_PAD) + PREVIEW_RESIZE_HANDLE_SIZE;

	S32 info_height = dim_rect.mTop + CLIENT_RECT_VPAD;

	LLRect client_rect(horiz_pad, getRect().getHeight(), getRect().getWidth() - horiz_pad, 0);
	client_rect.mTop -= (PREVIEW_HEADER_SIZE + CLIENT_RECT_VPAD);
	client_rect.mBottom += PREVIEW_BORDER + CLIENT_RECT_VPAD + info_height ;

	S32 client_width = client_rect.getWidth();
	S32 client_height = client_width;

	if(client_height > client_rect.getHeight())
	{
		client_height = client_rect.getHeight();
		client_width = client_height;
	}
	mClientRect.setLeftTopAndSize(client_rect.getCenterX() - (client_width / 2), client_rect.getCenterY() +  (client_height / 2), client_width, client_height);

}


void LLFloaterOutfitPhotoPreview::updateDimensions()
{
	if (!mImage)
	{
		return;
	}
	if ((mImage->getFullWidth() * mImage->getFullHeight()) == 0)
	{
		return;
	}

	if (mAssetStatus != PREVIEW_ASSET_LOADED)
	{
		mAssetStatus = PREVIEW_ASSET_LOADED;
		mUpdateDimensions = TRUE;
	}
	
	getChild<LLUICtrl>("dimensions")->setTextArg("[WIDTH]",  llformat("%d", mImage->getFullWidth()));
	getChild<LLUICtrl>("dimensions")->setTextArg("[HEIGHT]", llformat("%d", mImage->getFullHeight()));

	if ((mImage->getFullWidth() <= MAX_OUTFIT_PHOTO_WIDTH) && (mImage->getFullHeight() <= MAX_OUTFIT_PHOTO_HEIGHT))
	{
		getChild<LLButton>("ok_btn")->setEnabled(TRUE);
		mExceedLimits = FALSE;
	}
	else
	{
		mExceedLimits = TRUE;
		LLStringUtil::format_map_t args;
		args["MAX_WIDTH"] = llformat("%d", MAX_OUTFIT_PHOTO_WIDTH);
		args["MAX_HEIGHT"] = llformat("%d", MAX_OUTFIT_PHOTO_HEIGHT);
		std::string label = getString("exceed_limits", args);
		getChild<LLUICtrl>("notification")->setValue(label);
		getChild<LLUICtrl>("notification")->setColor(LLColor4::yellow);
		getChild<LLButton>("ok_btn")->setEnabled(FALSE);
	}

	if (mUpdateDimensions)
	{
		mUpdateDimensions = FALSE;

		reshape(getRect().getWidth(), getRect().getHeight());
		gFloaterView->adjustToFitScreen(this, FALSE);
	}
}

void LLFloaterOutfitPhotoPreview::loadAsset()
{
	if (mImage.notNull())
	{
		mImage->setBoostLevel(mImageOldBoostLevel);
	}
	mImage = LLViewerTextureManager::getFetchedTexture(mImageID, FTT_DEFAULT, MIPMAP_TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
	mImageOldBoostLevel = mImage->getBoostLevel();
	mImage->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
	mImage->forceToSaveRawImage(0) ;
	mAssetStatus = PREVIEW_ASSET_LOADING;
	mUpdateDimensions = TRUE;
	updateDimensions();
}

LLPreview::EAssetStatus LLFloaterOutfitPhotoPreview::getAssetStatus()
{
	if (mImage.notNull() && (mImage->getFullWidth() * mImage->getFullHeight() > 0))
	{
		mAssetStatus = PREVIEW_ASSET_LOADED;
	}
	return mAssetStatus;
}

void LLFloaterOutfitPhotoPreview::updateImageID()
{
	const LLViewerInventoryItem *item = static_cast<const LLViewerInventoryItem*>(getItem());
	if(item)
	{
		mImageID = item->getAssetUUID();
		LLPermissions perm(item->getPermissions());
	}
	else
	{
		mImageID = mItemUUID;
	}

}

/* virtual */
void LLFloaterOutfitPhotoPreview::setObjectID(const LLUUID& object_id)
{
	mObjectUUID = object_id;

	const LLUUID old_image_id = mImageID;

	updateImageID();
	if (mImageID != old_image_id)
	{
		mAssetStatus = PREVIEW_ASSET_UNLOADED;
		loadAsset();
	}
	refreshFromItem();
}

void LLFloaterOutfitPhotoPreview::setOutfitID(const LLUUID& outfit_id)
{
	mOutfitID = outfit_id;
	LLViewerInventoryCategory* outfit_folder = gInventory.getCategory(mOutfitID);
	if(outfit_folder && !mExceedLimits)
	{
		getChild<LLUICtrl>("notification")->setValue( getString("photo_confirmation"));
		getChild<LLUICtrl>("notification")->setTextArg("[OUTFIT]", outfit_folder->getName());
		getChild<LLUICtrl>("notification")->setColor(LLColor4::white);
	}

}

void LLFloaterOutfitPhotoPreview::onOkBtn()
{
	if(mOutfitID.notNull() && getItem())
	{
		LLAppearanceMgr::instance().removeOutfitPhoto(mOutfitID);
		LLPointer<LLInventoryCallback> cb = NULL;
		link_inventory_object(mOutfitID, LLConstPointer<LLInventoryObject>(getItem()), cb);
	}
	closeFloater();
}

void LLFloaterOutfitPhotoPreview::onCancelBtn()
{
	closeFloater();
}